summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/lib
diff options
context:
space:
mode:
authorMichael Meskes2001-12-23 12:17:41 +0000
committerMichael Meskes2001-12-23 12:17:41 +0000
commit988fdce5d1dcb1d5b7381f378079e76127b30882 (patch)
treea2632c4dcab7c2fad7a960d384ef79da6f43ef8d /src/interfaces/ecpg/lib
parentaed0c29f7e4626032669ebc3150e5121f36a9b4d (diff)
- Removed space_or_nl and line_end from pgc.l.
- Fixed several bugs concerning arrays of structs including a memory allocation bug.
Diffstat (limited to 'src/interfaces/ecpg/lib')
-rw-r--r--src/interfaces/ecpg/lib/Makefile4
-rw-r--r--src/interfaces/ecpg/lib/connect.c48
-rw-r--r--src/interfaces/ecpg/lib/data.c101
-rw-r--r--src/interfaces/ecpg/lib/descriptor.c6
-rw-r--r--src/interfaces/ecpg/lib/error.c7
-rw-r--r--src/interfaces/ecpg/lib/execute.c88
-rw-r--r--src/interfaces/ecpg/lib/extern.h6
-rw-r--r--src/interfaces/ecpg/lib/memory.c59
-rw-r--r--src/interfaces/ecpg/lib/misc.c4
-rw-r--r--src/interfaces/ecpg/lib/prepare.c12
10 files changed, 210 insertions, 125 deletions
diff --git a/src/interfaces/ecpg/lib/Makefile b/src/interfaces/ecpg/lib/Makefile
index d69b0215e4c..e512d304764 100644
--- a/src/interfaces/ecpg/lib/Makefile
+++ b/src/interfaces/ecpg/lib/Makefile
@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
-# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.13 2001/09/19 14:09:32 meskes Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.14 2001/12/23 12:17:41 meskes Exp $
#
#-------------------------------------------------------------------------
@@ -12,6 +12,8 @@ subdir = src/interfaces/ecpg/lib
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
+CFLAGS=-g
+
NAME= ecpg
SO_MAJOR_VERSION= 3
SO_MINOR_VERSION= 3.0
diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c
index 4520e1bf609..cb35a08ca25 100644
--- a/src/interfaces/ecpg/lib/connect.c
+++ b/src/interfaces/ecpg/lib/connect.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.16 2001/12/05 15:32:06 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.17 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -52,9 +52,9 @@ ecpg_finish(struct connection * act)
if (actual_connection == act)
actual_connection = all_connections;
- for (cache = act->cache_head; cache; ptr = cache, cache = cache->next, free(ptr));
- free(act->name);
- free(act);
+ for (cache = act->cache_head; cache; ptr = cache, cache = cache->next, ECPGfree(ptr));
+ ECPGfree(act->name);
+ ECPGfree(act);
}
else
ECPGlog("ecpg_finish: called an extra time.\n");
@@ -348,15 +348,15 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
ECPGlog("connect: socketname %s given for TCP connection in line %d\n", host, lineno);
ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>");
if (host)
- free(host);
+ ECPGfree(host);
if (port)
- free(port);
+ ECPGfree(port);
if (options)
- free(options);
+ ECPGfree(options);
if (realname)
- free(realname);
+ ECPGfree(realname);
if (dbname)
- free(dbname);
+ ECPGfree(dbname);
return false;
}
}
@@ -371,15 +371,15 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
ECPGlog("connect: non-localhost access via sockets in line %d\n", lineno);
ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>");
if (host)
- free(host);
+ ECPGfree(host);
if (port)
- free(port);
+ ECPGfree(port);
if (options)
- free(options);
+ ECPGfree(options);
if (realname)
- free(realname);
+ ECPGfree(realname);
if (dbname)
- free(dbname);
+ ECPGfree(dbname);
return false;
}
}
@@ -431,28 +431,28 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
lineno);
ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>");
if (host)
- free(host);
+ ECPGfree(host);
if (port)
- free(port);
+ ECPGfree(port);
if (options)
- free(options);
+ ECPGfree(options);
if (realname)
- free(realname);
+ ECPGfree(realname);
if (dbname)
- free(dbname);
+ ECPGfree(dbname);
return false;
}
if (host)
- free(host);
+ ECPGfree(host);
if (port)
- free(port);
+ ECPGfree(port);
if (options)
- free(options);
+ ECPGfree(options);
if (realname)
- free(realname);
+ ECPGfree(realname);
if (dbname)
- free(dbname);
+ ECPGfree(dbname);
this->committed = true;
this->autocommit = autocommit;
diff --git a/src/interfaces/ecpg/lib/data.c b/src/interfaces/ecpg/lib/data.c
index b0d91b9453a..678dde39a79 100644
--- a/src/interfaces/ecpg/lib/data.c
+++ b/src/interfaces/ecpg/lib/data.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/data.c,v 1.20 2001/12/05 15:32:06 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/data.c,v 1.21 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -15,11 +15,11 @@ bool
ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
enum ECPGttype type, enum ECPGttype ind_type,
void *var, void *ind, long varcharsize, long offset,
- bool isarray)
+ long ind_offset, bool isarray)
{
char *pval = (char *) PQgetvalue(results, act_tuple, act_field);
- ECPGlog("ECPGget_data line %d: RESULT: %s\n", lineno, pval ? pval : "");
+ ECPGlog("ECPGget_data line %d: RESULT: %s offset: %ld\n", lineno, pval ? pval : "", offset);
/* pval is a pointer to the value */
/* let's check is it really is an array if it should be one */
@@ -53,23 +53,28 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
case ECPGt_short:
case ECPGt_unsigned_short:
- ((short *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
+/* ((short *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
+ *((short *) (ind + ind_offset*act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
break;
case ECPGt_int:
case ECPGt_unsigned_int:
- ((int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
+/* ((int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
+ *((int *) (ind + ind_offset*act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
break;
case ECPGt_long:
case ECPGt_unsigned_long:
- ((long *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
+/* ((long *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
+ *((long *) (ind + ind_offset*act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
break;
#ifdef HAVE_LONG_LONG_INT_64
case ECPGt_long_long:
- ((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
- break;
case ECPGt_unsigned_long_long:
- ((unsigned long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
+/* ((long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);*/
+ *((long long int *) (ind + ind_offset*act_tuple)) = -PQgetisnull(results, act_tuple, act_field);
break;
+/* case ECPGt_unsigned_long_long:
+ ((unsigned long long int *) ind)[act_tuple] = -PQgetisnull(results, act_tuple, act_field);
+ break;*/
#endif /* HAVE_LONG_LONG_INT_64 */
case ECPGt_NO_INDICATOR:
if (PQgetisnull(results, act_tuple, act_field))
@@ -112,13 +117,16 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
switch (type)
{
case ECPGt_short:
- ((short *) var)[act_tuple] = (short) res;
+/* ((short *) var)[act_tuple] = (short) res;*/
+ *((short *) (var + offset*act_tuple)) = (short) res;
break;
case ECPGt_int:
- ((int *) var)[act_tuple] = (int) res;
+/* ((int *) var)[act_tuple] = (int) res;*/
+ *((int *) (var + offset*act_tuple)) = (int) res;
break;
case ECPGt_long:
- ((long *) var)[act_tuple] = res;
+/* ((long *) var)[act_tuple] = res;*/
+ *((long *) (var + offset*act_tuple)) = (long) res;
break;
default:
/* Cannot happen */
@@ -145,13 +153,16 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
switch (type)
{
case ECPGt_unsigned_short:
- ((unsigned short *) var)[act_tuple] = (unsigned short) ures;
+/* ((unsigned short *) var)[act_tuple] = (unsigned short) ures;*/
+ *((unsigned short *) (var + offset*act_tuple)) = (unsigned short) res;
break;
case ECPGt_unsigned_int:
- ((unsigned int *) var)[act_tuple] = (unsigned int) ures;
+/* ((unsigned int *) var)[act_tuple] = (unsigned int) ures;*/
+ *((unsigned int *) (var + offset*act_tuple)) = (unsigned int) res;
break;
case ECPGt_unsigned_long:
- ((unsigned long *) var)[act_tuple] = ures;
+/* ((unsigned long *) var)[act_tuple] = ures;*/
+ *((unsigned long *) (var + offset*act_tuple)) = (unsigned long) res;
break;
default:
/* Cannot happen */
@@ -164,7 +175,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_long_long:
if (pval)
{
- ((long long int *) var)[act_tuple] = strtoll(pval, &scan_length, 10);
+/* ((long long int *) var)[act_tuple] = strtoll(pval, &scan_length, 10);*/
+ *((long long int *) (var + offset*act_tuple)) = strtoll(pval, &scan_length, 10);
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
@@ -173,7 +185,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
}
else
- ((long long int *) var)[act_tuple] = (long long) 0;
+/* ((long long int *) var)[act_tuple] = (long long) 0;*/
+ *((long long int *) (var + offset*act_tuple)) = (long long) 0;
break;
#endif /* HAVE_STRTOLL */
@@ -181,7 +194,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
case ECPGt_unsigned_long_long:
if (pval)
{
- ((unsigned long long int *) var)[act_tuple] = strtoull(pval, &scan_length, 10);
+/* ((unsigned long long int *) var)[act_tuple] = strtoull(pval, &scan_length, 10);*/
+ *((unsigned long long int *) (var + offset*act_tuple)) = strtoull(pval, &scan_length, 10);
if ((isarray && *scan_length != ',' && *scan_length != '}')
|| (!isarray && *scan_length != '\0')) /* Garbage left */
{
@@ -190,7 +204,8 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
}
}
else
- ((unsigned long long int *) var)[act_tuple] = (long long) 0;
+/* ((unsigned long long int *) var)[act_tuple] = (long long) 0;*/
+ *((unsigned long long int *) (var + offset*act_tuple)) = (long long) 0;
break;
#endif /* HAVE_STRTOULL */
@@ -221,10 +236,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
switch (type)
{
case ECPGt_float:
- ((float *) var)[act_tuple] = dres;
+/* ((float *) var)[act_tuple] = dres;*/
+ *((float *) (var + offset*act_tuple)) = dres;
break;
case ECPGt_double:
- ((double *) var)[act_tuple] = dres;
+/* ((double *) var)[act_tuple] = dres;*/
+ *((double *) (var + offset*act_tuple)) = dres;
break;
default:
/* Cannot happen */
@@ -238,9 +255,11 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if (pval[0] == 'f' && pval[1] == '\0')
{
if (offset == sizeof(char))
- ((char *) var)[act_tuple] = false;
+/* ((char *) var)[act_tuple] = false;*/
+ *((char *) (var + offset*act_tuple)) = false;
else if (offset == sizeof(int))
- ((int *) var)[act_tuple] = false;
+/* ((int *) var)[act_tuple] = false;*/
+ *((int *) (var + offset*act_tuple)) = false;
else
ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size");
break;
@@ -248,9 +267,11 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
else if (pval[0] == 't' && pval[1] == '\0')
{
if (offset == sizeof(char))
- ((char *) var)[act_tuple] = true;
+/* ((char *) var)[act_tuple] = true;*/
+ *((char *) (var + offset*act_tuple)) = true;
else if (offset == sizeof(int))
- ((int *) var)[act_tuple] = true;
+/* ((int *) var)[act_tuple] = true;*/
+ *((int *) (var + offset*act_tuple)) = true;
else
ECPGraise(lineno, ECPG_CONVERT_BOOL, "different size");
break;
@@ -277,16 +298,25 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
case ECPGt_short:
case ECPGt_unsigned_short:
- ((short *) ind)[act_tuple] = strlen(pval);
+/* ((short *) ind)[act_tuple] = strlen(pval);*/
+ *((short *) (ind + ind_offset*act_tuple)) = strlen(pval);
break;
case ECPGt_int:
case ECPGt_unsigned_int:
- ((int *) ind)[act_tuple] = strlen(pval);
+/* ((int *) ind)[act_tuple] = strlen(pval);*/
+ *((int *) (ind + ind_offset*act_tuple)) = strlen(pval);
break;
case ECPGt_long:
case ECPGt_unsigned_long:
- ((long *) ind)[act_tuple] = strlen(pval);
+/* ((long *) ind)[act_tuple] = strlen(pval);*/
+ *((long *) (ind + ind_offset*act_tuple)) = strlen(pval);
+ break;
+#ifdef HAVE_LONG_LONG_INT_64
+ case ECPGt_long_long:
+ case ECPGt_unsigned_long_long:
+ *((long long int *) (ind + ind_offset*act_tuple)) = strlen(pval);
break;
+#endif /* HAVE_LONG_LONG_INT_64 */
default:
break;
}
@@ -313,16 +343,25 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{
case ECPGt_short:
case ECPGt_unsigned_short:
- ((short *) ind)[act_tuple] = variable->len;
+/* ((short *) ind)[act_tuple] = variable->len;*/
+ *((short *) (ind + offset*act_tuple)) = variable->len;
break;
case ECPGt_int:
case ECPGt_unsigned_int:
- ((int *) ind)[act_tuple] = variable->len;
+/* ((int *) ind)[act_tuple] = variable->len;*/
+ *((int *) (ind + offset*act_tuple)) = variable->len;
break;
case ECPGt_long:
case ECPGt_unsigned_long:
- ((long *) ind)[act_tuple] = variable->len;
+/* ((long *) ind)[act_tuple] = variable->len;*/
+ *((long *) (ind + offset*act_tuple)) = variable->len;
+ break;
+#ifdef HAVE_LONG_LONG_INT_64
+ case ECPGt_long_long:
+ case ECPGt_unsigned_long_long:
+ *((long long int *) (ind + ind_offset*act_tuple)) = variable->len;
break;
+#endif /* HAVE_LONG_LONG_INT_64 */
default:
break;
}
diff --git a/src/interfaces/ecpg/lib/descriptor.c b/src/interfaces/ecpg/lib/descriptor.c
index 533bdcea5a4..66fb6b1d861 100644
--- a/src/interfaces/ecpg/lib/descriptor.c
+++ b/src/interfaces/ecpg/lib/descriptor.c
@@ -1,6 +1,6 @@
/* dynamic SQL support routines
*
- * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/descriptor.c,v 1.19 2001/11/14 11:11:49 meskes Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/descriptor.c,v 1.20 2001/12/23 12:17:41 meskes Exp $
*/
#include "postgres_fe.h"
@@ -374,9 +374,9 @@ ECPGdeallocate_desc(int line, const char *name)
if (!strcmp(name, i->name))
{
*lastptr = i->next;
- free(i->name);
+ ECPGfree(i->name);
PQclear(i->result);
- free(i);
+ ECPGfree(i);
return true;
}
}
diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c
index 56dd42fbed9..e92f8f142ee 100644
--- a/src/interfaces/ecpg/lib/error.c
+++ b/src/interfaces/ecpg/lib/error.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.13 2001/11/14 11:11:49 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.14 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -82,6 +82,11 @@ ECPGraise(int line, int code, const char *str)
"Data read from backend is not an array in line %d.", line);
break;
+ case ECPG_ARRAY_INSERT:
+ snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
+ "Trying to insert an array of variables in line %d.", line);
+ break;
+
case ECPG_NO_CONN:
snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc),
"No such connection %s in line %d.", str, line);
diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c
index d37af5f61f1..c2f1e6bda48 100644
--- a/src/interfaces/ecpg/lib/execute.c
+++ b/src/interfaces/ecpg/lib/execute.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.33 2001/11/21 22:57:01 tgl Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.34 2001/12/23 12:17:41 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
@@ -55,40 +55,6 @@ struct sqlca sqlca =
}
};
-/* keep a list of memory we allocated for the user */
-static struct auto_mem
-{
- void *pointer;
- struct auto_mem *next;
-} *auto_allocs = NULL;
-
-void
-ECPGadd_mem(void *ptr, int lineno)
-{
- struct auto_mem *am = (struct auto_mem *) ECPGalloc(sizeof(struct auto_mem), lineno);
- am->pointer = ptr;
- am->next = auto_allocs;
- auto_allocs = am;
-}
-
-void
-ECPGfree_auto_mem(void)
-{
- struct auto_mem *am;
-
- /* free all memory we have allocated for the user */
- for (am = auto_allocs; am;)
- {
- struct auto_mem *act = am;
-
- am = am->next;
- free(act->pointer);
- free(act);
- }
-
- auto_allocs = NULL;
-}
-
/* This function returns a newly malloced string that has the \
in the argument quoted with \ and the ' quote with ' as SQL92 says.
*/
@@ -182,7 +148,7 @@ create_statement(int lineno, struct connection * connection, struct statement **
if (var->pointer == NULL)
{
ECPGraise(lineno, ECPG_INVALID_STMT, NULL);
- free(var);
+ ECPGfree(var);
return false;
}
@@ -202,7 +168,7 @@ create_statement(int lineno, struct connection * connection, struct statement **
var->ind_offset = va_arg(ap, long);
var->next = NULL;
- if (var->ind_type!=ECPGt_NO_INDICATOR
+ if (var->ind_type != ECPGt_NO_INDICATOR
&& (var->ind_arrsize == 0 || var->ind_varcharsize == 0))
var->ind_value = *((void **) (var->ind_pointer));
else
@@ -230,13 +196,13 @@ free_variable(struct variable * var)
if (var == (struct variable *) NULL)
return;
var_next = var->next;
- free(var);
+ ECPGfree(var);
while (var_next)
{
var = var_next;
var_next = var->next;
- free(var);
+ ECPGfree(var);
}
}
@@ -247,7 +213,7 @@ free_statement(struct statement * stmt)
return;
free_variable(stmt->inlist);
free_variable(stmt->outlist);
- free(stmt);
+ ECPGfree(stmt);
}
static char *
@@ -354,7 +320,7 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
array_query = (char *) ECPGalloc(strlen("select typelem from pg_type where oid=") + 11, stmt->lineno);
sprintf(array_query, "select typelem from pg_type where oid=%d", type);
query = PQexec(stmt->connection->connection, array_query);
- free(array_query);
+ ECPGfree(array_query);
if (PQresultStatus(query) == PGRES_TUPLES_OK)
{
isarray = atol((char *) PQgetvalue(query, 0, 0));
@@ -460,6 +426,7 @@ ECPGstore_result(const PGresult *results, int act_field,
*((void **) var->pointer) = var->value;
ECPGadd_mem(var->value, stmt->lineno);
}
+
/* allocate indicator variable if needed */
if ((var->ind_arrsize == 0 || var->ind_varcharsize == 0) && var->ind_value == NULL && var->ind_pointer!=NULL)
{
@@ -470,7 +437,6 @@ ECPGstore_result(const PGresult *results, int act_field,
}
/* fill the variable with the tuple(s) */
-
if (!var->varcharsize && !var->arrsize &&
(var->type==ECPGt_char || var->type==ECPGt_unsigned_char))
{
@@ -486,7 +452,7 @@ ECPGstore_result(const PGresult *results, int act_field,
int len = strlen(PQgetvalue(results, act_tuple, act_field)) + 1;
if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
var->type, var->ind_type, current_data_location,
- var->ind_value, len, 0, isarray))
+ var->ind_value, len, 0, 0, isarray))
status = false;
else
{
@@ -505,7 +471,7 @@ ECPGstore_result(const PGresult *results, int act_field,
{
if (!ECPGget_data(results, act_tuple, act_field, stmt->lineno,
var->type, var->ind_type, var->value,
- var->ind_value, var->varcharsize, var->offset, isarray))
+ var->ind_value, var->varcharsize, var->offset, var->ind_offset, isarray))
status = false;
}
}
@@ -519,6 +485,16 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
char *mallocedval = NULL;
char *newcopy = NULL;
+ /*
+ * arrays are not possible
+ */
+
+ if (var->arrsize > 1)
+ {
+ ECPGraise(stmt->lineno, ECPG_ARRAY_INSERT, NULL);
+ return false;
+ }
+
/*
* Some special treatment is needed for records since we want their
* contents to arrive in a comma-separated list on insert (I think).
@@ -816,7 +792,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
if (!mallocedval)
return false;
- free(newcopy);
+ ECPGfree(newcopy);
*tobeinserted_p = mallocedval;
*malloced_p = true;
@@ -851,7 +827,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
if (!mallocedval)
return false;
- free(newcopy);
+ ECPGfree(newcopy);
*tobeinserted_p = mallocedval;
*malloced_p = true;
@@ -936,11 +912,11 @@ ECPGexecute(struct statement * stmt)
*/
if (malloced)
{
- free((char *) tobeinserted);
+ ECPGfree((char *) tobeinserted);
tobeinserted = NULL;
}
- free(copiedquery);
+ ECPGfree(copiedquery);
copiedquery = newcopy;
var = var->next;
@@ -968,7 +944,7 @@ ECPGexecute(struct statement * stmt)
ECPGlog("ECPGexecute line %d: QUERY: %s on connection %s\n", stmt->lineno, copiedquery, stmt->connection->name);
results = PQexec(stmt->connection->connection, copiedquery);
- free(copiedquery);
+ ECPGfree(copiedquery);
if (results == NULL)
{
@@ -1091,7 +1067,7 @@ ECPGexecute(struct statement * stmt)
{
ECPGlog("ECPGexecute line %d: ASYNC NOTIFY of '%s' from backend pid '%d' received\n",
stmt->lineno, notify->relname, notify->be_pid);
- free(notify);
+ ECPGfree(notify);
}
return status;
@@ -1114,15 +1090,16 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
if (!ECPGinit(con, connection_name, lineno))
{
setlocale(LC_NUMERIC, oldlocale);
- free(oldlocale);
+ ECPGfree(oldlocale);
return (false);
}
+ /* construct statement in our own structure */
va_start(args, query);
if (create_statement(lineno, con, &stmt, query, args) == false)
{
setlocale(LC_NUMERIC, oldlocale);
- free(oldlocale);
+ ECPGfree(oldlocale);
return (false);
}
va_end(args);
@@ -1133,16 +1110,19 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
free_statement(stmt);
ECPGraise(lineno, ECPG_NOT_CONN, (con) ? con->name : "<empty>");
setlocale(LC_NUMERIC, oldlocale);
- free(oldlocale);
+ ECPGfree(oldlocale);
return false;
}
+ /* initialize auto_mem struct */
+ ECPGclear_auto_mem();
+
status = ECPGexecute(stmt);
free_statement(stmt);
/* and reset locale value so our application is not affected */
setlocale(LC_NUMERIC, oldlocale);
- free(oldlocale);
+ ECPGfree(oldlocale);
return (status);
}
diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h
index 3759751555b..478ec4b99f2 100644
--- a/src/interfaces/ecpg/lib/extern.h
+++ b/src/interfaces/ecpg/lib/extern.h
@@ -6,15 +6,17 @@
void ECPGadd_mem(void *ptr, int lineno);
bool ECPGget_data(const PGresult *, int, int, int, enum ECPGttype type,
- enum ECPGttype, void *, void *, long, long, bool);
+ enum ECPGttype, void *, void *, long, long, long, bool);
struct connection *ECPGget_connection(const char *);
void ECPGinit_sqlca(void);
char *ECPGalloc(long, int);
+void ECPGfree(void *);
bool ECPGinit(const struct connection *, const char *, const int);
char *ECPGstrdup(const char *, int);
const char *ECPGtype_name(enum ECPGttype);
unsigned int ECPGDynamicType(Oid);
-
+void ECPGfree_auto_mem(void);
+void ECPGclear_auto_mem(void);
/* A generic varchar type. */
struct ECPGgeneric_varchar
diff --git a/src/interfaces/ecpg/lib/memory.c b/src/interfaces/ecpg/lib/memory.c
index e1bc12eef3f..5e85261332c 100644
--- a/src/interfaces/ecpg/lib/memory.c
+++ b/src/interfaces/ecpg/lib/memory.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/memory.c,v 1.7 2001/11/14 11:11:49 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/memory.c,v 1.8 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -7,6 +7,12 @@
#include "ecpgerrno.h"
#include "extern.h"
+void
+ECPGfree(void *ptr)
+{
+ free(ptr);
+}
+
char *
ECPGalloc(long size, int lineno)
{
@@ -35,3 +41,54 @@ ECPGstrdup(const char *string, int lineno)
return (new);
}
+
+/* keep a list of memory we allocated for the user */
+static struct auto_mem
+{
+ void *pointer;
+ struct auto_mem *next;
+} *auto_allocs = NULL;
+
+void
+ECPGadd_mem(void *ptr, int lineno)
+{
+ struct auto_mem *am = (struct auto_mem *) ECPGalloc(sizeof(struct auto_mem), lineno);
+ am->pointer = ptr;
+ am->next = auto_allocs;
+ auto_allocs = am;
+}
+
+void
+ECPGfree_auto_mem(void)
+{
+ struct auto_mem *am;
+
+ /* free all memory we have allocated for the user */
+ for (am = auto_allocs; am;)
+ {
+ struct auto_mem *act = am;
+
+ am = am->next;
+ ECPGfree(act->pointer);
+ ECPGfree(act);
+ }
+
+ auto_allocs = NULL;
+}
+
+void
+ECPGclear_auto_mem(void)
+{
+ struct auto_mem *am;
+
+ /* free just our own structure */
+ for (am = auto_allocs; am;)
+ {
+ struct auto_mem *act = am;
+
+ am = am->next;
+ ECPGfree(act);
+ }
+
+ auto_allocs = NULL;
+}
diff --git a/src/interfaces/ecpg/lib/misc.c b/src/interfaces/ecpg/lib/misc.c
index 1a74cf46d30..a3dd727cbd6 100644
--- a/src/interfaces/ecpg/lib/misc.c
+++ b/src/interfaces/ecpg/lib/misc.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/misc.c,v 1.10 2001/11/14 11:11:49 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/misc.c,v 1.11 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -137,6 +137,6 @@ ECPGlog(const char *format,...)
vfprintf(debugstream, f, ap);
va_end(ap);
- free(f);
+ ECPGfree(f);
}
}
diff --git a/src/interfaces/ecpg/lib/prepare.c b/src/interfaces/ecpg/lib/prepare.c
index 4117454835e..740afb5978e 100644
--- a/src/interfaces/ecpg/lib/prepare.c
+++ b/src/interfaces/ecpg/lib/prepare.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/prepare.c,v 1.11 2001/11/14 11:11:49 meskes Exp $ */
+/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/prepare.c,v 1.12 2001/12/23 12:17:41 meskes Exp $ */
#include "postgres_fe.h"
@@ -76,7 +76,7 @@ ECPGprepare(int lineno, char *name, char *variable)
stmt = (struct statement *) ECPGalloc(sizeof(struct statement), lineno);
if (!stmt)
{
- free(this);
+ ECPGfree(this);
return false;
}
@@ -114,15 +114,15 @@ ECPGdeallocate(int lineno, char *name)
if (this)
{
/* okay, free all the resources */
- free(this->name);
- free(this->stmt->command);
- free(this->stmt);
+ ECPGfree(this->name);
+ ECPGfree(this->stmt->command);
+ ECPGfree(this->stmt);
if (prev != NULL)
prev->next = this->next;
else
prep_stmts = this->next;
- free(this);
+ ECPGfree(this);
return true;
}
ECPGraise(lineno, ECPG_INVALID_STMT, name);