I am using ECPG with PostgreSQL 8.4. I have a function which takes a struct containing pointers to a couple of dynamically allocated, "null"-terminated arrays of integers (I have defined null in this case to be -1, as there is no need for negative values, as in
#define INT_ARR_NULL -1
struct foobar {
int * foo;
int * bar;
};
void init_foobar( struct foobar * fb ) {
fb->foo = (int*) calloc( 11, sizeof(int) );
fb->bar = (int*) calloc( 11, sizeof(int) );
fb->foo[10]=INT_ARR_NULL;
fb->bar[10]=INT_ARR_NULL;
int i;
for( i = 0; i < 10; ++i ) {
fb->foo[i] = i;
fb->bar[i] = i;
}
}
void print_foo( struct foobar * fb ) {
int * cursor = fb->foo;
while( *cursor != INT_ARR_NULL ) {
printf( "%d ", *cursor );
++cursor;
}
}
I included the print_foo function to show how the array would normally work. If I want to insert these values into an array in a PostgreSQL column using ECPG, how would I go about this?