Help on esql/c syntax
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Help on esql/c syntax ===================== Why don't these work? I've read and re-read the ESQL/C Programmer's Manual and if I understand the book correctly, these should work. (I'm using Informix-SE and ESQL/C 7.24.UC5.) 1. Storing a table identifier into a host variable. Example: ... $char tablename[50]; stcopy ("farkle", tablename); $select from $tablename; ... When I compile it I get the error "-33051: Syntax error on identifier or symbol '$'. 2. Using EXECUTE...INTO for counting number of rows. Example: ... $int num_rows; $prepare sel1 from 'select count (*) from farkle'; $execute sel1 into :num_rows; $free sel1; ... When I compile it I get the error "-33051: Syntax error on identifier or symbol 'into'. Thanks, Michelle --== Sent via Deja.com http://www.deja.com/ ==-- ---Share what you know. Learn what you don't.---
mc_santos@my-dejanews.com wrote: > > Help on esql/c syntax > ===================== > > Why don't these work? I've read and re-read the ESQL/C Programmer's > Manual and if I understand the book correctly, these should work. > (I'm using Informix-SE and ESQL/C 7.24.UC5.) > > 1. Storing a table identifier into a host variable. Example: > > ... > $char tablename[50]; > stcopy ("farkle", tablename); > $select from $tablename; > ... > > When I compile it I get the error "-33051: Syntax error on > identifier or symbol '$'. There are no staements where you can use a host variable to specify the table. To get the equivalent effect, you have to use a PREPARE statement. Also, you need to specify what you are selecting; the FROM is being treated as a column name, the $tablename as a failed attempt to provide a display label (column alias) for the column FROM, and you've omitted the FROM clause. But any error is as good as any other and if you put a '*' in the SELECT-list, you'd still not be able to use $tablename to identify the table. > 2. Using EXECUTE...INTO for counting number of rows. Example: > > ... > $int num_rows; > $prepare sel1 from 'select count (*) from farkle'; > $execute sel1 into :num_rows; > $free sel1; > ... > > When I compile it I get the error "-33051: Syntax error on > identifier or symbol 'into'. Hmmm, trickier, especially since my box of 7.2 manuals went walkabout when I moved offices. Being able to use EXECUTE stmt INTO :var is very recent syntax and may not be available in 7.2x ESQL/C. I think it is available in the ClientSDK versions of ESQL/C. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>
HI Buddy, Answer to Ist question : Since in this case you are trying to have table name as variable so you really need to use Dynamic SQL. You will need to formulate a full string which contains the statement including table name. prepare that query and then declare a cursor for that prepared query. Open that cursor and then fetch rows into your program. For your 2nd question you can not use prepare and execute like this for select statements. you can use it only for insert, update, delete etc but not for select. From informix 7.3.1 onward you would be able do this prepare and execute as long as your select returns one single row. Hope that answers your question. Thanks, Khem Chander. kchande@yahoo.com mc_santos@my-dejanews.com wrote in article <7hfml4$2hs$1@nnrp1.deja.com>... > Help on esql/c syntax > ===================== > > Why don't these work? I've read and re-read the ESQL/C Programmer's > Manual and if I understand the book correctly, these should work. > (I'm using Informix-SE and ESQL/C 7.24.UC5.) > > 1. Storing a table identifier into a host variable. Example: > > ... > $char tablename[50]; > stcopy ("farkle", tablename); > $select from $tablename; > ... > > When I compile it I get the error "-33051: Syntax error on identifier or > symbol '$'. > > 2. Using EXECUTE...INTO for counting number of rows. Example: > > ... > $int num_rows; > $prepare sel1 from 'select count (*) from farkle'; > $execute sel1 into :num_rows; > $free sel1; > ... > > When I compile it I get the error "-33051: Syntax error on identifier or > symbol 'into'. > > Thanks, > Michelle > > > --== Sent via Deja.com http://www.deja.com/ ==-- > ---Share what you know. Learn what you don't.--- >