summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/ecpg/ecpglib')
-rw-r--r--src/interfaces/ecpg/ecpglib/connect.c3
-rw-r--r--src/interfaces/ecpg/ecpglib/data.c92
-rw-r--r--src/interfaces/ecpg/ecpglib/descriptor.c14
-rw-r--r--src/interfaces/ecpg/ecpglib/execute.c176
-rw-r--r--src/interfaces/ecpg/ecpglib/extern.h4
5 files changed, 201 insertions, 88 deletions
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index b3209db5cd..5de287c973 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.28 2006/06/19 09:19:49 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.29 2006/06/21 10:24:40 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -403,6 +403,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
ECPGfree(realname);
if (dbname)
ECPGfree(dbname);
+ ecpg_finish(this);
return false;
}
}
diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 1f6d26f7ee..c81a682847 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.31 2006/06/06 11:31:55 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.32 2006/06/21 10:24:40 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -93,13 +93,17 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- ECPGraise(lineno, ECPG_MISSING_INDICATOR, ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER, NULL);
+ ECPGraise(lineno, ECPG_MISSING_INDICATOR,
+ ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER,
+ NULL);
return (false);
}
}
break;
default:
- ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(ind_type));
+ ECPGraise(lineno, ECPG_UNSUPPORTED,
+ ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
+ ECPGtype_name(ind_type));
return (false);
break;
}
@@ -111,9 +115,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
/* let's check if it really is an array if it should be one */
if (isarray == ECPG_ARRAY_ARRAY)
{
- if (*pval != '{')
+ if (!pval || *pval != '{')
{
- ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
+ ECPGraise(lineno, ECPG_DATA_NOT_ARRAY,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, NULL);
return (false);
}
@@ -134,13 +139,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
if (binary)
{
- if (pval)
- {
- if (varcharsize == 0 || varcharsize*offset >= size)
- memcpy((char *) ((long) var + offset * act_tuple), pval, size);
+ if (pval)
+ {
+ if (varcharsize == 0 || varcharsize*offset >= size)
+ memcpy((char *) ((long) var + offset * act_tuple),
+ pval, size);
else
{
- memcpy((char *) ((long) var + offset * act_tuple), pval, varcharsize*offset);
+ memcpy((char *) ((long) var + offset * act_tuple),
+ pval, varcharsize*offset);
if (varcharsize*offset < size)
{
@@ -195,7 +202,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
res = strtol(pval, &scan_length, 10);
if (garbage_left(isarray, scan_length, compat))
{
- ECPGraise(lineno, ECPG_INT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_INT_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
@@ -228,7 +236,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
ures = strtoul(pval, &scan_length, 10);
if (garbage_left(isarray, scan_length, compat))
{
- ECPGraise(lineno, ECPG_UINT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_UINT_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
@@ -305,7 +314,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
- ECPGraise(lineno, ECPG_FLOAT_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_FLOAT_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
pval = scan_length;
@@ -337,7 +347,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else if (offset == sizeof(int))
*((int *) (var + offset * act_tuple)) = false;
else
- ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
+ ECPGraise(lineno, ECPG_CONVERT_BOOL,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH,
+ "different size");
break;
}
else if (pval[0] == 't' && pval[1] == '\0')
@@ -347,7 +359,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else if (offset == sizeof(int))
*((int *) (var + offset * act_tuple)) = true;
else
- ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
+ ECPGraise(lineno, ECPG_CONVERT_BOOL,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH,
+ "different size");
break;
}
else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field))
@@ -357,7 +371,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
}
- ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_CONVERT_BOOL,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
break;
@@ -464,7 +479,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
/* did we get an error? */
if (nres == NULL)
{
- ECPGlog("ECPGget_data line %d: RESULT: %s errno %d\n", lineno, pval ? pval : "", errno);
+ ECPGlog("ECPGget_data line %d: RESULT: %s errno %d\n",
+ lineno, pval ? pval : "", errno);
if (INFORMIX_MODE(compat))
{
@@ -472,11 +488,20 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* Informix wants its own NULL value here instead
* of an error
*/
- ECPGset_noind_null(ECPGt_numeric, nres);
+ nres = PGTYPESnumeric_new();
+ if (nres)
+ ECPGset_noind_null(ECPGt_numeric, nres);
+ else
+ {
+ ECPGraise(lineno, ECPG_OUT_OF_MEMORY,
+ ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
+ return (false);
+ }
}
else
{
- ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_NUMERIC_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -488,7 +513,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
free(nres);
- ECPGraise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_NUMERIC_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -522,11 +548,16 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* Informix wants its own NULL value here instead
* of an error
*/
+ ires = (interval *) ECPGalloc(sizeof(interval), lineno);
+ if (!ires)
+ return (false);
+
ECPGset_noind_null(ECPGt_interval, ires);
}
else
{
- ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_INTERVAL_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -538,7 +569,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
free(ires);
- ECPGraise(lineno, ECPG_INTERVAL_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_INTERVAL_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -571,7 +603,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_DATE_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -582,7 +615,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
- ECPGraise(lineno, ECPG_DATE_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_DATE_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -613,7 +647,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
else
{
- ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -624,7 +659,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (garbage_left(isarray, scan_length, compat))
{
- ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
+ ECPGraise(lineno, ECPG_TIMESTAMP_FORMAT,
+ ECPG_SQLSTATE_DATATYPE_MISMATCH, pval);
return (false);
}
}
@@ -635,7 +671,9 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
break;
default:
- ECPGraise(lineno, ECPG_UNSUPPORTED, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, ECPGtype_name(type));
+ ECPGraise(lineno, ECPG_UNSUPPORTED,
+ ECPG_SQLSTATE_ECPG_INTERNAL_ERROR,
+ ECPGtype_name(type));
return (false);
break;
}
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index ff47cd1325..19fd0173a3 100644
--- a/src/interfaces/ecpg/ecpglib/descriptor.c
+++ b/src/interfaces/ecpg/ecpglib/descriptor.c
@@ -1,6 +1,6 @@
/* dynamic SQL support routines
*
- * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.14 2006/01/15 22:46:53 neilc Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.15 2006/06/21 10:24:40 meskes Exp $
*/
#define POSTGRES_ECPG_INTERNAL
@@ -351,8 +351,9 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
/* allocate storage if needed */
if (arrsize == 0 && var != NULL && *(void **) var == NULL)
{
- void *mem = (void *) ECPGalloc(offset * ntuples, lineno);
-
+ void *mem = (void *) ECPGalloc(offset * ntuples, lineno);
+ if (!mem)
+ return false;
*(void **) var = mem;
ECPGadd_mem(mem, lineno);
var = mem;
@@ -412,8 +413,9 @@ ECPGget_desc(int lineno, const char *desc_name, int index,...)
/* allocate storage if needed */
if (data_var.ind_arrsize == 0 && data_var.ind_pointer != NULL && data_var.ind_value == NULL)
{
- void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
-
+ void *mem = (void *) ECPGalloc(data_var.ind_offset * ntuples, lineno);
+ if (!mem)
+ return false;
*(void **) data_var.ind_pointer = mem;
ECPGadd_mem(mem, lineno);
data_var.ind_value = mem;
@@ -480,6 +482,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
if (desc_item == NULL)
{
desc_item = (struct descriptor_item *) ECPGalloc(sizeof(*desc_item), lineno);
+ if (!desc_item)
+ return false;
desc_item->num = index;
desc_item->next = desc->items;
desc->items = desc_item;
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index a3a14e2e48..c2ff9b6de9 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.46 2006/05/26 23:48:54 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.47 2006/06/21 10:24:40 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -250,16 +250,20 @@ next_insert(char *text)
return (*ptr == '\0') ? NULL : ptr;
}
-static void
+static bool
ECPGtypeinfocache_push(struct ECPGtype_information_cache ** cache, int oid, bool isarray, int lineno)
{
struct ECPGtype_information_cache *new_entry
= (struct ECPGtype_information_cache *) ECPGalloc(sizeof(struct ECPGtype_information_cache), lineno);
+ if (new_entry == NULL)
+ return (false);
+
new_entry->oid = oid;
new_entry->isarray = isarray;
new_entry->next = *cache;
*cache = new_entry;
+ return(true);
}
static enum ARRAY_TYPE
@@ -279,48 +283,48 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
#define not_an_array_in_ecpg ECPG_ARRAY_NONE
/* populate cache with well known types to speed things up */
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOOLOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), BYTEAOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), CHAROID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), NAMEOID, not_an_array_in_ecpg, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT8OID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2OID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2VECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT4OID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), REGPROCOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TEXTOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIDOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), XIDOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDVECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), POINTOID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), LSEGOID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), PATHOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOXOID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), POLYGONOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), LINEOID, ECPG_ARRAY_VECTOR, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT4OID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT8OID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), ABSTIMEOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), RELTIMEOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TINTERVALOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), UNKNOWNOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIRCLEOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), CASHOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INETOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDROID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), BPCHAROID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARCHAROID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), DATEOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMEOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPTZOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), INTERVALOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno);
- ECPGtypeinfocache_push(&(stmt->connection->cache_head), NUMERICOID, ECPG_ARRAY_NONE, stmt->lineno);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOOLOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BYTEAOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CHAROID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), NAMEOID, not_an_array_in_ecpg, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT8OID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2OID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT2VECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INT4OID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), REGPROCOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TEXTOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIDOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), XIDOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), OIDVECTOROID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), POINTOID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), LSEGOID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), PATHOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BOXOID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), POLYGONOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), LINEOID, ECPG_ARRAY_VECTOR, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT4OID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), FLOAT8OID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), ABSTIMEOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), RELTIMEOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TINTERVALOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), UNKNOWNOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIRCLEOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CASHOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INETOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), CIDROID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), BPCHAROID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARCHAROID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), DATEOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMEOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMESTAMPTZOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), INTERVALOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
+ if (!ECPGtypeinfocache_push(&(stmt->connection->cache_head), NUMERICOID, ECPG_ARRAY_NONE, stmt->lineno)) return (ECPG_ARRAY_ERROR);
}
for (cache_entry = (stmt->connection->cache_head); cache_entry != NULL; cache_entry = cache_entry->next)
@@ -330,6 +334,9 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
}
array_query = (char *) ECPGalloc(strlen("select typlen from pg_type where oid= and typelem<>0") + 11, stmt->lineno);
+ if (array_query == NULL)
+ return (ECPG_ARRAY_ERROR);
+
sprintf(array_query, "select typlen from pg_type where oid=%d and typelem<>0", type);
query = PQexec(stmt->connection->connection, array_query);
ECPGfree(array_query);
@@ -366,7 +373,11 @@ ECPGstore_result(const PGresult *results, int act_field,
ntuples = PQntuples(results);
bool status = true;
- isarray = ECPGis_type_an_array(PQftype(results, act_field), stmt, var);
+ if ((isarray = ECPGis_type_an_array(PQftype(results, act_field), stmt, var)) == ECPG_ARRAY_ERROR)
+ {
+ ECPGraise(stmt->lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
+ return false;
+ }
if (isarray == ECPG_ARRAY_NONE)
{
@@ -438,6 +449,8 @@ ECPGstore_result(const PGresult *results, int act_field,
break;
}
var->value = (char *) ECPGalloc(len, stmt->lineno);
+ if (!var->value)
+ return false;
*((char **) var->pointer) = var->value;
ECPGadd_mem(var->value, stmt->lineno);
}
@@ -448,6 +461,8 @@ ECPGstore_result(const PGresult *results, int act_field,
int len = var->ind_offset * ntuples;
var->ind_value = (char *) ECPGalloc(len, stmt->lineno);
+ if (!var->ind_value)
+ return false;
*((char **) var->ind_pointer) = var->ind_value;
ECPGadd_mem(var->ind_value, stmt->lineno);
}
@@ -863,6 +878,9 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
int slen;
numeric *nval = PGTYPESnumeric_new();
+ if (!nval)
+ return false;
+
if (var->arrsize > 1)
{
for (element = 0; element < var->arrsize; element++, nval = PGTYPESnumeric_new())
@@ -877,7 +895,11 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [] "), lineno)))
+ {
+ PGTYPESnumeric_free(nval);
+ free(str);
return false;
+ }
if (!element)
strcpy(mallocedval, "array [");
@@ -896,11 +918,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
str = PGTYPESnumeric_to_asc(nval, nval->dscale);
- PGTYPESnumeric_free(nval);
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + 1, lineno)))
+ {
+ PGTYPESnumeric_free(nval);
+ free(str);
return false;
+ }
strncpy(mallocedval, str, slen);
mallocedval[slen] = '\0';
@@ -908,6 +933,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
*tobeinserted_p = mallocedval;
*malloced_p = true;
+ PGTYPESnumeric_free(nval);
free(str);
}
break;
@@ -922,10 +948,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
for (element = 0; element < var->arrsize; element++)
{
str = quote_postgres(PGTYPESinterval_to_asc((interval *) ((var + var->offset * element)->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],interval "), lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
if (!element)
strcpy(mallocedval, "array [");
@@ -939,10 +970,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
else
{
str = quote_postgres(PGTYPESinterval_to_asc((interval *) (var->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("interval ") + 1, lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
strcpy(mallocedval, "interval ");
/* also copy trailing '\0' */
@@ -951,7 +987,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
*tobeinserted_p = mallocedval;
*malloced_p = true;
- free(str);
+ ECPGfree(str);
}
break;
@@ -965,10 +1001,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
for (element = 0; element < var->arrsize; element++)
{
str = quote_postgres(PGTYPESdate_to_asc(*(date *) ((var + var->offset * element)->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [],date "), lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
if (!element)
strcpy(mallocedval, "array [");
@@ -982,10 +1023,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
else
{
str = quote_postgres(PGTYPESdate_to_asc(*(date *) (var->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("date ") + 1, lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
strcpy(mallocedval, "date ");
/* also copy trailing '\0' */
@@ -994,7 +1040,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
*tobeinserted_p = mallocedval;
*malloced_p = true;
- free(str);
+ ECPGfree(str);
}
break;
@@ -1008,10 +1054,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
for (element = 0; element < var->arrsize; element++)
{
str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) ((var + var->offset * element)->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGrealloc(mallocedval, strlen(mallocedval) + slen + sizeof("array [], timestamp "), lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
if (!element)
strcpy(mallocedval, "array [");
@@ -1025,10 +1076,15 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
else
{
str = quote_postgres(PGTYPEStimestamp_to_asc(*(timestamp *) (var->value)), lineno);
+ if (!str)
+ return false;
slen = strlen(str);
if (!(mallocedval = ECPGalloc(slen + sizeof("timestamp") + 1, lineno)))
+ {
+ ECPGfree(str);
return false;
+ }
strcpy(mallocedval, "timestamp ");
/* also copy trailing '\0' */
@@ -1037,7 +1093,7 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
*tobeinserted_p = mallocedval;
*malloced_p = true;
- free(str);
+ ECPGfree(str);
}
break;
@@ -1162,8 +1218,13 @@ ECPGexecute(struct statement * stmt)
* Now tobeinserted points to an area that is to be inserted at
* the first %s
*/
- if (!(newcopy = (char *) ECPGalloc(strlen(copiedquery) + strlen(tobeinserted) + 1, stmt->lineno)))
+ if (!(newcopy = (char *) ECPGalloc(strlen(copiedquery)
+ + strlen(tobeinserted)
+ + 1, stmt->lineno)))
+ {
+ ECPGfree(copiedquery);
return false;
+ }
strcpy(newcopy, copiedquery);
if ((p = next_insert(newcopy + hostvarl)) == NULL)
@@ -1172,7 +1233,11 @@ ECPGexecute(struct statement * stmt)
* We have an argument but we dont have the matched up string
* in the string
*/
- ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
+ ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
+ NULL);
+ ECPGfree(copiedquery);
+ ECPGfree(newcopy);
return false;
}
else
@@ -1212,7 +1277,9 @@ ECPGexecute(struct statement * stmt)
/* Check if there are unmatched things left. */
if (next_insert(copiedquery) != NULL)
{
- ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
+ ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
+ ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
+ ECPGfree(copiedquery);
return false;
}
@@ -1222,7 +1289,9 @@ ECPGexecute(struct statement * stmt)
{
if ((results = PQexec(stmt->connection->connection, "begin transaction")) == NULL)
{
- ECPGraise(stmt->lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+ ECPGraise(stmt->lineno, ECPG_TRANS,
+ ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+ ECPGfree(copiedquery);
return false;
}
PQclear(results);
@@ -1391,6 +1460,7 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name,
{
setlocale(LC_NUMERIC, oldlocale);
ECPGfree(oldlocale);
+ free_statement(stmt);
return (false);
}
va_end(args);
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index 48c956cca0..120f54302b 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.16 2006/03/11 04:38:39 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.17 2006/06/21 10:24:41 meskes Exp $ */
#ifndef _ECPG_LIB_EXTERN_H
#define _ECPG_LIB_EXTERN_H
@@ -16,7 +16,7 @@ enum COMPAT_MODE
enum ARRAY_TYPE
{
- ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
+ ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
};
/* Here are some methods used by the lib. */