aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/execute.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/execute.c')
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c280
1 files changed, 110 insertions, 170 deletions
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index c2b96f7f16e..22ce55b60a0 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -499,16 +499,10 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
char *newcopy = NULL;
/*
- * arrays are not possible unless the attribute is an array too FIXME: we
- * do not know if the attribute is an array here
+ * arrays are not possible unless the column is an array, too
+ * FIXME: we do not know if the column is an array here
+ * array input to singleton column will result in a runtime error
*/
-#if 0
- if (var->arrsize > 1 &&...)
- {
- ecpg_raise(lineno, ECPG_ARRAY_INSERT, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
- return false;
- }
-#endif
/*
* Some special treatment is needed for records since we want their
@@ -566,12 +560,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; 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));
@@ -604,12 +598,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; 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));
@@ -623,12 +617,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; 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));
@@ -642,12 +636,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; 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));
@@ -661,12 +655,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; 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));
@@ -680,12 +674,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%lld,", ((long long int *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
}
else
sprintf(mallocedval, "%lld", *((long long int *) var->value));
@@ -699,12 +693,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%llu,", ((unsigned long long int *) var->value)[element]);
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
}
else
sprintf(mallocedval, "%llu", *((unsigned long long int *) var->value));
@@ -718,12 +712,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; element++)
sprintf_float_value(mallocedval + strlen(mallocedval), ((float *) var->value)[element], ",");
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
}
else
sprintf_float_value(mallocedval, *((float *) var->value), "");
@@ -737,12 +731,12 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
if (asize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
for (element = 0; element < asize; element++)
sprintf_double_value(mallocedval + strlen(mallocedval), ((double *) var->value)[element], ",");
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
}
else
sprintf_double_value(mallocedval, *((double *) var->value), "");
@@ -751,27 +745,27 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
break;
case ECPGt_bool:
- if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("array []"), lineno)))
+ if (!(mallocedval = ecpg_alloc(var->arrsize + sizeof("{}"), lineno)))
return false;
if (var->arrsize > 1)
{
- strcpy(mallocedval, "array [");
+ strcpy(mallocedval, "{");
if (var->offset == sizeof(char))
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f');
/*
* this is necessary since sizeof(C++'s bool)==sizeof(int)
*/
else if (var->offset == sizeof(int))
- for (element = 0; element < var->arrsize; element++)
+ for (element = 0; element < asize; element++)
sprintf(mallocedval + strlen(mallocedval), "%c,", (((int *) var->value)[element]) ? 't' : 'f');
else
ecpg_raise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
}
else
{
@@ -853,67 +847,33 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
numeric *nval;
if (var->arrsize > 1)
- {
- if (!(mallocedval = ecpg_strdup("array [", lineno)))
- return false;
-
- for (element = 0; element < var->arrsize; element++)
- {
- int result;
-
- nval = PGTYPESnumeric_new();
- if (!nval)
- {
- ecpg_free(mallocedval);
- return false;
- }
-
- if (var->type == ECPGt_numeric)
- result = PGTYPESnumeric_copy((numeric *) ((var + var->offset * element)->value), nval);
- else
- result = PGTYPESnumeric_from_decimal((decimal *) ((var + var->offset * element)->value), nval);
-
- if (result != 0)
- {
- PGTYPESnumeric_free(nval);
- ecpg_free(mallocedval);
- return false;
- }
-
- str = PGTYPESnumeric_to_asc(nval, nval->dscale);
- slen = strlen(str);
- PGTYPESnumeric_free(nval);
+ mallocedval = ecpg_strdup("{", lineno);
+ else
+ mallocedval = ecpg_strdup("", lineno);
- if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
- {
- ecpg_free(mallocedval);
- ecpg_free(str);
- return false;
- }
- mallocedval = newcopy;
+ if (!mallocedval)
+ return false;
- memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
- strcpy(mallocedval + strlen(mallocedval), ",");
- ecpg_free(str);
- }
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
- }
- else
+ for (element = 0; element < asize; element++)
{
int result;
nval = PGTYPESnumeric_new();
if (!nval)
+ {
+ ecpg_free(mallocedval);
return false;
+ }
if (var->type == ECPGt_numeric)
- result = PGTYPESnumeric_copy((numeric *) (var->value), nval);
+ result = PGTYPESnumeric_copy(&(((numeric *) (var->value))[element]), nval);
else
- result = PGTYPESnumeric_from_decimal((decimal *) (var->value), nval);
+ result = PGTYPESnumeric_from_decimal(&(((decimal *) (var->value))[element]), nval);
if (result != 0)
{
PGTYPESnumeric_free(nval);
+ ecpg_free(mallocedval);
return false;
}
@@ -921,17 +881,25 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
slen = strlen(str);
PGTYPESnumeric_free(nval);
- if (!(mallocedval = ecpg_alloc(slen + 1, lineno)))
+ if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
{
- free(str);
+ ecpg_free(mallocedval);
+ ecpg_free(str);
return false;
}
+ mallocedval = newcopy;
+
+ /* also copy trailing '\0' */
+ memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval), ",");
- strncpy(mallocedval, str, slen);
- mallocedval[slen] = '\0';
ecpg_free(str);
}
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
+
*tobeinserted_p = mallocedval;
}
break;
@@ -942,52 +910,43 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
int slen;
if (var->arrsize > 1)
- {
- if (!(mallocedval = ecpg_strdup("array [", lineno)))
- return false;
-
- for (element = 0; element < var->arrsize; element++)
- {
- str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), quote, lineno);
- if (!str)
- {
- ecpg_free(mallocedval);
- return false;
- }
- slen = strlen(str);
+ mallocedval = ecpg_strdup("{", lineno);
+ else
+ mallocedval = ecpg_strdup("", lineno);
- if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
- {
- ecpg_free(mallocedval);
- ecpg_free(str);
- return false;
- }
- mallocedval = newcopy;
+ if (!mallocedval)
+ return false;
- memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
- strcpy(mallocedval + strlen(mallocedval), ",");
- ecpg_free(str);
- }
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
- }
- else
+ for (element = 0; element < asize; element++)
{
- str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), quote, lineno);
+ str = quote_postgres(PGTYPESinterval_to_asc(&(((interval *) (var->value))[element])), quote, lineno);
if (!str)
+ {
+ ecpg_free(mallocedval);
return false;
+ }
+
slen = strlen(str);
- if (!(mallocedval = ecpg_alloc(slen + sizeof("interval ") + 1, lineno)))
+ if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
{
+ ecpg_free(mallocedval);
ecpg_free(str);
return false;
}
+ mallocedval = newcopy;
/* also copy trailing '\0' */
memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval), ",");
+
ecpg_free(str);
}
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
+
*tobeinserted_p = mallocedval;
}
break;
@@ -998,52 +957,43 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
int slen;
if (var->arrsize > 1)
- {
- if (!(mallocedval = ecpg_strdup("array [", lineno)))
- return false;
-
- for (element = 0; element < var->arrsize; element++)
- {
- str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), quote, lineno);
- if (!str)
- {
- ecpg_free(mallocedval);
- return false;
- }
- slen = strlen(str);
+ mallocedval = ecpg_strdup("{", lineno);
+ else
+ mallocedval = ecpg_strdup("", lineno);
- if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
- {
- ecpg_free(mallocedval);
- ecpg_free(str);
- return false;
- }
- mallocedval = newcopy;
+ if (!mallocedval)
+ return false;
- memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
- strcpy(mallocedval + strlen(mallocedval), ",");
- ecpg_free(str);
- }
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
- }
- else
+ for (element = 0; element < asize; element++)
{
- str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), quote, lineno);
+ str = quote_postgres(PGTYPESdate_to_asc(((date *) (var->value))[element]), quote, lineno);
if (!str)
+ {
+ ecpg_free(mallocedval);
return false;
+ }
+
slen = strlen(str);
- if (!(mallocedval = ecpg_alloc(slen + sizeof("date ") + 1, lineno)))
+ if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
{
+ ecpg_free(mallocedval);
ecpg_free(str);
return false;
}
+ mallocedval = newcopy;
/* also copy trailing '\0' */
memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval), ",");
+
ecpg_free(str);
}
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
+
*tobeinserted_p = mallocedval;
}
break;
@@ -1054,53 +1004,43 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
int slen;
if (var->arrsize > 1)
- {
- if (!(mallocedval = ecpg_strdup("array [", lineno)))
- return false;
-
- for (element = 0; element < var->arrsize; element++)
- {
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), quote, lineno);
- if (!str)
- {
- ecpg_free(mallocedval);
- return false;
- }
-
- slen = strlen(str);
+ mallocedval = ecpg_strdup("{", lineno);
+ else
+ mallocedval = ecpg_strdup("", lineno);
- if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
- {
- ecpg_free(mallocedval);
- ecpg_free(str);
- return false;
- }
- mallocedval = newcopy;
+ if (!mallocedval)
+ return false;
- memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
- strcpy(mallocedval + strlen(mallocedval), ",");
- ecpg_free(str);
- }
- strcpy(mallocedval + strlen(mallocedval) - 1, "]");
- }
- else
+ for (element = 0; element < asize; element++)
{
- str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), quote, lineno);
+ str = quote_postgres(PGTYPEStimestamp_to_asc(((timestamp *) (var->value))[element]), quote, lineno);
if (!str)
+ {
+ ecpg_free(mallocedval);
return false;
+ }
+
slen = strlen(str);
- if (!(mallocedval = ecpg_alloc(slen + sizeof("timestamp") + 1, lineno)))
+ if (!(newcopy = ecpg_realloc(mallocedval, strlen(mallocedval) + slen + 2, lineno)))
{
+ ecpg_free(mallocedval);
ecpg_free(str);
return false;
}
+ mallocedval = newcopy;
/* also copy trailing '\0' */
memcpy(mallocedval + strlen(mallocedval), str, slen + 1);
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval), ",");
+
ecpg_free(str);
}
+ if (var->arrsize > 1)
+ strcpy(mallocedval + strlen(mallocedval) - 1, "}");
+
*tobeinserted_p = mallocedval;
}
break;