This is a discussion on dynamic fixchar array ? within the Informix forums, part of the Database Server Software category; --> I want to read from a number of different posible versions of a table where field1 may be nchar(x) ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I want to read from a number of different posible versions of a table where field1 may be nchar(x) where x nay vary over versions of the database. This situation already exists. I want the code below to select successfully based on db version. Based on db version the size of field1 in the_table will be set, but I am having difficulty compiling a dynamically sized ESQL fixchar array. Any ideas. Many thanks, Andrew H. /* global */ unsigned int the_size; .... .... the_size = ???; .... .... f(); .... .... f() { EXEC SQL BEGIN DECLARE SECTION; fixchar data[the_size]; char read_cur[100]; EXEC SQL END DECLARE SECTION; sprintf (read_cur, "%s", CHARGING_PERSIST_READ); EXEC SQL DECLARE :read_cur CURSOR FOR SELECT field1 INTO :data FROM the_table; .... .... } sending to informix-list |
| |||
| Andrew Hardy wrote: > I want to read from a number of different posible versions of a table where > field1 may be nchar(x) where x nay vary over versions of the database. > This situation already exists. I want the code below to select > successfully based on db version. Based on db version the size of field1 > in the_table will be set, but I am having difficulty compiling a > dynamically sized ESQL fixchar array. And the error message was? > fixchar data[the_size]; VLAs are C99, maybe that's the problem. -- rh |
| ||||
| On Wed, 21 Jul 2004 04:50:56 -0400, Andrew Hardy wrote: You need to DESCRIBE the cursor to discover the length of the column and delay binding the host variable to the cursor until OPEN time. Lookup DESCRIBE in the Guide to SQL Syntax (look at the ESQL/C Programmers manual also, but SQL first). Here's a quick and dirty: EXEC SQL INCLUDE sqlda; f() { EXEC SQL BEGIN DECLARE SECTION; fixchar data[the_size]; char read_cur[100]; ifx_sqlda_t *da_struct; EXEC SQL END DECLARE SECTION; int len_field1; sprintf (read_cur, "%s", CHARGING_PERSIST_READ); EXEC SQL PREPARE read_stmt FROM "SELECT field1 FROM the_table"; EXEC SQL DESCRIBE read_stmt INTO da_struct; len_field1 = da_struct->sqlvar[0].sqllen; data = (char *)malloc( len_field1 ); da_struct->sqlvar[0].sqldata = data; da_struct->sqltype = SQLFIXCHAR; /* Convert the column to fixed string */ EXEC SQL DECLARE :read_cur CURSOR FOR read_stmt; EXEC SQL OPEN :read_cur USING DESCRIPTOR da_struct; .... .... EXEC SQL FETCH :read_cur; .... } Art S. Kagel > I want to read from a number of different posible versions of a table where > field1 may be nchar(x) where x nay vary over versions of the database. This > situation already exists. I want the code below to select successfully > based on db version. Based on db version the size of field1 in the_table > will be set, but I am having difficulty compiling a dynamically sized ESQL > fixchar array. > > Any ideas. > > Many thanks, > > Andrew H. > > > /* global */ > unsigned int the_size; > > ... > ... > the_size = ???; > ... > ... > f(); > ... > ... > > f() > { > EXEC SQL BEGIN DECLARE SECTION; > fixchar data[the_size]; > char read_cur[100]; > EXEC SQL END DECLARE SECTION; > > sprintf (read_cur, "%s", CHARGING_PERSIST_READ); > > EXEC SQL DECLARE :read_cur CURSOR FOR > SELECT field1 > INTO :data > FROM the_table; > ... > ... > } > > > > > sending to informix-list |
| Thread Tools | |
| Display Modes | |
|
|