Strange problem with ESQL/C and I-NET
Posted in 1995
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL
Hi netters, i have a very strange problem with ESQL/C (version 5.01.UD2) and I-NET (4.01). Problems: 1. The following listing function works most of the times (99%), but sometimes, it exits with the error: Error -349: Prepare: Database not selected yet. 2. I also have similiar function called (addreq) which uses straight 'Insert' command to insert dblines, when the above function fails, addreq will fail also, but with no errors. 3. In normal operation, addreq have to add a field (cc) which has a length of say 80 chars, but only 38 are inserted and the line is truncted. Please help me All help is appreciated Thanks jaswant -----------------------The listing fuction----------------------------------- #include <stdio.h> $include sqlca; char errmsg[400]; main (argc,argv) int argc; char *argv[]; { $char r_req_no [7]; $char r_state [10]; $char r_assigned [15]; $char r_date_needed [15]; $char r_date_closed [15]; $char r_now [15]; $char r_abstract[60]; $char r_fullname [30]; $char r_cc [120]; $char r_login [15]; $char value1 [15]; $char value2 [15]; $char attribute [20]; $char query_1[160]; int i; $database "//pyramid/request"; if ( argc < 4 ) { printf("%s\\n", "Usage: list <status> <assigned/orig/date> <login/date>"); exit (1); } strcpy(value2,argv[1]); strcpy(attribute,argv[2]); strcpy(value1,argv[3]); if ( strcmp("all",value1)==0){ strcpy(value1,"*"); } if ( strcmp("assigned",attribute)==0){ sprintf(query_1,"%s", "SELECT req_no, state, now, date_needed,fullname,login, cc, assigned, abstract, date_closed FROM request WHERE assigned matches ? and state matches ?"); } if ( strcmp("orig",attribute)==0){ close(query_1); sprintf(query_1,"%s", "SELECT req_no, state, now, date_needed,fullname,login, cc, assigned, abstract, date_closed FROM request WHERE login matches ? and state matches ?"); } if ( strcmp("date",attribute)==0){ close(query_1); sprintf(query_1,"%s", "SELECT req_no, state, now, date_needed,fullname,login, cc, assigned, abstract, date_closed FROM request WHERE date_closed >= ? and state matches ?"); } if ( strcmp("COUNT",attribute)==0){ close(query_1); sprintf(query_1,"%s", "SELECT req_no, state, now, date_needed,fullname,login, cc, assigned, abstract, date_closed FROM request WHERE req_no = ? and state matches ?"); } $prepare q_req from $query_1; err_chk("Prepare"); $declare reqcursor cursor for q_req; err_chk("Declare"); $open reqcursor using $value1, $value2; err_chk("OpenCursor"); for (;;) { $fetch reqcursor into $r_req_no, $r_state, $r_now, $r_date_needed,$r_fullname,$r_login, $r_cc, $r_assigned, $r_abstract, $r_date_closed; err_chk("Fetch"); if ( sqlca.sqlcode) break; printf("%s::%s::%s::%s::%s::%s::%s::%s::%s::%s\\n", r_req_no, r_state, r_now, r_date_needed,r_fullname, r_login, r_cc, r_assigned, r_abstract, r_date_closed); } $close reqcursor; } err_chk(name) char *name; { if (sqlca.sqlcode < 0 ) { rgetmsg((short)sqlca.sqlcode, errmsg, sizeof(errmsg)); printf("\\n\\tError %d during %s: %s\\n", sqlca.sqlcode, name, errmsg); exit (1); } return((sqlca.sqlcode==SQLNOTFOUND) ? 0 : 1); } -- +-----------------------------------------------------------------------------+ Jaswant S. Bhardwaj Ext: 2651 Development Engineering Computing Services Group