howto declare variable sized array w esql

From: Jeffrey Graham <jgraham(at)titan(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: howto declare variable sized array w esql
Date: 2002-06-11 13:32:59
Message-ID: 3D05FC0B.8090609@titan.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hello everyone,

Can someone please tell me how to declare an array of double (float8)
using esql when you
don't know how long the array is until runtime?

I have the code work for a fixed length of 10, but at run-time I might only
put 2 values or there could just as easily be 100 or 200 or 5000!

I tried several variations declaring my array as a pointer, but ecpg did
not like
any of my attempts.

If I must and it someone can confirm, I guess I could declare the array
as some fixed
max size and then save just the slice? How to do that?

Thanks,
Jeff

Here is some code I am trying:

void myinsert(const std::vector<double>& myVector)
{
EXEC SQL BEGIN DECLARE SECTION;

/* this would be ideal but ecpg does not like it */
/* double m_data[myVector.length()]; */

/* This works but length might actually be 1 or 200! */
double m_data[10];

EXEC SQL END DECLARE SECTION;

/* stuff the sql array with data from my stl vector */
for ( unsigned int i=0; i < myVector.length(); i++ )
m_data[i] = myVector[i];

EXEC SQL
insert into eraDATA
( data )
VALUES( :m_data );
return sqlOK();
}

Browse pgsql-interfaces by date

  From Date Subject
Next Message Sandro Dentella 2002-06-11 17:23:33 Re: libpgtcl and encoding
Previous Message Friedrich Dodt 2002-06-11 13:09:39 Re: Where is PLbash ??