Unix Technical Forum

dynamic fixchar array ?

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) ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 07:17 AM
Andrew Hardy
 
Posts: n/a
Default dynamic fixchar array ?



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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 07:18 AM
Richard Harnden
 
Posts: n/a
Default Re: dynamic fixchar array ?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 07:18 AM
Art S. Kagel
 
Posts: n/a
Default Re: dynamic fixchar array ?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

« MIME | JDBC-Problem »

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:37 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com