I put together the following script which illustrates my problem.
Basically, the main part of the script runs fine (the actual selection), but not if I try and run it twice as shown below.
I assume I'm doing something wrong (or missing doing something) but what ?
LIBRARY rxodbc
odbcerr = "ERROR"
odbcheading = 1
DO
odbcallocenv()
CATCH ERROR
CONDITION("M")
RETURN
END
rc = get_number_of_rows()
IF rc <> 0 THEN
EXIT 1
rc = get_number_of_rows()
IF rc <> 0 THEN
EXIT 1
RETURN
get_number_of_rows:
connectstring = "DSN=MFEODBC;SERVER=DATOR;Database=userid;UID=userid;PWD=;"
db2_handlename = "DB2.MFE_handle"
rc = odbcconnect(connect_string, db2_handlename, , "PROMPT")
DO
rc = odbcallocdatabase(db2_handlename, "ConnectString", "stmt")
SELECT
WHEN rc <> '' THEN
SAY rc
OTHERWISE
NOP
END
CATCH ERROR
err = CONDITION('D')
SAY err
RETURN 1
END
data. = "Select count(*) from sysibm.syscolumns where name = 'NAME'"
DO
odbcexecute(data., "columns")
CATCH ERROR
err = CONDITION('D')
SAY err
RETURN 1
END
DO
DO WHILE odbcfetch("data.", columns) <> "DONE"
SAY 'data.1 ' data.1
END
CATCH ERROR
err = CONDITION('D')
SAY err
RETURN 1
END
odbcfreestmt('CLOSE')
err = odbcfreedatabase()
RETURN 0
|