Problem: When gpre is run against an application that tries to create a table and populate the table an error is produced: "tablenot defined" Solution: The information in this article applies to: * InterBase v4.x * InterBase v5.x When a table is referenced gpre will check the column descriptions and data types against the description stored in the database. If the table description is not in the database or not declared gpre will return an error. The Declare Table statement allows gpre to see the table definition so that it can use the table in other SQL statements without having to reset the connection to the database. What follows is an example embedded application demonstrating the use of the Declare Table statement. If the Declare Table statement is commented out of the example, gpre will produce the "table not defined" error. ------------------- Begin code fragment ------------------- /* * Program type: Embedded Static SQL * * Description: * This program uses the DECLARE TABLE statement to * create and populate a table without disconnecting. */ #include #include #include "ibase.h" EXEC SQL SET DATABASE DB = "foo.gdb"; int main () { /* connect to db */ EXEC SQL CONNECT DB; EXEC SQL SET TRANSACTION; /* declare the table so can insert into it as well */ EXEC SQL DECLARE foo3 TABLE (I1 integer, v1 varchar(20), d1 date, b1 blob); /* Actually create the table */ EXEC SQL CREATE TABLE foo3 ( I1 INTEGER, V1 VARCHAR(20), D1 DATE, B1 BLOB ); EXEC SQL COMMIT; EXEC SQL SET TRANSACTION; EXEC SQL Insert into foo3 (i1, v1, d1) values (22, "insert string", "now"); EXEC SQL COMMIT; EXEC SQL DISCONNECT DB; return(0); } /* end main */
Last Modified: 28-SEP-00