/* dynamic SQL support routines
*
- * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.16 2006/06/25 09:38:39 meskes Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.17 2006/07/05 10:49:56 meskes Exp $
*/
#define POSTGRES_ECPG_INTERNAL
data_var.ind_varcharsize = varcharsize;
data_var.ind_arrsize = arrsize;
data_var.ind_offset = offset;
- if (data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0)
+ if ((data_var.ind_arrsize == 0 || data_var.ind_varcharsize == 0) && data_var.ind_pointer != NULL)
data_var.ind_value = *((void **) (data_var.ind_pointer));
else
data_var.ind_value = data_var.ind_pointer;
setlocale(LC_NUMERIC, oldlocale);
ECPGfree(oldlocale);
}
- else if (data_var.ind_type != ECPGt_NO_INDICATOR)
+ else if (data_var.ind_type != ECPGt_NO_INDICATOR && data_var.ind_pointer != NULL)
+ /* ind_type != NO_INDICATOR should always have ind_pointer != NULL but since this might be changed manually in the .c file let's play it safe */
{
/*
* this is like ECPGstore_result but since we don't have a data
ECPGraise(lineno, ECPG_TOO_MANY_MATCHES, ECPG_SQLSTATE_CARDINALITY_VIOLATION, NULL);
return false;
}
+
/* allocate storage if needed */
- if (data_var.ind_arrsize == 0 && data_var.ind_pointer != NULL && data_var.ind_value == NULL)
+ if (data_var.ind_arrsize == 0 && data_var.ind_value == NULL)
{
void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
if (!mem)
ECPGadd_mem(mem, lineno);
data_var.ind_value = mem;
}
+
for (act_tuple = 0; act_tuple < ntuples; act_tuple++)
{
if (!get_int_item(lineno, data_var.ind_value, data_var.ind_type, -PQgetisnull(ECPGresult, act_tuple, index)))
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.50 2006/06/26 09:20:09 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.51 2006/07/05 10:49:56 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
{
char *str = NULL;
int slen;
- numeric *nval = PGTYPESnumeric_new();
+ numeric *nval;
if (var->arrsize > 1)
{
- for (element = 0; element < var->arrsize; element++, nval = PGTYPESnumeric_new())
+ for (element = 0; element < var->arrsize; element++)
{
+ nval = PGTYPESnumeric_new();
if (!nval)
return false;
}
else
{
+ nval = PGTYPESnumeric_new();
if (!nval)
return false;
case ECPGt_timestamp:
{
- char *str = NULL;
+ char *str = NULL, *asc = NULL;
int slen;
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++)
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), lineno);
+ asc = PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value));
+ if (!asc)
+ return false;
+
+ str = quote_postgres(asc, lineno);
+ ECPGfree(asc); /* we don't need this anymore so free it asap. */
if (!str)
return false;
+
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))
}
else
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), lineno);
+ asc = PGTYPEStimestamp_to_asc(*(timestamp *) (var->value));
+ if (!asc)
+ return false;
+
+ str = quote_postgres(asc, lineno);
+ ECPGfree(asc); /* we don't need this anymore so free it asap. */
if (!str)
return false;
slen = strlen(str);