rbp@investor.pgh.pa.us (Bob Peirce #305) (09/09/90)
According to the FM, "INFORMIX-ESQL/C returns a result code into the sqlca structure after executing every RDSQL statement except DECLARE." Further, sqlca.sqlcode "is set to zero for a successful execution of most statements" and to something else for unsuccessful. However, when I do the following, which I know fails, I get a zero in sqlcode and in the ISAM error code, sqlerrd[1]. Anybody know why? I need to check this stuff to avoid continuing with bad or no data, but I am not getting the expected results. $include sqlca; $ database reports $ SELECT c_name, c_no FROM client where c_no = 12345 <== 12345 substituted for $account into temp c; fprintf(stderr, "Unable to find client record for %d. Sqlcode = %ld, sqlerrd = %ld.\n", account, sqlca.sqlcode, sqlca.sqlerrd[1]); -- Bob Peirce, Pittsburgh, PA 412-471-5320 ...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us
rbp@investor.pgh.pa.us (Bob Peirce #305) (09/09/90)
I forgot. I am using the following versions on an Altos 3068. 1.10.00aS0 INFORMIX 4GL 2.10.00aS0 INFORMIX ESQL/C 2.10.00aS0 INFORMIX SQL -- Bob Peirce, Pittsburgh, PA 412-471-5320 ...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us
bochner@lange.harvard.EDU (Harry Bochner) (09/11/90)
In article <1990Sep8.192210.26950@investor.pgh.pa.us>, rbp@investor.pgh.pa.us (Bob Peirce #305) writes: > when I do the following, which I know fails, I get a zero in sqlcode > and in the ISAM error code, sqlerrd[1]. Anybody know why? > $include sqlca; > $ database reports > $ SELECT c_name, c_no > FROM client > where c_no = 12345 <== 12345 substituted for $account > into temp c; > fprintf(stderr, > "Unable to find client record for %d. Sqlcode = %ld, sqlerrd = %ld.\n", > account, sqlca.sqlcode, sqlca.sqlerrd[1]); I just tried it out with INFORMIX-4gl (I don't have ESQL, but I imagine it'll be the same). What seems to be happening is that finding zero rows, and thus creating a temp table c with zero rows, doesn't count as an error condition. Not too strange, actually. According to my experiments, the following behaves more like what you're looking for (assuming ESQL has this 4GL construction): sqlca.sqlcode gets set to 100 (NOTFOUND). select c_name, c_no into namevar, numvar ... ^^^^ Likewise if you set up a cursor for the select: no error when you open the cursor, but error 100 when you do a fetch. But your best bet might be to do a select count(*) into cnt, and then just check whether cnt=0. I use this method frequently. Assuming that you really want to fetch into a temp table, as in your example, you can keep the select as you wrote it, but follow it with "select count(*) into cnt from c". Harry Bochner bochner@das.harvard.edu
rbp@investor.pgh.pa.us (Bob Peirce #305) (09/11/90)
tomb@dpocs2 solved my problem. He pointed out that reading into a temp file will not set sqlcode if nothing is found but that sqlerrd[2] should contain the count of records found. It does. -- Bob Peirce, Pittsburgh, PA 412-471-5320 ...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us