Questions about ESQL/C 5.0
Posted in 1994
Topics: SQL Development & Query Writing, Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Hello! I am using ESQL/C 5.0 and I am looking for information on how to write certain functions. As an exercise, I am writing a program that is given a database and table name. The program should be able (without modifications!) to display the structure of the table (number of columns, name and type of columns, number of rows, etc.), display the contents of the table and allow inserts, updates and deletes. The basic things such as SELECT, INSERT and UPDATE are working, but I think that some things can be done in a more elegant and/or simpler way. 1. I would like to obtain information on a table (such as column name, type, etc.). Currently I am using a program like this: $PREPARE foo FROM "SELECT * FROM table"; $ALLOCATE DESCRIPTOR 'bar'; $DESCRIBE foo USING SQL DESCRIPTOR 'bar'; $GET DESCRIPTOR 'bar' $count = COUNT; for (i=1; i<=count; i++) { $GET DESCRIPTOR 'desc' VALUE $i $type = TYPE, $name = NAME; printf("%d %s\\n", type, name); } Is there another way to this without $PREPARE, $ALLOCATE, etc. (i.e. less overhead)? 2. Is there a way to specify an INSERT statement (via $PREPARE or some other way) without knowing the number of columns? Currently I am using something like: $PREPARE foo FROM "INSERT INTO table VALUES(?,?,?)"; were I need to know the number of rows in order to specify the correct number of "?" in the VALUE clause. (I am using "$SET DESCRIPTOR" and "$PUT cursor USING DESCRIPTOR" to actually do the insert.) 3. Using a cursor, I would like to UPDATE a row that I have just FETCHed. How can I write an "UPDATE WHERE CURRENT OF cursor" statement that uses the cursor from a $PREPAREd SELECT statement? 4. Is there a way to determine the number of rows returned by a $PREPAREd SELECT WHERE... statement? 5. Is there a way to use rowid() from within ESQL/C? If not, is there a similar function? Thanks for any help you may provide! -Walter