-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.19 2003/07/15 12:38:38 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.20 2003/07/25 16:10:26 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%hd", *((short *) var->value));
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%d", *((int *) var->value));
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%u", *((unsigned int *) var->value));
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%ld", *((long *) var->value));
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
break;
#ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 25, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize * 30, stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%lld", *((long long *) var->value));
break;
case ECPGt_unsigned_long_long:
- if (!(mallocedval = ECPGalloc(var->arrsize * 25, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize * 30, stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
break;
#endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_float:
- if (!(mallocedval = ECPGalloc(var->arrsize * 21, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize * 25, stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%.14g", *((float *) var->value));
break;
case ECPGt_double:
- if (!(mallocedval = ECPGalloc(var->arrsize * 21, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize * 25, stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
for (element = 0; element < var->arrsize; element++)
sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
sprintf(mallocedval, "%.14g", *((double *) var->value));
break;
case ECPGt_bool:
- if (!(mallocedval = ECPGalloc(var->arrsize * 2, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(var->arrsize +sizeof ("array []"), stmt->lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
if (var->offset == sizeof(char))
for (element = 0; element < var->arrsize; element++)
else
ECPGraise(stmt->lineno, ECPG_CONVERT_BOOL, "different size");
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
PGTYPESnumeric_free(nval);
slen = strlen (str);
- if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
+ if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), stmt->lineno)))
return false;
if (!element)
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
str = quote_postgres(PGTYPESinterval_to_asc((Interval *)((var + var->offset * element)->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
+ if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), stmt->lineno)))
return false;
if (!element)
- strcpy(mallocedval, "'{");
-
+ strcpy(mallocedval, "array [");
+
+ strcpy(mallocedval + strlen(mallocedval), "interval ");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
str = quote_postgres(PGTYPESinterval_to_asc((Interval *)(var->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, stmt->lineno)))
return false;
- strncpy(mallocedval, str , slen);
- mallocedval[slen] = '\0';
+ strcpy(mallocedval, "interval ");
+ /* also copy trailing '\0' */
+ strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
}
*tobeinserted_p = mallocedval;
str = quote_postgres(PGTYPESdate_to_asc(*(Date *)((var + var->offset * element)->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
+ if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), stmt->lineno)))
return false;
if (!element)
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
+ strcpy(mallocedval + strlen(mallocedval), "date ");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
str = quote_postgres(PGTYPESdate_to_asc(*(Date *)(var->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, stmt->lineno)))
return false;
- strncpy(mallocedval, str , slen);
- mallocedval[slen] = '\0';
+ strcpy(mallocedval, "date ");
+ /* also copy trailing '\0' */
+ strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
}
*tobeinserted_p = mallocedval;
str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)((var + var->offset * element)->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + 5, stmt->lineno)))
+ if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), stmt->lineno)))
return false;
if (!element)
- strcpy(mallocedval, "'{");
+ strcpy(mallocedval, "array [");
+ strcpy(mallocedval + strlen(mallocedval), "timestamp ");
strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
strcpy(mallocedval + strlen(mallocedval), ",");
}
- strcpy(mallocedval + strlen(mallocedval) - 1, "}'");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "]");
}
else
{
str = quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp *)(var->value)), stmt->lineno);
slen = strlen (str);
- if (!(mallocedval = ECPGalloc(slen + 1, stmt->lineno)))
+ if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, stmt->lineno)))
return false;
- strncpy(mallocedval, str , slen);
- mallocedval[slen] = '\0';
+ strcpy(mallocedval, "timestamp ");
+ /* also copy trailing '\0' */
+ strncpy(mallocedval + strlen(mallocedval), str , slen + 1);
}
*tobeinserted_p = mallocedval;