-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.58 2006/08/09 09:08:31 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.59 2006/08/18 16:30:53 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
}
if (**tobeinserted_p == '\0')
{
+ int asize = var->arrsize? var->arrsize : 1;
+
switch (var->type)
{
int element;
case ECPGt_short:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_int:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_unsigned_short:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_unsigned_int:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_unsigned_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 20, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 20, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
#ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_unsigned_long_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 30, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 30, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
#endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_float:
- if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
break;
case ECPGt_double:
- if (!(mallocedval = ECPGalloc(var->arrsize * 25, lineno)))
+ if (!(mallocedval = ECPGalloc(asize * 25, lineno)))
return false;
- if (var->arrsize > 1)
+ if (asize > 1)
{
strcpy(mallocedval, "array [");
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
strcpy(mallocedval + strlen(mallocedval) - 1, "]");
char text [ 25 ] = "klmnopqrst" ;
#line 30 "test4.pgc"
- char * t = ( char * ) malloc ( 10 ) ;
+ char * t = ( char * ) malloc ( 11 ) ;
#line 31 "test4.pgc"
double f ;
#line 46 "test4.pgc"
- { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , 'f' , 0 , 0 )", ECPGt_EOIT, ECPGt_EORT);
+ { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' , 'f' , 0 , 0 ) ", ECPGt_EOIT, ECPGt_EORT);
#line 48 "test4.pgc"
if (sqlca.sqlcode < 0) sqlprint();}
#line 48 "test4.pgc"
- { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 140787.0 , 2 , ? , ? , 't' , 2 , 14 )",
+ { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 140787.0 , 2 , ? , ? , 't' , 2 , 14 ) ",
ECPGt_int,(a),(long)1,(long)10,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char),
- { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 14.07 , ? , ? , ? , ? , 1 , 147 )",
+ { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f , i , a , text , b , t , err ) values( 14.07 , ? , ? , ? , ? , 1 , 147 ) ",
ECPGt_int,&(did),(long)1,(long)0,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
ECPGt_int,(a),(long)1,(long)10,sizeof(int),