diff --git a/src/interfaces/ecpg/ChangeLog b/src/interfaces/ecpg/ChangeLog
index b7b85f91b52620709e92ac6732001cd48cf56a28..1f3bf095e44462a5782535e91d36f5ee5f0be8a4 100644
--- a/src/interfaces/ecpg/ChangeLog
+++ b/src/interfaces/ecpg/ChangeLog
@@ -2215,5 +2215,15 @@ Tue, 12 Jun 2007 09:46:03 +0200
 Wed, 25 Jul 2007 15:34:54 +0200
 
 	- Synced parser.
-	- Set ecpg library version to 5.3.
-	- Set ecpg version to 4.3.1.
+
+Tue, 14 Aug 2007 11:46:51 +0200
+
+	- Finished major rewrite to use new protocol version.
+	- Really prepare statements.
+	- Added more regression tests.
+	- Added auto-prepare mode.
+	- Use '$n' for positional variables, '?' is still possible via ecpg
+	  option.
+	- Cleaned up the sources a little bit.
+	- Set ecpg library version to 6.0.
+	- Set ecpg version to 4.4.
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index cfde8be5aa139ac6eadec3c5b11e113ae4e65ee8..032ccaf89a32104a1399b15e265de3c81ad4d6b2 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.48 2006/10/04 00:30:11 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/informix.c,v 1.49 2007/08/14 10:01:52 meskes Exp $ */
 
 #include <stdlib.h>
 #include <string.h>
@@ -202,10 +202,11 @@ deccvasc(char *cp, int len, decimal *np)
 		}
 		else
 		{
-			if (PGTYPESnumeric_to_decimal(result, np) != 0)
-				ret = ECPG_INFORMIX_NUM_OVERFLOW;
+			int i = PGTYPESnumeric_to_decimal(result, np);
 
 			free(result);
+			if (i != 0)
+				ret = ECPG_INFORMIX_NUM_OVERFLOW;
 		}
 	}
 
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index a64f8fa2699fb18c23c3ea0b325c47f893cc240c..f60207e23c01e77235825dd272147e42aae33bcf 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.46 2007/01/20 17:16:17 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.47 2007/08/14 10:01:52 meskes Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,8 +13,8 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 NAME= ecpg
-SO_MAJOR_VERSION= 5
-SO_MINOR_VERSION= 3
+SO_MAJOR_VERSION= 6
+SO_MINOR_VERSION= 0
 DLTYPE= library
 
 override CPPFLAGS := -DFRONTEND \
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 650c4e503c03007db098647778a3c1a2c9fc49aa..421155bb9230576cb1d9cfaaa22d7b72c72beb30 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.41 2007/03/29 12:02:24 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.42 2007/08/14 10:01:52 meskes Exp $ */
 
 #define POSTGRES_ECPG_INTERNAL
 #include "postgres_fe.h"
@@ -185,11 +185,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
 	{
 		if (con->committed)
 		{
-			if ((results = PQexec(con->connection, "begin transaction")) == NULL)
-			{
-				ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+			results = PQexec(con->connection, "begin transaction");
+			if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
 				return false;
-			}
 			PQclear(results);
 			con->committed = false;
 		}
@@ -199,11 +197,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
 	{
 		if (!con->committed)
 		{
-			if ((results = PQexec(con->connection, "commit")) == NULL)
-			{
-				ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+			results = PQexec(con->connection, "commit");
+			if (!ECPGcheck_PQresult(results, lineno, con->connection, ECPG_COMPAT_PGSQL))
 				return false;
-			}
 			PQclear(results);
 			con->committed = true;
 		}
@@ -249,7 +245,7 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
 	if (strncmp(sqlstate, "00", 2) == 0)
 		return;
 
-	ECPGlog("%s", message);
+	ECPGlog("ECPGnoticeReceiver %s\n", message);
 
 	/* map to SQLCODE for backward compatibility */
 	if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME) == 0)
diff --git a/src/interfaces/ecpg/ecpglib/descriptor.c b/src/interfaces/ecpg/ecpglib/descriptor.c
index 0a4ecf86fc752e04fd47c790fce60cf78f49c104..f70aaa42f885dab98133c6f6d5d694cd8e849ef6 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.22 2007/06/11 11:52:08 meskes Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.23 2007/08/14 10:01:52 meskes Exp $
  */
 
 #define POSTGRES_ECPG_INTERNAL
@@ -495,6 +495,8 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
 		if (!desc_item)
 			return false;
 		desc_item->num = index;
+		if (desc->count < index)
+			desc->count = index;
 		desc_item->next = desc->items;
 		desc->items = desc_item;
 	}
@@ -508,7 +510,6 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
 	{
 		enum ECPGdtype itemtype;
 		const char *tobeinserted = NULL;
-		bool		malloced;
 
 		itemtype = va_arg(args, enum ECPGdtype);
 
@@ -542,11 +543,12 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
 		{
 			case ECPGd_data:
 				{
-					if (!ECPGstore_input(lineno, true, var, &tobeinserted, &malloced, false))
+					if (!ECPGstore_input(lineno, true, var, &tobeinserted, false))
 					{
 						ECPGfree(var);
 						return false;
 					}
+
 					ECPGfree(desc_item->data); /* free() takes care of a potential NULL value */
 					desc_item->data = (char *) tobeinserted;
 					tobeinserted = NULL;
@@ -583,13 +585,7 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
 					return false;
 				}
 		}
-
-		/*
-		 * if (itemtype == ECPGd_data) { free(desc_item->data);
-		 * desc_item->data = NULL; }
-		 */
-	}
-	while (true);
+	} while (true);
 	ECPGfree(var);
 
 	return true;
@@ -598,18 +594,18 @@ ECPGset_desc(int lineno, const char *desc_name, int index,...)
 bool
 ECPGdeallocate_desc(int line, const char *name)
 {
-	struct descriptor *i;
+	struct descriptor *desc;
 	struct descriptor **lastptr = &all_descriptors;
 	struct sqlca_t *sqlca = ECPGget_sqlca();
 
 	ECPGinit_sqlca(sqlca);
-	for (i = all_descriptors; i; lastptr = &i->next, i = i->next)
+	for (desc = all_descriptors; desc; lastptr = &desc->next, desc = desc->next)
 	{
-		if (!strcmp(name, i->name))
+		if (!strcmp(name, desc->name))
 		{
 			struct descriptor_item *desc_item;
 
-			for (desc_item = i->items; desc_item;)
+			for (desc_item = desc->items; desc_item;)
 			{
 				struct descriptor_item *di;
 
@@ -619,10 +615,10 @@ ECPGdeallocate_desc(int line, const char *name)
 				ECPGfree(di);
 			}
 
-			*lastptr = i->next;
-			ECPGfree(i->name);
-			PQclear(i->result);
-			ECPGfree(i);
+			*lastptr = desc->next;
+			ECPGfree(desc->name);
+			PQclear(desc->result);
+			ECPGfree(desc);
 			return true;
 		}
 	}
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index 12d948b3d171e2895cc14c8d350ad0af935fd572..ef15cccb94a023985fa4163968298db8549cbeca 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.16 2007/05/31 15:13:05 petere Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.17 2007/08/14 10:01:52 meskes Exp $ */
 
 #define POSTGRES_ECPG_INTERNAL
 #include "postgres_fe.h"
@@ -9,7 +9,6 @@
 #include "extern.h"
 #include "sqlca.h"
 
-
 void
 ECPGraise(int line, int code, const char *sqlstate, const char *str)
 {
@@ -196,6 +195,59 @@ ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat)
 	ECPGfree_auto_mem();
 }
 
+/* filter out all error codes */
+bool
+ECPGcheck_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat) 
+{
+	if (results == NULL)
+	{
+		ECPGlog("ECPGcheck_PQresult line %d: error: %s", lineno, PQerrorMessage(connection));
+		ECPGraise_backend(lineno, NULL, connection, compat);
+		return (false);
+	}
+
+	switch (PQresultStatus(results))
+	{
+
+		case PGRES_TUPLES_OK:
+			return (true);
+			break;
+		case PGRES_EMPTY_QUERY:
+			/* do nothing */
+			ECPGraise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
+			PQclear(results);
+			return (false);
+			break;
+		case PGRES_COMMAND_OK:
+			return (true);
+			break;
+		case PGRES_NONFATAL_ERROR:
+		case PGRES_FATAL_ERROR:
+		case PGRES_BAD_RESPONSE:
+			ECPGlog("ECPGcheck_PQresult line %d: Error: %s", lineno, PQresultErrorMessage(results));
+			ECPGraise_backend(lineno, results, connection, compat);
+			PQclear(results);
+			return (false);
+			break;
+		case PGRES_COPY_OUT:
+			return(true);
+			break;
+		case PGRES_COPY_IN:
+			ECPGlog("ECPGcheck_PQresult line %d: Got PGRES_COPY_IN ... tossing.\n", lineno);
+			PQendcopy(connection);
+			PQclear(results);
+			return(false);
+			break;
+		default:
+			ECPGlog("ECPGcheck_PQresult line %d: Got something else, postgres error.\n",
+					lineno);
+			ECPGraise_backend(lineno, results, connection, compat);
+			PQclear(results);
+			return(false);
+			break;
+	}
+}
+
 /* print out an error message */
 void
 sqlprint(void)
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 5c3ecf6461f0534c3f21f62ed75f7a13067e974e..4a9f82cc1ac19af2d942e0419cb8b45fc1c2b4a2 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.67 2007/06/11 11:52:08 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.68 2007/08/14 10:01:52 meskes Exp $ */
 
 /*
  * The aim is to get a simpler inteface to the database routines.
@@ -56,7 +56,6 @@ quote_postgres(char *arg, bool quote, int lineno)
 		res = (char *) ECPGalloc(buffer_len + 3, lineno);
 		if (!res)
 			return (res);
-
 		escaped_len = PQescapeString(res+1, arg, buffer_len);
 		if (length == escaped_len)
 		{
@@ -105,24 +104,43 @@ free_statement(struct statement * stmt)
 	free_variable(stmt->inlist);
 	free_variable(stmt->outlist);
 	ECPGfree(stmt->command);
+	ECPGfree(stmt->name);
 	ECPGfree(stmt);
 }
 
-static char *
-next_insert(char *text)
+static int 
+next_insert(char *text, int pos, bool questionmarks)
 {
-	char	   *ptr = text;
 	bool		string = false;
+	int 		p = pos;
 
-	for (; *ptr != '\0' && (*ptr != '?' || string); ptr++)
+	for (; text[p] != '\0'; p++)
 	{
-		if (*ptr == '\\')		/* escape character */
-			ptr++;
-		else if (*ptr == '\'')
+		if (text[p] == '\\')		/* escape character */
+			p++;
+		else if (text[p] == '\'')
 			string = string ? false : true;
+		else if (!string)
+		{
+			if (text[p] == '$' && isdigit(text[p+1]))
+			{
+				/* this can be either a dollar quote or a variable */
+				int i;
+
+				for (i = p + 1; isdigit(text[i]); i++);
+				if (!isalpha(text[i]) && isascii(text[i]) && text[i] != '_')
+					/* not dollar delimeted quote */
+					return p;
+			}
+			else if (questionmarks && text[p] == '?') 
+			{
+				/* also allow old style placeholders */
+				return p;
+			}
+		}
 	}
 
-	return (*ptr == '\0') ? NULL : ptr;
+	return -1;
 }
 
 static bool
@@ -257,7 +275,9 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
 	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);
-	if (PQresultStatus(query) == PGRES_TUPLES_OK)
+	if (!ECPGcheck_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
+		return (ECPG_ARRAY_ERROR);
+	else if (PQresultStatus(query) == PGRES_TUPLES_OK)
 	{
 		if (PQntuples(query) == 0)
 			isarray = ECPG_ARRAY_NONE;
@@ -273,8 +293,11 @@ ECPGis_type_an_array(int type, const struct statement * stmt, const struct varia
 				isarray = ECPG_ARRAY_NONE;
 			}
 		}
+		PQclear(query);
 	}
-	PQclear(query);
+	else
+		return (ECPG_ARRAY_ERROR);
+
 	ECPGtypeinfocache_push(&(stmt->connection->cache_head), type, isarray, stmt->lineno);
 	ECPGlog("ECPGis_type_an_array line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, type, var->type, isarray ? "Yes" : "No");
 	return isarray;
@@ -428,7 +451,7 @@ ECPGstore_result(const PGresult *results, int act_field,
 
 bool
 ECPGstore_input(const int lineno, const bool force_indicator, const struct variable * var,
-				const char **tobeinserted_p, bool *malloced_p, bool quote)
+				const char **tobeinserted_p, bool quote)
 {
 	char	   *mallocedval = NULL;
 	char	   *newcopy = NULL;
@@ -450,7 +473,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 	 * contents to arrive in a comma-separated list on insert (I think).
 	 */
 
-	*malloced_p = false;
 	*tobeinserted_p = "";
 
 	/* check for null value and set input buffer accordingly */
@@ -459,36 +481,36 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 		case ECPGt_short:
 		case ECPGt_unsigned_short:
 			if (*(short *) var->ind_value < 0)
-				*tobeinserted_p = "null";
+				*tobeinserted_p = NULL;
 			break;
 		case ECPGt_int:
 		case ECPGt_unsigned_int:
 			if (*(int *) var->ind_value < 0)
-				*tobeinserted_p = "null";
+				*tobeinserted_p = NULL;
 			break;
 		case ECPGt_long:
 		case ECPGt_unsigned_long:
 			if (*(long *) var->ind_value < 0L)
-				*tobeinserted_p = "null";
+				*tobeinserted_p = NULL;
 			break;
 #ifdef HAVE_LONG_LONG_INT_64
 		case ECPGt_long_long:
 		case ECPGt_unsigned_long_long:
 			if (*(long long int *) var->ind_value < (long long) 0)
-				*tobeinserted_p = "null";
+				*tobeinserted_p = NULL;
 			break;
 #endif   /* HAVE_LONG_LONG_INT_64 */
 		case ECPGt_NO_INDICATOR:
 			if (force_indicator == false)
 			{
 				if (ECPGis_noind_null(var->type, var->value))
-					*tobeinserted_p = "null";
+					*tobeinserted_p = NULL;
 			}
 			break;
 		default:
 			break;
 	}
-	if (**tobeinserted_p == '\0')
+	if (*tobeinserted_p != NULL)
 	{
 		int			asize = var->arrsize ? var->arrsize : 1;
 
@@ -513,7 +535,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%hd", *((short *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_int:
@@ -522,18 +543,17 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 
 				if (asize > 1)
 				{
-					strcpy(mallocedval, "array [");
+					strcpy(mallocedval, "{");
 
 					for (element = 0; element < asize; 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));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_unsigned_short:
@@ -553,7 +573,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%hu", *((unsigned short *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_unsigned_int:
@@ -573,7 +592,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%u", *((unsigned int *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_long:
@@ -593,7 +611,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%ld", *((long *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_unsigned_long:
@@ -613,7 +630,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%lu", *((unsigned long *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 #ifdef HAVE_LONG_LONG_INT_64
 			case ECPGt_long_long:
@@ -633,7 +649,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%lld", *((long long *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_unsigned_long_long:
@@ -653,7 +668,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%llu", *((unsigned long long *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 #endif   /* HAVE_LONG_LONG_INT_64 */
 			case ECPGt_float:
@@ -673,7 +687,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%.14g", *((float *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_double:
@@ -693,7 +706,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					sprintf(mallocedval, "%.14g", *((double *) var->value));
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_bool:
@@ -722,15 +734,14 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 				else
 				{
 					if (var->offset == sizeof(char))
-						sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f');
+						sprintf(mallocedval, "%c", (*((char *) var->value)) ? 't' : 'f');
 					else if (var->offset == sizeof(int))
-						sprintf(mallocedval, "'%c'", (*((int *) var->value)) ? 't' : 'f');
+						sprintf(mallocedval, "%c", (*((int *) var->value)) ? 't' : 'f');
 					else
 						ECPGraise(lineno, ECPG_CONVERT_BOOL, ECPG_SQLSTATE_DATATYPE_MISMATCH, "different size");
 				}
 
 				*tobeinserted_p = mallocedval;
-				*malloced_p = true;
 				break;
 
 			case ECPGt_char:
@@ -750,7 +761,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 						return false;
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 			case ECPGt_const:
@@ -765,7 +775,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					mallocedval[slen] = '\0';
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 			case ECPGt_varchar:
@@ -784,7 +793,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 						return false;
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 
@@ -854,7 +862,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 					}
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 
@@ -881,7 +888,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							if (!element)
 								strcpy(mallocedval, "array [");
 
-							strcpy(mallocedval + strlen(mallocedval), "interval ");
 							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 							strcpy(mallocedval + strlen(mallocedval), ",");
 							ECPGfree(str);
@@ -901,14 +907,12 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							return false;
 						}
 
-						strcpy(mallocedval, "interval ");
 						/* also copy trailing '\0' */
 						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 						ECPGfree(str);
 					}
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 
@@ -935,7 +939,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							if (!element)
 								strcpy(mallocedval, "array [");
 
-							strcpy(mallocedval + strlen(mallocedval), "date ");
 							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 							strcpy(mallocedval + strlen(mallocedval), ",");
 							ECPGfree(str);
@@ -955,14 +958,12 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							return false;
 						}
 
-						strcpy(mallocedval, "date ");
 						/* also copy trailing '\0' */
 						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 						ECPGfree(str);
 					}
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 
@@ -990,7 +991,6 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							if (!element)
 								strcpy(mallocedval, "array [");
 
-							strcpy(mallocedval + strlen(mallocedval), "timestamp ");
 							strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 							strcpy(mallocedval + strlen(mallocedval), ",");
 							ECPGfree(str);
@@ -1010,14 +1010,12 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 							return false;
 						}
 
-						strcpy(mallocedval, "timestamp ");
 						/* also copy trailing '\0' */
 						strncpy(mallocedval + strlen(mallocedval), str, slen + 1);
 						ECPGfree(str);
 					}
 
 					*tobeinserted_p = mallocedval;
-					*malloced_p = true;
 				}
 				break;
 
@@ -1034,33 +1032,45 @@ ECPGstore_input(const int lineno, const bool force_indicator, const struct varia
 	return true;
 }
 
+static void
+free_params(const char **paramValues, int nParams, bool print, int lineno)
+{
+	int n;
+
+	for (n = 0; n < nParams; n++)
+	{
+		if (print)
+			ECPGlog("ECPGexecute line %d: parameter %d = %s\n", lineno, n + 1, paramValues[n] ? paramValues[n] : "null");
+		ECPGfree((void *)(paramValues[n]));
+	}
+	ECPGfree(paramValues);
+}
+
 static bool
 ECPGexecute(struct statement * stmt)
 {
 	bool		status = false;
-	char	   *copiedquery;
 	char	   *cmdstat;
 	PGresult   *results;
 	PGnotify   *notify;
 	struct variable *var;
 	int			desc_counter = 0;
-
-	copiedquery = ECPGstrdup(stmt->command, stmt->lineno);
+	const char * *paramValues = NULL;
+	int nParams = 0;
+	int position = 0;
+	struct sqlca_t *sqlca = ECPGget_sqlca();
+	bool			clear_result = true;
 
 	/*
-	 * Now, if the type is one of the fill in types then we take the argument
-	 * and enter that in the string at the first %s position. Then if there
-	 * are any more fill in types we fill in at the next and so on.
+	 * If the type is one of the fill in types then we take the argument
+	 * and enter it to our parameter array at the first position. Then if there
+	 * are any more fill in types we add more parameters.
 	 */
 	var = stmt->inlist;
-
 	while (var)
 	{
-		char	   *newcopy = NULL;
 		const char *tobeinserted;
-		char	   *p;
-		bool		malloced = FALSE;
-		int			hostvarl = 0;
+		int counter = 1;
 
 		tobeinserted = NULL;
 
@@ -1087,75 +1097,131 @@ ECPGexecute(struct statement * stmt)
 			if (desc == NULL)
 			{
 				ECPGraise(stmt->lineno, ECPG_UNKNOWN_DESCRIPTOR, ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME, var->pointer);
-				ECPGfree(copiedquery);
 				return false;
 			}
 
 			desc_counter++;
-			if (desc->count < 0 || desc->count >= desc_counter)
+			for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
 			{
-				for (desc_item = desc->items; desc_item; desc_item = desc_item->next)
+				if (desc_item->num == desc_counter)
 				{
-					if (desc_item->num == desc_counter)
+					desc_inlist.type = ECPGt_char;
+					desc_inlist.value = desc_item->data;
+					desc_inlist.pointer = &(desc_item->data);
+					desc_inlist.varcharsize = strlen(desc_item->data);
+					desc_inlist.arrsize = 1;
+					desc_inlist.offset = 0;
+					if (!desc_item->indicator)
 					{
-						desc_inlist.type = ECPGt_char;
-						desc_inlist.value = desc_item->data;
-						desc_inlist.pointer = &(desc_item->data);
-						desc_inlist.varcharsize = strlen(desc_item->data);
-						desc_inlist.arrsize = 1;
-						desc_inlist.offset = 0;
-						if (!desc_item->indicator)
-						{
-							desc_inlist.ind_type = ECPGt_NO_INDICATOR;
-							desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
-							desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
-						}
-						else
-						{
-							desc_inlist.ind_type = ECPGt_int;
-							desc_inlist.ind_value = &(desc_item->indicator);
-							desc_inlist.ind_pointer = &(desc_inlist.ind_value);
-							desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
-							desc_inlist.ind_offset = 0;
-						}
-						if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, &malloced, true))
-						{
-							ECPGfree(copiedquery);
-							return false;
-						}
-
-						break;
+						desc_inlist.ind_type = ECPGt_NO_INDICATOR;
+						desc_inlist.ind_value = desc_inlist.ind_pointer = NULL;
+						desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = desc_inlist.ind_offset = 0;
 					}
-				}
+					else
+					{
+						desc_inlist.ind_type = ECPGt_int;
+						desc_inlist.ind_value = &(desc_item->indicator);
+						desc_inlist.ind_pointer = &(desc_inlist.ind_value);
+						desc_inlist.ind_varcharsize = desc_inlist.ind_arrsize = 1;
+						desc_inlist.ind_offset = 0;
+					}
+					if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, &desc_inlist, &tobeinserted, false))
+						return false;
 
-				if (!desc_item) /* no more entries found in descriptor */
-					desc_counter = 0;
+					break;
+				}
 			}
-			else
+			if (desc->count == desc_counter)
 				desc_counter = 0;
 		}
 		else
 		{
-			if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, &malloced, true))
+			if (!ECPGstore_input(stmt->lineno, stmt->force_indicator, var, &tobeinserted, false))
 				return false;
 		}
 
-		if (tobeinserted)
+		/*
+		 * now tobeinserted points to an area that contains the next parameter
+		 * if var->type=ECPGt_char_variable we have a dynamic cursor 
+		 * we have to simulate a dynamic cursor because there is no backend functionality for it
+		 */
+		if (var->type != ECPGt_char_variable)
 		{
-			/*
-			 * Now tobeinserted points to an area that is to be inserted at
-			 * the first %s
-			 */
-			if (!(newcopy = (char *) ECPGalloc(strlen(copiedquery)
+			nParams++;
+			if (!(paramValues = (const char **) ECPGrealloc(paramValues, sizeof(const char *) * nParams, stmt->lineno)))
+			{
+				ECPGfree(paramValues);
+				return false;
+			}
+
+			paramValues[nParams - 1] = tobeinserted;
+
+			if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
+			{
+				/*
+				 * We have an argument but we dont have the matched up
+				 * placeholder in the string
+				 */
+				ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
+						ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
+						  NULL);
+				free_params(paramValues, nParams, false, stmt->lineno);
+				return false;
+			}
+			
+			/* let's see if this was an old style placeholder */
+			if (stmt->command[position-1] == '?')
+			{
+				/* yes, replace with new style */
+				int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */
+				char *buffer, *newcopy;
+
+				if (!(buffer = (char *) ECPGalloc(buffersize, stmt->lineno)))
+				{
+					free_params(paramValues, nParams, false, stmt->lineno);
+					return false;
+				}
+
+				snprintf(buffer, buffersize, "$%d", counter++);
+
+				if (!(newcopy = (char *) ECPGalloc(strlen(stmt->command) + strlen(buffer) + 1, stmt->lineno)))
+				{
+					free_params(paramValues, nParams, false, stmt->lineno);
+					ECPGfree(buffer);
+					return false;
+				}
+
+				strcpy(newcopy, stmt->command);
+
+				/* set positional parameter */
+				strcpy(newcopy + position - 1, buffer);
+
+				/*
+				 * The strange thing in the second argument is the rest of the
+				 * string from the old string
+				 */
+				strcat(newcopy,
+					   stmt->command
+					   + position + 1);
+				ECPGfree(buffer);
+				ECPGfree(stmt->command);
+				stmt->command = newcopy;
+			}
+		}
+		else
+		{
+			char *newcopy;
+
+			if (!(newcopy = (char *) ECPGalloc(strlen(stmt->command)
 											   + strlen(tobeinserted)
 											   + 1, stmt->lineno)))
 			{
-				ECPGfree(copiedquery);
+				free_params(paramValues, nParams, false, stmt->lineno);
 				return false;
 			}
 
-			strcpy(newcopy, copiedquery);
-			if ((p = next_insert(newcopy + hostvarl)) == NULL)
+			strcpy(newcopy, stmt->command);
+			if ((position = next_insert(stmt->command, position, stmt->questionmarks) + 1) == 0)
 			{
 				/*
 				 * We have an argument but we dont have the matched up string
@@ -1164,38 +1230,31 @@ ECPGexecute(struct statement * stmt)
 				ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS,
 						ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS,
 						  NULL);
-				ECPGfree(copiedquery);
+				free_params(paramValues, nParams, false, stmt->lineno);
 				ECPGfree(newcopy);
 				return false;
 			}
 			else
 			{
-				strcpy(p, tobeinserted);
-				hostvarl = strlen(newcopy);
+				int ph_len = (stmt->command[position] == '?') ? strlen("?") : strlen("$1");
+
+				strcpy(newcopy + position - 1, tobeinserted);
 
 				/*
 				 * The strange thing in the second argument is the rest of the
 				 * string from the old string
 				 */
 				strcat(newcopy,
-					   copiedquery
-					   + (p - newcopy)
-					   + sizeof("?") - 1 /* don't count the '\0' */ );
-			}
-
-			/*
-			 * Now everything is safely copied to the newcopy. Lets free the
-			 * oldcopy and let the copiedquery get the var->value from the
-			 * newcopy.
-			 */
-			if (malloced)
-			{
-				ECPGfree((char *) tobeinserted);
-				tobeinserted = NULL;
+					   stmt->command
+					   + position 
+					   + ph_len - 1);
 			}
 
-			ECPGfree(copiedquery);
-			copiedquery = newcopy;
+			ECPGfree(stmt->command);
+			stmt->command = newcopy;
+			
+			ECPGfree((char *)tobeinserted);
+			tobeinserted = NULL;
 		}
 
 		if (desc_counter == 0)
@@ -1203,171 +1262,161 @@ ECPGexecute(struct statement * stmt)
 	}
 
 	/* Check if there are unmatched things left. */
-	if (next_insert(copiedquery) != NULL)
+	if (next_insert(stmt->command, position, stmt->questionmarks) >= 0)
 	{
 		ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS,
 				  ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS, NULL);
-		ECPGfree(copiedquery);
+		free_params(paramValues, nParams, false, stmt->lineno);
 		return false;
 	}
 
-	/* Now the request is built. */
+	/* The request has been build. */
 
 	if (stmt->connection->committed && !stmt->connection->autocommit)
 	{
-		if ((results = PQexec(stmt->connection->connection, "begin transaction")) == NULL)
+		results = PQexec(stmt->connection->connection, "begin transaction");
+		if (!ECPGcheck_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
 		{
-			ECPGraise(stmt->lineno, ECPG_TRANS,
-					  ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
-			ECPGfree(copiedquery);
+			free_params(paramValues, nParams, false, stmt->lineno);
 			return false;
 		}
 		PQclear(results);
 		stmt->connection->committed = false;
 	}
 
-	ECPGlog("ECPGexecute line %d: QUERY: %s on connection %s\n", stmt->lineno, copiedquery, stmt->connection->name);
-	results = PQexec(stmt->connection->connection, copiedquery);
-	ECPGfree(copiedquery);
-
-	if (results == NULL)
+	ECPGlog("ECPGexecute line %d: QUERY: %s with %d parameter on connection %s \n", stmt->lineno, stmt->command, nParams, stmt->connection->name);
+	if (stmt->statement_type == ECPGst_execute)
 	{
-		ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno, PQerrorMessage(stmt->connection->connection));
-		ECPGraise_backend(stmt->lineno, NULL, stmt->connection->connection, stmt->compat);
+		results = PQexecPrepared(stmt->connection->connection, stmt->name, nParams, paramValues, NULL, NULL, 0);
+		ECPGlog("ECPGexecute line %d: using PQexecPrepared for %s\n", stmt->lineno, stmt->command);
 	}
 	else
+	{
+		if (nParams == 0)
+		{
+			results = PQexec(stmt->connection->connection, stmt->command);
+			ECPGlog("ECPGexecute line %d: using PQexec\n", stmt->lineno);
+		}
+		else
+		{
+			results = PQexecParams(stmt->connection->connection, stmt->command, nParams, NULL, paramValues, NULL, NULL, 0);
+			ECPGlog("ECPGexecute line %d: using PQexecParams \n", stmt->lineno);
+		}
+	}
 
-		/*
-		 * note: since some of the following code is duplicated in
-		 * descriptor.c it should go into a separate function
-		 */
+	free_params(paramValues, nParams, true, stmt->lineno);
+
+	if (!ECPGcheck_PQresult(results, stmt->lineno, stmt->connection->connection, stmt->compat))
+		return (false);
+
+	var = stmt->outlist;
+	switch (PQresultStatus(results))
 	{
-		bool		clear_result = TRUE;
-		struct sqlca_t *sqlca = ECPGget_sqlca();
+		int			nfields,
+					ntuples,
+					act_field;
 
-		var = stmt->outlist;
-		switch (PQresultStatus(results))
-		{
-				int			nfields,
-							ntuples,
-							act_field;
+		case PGRES_TUPLES_OK:
+			nfields = PQnfields(results);
+			sqlca->sqlerrd[2] = ntuples = PQntuples(results);
+			ECPGlog("ECPGexecute line %d: Correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
+			status = true;
 
-			case PGRES_TUPLES_OK:
-				nfields = PQnfields(results);
-				sqlca->sqlerrd[2] = ntuples = PQntuples(results);
-				ECPGlog("ECPGexecute line %d: Correctly got %d tuples with %d fields\n", stmt->lineno, ntuples, nfields);
-				status = true;
+			if (ntuples < 1)
+			{
+				if (ntuples)
+					ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
+							stmt->lineno, ntuples);
+				ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
+				status = false;
+				break;
+			}
 
-				if (ntuples < 1)
-				{
-					if (ntuples)
-						ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d\n",
-								stmt->lineno, ntuples);
-					ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
+			if (var != NULL && var->type == ECPGt_descriptor)
+			{
+				PGresult  **resultpp = ECPGdescriptor_lvalue(stmt->lineno, (const char *) var->pointer);
+
+				if (resultpp == NULL)
 					status = false;
-					break;
+				else
+				{
+					if (*resultpp)
+						PQclear(*resultpp);
+					*resultpp = results;
+					clear_result = FALSE;
+					ECPGlog("ECPGexecute putting result (%d tuples) into descriptor '%s'\n", PQntuples(results), (const char *) var->pointer);
 				}
-
-				if (var != NULL && var->type == ECPGt_descriptor)
+				var = var->next;
+			}
+			else
+				for (act_field = 0; act_field < nfields && status; act_field++)
 				{
-					PGresult  **resultpp = ECPGdescriptor_lvalue(stmt->lineno, (const char *) var->pointer);
-
-					if (resultpp == NULL)
-						status = false;
-					else
+					if (var != NULL)
 					{
-						if (*resultpp)
-							PQclear(*resultpp);
-						*resultpp = results;
-						clear_result = FALSE;
-						ECPGlog("ECPGexecute putting result (%d tuples) into descriptor '%s'\n", PQntuples(results), (const char *) var->pointer);
+						status = ECPGstore_result(results, act_field, stmt, var);
+						var = var->next;
 					}
-					var = var->next;
-				}
-				else
-					for (act_field = 0; act_field < nfields && status; act_field++)
+					else if (!INFORMIX_MODE(stmt->compat))
 					{
-						if (var != NULL)
-						{
-							status = ECPGstore_result(results, act_field, stmt, var);
-							var = var->next;
-						}
-						else if (!INFORMIX_MODE(stmt->compat))
-						{
-							ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
-							return (false);
-						}
+						ECPGraise(stmt->lineno, ECPG_TOO_FEW_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
+						return (false);
 					}
-
-				if (status && var != NULL)
-				{
-					ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
-					status = false;
 				}
 
-				break;
-			case PGRES_EMPTY_QUERY:
-				/* do nothing */
-				ECPGraise(stmt->lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
-				break;
-			case PGRES_COMMAND_OK:
-				status = true;
-				cmdstat = PQcmdStatus(results);
-				sqlca->sqlerrd[1] = PQoidValue(results);
-				sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
-				ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
-				if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
-					!sqlca->sqlerrd[2] &&
-					(!strncmp(cmdstat, "UPDATE", 6)
-					 || !strncmp(cmdstat, "INSERT", 6)
-					 || !strncmp(cmdstat, "DELETE", 6)))
-					ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
-				break;
-			case PGRES_NONFATAL_ERROR:
-			case PGRES_FATAL_ERROR:
-			case PGRES_BAD_RESPONSE:
-				ECPGlog("ECPGexecute line %d: Error: %s", stmt->lineno, PQresultErrorMessage(results));
-				ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
+			if (status && var != NULL)
+			{
+				ECPGraise(stmt->lineno, ECPG_TOO_MANY_ARGUMENTS, ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS, NULL);
 				status = false;
-				break;
-			case PGRES_COPY_OUT:
-				{
-					char	   *buffer;
-					int			res;
+			}
 
-					ECPGlog("ECPGexecute line %d: Got PGRES_COPY_OUT\n", stmt->lineno);
-					while ((res = PQgetCopyData(stmt->connection->connection,
-												&buffer, 0)) > 0)
-					{
-						printf("%s", buffer);
-						PQfreemem(buffer);
-					}
-					if (res == -1)
-					{
-						/* COPY done */
-						PQclear(results);
-						results = PQgetResult(stmt->connection->connection);
-						if (PQresultStatus(results) == PGRES_COMMAND_OK)
-							ECPGlog("ECPGexecute line %d: Got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
-						else
-							ECPGlog("ECPGexecute line %d: Got error after PGRES_COPY_OUT: %s", PQresultErrorMessage(results));
-					}
-					break;
+			break;
+		case PGRES_COMMAND_OK:
+			status = true;
+			cmdstat = PQcmdStatus(results);
+			sqlca->sqlerrd[1] = PQoidValue(results);
+			sqlca->sqlerrd[2] = atol(PQcmdTuples(results));
+			ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
+			if (stmt->compat != ECPG_COMPAT_INFORMIX_SE &&
+				!sqlca->sqlerrd[2] &&
+				(!strncmp(cmdstat, "UPDATE", 6)
+				 || !strncmp(cmdstat, "INSERT", 6)
+				 || !strncmp(cmdstat, "DELETE", 6)))
+				ECPGraise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
+			break;
+		case PGRES_COPY_OUT:
+			{
+				char	   *buffer;
+				int			res;
+
+				ECPGlog("ECPGexecute line %d: Got PGRES_COPY_OUT\n", stmt->lineno);
+				while ((res = PQgetCopyData(stmt->connection->connection,
+											&buffer, 0)) > 0)
+				{
+					printf("%s", buffer);
+					PQfreemem(buffer);
+				}
+				if (res == -1)
+				{
+					/* COPY done */
+					PQclear(results);
+					results = PQgetResult(stmt->connection->connection);
+					if (PQresultStatus(results) == PGRES_COMMAND_OK)
+						ECPGlog("ECPGexecute line %d: Got PGRES_COMMAND_OK after PGRES_COPY_OUT\n", stmt->lineno);
+					else
+						ECPGlog("ECPGexecute line %d: Got error after PGRES_COPY_OUT: %s", PQresultErrorMessage(results));
 				}
-			case PGRES_COPY_IN:
-				ECPGlog("ECPGexecute line %d: Got PGRES_COPY_IN ... tossing.\n", stmt->lineno);
-				PQendcopy(stmt->connection->connection);
-				break;
-			default:
-				ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
-						stmt->lineno);
-				ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
-				status = false;
 				break;
-		}
-		if (clear_result)
-			PQclear(results);
+			}
+		default:
+			/* execution should never reach this code because it is already handled in ECPGcheck_PQresult() */
+			ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
+					stmt->lineno);
+			ECPGraise_backend(stmt->lineno, results, stmt->connection->connection, stmt->compat);
+			status = false;
+			break;
 	}
+	if (clear_result)
+		PQclear(results);
 
 	/* check for asynchronous returns */
 	notify = PQnotifies(stmt->connection->connection);
@@ -1382,7 +1431,7 @@ ECPGexecute(struct statement * stmt)
 }
 
 bool
-ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name, const char *query,...)
+ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const enum ECPG_statement_type st, const char *query,...)
 {
 	va_list		args;
 	struct statement *stmt;
@@ -1391,6 +1440,14 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name,
 	char	   *oldlocale;
 	enum ECPGttype type;
 	struct variable **list;
+	enum ECPG_statement_type statement_type = st;
+	char *prepname;
+
+	if (!query)
+	{
+		ECPGraise(lineno, ECPG_EMPTY, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, NULL);
+		return(false);
+	}
 
 	/* Make sure we do NOT honor the locale for numeric input/output */
 	/* since the database wants the standard decimal point */
@@ -1435,15 +1492,47 @@ ECPGdo(int lineno, int compat, int force_indicator, const char *connection_name,
 	{
 		setlocale(LC_NUMERIC, oldlocale);
 		ECPGfree(oldlocale);
+		ECPGfree(prepname);
 		va_end(args);
 		return false;
 	}
 
-	stmt->command = ECPGstrdup(query, lineno);
+	/* If statement type is ECPGst_prepnormal we are supposed to prepare
+	 * the statement before executing them */
+	if (statement_type == ECPGst_prepnormal)
+	{
+		if (!ECPGauto_prepare(lineno, connection_name, questionmarks, &prepname, query))
+			return(false);
+
+		/* statement is now prepared, so instead of the query we have to execute the name */
+		stmt->command = prepname;
+		statement_type = ECPGst_execute;
+	}
+	else
+		stmt->command = ECPGstrdup(query, lineno);
+
+	stmt->name = NULL;
+
+	if (statement_type == ECPGst_execute)
+	{
+		/* if we have an EXECUTE command, only the name is send */
+		char *command = ECPGprepared(stmt->command, lineno);
+
+		if (command)
+		{
+			stmt->name = stmt->command;
+			stmt->command = ECPGstrdup(command, lineno);
+		}
+		else
+			ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, stmt->command);
+	}
+
 	stmt->connection = con;
 	stmt->lineno = lineno;
 	stmt->compat = compat;
 	stmt->force_indicator = force_indicator;
+	stmt->questionmarks = questionmarks;
+	stmt->statement_type = statement_type;
 
 	list = &(stmt->inlist);
 
@@ -1564,7 +1653,7 @@ bool
 ECPGdo_descriptor(int line, const char *connection,
 				  const char *descriptor, const char *query)
 {
-	return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, (char *) query, ECPGt_EOIT,
+	return ECPGdo(line, ECPG_COMPAT_PGSQL, true, connection, '\0', 0, (char *) query, ECPGt_EOIT,
 				  ECPGt_descriptor, descriptor, 0L, 0L, 0L,
 				  ECPGt_NO_INDICATOR, NULL, 0L, 0L, 0L, ECPGt_EORT);
 }
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index a28e6bff0431959e9c99d24f0238fc7e4dbd561a..7c69e98148de9f863c21a810e58fad8a5779d4cc 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.24 2007/04/27 07:55:14 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/extern.h,v 1.25 2007/08/14 10:01:52 meskes Exp $ */
 
 #ifndef _ECPG_LIB_EXTERN_H
 #define _ECPG_LIB_EXTERN_H
@@ -70,9 +70,12 @@ struct statement
 {
 	int			lineno;
 	char	   *command;
+	char	   *name;
 	struct connection *connection;
 	enum COMPAT_MODE compat;
 	bool		force_indicator;
+	enum ECPG_statement_type statement_type;
+	bool	questionmarks;
 	struct variable *inlist;
 	struct variable *outlist;
 };
@@ -133,7 +136,12 @@ PGresult  **ECPGdescriptor_lvalue(int line, const char *descriptor);
 
 bool ECPGstore_result(const PGresult *results, int act_field,
 				 const struct statement * stmt, struct variable * var);
-bool		ECPGstore_input(const int, const bool, const struct variable *, const char **, bool *, bool);
+bool		ECPGstore_input(const int, const bool, const struct variable *, const char **, bool);
+
+bool ECPGcheck_PQresult(PGresult *, int, PGconn *, enum COMPAT_MODE);
+void ECPGraise(int line, int code, const char *sqlstate, const char *str);
+void ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat);
+char *ECPGprepared(const char *, int);
 
 /* SQLSTATE values generated or processed by ecpglib (intentionally
  * not exported -- users should refer to the codes directly) */
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 47d924fac86160df0e6e8aec58fe3b3afa2d54b0..1da37ec5f77894f1a627ed3abbaf9ad27ab3d87b 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.35 2007/03/29 12:02:24 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.36 2007/08/14 10:01:52 meskes Exp $ */
 
 #define POSTGRES_ECPG_INTERNAL
 #include "postgres_fe.h"
@@ -213,20 +213,14 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
 		if (con->committed && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
 		{
 			res = PQexec(con->connection, "begin transaction");
-			if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK)
-			{
-				ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+			if (!ECPGcheck_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
 				return FALSE;
-			}
 			PQclear(res);
 		}
 
 		res = PQexec(con->connection, transaction);
-		if (res == NULL || PQresultStatus(res) != PGRES_COMMAND_OK)
-		{
-			ECPGraise(lineno, ECPG_TRANS, ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN, NULL);
+		if (!ECPGcheck_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
 			return FALSE;
-		}
 		PQclear(res);
 	}
 
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index f1a9db0729ff593ce2113e113ba4510918c71103..bad7b359b45dffe77aaa1fd0762f8ae3f0f38a78 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.18 2006/10/04 00:30:11 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/prepare.c,v 1.19 2007/08/14 10:01:52 meskes Exp $ */
 
 #define POSTGRES_ECPG_INTERNAL
 #include "postgres_fe.h"
@@ -13,11 +13,28 @@
 
 static struct prepared_statement
 {
-	char	   *name;
+	char	*name;
+	bool	prepared;
 	struct statement *stmt;
 	struct prepared_statement *next;
 }	*prep_stmts = NULL;
 
+#define STMTID_SIZE 32
+
+typedef struct 
+{
+    int         lineno;
+    char        stmtID[STMTID_SIZE];
+    char        *ecpgQuery;
+    long        execs;                  /* # of executions      */
+    char        *connection;            /* connection for the statement     */
+} stmtCacheEntry;
+
+static int             nextStmtID               = 1;
+static int             stmtCacheNBuckets        = 2039;     /* # buckets - a prime # */
+static int             stmtCacheEntPerBucket    = 8;        /* # entries/bucket     */
+static stmtCacheEntry  stmtCacheEntries[16384] = {{0,{0},0,0,0}};
+
 static bool
 isvarchar(unsigned char c)
 {
@@ -33,43 +50,68 @@ isvarchar(unsigned char c)
 	return (false);
 }
 
-static void
-replace_variables(char *text)
+static bool
+replace_variables(char **text, int lineno, bool questionmarks)
 {
-	char	   *ptr = text;
-	bool		string = false;
+	bool	string = false;
+	int 	counter = 1, ptr = 0;
 
-	for (; *ptr != '\0'; ptr++)
+	for (; (*text)[ptr] != '\0'; ptr++)
 	{
-		if (*ptr == '\'')
+		if ((*text)[ptr] == '\'')
 			string = string ? false : true;
 
-		if (!string && *ptr == ':')
+		if (string || (((*text)[ptr] != ':') && ((*text)[ptr] != '?')))
+			continue;
+
+		if (((*text)[ptr] == ':') && ((*text)[ptr+1] == ':')) 
+			ptr += 2;		/* skip  '::' */
+		else
 		{
-			if (ptr[1] == ':')
-				ptr += 2;		/* skip  '::' */
-			else
+			int len;
+			int buffersize = sizeof(int) * CHAR_BIT * 10 / 3; /* a rough guess of the size we need */
+			char *buffer, *newcopy;
+
+			if (!(buffer = (char *) ECPGalloc(buffersize, lineno)))
+				return false;
+
+			snprintf(buffer, buffersize, "$%d", counter++);
+
+			for (len=1; (*text)[ptr+len] && isvarchar((*text)[ptr+len]); len++);
+			if (!(newcopy = (char *) ECPGalloc(strlen(*text) - len + strlen(buffer) + 1, lineno)))
 			{
-				*ptr = '?';
-				for (++ptr; *ptr && isvarchar(*ptr); ptr++)
-					*ptr = ' ';
-				if (*ptr == '\0')		/* we reached the end */
-					ptr--;		/* since we will ptr++ in the top level for
-								 * loop */
+				ECPGfree(buffer);
+				return false;
 			}
+
+			strncpy(newcopy, *text, ptr);
+			strcpy(newcopy + ptr, buffer);
+			strcat(newcopy, (*text) + ptr + len);
+
+			ECPGfree(*text);
+			ECPGfree(buffer);
+
+			*text = newcopy;
+
+			if ((*text)[ptr] == '\0')		/* we reached the end */
+				ptr--;		/* since we will (*text)[ptr]++ in the top level for
+							 * loop */
 		}
 	}
+	return true;
 }
 
 /* handle the EXEC SQL PREPARE statement */
 bool
-ECPGprepare(int lineno, const char *name, const char *variable)
+ECPGprepare(int lineno, const char *connection_name, const int questionmarks, const char *name, const char *variable)
 {
 	struct statement *stmt;
 	struct prepared_statement *this;
 	struct sqlca_t *sqlca = ECPGget_sqlca();
+	PGresult   *query;
 
 	ECPGinit_sqlca(sqlca);
+
 	/* check if we already have prepared this statement */
 	for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
 	if (this)
@@ -93,18 +135,30 @@ ECPGprepare(int lineno, const char *name, const char *variable)
 
 	/* create statement */
 	stmt->lineno = lineno;
-	stmt->connection = NULL;
+	stmt->connection = ECPGget_connection(connection_name);
 	stmt->command = ECPGstrdup(variable, lineno);
 	stmt->inlist = stmt->outlist = NULL;
 
 	/* if we have C variables in our statment replace them with '?' */
-	replace_variables(stmt->command);
+	replace_variables(&(stmt->command), lineno, questionmarks);
 
 	/* add prepared statement to our list */
-	this->name = ECPGstrdup(name, lineno);
+	this->name = (char *) name;
 	this->stmt = stmt;
-	ECPGlog("ECPGprepare line %d: QUERY: %s\n", stmt->lineno, stmt->command);
 
+	/* and finally really prepare the statement */
+	query = PQprepare(stmt->connection->connection, name, stmt->command, 0, NULL);
+	if (!ECPGcheck_PQresult(query, stmt->lineno, stmt->connection->connection, stmt->compat))
+	{
+		ECPGfree(stmt->command);
+		ECPGfree(this);
+		ECPGfree(stmt);
+		return false;
+	}
+
+	ECPGlog("ECPGprepare line %d: NAME: %s QUERY: %s\n", stmt->lineno, name, stmt->command);
+	PQclear(query);
+	this->prepared = true;
 
 	if (prep_stmts == NULL)
 		this->next = NULL;
@@ -115,30 +169,8 @@ ECPGprepare(int lineno, const char *name, const char *variable)
 	return true;
 }
 
-/* handle the EXEC SQL DEALLOCATE PREPARE statement */
-bool
-ECPGdeallocate(int lineno, int c, const char *name)
-{
-	bool		ret = ECPGdeallocate_one(lineno, name);
-	enum COMPAT_MODE compat = c;
-
-	if (INFORMIX_MODE(compat))
-	{
-		/*
-		 * Just ignore all errors since we do not know the list of cursors we
-		 * are allowed to free. We have to trust the software.
-		 */
-		return true;
-	}
-
-	if (!ret)
-		ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, name);
-
-	return ret;
-}
-
-bool
-ECPGdeallocate_one(int lineno, const char *name)
+static bool
+deallocate_one(int lineno, const char *name)
 {
 	struct prepared_statement *this,
 			   *prev;
@@ -147,8 +179,26 @@ ECPGdeallocate_one(int lineno, const char *name)
 	for (this = prep_stmts, prev = NULL; this != NULL && strcmp(this->name, name) != 0; prev = this, this = this->next);
 	if (this)
 	{
+		/* first deallocate the statement in the backend */
+		if (this->prepared)
+		{
+			char *text;
+			PGresult *query;
+			
+			if (!(text = (char *) ECPGalloc(strlen("deallocate \"\" ") + strlen(this->name), this->stmt->lineno)))
+				return false;
+			else
+			{
+				sprintf(text, "deallocate \"%s\"", this->name);
+				query = PQexec(this->stmt->connection->connection, text);
+				ECPGfree(text);
+				if (!ECPGcheck_PQresult(query, lineno, this->stmt->connection->connection, this->stmt->compat))
+					return false;
+				PQclear(query);
+			}
+		}
+		
 		/* okay, free all the resources */
-		ECPGfree(this->name);
 		ECPGfree(this->stmt->command);
 		ECPGfree(this->stmt);
 		if (prev != NULL)
@@ -162,13 +212,36 @@ ECPGdeallocate_one(int lineno, const char *name)
 	return false;
 }
 
+/* handle the EXEC SQL DEALLOCATE PREPARE statement */
 bool
-ECPGdeallocate_all(int lineno)
+ECPGdeallocate(int lineno, int c, const char *name)
+{
+	bool		ret = deallocate_one(lineno, name);
+	enum COMPAT_MODE compat = c;
+
+	ECPGlog("ECPGdeallocate line %d: NAME: %s\n", lineno, name);
+	if (INFORMIX_MODE(compat))
+	{
+		/*
+		 * Just ignore all errors since we do not know the list of cursors we
+		 * are allowed to free. We have to trust the software.
+		 */
+		return true;
+	}
+
+	if (!ret)
+		ECPGraise(lineno, ECPG_INVALID_STMT, ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME, name);
+
+	return ret;
+}
+
+bool
+ECPGdeallocate_all(int lineno, int compat)
 {
 	/* deallocate all prepared statements */
 	while (prep_stmts != NULL)
 	{
-		bool		b = ECPGdeallocate(lineno, ECPG_COMPAT_PGSQL, prep_stmts->name);
+		bool		b = ECPGdeallocate(lineno, compat, prep_stmts->name);
 
 		if (!b)
 			return false;
@@ -177,12 +250,204 @@ ECPGdeallocate_all(int lineno)
 	return true;
 }
 
+char *
+ECPGprepared(const char *name, int lineno)
+{
+	struct prepared_statement *this;
+
+	for (this = prep_stmts; this != NULL && ((strcmp(this->name, name) != 0) || this->prepared == false); this = this->next);
+	return (this) ? this->stmt->command : NULL;
+}
+
 /* return the prepared statement */
 char *
-ECPGprepared_statement(const char *name)
+ECPGprepared_statement(const char *name, int lineno)
 {
 	struct prepared_statement *this;
 
 	for (this = prep_stmts; this != NULL && strcmp(this->name, name) != 0; this = this->next);
 	return (this) ? this->stmt->command : NULL;
 }
+
+/*
+ * hash a SQL statement -  returns entry # of first entry in the bucket
+ */
+static int
+HashStmt(const char *ecpgQuery)
+{
+    int             stmtIx, bucketNo, hashLeng, stmtLeng;
+    long long       hashVal, rotVal;
+
+    stmtLeng = strlen(ecpgQuery);
+    hashLeng = 50;                          /* use 1st 50 characters of statement       */
+    if(hashLeng > stmtLeng)                 /* if the statement isn't that long         */
+        hashLeng = stmtLeng;                /*      use its actual length               */
+
+    hashVal = 0;
+    for(stmtIx = 0; stmtIx < hashLeng; ++stmtIx)
+    {
+        hashVal = hashVal +  (int) ecpgQuery[stmtIx];
+        hashVal = hashVal << 13;
+        rotVal  = (hashVal & 0x1fff00000000LL) >> 32;
+        hashVal = (hashVal & 0xffffffffLL) | rotVal;
+    }
+
+    bucketNo  = hashVal % stmtCacheNBuckets;
+    bucketNo += 1;                                      /* don't use bucket # 0         */
+
+    return (bucketNo * stmtCacheEntPerBucket);
+}
+
+/*
+ * search the statement cache - search for entry with matching ECPG-format query
+ * Returns entry # in cache if found
+ *   OR  zero if not present (zero'th entry isn't used)
+ */
+static int
+SearchStmtCache(const char *ecpgQuery)
+{
+    int             entNo, entIx;
+
+/* hash the statement           */
+    entNo = HashStmt(ecpgQuery);
+
+/* search the cache     */
+    for(entIx = 0; entIx < stmtCacheEntPerBucket; ++entIx)
+    {
+        if(stmtCacheEntries[entNo].stmtID[0])   /* check if entry is in use     */
+        {
+		if(!strcmp(ecpgQuery, stmtCacheEntries[entNo].ecpgQuery))
+                	break;                          /* found it     */
+        }
+        ++entNo;                                /* incr entry #     */
+    }
+
+/* if entry wasn't found - set entry # to zero  */
+    if(entIx >= stmtCacheEntPerBucket)
+        entNo = 0;
+
+    return(entNo);
+}
+
+/*
+ * free an entry in the statement cache
+ * Returns entry # in cache used
+ *   OR  negative error code
+ */
+static int
+ECPGfreeStmtCacheEntry(int      entNo)          /* entry # to free          */
+{
+    stmtCacheEntry  *entry;
+    PGresult        *results;
+    char            deallocText[100];
+    struct connection *con;
+
+    entry = &stmtCacheEntries[entNo];
+    if(!entry->stmtID[0])                       /* return if the entry isn't in use     */
+        return(0);
+
+    con = ECPGget_connection(entry->connection);
+/* free the server resources for the statement                                          */
+    ECPGlog("ECPGfreeStmtCacheEntry line %d: deallocate %s, cache entry #%d\n", entry->lineno, entry->stmtID, entNo);
+    sprintf(deallocText, "DEALLOCATE PREPARE %s", entry->stmtID);
+    results = PQexec(con->connection, deallocText);
+
+    if (!ECPGcheck_PQresult(results, entry->lineno, con->connection, ECPG_COMPAT_PGSQL))
+    	return(-1);
+    PQclear(results);
+
+    entry->stmtID[0] = '\0';
+
+/* free the memory used by the cache entry      */
+    if(entry->ecpgQuery)
+    {
+	ECPGfree(entry->ecpgQuery);
+        entry->ecpgQuery = 0;
+    }
+
+    return(entNo);
+}
+
+/*
+ * add an entry to the statement cache
+ * returns entry # in cache used  OR  negative error code
+ */
+static int
+AddStmtToCache(int      	lineno,         /* line # of statement      */
+               char		*stmtID,        /* statement ID             */
+               const char	*connection,    /* connection               */
+               const char	*ecpgQuery)     /* query                    */
+{
+    int             ix, initEntNo, luEntNo, entNo;
+    stmtCacheEntry  *entry;
+
+/* hash the statement                                                                   */
+    initEntNo = HashStmt(ecpgQuery);
+
+/* search for an unused entry                                                           */
+    entNo   = initEntNo;            /* start with the initial entry # for the bucket    */
+    luEntNo = initEntNo;            /* use it as the initial 'least used' entry         */
+    for(ix = 0; ix < stmtCacheEntPerBucket; ++ix)
+    {
+        entry = &stmtCacheEntries[entNo];
+        if(!entry->stmtID[0])                       /* unused entry  -  use it          */
+            break;
+        if(entry->execs < stmtCacheEntries[luEntNo].execs)
+            luEntNo = entNo;                        /* save new 'least used' entry      */
+        ++entNo;                                    /* increment entry #                */
+    }
+
+/* if no unused entries were found - use the 'least used' entry found in the bucket     */
+    if(ix >= stmtCacheEntPerBucket)                 /* if no unused entries were found  */
+        entNo = luEntNo;                            /* re-use the 'least used' entry    */
+
+/* 'entNo' is the entry to use - make sure its free                                     */
+    if (ECPGfreeStmtCacheEntry(entNo) < 0)
+    	return (-1);
+
+/* add the query to the entry                                                           */
+    entry = &stmtCacheEntries[entNo];
+    entry->lineno = lineno;
+    entry->ecpgQuery = ECPGstrdup(ecpgQuery, lineno);
+    entry->connection = (char *)connection;
+    entry->execs = 0;
+    memcpy(entry->stmtID, stmtID, sizeof(entry->stmtID));
+
+    return(entNo);
+}
+
+/* handle cache and preparation of statments in auto-prepare mode */
+bool
+ECPGauto_prepare(int lineno, const char *connection_name, const int questionmarks, char **name, const char *query)
+{
+	int entNo;
+
+	/* search the statement cache for this statement    */
+	entNo = SearchStmtCache(query);
+
+	/* if not found - add the statement to the cache    */
+        if(entNo)
+	{
+	        ECPGlog("ECPGauto_prepare line %d: stmt found in cache, entry %d\n", lineno, entNo);
+		*name = ECPGstrdup(stmtCacheEntries[entNo].stmtID, lineno); 
+	}
+	else
+	{
+	        ECPGlog("ECPGauto_prepare line %d: stmt not in cache; inserting\n", lineno);
+
+		/* generate a statement ID */
+		*name = (char *) ECPGalloc(STMTID_SIZE, lineno);
+		sprintf(*name, "ecpg%d", nextStmtID++);
+
+		if (!ECPGprepare(lineno, connection_name, questionmarks, ECPGstrdup(*name, lineno), query))
+			return(false);
+		if (AddStmtToCache(lineno, *name, connection_name, query) < 0)
+			return(false);
+	}
+
+	/* increase usage counter */
+	stmtCacheEntries[entNo].execs++;
+
+	return(true);
+}
+
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index ab18b7e5f985be333ebfdc4df6eeb91e46a52cd7..80e5452a13102ca7599af80f3d1c80d4c46f7dca 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -1,7 +1,7 @@
 /*
  * this is a small part of c.h since we don't want to leak all postgres
  * definitions into ecpg programs
- * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.70 2006/10/04 00:30:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpglib.h,v 1.71 2007/08/14 10:01:52 meskes Exp $
  */
 
 #ifndef _ECPGLIB_H
@@ -44,14 +44,14 @@ bool		ECPGstatus(int, const char *);
 bool		ECPGsetcommit(int, const char *, const char *);
 bool		ECPGsetconn(int, const char *);
 bool		ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
-bool		ECPGdo(int, int, int, const char *, const char *,...);
+bool		ECPGdo(const int, const int, const int, const char *, const char, const enum ECPG_statement_type, const char *,...);
 bool		ECPGtrans(int, const char *, const char *);
 bool		ECPGdisconnect(int, const char *);
-bool		ECPGprepare(int, const char *, const char *);
+bool		ECPGprepare(int, const char *, const int, const char *, const char *);
+bool		ECPGauto_prepare(int, const char *, const int, char **, const char *);
 bool		ECPGdeallocate(int, int, const char *);
-bool		ECPGdeallocate_one(int, const char *);
-bool		ECPGdeallocate_all(int);
-char	   *ECPGprepared_statement(const char *);
+bool		ECPGdeallocate_all(int, int);
+char	   *ECPGprepared_statement(const char *, int);
 
 void		ECPGlog(const char *format,...);
 char	   *ECPGerrmsg(void);
@@ -69,8 +69,6 @@ bool ECPGdo_descriptor(int line, const char *connection,
 				  const char *descriptor, const char *query);
 bool		ECPGdeallocate_desc(int line, const char *name);
 bool		ECPGallocate_desc(int line, const char *name);
-void		ECPGraise(int line, int code, const char *sqlstate, const char *str);
-void		ECPGraise_backend(int line, PGresult *result, PGconn *conn, int compat);
 bool		ECPGget_desc_header(int, const char *, int *);
 bool		ECPGget_desc(int, const char *, int,...);
 bool		ECPGset_desc_header(int, const char *, int);
diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h
index d7b8cce89a1432c46f3238e1b5f4e40abfa57bbe..62cf255ceff0765531edeb843c695250392b4240 100644
--- a/src/interfaces/ecpg/include/ecpgtype.h
+++ b/src/interfaces/ecpg/include/ecpgtype.h
@@ -5,7 +5,7 @@
  * All types that can be handled for host variable declarations has to
  * be handled eventually.
  *
- * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpgtype.h,v 1.36 2006/03/11 04:38:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/include/ecpgtype.h,v 1.37 2007/08/14 10:01:52 meskes Exp $
  */
 
 /*
@@ -88,6 +88,15 @@ enum ECPGdtype
 
 #define IS_SIMPLE_TYPE(type) ((type) >= ECPGt_char && (type) <= ECPGt_interval)
 
+/* we also have to handle different statement types */
+enum ECPG_statement_type
+{
+	ECPGst_normal,
+	ECPGst_execute,
+	ECPGst_exec_immediate,
+	ECPGst_prepnormal
+};
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c
index 87b62c0b10529c2b51d9d01adf4d9c17c42070d6..70128d1802d9a9f36aeb80cda2c1c2457cabad26 100644
--- a/src/interfaces/ecpg/pgtypeslib/datetime.c
+++ b/src/interfaces/ecpg/pgtypeslib/datetime.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.32 2006/10/04 00:30:11 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/datetime.c,v 1.33 2007/08/14 10:01:52 meskes Exp $ */
 
 #include "postgres_fe.h"
 
@@ -57,7 +57,6 @@ PGTYPESdate_from_asc(char *str, char **endptr)
 	fsec_t		fsec;
 	struct tm	tt,
 			   *tm = &tt;
-	int			tzp;
 	int			dtype;
 	int			nf;
 	char	   *field[MAXDATEFIELDS];
@@ -76,7 +75,7 @@ PGTYPESdate_from_asc(char *str, char **endptr)
 	}
 
 	if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
-	DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp, EuroDates) != 0)
+	DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, EuroDates) != 0)
 	{
 		errno = PGTYPES_DATE_BAD_DATE;
 		return INT_MIN;
diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index b94bd5a73b966d1a40db9175862369a65780b2c1..83f8c520c274b31807a828300b1167071e70a52d 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.36 2007/02/19 17:41:39 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt.h,v 1.37 2007/08/14 10:01:53 meskes Exp $ */
 
 #ifndef DT_H
 #define DT_H
@@ -331,7 +331,7 @@ bool		CheckDateTokenTables(void);
 int			EncodeDateOnly(struct tm *, int, char *, bool);
 void		GetEpochTime(struct tm *);
 int			ParseDateTime(char *, char *, char **, int *, int, int *, char **);
-int			DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, int *, bool);
+int			DecodeDateTime(char **, int *, int, int *, struct tm *, fsec_t *, bool);
 void		j2date(int, int *, int *, int *);
 void		GetCurrentDateTime(struct tm *);
 int			date2j(int, int, int);
diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c
index 3dec7f4a42cd71b0f1449539ae4de57e267df4f9..53dc325a465bbb44623d6e7737d9501cfe840304 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt_common.c
+++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.40 2007/05/21 07:07:48 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.41 2007/08/14 10:01:53 meskes Exp $ */
 
 #include "postgres_fe.h"
 
@@ -1816,7 +1816,7 @@ ParseDateTime(char *timestr, char *lowstr,
  */
 int
 DecodeDateTime(char **field, int *ftype, int nf,
-		  int *dtype, struct tm * tm, fsec_t *fsec, int *tzp, bool EuroDates)
+		  int *dtype, struct tm * tm, fsec_t *fsec, bool EuroDates)
 {
 	int			fmask = 0,
 				tmask,
@@ -1828,6 +1828,8 @@ DecodeDateTime(char **field, int *ftype, int nf,
 	int			haveTextMonth = FALSE;
 	int			is2digits = FALSE;
 	int			bc = FALSE;
+	int			t = 0;
+	int			*tzp = &t;
 
 	/***
 	 * We'll insist on at least all of the date fields, but initialize the
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 97a5190137c9c407a1b69251052e7745e4f5cbf5..4ec94672bb9402941ed77b38d5d7179d272b03eb 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -308,7 +308,6 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr)
 	fsec_t		fsec;
 	struct tm	tt,
 			   *tm = &tt;
-	int			tz;
 	int			dtype;
 	int			nf;
 	char	   *field[MAXDATEFIELDS];
@@ -324,7 +323,7 @@ PGTYPEStimestamp_from_asc(char *str, char **endptr)
 	}
 
 	if (ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf, ptr) != 0 ||
-		DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tz, 0) != 0)
+		DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, 0) != 0)
 	{
 		errno = PGTYPES_TS_BAD_TIMESTAMP;
 		return (noresult);
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index 679331d979323a10f4c4c3b7060cee93164b12d0..6d8826608798eed09923b908a93def199228bd27 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1998-2007, PostgreSQL Global Development Group
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.126 2007/04/01 08:56:58 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.127 2007/08/14 10:01:53 meskes Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -14,8 +14,8 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 MAJOR_VERSION= 4
-MINOR_VERSION= 3
-PATCHLEVEL=1
+MINOR_VERSION= 4
+PATCHLEVEL=0
 
 override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(srcdir) -DMAJOR_VERSION=$(MAJOR_VERSION) \
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index e5439a9622ea37ab88fc09b42d728ca9c12729e3..213118586230ef1bb37776409ad4be3dab35cb19 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.99 2007/06/11 11:52:08 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.100 2007/08/14 10:01:53 meskes Exp $ */
 
 /* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
 /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -17,10 +17,12 @@ int			ret_value = 0,
 			auto_create_c = false,
 			system_includes = false,
 			force_indicator = true,
+			questionmarks = false,
 			header_mode = false,
-			regression_mode = false;
+			regression_mode = false,
+			auto_prepare = false;
 
-char	   *output_filename;
+char      *output_filename;
 
 enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL;
 
@@ -51,7 +53,10 @@ help(const char *progname)
 	printf("  -I DIRECTORY   search DIRECTORY for include files\n");
 	printf("  -o OUTFILE     write result to OUTFILE\n");
 	printf("  -r OPTION      specify runtime behaviour;\n"
-		   "                 OPTION can only be \"no_indicator\"\n");
+		   "                 OPTION can be:\n"
+		   "                  \"no_indicator\"\n"
+		   "                  \"prepare\"\n"
+		   "                  \"questionmarks\"\n");
 	printf("  -t             turn on autocommit of transactions\n");
 	printf("  --help         show this help, then exit\n");
 	printf("  --regression   run in regression testing mode\n");
@@ -225,6 +230,10 @@ main(int argc, char *const argv[])
 			case 'r':
 				if (strcmp(optarg, "no_indicator") == 0)
 					force_indicator = false;
+				else if (strcmp(optarg, "prepare") == 0)
+					auto_prepare = true;
+				else if (strcmp(optarg, "questionmarks") == 0)
+					questionmarks = true;
 				else
 				{
 					fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index 4a2cfaf747c9be1ccb1c4b27817a4e6873d5b685..8357b2514f6adc5542c0856722ac35e92fbc5383 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.66 2007/06/11 11:52:08 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.67 2007/08/14 10:01:53 meskes Exp $ */
 
 #ifndef _ECPG_PREPROC_EXTERN_H
 #define _ECPG_PREPROC_EXTERN_H
@@ -19,10 +19,12 @@ extern int	braces_open,
 			auto_create_c,
 			system_includes,
 			force_indicator,
+			questionmarks,
 			ret_value,
 			struct_level,
 			ecpg_informix_var,
-			regression_mode;
+			regression_mode,
+			auto_prepare;
 extern char *descriptor_index;
 extern char *descriptor_name;
 extern char *connection;
@@ -58,7 +60,9 @@ extern const char *get_dtype(enum ECPGdtype);
 extern void lex_init(void);
 extern char *make_str(const char *);
 extern void output_line_number(void);
-extern void output_statement(char *, int, char *);
+extern void output_statement(char *, int, enum ECPG_statement_type);
+extern void output_prepare_statement(char *, char *);
+extern void output_deallocate_prepare_statement(char *);
 extern void output_simple_statement(char *);
 extern char *hashline_number(void);
 extern int	base_yyparse(void);
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 23469fca8608acfc6da85374bcfd3a93ec01e221..7a83d67ed1eca8d25dba4a7c1e4d6654f47933fb 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -1,17 +1,16 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.19 2006/10/04 00:30:12 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/output.c,v 1.20 2007/08/14 10:01:53 meskes Exp $ */
 
 #include "postgres_fe.h"
 
 #include "extern.h"
 
-static void output_escaped_str(char *cmd);
+static void output_escaped_str(char *cmd, bool quoted);
 
 void
 output_line_number(void)
 {
 	char	   *line = hashline_number();
 
-	/* output_escaped_str(line); */
 	fprintf(yyout, "%s", line);
 	free(line);
 }
@@ -19,11 +18,12 @@ output_line_number(void)
 void
 output_simple_statement(char *stmt)
 {
-	output_escaped_str(stmt);
+	output_escaped_str(stmt, false);
 	output_line_number();
 	free(stmt);
 }
 
+
 /*
  * store the whenever action here
  */
@@ -95,7 +95,7 @@ hashline_number(void)
 #endif
 		)
 	{
-		char	   *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename));
+		char	   *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename));
 
 		sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename);
 
@@ -106,11 +106,22 @@ hashline_number(void)
 }
 
 void
-output_statement(char *stmt, int mode, char *con)
+output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
 {
-	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, \"", compat, force_indicator, con ? con : "NULL");
-	output_escaped_str(stmt);
-	fputs("\", ", yyout);
+
+	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	if (st == ECPGst_normal)
+	{
+		if (auto_prepare)
+			fprintf(yyout, "%d, \"", ECPGst_prepnormal);
+		else
+			fprintf(yyout, "%d, \"", ECPGst_normal);
+
+		output_escaped_str(stmt, false);
+		fputs("\", ", yyout);
+	}
+	else
+		fprintf(yyout, "%d, %s, ", st, stmt);
 
 	/* dump variables to C file */
 	dump_variables(argsinsert, 1);
@@ -119,27 +130,66 @@ output_statement(char *stmt, int mode, char *con)
 	fputs("ECPGt_EORT);", yyout);
 	reset_variables();
 
-	mode |= 2;
-	whenever_action(mode);
+	whenever_action(whenever_mode|2);
 	free(stmt);
 	if (connection != NULL)
 		free(connection);
 }
 
+void
+output_prepare_statement(char *name, char *stmt)
+{
+	fprintf(yyout, "{ ECPGprepare(__LINE__, %s, %d, ", connection ? connection : "NULL", questionmarks);
+	output_escaped_str(name, true);
+	fputs(", ", yyout);
+	output_escaped_str(stmt, true);
+	fputs(");", yyout);
+	whenever_action(2);
+	free(name);
+	if (connection != NULL)
+		free(connection);
+}
+
+void
+output_deallocate_prepare_statement(char *name)
+{
+	if (strcmp(name, "all"))
+	{
+		fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, ", compat);
+		output_escaped_str(name, true);
+		fputs(");", yyout);
+	}
+	else
+		fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d);", compat);
+
+	whenever_action(2);
+	free(name);
+	if (connection != NULL)
+		free(connection);
+}
 
 static void
-output_escaped_str(char *str)
+output_escaped_str(char *str, bool quoted)
 {
-	int			i,
-				len = strlen(str);
+	int i = 0;
+	int len = strlen(str);
+	
+	if (quoted && str[0] == '\"' && str[len-1] == '\"') /* do not escape quotes at beginning and end if quoted string */
+	{
+		i = 1;
+		len--;
+		fputs("\"", yyout);
+	}
 
 	/* output this char by char as we have to filter " and \n */
-	for (i = 0; i < len; i++)
+	for (; i < len; i++)
 	{
 		if (str[i] == '"')
 			fputs("\\\"", yyout);
 		else if (str[i] == '\n')
 			fputs("\\\n", yyout);
+		else if (str[i] == '\\')
+			fputs("\\\\", yyout);
 		else if (str[i] == '\r' && str[i + 1] == '\n')
 		{
 			fputs("\\\r\n", yyout);
@@ -148,4 +198,7 @@ output_escaped_str(char *str)
 		else
 			fputc(str[i], yyout);
 	}
+
+	if (quoted && str[0] == '\"' && str[len] == '\"') 
+		fputs("\"", yyout);
 }
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index 2660f25af55452e4a07df60063020d05fb4e420a..23f22071225d6403e8605dcfc65ee0a934ce8c80 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -12,7 +12,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.152 2007/03/17 19:25:23 meskes Exp $
+ *	  $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.153 2007/08/14 10:01:53 meskes Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,7 +29,6 @@ extern YYSTYPE yylval;
 static int		xcdepth = 0;	/* depth of nesting in slash-star comments */
 static char	   *dolqstart;      /* current $foo$ quote start string */
 static bool		escape_string_warning;
-static bool		standard_conforming_strings;
 static bool 	warn_on_first_escape;
 static YY_BUFFER_STATE scanbufhandle;
 static char *scanbuf;
@@ -101,6 +100,7 @@ static struct _if_value
  *	<xh> hexadecimal numeric string - thomas 1997-11-16
  *	<xq> standard quoted strings - thomas 1997-07-30
  *	<xe> extended quoted strings (support backslash escape sequences)
+ *	<xn> national character quoted strings
  *  <xdolq> $foo$ quoted strings
  */
 
@@ -110,6 +110,7 @@ static struct _if_value
 %x xdc
 %x xh
 %x xe
+%x xn
 %x xq
 %x xdolq
 %x xcond
@@ -409,27 +410,21 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 				warn_on_first_escape = true;
 		        token_start = yytext;
 				state_before = YYSTATE;
-				if (standard_conforming_strings)
-					BEGIN(xq);
-				else
-					BEGIN(xe);
+				BEGIN(xn);
 				startlit();
 			}
 <C>{xqstart}	{
 				warn_on_first_escape = false;
 				token_start = yytext;
 				state_before = YYSTATE;
-				BEGIN(xe);
+				BEGIN(xq);
 				startlit();
 			}
 <SQL>{xqstart}	{
 				warn_on_first_escape = true;
 				token_start = yytext;
 				state_before = YYSTATE;
-				if (standard_conforming_strings)
-					BEGIN(xq);
-				else
-					BEGIN(xe);
+				BEGIN(xq);
 				startlit();
 			}
 <SQL>{xestart}	{
@@ -439,15 +434,29 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 				BEGIN(xe);
 				startlit();
 			}
-<xq,xe>{quotestop} |
-<xq,xe>{quotefail} {
+<xq>{quotestop} |
+<xq>{quotefail} {
 				yyless(1);
 				BEGIN(state_before);
 				yylval.str = mm_strdup(literalbuf);
 				return SCONST;
 			}
-<xq,xe>{xqdouble}		{ addlitchar('\''); }
-<xq>{xqinside}		{ addlit(yytext, yyleng); }
+<xe>{quotestop} |
+<xe>{quotefail} {
+				yyless(1);
+				BEGIN(state_before);
+				yylval.str = mm_strdup(literalbuf);
+				return ECONST;
+			}
+<xn>{quotestop} |
+<xn>{quotefail} {
+				yyless(1);
+				BEGIN(state_before);
+				yylval.str = mm_strdup(literalbuf);
+				return NCONST;
+			}
+<xq,xe,xn>{xqdouble}		{ addlitchar('\''); }
+<xq,xn>{xqinside}		{ addlit(yytext, yyleng); }
 <xe>{xeinside}		{ addlit(yytext, yyleng); }
 <xe>{xeescape}  	{ 
 				check_escape_warning();
@@ -461,12 +470,12 @@ cppline			{space}*#(.*\\{space})*.*{newline}
 				check_escape_warning();
 				addlit(yytext, yyleng);
 			}
-<xq,xe>{quotecontinue}	{ /* ignore */ }
+<xq,xe,xn>{quotecontinue}	{ /* ignore */ }
 <xe>.                   {
 			   /* This is only needed for \ just before EOF */
 			   addlitchar(yytext[0]);
 			}
-<xq,xe><<EOF>>		{ mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
+<xq,xe,xn><<EOF>>		{ mmerror(PARSE_ERROR, ET_FATAL, "Unterminated quoted string"); }
 <SQL>{dolqfailed}	{
 				/* throw back all but the initial "$" */
 				yyless(1);
diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y
index 354ff6363cbe00924b160d215fab755a6012d586..6d665392f5e4815c12177a51b18eebd00df9a764 100644
--- a/src/interfaces/ecpg/preproc/preproc.y
+++ b/src/interfaces/ecpg/preproc/preproc.y
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.348 2007/07/25 16:10:41 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.349 2007/08/14 10:01:53 meskes Exp $ */
 
 /* Copyright comment */
 %{
@@ -33,6 +33,8 @@ char	*input_filename = NULL;
 
 static int	QueryIsRule = 0, FoundInto = 0;
 static int	initializer = 0;
+static int	pacounter = 1;
+static char     pacounter_buffer[sizeof(int) * CHAR_BIT * 10 / 3]; /* a rough guess at the size we need */
 static struct this_type actual_type[STRUCT_DEPTH];
 static char *actual_startline[STRUCT_DEPTH];
 
@@ -50,21 +52,6 @@ struct variable no_indicator = {"no_indicator", &ecpg_no_indicator, 0, NULL};
 
 struct ECPGtype ecpg_query = {ECPGt_char_variable, 0L, NULL, {NULL}};
 
-/* INFORMIX workaround, no longer needed
-static struct inf_compat_col
-{
-	char *name;
-	char *indirection;
-	struct inf_compat_col *next;
-} *informix_col;
-
-static struct inf_compat_val
-{
-	char *val;
-	struct inf_compat_val *next;
-} *informix_val;
-*/
-
 /*
  * Handle parsing errors and warnings
  */
@@ -103,7 +90,7 @@ mmerror(int error_code, enum errortype type, char * error, ...)
 			fclose(yyin);
 			fclose(yyout);
 			if (unlink(output_filename) != 0 && *output_filename != '-')
-				fprintf(stderr, "Could not remove output file %s!\n", output_filename);
+			        fprintf(stderr, "Could not remove output file %s!\n", output_filename);
 			exit(error_code);
 	}
 }
@@ -218,7 +205,10 @@ create_questionmarks(char *name, bool array)
 		count = 1;
 
 	for (; count > 0; count --)
-		result = cat2_str(result, make_str("? , "));
+	{
+		sprintf(pacounter_buffer, "$%d", pacounter++);
+		result = cat_str(3, result, strdup(pacounter_buffer), make_str(" , "));
+	}
 
 	/* removed the trailing " ," */
 
@@ -255,17 +245,17 @@ adjust_informix(struct arguments *list)
 
 		if ((ptr->variable->type->type != ECPGt_varchar && ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char) && atoi(ptr->variable->type->size) > 1)
 		{
-			ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1")), ptr->variable->type->size), 0);
+			ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1"), ptr->variable->type->u.element->lineno), ptr->variable->type->size), 0);
 			sprintf(temp, "%d, (", ecpg_informix_var++);
 		}
 		else if ((ptr->variable->type->type == ECPGt_varchar || ptr->variable->type->type == ECPGt_char || ptr->variable->type->type == ECPGt_unsigned_char) && atoi(ptr->variable->type->size) > 1)
 		{
-			ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
+			ptr->variable = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
 			sprintf(temp, "%d, (", ecpg_informix_var++);
 		}
 		else
 		{
-			ptr->variable = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size), 0);
+			ptr->variable = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->variable->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
 			sprintf(temp, "%d, &(", ecpg_informix_var++);
 		}
 
@@ -282,12 +272,12 @@ adjust_informix(struct arguments *list)
 			/* create call to "ECPG_informix_set_var(<counter>, <pointer>. <linen number>)" */
 			if (atoi(ptr->indicator->type->size) > 1)
 			{
-				ptr->indicator = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size), 0);
+				ptr->indicator = new_variable(cat_str(4, make_str("("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
 				sprintf(temp, "%d, (", ecpg_informix_var++);
 			}
 			else
 			{
-				ptr->indicator = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size), 0);
+				ptr->indicator = new_variable(cat_str(4, make_str("*("), mm_strdup(ECPGtype_name(ptr->indicator->type->type)), make_str(" *)(ECPG_informix_get_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
 				sprintf(temp, "%d, &(", ecpg_informix_var++);
 			}
 			result = cat_str(5, result, make_str("ECPG_informix_set_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
@@ -346,6 +336,7 @@ add_additional_variables(char *name, bool insert)
 	enum	ECPGdtype	dtype_enum;
 	struct	fetch_desc	descriptor;
 	struct  su_symbol	struct_union;
+	struct	prep		prep;
 }
 
 /* special embedded SQL token */
@@ -466,7 +457,8 @@ add_additional_variables(char *name, bool insert)
 %token           NULLS_FIRST NULLS_LAST WITH_CASCADED WITH_LOCAL WITH_CHECK
 
 /* Special token types, not actually keywords - see the "lex" file */
-%token <str>	IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST XCONST DOLCONST
+%token <str>	IDENT SCONST Op CSTRING CVARIABLE CPP_LINE IP BCONST
+%token <str>	XCONST DOLCONST ECONST NCONST
 %token <ival>	ICONST PARAM
 %token <dval>	FCONST
 
@@ -547,7 +539,7 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	RemoveOperStmt RenameStmt all_Op opt_trusted opt_lancompiler
 %type  <str>	VariableSetStmt var_value zone_value VariableShowStmt
 %type  <str>	VariableResetStmt AlterTableStmt from_list overlay_list
-%type  <str>	relation_name OptTableSpace LockStmt opt_lock
+%type  <str>	relation_name OptTableSpace LockStmt opt_lock 
 %type  <str>	CreateUserStmt AlterUserStmt CreateSeqStmt OptSeqList
 %type  <str>	OptSeqElem TriggerForSpec TriggerForOpt TriggerForType
 %type  <str>	DropTrigStmt TriggerOneEvent TriggerEvents RuleActionStmt
@@ -576,8 +568,8 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	select_limit CheckPointStmt ECPGColId old_aggr_list
 %type  <str>	OptSchemaName OptSchemaEltList schema_stmt opt_drop_behavior
 %type  <str>	handler_name any_name_list any_name opt_as insert_column_list
-%type  <str>	columnref values_clause AllConstVar where_or_current_clause
-%type  <str>	insert_column_item DropRuleStmt ctext_expr 
+%type  <str>	columnref values_clause AllConstVar prep_type_clause ExecuteStmt
+%type  <str>	insert_column_item DropRuleStmt ctext_expr execute_param_clause 
 %type  <str>	createfunc_opt_item set_rest var_list_or_default alter_rel_cmd
 %type  <str>	CreateFunctionStmt createfunc_opt_list func_table
 %type  <str>	DropUserStmt copy_from copy_opt_list copy_opt_item
@@ -589,7 +581,7 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	ConstBit GenericType TableFuncElementList opt_analyze
 %type  <str>	opt_sort_clause subquery_Op transaction_mode_item
 %type  <str>	ECPGWhenever ECPGConnect connection_target ECPGOpen
-%type  <str>	indicator ECPGExecute ECPGPrepare ecpg_using ecpg_into
+%type  <str>	indicator ecpg_using ecpg_into DeallocateStmt
 %type  <str>	storage_declaration storage_clause opt_initializer c_anything
 %type  <str>	variable_list variable c_thing c_term ECPGKeywords_vanames
 %type  <str>	opt_pointer ECPGDisconnect dis_name storage_modifier
@@ -599,15 +591,15 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	var_type_declarations quoted_ident_stringvar ECPGKeywords_rest
 %type  <str>	db_prefix server opt_options opt_connection_name c_list
 %type  <str>	ECPGSetConnection ECPGTypedef c_args ECPGKeywords ECPGCKeywords
-%type  <str>	enum_type civar civarind ECPGCursorStmt ECPGDeallocate
-%type  <str>	ECPGFree ECPGDeclare ECPGVar opt_at enum_definition
+%type  <str>	enum_type civar civarind ECPGCursorStmt PreparableStmt
+%type  <str>	ECPGFree ECPGDeclare ECPGVar at enum_definition
 %type  <str>	struct_union_type s_struct_union vt_declarations execute_rest
 %type  <str>	var_declaration type_declaration single_vt_declaration
 %type  <str>	ECPGSetAutocommit on_off variable_declarations ECPGDescribe
 %type  <str>	ECPGAllocateDescr ECPGDeallocateDescr symbol opt_output
 %type  <str>	ECPGGetDescriptorHeader ECPGColLabel single_var_declaration
 %type  <str>	reserved_keyword unreserved_keyword ecpg_interval opt_ecpg_using
-%type  <str>	col_name_keyword precision opt_scale
+%type  <str>	col_name_keyword precision opt_scale ECPGExecuteImmediateStmt
 %type  <str>	ECPGTypeName using_list ECPGColLabelCommon UsingConst 
 %type  <str>	using_descriptor into_descriptor opt_nulls_order opt_asc_desc
 %type  <str>	prepared_name struct_union_type_with_symbol OptConsTableSpace
@@ -627,6 +619,7 @@ add_additional_variables(char *name, bool insert)
 %type  <str>	CreateOpFamilyStmt AlterOpFamilyStmt create_as_target
 %type  <str>	xml_attributes xml_attribute_list document_or_content xml_whitespace_option
 %type  <str>	opt_xml_root_standalone xml_root_version xml_attribute_el 
+%type  <str>	where_or_current_clause
 
 %type  <struct_union> s_struct_union_symbol
 
@@ -638,6 +631,8 @@ add_additional_variables(char *name, bool insert)
 
 %type  <type>	var_type
 
+%type  <prep>	PrepareStmt
+
 %type  <action> action
 
 %type  <index>	opt_array_bounds
@@ -649,7 +644,7 @@ statements: /*EMPTY*/
 		| statements statement
 		;
 
-statement: ecpgstart opt_at stmt ';'	{ connection = NULL; }
+statement: ecpgstart at stmt ';'	{ connection = NULL; }
 		| ecpgstart stmt ';'
 		| ecpgstart ECPGVarDeclaration
 		{
@@ -664,7 +659,7 @@ statement: ecpgstart opt_at stmt ';'	{ connection = NULL; }
 		| '}'			{ remove_typedefs(braces_open); remove_variables(braces_open--); fputs("}", yyout); }
 		;
 
-opt_at: AT connection_object
+at: AT connection_object
 		{
 			connection = $2;
 			/*
@@ -674,22 +669,23 @@ opt_at: AT connection_object
 			 */
 			if (argsinsert != NULL)
 				argsinsert = NULL;
-		};
-
-stmt:  AlterDatabaseStmt		{ output_statement($1, 0, connection); }
-		| AlterDatabaseSetStmt	{ output_statement($1, 0, connection); }
-		| AlterDomainStmt	{ output_statement($1, 0, connection); }
-		| AlterFunctionStmt	{ output_statement($1, 0, connection); }
-		| AlterGroupStmt	{ output_statement($1, 0, connection); }
-		| AlterObjectSchemaStmt	{ output_statement($1, 0, connection); }
-		| AlterOwnerStmt	{ output_statement($1, 0, connection); }
-		| AlterSeqStmt		{ output_statement($1, 0, connection); }
-		| AlterTableStmt	{ output_statement($1, 0, connection); }
-		| AlterRoleSetStmt	{ output_statement($1, 0, connection); }
-		| AlterRoleStmt		{ output_statement($1, 0, connection); }
-		| AlterUserStmt		{ output_statement($1, 0, connection); }
-		| AnalyzeStmt		{ output_statement($1, 0, connection); }
-		| CheckPointStmt	{ output_statement($1, 0, connection); }
+		}
+	;
+
+stmt:  AlterDatabaseStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| AlterDatabaseSetStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterDomainStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterFunctionStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterGroupStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterObjectSchemaStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterOwnerStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterSeqStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| AlterTableStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterRoleSetStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterRoleStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| AlterUserStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| AnalyzeStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CheckPointStmt	{ output_statement($1, 0, ECPGst_normal); }
 		| ClosePortalStmt
 		{
 			if (INFORMIX_MODE)
@@ -709,89 +705,103 @@ stmt:  AlterDatabaseStmt		{ output_statement($1, 0, connection); }
 					free($1);
 				}
 				else
-					output_statement($1, 0, connection);
+					output_statement($1, 0, ECPGst_normal);
 			}
 			else
-				output_statement($1, 0, connection);
-		}
-		| ClusterStmt		{ output_statement($1, 0, connection); }
-		| CommentStmt		{ output_statement($1, 0, connection); }
-		| ConstraintsSetStmt	{ output_statement($1, 0, connection); }
-		| CopyStmt		{ output_statement($1, 0, connection); }
-		| CreateAsStmt		{ output_statement($1, 0, connection); }
-		| CreateAssertStmt	{ output_statement($1, 0, connection); }
-		| CreateCastStmt	{ output_statement($1, 0, connection); }
-		| CreateConversionStmt	{ output_statement($1, 0, connection); }
-		| CreateDomainStmt	{ output_statement($1, 0, connection); }
-		| CreateFunctionStmt	{ output_statement($1, 0, connection); }
-		| CreateGroupStmt	{ output_statement($1, 0, connection); }
-		| CreatePLangStmt	{ output_statement($1, 0, connection); }
-		| CreateOpClassStmt	{ output_statement($1, 0, connection); }
-		| CreateOpFamilyStmt	{ output_statement($1, 0, connection); }
-		| AlterOpFamilyStmt	{ output_statement($1, 0, connection); }
-		| CreateRoleStmt	{ output_statement($1, 0, connection); }
-		| CreateSchemaStmt	{ output_statement($1, 0, connection); }
-		| CreateSeqStmt		{ output_statement($1, 0, connection); }
-		| CreateStmt		{ output_statement($1, 0, connection); }
-		| CreateTableSpaceStmt	{ output_statement($1, 0, connection); }
-		| CreateTrigStmt	{ output_statement($1, 0, connection); }
-		| CreateUserStmt	{ output_statement($1, 0, connection); }
-		| CreatedbStmt		{ output_statement($1, 0, connection); }
-		/*| DeallocateStmt	{ output_statement($1, 0, connection); }*/
+				output_statement($1, 0, ECPGst_normal);
+		}
+		| ClusterStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CommentStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| ConstraintsSetStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CopyStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CreateAsStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CreateAssertStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateCastStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateConversionStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateDomainStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateFunctionStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateGroupStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreatePLangStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateOpClassStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateOpFamilyStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| AlterOpFamilyStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateRoleStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateSchemaStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateSeqStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CreateStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| CreateTableSpaceStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateTrigStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreateUserStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| CreatedbStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DeallocateStmt
+		{
+			if (connection)
+				mmerror(PARSE_ERROR, ET_ERROR, "no at option for deallocate statement.\n");
+				
+			output_deallocate_prepare_statement($1);
+		}
 		| DeclareCursorStmt	{ output_simple_statement($1); }
-		| DefineStmt		{ output_statement($1, 0, connection); }
-		| DeleteStmt		{ output_statement($1, 1, connection); }
-		| DiscardStmt		{ output_statement($1, 1, connection); }
-		| DropAssertStmt	{ output_statement($1, 0, connection); }
-		| DropCastStmt		{ output_statement($1, 0, connection); }
-		| DropGroupStmt		{ output_statement($1, 0, connection); }
-		| DropOpClassStmt	{ output_statement($1, 0, connection); }
-		| DropOpFamilyStmt	{ output_statement($1, 0, connection); }
-		| DropOwnedStmt		{ output_statement($1, 0, connection); }
-		| DropPLangStmt		{ output_statement($1, 0, connection); }
-		| DropRoleStmt		{ output_statement($1, 0, connection); }
-		| DropRuleStmt		{ output_statement($1, 0, connection); }
-		| DropStmt		{ output_statement($1, 0, connection); }
-		| DropTableSpaceStmt	{ output_statement($1, 0, connection); }
-		| DropTrigStmt		{ output_statement($1, 0, connection); }
-		| DropUserStmt		{ output_statement($1, 0, connection); }
-		| DropdbStmt		{ output_statement($1, 0, connection); }
-		| ExplainStmt		{ output_statement($1, 0, connection); }
-/*		| ExecuteStmt		{ output_statement($1, 0, connection); }*/
-		| FetchStmt			{ output_statement($1, 1, connection); }
-		| GrantStmt			{ output_statement($1, 0, connection); }
-		| GrantRoleStmt		{ output_statement($1, 0, connection); }
-		| IndexStmt			{ output_statement($1, 0, connection); }
-		| InsertStmt		{ output_statement($1, 1, connection); }
-		| ListenStmt		{ output_statement($1, 0, connection); }
-		| LoadStmt			{ output_statement($1, 0, connection); }
-		| LockStmt			{ output_statement($1, 0, connection); }
-		| NotifyStmt		{ output_statement($1, 0, connection); }
-/*		| PrepareStmt		{ output_statement($1, 0, connection); }*/
-		| ReassignOwnedStmt	{ output_statement($1, 0, connection); }
-		| ReindexStmt		{ output_statement($1, 0, connection); }
-		| RemoveAggrStmt	{ output_statement($1, 0, connection); }
-		| RemoveOperStmt	{ output_statement($1, 0, connection); }
-		| RemoveFuncStmt	{ output_statement($1, 0, connection); }
-		| RenameStmt		{ output_statement($1, 0, connection); }
-		| RevokeStmt		{ output_statement($1, 0, connection); }
-		| RevokeRoleStmt	{ output_statement($1, 0, connection); }
-		| RuleStmt			{ output_statement($1, 0, connection); }
-		| SelectStmt		{ output_statement($1, 1, connection); }
+		| DefineStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DeleteStmt		{ output_statement($1, 1, ECPGst_normal); }
+		| DiscardStmt		{ output_statement($1, 1, ECPGst_normal); }
+		| DropAssertStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| DropCastStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropGroupStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropOpClassStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| DropOpFamilyStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| DropOwnedStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropPLangStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropRoleStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropRuleStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropTableSpaceStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| DropTrigStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropUserStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| DropdbStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| ExplainStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| ExecuteStmt		{ output_statement($1, 0, ECPGst_execute); }
+		| FetchStmt		{ output_statement($1, 1, ECPGst_normal); }
+		| GrantStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| GrantRoleStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| IndexStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| InsertStmt		{ output_statement($1, 1, ECPGst_normal); }
+		| ListenStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| LoadStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| LockStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| NotifyStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| PrepareStmt		{ 
+						if ($1.type == NULL || strlen($1.type) == 0) /* use PQprepare without type parameters */
+							output_prepare_statement($1.name, $1.stmt);  
+						else	/* use PQexec and let backend do its stuff */
+						{
+							char *txt = cat_str(5, make_str("prepare"), $1.name, $1.type, make_str("as"), $1.stmt);
+							output_statement(txt, 0, ECPGst_normal);
+						}
+					}		
+		| ReassignOwnedStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| ReindexStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| RemoveAggrStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| RemoveOperStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| RemoveFuncStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| RenameStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| RevokeStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| RevokeRoleStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| RuleStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| SelectStmt		{ output_statement($1, 1, ECPGst_normal); }
 		| TransactionStmt
 		{
 			fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
 			whenever_action(2);
 			free($1);
 		}
-		| TruncateStmt		{ output_statement($1, 0, connection); }
-		| UnlistenStmt		{ output_statement($1, 0, connection); }
-		| UpdateStmt		{ output_statement($1, 1, connection); }
-		| VacuumStmt		{ output_statement($1, 0, connection); }
-		| VariableSetStmt	{ output_statement($1, 0, connection); }
-		| VariableShowStmt	{ output_statement($1, 0, connection); }
-		| VariableResetStmt	{ output_statement($1, 0, connection); }
-		| ViewStmt			{ output_statement($1, 0, connection); }
+		| TruncateStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| UnlistenStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| UpdateStmt		{ output_statement($1, 1, ECPGst_normal); }
+		| VacuumStmt		{ output_statement($1, 0, ECPGst_normal); }
+		| VariableSetStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| VariableShowStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| VariableResetStmt	{ output_statement($1, 0, ECPGst_normal); }
+		| ViewStmt		{ output_statement($1, 0, ECPGst_normal); }
 		| ECPGAllocateDescr
 		{
 			fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
@@ -812,14 +822,6 @@ stmt:  AlterDatabaseStmt		{ output_statement($1, 0, connection); }
 		{
 			output_simple_statement($1);
 		}
-		| ECPGDeallocate
-		{
-			if (connection)
-				mmerror(PARSE_ERROR, ET_ERROR, "no at option for deallocate statement.\n");
-			fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, %s);", compat, $1);
-			whenever_action(2);
-			free($1);
-		}
 		| ECPGDeallocateDescr
 		{
 			if (connection)
@@ -853,13 +855,13 @@ stmt:  AlterDatabaseStmt		{ output_statement($1, 0, connection); }
 			whenever_action(2);
 			free($1);
 		}
-		| ECPGExecute
-		{
-			output_statement($1, 0, connection);
-		}
+		| ECPGExecuteImmediateStmt	{ output_statement($1, 0, ECPGst_exec_immediate); }
 		| ECPGFree
 		{
-			fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, \"%s\");", compat, $1);
+			if (strcmp($1, "all"))
+				fprintf(yyout, "{ ECPGdeallocate(__LINE__, %d, \"%s\");", compat, $1);
+			else
+				fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d);", compat);
 
 			whenever_action(2);
 			free($1);
@@ -883,21 +885,11 @@ stmt:  AlterDatabaseStmt		{ output_statement($1, 0, connection); }
 
 			if ((ptr = add_additional_variables($1, true)) != NULL)
 			{
-				output_statement(mm_strdup(ptr->command), 0,
-								 ptr->connection ? mm_strdup(ptr->connection) : NULL);
+				connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
+				output_statement(mm_strdup(ptr->command), 0, 0);
 				ptr->opened = true;
 			}
 		}
-		| ECPGPrepare
-		{
-			if (connection)
-				mmerror(PARSE_ERROR, ET_ERROR, "no at option for prepare statement.\n");
-
-			fprintf(yyout, "{ ECPGprepare(__LINE__, %s);", $1);
-			whenever_action(2);
-			free($1);
-		}
-		/* | ECPGRelease		{ / * output already done * / } */
 		| ECPGSetAutocommit
 		{
 			fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
@@ -2274,19 +2266,44 @@ FetchStmt: FETCH fetch_direction from_in name ecpg_into
 		;
 
 fetch_direction:  NEXT			{ $$ = make_str("next"); }
-		| PRIOR					{ $$ = make_str("prior"); }
-		| FIRST_P				{ $$ = make_str("first"); }
-		| LAST_P				{ $$ = make_str("last"); }
-		| ABSOLUTE_P IntConst	{ $$ = cat2_str(make_str("absolute"), $2); }
-		| RELATIVE_P IntConst	{ $$ = cat2_str(make_str("relative"), $2); }
-		| IntConst				{ $$ = $1; }
-		| ALL					{ $$ = make_str("all"); }
-		| FORWARD				{ $$ = make_str("forward"); }
-		| FORWARD IntConst		{ $$ = cat2_str(make_str("forward"), $2); }
-		| FORWARD ALL			{ $$ = make_str("forward all"); }
-		| BACKWARD				{ $$ = make_str("backward"); }
-		| BACKWARD IntConst		{ $$ = cat2_str(make_str("backward"), $2); }
-		| BACKWARD ALL			{ $$ = make_str("backward all"); }
+		| PRIOR			{ $$ = make_str("prior"); }
+		| FIRST_P		{ $$ = make_str("first"); }
+		| LAST_P		{ $$ = make_str("last"); }
+		| ABSOLUTE_P IntConst	{ 
+					  if ($2[1] == '$')
+					  	 mmerror(PARSE_ERROR, ET_ERROR, "fetch/move count must not be a variable.\n");
+					  else
+					  	$$ = cat2_str(make_str("absolute"), $2);
+					}
+		| RELATIVE_P IntConst	{ 
+		                          if ($2[1] == '$')
+						mmerror(PARSE_ERROR, ET_ERROR, "fetch/move count must not be a variable.\n");
+					  else
+						$$ = cat2_str(make_str("relative"), $2);
+					}
+		| IntConst		{  
+		                          if ($1[1] == '$')
+						mmerror(PARSE_ERROR, ET_ERROR, "fetch/move count must not be a variable.\n");
+					  else
+						$$ = $1;
+					}
+		| ALL			{ $$ = make_str("all"); }
+		| FORWARD		{ $$ = make_str("forward"); }
+		| FORWARD IntConst	{  
+		                          if ($2[1] == '$')
+						mmerror(PARSE_ERROR, ET_ERROR, "fetch/move count must not be a variable.\n");
+					  else
+						$$ = cat2_str(make_str("forward"), $2);
+					}
+		| FORWARD ALL		{ $$ = make_str("forward all"); }
+		| BACKWARD		{ $$ = make_str("backward"); }
+		| BACKWARD IntConst	{  
+		                          if ($2[1] == '$')
+						mmerror(PARSE_ERROR, ET_ERROR, "fetch/move count must not be a variable.\n");
+					  else
+						$$ = cat2_str(make_str("backward"), $2);
+					}
+		| BACKWARD ALL		{ $$ = make_str("backward all"); }
 		;
 
 from_in: IN_P			{ $$ = make_str("in"); }
@@ -3193,19 +3210,25 @@ ExplainableStmt:
 		| UpdateStmt
 		| DeleteStmt
 		| DeclareCursorStmt
-		/* | ExecuteStmt */
+		| ExecuteStmt
 		;
 opt_analyze:
 		analyze_keyword                 { $$ = $1; }
 		| /* EMPTY */			{ $$ = EMPTY; }
 		;
 
-/*
-
-conflicts with ecpg
-
-PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
-		{ $$ = cat_str(5, make_str("prepare"), $2, $3, make_str("as"), $5); }
+PrepareStmt: PREPARE prepared_name prep_type_clause AS PreparableStmt
+		{
+			$$.name = $2;
+			$$.type = $3;
+			$$.stmt = cat_str(3, make_str("\""), $5, make_str("\""));
+		}
+		| PREPARE prepared_name FROM execstring /* ECPG addon */
+		{
+			$$.name = $2;
+			$$.type = NULL;
+			$$.stmt = $4;
+		}
 		;
 
 PreparableStmt:
@@ -3216,26 +3239,28 @@ PreparableStmt:
 		;
 
 prep_type_clause: '(' type_list ')'	{ $$ = cat_str(3, make_str("("), $2, make_str(")")); }
-		| /* EMPTY * /		{ $$ = EMPTY; }
+		| /* EMPTY */		{ $$ = EMPTY; }
 			;
 
-ExecuteStmt: EXECUTE name execute_param_clause
-			{ $$ = cat_str(3, make_str("execute"), $2, $3); }
+ExecuteStmt: EXECUTE prepared_name execute_param_clause execute_rest /* execute_rest is an ecpg addon */
+			{
+				/* $$ = cat_str(3, make_str("ECPGprepared_statement("), $2, make_str(", __LINE__)"));*/
+				$$ = $2;
+			}
 		| CREATE OptTemp TABLE create_as_target AS
-			EXECUTE name execute_param_clause
-			{ $$ = cat_str(11, make_str("create"), $2, make_str("table"), $4, $5, $6, $7, $8, make_str("as execute"), $11, $12); }
+			EXECUTE prepared_name execute_param_clause
+			{ $$ = cat_str(7, make_str("create"), $2, make_str("table"), $4,  make_str("as execute"), $7, $8); }
 		;
 
 execute_param_clause: '(' expr_list ')'	{ $$ = cat_str(3, make_str("("), $2, make_str(")")); }
-		| /* EMPTY * /		{ $$ = EMPTY; }
+		| /* EMPTY */		{ $$ = EMPTY; }
 		;
 
-DeallocateStmt: DEALLOCATE name		{ $$ = cat2_str(make_str("deallocate"), $2); }
-		| DEALLOCATE PREPARE name	{ $$ = cat2_str(make_str("deallocate prepare"), $3); }
-		| DEALLOCATE ALL		{ $$ = make_str("deallocate all"); }
-		| DEALLOCATE PREPARE ALL	{ $$ = make_str("deallocate prepare all"); }
+DeallocateStmt: DEALLOCATE prepared_name		{ $$ = $2; }
+		| DEALLOCATE PREPARE prepared_name	{ $$ = $3; }
+		| DEALLOCATE ALL			{ $$ = make_str("all"); }
+		| DEALLOCATE PREPARE ALL		{ $$ = make_str("all"); }
 		;
-*/
 
 /*****************************************************************************
  *
@@ -3733,11 +3758,11 @@ where_clause:  WHERE a_expr		{ $$ = cat2_str(make_str("where"), $2); }
 		| /*EMPTY*/				{ $$ = EMPTY;  /* no qualifiers */ }
 		;
 
-where_or_current_clause:  WHERE a_expr                  { $$ = cat2_str(make_str("where"), $2); }
-                | WHERE CURRENT_P OF name               { $$ = cat2_str(make_str("where current of"), $4); }
-                | WHERE CURRENT_P OF PARAM              { $$ = make_str("where current of param"); }
-                | /*EMPTY*/                             { $$ = EMPTY;  /* no qualifiers */ }
-                ;
+where_or_current_clause:  WHERE a_expr			{ $$ = cat2_str(make_str("where"), $2); }
+		| WHERE CURRENT_P OF name		{ $$ = cat2_str(make_str("where current of"), $4); }
+		| WHERE CURRENT_P OF PARAM		{ $$ = make_str("where current of param"); }
+		| /*EMPTY*/				{ $$ = EMPTY;  /* no qualifiers */ }
+		;
 
 TableFuncElementList: TableFuncElement
 			{ $$ = $1; }
@@ -4720,6 +4745,28 @@ Sconst:  SCONST
 			$$[strlen($1)+2]='\0';
 			free($1);
 		}
+	| ECONST
+		{
+			/* escaped quote starting with E */
+			$$ = (char *)mm_alloc(strlen($1) + 4);
+			$$[0]='E';
+			$$[1]='\'';
+			strcpy($$+2, $1);
+			$$[strlen($1)+2]='\'';
+			$$[strlen($1)+3]='\0';
+			free($1);
+		}
+	| NCONST
+		{
+			/* escaped quote starting with rNE */
+			$$ = (char *)mm_alloc(strlen($1) + 4);
+			$$[0]='N';
+			$$[1]='\'';
+			strcpy($$+2, $1);
+			$$[strlen($1)+2]='\'';
+			$$[strlen($1)+3]='\0';
+			free($1);
+		}
 	| DOLCONST
 		{
 			$$ = $1; 
@@ -4736,10 +4783,10 @@ IntConst:	PosIntConst		{ $$ = $1; }
 
 IntConstVar:	Iconst
 		{
-	        char *length = mm_alloc(32);
+	        	char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
 
 			sprintf(length, "%d", (int) strlen($1));
-			new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
+			new_variable($1, ECPGmake_simple_type(ECPGt_const, length, 0), 0);
 			$$ = $1;
 		}
 		| cvariable	{ $$ = $1; }
@@ -4747,39 +4794,39 @@ IntConstVar:	Iconst
 
 AllConstVar:	Fconst
 		{
-	        char *length = mm_alloc(32);
+		        char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
 
 			sprintf(length, "%d", (int) strlen($1));
-			new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
+			new_variable($1, ECPGmake_simple_type(ECPGt_const, length, 0), 0);
 			$$ = $1;
 		}
 		| IntConstVar		{ $$ = $1; }
 		| '-' Fconst
 		{
-	        char *length = mm_alloc(32);
+		        char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
 			char *var = cat2_str(make_str("-"), $2);
 
 			sprintf(length, "%d", (int) strlen(var));
-			new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
+			new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0);
 			$$ = var;
 		}
 		| '-' Iconst
 		{
-	        char *length = mm_alloc(32);
+		        char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
 			char *var = cat2_str(make_str("-"), $2);
 
 			sprintf(length, "%d", (int) strlen(var));
-			new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
+			new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0);
 			$$ = var;
 		}
 		| Sconst
 		{
-	        char *length = mm_alloc(32);
+		        char *length = mm_alloc(sizeof(int) * CHAR_BIT * 10 / 3);
 			char *var = $1 + 1;
 
 			var[strlen(var) - 1] = '\0';
 			sprintf(length, "%d", (int) strlen(var));
-			new_variable(var, ECPGmake_simple_type(ECPGt_const, length), 0);
+			new_variable(var, ECPGmake_simple_type(ECPGt_const, length, 0), 0);
 			$$ = var;
 		}
 		;
@@ -5047,14 +5094,14 @@ ECPGCursorStmt:  DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
 			this->next = cur;
 			this->name = $2;
 			this->connection = connection;
-			this->command =  cat_str(6, make_str("declare"), mm_strdup($2), $3, make_str("cursor"), $5, make_str("for ?"));
+			this->command =  cat_str(6, make_str("declare"), mm_strdup($2), $3, make_str("cursor"), $5, make_str("for $1"));
 			this->argsresult = NULL;
 
 			thisquery->type = &ecpg_query;
 			thisquery->brace_level = 0;
 			thisquery->next = NULL;
-			thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($7));
-			sprintf(thisquery->name, "ECPGprepared_statement(%s)", $7);
+			thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(, __LINE__)") + strlen($7));
+			sprintf(thisquery->name, "ECPGprepared_statement(%s, __LINE__)", $7);
 
 			this->argsinsert = NULL;
 			add_variable_to_head(&(this->argsinsert), thisquery, &no_indicator);
@@ -5065,16 +5112,12 @@ ECPGCursorStmt:  DECLARE name cursor_options CURSOR opt_hold FOR prepared_name
 		}
 		;
 
-/*
- * the exec sql deallocate prepare command to deallocate a previously
- * prepared statement
- */
-ECPGDeallocate: DEALLOCATE PREPARE prepared_name
-			{ $$ = $3; }
-		| DEALLOCATE prepared_name
-			{ $$ = $2; }
-		;
-
+ECPGExecuteImmediateStmt: EXECUTE IMMEDIATE execstring
+			{ 
+			  /* execute immediate means prepare the statement and
+			   * immediately execute it */
+			  $$ = $3;
+			};
 /*
  * variable decalartion outside exec sql declare block
  */
@@ -5418,7 +5461,11 @@ var_type:	simple_type
 				$$.type_enum = this->type->type_enum;
 				$$.type_dimension = this->type->type_dimension;
 				$$.type_index = this->type->type_index;
-				$$.type_sizeof = this->type->type_sizeof;
+				if (this->type->type_sizeof && strlen(this->type->type_sizeof) != 0)
+					$$.type_sizeof = this->type->type_sizeof;
+				else 
+					$$.type_sizeof = cat_str(3, make_str("sizeof("), mm_strdup(this->name), make_str(")"));
+
 				struct_member_list[struct_level] = ECPGstruct_member_dup(this->struct_member_list);
 			}
 		}
@@ -5626,6 +5673,7 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
 			char *dimension = $3.index1; /* dimension of array */
 			char *length = $3.index2;    /* length of string */
 			char dim[14L];
+			char *vcn;
 
 			adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1), false);
 
@@ -5643,10 +5691,10 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
 
 				case ECPGt_varchar:
 					if (atoi(dimension) < 0)
-						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
+						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, yylineno);
 					else
-						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
-
+						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, yylineno), dimension);
+					
 					if (strcmp(dimension, "0") == 0 || abs(atoi(dimension)) == 1)
 							*dim = '\0';
 					else
@@ -5655,10 +5703,13 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
 					if (atoi(length) < 0 || strcmp(length, "0") == 0)
 						mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented");
 
+					/* make sure varchar struct name is unique by adding linenumer of its definition */
+					vcn = (char *) mm_alloc(strlen($2) + sizeof(int) * CHAR_BIT * 10 / 3);
+					sprintf(vcn, "%s_%d", $2, yylineno);
 					if (strcmp(dimension, "0") == 0)
-						$$ = cat_str(7, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4, $5);
+						$$ = cat_str(7, make2_str(make_str(" struct varchar_"), vcn), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4, $5);
 					else
-						$$ = cat_str(8, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4, $5);
+						$$ = cat_str(8, make2_str(make_str(" struct varchar_"), vcn), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4, $5);
 					break;
 
 				case ECPGt_char:
@@ -5674,19 +5725,19 @@ variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initialize
 							length = mm_alloc(i+sizeof("sizeof()"));
 							sprintf(length, "sizeof(%s)", $5+2);
 						}
-						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
+						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length, 0);
 					}
 					else
-						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
+						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length, 0), dimension);
 
 					$$ = cat_str(5, $1, mm_strdup($2), $3.str, $4, $5);
 					break;
 
 				default:
 					if (atoi(dimension) < 0)
-						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1"));
+						type = ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1"), 0);
 					else
-						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1")), dimension);
+						type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, make_str("1"), 0), dimension);
 
 					$$ = cat_str(5, $1, mm_strdup($2), $3.str, $4, $5);
 					break;
@@ -5741,40 +5792,6 @@ connection_object: database_name		{ $$ = make3_str(make_str("\""), $1, make_str(
 		| char_variable			{ $$ = $1; }
 		;
 
-/*
- * execute a given string as sql command
- */
-ECPGExecute : EXECUTE IMMEDIATE execstring
-		{
-			struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
-
-			thisquery->type = &ecpg_query;
-			thisquery->brace_level = 0;
-			thisquery->next = NULL;
-			thisquery->name = $3;
-
-			add_variable_to_head(&argsinsert, thisquery, &no_indicator);
-
-			$$ = make_str("?");
-		}
-		| EXECUTE prepared_name
-		{
-			struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
-
-			thisquery->type = &ecpg_query;
-			thisquery->brace_level = 0;
-			thisquery->next = NULL;
-			thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement()") + strlen($2));
-			sprintf(thisquery->name, "ECPGprepared_statement(%s)", $2);
-
-			add_variable_to_head(&argsinsert, thisquery, &no_indicator);
-		}
-		execute_rest
-		{
-			$$ = make_str("?");
-		}
-		;
-
 execute_rest:	ecpg_using ecpg_into	{ $$ = EMPTY; }
 		| ecpg_into ecpg_using	{ $$ = EMPTY; }
 		| ecpg_using		{ $$ = EMPTY; }
@@ -5788,7 +5805,19 @@ execstring: char_variable
 			{ $$ = make3_str(make_str("\""), $1, make_str("\"")); }
 		;
 
-prepared_name: name	 	{ $$ = make3_str(make_str("\""), $1, make_str("\"")); }
+prepared_name: name	 	{ 
+					if ($1[0] == '\"' && $1[strlen($1)-1] == '\"') /* already quoted? */
+						$$ = $1;
+					else /* not quoted => convert to lowercase */
+					{
+						int i;
+
+						for (i = 0; i< strlen($1); i++)
+							$1[i] = tolower($1[i]);
+
+						$$ = make3_str(make_str("\""), $1, make_str("\""));
+					}
+				}
 		| char_variable	{ $$ = $1; }
 		;
 
@@ -5796,7 +5825,9 @@ prepared_name: name	 	{ $$ = make3_str(make_str("\""), $1, make_str("\"")); }
  * the exec sql free command to deallocate a previously
  * prepared statement
  */
-ECPGFree:	SQL_FREE name	{ $$ = $2; };
+ECPGFree:	SQL_FREE name	{ $$ = $2; }
+		| SQL_FREE ALL	{ $$ = make_str("all"); }
+		;
 
 /*
  * open is an open cursor, at the moment this has to be removed
@@ -5835,26 +5866,17 @@ using_list: UsingConst | UsingConst ',' using_list;
 
 UsingConst: AllConst
 		{
-			if ($1[1] != '?') /* found a constant */
+			if ($1[1] != '$') /* found a constant */
 			{
 				char *length = mm_alloc(32);
 
 				sprintf(length, "%d", (int) strlen($1));
-				add_variable_to_head(&argsinsert, new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0), &no_indicator);
+				add_variable_to_head(&argsinsert, new_variable($1, ECPGmake_simple_type(ECPGt_const, length, 0), 0), &no_indicator);
 			}
 		}
 		| civarind { $$ = EMPTY; }
 		;
 
-/*
- * As long as the prepare statement is not supported by the backend, we will
- * try to simulate it here so we get dynamic SQL
- *
- * It is supported now but not usable yet by ecpg.
- */
-ECPGPrepare: PREPARE prepared_name FROM execstring
-			{ $$ = cat_str(3, $2, make_str(","), $4); }
-		;
 
 /*
  * We accept descibe but do nothing with it so far.
@@ -5862,20 +5884,20 @@ ECPGPrepare: PREPARE prepared_name FROM execstring
 ECPGDescribe: SQL_DESCRIBE INPUT_P name using_descriptor
 	{
 		mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
-		$$ = (char *) mm_alloc(sizeof("1, ECPGprepared_statement(\"\")") + strlen($3));
-		sprintf($$, "1, ECPGprepared_statement(\"%s\")", $3);
+		$$ = (char *) mm_alloc(sizeof("1, ECPGprepared_statement(\"\", __LINE__)") + strlen($3));
+		sprintf($$, "1, ECPGprepared_statement(\"%s\", __LINE__)", $3);
 	}
 	| SQL_DESCRIBE opt_output name using_descriptor
 	{
 		mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
-		$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\")") + strlen($3));
-		sprintf($$, "0, ECPGprepared_statement(\"%s\")", $3);
+		$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\", __LINE__)") + strlen($3));
+		sprintf($$, "0, ECPGprepared_statement(\"%s\", __LINE__)", $3);
 	}
 	| SQL_DESCRIBE opt_output name into_descriptor
 	{
 		mmerror(PARSE_ERROR, ET_WARNING, "using unsupported describe statement.\n");
-		$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\")") + strlen($3));
-		sprintf($$, "0, ECPGprepared_statement(\"%s\")", $3);
+		$$ = (char *) mm_alloc(sizeof("0, ECPGprepared_statement(\"\", __LINE__)") + strlen($3));
+		sprintf($$, "0, ECPGprepared_statement(\"%s\", __LINE__)", $3);
 	}
 	;
 
@@ -5992,29 +6014,6 @@ descriptor_item:	SQL_CARDINALITY			{ $$ = ECPGd_cardinality; }
 		| TYPE_P				{ $$ = ECPGd_type; }
 		;
 
-
-/*
- * for compatibility with ORACLE we will also allow the keyword RELEASE
- * after a transaction statement to disconnect from the database.
- */
-
-/* We cannot do that anymore since it causes shift/reduce conflicts. 2004-09-27 Michael Meskes
-ECPGRelease: TransactionStmt RELEASE
-		{
-			if (strcmp($1, "begin") == 0)
-							mmerror(PARSE_ERROR, ET_ERROR, "RELEASE does not make sense when beginning a transaction");
-
-			fprintf(yyout, "ECPGtrans(__LINE__, %s, \"%s\");",
-					connection ? connection : "NULL", $1);
-			whenever_action(0);
-			fprintf(yyout, "ECPGdisconnect(__LINE__, %s);",
-					connection ? connection : "\"CURRENT\"");
-			whenever_action(0);
-			free($1);
-		}
-		;
-*/
-
 /*
  * set/reset the automatic transaction mode, this needs a differnet handling
  * as the other set commands
@@ -6138,17 +6137,17 @@ ECPGVar: SQL_VAR
 
 					case ECPGt_varchar:
 						if (atoi(dimension) == -1)
-							type = ECPGmake_simple_type($5.type_enum, length);
+							type = ECPGmake_simple_type($5.type_enum, length, 0);
 						else
-							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
+							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length, 0), dimension);
 						break;
 
 					case ECPGt_char:
 					case ECPGt_unsigned_char:
 						if (atoi(dimension) == -1)
-							type = ECPGmake_simple_type($5.type_enum, length);
+							type = ECPGmake_simple_type($5.type_enum, length, 0);
 						else
-							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length), dimension);
+							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, length, 0), dimension);
 						break;
 
 					default:
@@ -6156,9 +6155,9 @@ ECPGVar: SQL_VAR
 							mmerror(PARSE_ERROR, ET_ERROR, "No multidimensional array support for simple data types");
 
 						if (atoi(dimension) < 0)
-							type = ECPGmake_simple_type($5.type_enum, make_str("1"));
+							type = ECPGmake_simple_type($5.type_enum, make_str("1"), 0);
 						else
-							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, make_str("1")), dimension);
+							type = ECPGmake_array_type(ECPGmake_simple_type($5.type_enum, make_str("1"), 0), dimension);
 						break;
 				}
 
@@ -6820,7 +6819,10 @@ reserved_keyword:
 into_list : coutputvariable | into_list ',' coutputvariable
 		;
 
-ecpgstart: SQL_START	{ reset_variables(); }
+ecpgstart: SQL_START	{
+				reset_variables();
+				pacounter = 1;
+			}
 		;
 
 c_args: /*EMPTY*/		{ $$ = EMPTY; }
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 34dce75e896f477e4e0f6a1facf634185c8bcc25..464c54ed648ea7f07beab32034b2e1e0eb981f72 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.72 2007/03/17 19:25:23 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/type.c,v 1.73 2007/08/14 10:01:53 meskes Exp $ */
 
 #include "postgres_fe.h"
 
@@ -57,10 +57,10 @@ ECPGstruct_member_dup(struct ECPGstruct_member * rm)
 				if (rm->type->u.element->type == ECPGt_struct)
 					type = ECPGmake_struct_type(rm->type->u.element->u.members, rm->type->u.element->type, rm->type->u.element->struct_sizeof);
 				else
-					type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size), rm->type->size);
+					type = ECPGmake_array_type(ECPGmake_simple_type(rm->type->u.element->type, rm->type->u.element->size, rm->type->u.element->lineno), rm->type->size);
 				break;
 			default:
-				type = ECPGmake_simple_type(rm->type->type, rm->type->size);
+				type = ECPGmake_simple_type(rm->type->type, rm->type->size, rm->type->lineno);
 				break;
 		}
 
@@ -93,7 +93,7 @@ ECPGmake_struct_member(char *name, struct ECPGtype * type, struct ECPGstruct_mem
 }
 
 struct ECPGtype *
-ECPGmake_simple_type(enum ECPGttype type, char *size)
+ECPGmake_simple_type(enum ECPGttype type, char *size, int lineno)
 {
 	struct ECPGtype *ne = (struct ECPGtype *) mm_alloc(sizeof(struct ECPGtype));
 
@@ -101,6 +101,7 @@ ECPGmake_simple_type(enum ECPGttype type, char *size)
 	ne->size = size;
 	ne->u.element = NULL;
 	ne->struct_sizeof = NULL;
+	ne->lineno = lineno; /* only needed for varchar */
 
 	return ne;
 }
@@ -108,7 +109,7 @@ ECPGmake_simple_type(enum ECPGttype type, char *size)
 struct ECPGtype *
 ECPGmake_array_type(struct ECPGtype * type, char *size)
 {
-	struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size);
+	struct ECPGtype *ne = ECPGmake_simple_type(ECPGt_array, size, 0);
 
 	ne->u.element = type;
 
@@ -118,7 +119,7 @@ ECPGmake_array_type(struct ECPGtype * type, char *size)
 struct ECPGtype *
 ECPGmake_struct_type(struct ECPGstruct_member * rm, enum ECPGttype type, char *struct_sizeof)
 {
-	struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1"));
+	struct ECPGtype *ne = ECPGmake_simple_type(type, make_str("1"), 0);
 
 	ne->u.members = ECPGstruct_member_dup(rm);
 	ne->struct_sizeof = struct_sizeof;
@@ -222,7 +223,7 @@ get_type(enum ECPGttype type)
  */
 static void ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 				  char *varcharsize,
-				  char *arrsiz, const char *siz, const char *prefix);
+				  char *arrsiz, const char *siz, const char *prefix, int);
 static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
 				  struct ECPGtype * type, struct ECPGtype * ind_type, const char *offset, const char *prefix, const char *ind_prefix);
 
@@ -258,16 +259,16 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
 
 					ECPGdump_a_simple(o, name,
 									  type->u.element->type,
-							type->u.element->size, type->size, NULL, prefix);
+							type->u.element->size, type->size, NULL, prefix, type->lineno);
 
 					if (ind_type != NULL)
 					{
 						if (ind_type->type == ECPGt_NO_INDICATOR)
-							ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
+							ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix, 0);
 						else
 						{
 							ECPGdump_a_simple(o, ind_name, ind_type->u.element->type,
-											  ind_type->u.element->size, ind_type->size, NULL, ind_prefix);
+											  ind_type->u.element->size, ind_type->size, NULL, ind_prefix, 0);
 						}
 					}
 			}
@@ -285,25 +286,25 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
 			if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
 				mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
 
-			ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix);
+			ECPGdump_a_simple(o, name, type->type, make_str("1"), (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("1"), struct_sizeof, prefix, 0);
 			if (ind_type != NULL)
-				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
+				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix, 0);
 			break;
 		case ECPGt_descriptor:
 			if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
 				mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
 
-			ECPGdump_a_simple(o, name, type->type, NULL, make_str("-1"), NULL, prefix);
+			ECPGdump_a_simple(o, name, type->type, NULL, make_str("-1"), NULL, prefix, 0);
 			if (ind_type != NULL)
-				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix);
+				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, make_str("-1"), NULL, ind_prefix, 0);
 			break;
 		default:
 			if (indicator_set && (ind_type->type == ECPGt_struct || ind_type->type == ECPGt_array))
 				mmerror(INDICATOR_NOT_SIMPLE, ET_FATAL, "Indicator for simple datatype has to be simple.\n");
 
-			ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix);
+			ECPGdump_a_simple(o, name, type->type, type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), struct_sizeof, prefix, type->lineno);
 			if (ind_type != NULL)
-				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix);
+				ECPGdump_a_simple(o, ind_name, ind_type->type, ind_type->size, (arr_str_siz && strcmp(arr_str_siz, "0") != 0) ? arr_str_siz : make_str("-1"), ind_struct_sizeof, ind_prefix, 0);
 			break;
 	}
 }
@@ -316,8 +317,8 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 				  char *varcharsize,
 				  char *arrsize,
 				  const char *siz,
-				  const char *prefix
-)
+				  const char *prefix,
+				  int lineno)
 {
 	if (type == ECPGt_NO_INDICATOR)
 		fprintf(o, "\n\tECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ");
@@ -327,7 +328,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 	else
 	{
 		char	   *variable = (char *) mm_alloc(strlen(name) + ((prefix == NULL) ? 0 : strlen(prefix)) + 4);
-		char	   *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize));
+		char	   *offset = (char *) mm_alloc(strlen(name) + strlen("sizeof(struct varchar_)") + 1 + strlen(varcharsize)+ sizeof(int) * CHAR_BIT * 10 / 3);
 
 		switch (type)
 		{
@@ -349,7 +350,10 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 				else
 					sprintf(variable, "&(%s%s)", prefix ? prefix : "", name);
 
-				sprintf(offset, "sizeof(struct varchar_%s)", name);
+				if (lineno)
+					sprintf(offset, "sizeof(struct varchar_%s_%d)", name, lineno);
+				else
+					sprintf(offset, "sizeof(struct varchar_%s)", name);
 				break;
 			case ECPGt_char:
 			case ECPGt_unsigned_char:
@@ -430,7 +434,7 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
 		if (atoi(arrsize) < 0)
 			strcpy(arrsize, "1");
 
-		if (siz == NULL || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
+		if (siz == NULL || strlen(siz) == 0 || strcmp(arrsize, "0") == 0 || strcmp(arrsize, "1") == 0)
 			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, offset);
 		else
 			fprintf(o, "\n\t%s,%s,(long)%s,(long)%s,%s, ", get_type(type), variable, varcharsize, arrsize, siz);
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index 020e6b4fdec1d57cdf97913d002ed0fe7f57813b..f28c0538aa35ac9b8242c4afe4180a5931328cc9 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -25,11 +25,12 @@ struct ECPGtype
 		struct ECPGstruct_member *members;		/* A pointer to a list of
 												 * members. */
 	}			u;
+	int	lineno;
 };
 
 /* Everything is malloced. */
 void		ECPGmake_struct_member(char *, struct ECPGtype *, struct ECPGstruct_member **);
-struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *);
+struct ECPGtype *ECPGmake_simple_type(enum ECPGttype, char *, int);
 struct ECPGtype *ECPGmake_varchar_type(enum ECPGttype, long);
 struct ECPGtype *ECPGmake_array_type(struct ECPGtype *, char *);
 struct ECPGtype *ECPGmake_struct_type(struct ECPGstruct_member *, enum ECPGttype, char *);
@@ -94,6 +95,13 @@ struct su_symbol
 	char	   *symbol;
 };
 
+struct prep
+{
+	char	*name;
+	char 	*stmt;
+	char	*type;
+};
+
 struct this_type
 {
 	enum ECPGttype type_enum;
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index 4ab2a62bb9e4da575776f4e4cbfb1546e276b378..0dadd9c866afc8b0dea2371ae7e2601fa3ecd084 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.41 2006/07/30 16:28:58 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.42 2007/08/14 10:01:53 meskes Exp $ */
 
 #include "postgres_fe.h"
 
@@ -44,12 +44,12 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
 				switch (members->type->type)
 				{
 					case ECPGt_array:
-						return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(members->type->u.element->type, members->type->u.element->size), members->type->size), brace_level));
+						return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(members->type->u.element->type, members->type->u.element->size, members->type->u.element->lineno), members->type->size), brace_level));
 					case ECPGt_struct:
 					case ECPGt_union:
 						return (new_variable(name, ECPGmake_struct_type(members->type->u.members, members->type->type, members->type->struct_sizeof), brace_level));
 					default:
-						return (new_variable(name, ECPGmake_simple_type(members->type->type, members->type->size), brace_level));
+						return (new_variable(name, ECPGmake_simple_type(members->type->type, members->type->size, members->type->lineno), brace_level));
 				}
 			}
 			else
@@ -91,12 +91,12 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
 						switch (members->type->u.element->type)
 						{
 							case ECPGt_array:
-								return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(members->type->u.element->u.element->type, members->type->u.element->u.element->size), members->type->u.element->size), brace_level));
+								return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(members->type->u.element->u.element->type, members->type->u.element->u.element->size, members->type->u.element->u.element->lineno), members->type->u.element->size), brace_level));
 							case ECPGt_struct:
 							case ECPGt_union:
 								return (new_variable(name, ECPGmake_struct_type(members->type->u.element->u.members, members->type->u.element->type, members->type->u.element->struct_sizeof), brace_level));
 							default:
-								return (new_variable(name, ECPGmake_simple_type(members->type->u.element->type, members->type->u.element->size), brace_level));
+								return (new_variable(name, ECPGmake_simple_type(members->type->u.element->type, members->type->u.element->size, members->type->u.element->lineno), brace_level));
 						}
 						break;
 					case '-':
@@ -232,12 +232,12 @@ find_variable(char *name)
 				switch (p->type->u.element->type)
 				{
 					case ECPGt_array:
-						return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size), p->type->u.element->size), p->brace_level));
+						return (new_variable(name, ECPGmake_array_type(ECPGmake_simple_type(p->type->u.element->u.element->type, p->type->u.element->u.element->size, p->type->u.element->u.element->lineno), p->type->u.element->size), p->brace_level));
 					case ECPGt_struct:
 					case ECPGt_union:
 						return (new_variable(name, ECPGmake_struct_type(p->type->u.element->u.members, p->type->u.element->type, p->type->u.element->struct_sizeof), p->brace_level));
 					default:
-						return (new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size), p->brace_level));
+						return (new_variable(name, ECPGmake_simple_type(p->type->u.element->type, p->type->u.element->size, p->type->u.element->u.element->lineno), p->brace_level));
 				}
 			}
 		}
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index 491cd2ff01e5a5a94a030fb1b320de804b5618a5..bac7783f2c7f32804d53d1ca7dd89b367b7a9825 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.71 2007/06/15 08:23:52 meskes Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.72 2007/08/14 10:01:53 meskes Exp $
 
 subdir = src/interfaces/ecpg/test
 top_builddir = ../../../..
@@ -6,7 +6,7 @@ include $(top_builddir)/src/Makefile.global
 
 # port number for temp-installation test postmaster
 # this is also defined in test/connect/Makefile
-TEMP_PORT = 5$(DEF_PGPORT)
+TEMP_PORT = 4$(DEF_PGPORT)
 
 # where to find psql for testing an existing installation
 PSQLDIR = $(bindir)
diff --git a/src/interfaces/ecpg/test/compat_informix/dec_test.pgc b/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
index 02e48b56ce6afc596ad5ed8fb64412a0194866ed..d1a01b556dd42dc301aa073310dd2b82549fd1fc 100644
--- a/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/dec_test.pgc
@@ -236,5 +236,4 @@ check_errno(void)
 			printf("(libc: (%s)) ", strerror(errno));
 			break;
 	}
-
 }
diff --git a/src/interfaces/ecpg/test/compat_informix/rnull.pgc b/src/interfaces/ecpg/test/compat_informix/rnull.pgc
index e661afa430cd5fb6dd0a034ad5c0d6deb3ec6618..aa3e0823c5571173077f3d30a33a639d0fb7e036 100644
--- a/src/interfaces/ecpg/test/compat_informix/rnull.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/rnull.pgc
@@ -12,7 +12,7 @@ test_null(int type, char *ptr)
 
 int main(void)
 {
-	$char c[] = "abc       ";
+	$char c[] = "abc";
 	$short s = 17;
 	$int i = -74874;
 	$bool b = 1;
diff --git a/src/interfaces/ecpg/test/compat_informix/test_informix.pgc b/src/interfaces/ecpg/test/compat_informix/test_informix.pgc
index 744eded5745a5fd2257f6f56c46d543768d16a2f..51ac48eda11a22d790453ac42e7d09186a78aff7 100644
--- a/src/interfaces/ecpg/test/compat_informix/test_informix.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/test_informix.pgc
@@ -69,7 +69,7 @@ int main(void)
 	deccvint(7, &j);
 	deccvint(14, &m);
 	decadd(&j, &m, &n);
-	$delete from test where i=:n;
+	$delete from test where i= :n::decimal;
 	printf("DELETE: %ld\n", sqlca.sqlcode);
 
 	$select 1 from test where i=14;
diff --git a/src/interfaces/ecpg/test/compat_informix/test_informix2.pgc b/src/interfaces/ecpg/test/compat_informix/test_informix2.pgc
index 1f015927ffce6a7f85cc858dee8ff069bc775e42..9b324e25e874c029b8d44ad1e40300e23e38680f 100644
--- a/src/interfaces/ecpg/test/compat_informix/test_informix2.pgc
+++ b/src/interfaces/ecpg/test/compat_informix/test_informix2.pgc
@@ -89,7 +89,7 @@ int main(void)
 
 	intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
 	PGTYPEStimestamp_add_interval(&d, intvl, &e);
-
+	free(intvl);
 	c++;
 
 	EXEC SQL insert into history
diff --git a/src/interfaces/ecpg/test/connect/Makefile b/src/interfaces/ecpg/test/connect/Makefile
index ab3750a47f94d01645a4977e4a26639ad47ca204..1e2d9f2e3eae9c9588132aa4a5340886448f5eff 100644
--- a/src/interfaces/ecpg/test/connect/Makefile
+++ b/src/interfaces/ecpg/test/connect/Makefile
@@ -5,7 +5,7 @@ include $(top_srcdir)/$(subdir)/../Makefile.regress
 
 # port number for temp-installation test postmaster
 # this is also defined in ../Makefile
-TEMP_PORT = 5$(DEF_PGPORT)
+TEMP_PORT = 4$(DEF_PGPORT)
 
 test1.pgc: test1.pgc.in
 	sed -e 's,@TEMP_PORT@,$(TEMP_PORT),g' \
diff --git a/src/interfaces/ecpg/test/ecpg_schedule b/src/interfaces/ecpg/test/ecpg_schedule
index 108881c49e94ef55596468424ebc354b8fe2010a..4df5d088deb6ff505c82a28ae8932c5f4bf2eb47 100644
--- a/src/interfaces/ecpg/test/ecpg_schedule
+++ b/src/interfaces/ecpg/test/ecpg_schedule
@@ -13,6 +13,8 @@ test: pgtypeslib/dt_test
 test: pgtypeslib/dt_test2
 test: pgtypeslib/num_test
 test: pgtypeslib/num_test2
+test: preproc/array_of_struct
+test: preproc/autoprep
 test: preproc/comment
 test: preproc/define
 test: preproc/init
@@ -32,6 +34,7 @@ test: sql/execute
 test: sql/fetch
 test: sql/func
 test: sql/indicators
+test: sql/oldexec
 test: sql/quote
 test: sql/show
 test: sql/insupd
diff --git a/src/interfaces/ecpg/test/ecpg_schedule_tcp b/src/interfaces/ecpg/test/ecpg_schedule_tcp
index 62c26a1cabdc05cde4973065202fec82dd6bd1e7..03703a0d06a0a19cbd96c28144e6dc7d9085580a 100644
--- a/src/interfaces/ecpg/test/ecpg_schedule_tcp
+++ b/src/interfaces/ecpg/test/ecpg_schedule_tcp
@@ -13,6 +13,8 @@ test: pgtypeslib/dt_test
 test: pgtypeslib/dt_test2
 test: pgtypeslib/num_test
 test: pgtypeslib/num_test2
+test: preproc/array_of_struct
+test: preproc/autoprep
 test: preproc/comment
 test: preproc/define
 test: preproc/init
@@ -32,6 +34,7 @@ test: sql/execute
 test: sql/fetch
 test: sql/func
 test: sql/indicators
+test: sql/oldexec
 test: sql/quote
 test: sql/show
 test: sql/insupd
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
index 35cd43282001e178453c064fc824d912b87f43b9..071174c1bde45ecc2ea510c55023b75ca8964723 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
@@ -257,5 +257,4 @@ check_errno(void)
 			printf("(libc: (%s)) ", strerror(errno));
 			break;
 	}
-
 }
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
index a70e154f498fb15644147b444d3a94651fdd57af..c18d2edaf9a87c70e3820fd7e2d14efc3ef52f09 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
@@ -35,7 +35,7 @@ int main(void)
 {
 	
 #line 15 "rnull.pgc"
- char  c []   = "abc       " ;
+ char  c []   = "abc" ;
 
 #line 15 "rnull.pgc"
 
@@ -106,7 +106,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 29 "rnull.pgc"
 
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "create  table test ( id int   , c char  ( 10 )    , s smallint   , i int   , b bool    , f float    , l bigint   , dbl double precision   , dec decimal    , dat date    , tmp timestamptz    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "create  table test ( id int   , c char  ( 10 )    , s smallint   , i int   , b bool    , f float    , l bigint   , dbl double precision   , dec decimal    , dat date    , tmp timestamptz    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 33 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -119,8 +119,8 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 34 "rnull.pgc"
 
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  ) values ( 1 ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ) ", 
-	ECPGt_char,(c),(long)sizeof("abc       "),(long)1,(sizeof("abc       "))*sizeof(char), 
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  ) values ( 1 ,  $1  ,  $2  ,  $3  ,  $4  ,  $5  ,  $6  ,  $7  ) ", 
+	ECPGt_char,(c),(long)sizeof("abc"),(long)1,(sizeof("abc"))*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(s),(long)1,(long)1,sizeof(short), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
@@ -157,8 +157,8 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 	rsetnull(CDATETYPE, (char *) &dat);
 	rsetnull(CDTIMETYPE, (char *) &tmp);
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  , dec  , dat  , tmp  ) values ( 2 ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ,  ? ) ", 
-	ECPGt_char,(c),(long)sizeof("abc       "),(long)1,(sizeof("abc       "))*sizeof(char), 
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  , dec  , dat  , tmp  ) values ( 2 ,  $1  ,  $2  ,  $3  ,  $4  ,  $5  ,  $6  ,  $7  ,  $8  ,  $9  ,  $10  ) ", 
+	ECPGt_char,(c),(long)sizeof("abc"),(long)1,(sizeof("abc"))*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(s),(long)1,(long)1,sizeof(short), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
@@ -192,8 +192,8 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
 	printf("first select\n");
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 1  ", ECPGt_EOIT, 
-	ECPGt_char,(c),(long)sizeof("abc       "),(long)1,(sizeof("abc       "))*sizeof(char), 
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 1  ", ECPGt_EOIT, 
+	ECPGt_char,(c),(long)sizeof("abc"),(long)1,(sizeof("abc"))*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(s),(long)1,(long)1,sizeof(short), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
@@ -232,8 +232,8 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
 	printf("second select\n");
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 2  ", ECPGt_EOIT, 
-	ECPGt_char,(c),(long)sizeof("abc       "),(long)1,(sizeof("abc       "))*sizeof(char), 
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 2  ", ECPGt_EOIT, 
+	ECPGt_char,(c),(long)sizeof("abc"),(long)1,(sizeof("abc"))*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(s),(long)1,(long)1,sizeof(short), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
@@ -270,7 +270,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 	test_null(CDATETYPE, (char *) &dat);
 	test_null(CDTIMETYPE, (char *) &tmp);
 
-	{ ECPGdo(__LINE__, 1, 0, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 0, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
 #line 91 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr b/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
index b1bce4b81aa249738da3ce903cfdfb69166d2d65..2a8290df3bce5433ae7a8a69471d6200a7aa9b01 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
+++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.stderr
@@ -2,25 +2,67 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: create  table test ( id int   , c char  ( 10 )    , s smallint   , i int   , b bool    , f float    , l bigint   , dbl double precision   , dec decimal    , dat date    , tmp timestamptz    )     on connection regress1
+[NO_PID]: ECPGexecute line 31: QUERY: create  table test ( id int   , c char  ( 10 )    , s smallint   , i int   , b bool    , f float    , l bigint   , dbl double precision   , dec decimal    , dat date    , tmp timestamptz    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 31 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 34 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  ) values ( 1 ,  'abc       ' ,  17 ,  -74874 ,  't' ,  3.710000038147 ,  487444 ,  404.404 )  on connection regress1
+[NO_PID]: ECPGexecute line 36: QUERY: insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  ) values ( 1 ,  $1  ,  $2  ,  $3  ,  $4  ,  $5  ,  $6  ,  $7  )  with 7 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 1 = abc
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 2 = 17
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 3 = -74874
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 4 = t
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 5 = 3.710000038147
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 6 = 487444
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: parameter 7 = 404.404
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 36 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 39 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 52: QUERY: insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  , dec  , dat  , tmp  ) values ( 2 ,  null ,  null ,  null ,  't' ,  null ,  null ,  null ,  null ,  null ,  null )  on connection regress1
+[NO_PID]: ECPGexecute line 52: QUERY: insert into test ( id  , c  , s  , i  , b  , f  , l  , dbl  , dec  , dat  , tmp  ) values ( 2 ,  $1  ,  $2  ,  $3  ,  $4  ,  $5  ,  $6  ,  $7  ,  $8  ,  $9  ,  $10  )  with 10 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 1 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 2 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 3 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 4 = t
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 5 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 6 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 7 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 8 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 9 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: parameter 10 = null
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 52 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 55 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 59: QUERY: select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 1   on connection regress1
+[NO_PID]: ECPGexecute line 59: QUERY: select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 1   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 59: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 59: Correctly got 1 tuples with 10 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -44,7 +86,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 59: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 76: QUERY: select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 2   on connection regress1
+[NO_PID]: ECPGexecute line 76: QUERY: select  c , s , i , b , f , l , dbl , dec , dat , tmp  from test where id = 2   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 76: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 76: Correctly got 1 tuples with 10 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -68,7 +112,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 76: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 91: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 91: QUERY: drop table test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 91: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 91 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
index e05f009094d83211c26e4a675e6d00884d3a7508..19aa0074e0c64ba19d59147f39d8c746e75f1d17 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
@@ -58,7 +58,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 	if (sqlca.sqlcode != 0) exit(1);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "create  table test ( i int   primary key   , j int   )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "create  table test ( i int   primary key   , j int   )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 23 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -67,7 +67,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 	/* this INSERT works */
 	rsetnull(CDECIMALTYPE, (char *)&j);
-	{ ECPGdo(__LINE__, 1, 1, NULL, "insert into test ( i  , j  ) values ( 7 ,  ? ) ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "insert into test ( i  , j  ) values ( 7 ,  $1  ) ", 
 	ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 27 "test_informix.pgc"
@@ -83,7 +83,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 
 	/* this INSERT should fail because i is a unique column */
-	{ ECPGdo(__LINE__, 1, 1, NULL, "insert into test ( i  , j  ) values ( 7 , 12 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "insert into test ( i  , j  ) values ( 7 , 12 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 31 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -97,7 +97,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 #line 33 "test_informix.pgc"
 
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "insert into test ( i  , j  ) values (  ? , 1 ) ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "insert into test ( i  , j  ) values (  $1  , 1 ) ", 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 35 "test_informix.pgc"
@@ -113,7 +113,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 
 	/* this will fail (more than one row in subquery) */
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  i  from test where j = ( select  j  from test    )  ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  i  from test where j = ( select  j  from test    )  ", ECPGt_EOIT, ECPGt_EORT);
 #line 39 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -127,7 +127,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 
 	/* this however should be ok */
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  i  from test where j = ( select  j  from test    order by i   limit 1  )  ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  i  from test where j = ( select  j  from test    order by i   limit 1  )  ", ECPGt_EOIT, ECPGt_EORT);
 #line 43 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 
 	 ECPG_informix_set_var( 0, &( i ), __LINE__);\
-  /* declare c  cursor  for select  *  from test where i <=  ?   */
+  /* declare c  cursor  for select  *  from test where i <=  $1    */
 #line 47 "test_informix.pgc"
 
 	openit();
@@ -151,7 +151,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 	while (1)
 	{
-		{ ECPGdo(__LINE__, 1, 1, NULL, "fetch forward from c", ECPGt_EOIT, 
+		{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "fetch forward from c", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
@@ -178,7 +178,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 	deccvint(7, &j);
 	deccvint(14, &m);
 	decadd(&j, &m, &n);
-	{ ECPGdo(__LINE__, 1, 1, NULL, "delete from test  where i =  ? ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "delete from test  where i =  $1  :: decimal   ", 
 	ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 72 "test_informix.pgc"
@@ -188,7 +188,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 	printf("DELETE: %ld\n", sqlca.sqlcode);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  1  from test where i = 14  ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  1  from test where i = 14  ", ECPGt_EOIT, ECPGt_EORT);
 #line 75 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -196,7 +196,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 	printf("Exists: %ld\n", sqlca.sqlcode);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  1  from test where i = 147  ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  1  from test where i = 147  ", ECPGt_EOIT, ECPGt_EORT);
 #line 78 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -210,7 +210,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 if (sqlca.sqlcode < 0) dosqlprint (  );}
 #line 81 "test_informix.pgc"
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
 #line 82 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint (  );}
@@ -235,7 +235,7 @@ if (sqlca.sqlcode < 0) dosqlprint (  );}
 
 static void openit(void)
 {
-	{ ECPGdo(__LINE__, 1, 1, NULL, "declare c  cursor  for select  *  from test where i <=  ?  ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "declare c  cursor  for select  *  from test where i <=  $1   ", 
 	ECPGt_int,&(*( int  *)(ECPG_informix_get_var( 0))),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 92 "test_informix.pgc"
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr
index cf8b024c8579cd5ca911a1f19d100003bd415302..b07e9193a32fb034604dfbdc9a9512ccafbb14ee 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.stderr
@@ -2,47 +2,69 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: create  table test ( i int   primary key   , j int   )     on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: create  table test ( i int   primary key   , j int   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 27: QUERY: insert into test ( i  , j  ) values ( 7 ,  0 )  on connection regress1
+[NO_PID]: ECPGexecute line 27: QUERY: insert into test ( i  , j  ) values ( 7 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 27: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 27: parameter 1 = 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 27 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 28 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: insert into test ( i  , j  ) values ( 7 , 12 )  on connection regress1
+[NO_PID]: ECPGexecute line 31: QUERY: insert into test ( i  , j  ) values ( 7 , 12 )  with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: Error: ERROR:  duplicate key value violates unique constraint "test_pkey"
+[NO_PID]: ECPGexecute line 31: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGcheck_PQresult line 31: Error: ERROR:  duplicate key value violates unique constraint "test_pkey"
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 23505 (sqlcode: -239) in line 31, ''duplicate key value violates unique constraint "test_pkey"' in line 31.'.
 [NO_PID]: sqlca: code: -239, state: 23505
 [NO_PID]: ECPGtrans line 33 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: insert into test ( i  , j  ) values (  14 , 1 )  on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: insert into test ( i  , j  ) values (  $1  , 1 )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: parameter 1 = 14
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 36 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: select  i  from test where j = ( select  j  from test    )   on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: select  i  from test where j = ( select  j  from test    )   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: Error: ERROR:  more than one row returned by a subquery used as an expression
+[NO_PID]: ECPGcheck_PQresult line 39: Error: ERROR:  more than one row returned by a subquery used as an expression
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 21000 (sqlcode: -284) in line 39, ''more than one row returned by a subquery used as an expression' in line 39.'.
 [NO_PID]: sqlca: code: -284, state: 21000
 [NO_PID]: ECPGtrans line 40 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: QUERY: select  i  from test where j = ( select  j  from test    order by i   limit 1  )   on connection regress1
+[NO_PID]: ECPGexecute line 43: QUERY: select  i  from test where j = ( select  j  from test    order by i   limit 1  )   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 43: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 92: QUERY: declare c  cursor  for select  *  from test where i <=  14   on connection regress1
+[NO_PID]: ECPGexecute line 92: QUERY: declare c  cursor  for select  *  from test where i <=  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 92: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 92: parameter 1 = 14
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 92 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c on connection regress1
+[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 54: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 54: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -50,7 +72,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 54: RESULT: 0 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c on connection regress1
+[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 54: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 54: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -58,23 +82,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 54: RESULT: 1 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c on connection regress1
+[NO_PID]: ECPGexecute line 54: QUERY: fetch forward from c with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 54: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 54: Correctly got 0 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 54, 'No data found in line 54.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 72: QUERY: delete from test  where i =  21.0  on connection regress1
+[NO_PID]: ECPGexecute line 72: QUERY: delete from test  where i =  $1  :: decimal    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 72: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 72: parameter 1 = 21.0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 72 Ok: DELETE 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 72, 'No data found in line 72.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 75: QUERY: select  1  from test where i = 14   on connection regress1
+[NO_PID]: ECPGexecute line 75: QUERY: select  1  from test where i = 14   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 75: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 75: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 78: QUERY: select  1  from test where i = 147   on connection regress1
+[NO_PID]: ECPGexecute line 78: QUERY: select  1  from test where i = 147   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 78: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 78: Correctly got 0 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -82,7 +116,9 @@
 [NO_PID]: sqlca: code: 100, state: 02000
 [NO_PID]: ECPGtrans line 81 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 82: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 82: QUERY: drop table test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 82: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 82 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c b/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
index e83779deb517a2ec94a69d398bc589255a5872af..9e2b9f7958b2862239372423ede1f480fe56094d 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
@@ -180,14 +180,14 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	sql_check("main", "connect", 0);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "set DateStyle to 'DMY'", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "set DateStyle to 'DMY'", ECPGt_EOIT, ECPGt_EORT);
 #line 66 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 66 "test_informix2.pgc"
 
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "create  table history ( customerid integer   , timestamp timestamp without time zone   , action_taken char  ( 5 )    , narrative varchar ( 100 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "create  table history ( customerid integer   , timestamp timestamp without time zone   , action_taken char  ( 5 )    , narrative varchar ( 100 )    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 68 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -195,7 +195,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	sql_check("main", "create", 0);
 	
-	{ ECPGdo(__LINE__, 1, 1, NULL, "insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 73 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -203,7 +203,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	sql_check("main", "insert", 0);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  max ( timestamp )  from history   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  max ( timestamp )  from history   ", ECPGt_EOIT, 
 	ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 78 "test_informix2.pgc"
@@ -213,7 +213,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	sql_check("main", "select max", 100);
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "select  customerid , timestamp  from history where timestamp =  ?    limit 1 ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "select  customerid , timestamp  from history where timestamp =  $1     limit 1 ", 
 	ECPGt_timestamp,&(maxd),(long)1,(long)1,sizeof(timestamp), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(c),(long)1,(long)1,sizeof(int), 
@@ -231,10 +231,10 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	intvl = PGTYPESinterval_from_asc("1 day 2 hours 24 minutes 65 seconds", NULL);
 	PGTYPEStimestamp_add_interval(&d, intvl, &e);
-
+	free(intvl);
 	c++;
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values (  ? ,  ? , 'test' , 'test' ) ", 
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values (  $1  ,  $2  , 'test' , 'test' ) ", 
 	ECPGt_int,&(c),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp), 
@@ -253,7 +253,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 100 "test_informix2.pgc"
 
 
-	{ ECPGdo(__LINE__, 1, 1, NULL, "drop table history ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 1, 1, NULL, 0, 0, "drop table history ", ECPGt_EOIT, ECPGt_EORT);
 #line 102 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.stderr b/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.stderr
index bd21af0a4df62975c8dce600692cc2895893f949..1e3e6862ca145967579839ef599b133a3c37d101 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.stderr
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.stderr
@@ -2,25 +2,37 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 66: QUERY: set DateStyle to 'DMY' on connection regress1
+[NO_PID]: ECPGexecute line 66: QUERY: set DateStyle to 'DMY' with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 66 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 68: QUERY: create  table history ( customerid integer   , timestamp timestamp without time zone   , action_taken char  ( 5 )    , narrative varchar ( 100 )    )     on connection regress1
+[NO_PID]: ECPGexecute line 68: QUERY: create  table history ( customerid integer   , timestamp timestamp without time zone   , action_taken char  ( 5 )    , narrative varchar ( 100 )    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 68: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 68 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )  on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values ( 1 , '2003-05-07 13:28:34 CEST' , 'test' , 'test' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 76: QUERY: select  max ( timestamp )  from history    on connection regress1
+[NO_PID]: ECPGexecute line 76: QUERY: select  max ( timestamp )  from history    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 76: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 76: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 76: RESULT: Wed 07 May 13:28:34 2003 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 81: QUERY: select  customerid , timestamp  from history where timestamp =  timestamp '2003-05-07 13:28:34'    limit 1  on connection regress1
+[NO_PID]: ECPGexecute line 81: QUERY: select  customerid , timestamp  from history where timestamp =  $1     limit 1  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 81: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 81: parameter 1 = 2003-05-07 13:28:34
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 81: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -28,13 +40,21 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 81: RESULT: Wed 07 May 13:28:34 2003 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 95: QUERY: insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values (  2 ,  timestamp '2003-05-08 15:53:39' , 'test' , 'test' )  on connection regress1
+[NO_PID]: ECPGexecute line 95: QUERY: insert into history ( customerid  , timestamp  , action_taken  , narrative  ) values (  $1  ,  $2  , 'test' , 'test' )  with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 95: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 95: parameter 1 = 2
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 95: parameter 2 = 2003-05-08 15:53:39
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 95 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 100 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 102: QUERY: drop table history  on connection regress1
+[NO_PID]: ECPGexecute line 102: QUERY: drop table history  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 102: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 102 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/connect-test1.stderr b/src/interfaces/ecpg/test/expected/connect-test1.stderr
index 18911ce4343758a51b4f16ef5751f263a99881f9..ffd206ce26df6088b83a19ee2c37f0b2b8dde5f7 100644
--- a/src/interfaces/ecpg/test/expected/connect-test1.stderr
+++ b/src/interfaces/ecpg/test/expected/connect-test1.stderr
@@ -2,7 +2,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database connectdb on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: alter user connectuser  encrypted password 'connectpw' on connection main
+[NO_PID]: ECPGexecute line 23: QUERY: alter user connectuser  encrypted password 'connectpw' with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: ALTER ROLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/connect-test2.c b/src/interfaces/ecpg/test/expected/connect-test2.c
index 15c2e8af8cb6b44c88107be5bb7a67eeefe5d2cd..cce486561198331298eeea33f9eb03db7414c90e 100644
--- a/src/interfaces/ecpg/test/expected/connect-test2.c
+++ b/src/interfaces/ecpg/test/expected/connect-test2.c
@@ -56,17 +56,17 @@ main(void)
 
 
 	/* this selects from "second" which was opened last */
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 28 "test2.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, "first", "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, "first", 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 29 "test2.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, "second", "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, "second", 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 30 "test2.pgc"
@@ -75,7 +75,7 @@ main(void)
 	{ ECPGsetconn(__LINE__, "first");}
 #line 32 "test2.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 33 "test2.pgc"
@@ -85,7 +85,7 @@ main(void)
 	{ ECPGdisconnect(__LINE__, "CURRENT");}
 #line 36 "test2.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 37 "test2.pgc"
diff --git a/src/interfaces/ecpg/test/expected/connect-test2.stderr b/src/interfaces/ecpg/test/expected/connect-test2.stderr
index e43cedf1a564626c11ae7d2e013ebc4e18fd4b06..2e497d5edf4957f86f2c5527739d0b27f5711f4b 100644
--- a/src/interfaces/ecpg/test/expected/connect-test2.stderr
+++ b/src/interfaces/ecpg/test/expected/connect-test2.stderr
@@ -4,25 +4,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 28: QUERY: select  current_database ()      on connection second
+[NO_PID]: ECPGexecute line 28: QUERY: select  current_database ()      with 0 parameter on connection second 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 28: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 28: RESULT: regress1 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: select  current_database ()      on connection first
+[NO_PID]: ECPGexecute line 29: QUERY: select  current_database ()      with 0 parameter on connection first 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 29: RESULT: connectdb offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 30: QUERY: select  current_database ()      on connection second
+[NO_PID]: ECPGexecute line 30: QUERY: select  current_database ()      with 0 parameter on connection second 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 30: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 30: RESULT: regress1 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 33: QUERY: select  current_database ()      on connection first
+[NO_PID]: ECPGexecute line 33: QUERY: select  current_database ()      with 0 parameter on connection first 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 33: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -30,7 +38,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection first closed.
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: select  current_database ()      on connection second
+[NO_PID]: ECPGexecute line 37: QUERY: select  current_database ()      with 0 parameter on connection second 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/connect-test3.c b/src/interfaces/ecpg/test/expected/connect-test3.c
index 9d4f2c1511f0068d8a361b9b725b7f9549375be5..ad142fd2437b2572a6bfe76cdb2753a79ef3ca15 100644
--- a/src/interfaces/ecpg/test/expected/connect-test3.c
+++ b/src/interfaces/ecpg/test/expected/connect-test3.c
@@ -55,7 +55,7 @@ main(void)
 
 
 	/* this selects from "second" which was opened last */
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 27 "test3.pgc"
@@ -65,7 +65,7 @@ main(void)
 	{ ECPGdisconnect(__LINE__, "CURRENT");}
 #line 30 "test3.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  current_database ()     ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  current_database ()     ", ECPGt_EOIT, 
 	ECPGt_char,(res),(long)200,(long)1,(200)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 31 "test3.pgc"
diff --git a/src/interfaces/ecpg/test/expected/connect-test3.stderr b/src/interfaces/ecpg/test/expected/connect-test3.stderr
index f37c9f0814ee319024f782b0dc1893d295cfa488..42927afc46052d15034c60250e27ce54813836c9 100644
--- a/src/interfaces/ecpg/test/expected/connect-test3.stderr
+++ b/src/interfaces/ecpg/test/expected/connect-test3.stderr
@@ -4,7 +4,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 27: QUERY: select  current_database ()      on connection second
+[NO_PID]: ECPGexecute line 27: QUERY: select  current_database ()      with 0 parameter on connection second 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 27: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 27: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -12,7 +14,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection second closed.
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: select  current_database ()      on connection first
+[NO_PID]: ECPGexecute line 31: QUERY: select  current_database ()      with 0 parameter on connection first 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 31: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/connect-test5.c b/src/interfaces/ecpg/test/expected/connect-test5.c
index 0e52e193079831ab82f73f46c675fa301adc1a43..4f119189800cd3b11497690cdebc0177626f0f8a 100644
--- a/src/interfaces/ecpg/test/expected/connect-test5.c
+++ b/src/interfaces/ecpg/test/expected/connect-test5.c
@@ -40,7 +40,7 @@ main(void)
 	{ ECPGconnect(__LINE__, 0, "connectdb" , NULL, NULL , "main", 0); }
 #line 22 "test5.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "alter user connectuser  encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "alter user connectuser  encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
 #line 23 "test5.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");}
diff --git a/src/interfaces/ecpg/test/expected/connect-test5.stderr b/src/interfaces/ecpg/test/expected/connect-test5.stderr
index 877b24b37d07df286317314720d565808dd73bb3..f72f468f915e1cc949245ebf47b4f75e1a772b9a 100644
--- a/src/interfaces/ecpg/test/expected/connect-test5.stderr
+++ b/src/interfaces/ecpg/test/expected/connect-test5.stderr
@@ -2,7 +2,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database connectdb on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: alter user connectuser  encrypted password 'connectpw' on connection main
+[NO_PID]: ECPGexecute line 23: QUERY: alter user connectuser  encrypted password 'connectpw' with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: ALTER ROLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
index 46ef2959ab4647111281e1ace22ddecccf8a3683..128f21d03b29cfdc03de53bf053ad13f64ba98aa 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
@@ -66,13 +66,13 @@ main(void)
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 28 "dt_test.pgc"
 
-        { ECPGdo(__LINE__, 0, 1, NULL, "create  table date_test ( d date    , ts timestamp    )    ", ECPGt_EOIT, ECPGt_EORT);
+        { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table date_test ( d date    , ts timestamp    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 29 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 29 "dt_test.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
 #line 30 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -82,7 +82,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 	date1 = PGTYPESdate_from_asc(d1, NULL); 
 	ts1 = PGTYPEStimestamp_from_asc(t1, NULL); 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into date_test ( d  , ts  ) values (  ? ,  ? ) ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into date_test ( d  , ts  ) values (  $1  ,  $2  ) ", 
 	ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_timestamp,&(ts1),(long)1,(long)1,sizeof(timestamp), 
@@ -93,7 +93,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 35 "dt_test.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from date_test where d =  ?  ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from date_test where d =  $1   ", 
 	ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_date,&(date1),(long)1,(long)1,sizeof(date), 
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
index bb2f8d2959e0ec66e6c788b69403a0ff0ffc1703..8678608bfda07c1514e64099a2fc99dea104a9fb 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr
@@ -2,19 +2,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: create  table date_test ( d date    , ts timestamp    )     on connection regress1
+[NO_PID]: ECPGexecute line 29: QUERY: create  table date_test ( d date    , ts timestamp    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 30: QUERY: set datestyle to iso on connection regress1
+[NO_PID]: ECPGexecute line 30: QUERY: set datestyle to iso with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 30 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: insert into date_test ( d  , ts  ) values (  date '1966-01-17' ,  timestamp '2000-07-12 17:34:29' )  on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: insert into date_test ( d  , ts  ) values (  $1  ,  $2  )  with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: parameter 1 = 1966-01-17
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: parameter 2 = 2000-07-12 17:34:29
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: select  *  from date_test where d =  date '1966-01-17'   on connection regress1
+[NO_PID]: ECPGexecute line 37: QUERY: select  *  from date_test where d =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: parameter 1 = 1966-01-17
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
index 4053e52fcc59b7549d9a16f008fad0237eacc67e..858bc87d57cf8c0beb12d6149b2458cb618bb207 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
@@ -68,7 +68,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 34 "num_test.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( text char  ( 5 )    , num numeric ( 14 , 7 )   )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( text char  ( 5 )    , num numeric ( 14 , 7 )   )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 35 "num_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -98,7 +98,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
 	des = PGTYPESnumeric_new();
 	PGTYPESnumeric_copy(res, des);
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( text  , num  ) values ( 'test' ,  ? ) ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( text  , num  ) values ( 'test' ,  $1  ) ", 
 	ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 60 "num_test.pgc"
@@ -111,7 +111,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 	PGTYPESnumeric_mul(value1, value2, res);
 	PGTYPESnumeric_free(value2);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  num  from test where text = 'test'  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  num  from test where text = 'test'  ", ECPGt_EOIT, 
 	ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 66 "num_test.pgc"
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
index 63103d8c00e0c6ade88b0814411eef9fd8ab1a72..242cb33f52cb332cad51e30daf6100ec46424c68 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.stderr
@@ -4,15 +4,23 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGsetcommit line 34 action = off connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: create  table test ( text char  ( 5 )    , num numeric ( 14 , 7 )   )     on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: create  table test ( text char  ( 5 )    , num numeric ( 14 , 7 )   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 60: QUERY: insert into test ( text  , num  ) values ( 'test' ,  2369.7 )  on connection regress1
+[NO_PID]: ECPGexecute line 60: QUERY: insert into test ( text  , num  ) values ( 'test' ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: parameter 1 = 2369.7
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 60 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 66: QUERY: select  num  from test where text = 'test'   on connection regress1
+[NO_PID]: ECPGexecute line 66: QUERY: select  num  from test where text = 'test'   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 66: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-array_of_struct.c b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.c
new file mode 100644
index 0000000000000000000000000000000000000000..9d465a2a128f1b0c661d3490f207d16099862054
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.c
@@ -0,0 +1,265 @@
+/* Processed by ecpg (regression mode) */
+/* These include files are added by the preprocessor */
+#include <ecpgtype.h>
+#include <ecpglib.h>
+#include <ecpgerrno.h>
+#include <sqlca.h>
+/* End of automatic include section */
+#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
+
+#line 1 "array_of_struct.pgc"
+#include <stdio.h>
+
+
+#line 1 "regression.h"
+
+
+
+
+
+
+#line 3 "array_of_struct.pgc"
+
+
+/* exec sql whenever sqlerror  sqlprint ; */
+#line 5 "array_of_struct.pgc"
+
+/* exec sql whenever sql_warning  sqlprint ; */
+#line 6 "array_of_struct.pgc"
+
+/* exec sql whenever not found  sqlprint ; */
+#line 7 "array_of_struct.pgc"
+
+
+typedef  struct { 
+#line 12 "array_of_struct.pgc"
+   struct varchar_name_12  { int len; char arr[ 50 ]; }  name    ;
+ 
+#line 13 "array_of_struct.pgc"
+ int  phone    ;
+ }   customer ;
+#line 14 "array_of_struct.pgc"
+
+
+typedef  struct ind { 
+#line 19 "array_of_struct.pgc"
+ short  name_ind    ;
+ 
+#line 20 "array_of_struct.pgc"
+ short  phone_ind    ;
+ }   cust_ind ;
+#line 21 "array_of_struct.pgc"
+
+
+int main( int argc, char * argv[] )
+{
+    /* exec sql begin declare section */
+        
+        
+       
+      
+         
+             
+       typedef struct { 
+#line 30 "array_of_struct.pgc"
+   struct varchar_name_30  { int len; char arr[ 50 ]; }  name    ;
+ 
+#line 31 "array_of_struct.pgc"
+ int  phone    ;
+ }  customer2 ;
+
+#line 32 "array_of_struct.pgc"
+
+        
+       
+      
+         
+             
+       
+       
+      
+         
+             
+       
+       
+    
+#line 26 "array_of_struct.pgc"
+ customer  custs1 [ 10 ]    ;
+ 
+#line 27 "array_of_struct.pgc"
+ cust_ind  inds [ 10 ]    ;
+  
+#line 33 "array_of_struct.pgc"
+ customer2  custs2 [ 10 ]    ;
+ 
+#line 38 "array_of_struct.pgc"
+ struct customer3 { 
+#line 36 "array_of_struct.pgc"
+   struct varchar_name_36  { int len; char arr[ 50 ]; }  name    ;
+ 
+#line 37 "array_of_struct.pgc"
+ int  phone    ;
+ }  custs3 [ 10 ]    ;
+ 
+#line 43 "array_of_struct.pgc"
+ struct customer4 { 
+#line 41 "array_of_struct.pgc"
+   struct varchar_name_41  { int len; char arr[ 50 ]; }  name    ;
+ 
+#line 42 "array_of_struct.pgc"
+ int  phone    ;
+ }  custs4    ;
+ 
+#line 44 "array_of_struct.pgc"
+ int  r    ;
+/* exec sql end declare section */
+#line 45 "array_of_struct.pgc"
+
+
+    ECPGdebug(1, stderr);
+	  
+    { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
+#line 49 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 49 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 49 "array_of_struct.pgc"
+
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table customers ( c varchar ( 50 )    , p int   )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 51 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 51 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 51 "array_of_struct.pgc"
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into customers values ( 'John Doe' , '12345' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 52 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 52 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 52 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 52 "array_of_struct.pgc"
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into customers values ( 'Jane Doe' , '67890' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 53 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 53 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 53 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 53 "array_of_struct.pgc"
+
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from customers     limit 2 ", ECPGt_EOIT, 
+	ECPGt_varchar,&(custs1->name),(long)50,(long)10,sizeof( customer ), 
+	ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ), 
+	ECPGt_int,&(custs1->phone),(long)1,(long)10,sizeof( customer ), 
+	ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
+#line 55 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 55 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 55 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 55 "array_of_struct.pgc"
+
+    printf("custs1:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs1[r].name.arr );
+	    printf( "phone - %d\n", custs1[r].phone );
+    }
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from customers     limit 2 ", ECPGt_EOIT, 
+	ECPGt_varchar,&(custs2->name),(long)50,(long)10,sizeof( customer2 ), 
+	ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ), 
+	ECPGt_int,&(custs2->phone),(long)1,(long)10,sizeof( customer2 ), 
+	ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
+#line 63 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 63 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 63 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 63 "array_of_struct.pgc"
+
+    printf("\ncusts2:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs2[r].name.arr );
+	    printf( "phone - %d\n", custs2[r].phone );
+    }
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from customers     limit 2 ", ECPGt_EOIT, 
+	ECPGt_varchar,&(custs3->name),(long)50,(long)10,sizeof( struct customer3 ), 
+	ECPGt_short,&(inds->name_ind),(long)1,(long)10,sizeof( struct ind ), 
+	ECPGt_int,&(custs3->phone),(long)1,(long)10,sizeof( struct customer3 ), 
+	ECPGt_short,&(inds->phone_ind),(long)1,(long)10,sizeof( struct ind ), ECPGt_EORT);
+#line 71 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 71 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 71 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 71 "array_of_struct.pgc"
+
+    printf("\ncusts3:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs3[r].name.arr );
+	    printf( "phone - %d\n", custs3[r].phone );
+    }
+
+    { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from customers     limit 1 ", ECPGt_EOIT, 
+	ECPGt_varchar,&(custs4.name),(long)50,(long)1,sizeof(struct varchar_name_41), 
+	ECPGt_short,&(inds[0].name_ind),(long)1,(long)1,sizeof(short), 
+	ECPGt_int,&(custs4.phone),(long)1,(long)1,sizeof(int), 
+	ECPGt_short,&(inds[0].phone_ind),(long)1,(long)1,sizeof(short), ECPGt_EORT);
+#line 79 "array_of_struct.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) sqlprint();
+#line 79 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 79 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 79 "array_of_struct.pgc"
+
+    printf("\ncusts4:\n");
+    printf( "name  - %s\n", custs4.name.arr );
+    printf( "phone - %d\n", custs4.phone );
+
+    { ECPGdisconnect(__LINE__, "ALL");
+#line 84 "array_of_struct.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 84 "array_of_struct.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 84 "array_of_struct.pgc"
+
+
+    return( 0 );
+}
diff --git a/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stderr b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stderr
new file mode 100644
index 0000000000000000000000000000000000000000..5326b1ea56f01a8601e3d757199eeead2745a499
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stderr
@@ -0,0 +1,76 @@
+[NO_PID]: ECPGdebug: set to 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: QUERY: create  table customers ( c varchar ( 50 )    , p int   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51 Ok: CREATE TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: QUERY: insert into customers values ( 'John Doe' , '12345' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: QUERY: insert into customers values ( 'Jane Doe' , '67890' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 55: QUERY: select  *  from customers     limit 2  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 55: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 55: Correctly got 2 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 55: RESULT: John Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 55: RESULT: Jane Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 55: RESULT: 12345 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 55: RESULT: 67890 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 63: QUERY: select  *  from customers     limit 2  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 63: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 63: Correctly got 2 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 63: RESULT: John Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 63: RESULT: Jane Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 63: RESULT: 12345 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 63: RESULT: 67890 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: QUERY: select  *  from customers     limit 2  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: Correctly got 2 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 71: RESULT: John Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 71: RESULT: Jane Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 71: RESULT: 12345 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 71: RESULT: 67890 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 79: QUERY: select  *  from customers     limit 1  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 79: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 79: Correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 79: RESULT: John Doe offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 79: RESULT: 12345 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_finish: Connection regress1 closed.
+[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stdout b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..e307ea5943d2922bbb68664e0066e3d2e2d2eea2
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-array_of_struct.stdout
@@ -0,0 +1,21 @@
+custs1:
+name  - John Doe
+phone - 12345
+name  - Jane Doe
+phone - 67890
+
+custs2:
+name  - John Doe
+phone - 12345
+name  - Jane Doe
+phone - 67890
+
+custs3:
+name  - John Doe
+phone - 12345
+name  - Jane Doe
+phone - 67890
+
+custs4:
+name  - John Doe
+phone - 12345
diff --git a/src/interfaces/ecpg/test/expected/preproc-autoprep.c b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
new file mode 100644
index 0000000000000000000000000000000000000000..02a41e3380f0f9a2407fe1c46edb82704414fec3
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
@@ -0,0 +1,183 @@
+/* Processed by ecpg (regression mode) */
+/* These include files are added by the preprocessor */
+#include <ecpgtype.h>
+#include <ecpglib.h>
+#include <ecpgerrno.h>
+#include <sqlca.h>
+/* End of automatic include section */
+#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
+
+#line 1 "autoprep.pgc"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* test automatic prepare for all statements */
+
+#line 1 "regression.h"
+
+
+
+
+
+
+#line 6 "autoprep.pgc"
+
+
+int main(int argc, char* argv[]) {
+  /* exec sql begin declare section */
+  	     
+  
+#line 10 "autoprep.pgc"
+ int  item [ 4 ]    ,  ind [ 4 ]    ,  i   = 1 ;
+/* exec sql end declare section */
+#line 11 "autoprep.pgc"
+
+
+  ECPGdebug(1, stderr);
+  { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
+#line 14 "autoprep.pgc"
+
+
+  /* exec sql whenever sql_warning  sqlprint ; */
+#line 16 "autoprep.pgc"
+
+  /* exec sql whenever sqlerror  sqlprint ; */
+#line 17 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "create  table T ( Item1 int   , Item2 int   )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 19 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 19 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 19 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "insert into T values ( 1 , null ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 21 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 21 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 21 "autoprep.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "insert into T values ( 1 ,  $1  ) ", 
+	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 22 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 22 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 22 "autoprep.pgc"
+
+  i++;
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "insert into T values ( 1 ,  $1  ) ", 
+	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 24 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 24 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 24 "autoprep.pgc"
+
+  { ECPGprepare(__LINE__, NULL, 0, "i", " insert into T values ( 1 , 2 )  ");
+#line 25 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 25 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 25 "autoprep.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i", ECPGt_EOIT, ECPGt_EORT);
+#line 26 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 26 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 26 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "select  Item2  from T    order by Item2  nulls last", ECPGt_EOIT, 
+	ECPGt_int,(item),(long)1,(long)4,sizeof(int), 
+	ECPGt_int,(ind),(long)1,(long)4,sizeof(int), ECPGt_EORT);
+#line 28 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 28 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 28 "autoprep.pgc"
+
+
+  for (i=0; i<4; i++)
+  	printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
+
+  /* declare C  cursor  for select  Item1  from T    */
+#line 33 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "declare C  cursor  for select  Item1  from T   ", ECPGt_EOIT, ECPGt_EORT);
+#line 35 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 35 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 35 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "fetch 1 in C", ECPGt_EOIT, 
+	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 37 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 37 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 37 "autoprep.pgc"
+
+  printf("i = %d\n", i);
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "close C", ECPGt_EOIT, ECPGt_EORT);
+#line 40 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 40 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 40 "autoprep.pgc"
+
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 3, "drop table T ", ECPGt_EOIT, ECPGt_EORT);
+#line 42 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 42 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 42 "autoprep.pgc"
+
+
+  { ECPGdisconnect(__LINE__, "ALL");
+#line 44 "autoprep.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 44 "autoprep.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 44 "autoprep.pgc"
+
+
+  return 0;
+}
diff --git a/src/interfaces/ecpg/test/expected/preproc-autoprep.stderr b/src/interfaces/ecpg/test/expected/preproc-autoprep.stderr
new file mode 100644
index 0000000000000000000000000000000000000000..ec86193d9d16fc1956b10e75df79c5118ea21e50
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-autoprep.stderr
@@ -0,0 +1,116 @@
+[NO_PID]: ECPGdebug: set to 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 19: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 19: NAME: ecpg1 QUERY: create  table T ( Item1 int   , Item2 int   )    
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: QUERY: create  table T ( Item1 int   , Item2 int   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: using PQexecPrepared for create  table T ( Item1 int   , Item2 int   )    
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19 Ok: CREATE TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 21: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 21: NAME: ecpg2 QUERY: insert into T values ( 1 , null ) 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21: QUERY: insert into T values ( 1 , null )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21: using PQexecPrepared for insert into T values ( 1 , null ) 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 22: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 22: NAME: ecpg3 QUERY: insert into T values ( 1 ,  $1  ) 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: QUERY: insert into T values ( 1 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexecPrepared for insert into T values ( 1 ,  $1  ) 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 24: stmt found in cache, entry 6248
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: QUERY: insert into T values ( 1 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: using PQexecPrepared for insert into T values ( 1 ,  $1  ) 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: parameter 1 = 2
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 25: NAME: i QUERY:  insert into T values ( 1 , 2 )  
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: QUERY:  insert into T values ( 1 , 2 )   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecPrepared for  insert into T values ( 1 , 2 )  
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 28: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 28: NAME: ecpg4 QUERY: select  Item2  from T    order by Item2  nulls last
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: QUERY: select  Item2  from T    order by Item2  nulls last with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexecPrepared for select  Item2  from T    order by Item2  nulls last
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: Correctly got 4 tuples with 1 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 28: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 28: RESULT: 2 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 28: RESULT: 2 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 28: RESULT:  offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 35: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 35: NAME: ecpg5 QUERY: declare C  cursor  for select  Item1  from T   
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: QUERY: declare C  cursor  for select  Item1  from T    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexecPrepared for declare C  cursor  for select  Item1  from T   
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 37: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 37: NAME: ecpg6 QUERY: fetch 1 in C
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexecPrepared for fetch 1 in C
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 1 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 37: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 40: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 40: NAME: ecpg7 QUERY: close C
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: QUERY: close C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: using PQexecPrepared for close C
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40 Ok: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGauto_prepare line 42: stmt not in cache; inserting
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 42: NAME: ecpg8 QUERY: drop table T 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: QUERY: drop table T  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexecPrepared for drop table T 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42 Ok: DROP TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_finish: Connection regress1 closed.
+[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-autoprep.stdout b/src/interfaces/ecpg/test/expected/preproc-autoprep.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..31f18bf1dfe50de9670468604301abbb9854d060
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/preproc-autoprep.stdout
@@ -0,0 +1,5 @@
+item[0] = 1
+item[1] = 2
+item[2] = 2
+item[3] = -1
+i = 1
diff --git a/src/interfaces/ecpg/test/expected/preproc-define.c b/src/interfaces/ecpg/test/expected/preproc-define.c
index 89d6b83575e80682fb76cb0f698967f5043457f2..2de5b482f551131ef95cf2a8db0901060eedea0d 100644
--- a/src/interfaces/ecpg/test/expected/preproc-define.c
+++ b/src/interfaces/ecpg/test/expected/preproc-define.c
@@ -78,7 +78,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 34 "define.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 36 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -91,13 +91,13 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "define.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into Test ( name  , amount  , letter  ) values ( 'false' , 1 , 'f' ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into Test ( name  , amount  , letter  ) values ( 'false' , 1 , 'f' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 39 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 39 "define.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( name  , amount  , letter  ) values ( 'true' , 2 , 't' ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( name  , amount  , letter  ) values ( 'true' , 2 , 't' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 40 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -110,7 +110,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 41 "define.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from test   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from test   ", ECPGt_EOIT, 
 	ECPGt_char,(name),(long)8,(long)6,(8)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,(amount),(long)1,(long)6,sizeof(int), 
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
 	}
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
 #line 56 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/preproc-define.stderr b/src/interfaces/ecpg/test/expected/preproc-define.stderr
index 1a1387374953d389e1b46da22c41e78bba6c706c..951501c3e4308ddabb5a767f061b82627cdcfbd9 100644
--- a/src/interfaces/ecpg/test/expected/preproc-define.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-define.stderr
@@ -2,23 +2,31 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )     on connection regress1
+[NO_PID]: ECPGexecute line 36: QUERY: create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 36 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 37 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: insert into Test ( name  , amount  , letter  ) values ( 'false' , 1 , 'f' )  on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: insert into Test ( name  , amount  , letter  ) values ( 'false' , 1 , 'f' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 39 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 40: QUERY: insert into test ( name  , amount  , letter  ) values ( 'true' , 2 , 't' )  on connection regress1
+[NO_PID]: ECPGexecute line 40: QUERY: insert into test ( name  , amount  , letter  ) values ( 'true' , 2 , 't' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 40 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 41 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: QUERY: select  *  from test    on connection regress1
+[NO_PID]: ECPGexecute line 43: QUERY: select  *  from test    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 43: Correctly got 2 tuples with 3 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -34,7 +42,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 43: RESULT: t offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 56: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 56: QUERY: drop table test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 56: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 56 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-init.c b/src/interfaces/ecpg/test/expected/preproc-init.c
index 68af154da81d23372c3dec7048bfa55bf961d6f4..6cb31f5d3c63a77113d5e6fddabb9c1e4a4cc6fa 100644
--- a/src/interfaces/ecpg/test/expected/preproc-init.c
+++ b/src/interfaces/ecpg/test/expected/preproc-init.c
@@ -207,7 +207,7 @@ int main(void)
 	/* exec sql whenever sqlerror  do fa (  ) ; */
 #line 87 "init.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 88 "init.pgc"
 
 if (sqlca.sqlcode < 0) fa (  );}
@@ -216,7 +216,7 @@ if (sqlca.sqlcode < 0) fa (  );}
 	/* exec sql whenever sqlerror  do fb ( 20 ) ; */
 #line 89 "init.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 90 "init.pgc"
 
 if (sqlca.sqlcode < 0) fb ( 20 );}
@@ -225,7 +225,7 @@ if (sqlca.sqlcode < 0) fb ( 20 );}
 	/* exec sql whenever sqlerror  do fc ( \"50\" ) ; */
 #line 91 "init.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 92 "init.pgc"
 
 if (sqlca.sqlcode < 0) fc ( "50" );}
@@ -234,7 +234,7 @@ if (sqlca.sqlcode < 0) fc ( "50" );}
 	/* exec sql whenever sqlerror  do fd ( \"50\" , 1 ) ; */
 #line 93 "init.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 94 "init.pgc"
 
 if (sqlca.sqlcode < 0) fd ( "50" , 1 );}
@@ -243,7 +243,7 @@ if (sqlca.sqlcode < 0) fd ( "50" , 1 );}
 	/* exec sql whenever sqlerror  do fe ( ENUM0 ) ; */
 #line 95 "init.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 96 "init.pgc"
 
 if (sqlca.sqlcode < 0) fe ( ENUM0 );}
@@ -252,7 +252,7 @@ if (sqlca.sqlcode < 0) fe ( ENUM0 );}
 	/* exec sql whenever sqlerror  do sqlnotice ( NULL , 0 ) ; */
 #line 97 "init.pgc"
  
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  now ()     ", ECPGt_EOIT, ECPGt_EORT);
 #line 98 "init.pgc"
 
 if (sqlca.sqlcode < 0) sqlnotice ( NULL , 0 );}
diff --git a/src/interfaces/ecpg/test/expected/preproc-type.c b/src/interfaces/ecpg/test/expected/preproc-type.c
index 1677b03ba787ac45642c0a47017d2b2b16cdc8b2..d01f2c1ece37feb435c16d79d38e2aecc1fe0363 100644
--- a/src/interfaces/ecpg/test/expected/preproc-type.c
+++ b/src/interfaces/ecpg/test/expected/preproc-type.c
@@ -120,7 +120,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , string1 char  ( 10 )    , string2 char  ( 10 )    , string3 char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , string1 char  ( 10 )    , string2 char  ( 10 )    , string3 char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 51 "type.pgc"
 
   if (sqlca.sqlcode)
@@ -129,7 +129,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values ( 1 , 'user name' , 320 , 'first str' , 'second str' , 'third str' ) ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into empl values ( 1 , 'user name' , 320 , 'first str' , 'second str' , 'third str' ) ", ECPGt_EOIT, ECPGt_EORT);}
 #line 58 "type.pgc"
 
   if (sqlca.sqlcode)
@@ -138,7 +138,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  idnum , name , accs , string1 , string2 , string3  from empl where idnum =  ?  ", 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  idnum , name , accs , string1 , string2 , string3  from empl where idnum =  $1   ", 
 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
diff --git a/src/interfaces/ecpg/test/expected/preproc-type.stderr b/src/interfaces/ecpg/test/expected/preproc-type.stderr
index f53eeda9bcb22668999de1e95d6e007c901cb0b7..960695af30340448c80756e3a35cc0ae8852e68c 100644
--- a/src/interfaces/ecpg/test/expected/preproc-type.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-type.stderr
@@ -2,15 +2,23 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 50: QUERY: create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , string1 char  ( 10 )    , string2 char  ( 10 )    , string3 char  ( 10 )    )     on connection regress1
+[NO_PID]: ECPGexecute line 50: QUERY: create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , string1 char  ( 10 )    , string2 char  ( 10 )    , string3 char  ( 10 )    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 50: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 50 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 58: QUERY: insert into empl values ( 1 , 'user name' , 320 , 'first str' , 'second str' , 'third str' )  on connection regress1
+[NO_PID]: ECPGexecute line 58: QUERY: insert into empl values ( 1 , 'user name' , 320 , 'first str' , 'second str' , 'third str' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 58 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 65: QUERY: select  idnum , name , accs , string1 , string2 , string3  from empl where idnum =  1   on connection regress1
+[NO_PID]: ECPGexecute line 65: QUERY: select  idnum , name , accs , string1 , string2 , string3  from empl where idnum =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 65: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 65: parameter 1 = 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 65: Correctly got 1 tuples with 6 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-variable.c b/src/interfaces/ecpg/test/expected/preproc-variable.c
index 1e3f38b6d1e97a4c08199b232a5f4b55d600d0f2..9b40fb8a5590f77e80b91f8b27c920e6320b5ce4 100644
--- a/src/interfaces/ecpg/test/expected/preproc-variable.c
+++ b/src/interfaces/ecpg/test/expected/preproc-variable.c
@@ -75,7 +75,7 @@ main (void)
 #line 27 "variable.pgc"
  struct personal_struct { 
 #line 25 "variable.pgc"
-   struct varchar_name  { int len; char arr[ BUFFERSIZ ]; }  name    ;
+   struct varchar_name_25  { int len; char arr[ BUFFERSIZ ]; }  name    ;
  
 #line 26 "variable.pgc"
  struct birthinfo  birth    ;
@@ -128,7 +128,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "set");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set datestyle to iso", ECPGt_EOIT, ECPGt_EORT);
 #line 46 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -136,7 +136,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "create");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table family ( name char  ( 8 )    , born integer   , age smallint   , married date    , children integer   )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table family ( name char  ( 8 )    , born integer   , age smallint   , married date    , children integer   )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 49 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -144,31 +144,31 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "insert");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into family ( name  , married  , children  ) values ( 'Mum' , '19870714' , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into family ( name  , married  , children  ) values ( 'Mum' , '19870714' , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 52 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 52 "variable.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into family ( name  , born  , married  , children  ) values ( 'Dad' , '19610721' , '19870714' , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into family ( name  , born  , married  , children  ) values ( 'Dad' , '19610721' , '19870714' , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 53 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 53 "variable.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into family ( name  , age  ) values ( 'Child 1' , 16 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into family ( name  , age  ) values ( 'Child 1' , 16 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 54 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 54 "variable.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into family ( name  , age  ) values ( 'Child 2' , 14 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into family ( name  , age  ) values ( 'Child 2' , 14 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 55 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 55 "variable.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into family ( name  , age  ) values ( 'Child 3' , 9 ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into family ( name  , age  ) values ( 'Child 3' , 9 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 56 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -184,7 +184,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "declare cur  cursor  for select  name , born , age , married , children  from family   ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare cur  cursor  for select  name , born , age , married , children  from family   ", ECPGt_EOIT, ECPGt_EORT);
 #line 62 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -200,8 +200,8 @@ if (sqlca.sqlcode < 0) exit (1);}
 	memset(i, 0, sizeof(ind_personal));
 	while (1) {
 		strcpy(msg, "fetch");
-		{ ECPGdo(__LINE__, 0, 1, NULL, "fetch cur", ECPGt_EOIT, 
-	ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_name), 
+		{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch cur", ECPGt_EOIT, 
+	ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_name_25), 
 	ECPGt_int,&(i->ind_name),(long)1,(long)1,sizeof(int), 
 	ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof(long), 
 	ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof(long), 
@@ -235,7 +235,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	}
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "close cur", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close cur", ECPGt_EOIT, ECPGt_EORT);
 #line 88 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
@@ -243,7 +243,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "drop");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table family ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table family ", ECPGt_EOIT, ECPGt_EORT);
 #line 91 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
diff --git a/src/interfaces/ecpg/test/expected/preproc-variable.stderr b/src/interfaces/ecpg/test/expected/preproc-variable.stderr
index 01b21c804d7bb8a0eaf3fc7991b594ff3a42c5f8..b113b0fbd4fc557c4ecfef614b6e48698e0389f3 100644
--- a/src/interfaces/ecpg/test/expected/preproc-variable.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-variable.stderr
@@ -2,41 +2,59 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 46: QUERY: set datestyle to iso on connection regress1
+[NO_PID]: ECPGexecute line 46: QUERY: set datestyle to iso with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 46 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 49: QUERY: create  table family ( name char  ( 8 )    , born integer   , age smallint   , married date    , children integer   )     on connection regress1
+[NO_PID]: ECPGexecute line 49: QUERY: create  table family ( name char  ( 8 )    , born integer   , age smallint   , married date    , children integer   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 49: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 49 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 52: QUERY: insert into family ( name  , married  , children  ) values ( 'Mum' , '19870714' , 3 )  on connection regress1
+[NO_PID]: ECPGexecute line 52: QUERY: insert into family ( name  , married  , children  ) values ( 'Mum' , '19870714' , 3 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 52 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 53: QUERY: insert into family ( name  , born  , married  , children  ) values ( 'Dad' , '19610721' , '19870714' , 3 )  on connection regress1
+[NO_PID]: ECPGexecute line 53: QUERY: insert into family ( name  , born  , married  , children  ) values ( 'Dad' , '19610721' , '19870714' , 3 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 53 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 54: QUERY: insert into family ( name  , age  ) values ( 'Child 1' , 16 )  on connection regress1
+[NO_PID]: ECPGexecute line 54: QUERY: insert into family ( name  , age  ) values ( 'Child 1' , 16 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 54: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 54 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55: QUERY: insert into family ( name  , age  ) values ( 'Child 2' , 14 )  on connection regress1
+[NO_PID]: ECPGexecute line 55: QUERY: insert into family ( name  , age  ) values ( 'Child 2' , 14 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 55: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 55 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 56: QUERY: insert into family ( name  , age  ) values ( 'Child 3' , 9 )  on connection regress1
+[NO_PID]: ECPGexecute line 56: QUERY: insert into family ( name  , age  ) values ( 'Child 3' , 9 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 56: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 56 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 59 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 62: QUERY: declare cur  cursor  for select  name , born , age , married , children  from family    on connection regress1
+[NO_PID]: ECPGexecute line 62: QUERY: declare cur  cursor  for select  name , born , age , married , children  from family    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 62: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 62 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -52,7 +70,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 71: RESULT: 3 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -68,7 +88,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 71: RESULT: 3 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -84,7 +106,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 71: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -100,7 +124,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 71: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 1 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -116,17 +142,23 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 71: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 71: QUERY: fetch cur on connection regress1
+[NO_PID]: ECPGexecute line 71: QUERY: fetch cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 71: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 71: Correctly got 0 tuples with 5 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 71, 'No data found in line 71.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 88: QUERY: close cur on connection regress1
+[NO_PID]: ECPGexecute line 88: QUERY: close cur with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 88: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 88 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 91: QUERY: drop table family  on connection regress1
+[NO_PID]: ECPGexecute line 91: QUERY: drop table family  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 91: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 91 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/preproc-whenever.c b/src/interfaces/ecpg/test/expected/preproc-whenever.c
index 3acb4ece4f1186680f06d5de7acec8cb9689fecf..ae6df52104e09723846f2952bdc1535384ceb2ac 100644
--- a/src/interfaces/ecpg/test/expected/preproc-whenever.c
+++ b/src/interfaces/ecpg/test/expected/preproc-whenever.c
@@ -65,13 +65,13 @@ int main(void)
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 31 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( i int   , c char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( i int   , c char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 32 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 32 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 1 , 'abcdefghij' ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 1 , 'abcdefghij' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 33 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -81,7 +81,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	/* exec sql whenever sql_warning  do warn (  ) ; */
 #line 35 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from test   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from test   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(c),(long)6,(long)1,(6)*sizeof(char), 
@@ -104,7 +104,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "whenever.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 39 "whenever.pgc"
@@ -128,7 +128,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	/* exec sql whenever sqlerror  do print ( \"select\" ) ; */
 #line 42 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 43 "whenever.pgc"
@@ -152,7 +152,7 @@ if (sqlca.sqlcode < 0) print ( "select" );}
 	/* exec sql whenever sqlerror  call print2 (  ) ; */
 #line 46 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 47 "whenever.pgc"
@@ -176,7 +176,7 @@ if (sqlca.sqlcode < 0) print2 (  );}
 	/* exec sql whenever sqlerror  continue ; */
 #line 50 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 51 "whenever.pgc"
@@ -194,7 +194,7 @@ if (sqlca.sqlwarn[0] == 'W') warn (  );}
 	/* exec sql whenever sqlerror  goto  error ; */
 #line 54 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 55 "whenever.pgc"
@@ -221,7 +221,7 @@ if (sqlca.sqlcode < 0) goto error;}
 	/* exec sql whenever sqlerror  stop ; */
 #line 61 "whenever.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from nonexistant   ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from nonexistant   ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 62 "whenever.pgc"
diff --git a/src/interfaces/ecpg/test/expected/preproc-whenever.stderr b/src/interfaces/ecpg/test/expected/preproc-whenever.stderr
index 5d50d498328baa7d9c9080d062fc69154bc0611d..63b925f7047919a58b5fb584544ca4e46a220e2b 100644
--- a/src/interfaces/ecpg/test/expected/preproc-whenever.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-whenever.stderr
@@ -2,15 +2,21 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: create  table test ( i int   , c char  ( 10 )    )     on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: create  table test ( i int   , c char  ( 10 )    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 33: QUERY: insert into test values ( 1 , 'abcdefghij' )  on connection regress1
+[NO_PID]: ECPGexecute line 33: QUERY: insert into test values ( 1 , 'abcdefghij' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 33 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: select  *  from test    on connection regress1
+[NO_PID]: ECPGexecute line 36: QUERY: select  *  from test    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 36: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -21,18 +27,22 @@
 Warning: At least one column was truncated
 [NO_PID]: ECPGtrans line 37 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGexecute line 39: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGcheck_PQresult line 39: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 39, ''relation "nonexistant" does not exist' in line 39.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
 sql error 'relation "nonexistant" does not exist' in line 39.
 [NO_PID]: ECPGtrans line 40 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 43: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGcheck_PQresult line 43: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 43, ''relation "nonexistant" does not exist' in line 43.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
@@ -40,9 +50,11 @@ Error in statement 'select':
 sql error 'relation "nonexistant" does not exist' in line 43.
 [NO_PID]: ECPGtrans line 44 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 47: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 47: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 47: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGexecute line 47: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGcheck_PQresult line 47: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 47, ''relation "nonexistant" does not exist' in line 47.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
@@ -50,25 +62,31 @@ Found another error
 sql error 'relation "nonexistant" does not exist' in line 47.
 [NO_PID]: ECPGtrans line 48 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 51: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 51: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 51: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGcheck_PQresult line 51: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 51, ''relation "nonexistant" does not exist' in line 51.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
 [NO_PID]: ECPGtrans line 52 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 55: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGexecute line 55: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGcheck_PQresult line 55: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 55, ''relation "nonexistant" does not exist' in line 55.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
 [NO_PID]: ECPGtrans line 59 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 62: QUERY: select  *  from nonexistant    on connection regress1
+[NO_PID]: ECPGexecute line 62: QUERY: select  *  from nonexistant    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 62: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 62: Error: ERROR:  relation "nonexistant" does not exist
+[NO_PID]: ECPGcheck_PQresult line 62: Error: ERROR:  relation "nonexistant" does not exist
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlstate 42P01 (sqlcode: -400) in line 62, ''relation "nonexistant" does not exist' in line 62.'.
 [NO_PID]: sqlca: code: -400, state: 42P01
diff --git a/src/interfaces/ecpg/test/expected/sql-array.c b/src/interfaces/ecpg/test/expected/sql-array.c
index f63d7247f1ef0a21836599e03ab917f1349e54b5..0a7af6dc4b0a18f3f2e5d2db7c7bcc43a936544e 100644
--- a/src/interfaces/ecpg/test/expected/sql-array.c
+++ b/src/interfaces/ecpg/test/expected/sql-array.c
@@ -156,21 +156,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 31 "array.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( f float    , i int   , a int [ 10 ]   , text char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( f float    , i int   , a int [ 10 ]   , text char  ( 10 )    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 33 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 33 "array.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f  , i  , a  , text  ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' ) ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( f  , i  , a  , text  ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 35 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 35 "array.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f  , i  , a  , text  ) values ( 140787.0 , 2 ,  ? ,  ? ) ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( f  , i  , a  , text  ) values ( 140787.0 , 2 ,  $1  ,  $2  ) ", 
 	ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
@@ -180,8 +180,8 @@ if (sqlca.sqlcode < 0) sqlprint();}
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "array.pgc"
 
-	
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( f  , i  , a  , text  ) values ( 14.07 ,  ? ,  ? ,  ? ) ", 
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( f  , i  , a  , text  ) values ( 14.07 ,  $1  ,  $2  ,  $3  ) ", 
 	ECPGt_int,&(did),(long)1,(long)0,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
@@ -208,7 +208,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 43 "array.pgc"
  
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  f , text  from test where i = 1  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  f , text  from test where i = 1  ", ECPGt_EOIT, 
 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
@@ -222,7 +222,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	printf("Found f=%f text=%10.10s\n", f, text);
 
 	f=140787;
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  a , text  from test where f =  ?  ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  a , text  from test where f =  $1   ", 
 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
@@ -240,7 +240,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	printf("Found text=%10.10s\n", t);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  a  from test where f =  ?  ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  a  from test where f =  $1   ", 
 	ECPGt_double,&(f),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
@@ -253,7 +253,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	printf("Found text=%s\n", text);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
 #line 70 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/sql-array.stderr b/src/interfaces/ecpg/test/expected/sql-array.stderr
index 00eda214549fefba6803a5dd03ea9e11937eb3a4..949c9967272477a14c4fb632b1542d4c6046538c 100644
--- a/src/interfaces/ecpg/test/expected/sql-array.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-array.stderr
@@ -6,19 +6,37 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 31 action = begin transaction  connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 33: QUERY: create  table test ( f float    , i int   , a int [ 10 ]   , text char  ( 10 )    )     on connection regress1
+[NO_PID]: ECPGexecute line 33: QUERY: create  table test ( f float    , i int   , a int [ 10 ]   , text char  ( 10 )    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 33 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: insert into test ( f  , i  , a  , text  ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' )  on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: insert into test ( f  , i  , a  , text  ) values ( 404.90 , 3 , '{0,1,2,3,4,5,6,7,8,9}' , 'abcdefghij' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: insert into test ( f  , i  , a  , text  ) values ( 140787.0 , 2 ,  array [9,8,7,6,5,4,3,2,1,0] ,  'klmnopqrst' )  on connection regress1
+[NO_PID]: ECPGexecute line 37: QUERY: insert into test ( f  , i  , a  , text  ) values ( 140787.0 , 2 ,  $1  ,  $2  )  with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: parameter 1 = {9,8,7,6,5,4,3,2,1,0}
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: parameter 2 = klmnopqrst
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: insert into test ( f  , i  , a  , text  ) values ( 14.07 ,  1 ,  array [9,8,7,6,5,4,3,2,1,0] ,  '0123456789' )  on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: insert into test ( f  , i  , a  , text  ) values ( 14.07 ,  $1  ,  $2  ,  $3  )  with 3 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: parameter 2 = {9,8,7,6,5,4,3,2,1,0}
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: parameter 3 = 0123456789
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 39 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -26,7 +44,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 43 action = begin transaction  connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 45: QUERY: select  f , text  from test where i = 1   on connection regress1
+[NO_PID]: ECPGexecute line 45: QUERY: select  f , text  from test where i = 1   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 45: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 45: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -34,7 +54,11 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 45: RESULT: 0123456789 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 53: QUERY: select  a , text  from test where f =  140787   on connection regress1
+[NO_PID]: ECPGexecute line 53: QUERY: select  a , text  from test where f =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: parameter 1 = 140787
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 53: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -44,13 +68,19 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 53: RESULT: klmnopqrst offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 63: QUERY: select  a  from test where f =  140787   on connection regress1
+[NO_PID]: ECPGexecute line 63: QUERY: select  a  from test where f =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 63: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 63: parameter 1 = 140787
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 63: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 63: RESULT: {9,8,7,6,5,4,3,2,1,0} offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 70: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 70: QUERY: drop table test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 70: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 70 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c
index dd59da207b1d3b8a413cf921d4a9fcd862f14606..b022c901baebfe633b0721965f55d80606c9d2c6 100644
--- a/src/interfaces/ecpg/test/expected/sql-binary.c
+++ b/src/interfaces/ecpg/test/expected/sql-binary.c
@@ -75,7 +75,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , byte bytea    )    ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , byte bytea    )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 36 "binary.pgc"
 
   if (sqlca.sqlcode)
@@ -84,7 +84,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into empl values ( 1 , 'first user' , 320 ,  ? ) ", 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into empl values ( 1 , 'first user' , 320 ,  $1  ) ", 
 	ECPGt_char,&(data),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
 #line 43 "binary.pgc"
@@ -95,15 +95,15 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  /* declare C  cursor  for select  name , accs , byte  from empl where idnum =  ?   */
+  /* declare C  cursor  for select  name , accs , byte  from empl where idnum =  $1    */
 #line 50 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "declare C  cursor  for select  name , accs , byte  from empl where idnum =  ?  ", 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare C  cursor  for select  name , accs , byte  from empl where idnum =  $1   ", 
 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
 #line 51 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "fetch C", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch C", ECPGt_EOIT, 
 	ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), 
@@ -122,15 +122,15 @@ main (void)
 
   memset(empl.name, 0, 21L);
   memset(empl.byte, '#', 20L);
-  /* declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  ?   */
+  /* declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  $1    */
 #line 63 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  ?  ", 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  $1   ", 
 	ECPGt_long,&(empl.idnum),(long)1,(long)1,sizeof(long), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
 #line 64 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "fetch B", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch B", ECPGt_EOIT, 
 	ECPGt_char,(empl.name),(long)21,(long)1,(21)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_short,&(empl.accs),(long)1,(long)1,sizeof(short), 
@@ -145,7 +145,7 @@ main (void)
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "close B", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close B", ECPGt_EOIT, ECPGt_EORT);}
 #line 72 "binary.pgc"
 
 
diff --git a/src/interfaces/ecpg/test/expected/sql-binary.stderr b/src/interfaces/ecpg/test/expected/sql-binary.stderr
index 42eef431f07613bb9f14f7c67248f4fe110b74e2..38b1bf29ff825b6747ae87af537df9272ce1d6f9 100644
--- a/src/interfaces/ecpg/test/expected/sql-binary.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-binary.stderr
@@ -2,19 +2,31 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , byte bytea    )     on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: create  table empl ( idnum integer   , name char  ( 20 )    , accs smallint   , byte bytea    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: QUERY: insert into empl values ( 1 , 'first user' , 320 ,  E'\\001\\155\\000\\212' )  on connection regress1
+[NO_PID]: ECPGexecute line 43: QUERY: insert into empl values ( 1 , 'first user' , 320 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: parameter 1 = \001\155\000\212
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 43 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 51: QUERY: declare C  cursor  for select  name , accs , byte  from empl where idnum =  1   on connection regress1
+[NO_PID]: ECPGexecute line 51: QUERY: declare C  cursor  for select  name , accs , byte  from empl where idnum =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: parameter 1 = 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 51 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 52: QUERY: fetch C on connection regress1
+[NO_PID]: ECPGexecute line 52: QUERY: fetch C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 52: Correctly got 1 tuples with 3 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -24,11 +36,17 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 52: RESULT: \001m\000\212 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 64: QUERY: declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  1   on connection regress1
+[NO_PID]: ECPGexecute line 64: QUERY: declare B  binary cursor  for select  name , accs , byte  from empl where idnum =  $1    with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: parameter 1 = 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 64 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 65: QUERY: fetch B on connection regress1
+[NO_PID]: ECPGexecute line 65: QUERY: fetch B with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 65: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 65: Correctly got 1 tuples with 3 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -38,7 +56,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 65: RESULT: BINARY offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 72: QUERY: close B on connection regress1
+[NO_PID]: ECPGexecute line 72: QUERY: close B with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 72: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 72 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-code100.c b/src/interfaces/ecpg/test/expected/sql-code100.c
index c37d82c2e1871a10adf95ac09622226c336355ef..592c290fbc4f18174b8e48a9d04140747e2c0475 100644
--- a/src/interfaces/ecpg/test/expected/sql-code100.c
+++ b/src/interfaces/ecpg/test/expected/sql-code100.c
@@ -111,7 +111,7 @@ int main(int argc, char **argv)
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( \"index\" numeric ( 3 )   primary key   , \"payload\" int4    not null )    ", ECPGt_EOIT, ECPGt_EORT);}
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( \"index\" numeric ( 3 )   primary key   , \"payload\" int4    not null )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 20 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
@@ -121,7 +121,7 @@ int main(int argc, char **argv)
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
    
    for (index=0;index<10;++index)
-   {  { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( payload  , index  ) values ( 0 ,  ? ) ", 
+   {  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( payload  , index  ) values ( 0 ,  $1  ) ", 
 	ECPGt_int,&(index),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
 #line 28 "code100.pgc"
@@ -133,22 +133,22 @@ int main(int argc, char **argv)
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "update test set payload  = payload + 1  where index = - 1 ", ECPGt_EOIT, ECPGt_EORT);}
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "update test set payload  = payload + 1  where index = - 1 ", ECPGt_EOIT, ECPGt_EORT);}
 #line 35 "code100.pgc"
 
    if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "delete from test  where index = - 1 ", ECPGt_EOIT, ECPGt_EORT);}
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "delete from test  where index = - 1 ", ECPGt_EOIT, ECPGt_EORT);}
 #line 38 "code100.pgc"
 
    if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( select  *  from test where index = - 1   ) ", ECPGt_EOIT, ECPGt_EORT);}
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( select  *  from test where index = - 1   ) ", ECPGt_EOIT, ECPGt_EORT);}
 #line 41 "code100.pgc"
 
    if (sqlca.sqlcode!=100) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);}
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);}
 #line 44 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
diff --git a/src/interfaces/ecpg/test/expected/sql-code100.stderr b/src/interfaces/ecpg/test/expected/sql-code100.stderr
index 83fd9c2ac58232af13564f11e671e974db6bda26..c3d90660c16c5fc86b66def974dd19bb634132b1 100644
--- a/src/interfaces/ecpg/test/expected/sql-code100.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-code100.stderr
@@ -2,73 +2,123 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 18: QUERY: create  table test ( "index" numeric ( 3 )   primary key   , "payload" int4    not null )     on connection regress1
+[NO_PID]: ECPGexecute line 18: QUERY: create  table test ( "index" numeric ( 3 )   primary key   , "payload" int4    not null )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 18: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 18 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 22 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  0 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  1 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  2 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 2
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  3 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 3
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  4 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 4
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  5 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 5
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  6 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 6
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  7 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 7
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  8 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 8
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  9 )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test ( payload  , index  ) values ( 0 ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: parameter 1 = 9
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 31 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34: QUERY: update test set payload  = payload + 1  where index = - 1  on connection regress1
+[NO_PID]: ECPGexecute line 34: QUERY: update test set payload  = payload + 1  where index = - 1  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 34: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 34 Ok: UPDATE 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 34, 'No data found in line 34.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 38: QUERY: delete from test  where index = - 1  on connection regress1
+[NO_PID]: ECPGexecute line 38: QUERY: delete from test  where index = - 1  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 38: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 38 Ok: DELETE 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 38, 'No data found in line 38.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 41: QUERY: insert into test ( select  *  from test where index = - 1   )  on connection regress1
+[NO_PID]: ECPGexecute line 41: QUERY: insert into test ( select  *  from test where index = - 1   )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 41 Ok: INSERT 0 0
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 41, 'No data found in line 41.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 44: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 44: QUERY: drop table test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 44: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 44 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-copystdout.c b/src/interfaces/ecpg/test/expected/sql-copystdout.c
index 3b39688ff13af7dde90e6fdeb95391f88834d951..c12c9e1b2faad5dec267a4b6617a403ccf6c6d65 100644
--- a/src/interfaces/ecpg/test/expected/sql-copystdout.c
+++ b/src/interfaces/ecpg/test/expected/sql-copystdout.c
@@ -113,25 +113,25 @@ main ()
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 19 "copystdout.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table foo ( a int   , b varchar    )    ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table foo ( a int   , b varchar    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 20 "copystdout.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 20 "copystdout.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into foo values ( 5 , 'abc' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into foo values ( 5 , 'abc' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 21 "copystdout.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 21 "copystdout.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into foo values ( 6 , 'def' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into foo values ( 6 , 'def' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "copystdout.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "copystdout.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into foo values ( 7 , 'ghi' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into foo values ( 7 , 'ghi' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 23 "copystdout.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -142,7 +142,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* EXEC SQL COPY foo TO:fname WITH DELIMITER ','; */
   /* printf ("copy to /tmp/foo : sqlca.sqlcode = %ld", sqlca.sqlcode); */
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "copy  foo  to stdout  with  delimiter  ','", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "copy  foo  to stdout  with  delimiter  ','", ECPGt_EOIT, ECPGt_EORT);
 #line 29 "copystdout.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/sql-copystdout.stderr b/src/interfaces/ecpg/test/expected/sql-copystdout.stderr
index b56845c1fe17eea22973192971cb5f63d252a4dd..3c86e1b603446688e9aef381ec309bc65e055ff8 100644
--- a/src/interfaces/ecpg/test/expected/sql-copystdout.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-copystdout.stderr
@@ -2,23 +2,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 20: QUERY: create  table foo ( a int   , b varchar    )     on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: create  table foo ( a int   , b varchar    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 20 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 21: QUERY: insert into foo values ( 5 , 'abc' )  on connection regress1
+[NO_PID]: ECPGexecute line 21: QUERY: insert into foo values ( 5 , 'abc' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 21 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: insert into foo values ( 6 , 'def' )  on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: insert into foo values ( 6 , 'def' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: insert into foo values ( 7 , 'ghi' )  on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: insert into foo values ( 7 , 'ghi' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: copy  foo  to stdout  with  delimiter  ',' on connection regress1
+[NO_PID]: ECPGexecute line 29: QUERY: copy  foo  to stdout  with  delimiter  ',' with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29: Got PGRES_COPY_OUT
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-define.c b/src/interfaces/ecpg/test/expected/sql-define.c
index e3b725fe9750b309a2a0a483abe84434205e4d03..7118bd1cc387e71802267ab5285d8020250a0e49 100644
--- a/src/interfaces/ecpg/test/expected/sql-define.c
+++ b/src/interfaces/ecpg/test/expected/sql-define.c
@@ -120,13 +120,13 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 17 "define.pgc"
 
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 19 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 19 "define.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 29 , 'abcdef' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 29 , 'abcdef' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 20 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -134,7 +134,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
 
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( null , 'defined' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( null , 'defined' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 23 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -147,7 +147,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
    
            
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( null , 'someothervar not defined' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( null , 'someothervar not defined' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 31 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -157,7 +157,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
    
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "select  1 , 29 :: text   || '-' || 'abcdef'     ", ECPGt_EOIT, 
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  1 , 29 :: text   || '-' || 'abcdef'     ", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(s),(long)200,(long)1,(200)*sizeof(char), 
@@ -172,7 +172,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 
    
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 29 , 'no string' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 29 , 'no string' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 42 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -188,7 +188,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
    
         
    
-   { ECPGdo(__LINE__, 0, 1, NULL, "set TIMEZONE to 'UTC'", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set TIMEZONE to 'UTC'", ECPGt_EOIT, ECPGt_EORT);
 #line 53 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
diff --git a/src/interfaces/ecpg/test/expected/sql-define.stderr b/src/interfaces/ecpg/test/expected/sql-define.stderr
index 7c93e03e862971e89deb6fc48e6fa739313bfc8a..dd9d25e0e722ee7d724b30607c5370b2bb4c7146 100644
--- a/src/interfaces/ecpg/test/expected/sql-define.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-define.stderr
@@ -2,23 +2,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19: QUERY: create  table test ( a int   , b text    )     on connection regress1
+[NO_PID]: ECPGexecute line 19: QUERY: create  table test ( a int   , b text    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 19 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 20: QUERY: insert into test values ( 29 , 'abcdef' )  on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: insert into test values ( 29 , 'abcdef' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 20 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: insert into test values ( null , 'defined' )  on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: insert into test values ( null , 'defined' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: insert into test values ( null , 'someothervar not defined' )  on connection regress1
+[NO_PID]: ECPGexecute line 31: QUERY: insert into test values ( null , 'someothervar not defined' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 31 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: select  1 , 29 :: text   || '-' || 'abcdef'      on connection regress1
+[NO_PID]: ECPGexecute line 36: QUERY: select  1 , 29 :: text   || '-' || 'abcdef'      with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 36: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -26,11 +36,15 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 36: RESULT: 29-abcdef offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 42: QUERY: insert into test values ( 29 , 'no string' )  on connection regress1
+[NO_PID]: ECPGexecute line 42: QUERY: insert into test values ( 29 , 'no string' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 42 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 53: QUERY: set TIMEZONE to 'UTC' on connection regress1
+[NO_PID]: ECPGexecute line 53: QUERY: set TIMEZONE to 'UTC' with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 53 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-desc.c b/src/interfaces/ecpg/test/expected/sql-desc.c
index 94bfba931d67f04cebf09d26fe871e695822e73c..1a269880db15940a67edd13e72c51c2d54a7df81 100644
--- a/src/interfaces/ecpg/test/expected/sql-desc.c
+++ b/src/interfaces/ecpg/test/expected/sql-desc.c
@@ -37,13 +37,13 @@ main(void)
 	  
 	
 #line 8 "desc.pgc"
- char * stmt1   = "INSERT INTO test1 VALUES (?, ?)" ;
+ char * stmt1   = "INSERT INTO test1 VALUES ($1, $2)" ;
  
 #line 9 "desc.pgc"
- char * stmt2   = "SELECT * from test1 where a = ? and b = ?" ;
+ char * stmt2   = "SELECT * from test1 where a = $1 and b = $2" ;
  
 #line 10 "desc.pgc"
- char * stmt3   = "SELECT * from test1 where a = ?" ;
+ char * stmt3   = "SELECT * from test1 where :var = a" ;
  
 #line 12 "desc.pgc"
  int  val1   = 1 ;
@@ -103,260 +103,271 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 27 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test1 ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test1 ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 29 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 29 "desc.pgc"
 
-	{ ECPGprepare(__LINE__, "foo1" , stmt1);
+	{ ECPGprepare(__LINE__, NULL, 0, "foo1", stmt1);
 #line 30 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "desc.pgc"
 
-	{ ECPGprepare(__LINE__, "foo2" , stmt2);
+	{ ECPGprepare(__LINE__, NULL, 0, "Foo-1", stmt1);
 #line 31 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 31 "desc.pgc"
 
-	{ ECPGprepare(__LINE__, "foo3" , stmt3);
+	{ ECPGprepare(__LINE__, NULL, 0, "foo2", stmt2);
 #line 32 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 32 "desc.pgc"
 
+	{ ECPGprepare(__LINE__, NULL, 0, "foo3", stmt3);
+#line 33 "desc.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo1")),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 33 "desc.pgc"
+
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo1", 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 34 "desc.pgc"
+#line 35 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 34 "desc.pgc"
+#line 35 "desc.pgc"
 
 
 	{ ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
 	ECPGt_const,"2",(long)1,(long)1,strlen("2"), ECPGd_EODT);
 
-#line 36 "desc.pgc"
+#line 37 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 36 "desc.pgc"
+#line 37 "desc.pgc"
 
 	{ ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
 	ECPGt_char,(val2),(long)4,(long)1,(4)*sizeof(char), ECPGd_indicator,
 	ECPGt_int,&(val2null),(long)1,(long)1,sizeof(int), ECPGd_EODT);
 
-#line 37 "desc.pgc"
+#line 38 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 37 "desc.pgc"
+#line 38 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo1")),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo1", 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 39 "desc.pgc"
+#line 40 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 39 "desc.pgc"
+#line 40 "desc.pgc"
 
 
 	{ ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
 	ECPGt_const,"3",(long)1,(long)1,strlen("3"), ECPGd_EODT);
 
-#line 41 "desc.pgc"
+#line 42 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 41 "desc.pgc"
+#line 42 "desc.pgc"
 
 	{ ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
 	ECPGt_const,"this is a long test",(long)19,(long)1,strlen("this is a long test"), ECPGd_indicator,
 	ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
 
-#line 42 "desc.pgc"
+#line 43 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 42 "desc.pgc"
+#line 43 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo1")),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "Foo-1", 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 44 "desc.pgc"
+#line 45 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 44 "desc.pgc"
+#line 45 "desc.pgc"
+
+
+	{ ECPGdeallocate(__LINE__, 0, "Foo-1");
+#line 47 "desc.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 47 "desc.pgc"
 
 
 	{ ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
 	ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
 
-#line 46 "desc.pgc"
+#line 49 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 46 "desc.pgc"
+#line 49 "desc.pgc"
 
 	{ ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
 	ECPGt_char,(val2),(long)4,(long)1,(4)*sizeof(char), ECPGd_indicator,
 	ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGd_EODT);
 
-#line 47 "desc.pgc"
+#line 50 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 47 "desc.pgc"
+#line 50 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo2")),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "foo2", 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_descriptor, "outdesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 49 "desc.pgc"
+#line 52 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 49 "desc.pgc"
+#line 52 "desc.pgc"
 
 
 	{ ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data,
 	ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), ECPGd_EODT);
 
-#line 51 "desc.pgc"
+#line 54 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 51 "desc.pgc"
+#line 54 "desc.pgc"
 
 	printf("output = %s\n", val2output);
 
-	/* declare c1  cursor  for ? */
-#line 54 "desc.pgc"
+	/* declare c1  cursor  for $1 */
+#line 57 "desc.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "declare c1  cursor  for ?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo2")),(long)1,(long)1,(1)*sizeof(char), 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare c1  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("foo2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 55 "desc.pgc"
+#line 58 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 55 "desc.pgc"
+#line 58 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c1", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch next from c1", ECPGt_EOIT, 
 	ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), 
 	ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
 	ECPGt_int,&(ind2),(long)1,(long)1,sizeof(int), ECPGt_EORT);
-#line 57 "desc.pgc"
+#line 60 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 57 "desc.pgc"
+#line 60 "desc.pgc"
 
 	printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n",
 		val1output, ind1, val2output, ind2);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "close c1", ECPGt_EOIT, ECPGt_EORT);
-#line 61 "desc.pgc"
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close c1", ECPGt_EOIT, ECPGt_EORT);
+#line 64 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 61 "desc.pgc"
+#line 64 "desc.pgc"
 
 
 	{ ECPGset_desc_header(__LINE__, "indesc", (int)(1));
 
-#line 63 "desc.pgc"
+#line 66 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 63 "desc.pgc"
+#line 66 "desc.pgc"
 
 	{ ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
 	ECPGt_const,"2",(long)1,(long)1,strlen("2"), ECPGd_EODT);
 
-#line 64 "desc.pgc"
+#line 67 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 64 "desc.pgc"
+#line 67 "desc.pgc"
 
 
-	/* declare c2  cursor  for ? */
-#line 66 "desc.pgc"
+	/* declare c2  cursor  for $1 */
+#line 69 "desc.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "declare c2  cursor  for ?", 
-	ECPGt_char_variable,(ECPGprepared_statement("foo3")),(long)1,(long)1,(1)*sizeof(char), 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare c2  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("foo3", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_descriptor, "indesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 67 "desc.pgc"
+#line 70 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 67 "desc.pgc"
+#line 70 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "fetch next from c2", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch next from c2", ECPGt_EOIT, 
 	ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
 	ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
-#line 69 "desc.pgc"
+#line 72 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 69 "desc.pgc"
+#line 72 "desc.pgc"
 
 	printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "close c2", ECPGt_EOIT, ECPGt_EORT);
-#line 72 "desc.pgc"
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close c2", ECPGt_EOIT, ECPGt_EORT);
+#line 75 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 72 "desc.pgc"
+#line 75 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  *  from test1 where a = 3  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from test1 where a = 3  ", ECPGt_EOIT, 
 	ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val2output),(long)sizeof("AAA"),(long)1,(sizeof("AAA"))*sizeof(char), 
 	ECPGt_int,&(val2i),(long)1,(long)1,sizeof(int), ECPGt_EORT);
-#line 74 "desc.pgc"
+#line 77 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 74 "desc.pgc"
+#line 77 "desc.pgc"
 
 	printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test1 ", ECPGt_EOIT, ECPGt_EORT);
-#line 77 "desc.pgc"
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test1 ", ECPGt_EOIT, ECPGt_EORT);
+#line 80 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 77 "desc.pgc"
+#line 80 "desc.pgc"
+
+	{ ECPGdeallocate_all(__LINE__, 0);
+#line 81 "desc.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 81 "desc.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
-#line 78 "desc.pgc"
+#line 82 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 78 "desc.pgc"
+#line 82 "desc.pgc"
 
 
 	ECPGdeallocate_desc(__LINE__, "indesc");
-#line 80 "desc.pgc"
+#line 84 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();
-#line 80 "desc.pgc"
+#line 84 "desc.pgc"
 
 	ECPGdeallocate_desc(__LINE__, "outdesc");
-#line 81 "desc.pgc"
+#line 85 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();
-#line 81 "desc.pgc"
+#line 85 "desc.pgc"
 
 
 	return 0;
diff --git a/src/interfaces/ecpg/test/expected/sql-desc.stderr b/src/interfaces/ecpg/test/expected/sql-desc.stderr
index 841964bd3182e5a2491d0b22ff3b1b7193c493a6..d6175b94a312532ff54e9acb9d1c6b08cdbd5262 100644
--- a/src/interfaces/ecpg/test/expected/sql-desc.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-desc.stderr
@@ -2,81 +2,139 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: create  table test1 ( a int   , b text    )     on connection regress1
+[NO_PID]: ECPGexecute line 29: QUERY: create  table test1 ( a int   , b text    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 30: QUERY: INSERT INTO test1 VALUES (?, ?)
+[NO_PID]: ECPGprepare line 30: NAME: foo1 QUERY: INSERT INTO test1 VALUES ($1, $2)
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 31: NAME: Foo-1 QUERY: INSERT INTO test1 VALUES ($1, $2)
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 32: NAME: foo2 QUERY: SELECT * from test1 where a = $1 and b = $2
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 33: NAME: foo3 QUERY: SELECT * from test1 where $1 = a
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: QUERY: INSERT INTO test1 VALUES ($1, $2) with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexecPrepared for INSERT INTO test1 VALUES ($1, $2)
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: parameter 2 = one
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: QUERY: INSERT INTO test1 VALUES ($1, $2) with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: using PQexecPrepared for INSERT INTO test1 VALUES ($1, $2)
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: parameter 1 = 2
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: parameter 2 = null
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 45: QUERY: INSERT INTO test1 VALUES ($1, $2) with 2 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 31: QUERY: SELECT * from test1 where a = ? and b = ?
+[NO_PID]: ECPGexecute line 45: using PQexecPrepared for INSERT INTO test1 VALUES ($1, $2)
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 32: QUERY: SELECT * from test1 where a = ?
+[NO_PID]: ECPGexecute line 45: parameter 1 = 3
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34: QUERY: INSERT INTO test1 VALUES ('1', 'one') on connection regress1
+[NO_PID]: ECPGexecute line 45: parameter 2 = this is a long test
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 45 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: INSERT INTO test1 VALUES ('2', null) on connection regress1
+[NO_PID]: ECPGdeallocate line 47: NAME: Foo-1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 52: QUERY: SELECT * from test1 where a = $1 and b = $2 with 2 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 44: QUERY: INSERT INTO test1 VALUES ('3', 'this is a long test') on connection regress1
+[NO_PID]: ECPGexecute line 52: using PQexecPrepared for SELECT * from test1 where a = $1 and b = $2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 44 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 52: parameter 1 = 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 49: QUERY: SELECT * from test1 where a = '1' and b = 'one' on connection regress1
+[NO_PID]: ECPGexecute line 52: parameter 2 = one
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 49: Correctly got 1 tuples with 2 fields
+[NO_PID]: ECPGexecute line 52: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute putting result (1 tuples) into descriptor 'outdesc'
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_desc: reading items for tuple 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 51: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: ECPGget_data line 54: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58: QUERY: declare c1  cursor  for SELECT * from test1 where a = $1 and b = $2 with 2 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58: parameter 2 = one
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 58 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: QUERY: fetch next from c1 with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: Correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 60: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 60: RESULT: one offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: QUERY: close c1 with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64 Ok: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 70: QUERY: declare c2  cursor  for SELECT * from test1 where $1 = a with 1 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55: QUERY: declare c1  cursor  for SELECT * from test1 where a = '1' and b = 'one' on connection regress1
+[NO_PID]: ECPGexecute line 70: using PQexecParams 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55 Ok: DECLARE CURSOR
+[NO_PID]: ECPGexecute line 70: parameter 1 = 2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 57: QUERY: fetch next from c1 on connection regress1
+[NO_PID]: ECPGexecute line 70 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 57: Correctly got 1 tuples with 2 fields
+[NO_PID]: ECPGexecute line 72: QUERY: fetch next from c2 with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 57: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 72: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 57: RESULT: one offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 72: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 61: QUERY: close c1 on connection regress1
+[NO_PID]: ECPGget_data line 72: RESULT: 2 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 61 Ok: CLOSE CURSOR
+[NO_PID]: ECPGget_data line 72: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 67: QUERY: declare c2  cursor  for SELECT * from test1 where a = '2' on connection regress1
+[NO_PID]: ECPGexecute line 75: QUERY: close c2 with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 67 Ok: DECLARE CURSOR
+[NO_PID]: ECPGexecute line 75: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 69: QUERY: fetch next from c2 on connection regress1
+[NO_PID]: ECPGexecute line 75 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 69: Correctly got 1 tuples with 2 fields
+[NO_PID]: ECPGexecute line 77: QUERY: select  *  from test1 where a = 3   with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 69: RESULT: 2 offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 77: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 69: RESULT:  offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 77: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 72: QUERY: close c2 on connection regress1
+[NO_PID]: ECPGget_data line 77: RESULT: 3 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 72 Ok: CLOSE CURSOR
+[NO_PID]: ECPGget_data line 77: RESULT: this is a long test offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 74: QUERY: select  *  from test1 where a = 3   on connection regress1
+[NO_PID]: ECPGexecute line 80: QUERY: drop table test1  with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 74: Correctly got 1 tuples with 2 fields
+[NO_PID]: ECPGexecute line 80: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 74: RESULT: 3 offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 80 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 74: RESULT: this is a long test offset: -1 array: Yes
+[NO_PID]: ECPGdeallocate line 81: NAME: foo3
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 77: QUERY: drop table test1  on connection regress1
+[NO_PID]: ECPGdeallocate line 81: NAME: foo2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 77 Ok: DROP TABLE
+[NO_PID]: ECPGdeallocate line 81: NAME: foo1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection regress1 closed.
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-dynalloc.c b/src/interfaces/ecpg/test/expected/sql-dynalloc.c
index 0a9d71c3610f20ad6a2e9b9acde3314a33055539..480d1dde7889bc9a2e02f2da364ec331a601ad0b 100644
--- a/src/interfaces/ecpg/test/expected/sql-dynalloc.c
+++ b/src/interfaces/ecpg/test/expected/sql-dynalloc.c
@@ -178,26 +178,26 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 33 "dynalloc.pgc"
 
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "set datestyle to mdy", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set datestyle to mdy", ECPGt_EOIT, ECPGt_EORT);
 #line 35 "dynalloc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 35 "dynalloc.pgc"
 
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( a serial    , b numeric ( 12 , 3 )   , c varchar    , d varchar ( 3 )    , e char  ( 4 )    , f timestamptz    , g boolean   , h box    , i inet    )    ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( a serial    , b numeric ( 12 , 3 )   , c varchar    , d varchar ( 3 )    , e char  ( 4 )    , f timestamptz    , g boolean   , h box    , i inet    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 37 "dynalloc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 37 "dynalloc.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 23.456 , 'varchar' , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , true , '(1,2,3,4)' , '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 23.456 , 'varchar' , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , true , '(1,2,3,4)' , '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 38 "dynalloc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 38 "dynalloc.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 2.446456 , null , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , false , null , null ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 2.446456 , null , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , false , null , null ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 39 "dynalloc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -210,7 +210,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 if (sqlca.sqlcode < 0) sqlprint (  );
 #line 41 "dynalloc.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "select  a , b , c , d , e , f , g , h , i  from test    order by a  ", ECPGt_EOIT, 
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  a , b , c , d , e , f , g , h , i  from test    order by a  ", ECPGt_EOIT, 
 	ECPGt_descriptor, "mydesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 42 "dynalloc.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-dynalloc.stderr b/src/interfaces/ecpg/test/expected/sql-dynalloc.stderr
index 6cc0fb296cf773eb9b4d18fe60b8cfbae0285eb4..9d0af4c8d4d8864ff21e95b4b53bd357f5882554 100644
--- a/src/interfaces/ecpg/test/expected/sql-dynalloc.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-dynalloc.stderr
@@ -2,23 +2,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: set datestyle to mdy on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: set datestyle to mdy with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: create  table test ( a serial    , b numeric ( 12 , 3 )   , c varchar    , d varchar ( 3 )    , e char  ( 4 )    , f timestamptz    , g boolean   , h box    , i inet    )     on connection regress1
+[NO_PID]: ECPGexecute line 37: QUERY: create  table test ( a serial    , b numeric ( 12 , 3 )   , c varchar    , d varchar ( 3 )    , e char  ( 4 )    , f timestamptz    , g boolean   , h box    , i inet    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 38: QUERY: insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 23.456 , 'varchar' , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , true , '(1,2,3,4)' , '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128' )  on connection regress1
+[NO_PID]: ECPGexecute line 38: QUERY: insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 23.456 , 'varchar' , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , true , '(1,2,3,4)' , '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 38: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 38 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 2.446456 , null , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , false , null , null )  on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: insert into test ( b  , c  , d  , e  , f  , g  , h  , i  ) values ( 2.446456 , null , 'v' , 'c' , '2003-03-03 12:33:07 PDT' , false , null , null )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 39 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 42: QUERY: select  a , b , c , d , e , f , g , h , i  from test    order by a   on connection regress1
+[NO_PID]: ECPGexecute line 42: QUERY: select  a , b , c , d , e , f , g , h , i  from test    order by a   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 42: Correctly got 2 tuples with 9 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-dynalloc2.c b/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
index 2f3a76192b7f51101202260d36fac86b7faabea1..7773c0161af1d124c7f7553b8526fad91c4fe10d 100644
--- a/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
+++ b/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
@@ -132,50 +132,50 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 20 "dynalloc2.pgc"
 
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "set datestyle to postgres", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set datestyle to postgres", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 22 "dynalloc2.pgc"
 
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( a int   , b text    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 24 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 24 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 1 , 'one' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 1 , 'one' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 25 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 25 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 2 , 'two' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 2 , 'two' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 26 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 26 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( null , 'three' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( null , 'three' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 27 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 27 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 4 , 'four' ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 4 , 'four' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 28 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 28 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( 5 , null ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( 5 , null ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 29 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
 #line 29 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "insert into test values ( null , null ) ", ECPGt_EOIT, ECPGt_EORT);
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test values ( null , null ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 30 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint (  );}
@@ -188,7 +188,7 @@ if (sqlca.sqlcode < 0) sqlprint (  );}
 if (sqlca.sqlcode < 0) sqlprint (  );
 #line 32 "dynalloc2.pgc"
 
-   { ECPGdo(__LINE__, 0, 1, NULL, "select  *  from test   ", ECPGt_EOIT, 
+   { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  *  from test   ", ECPGt_EOIT, 
 	ECPGt_descriptor, "mydesc", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 33 "dynalloc2.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-dynalloc2.stderr b/src/interfaces/ecpg/test/expected/sql-dynalloc2.stderr
index f7063fd16f90d990a7425d2c91acdf59c0262948..c39524c5be7e4b67479da9d67e9dfed7cc29be79 100644
--- a/src/interfaces/ecpg/test/expected/sql-dynalloc2.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-dynalloc2.stderr
@@ -2,39 +2,57 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: set datestyle to postgres on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: set datestyle to postgres with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 24: QUERY: create  table test ( a int   , b text    )     on connection regress1
+[NO_PID]: ECPGexecute line 24: QUERY: create  table test ( a int   , b text    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 24 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 25: QUERY: insert into test values ( 1 , 'one' )  on connection regress1
+[NO_PID]: ECPGexecute line 25: QUERY: insert into test values ( 1 , 'one' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 25 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: insert into test values ( 2 , 'two' )  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: insert into test values ( 2 , 'two' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 27: QUERY: insert into test values ( null , 'three' )  on connection regress1
+[NO_PID]: ECPGexecute line 27: QUERY: insert into test values ( null , 'three' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 27: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 27 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 28: QUERY: insert into test values ( 4 , 'four' )  on connection regress1
+[NO_PID]: ECPGexecute line 28: QUERY: insert into test values ( 4 , 'four' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 28 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: insert into test values ( 5 , null )  on connection regress1
+[NO_PID]: ECPGexecute line 29: QUERY: insert into test values ( 5 , null )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 30: QUERY: insert into test values ( null , null )  on connection regress1
+[NO_PID]: ECPGexecute line 30: QUERY: insert into test values ( null , null )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 30 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 33: QUERY: select  *  from test    on connection regress1
+[NO_PID]: ECPGexecute line 33: QUERY: select  *  from test    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 33: Correctly got 6 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.c b/src/interfaces/ecpg/test/expected/sql-dyntest.c
index 075d2bba81acefee9ec51a6a9a60f0869f8428c2..00935417dd37716e8eca27bba9d130a8a5a35cba 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.c
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.c
@@ -226,44 +226,44 @@ if (sqlca.sqlcode < 0) error (  );}
 #line 47 "dyntest.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set datestyle to german", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set datestyle to german", ECPGt_EOIT, ECPGt_EORT);
 #line 49 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
 #line 49 "dyntest.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table dyntest ( name char  ( 14 )    , d float8    , i int   , bignumber int8    , b boolean   , comment text    , day date    )    ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table dyntest ( name char  ( 14 )    , d float8    , i int   , bignumber int8    , b boolean   , comment text    , day date    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 53 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
 #line 53 "dyntest.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true , 'The world''s most advanced open source database.' , '1987-07-14' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true , 'The world''s most advanced open source database.' , '1987-07-14' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 54 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
 #line 54 "dyntest.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210 , false , 'The elephant never forgets.' , '1999-11-5' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210 , false , 'The elephant never forgets.' , '1999-11-5' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 55 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
 #line 55 "dyntest.pgc"
 
 
-  { ECPGprepare(__LINE__, "MYQUERY" , QUERY);
+  { ECPGprepare(__LINE__, NULL, 0, "myquery", QUERY);
 #line 57 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
 #line 57 "dyntest.pgc"
 
-  /* declare MYCURS  cursor  for ? */
+  /* declare MYCURS  cursor  for $1 */
 #line 58 "dyntest.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "declare MYCURS  cursor  for ?", 
-	ECPGt_char_variable,(ECPGprepared_statement("MYQUERY")),(long)1,(long)1,(1)*sizeof(char), 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare MYCURS  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("myquery", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 60 "dyntest.pgc"
 
@@ -273,7 +273,7 @@ if (sqlca.sqlcode < 0) error (  );}
 
   while (1)
     {
-      { ECPGdo(__LINE__, 0, 1, NULL, "fetch in MYCURS", ECPGt_EOIT, 
+      { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch in MYCURS", ECPGt_EOIT, 
 	ECPGt_descriptor, "MYDESC", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 64 "dyntest.pgc"
@@ -472,7 +472,7 @@ if (sqlca.sqlcode < 0) error (  );}
 	}
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
 #line 197 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error (  );}
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.stderr b/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
index 87b46cac842e40f463d81deb921c358334c4b73c..bfeab8a9c7da9e2488fad8159a36c08dddfec96f 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.stderr
@@ -2,29 +2,41 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 49: QUERY: set datestyle to german on connection regress1
+[NO_PID]: ECPGexecute line 49: QUERY: set datestyle to german with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 49: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 49 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 51: QUERY: create  table dyntest ( name char  ( 14 )    , d float8    , i int   , bignumber int8    , b boolean   , comment text    , day date    )     on connection regress1
+[NO_PID]: ECPGexecute line 51: QUERY: create  table dyntest ( name char  ( 14 )    , d float8    , i int   , bignumber int8    , b boolean   , comment text    , day date    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 51: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 51 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 54: QUERY: insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true , 'The world''s most advanced open source database.' , '1987-07-14' )  on connection regress1
+[NO_PID]: ECPGexecute line 54: QUERY: insert into dyntest values ( 'first entry' , 14.7 , 14 , 123045607890 , true , 'The world''s most advanced open source database.' , '1987-07-14' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 54: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 54 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 55: QUERY: insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210 , false , 'The elephant never forgets.' , '1999-11-5' )  on connection regress1
+[NO_PID]: ECPGexecute line 55: QUERY: insert into dyntest values ( 'second entry' , 1407.87 , 1407 , 987065403210 , false , 'The elephant never forgets.' , '1999-11-5' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 55: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 55 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 57: QUERY: select * from dyntest
+[NO_PID]: ECPGprepare line 57: NAME: myquery QUERY: select * from dyntest
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 60: QUERY: declare MYCURS  cursor  for select * from dyntest with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 60: QUERY: declare MYCURS  cursor  for select * from dyntest on connection regress1
+[NO_PID]: ECPGexecute line 60: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 60 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS on connection regress1
+[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 64: Correctly got 1 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -192,7 +204,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 179: RESULT: 14.07.1987 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS on connection regress1
+[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 64: Correctly got 1 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -360,13 +374,17 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 179: RESULT: 05.11.1999 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS on connection regress1
+[NO_PID]: ECPGexecute line 64: QUERY: fetch in MYCURS with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 64: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 64: Correctly got 0 tuples with 7 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 64, 'No data found in line 64.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 197: QUERY: close MYCURS on connection regress1
+[NO_PID]: ECPGexecute line 197: QUERY: close MYCURS with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 197: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 197 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-execute.c b/src/interfaces/ecpg/test/expected/sql-execute.c
index 4e0c78e33c2510eadb1768eda4ea008cdcac2f43..cc66dd50c6770a32dc779c76cc7ad560c9605e82 100644
--- a/src/interfaces/ecpg/test/expected/sql-execute.c
+++ b/src/interfaces/ecpg/test/expected/sql-execute.c
@@ -65,7 +65,7 @@ main(void)
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 25 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -79,9 +79,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 
 	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
 #line 29 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -89,9 +87,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 
 	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
 #line 32 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -99,9 +95,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 
 	sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
 #line 35 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
@@ -110,16 +104,14 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
 
-	sprintf(command, "insert into test (name, amount, letter) select name, amount+?, letter from test");
-	{ ECPGprepare(__LINE__, "I" , command);
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
+	{ ECPGprepare(__LINE__, NULL, 0, "i", command);
 #line 40 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 40 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "?", 
-	ECPGt_char_variable,(ECPGprepared_statement("I")),(long)1,(long)1,(1)*sizeof(char), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i", 
 	ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 41 "execute.pgc"
@@ -139,25 +131,25 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	sprintf (command, "select * from test");
 
-	{ ECPGprepare(__LINE__, "F" , command);
+	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
 #line 49 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 49 "execute.pgc"
 
-	/* declare CUR  cursor  for ? */
+	/* declare CUR  cursor  for $1 */
 #line 50 "execute.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "declare CUR  cursor  for ?", 
-	ECPGt_char_variable,(ECPGprepared_statement("F")),(long)1,(long)1,(1)*sizeof(char), 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare CUR  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 52 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 52 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "fetch 8 in CUR", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch 8 in CUR", ECPGt_EOIT, 
 	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
@@ -189,46 +181,52 @@ if (sqlca.sqlcode < 0) sqlprint();}
 		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
 	}
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "close CUR", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close CUR", ECPGt_EOIT, ECPGt_EORT);
 #line 66 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 66 "execute.pgc"
 
+	{ ECPGdeallocate(__LINE__, 0, "f");
+#line 67 "execute.pgc"
 
-	sprintf (command, "select * from test where amount = ?");
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 67 "execute.pgc"
 
-	{ ECPGprepare(__LINE__, "F" , command);
-#line 70 "execute.pgc"
 
-if (sqlca.sqlcode < 0) sqlprint();}
-#line 70 "execute.pgc"
+	sprintf (command, "select * from test where amount = $1");
+
+	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
+#line 71 "execute.pgc"
 
-	/* declare CUR2  cursor  for ? */
+if (sqlca.sqlcode < 0) sqlprint();}
 #line 71 "execute.pgc"
 
+	/* declare CUR2  cursor  for $1 */
+#line 72 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "declare CUR2  cursor  for ?", 
-	ECPGt_char_variable,(ECPGprepared_statement("F")),(long)1,(long)1,(1)*sizeof(char), 
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare CUR2  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
-#line 73 "execute.pgc"
+#line 74 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 73 "execute.pgc"
+#line 74 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "fetch in CUR2", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch in CUR2", ECPGt_EOIT, 
 	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 74 "execute.pgc"
+#line 75 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 74 "execute.pgc"
+#line 75 "execute.pgc"
 
 
 	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
@@ -237,43 +235,43 @@ if (sqlca.sqlcode < 0) sqlprint();}
 		    
 		   
 		
-#line 79 "execute.pgc"
+#line 80 "execute.pgc"
  char  n [ 8 ]    ,  l   = letter [ i ] [ 0 ] ;
  
-#line 80 "execute.pgc"
+#line 81 "execute.pgc"
  int  a   = amount [ i ] ;
 /* exec sql end declare section */
-#line 81 "execute.pgc"
+#line 82 "execute.pgc"
 
 
 		strncpy(n, name[i], 8);
 		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
 	}
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
-#line 87 "execute.pgc"
-
-if (sqlca.sqlcode < 0) sqlprint();}
-#line 87 "execute.pgc"
-
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
 #line 88 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 88 "execute.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
 #line 89 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 89 "execute.pgc"
 
-	{ ECPGdisconnect(__LINE__, "CURRENT");
+	{ ECPGtrans(__LINE__, NULL, "commit");
 #line 90 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 90 "execute.pgc"
 
+	{ ECPGdisconnect(__LINE__, "CURRENT");
+#line 91 "execute.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 91 "execute.pgc"
+
 
 	return (0);
 }
diff --git a/src/interfaces/ecpg/test/expected/sql-execute.stderr b/src/interfaces/ecpg/test/expected/sql-execute.stderr
index d98cd7724c1191ee0791ba2dfa66ccdaee1f57dc..d6c76a9b8a96cd1f1bf1c25e7d3bc28fe2e55e6e 100644
--- a/src/interfaces/ecpg/test/expected/sql-execute.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-execute.stderr
@@ -2,39 +2,55 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 25: QUERY: create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )     on connection main
+[NO_PID]: ECPGexecute line 25: QUERY: create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )     with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 25 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 26 action = commit connection = main
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f') on connection main
+[NO_PID]: ECPGexecute line 29: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f') with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 29 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 2, 't') on connection main
+[NO_PID]: ECPGexecute line 32: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 2, 't') with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: insert into test (name, amount, letter) select name, amount+10, letter from test on connection main
+[NO_PID]: ECPGexecute line 35: QUERY: insert into test (name, amount, letter) select name, amount+10, letter from test with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35 Ok: INSERT 0 2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 40: QUERY: insert into test (name, amount, letter) select name, amount+?, letter from test
+[NO_PID]: ECPGprepare line 40: NAME: i QUERY: insert into test (name, amount, letter) select name, amount+$1, letter from test
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 41: QUERY: insert into test (name, amount, letter) select name, amount+100, letter from test on connection main
+[NO_PID]: ECPGexecute line 41: QUERY: insert into test (name, amount, letter) select name, amount+$1, letter from test with 1 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: using PQexecPrepared for insert into test (name, amount, letter) select name, amount+$1, letter from test
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: parameter 1 = 100
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 41 Ok: INSERT 0 4
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 45 action = commit connection = main
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 49: QUERY: select * from test
+[NO_PID]: ECPGprepare line 49: NAME: f QUERY: select * from test
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 52: QUERY: declare CUR  cursor  for select * from test on connection main
+[NO_PID]: ECPGexecute line 52: QUERY: declare CUR  cursor  for select * from test with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 52 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 53: QUERY: fetch 8 in CUR on connection main
+[NO_PID]: ECPGexecute line 53: QUERY: fetch 8 in CUR with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 53: Correctly got 8 tuples with 3 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -86,35 +102,49 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 53: RESULT: t offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 66: QUERY: close CUR on connection main
+[NO_PID]: ECPGexecute line 66: QUERY: close CUR with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 66 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGprepare line 70: QUERY: select * from test where amount = ?
+[NO_PID]: ECPGdeallocate line 67: NAME: f
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 71: NAME: f QUERY: select * from test where amount = $1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: QUERY: declare CUR2  cursor  for select * from test where amount = $1 with 1 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 75: QUERY: fetch in CUR2 with 0 parameter on connection main 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 73: QUERY: declare CUR2  cursor  for select * from test where amount = 1 on connection main
+[NO_PID]: ECPGexecute line 75: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 73 Ok: DECLARE CURSOR
+[NO_PID]: ECPGexecute line 75: Correctly got 1 tuples with 3 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 74: QUERY: fetch in CUR2 on connection main
+[NO_PID]: ECPGget_data line 75: RESULT: db: 'r1' offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 74: Correctly got 1 tuples with 3 fields
+[NO_PID]: ECPGget_data line 75: RESULT: 1 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 74: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: ECPGget_data line 75: RESULT: f offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 74: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 88: QUERY: close CUR2 with 0 parameter on connection main 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 74: RESULT: f offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 88: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 87: QUERY: close CUR2 on connection main
+[NO_PID]: ECPGexecute line 88 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 87 Ok: CLOSE CURSOR
+[NO_PID]: ECPGexecute line 89: QUERY: drop table test  with 0 parameter on connection main 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 88: QUERY: drop table test  on connection main
+[NO_PID]: ECPGexecute line 89: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 88 Ok: DROP TABLE
+[NO_PID]: ECPGexecute line 89 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGtrans line 89 action = commit connection = main
+[NO_PID]: ECPGtrans line 90 action = commit connection = main
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection main closed.
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.c b/src/interfaces/ecpg/test/expected/sql-fetch.c
index 9245e75ee342d417d7f80b6fa4c6266ac53834ca..0f69d3c848f7b8606e7750a28b09a1c28dfbceb4 100644
--- a/src/interfaces/ecpg/test/expected/sql-fetch.c
+++ b/src/interfaces/ecpg/test/expected/sql-fetch.c
@@ -26,13 +26,13 @@
 int main(int argc, char* argv[]) {
   /* exec sql begin declare section */
      
-        
+      
   
 #line 9 "fetch.pgc"
  char  str [ 25 ]    ;
  
 #line 10 "fetch.pgc"
- int  i    ,  how_many   = 1 ;
+ int  i    ;
 /* exec sql end declare section */
 #line 11 "fetch.pgc"
 
@@ -49,7 +49,7 @@ int main(int argc, char* argv[]) {
 #line 17 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table My_Table ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table My_Table ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 19 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -59,7 +59,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 19 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 1 , 'text1' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 1 , 'text1' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 21 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -68,7 +68,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 21 "fetch.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 2 , 'text2' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 2 , 'text2' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -77,7 +77,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "fetch.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 3 , 'text3' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 3 , 'text3' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 23 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -86,7 +86,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 23 "fetch.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 4 , 'text4' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 4 , 'text4' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 24 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -100,7 +100,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "declare C  cursor  for select  *  from My_Table   ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare C  cursor  for select  *  from My_Table   ", ECPGt_EOIT, ECPGt_EORT);
 #line 28 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -114,7 +114,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "fetch.pgc"
 
   while (1) {
-  	{ ECPGdo(__LINE__, 0, 1, NULL, "fetch 1 in C", ECPGt_EOIT, 
+  	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch 1 in C", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char), 
@@ -136,7 +136,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* exec sql whenever not found  continue ; */
 #line 36 "fetch.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
 #line 37 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -146,9 +146,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "fetch  ? in C", 
-	ECPGt_int,&(how_many),(long)1,(long)1,sizeof(int), 
-	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch 1 in C", ECPGt_EOIT, 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(str),(long)25,(long)1,(25)*sizeof(char), 
@@ -163,7 +161,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   printf("%d: %s\n", i, str);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "close C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close C", ECPGt_EOIT, ECPGt_EORT);
 #line 42 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -173,7 +171,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 42 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table My_Table ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table My_Table ", ECPGt_EOIT, ECPGt_EORT);
 #line 44 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.stderr b/src/interfaces/ecpg/test/expected/sql-fetch.stderr
index 4df892fb2e2df472e3650827f81561e425f153a8..acdd7bd90627ca96c182bcade9f32fa28c772945 100644
--- a/src/interfaces/ecpg/test/expected/sql-fetch.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-fetch.stderr
@@ -2,31 +2,45 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19: QUERY: create  table My_Table ( Item1 int   , Item2 text    )     on connection regress1
+[NO_PID]: ECPGexecute line 19: QUERY: create  table My_Table ( Item1 int   , Item2 text    )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 19 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 21: QUERY: insert into My_Table values ( 1 , 'text1' )  on connection regress1
+[NO_PID]: ECPGexecute line 21: QUERY: insert into My_Table values ( 1 , 'text1' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 21 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: insert into My_Table values ( 2 , 'text2' )  on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: insert into My_Table values ( 2 , 'text2' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: insert into My_Table values ( 3 , 'text3' )  on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: insert into My_Table values ( 3 , 'text3' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 24: QUERY: insert into My_Table values ( 4 , 'text4' )  on connection regress1
+[NO_PID]: ECPGexecute line 24: QUERY: insert into My_Table values ( 4 , 'text4' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 24 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 28: QUERY: declare C  cursor  for select  *  from My_Table    on connection regress1
+[NO_PID]: ECPGexecute line 28: QUERY: declare C  cursor  for select  *  from My_Table    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 28 Ok: DECLARE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -34,7 +48,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 32: RESULT: text1 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -42,7 +58,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 32: RESULT: text2 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -50,7 +68,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 32: RESULT: text3 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -58,17 +78,23 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 32: RESULT: text4 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C on connection regress1
+[NO_PID]: ECPGexecute line 32: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 32: Correctly got 0 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 100 in line 32, 'No data found in line 32.'.
 [NO_PID]: sqlca: code: 100, state: 02000
-[NO_PID]: ECPGexecute line 37: QUERY: move backward 2 in C on connection regress1
+[NO_PID]: ECPGexecute line 37: QUERY: move backward 2 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37 Ok: MOVE 2
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 39: QUERY: fetch  1 in C on connection regress1
+[NO_PID]: ECPGexecute line 39: QUERY: fetch 1 in C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 39: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -76,11 +102,15 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 39: RESULT: text4 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 42: QUERY: close C on connection regress1
+[NO_PID]: ECPGexecute line 42: QUERY: close C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 42 Ok: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 44: QUERY: drop table My_Table  on connection regress1
+[NO_PID]: ECPGexecute line 44: QUERY: drop table My_Table  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 44: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 44 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-func.c b/src/interfaces/ecpg/test/expected/sql-func.c
index 50b385ee97ba813cb9ec33dbb9aad53ffdf2ee15..cdcbc6ae06d1418a8fa88f3593083d158f700c17 100644
--- a/src/interfaces/ecpg/test/expected/sql-func.c
+++ b/src/interfaces/ecpg/test/expected/sql-func.c
@@ -24,57 +24,62 @@
 
 
 int main(int argc, char* argv[]) {
+  
+#line 8 "func.pgc"
+ char  text [ 25 ]    ;
+
+#line 8 "func.pgc"
+
 
   ECPGdebug(1, stderr);
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
-#line 10 "func.pgc"
+#line 11 "func.pgc"
 
 
   { ECPGsetcommit(__LINE__, "on", NULL);}
-#line 12 "func.pgc"
+#line 13 "func.pgc"
 
   /* exec sql whenever sql_warning  sqlprint ; */
-#line 13 "func.pgc"
+#line 14 "func.pgc"
 
   /* exec sql whenever sqlerror  sqlprint ; */
-#line 14 "func.pgc"
+#line 15 "func.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table My_Table ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
-#line 16 "func.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table My_Table ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 17 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 16 "func.pgc"
+#line 17 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 16 "func.pgc"
-
+#line 17 "func.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  function My_Table_Check () returns trigger   as $test$\
-    BEGIN\
-	RAISE WARNING 'Notice: TG_NAME=%, TG WHEN=%', TG_NAME, TG_WHEN;\
-	RETURN NEW;\
-    END; $test$ language plpgsql", ECPGt_EOIT, ECPGt_EORT);
-#line 24 "func.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table Log ( name text    , w text    )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 18 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 24 "func.pgc"
+#line 18 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 24 "func.pgc"
+#line 18 "func.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create trigger My_Table_Check_Trigger before insert on My_Table for each row execute procedure My_Table_Check (  )", ECPGt_EOIT, ECPGt_EORT);
-#line 30 "func.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  function My_Table_Check () returns trigger   as $test$\
+    BEGIN\
+	INSERT INTO Log VALUES(TG_NAME, TG_WHEN);\
+	RETURN NEW;\
+    END; $test$ language plpgsql", ECPGt_EOIT, ECPGt_EORT);
+#line 26 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 30 "func.pgc"
+#line 26 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 30 "func.pgc"
+#line 26 "func.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 1234 , 'Some random text' ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create trigger My_Table_Check_Trigger before insert on My_Table for each row execute procedure My_Table_Check (  )", ECPGt_EOIT, ECPGt_EORT);
 #line 32 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -83,17 +88,17 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 32 "func.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into My_Table values ( 5678 , 'The Quick Brown' ) ", ECPGt_EOIT, ECPGt_EORT);
-#line 33 "func.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 1234 , 'Some random text' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 34 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 33 "func.pgc"
+#line 34 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 33 "func.pgc"
-
+#line 34 "func.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop trigger My_Table_Check_Trigger on My_Table ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into My_Table values ( 5678 , 'The Quick Brown' ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 35 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -102,7 +107,9 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 35 "func.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop function My_Table_Check () ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  name  from Log     limit 1 ", ECPGt_EOIT, 
+	ECPGt_char,(text),(long)25,(long)1,(25)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 36 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -111,24 +118,53 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 36 "func.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table My_Table ", ECPGt_EOIT, ECPGt_EORT);
-#line 37 "func.pgc"
+  printf("Trigger %s fired.\n", text);
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop trigger My_Table_Check_Trigger on My_Table ", ECPGt_EOIT, ECPGt_EORT);
+#line 39 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 37 "func.pgc"
+#line 39 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 37 "func.pgc"
+#line 39 "func.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop function My_Table_Check () ", ECPGt_EOIT, ECPGt_EORT);
+#line 40 "func.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 40 "func.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 40 "func.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table Log ", ECPGt_EOIT, ECPGt_EORT);
+#line 41 "func.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 41 "func.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 41 "func.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table My_Table ", ECPGt_EOIT, ECPGt_EORT);
+#line 42 "func.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 42 "func.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 42 "func.pgc"
 
 
   { ECPGdisconnect(__LINE__, "ALL");
-#line 39 "func.pgc"
+#line 44 "func.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 39 "func.pgc"
+#line 44 "func.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 39 "func.pgc"
+#line 44 "func.pgc"
 
 
   return 0;
diff --git a/src/interfaces/ecpg/test/expected/sql-func.stderr b/src/interfaces/ecpg/test/expected/sql-func.stderr
index cffe4da7f11394a7241d01ada130eb78176d8941..cafe0cf6892634c5c04b3fbc150e3942074f43ee 100644
--- a/src/interfaces/ecpg/test/expected/sql-func.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-func.stderr
@@ -2,47 +2,75 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGsetcommit line 12 action = on connection = regress1
+[NO_PID]: ECPGsetcommit line 13 action = on connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 16: QUERY: create  table My_Table ( Item1 int   , Item2 text    )     on connection regress1
+[NO_PID]: ECPGexecute line 17: QUERY: create  table My_Table ( Item1 int   , Item2 text    )     with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 16 Ok: CREATE TABLE
+[NO_PID]: ECPGexecute line 17: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 18: QUERY: create  function My_Table_Check () returns trigger   as $test$    BEGIN	RAISE WARNING 'Notice: TG_NAME=%, TG WHEN=%', TG_NAME, TG_WHEN;	RETURN NEW;    END; $test$ language plpgsql on connection regress1
+[NO_PID]: ECPGexecute line 17 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 18 Ok: CREATE FUNCTION
+[NO_PID]: ECPGexecute line 18: QUERY: create  table Log ( name text    , w text    )     with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: create trigger My_Table_Check_Trigger before insert on My_Table for each row execute procedure My_Table_Check (  ) on connection regress1
+[NO_PID]: ECPGexecute line 18: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26 Ok: CREATE TRIGGER
+[NO_PID]: ECPGexecute line 18 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: insert into My_Table values ( 1234 , 'Some random text' )  on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: create  function My_Table_Check () returns trigger   as $test$    BEGIN	INSERT INTO Log VALUES(TG_NAME, TG_WHEN);	RETURN NEW;    END; $test$ language plpgsql with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: Notice: TG_NAME=my_table_check_trigger, TG WHEN=BEFORE[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode 0
-[NO_PID]: sqlca: code: 0, state: 01000
-[NO_PID]: ECPGexecute line 32 Ok: INSERT 0 1
-[NO_PID]: sqlca: code: 0, state: 01000
-sql error Notice: TG_NAME=my_table_check_trigger, TG WHEN=BEFORE
-[NO_PID]: ECPGexecute line 33: QUERY: insert into My_Table values ( 5678 , 'The Quick Brown' )  on connection regress1
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: Notice: TG_NAME=my_table_check_trigger, TG WHEN=BEFORE[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode 0
-[NO_PID]: sqlca: code: 0, state: 01000
-[NO_PID]: ECPGexecute line 33 Ok: INSERT 0 1
-[NO_PID]: sqlca: code: 0, state: 01000
-sql error Notice: TG_NAME=my_table_check_trigger, TG WHEN=BEFORE
-[NO_PID]: ECPGexecute line 35: QUERY: drop trigger My_Table_Check_Trigger on My_Table  on connection regress1
+[NO_PID]: ECPGexecute line 20 Ok: CREATE FUNCTION
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35 Ok: DROP TRIGGER
+[NO_PID]: ECPGexecute line 28: QUERY: create trigger My_Table_Check_Trigger before insert on My_Table for each row execute procedure My_Table_Check (  ) with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: drop function My_Table_Check ()  on connection regress1
+[NO_PID]: ECPGexecute line 28: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36 Ok: DROP FUNCTION
+[NO_PID]: ECPGexecute line 28 Ok: CREATE TRIGGER
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: drop table My_Table  on connection regress1
+[NO_PID]: ECPGexecute line 34: QUERY: insert into My_Table values ( 1234 , 'Some random text' )  with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37 Ok: DROP TABLE
+[NO_PID]: ECPGexecute line 34: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 34 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: QUERY: insert into My_Table values ( 5678 , 'The Quick Brown' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: QUERY: select  name  from Log     limit 1  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 36: Correctly got 1 tuples with 1 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 36: RESULT: my_table_check_trigger offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: QUERY: drop trigger My_Table_Check_Trigger on My_Table  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 39 Ok: DROP TRIGGER
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: QUERY: drop function My_Table_Check ()  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40 Ok: DROP FUNCTION
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: QUERY: drop table Log  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41 Ok: DROP TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: QUERY: drop table My_Table  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection regress1 closed.
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-func.stdout b/src/interfaces/ecpg/test/expected/sql-func.stdout
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9a3ec25264a488edc13b2549fa97f3f1b6b39b7f 100644
--- a/src/interfaces/ecpg/test/expected/sql-func.stdout
+++ b/src/interfaces/ecpg/test/expected/sql-func.stdout
@@ -0,0 +1 @@
+Trigger my_table_check_trigger fired.
diff --git a/src/interfaces/ecpg/test/expected/sql-indicators.c b/src/interfaces/ecpg/test/expected/sql-indicators.c
index 781a7216a07c0c59e9e245c60c89353ba33bbfec..7cc1a9dfa813a1d2d9a335c3784e6141bc79aee1 100644
--- a/src/interfaces/ecpg/test/expected/sql-indicators.c
+++ b/src/interfaces/ecpg/test/expected/sql-indicators.c
@@ -117,25 +117,25 @@ int main(int argc, char **argv)
 #line 17 "indicators.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( \"id\" int   primary key   , \"str\" text    not null , val int   null )    ", ECPGt_EOIT, ECPGt_EORT);}
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table indicator_test ( \"id\" int   primary key   , \"str\" text    not null , val int   null )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 22 "indicators.pgc"
 
 	{ ECPGtrans(__LINE__, NULL, "commit");}
 #line 23 "indicators.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( id  , str  , val  ) values ( 1 , 'Hello' , 0 ) ", ECPGt_EOIT, ECPGt_EORT);}
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into indicator_test ( id  , str  , val  ) values ( 1 , 'Hello' , 0 ) ", ECPGt_EOIT, ECPGt_EORT);}
 #line 25 "indicators.pgc"
 
 
 	/* use indicator in insert */
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( id  , str  , val  ) values ( 2 , 'Hi there' ,  ? ) ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into indicator_test ( id  , str  , val  ) values ( 2 , 'Hi there' ,  $1  ) ", 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
 #line 28 "indicators.pgc"
 
 	nullind = 0;
-	{ ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( id  , str  , val  ) values ( 3 , 'Good evening' ,  ? ) ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into indicator_test ( id  , str  , val  ) values ( 3 , 'Good evening' ,  $1  ) ", 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
 #line 30 "indicators.pgc"
@@ -145,18 +145,18 @@ int main(int argc, char **argv)
 
 
 	/* use indicators to get information about selects */
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  val  from test where id = 1  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  val  from indicator_test where id = 1  ", ECPGt_EOIT, 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 34 "indicators.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  val  from test where id = 2  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  val  from indicator_test where id = 2  ", ECPGt_EOIT, 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
 #line 35 "indicators.pgc"
 
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  val  from test where id = 3  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  val  from indicator_test where id = 3  ", ECPGt_EOIT, 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
 #line 37 "indicators.pgc"
@@ -165,19 +165,19 @@ int main(int argc, char **argv)
 
 	/* use indicators for update */
 	intvar = 5; nullind = -1;
-	{ ECPGdo(__LINE__, 0, 1, NULL, "update test set val  =  ?  where id = 1 ", 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "update indicator_test set val  =  $1   where id = 1 ", 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
 #line 42 "indicators.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "select  val  from test where id = 1  ", ECPGt_EOIT, 
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  val  from indicator_test where id = 1  ", ECPGt_EOIT, 
 	ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
 #line 43 "indicators.pgc"
 
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);}
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table indicator_test ", ECPGt_EOIT, ECPGt_EORT);}
 #line 46 "indicators.pgc"
 
 	{ ECPGtrans(__LINE__, NULL, "commit");}
diff --git a/src/interfaces/ecpg/test/expected/sql-indicators.stderr b/src/interfaces/ecpg/test/expected/sql-indicators.stderr
index e31d0fe33fe87340b69f4331dcc741ac57757800..5a24225ecb9bbb79b3ab0ea98f94ca03bbcc849e 100644
--- a/src/interfaces/ecpg/test/expected/sql-indicators.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-indicators.stderr
@@ -4,55 +4,81 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGsetcommit line 17 action = off connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19: QUERY: create  table test ( "id" int   primary key   , "str" text    not null , val int   null )     on connection regress1
+[NO_PID]: ECPGexecute line 19: QUERY: create  table indicator_test ( "id" int   primary key   , "str" text    not null , val int   null )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 19 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 23 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 25: QUERY: insert into test ( id  , str  , val  ) values ( 1 , 'Hello' , 0 )  on connection regress1
+[NO_PID]: ECPGexecute line 25: QUERY: insert into indicator_test ( id  , str  , val  ) values ( 1 , 'Hello' , 0 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 25 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 28: QUERY: insert into test ( id  , str  , val  ) values ( 2 , 'Hi there' ,  null )  on connection regress1
+[NO_PID]: ECPGexecute line 28: QUERY: insert into indicator_test ( id  , str  , val  ) values ( 2 , 'Hi there' ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: parameter 1 = null
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 28 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 30: QUERY: insert into test ( id  , str  , val  ) values ( 3 , 'Good evening' ,  5 )  on connection regress1
+[NO_PID]: ECPGexecute line 30: QUERY: insert into indicator_test ( id  , str  , val  ) values ( 3 , 'Good evening' ,  $1  )  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: parameter 1 = 5
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 30 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGtrans line 31 action = commit connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34: QUERY: select  val  from test where id = 1   on connection regress1
+[NO_PID]: ECPGexecute line 34: QUERY: select  val  from indicator_test where id = 1   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 34: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 34: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 34: RESULT: 0 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 35: QUERY: select  val  from test where id = 2   on connection regress1
+[NO_PID]: ECPGexecute line 35: QUERY: select  val  from indicator_test where id = 2   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 35: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 35: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 37: QUERY: select  val  from test where id = 3   on connection regress1
+[NO_PID]: ECPGexecute line 37: QUERY: select  val  from indicator_test where id = 3   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 37: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 37: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 37: RESULT: 5 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 42: QUERY: update test set val  =  null  where id = 1  on connection regress1
+[NO_PID]: ECPGexecute line 42: QUERY: update indicator_test set val  =  $1   where id = 1  with 1 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 42: parameter 1 = null
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 42 Ok: UPDATE 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 43: QUERY: select  val  from test where id = 1   on connection regress1
+[NO_PID]: ECPGexecute line 43: QUERY: select  val  from indicator_test where id = 1   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 43: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 43: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 43: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 46: QUERY: drop table test  on connection regress1
+[NO_PID]: ECPGexecute line 46: QUERY: drop table indicator_test  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 46 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-insupd.c b/src/interfaces/ecpg/test/expected/sql-insupd.c
index 9eadaa72d5543d998ea21001fdf1f8bb9295d416..15b1db99d11fe59c46158a4faf4afc30be833a6b 100644
--- a/src/interfaces/ecpg/test/expected/sql-insupd.c
+++ b/src/interfaces/ecpg/test/expected/sql-insupd.c
@@ -45,7 +45,7 @@ int main(int argc, char* argv[]) {
 #line 16 "insupd.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table test ( a int   , b int   )    ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table insupd_test ( a int   , b int   )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 18 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -55,7 +55,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 18 "insupd.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( a  , b  ) values ( 1 , 1 ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into insupd_test ( a  , b  ) values ( 1 , 1 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 20 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -64,7 +64,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 20 "insupd.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( a  , b  ) values ( 2 , 2 ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into insupd_test ( a  , b  ) values ( 2 , 2 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 21 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -73,7 +73,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 21 "insupd.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into test ( a  , b  ) values ( 3 , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into insupd_test ( a  , b  ) values ( 3 , 3 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -83,7 +83,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "insupd.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "update test set a  = a + 1   ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "update insupd_test set a  = a + 1   ", ECPGt_EOIT, ECPGt_EORT);
 #line 24 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -92,7 +92,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "insupd.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "update test set ( a  , b  )= ( 5 , 5 )  where a = 4 ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "update insupd_test set ( a  , b  )= ( 5 , 5 )  where a = 4 ", ECPGt_EOIT, ECPGt_EORT);
 #line 25 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -101,7 +101,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 25 "insupd.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "update test set a  = 4  where a = 3 ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "update insupd_test set a  = 4  where a = 3 ", ECPGt_EOIT, ECPGt_EORT);
 #line 26 "insupd.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -111,7 +111,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "insupd.pgc"
 ;
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  a , b  from test    order by a  ", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  a , b  from insupd_test    order by a  ", ECPGt_EOIT, 
 	ECPGt_int,(i1),(long)1,(long)3,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,(i2),(long)1,(long)3,sizeof(int), 
diff --git a/src/interfaces/ecpg/test/expected/sql-insupd.stderr b/src/interfaces/ecpg/test/expected/sql-insupd.stderr
index dcb7822e25b8d9e16c29f03ae9759a4dce01eea3..a14a627d9e00ceb02129b520855ebc089af5b460 100644
--- a/src/interfaces/ecpg/test/expected/sql-insupd.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-insupd.stderr
@@ -2,35 +2,51 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 18: QUERY: create  table test ( a int   , b int   )     on connection regress1
+[NO_PID]: ECPGexecute line 18: QUERY: create  table insupd_test ( a int   , b int   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 18: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 18 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 20: QUERY: insert into test ( a  , b  ) values ( 1 , 1 )  on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: insert into insupd_test ( a  , b  ) values ( 1 , 1 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 20 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 21: QUERY: insert into test ( a  , b  ) values ( 2 , 2 )  on connection regress1
+[NO_PID]: ECPGexecute line 21: QUERY: insert into insupd_test ( a  , b  ) values ( 2 , 2 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 21: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 21 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: insert into test ( a  , b  ) values ( 3 , 3 )  on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: insert into insupd_test ( a  , b  ) values ( 3 , 3 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 24: QUERY: update test set a  = a + 1    on connection regress1
+[NO_PID]: ECPGexecute line 24: QUERY: update insupd_test set a  = a + 1    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 24 Ok: UPDATE 3
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 25: QUERY: update test set ( a  , b  )= ( 5 , 5 )  where a = 4  on connection regress1
+[NO_PID]: ECPGexecute line 25: QUERY: update insupd_test set ( a  , b  )= ( 5 , 5 )  where a = 4  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 25 Ok: UPDATE 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: update test set a  = 4  where a = 3  on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: update insupd_test set a  = 4  where a = 3  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: UPDATE 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 28: QUERY: select  a , b  from test    order by a   on connection regress1
+[NO_PID]: ECPGexecute line 28: QUERY: select  a , b  from insupd_test    order by a   with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 28: Correctly got 3 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-oldexec.c b/src/interfaces/ecpg/test/expected/sql-oldexec.c
new file mode 100644
index 0000000000000000000000000000000000000000..745715f343f1461514e1c2938011ec6f229310e2
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-oldexec.c
@@ -0,0 +1,271 @@
+/* Processed by ecpg (regression mode) */
+/* These include files are added by the preprocessor */
+#include <ecpgtype.h>
+#include <ecpglib.h>
+#include <ecpgerrno.h>
+#include <sqlca.h>
+/* End of automatic include section */
+#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
+
+#line 1 "oldexec.pgc"
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+#line 1 "regression.h"
+
+
+
+
+
+
+#line 6 "oldexec.pgc"
+
+
+/* exec sql whenever sqlerror  sqlprint ; */
+#line 8 "oldexec.pgc"
+
+
+int
+main(void)
+{
+/* exec sql begin declare section */
+	 
+	 
+	 
+	 
+	 
+
+#line 14 "oldexec.pgc"
+ int  amount [ 8 ]    ;
+ 
+#line 15 "oldexec.pgc"
+ int  increment   = 100 ;
+ 
+#line 16 "oldexec.pgc"
+ char  name [ 8 ] [ 8 ]    ;
+ 
+#line 17 "oldexec.pgc"
+ char  letter [ 8 ] [ 1 ]    ;
+ 
+#line 18 "oldexec.pgc"
+ char  command [ 128 ]    ;
+/* exec sql end declare section */
+#line 19 "oldexec.pgc"
+
+	int i,j;
+
+	ECPGdebug(1, stderr);
+
+	{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , "main", 0); 
+#line 24 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 24 "oldexec.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 25 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 25 "oldexec.pgc"
+
+	{ ECPGtrans(__LINE__, NULL, "commit");
+#line 26 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 26 "oldexec.pgc"
+
+
+	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
+#line 29 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 29 "oldexec.pgc"
+
+
+	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
+#line 32 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 32 "oldexec.pgc"
+
+
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 2, command, ECPGt_EOIT, ECPGt_EORT);
+#line 35 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 35 "oldexec.pgc"
+
+
+	printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
+
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
+	{ ECPGprepare(__LINE__, NULL, 1, "i", command);
+#line 40 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 40 "oldexec.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 1, "i", 
+	ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 41 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 41 "oldexec.pgc"
+
+
+	printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
+
+	{ ECPGtrans(__LINE__, NULL, "commit");
+#line 45 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 45 "oldexec.pgc"
+
+
+	sprintf (command, "select * from test");
+
+	{ ECPGprepare(__LINE__, NULL, 1, "f", command);
+#line 49 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 49 "oldexec.pgc"
+
+	/* declare CUR  cursor  for $1 */
+#line 50 "oldexec.pgc"
+
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "declare CUR  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 52 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 52 "oldexec.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "fetch 8 in CUR", ECPGt_EOIT, 
+	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 53 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 53 "oldexec.pgc"
+
+
+	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
+	{
+		/* exec sql begin declare section */
+		    
+		   
+		
+#line 58 "oldexec.pgc"
+ char  n [ 8 ]    ,  l   = letter [ i ] [ 0 ] ;
+ 
+#line 59 "oldexec.pgc"
+ int  a   = amount [ i ] ;
+/* exec sql end declare section */
+#line 60 "oldexec.pgc"
+
+
+		strncpy(n, name[i], 8);
+		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
+	}
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "close CUR", ECPGt_EOIT, ECPGt_EORT);
+#line 66 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 66 "oldexec.pgc"
+
+
+	sprintf (command, "select * from test where ? = amount");
+
+	{ ECPGprepare(__LINE__, NULL, 1, "f", command);
+#line 70 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 70 "oldexec.pgc"
+
+	/* declare CUR3  cursor  for $1 */
+#line 71 "oldexec.pgc"
+
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "declare CUR3  cursor  for $1", 
+	ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 73 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 73 "oldexec.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "fetch in CUR3", ECPGt_EOIT, 
+	ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_int,(amount),(long)1,(long)8,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 74 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 74 "oldexec.pgc"
+
+
+	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
+	{
+		/* exec sql begin declare section */
+		    
+		   
+		
+#line 79 "oldexec.pgc"
+ char  n [ 8 ]    ,  l   = letter [ i ] [ 0 ] ;
+ 
+#line 80 "oldexec.pgc"
+ int  a   = amount [ i ] ;
+/* exec sql end declare section */
+#line 81 "oldexec.pgc"
+
+
+		strncpy(n, name[i], 8);
+		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
+	}
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "close CUR3", ECPGt_EOIT, ECPGt_EORT);
+#line 87 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 87 "oldexec.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 1, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
+#line 88 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 88 "oldexec.pgc"
+
+	{ ECPGtrans(__LINE__, NULL, "commit");
+#line 89 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 89 "oldexec.pgc"
+
+	{ ECPGdisconnect(__LINE__, "CURRENT");
+#line 90 "oldexec.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 90 "oldexec.pgc"
+
+
+	return (0);
+}
diff --git a/src/interfaces/ecpg/test/expected/sql-oldexec.stderr b/src/interfaces/ecpg/test/expected/sql-oldexec.stderr
new file mode 100644
index 0000000000000000000000000000000000000000..66f181d51154dc3c8769406493f1318b2a0e994a
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-oldexec.stderr
@@ -0,0 +1,150 @@
+[NO_PID]: ECPGdebug: set to 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: QUERY: create  table test ( name char  ( 8 )    , amount int   , letter char  ( 1 )    )     with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 25 Ok: CREATE TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans line 26 action = commit connection = main
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f') with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 29 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: QUERY: insert into test (name, amount, letter) values ('db: ''r1''', 2, 't') with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 32 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: QUERY: insert into test (name, amount, letter) select name, amount+10, letter from test with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35 Ok: INSERT 0 2
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 40: NAME: i QUERY: insert into test (name, amount, letter) select name, amount+$1, letter from test
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: QUERY: insert into test (name, amount, letter) select name, amount+$1, letter from test with 1 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: using PQexecPrepared for insert into test (name, amount, letter) select name, amount+$1, letter from test
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41: parameter 1 = 100
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 41 Ok: INSERT 0 4
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans line 45 action = commit connection = main
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 49: NAME: f QUERY: select * from test
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: QUERY: declare CUR  cursor  for select * from test with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 52 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: QUERY: fetch 8 in CUR with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 53: Correctly got 8 tuples with 3 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 2 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 11 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 12 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 101 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 102 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 111 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: 112 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: f offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: t offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: f offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: t offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: f offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: t offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: f offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 53: RESULT: t offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66: QUERY: close CUR with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 66 Ok: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGdeallocate line 70: NAME: f
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGprepare line 70: NAME: f QUERY: select * from test where $1 = amount
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 73: QUERY: declare CUR3  cursor  for select * from test where $1 = amount with 1 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 73: using PQexecParams 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 73: parameter 1 = 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 73 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: QUERY: fetch in CUR3 with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 74: Correctly got 1 tuples with 3 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 74: RESULT: db: 'r1' offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 74: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 74: RESULT: f offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 87: QUERY: close CUR3 with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 87: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 87 Ok: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 88: QUERY: drop table test  with 0 parameter on connection main 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 88: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 88 Ok: DROP TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans line 89 action = commit connection = main
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_finish: Connection main closed.
+[NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-oldexec.stdout b/src/interfaces/ecpg/test/expected/sql-oldexec.stdout
new file mode 100644
index 0000000000000000000000000000000000000000..1f4d4f25d0dde9c15d6085d68910d2a30822c312
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-oldexec.stdout
@@ -0,0 +1,11 @@
+Inserted 2 tuples via execute immediate
+Inserted 4 tuples via prepared execute
+name[0]=db: 'r1'	amount[0]=1	letter[0]=f
+name[1]=db: 'r1'	amount[1]=2	letter[1]=t
+name[2]=db: 'r1'	amount[2]=11	letter[2]=f
+name[3]=db: 'r1'	amount[3]=12	letter[3]=t
+name[4]=db: 'r1'	amount[4]=101	letter[4]=f
+name[5]=db: 'r1'	amount[5]=102	letter[5]=t
+name[6]=db: 'r1'	amount[6]=111	letter[6]=f
+name[7]=db: 'r1'	amount[7]=112	letter[7]=t
+name[0]=db: 'r1'	amount[0]=1	letter[0]=f
diff --git a/src/interfaces/ecpg/test/expected/sql-parser.c b/src/interfaces/ecpg/test/expected/sql-parser.c
index 5f41bc9872d3f164e9f4246f8c966c19ae6ceb12..45a670a29fd7865da7290c8b7d77f535ddac1e86 100644
--- a/src/interfaces/ecpg/test/expected/sql-parser.c
+++ b/src/interfaces/ecpg/test/expected/sql-parser.c
@@ -49,7 +49,7 @@ int main(int argc, char* argv[]) {
 #line 18 "parser.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table T ( Item1 int   , Item2 int   )    ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table T ( Item1 int   , Item2 int   )    ", ECPGt_EOIT, ECPGt_EORT);
 #line 20 "parser.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -59,7 +59,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 20 "parser.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into T values ( 1 , null ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into T values ( 1 , null ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "parser.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -68,7 +68,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "parser.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into T values ( 1 , 1 ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into T values ( 1 , 1 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 23 "parser.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -77,7 +77,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 23 "parser.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into T values ( 1 , 2 ) ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into T values ( 1 , 2 ) ", ECPGt_EOIT, ECPGt_EORT);
 #line 24 "parser.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -87,7 +87,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "parser.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  Item2  from T    order by Item2  nulls last", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  Item2  from T    order by Item2  nulls last", ECPGt_EOIT, 
 	ECPGt_int,(item),(long)1,(long)3,sizeof(int), 
 	ECPGt_int,(ind),(long)1,(long)3,sizeof(int), ECPGt_EORT);
 #line 26 "parser.pgc"
@@ -102,7 +102,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   for (i=0; i<3; i++)
   	printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table T ", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table T ", ECPGt_EOIT, ECPGt_EORT);
 #line 31 "parser.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
diff --git a/src/interfaces/ecpg/test/expected/sql-parser.stderr b/src/interfaces/ecpg/test/expected/sql-parser.stderr
index f53baa6cd60cb7f9428b7b6dd4d37fde7177a411..0e59ddda8bc27f2ba1f22817c9aec8fcba42b8e8 100644
--- a/src/interfaces/ecpg/test/expected/sql-parser.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-parser.stderr
@@ -4,23 +4,33 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGsetcommit line 16 action = on connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 20: QUERY: create  table T ( Item1 int   , Item2 int   )     on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: create  table T ( Item1 int   , Item2 int   )     with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 20 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: insert into T values ( 1 , null )  on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: insert into T values ( 1 , null )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: insert into T values ( 1 , 1 )  on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: insert into T values ( 1 , 1 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 24: QUERY: insert into T values ( 1 , 2 )  on connection regress1
+[NO_PID]: ECPGexecute line 24: QUERY: insert into T values ( 1 , 2 )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 24: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 24 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: select  Item2  from T    order by Item2  nulls last on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: select  Item2  from T    order by Item2  nulls last with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26: Correctly got 3 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
@@ -30,7 +40,9 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 26: RESULT:  offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: drop table T  on connection regress1
+[NO_PID]: ECPGexecute line 31: QUERY: drop table T  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 31 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-quote.c b/src/interfaces/ecpg/test/expected/sql-quote.c
index b671969f0b72ab83bc24354505f8d95582f312c1..a3762203b34494de435ec1c12e75c44b79e7eb05 100644
--- a/src/interfaces/ecpg/test/expected/sql-quote.c
+++ b/src/interfaces/ecpg/test/expected/sql-quote.c
@@ -26,131 +26,182 @@
 int main(int argc, char* argv[]) {
   /* exec sql begin declare section */
      
+     
   
 #line 9 "quote.pgc"
  char  var [ 25 ]    ;
-/* exec sql end declare section */
+ 
 #line 10 "quote.pgc"
+ int  i    ;
+/* exec sql end declare section */
+#line 11 "quote.pgc"
 
 
   ECPGdebug(1, stderr);
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
-#line 13 "quote.pgc"
+#line 14 "quote.pgc"
 
 
   { ECPGsetcommit(__LINE__, "on", NULL);}
-#line 15 "quote.pgc"
+#line 16 "quote.pgc"
 
   /* exec sql whenever sql_warning  sqlprint ; */
-#line 16 "quote.pgc"
+#line 17 "quote.pgc"
 
   /* exec sql whenever sqlerror  sqlprint ; */
-#line 17 "quote.pgc"
+#line 18 "quote.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table \"My_Table\" ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
-#line 19 "quote.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table \"My_Table\" ( Item1 int   , Item2 text    )    ", ECPGt_EOIT, ECPGt_EORT);
+#line 20 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 19 "quote.pgc"
+#line 20 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 19 "quote.pgc"
+#line 20 "quote.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "show standard_conforming_strings", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "show standard_conforming_strings", ECPGt_EOIT, 
 	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
-#line 21 "quote.pgc"
+#line 22 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 21 "quote.pgc"
+#line 22 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 21 "quote.pgc"
+#line 22 "quote.pgc"
 
   printf("Standard conforming strings: %s\n", var);
 
   /* this is a\\b actually */
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into \"My_Table\" values ( 1 , 'a\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
-#line 25 "quote.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into \"My_Table\" values ( 1 , 'a\\\\\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 26 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 25 "quote.pgc"
+#line 26 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 25 "quote.pgc"
+#line 26 "quote.pgc"
 
-  /* this is a\b */
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into \"My_Table\" values ( 1 , 'a\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
-#line 27 "quote.pgc"
+  /* this is a\\b */
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into \"My_Table\" values ( 1 , E'a\\\\\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 28 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 27 "quote.pgc"
+#line 28 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 27 "quote.pgc"
+#line 28 "quote.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set standard_conforming_strings to on", ECPGt_EOIT, ECPGt_EORT);
-#line 29 "quote.pgc"
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set standard_conforming_strings to on", ECPGt_EOIT, ECPGt_EORT);
+#line 30 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 29 "quote.pgc"
+#line 30 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 29 "quote.pgc"
+#line 30 "quote.pgc"
 
 
-  /* this is a\\b actually */
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into \"My_Table\" values ( 1 , 'a\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
-#line 32 "quote.pgc"
+  /* this is a\\\\b actually */
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into \"My_Table\" values ( 2 , 'a\\\\\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 33 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 32 "quote.pgc"
+#line 33 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 32 "quote.pgc"
+#line 33 "quote.pgc"
 
-  /* this is a\b */
-  { ECPGdo(__LINE__, 0, 1, NULL, "insert into \"My_Table\" values ( 1 , 'a\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
-#line 34 "quote.pgc"
+  /* this is a\\b */
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into \"My_Table\" values ( 2 , E'a\\\\\\\\b' ) ", ECPGt_EOIT, ECPGt_EORT);
+#line 35 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 34 "quote.pgc"
+#line 35 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 34 "quote.pgc"
+#line 35 "quote.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  *  from \"My_Table\"   ", ECPGt_EOIT, ECPGt_EORT);
-#line 36 "quote.pgc"
+  { ECPGtrans(__LINE__, NULL, "begin transaction ");
+#line 37 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 36 "quote.pgc"
+#line 37 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 36 "quote.pgc"
-
+#line 37 "quote.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table \"My_Table\" ", ECPGt_EOIT, ECPGt_EORT);
+  /* declare C  cursor  for select  *  from \"My_Table\"    */
 #line 38 "quote.pgc"
 
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare C  cursor  for select  *  from \"My_Table\"   ", ECPGt_EOIT, ECPGt_EORT);
+#line 40 "quote.pgc"
+
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 38 "quote.pgc"
+#line 40 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 38 "quote.pgc"
+#line 40 "quote.pgc"
+
+
+  /* exec sql whenever not found  break ; */
+#line 42 "quote.pgc"
+
+
+  while (true)
+  {
+  	{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch C", ECPGt_EOIT, 
+	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 46 "quote.pgc"
+
+if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
+#line 46 "quote.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 46 "quote.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 46 "quote.pgc"
+
+	printf("value: %d %s\n", i, var);
+  }
+
+  { ECPGtrans(__LINE__, NULL, "rollback");
+#line 50 "quote.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 50 "quote.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 50 "quote.pgc"
+
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table \"My_Table\" ", ECPGt_EOIT, ECPGt_EORT);
+#line 51 "quote.pgc"
+
+if (sqlca.sqlwarn[0] == 'W') sqlprint();
+#line 51 "quote.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 51 "quote.pgc"
 
 
   { ECPGdisconnect(__LINE__, "ALL");
-#line 40 "quote.pgc"
+#line 53 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
-#line 40 "quote.pgc"
+#line 53 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
-#line 40 "quote.pgc"
+#line 53 "quote.pgc"
 
 
   return 0;
diff --git a/src/interfaces/ecpg/test/expected/sql-quote.stderr b/src/interfaces/ecpg/test/expected/sql-quote.stderr
index 08a11c4bbeb663c2e72274018aeded3a091a23ba..631223b6f747444ecf685507ca1d1fff68f034c0 100644
--- a/src/interfaces/ecpg/test/expected/sql-quote.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-quote.stderr
@@ -2,56 +2,120 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGsetcommit line 15 action = on connection = regress1
+[NO_PID]: ECPGsetcommit line 16 action = on connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19: QUERY: create  table "My_Table" ( Item1 int   , Item2 text    )     on connection regress1
+[NO_PID]: ECPGexecute line 20: QUERY: create  table "My_Table" ( Item1 int   , Item2 text    )     with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19 Ok: CREATE TABLE
+[NO_PID]: ECPGexecute line 20: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 21: QUERY: show standard_conforming_strings on connection regress1
+[NO_PID]: ECPGexecute line 20 Ok: CREATE TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 21: Correctly got 1 tuples with 1 fields
+[NO_PID]: ECPGexecute line 22: QUERY: show standard_conforming_strings with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGget_data line 21: RESULT: off offset: -1 array: Yes
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 25: QUERY: insert into "My_Table" values ( 1 , 'a\\b' )  on connection regress1
+[NO_PID]: ECPGexecute line 22: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: nonstandard use of \\ in a string literal[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode 0
-[NO_PID]: sqlca: code: 0, state: 22P06
-[NO_PID]: ECPGexecute line 25 Ok: INSERT 0 1
-[NO_PID]: sqlca: code: 0, state: 22P06
-sql error nonstandard use of \\ in a string literal
-[NO_PID]: ECPGexecute line 27: QUERY: insert into "My_Table" values ( 1 , 'a\\b' )  on connection regress1
+[NO_PID]: ECPGget_data line 22: RESULT: off offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: QUERY: insert into "My_Table" values ( 1 , 'a\\\\b' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGnoticeReceiver nonstandard use of \\ in a string literal
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: nonstandard use of \\ in a string literal[NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: raising sqlcode 0
 [NO_PID]: sqlca: code: 0, state: 22P06
-[NO_PID]: ECPGexecute line 27 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 26: using PQexec
+[NO_PID]: sqlca: code: 0, state: 22P06
+[NO_PID]: ECPGexecute line 26 Ok: INSERT 0 1
 [NO_PID]: sqlca: code: 0, state: 22P06
 sql error nonstandard use of \\ in a string literal
-[NO_PID]: ECPGexecute line 29: QUERY: set standard_conforming_strings to on on connection regress1
+[NO_PID]: ECPGexecute line 28: QUERY: insert into "My_Table" values ( 1 , E'a\\\\b' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 28 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: QUERY: set standard_conforming_strings to on with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30 Ok: SET
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: QUERY: insert into "My_Table" values ( 2 , 'a\\\\b' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 33 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: QUERY: insert into "My_Table" values ( 2 , E'a\\\\b' )  with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 35 Ok: INSERT 0 1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans line 37 action = begin transaction  connection = regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: QUERY: declare C  cursor  for select  *  from "My_Table"    with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 40 Ok: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: QUERY: fetch C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: Correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: a\\b offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: QUERY: fetch C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: Correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: 1 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: a\\b offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: QUERY: fetch C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: Correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: 2 offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGget_data line 46: RESULT: a\\\\b offset: -1 array: Yes
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: QUERY: fetch C with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 46: Correctly got 1 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 29 Ok: SET
+[NO_PID]: ECPGget_data line 46: RESULT: 2 offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32: QUERY: insert into "My_Table" values ( 1 , 'a\\b' )  on connection regress1
+[NO_PID]: ECPGget_data line 46: RESULT: a\\b offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 32 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 46: QUERY: fetch C with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34: QUERY: insert into "My_Table" values ( 1 , 'a\\b' )  on connection regress1
+[NO_PID]: ECPGexecute line 46: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 34 Ok: INSERT 0 1
+[NO_PID]: ECPGexecute line 46: Correctly got 0 tuples with 2 fields
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: QUERY: select  *  from "My_Table"    on connection regress1
+[NO_PID]: raising sqlcode 100 in line 46, 'No data found in line 46.'.
+[NO_PID]: sqlca: code: 100, state: 02000
+[NO_PID]: ECPGtrans line 50 action = rollback connection = regress1
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 36: Correctly got 4 tuples with 2 fields
+[NO_PID]: ECPGexecute line 51: QUERY: drop table "My_Table"  with 0 parameter on connection regress1 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlcode -202 in line 36, 'Too few arguments in line 36.'.
-[NO_PID]: sqlca: code: -202, state: 07002
-sql error Too few arguments in line 36.
-[NO_PID]: ECPGexecute line 38: QUERY: drop table "My_Table"  on connection regress1
+[NO_PID]: ECPGexecute line 51: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 38 Ok: DROP TABLE
+[NO_PID]: ECPGexecute line 51 Ok: DROP TABLE
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ecpg_finish: Connection regress1 closed.
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/sql-quote.stdout b/src/interfaces/ecpg/test/expected/sql-quote.stdout
index 1d93881f08823cb5941682b399ce95eb83cf57b8..5ec018963e0ecfe1a720f94245a68ad446b34536 100644
--- a/src/interfaces/ecpg/test/expected/sql-quote.stdout
+++ b/src/interfaces/ecpg/test/expected/sql-quote.stdout
@@ -1 +1,5 @@
 Standard conforming strings: off
+value: 1 a\\b
+value: 1 a\\b
+value: 2 a\\\\b
+value: 2 a\\b
diff --git a/src/interfaces/ecpg/test/expected/sql-show.c b/src/interfaces/ecpg/test/expected/sql-show.c
index d4a7affd80087c15a0cedcb07fb54e36f1fb997d..c3be5779bd52ef1a4115c98d59613e68c232c0b1 100644
--- a/src/interfaces/ecpg/test/expected/sql-show.c
+++ b/src/interfaces/ecpg/test/expected/sql-show.c
@@ -45,7 +45,7 @@ int main(int argc, char* argv[]) {
 #line 16 "show.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set search_path to 'public'", ECPGt_EOIT, ECPGt_EORT);
 #line 18 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -54,7 +54,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 18 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "show search_path", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "show search_path", ECPGt_EOIT, 
 	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 19 "show.pgc"
@@ -67,7 +67,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   printf("Var: Search path: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set standard_conforming_strings to off", ECPGt_EOIT, ECPGt_EORT);
 #line 22 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -76,7 +76,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 22 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "show standard_conforming_strings", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "show standard_conforming_strings", ECPGt_EOIT, 
 	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 23 "show.pgc"
@@ -89,7 +89,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   printf("Var: Standard conforming strings: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set time zone PST8PDT", ECPGt_EOIT, ECPGt_EORT);
 #line 26 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -98,7 +98,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "show time zone", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "show time zone", ECPGt_EOIT, 
 	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 27 "show.pgc"
@@ -111,7 +111,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   printf("Time Zone: %s\n", var);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "set transaction isolation level read committed", ECPGt_EOIT, ECPGt_EORT);
 #line 30 "show.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -120,7 +120,7 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "show.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "show transaction isolation level", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "show transaction isolation level", ECPGt_EOIT, 
 	ECPGt_char,(var),(long)25,(long)1,(25)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 31 "show.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-show.stderr b/src/interfaces/ecpg/test/expected/sql-show.stderr
index bf78e605ca840e39245e53add3ee95ef9a691efc..173f497d698f26b64cd13c44f9a0a0f43d49a97e 100644
--- a/src/interfaces/ecpg/test/expected/sql-show.stderr
+++ b/src/interfaces/ecpg/test/expected/sql-show.stderr
@@ -2,41 +2,57 @@
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGconnect: opening database regress1 on <DEFAULT> port <DEFAULT> 
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 18: QUERY: set search_path to 'public' on connection regress1
+[NO_PID]: ECPGexecute line 18: QUERY: set search_path to 'public' with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 18: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 18 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 19: QUERY: show search_path on connection regress1
+[NO_PID]: ECPGexecute line 19: QUERY: show search_path with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 19: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 19: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 19: RESULT: public offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 22: QUERY: set standard_conforming_strings to off on connection regress1
+[NO_PID]: ECPGexecute line 22: QUERY: set standard_conforming_strings to off with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 22: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 22 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 23: QUERY: show standard_conforming_strings on connection regress1
+[NO_PID]: ECPGexecute line 23: QUERY: show standard_conforming_strings with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 23: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 23: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 23: RESULT: off offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 26: QUERY: set time zone PST8PDT on connection regress1
+[NO_PID]: ECPGexecute line 26: QUERY: set time zone PST8PDT with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 26: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 26 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 27: QUERY: show time zone on connection regress1
+[NO_PID]: ECPGexecute line 27: QUERY: show time zone with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 27: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 27: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGget_data line 27: RESULT: PST8PDT offset: -1 array: Yes
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 30: QUERY: set transaction isolation level read committed on connection regress1
+[NO_PID]: ECPGexecute line 30: QUERY: set transaction isolation level read committed with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 30: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 30 Ok: SET
 [NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ECPGexecute line 31: QUERY: show transaction isolation level on connection regress1
+[NO_PID]: ECPGexecute line 31: QUERY: show transaction isolation level with 0 parameter on connection regress1 
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGexecute line 31: using PQexec
 [NO_PID]: sqlca: code: 0, state: 00000
 [NO_PID]: ECPGexecute line 31: Correctly got 1 tuples with 1 fields
 [NO_PID]: sqlca: code: 0, state: 00000
diff --git a/src/interfaces/ecpg/test/expected/thread-thread.c b/src/interfaces/ecpg/test/expected/thread-thread.c
index 36d920eb3cfdcfe0be7d60d56fb43b846ca720ae..6b132c5f243dc0918ac206a16eae1077cc974e56 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread.c
@@ -70,13 +70,13 @@ int main(int argc, char *argv[])
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 46 "thread.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
 #line 47 "thread.pgc"
  /* DROP might fail */
   { ECPGtrans(__LINE__, NULL, "commit");}
 #line 48 "thread.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table test_thread ( tstamp timestamp    not null default cast( timeofday () as timestamp   ) , thread TEXT    not null , iteration integer   not null , primary key( thread , iteration )   )    ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test_thread ( tstamp timestamp    not null default cast( timeofday () as timestamp   ) , thread TEXT    not null , iteration integer   not null , primary key( thread , iteration )   )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 53 "thread.pgc"
 
   { ECPGtrans(__LINE__, NULL, "commit");}
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 85 "thread.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  count (*)  from test_thread   ", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  count (*)  from test_thread   ", ECPGt_EOIT, 
 	ECPGt_int,&(l_rows),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 86 "thread.pgc"
@@ -182,7 +182,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* insert into test_thread table */
   for( l_i = 1; l_i <= iterations; l_i++ )
     {
-      { ECPGdo(__LINE__, 0, 1, l_connection, "insert into test_thread ( thread  , iteration  ) values (  ? ,  ? ) ", 
+      { ECPGdo(__LINE__, 0, 1, l_connection, 0, 0, "insert into test_thread ( thread  , iteration  ) values (  $1  ,  $2  ) ", 
 	ECPGt_char,(l_connection),(long)128,(long)1,(128)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,&(l_i),(long)1,(long)1,sizeof(int), 
diff --git a/src/interfaces/ecpg/test/expected/thread-thread.stdout b/src/interfaces/ecpg/test/expected/thread-thread.stdout
index 75fe16bb36bb2580d8365d62780f9c21ad7c259c..a9d787cc55cbb2d168495737dd11410b74e58b04 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread.stdout
+++ b/src/interfaces/ecpg/test/expected/thread-thread.stdout
@@ -1 +1 @@
-No threading enabled.
+Success.
diff --git a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
index bf20c51bb561249e6ee43d8b5d6122bef76ca85e..fb9b6c5b87014029a037253c044fc8888a859b52 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
@@ -71,13 +71,13 @@ int main(int argc, char *argv[])
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 47 "thread_implicit.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test_thread ", ECPGt_EOIT, ECPGt_EORT);}
 #line 48 "thread_implicit.pgc"
  /* DROP might fail */
   { ECPGtrans(__LINE__, NULL, "commit");}
 #line 49 "thread_implicit.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "create  table test_thread ( tstamp timestamp    not null default cast( timeofday () as timestamp   ) , thread TEXT    not null , iteration integer   not null , primary key( thread , iteration )   )    ", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create  table test_thread ( tstamp timestamp    not null default cast( timeofday () as timestamp   ) , thread TEXT    not null , iteration integer   not null , primary key( thread , iteration )   )    ", ECPGt_EOIT, ECPGt_EORT);}
 #line 54 "thread_implicit.pgc"
 
   { ECPGtrans(__LINE__, NULL, "commit");}
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 86 "thread_implicit.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, "select  count (*)  from test_thread   ", ECPGt_EOIT, 
+  { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "select  count (*)  from test_thread   ", ECPGt_EOIT, 
 	ECPGt_int,&(l_rows),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 87 "thread_implicit.pgc"
@@ -183,7 +183,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* insert into test_thread table */
   for( l_i = 1; l_i <= iterations; l_i++ )
     {
-      { ECPGdo(__LINE__, 0, 1, NULL, "insert into test_thread ( thread  , iteration  ) values (  ? ,  ? ) ", 
+      { ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "insert into test_thread ( thread  , iteration  ) values (  $1  ,  $2  ) ", 
 	ECPGt_char,(l_connection),(long)128,(long)1,(128)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_int,&(l_i),(long)1,(long)1,sizeof(int), 
diff --git a/src/interfaces/ecpg/test/expected/thread-thread_implicit.stdout b/src/interfaces/ecpg/test/expected/thread-thread_implicit.stdout
index 75fe16bb36bb2580d8365d62780f9c21ad7c259c..a9d787cc55cbb2d168495737dd11410b74e58b04 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread_implicit.stdout
+++ b/src/interfaces/ecpg/test/expected/thread-thread_implicit.stdout
@@ -1 +1 @@
-No threading enabled.
+Success.
diff --git a/src/interfaces/ecpg/test/preproc/Makefile b/src/interfaces/ecpg/test/preproc/Makefile
index 937f89ca52aa532590cfc409d84c1aae96b987ca..6928a1f3fe3e96e8447f660502c93a8ab901ac57 100644
--- a/src/interfaces/ecpg/test/preproc/Makefile
+++ b/src/interfaces/ecpg/test/preproc/Makefile
@@ -4,7 +4,9 @@ include $(top_builddir)/src/Makefile.global
 include $(top_srcdir)/$(subdir)/../Makefile.regress
 
 
-TESTS = comment comment.c \
+TESTS = array_of_struct array_of_struct.c \
+	autoprep autoprep.c \
+	comment comment.c \
 	define define.c \
 	init init.c \
 	type type.c \
@@ -13,3 +15,9 @@ TESTS = comment comment.c \
 
 all: $(TESTS)
 
+array_of_struct.c:	array_of_struct.pgc ../regression.h
+	$(ECPG) -c -o $@ -I$(srcdir) $<
+
+autoprep.c:     autoprep.pgc ../regression.h
+	$(ECPG) -r prepare -o $@ -I$(srcdir) $<
+
diff --git a/src/interfaces/ecpg/test/preproc/array_of_struct.pgc b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
new file mode 100644
index 0000000000000000000000000000000000000000..52f952d639f3ec7f55810bc3035209569a659f76
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/array_of_struct.pgc
@@ -0,0 +1,87 @@
+#include <stdio.h>
+
+exec sql include ../regression;
+
+EXEC SQL WHENEVER sqlerror sqlprint;
+EXEC SQL WHENEVER sqlwarning sqlprint;
+EXEC SQL WHENEVER not found sqlprint;
+
+EXEC SQL TYPE customer IS
+    struct
+    {
+        varchar name[50];
+        int     phone;
+    };
+
+EXEC SQL TYPE cust_ind IS
+    struct ind
+    {
+        short   name_ind;
+        short   phone_ind;
+    };
+
+int main( int argc, char * argv[] )
+{
+    EXEC SQL begin declare section;
+      customer  custs1[10];
+      cust_ind  inds[10];
+      typedef struct
+      {
+        varchar name[50];
+        int     phone;
+      } customer2;
+      customer2  custs2[10];
+      struct customer3
+      {
+        varchar name[50];
+        int     phone;
+      } custs3[10];
+      struct customer4
+      {
+        varchar name[50];
+        int     phone;
+      } custs4;
+      int r;
+    EXEC SQL end declare section;
+
+    ECPGdebug(1, stderr);
+	  
+    EXEC SQL connect to REGRESSDB1;
+
+    EXEC SQL create table customers (c varchar(50), p int);
+    EXEC SQL insert into customers values ('John Doe', '12345');
+    EXEC SQL insert into customers values ('Jane Doe', '67890');
+
+    EXEC SQL select * INTO :custs1:inds from customers limit 2;
+    printf("custs1:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs1[r].name.arr );
+	    printf( "phone - %d\n", custs1[r].phone );
+    }
+
+    EXEC SQL select * INTO :custs2:inds from customers limit 2;
+    printf("\ncusts2:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs2[r].name.arr );
+	    printf( "phone - %d\n", custs2[r].phone );
+    }
+
+    EXEC SQL select * INTO :custs3:inds from customers limit 2;
+    printf("\ncusts3:\n");
+    for (r = 0; r < 2; r++)
+    {
+	    printf( "name  - %s\n", custs3[r].name.arr );
+	    printf( "phone - %d\n", custs3[r].phone );
+    }
+
+    EXEC SQL select * INTO :custs4:inds[0] from customers limit 1;
+    printf("\ncusts4:\n");
+    printf( "name  - %s\n", custs4.name.arr );
+    printf( "phone - %d\n", custs4.phone );
+
+    EXEC SQL disconnect all;
+
+    return( 0 );
+}
diff --git a/src/interfaces/ecpg/test/preproc/autoprep.pgc b/src/interfaces/ecpg/test/preproc/autoprep.pgc
new file mode 100644
index 0000000000000000000000000000000000000000..d29c3d556d06feaf84ff55f64f21fa4db1ffe716
--- /dev/null
+++ b/src/interfaces/ecpg/test/preproc/autoprep.pgc
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* test automatic prepare for all statements */
+EXEC SQL INCLUDE ../regression;
+
+int main(int argc, char* argv[]) {
+  EXEC SQL BEGIN DECLARE SECTION;
+  	int item[4], ind[4], i = 1;
+  EXEC SQL END DECLARE SECTION;
+
+  ECPGdebug(1, stderr);
+  EXEC SQL CONNECT TO REGRESSDB1;
+
+  EXEC SQL WHENEVER SQLWARNING SQLPRINT;
+  EXEC SQL WHENEVER SQLERROR SQLPRINT;
+
+  EXEC SQL CREATE TABLE T ( Item1 int, Item2 int );
+
+  EXEC SQL INSERT INTO T VALUES ( 1, null );
+  EXEC SQL INSERT INTO T VALUES ( 1, :i );
+  i++;
+  EXEC SQL INSERT INTO T VALUES ( 1, :i );
+  EXEC SQL PREPARE I AS INSERT INTO T VALUES ( 1, 2 );
+  EXEC SQL EXECUTE I;
+
+  EXEC SQL SELECT Item2 INTO :item:ind FROM T ORDER BY Item2 NULLS LAST;
+
+  for (i=0; i<4; i++)
+  	printf("item[%d] = %d\n", i, ind[i] ? -1 : item[i]);
+
+  EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
+
+  EXEC SQL OPEN C;
+
+  EXEC SQL FETCH 1 IN C INTO :i;
+  printf("i = %d\n", i);
+
+  EXEC SQL CLOSE C;
+
+  EXEC SQL DROP TABLE T;
+
+  EXEC SQL DISCONNECT ALL;
+
+  return 0;
+}
diff --git a/src/interfaces/ecpg/test/sql/Makefile b/src/interfaces/ecpg/test/sql/Makefile
index 7d58a761e569baf2f45dfec6cb323b97568f0a1a..dc58291cc801e550974e9b5075adcd7b94f8f457 100644
--- a/src/interfaces/ecpg/test/sql/Makefile
+++ b/src/interfaces/ecpg/test/sql/Makefile
@@ -16,6 +16,7 @@ TESTS = array array.c \
         fetch fetch.c \
         func func.c \
         indicators indicators.c \
+	oldexec oldexec.c \
         parser parser.c \
         quote quote.c \
         show show.c \
@@ -23,7 +24,6 @@ TESTS = array array.c \
 
 all: $(TESTS)
 
-# bits needs the -c option for the "EXEC SQL TYPE" construct
-bits.c: bits.pgc ../regression.h
-	$(ECPG) -c -o $@ -I$(srcdir) $<
+oldexec.c:	oldexec.pgc ../regression.h
+	$(ECPG) -r questionmarks -o $@ -I$(srcdir) $<
 
diff --git a/src/interfaces/ecpg/test/sql/array.pgc b/src/interfaces/ecpg/test/sql/array.pgc
index 2444e0158be012f6e5ae0ed0d1cd4e3444274fa2..d589a242f57c8985db7b572be9d148860efaf80f 100644
--- a/src/interfaces/ecpg/test/sql/array.pgc
+++ b/src/interfaces/ecpg/test/sql/array.pgc
@@ -35,7 +35,7 @@ EXEC SQL END DECLARE SECTION;
 	EXEC SQL INSERT INTO test(f,i,a,text) VALUES(404.90,3,'{0,1,2,3,4,5,6,7,8,9}','abcdefghij');
 
 	EXEC SQL INSERT INTO test(f,i,a,text) VALUES(140787.0,2,:a,:text);
-	
+
 	EXEC SQL INSERT INTO test(f,i,a,text) VALUES(14.07,:did,:a,:t);
 
 	EXEC SQL COMMIT;
diff --git a/src/interfaces/ecpg/test/sql/desc.pgc b/src/interfaces/ecpg/test/sql/desc.pgc
index 9eae845ddfa0c0d95a61285f465006cb12e931f5..bf615bf22a76d526ec6b0c4d9e3818d4edda4e5c 100644
--- a/src/interfaces/ecpg/test/sql/desc.pgc
+++ b/src/interfaces/ecpg/test/sql/desc.pgc
@@ -5,9 +5,9 @@ int
 main(void)
 {
 	EXEC SQL BEGIN DECLARE SECTION;
-	char *stmt1 = "INSERT INTO test1 VALUES (?, ?)";
-	char *stmt2 = "SELECT * from test1 where a = ? and b = ?";
-	char *stmt3 = "SELECT * from test1 where a = ?";
+	char *stmt1 = "INSERT INTO test1 VALUES ($1, $2)";
+	char *stmt2 = "SELECT * from test1 where a = $1 and b = $2";
+	char *stmt3 = "SELECT * from test1 where :var = a";
 
 	int val1 = 1;
 	char val2[4] = "one", val2output[] = "AAA";
@@ -28,6 +28,7 @@ main(void)
 
 	EXEC SQL CREATE TABLE test1 (a int, b text);
 	EXEC SQL PREPARE foo1 FROM :stmt1;
+	EXEC SQL PREPARE "Foo-1" FROM :stmt1;
 	EXEC SQL PREPARE foo2 FROM :stmt2;
 	EXEC SQL PREPARE foo3 FROM :stmt3;
 
@@ -41,7 +42,9 @@ main(void)
 	EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 3;
 	EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val1, DATA = 'this is a long test';
 
-	EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
+	EXEC SQL EXECUTE "Foo-1" USING DESCRIPTOR indesc;
+
+	EXEC SQL DEALLOCATE "Foo-1";
 
 	EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1;
 	EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2i, DATA = :val2;
@@ -75,6 +78,7 @@ main(void)
 	printf("val1=%d val2=%c%c%c%c warn=%c truncate=%d\n", val1output, val2output[0], val2output[1], val2output[2], val2output[3], sqlca.sqlwarn[0], val2i);
 
 	EXEC SQL DROP TABLE test1;
+	EXEC SQL DEALLOCATE ALL;
 	EXEC SQL DISCONNECT;
 
 	EXEC SQL DEALLOCATE DESCRIPTOR indesc;
diff --git a/src/interfaces/ecpg/test/sql/dyntest.pgc b/src/interfaces/ecpg/test/sql/dyntest.pgc
index 2a2abfb4f95beb426451d0b0904d86324e5f2f25..a1efabe033c5a99f88c77e51ace951ec0c9963ab 100644
--- a/src/interfaces/ecpg/test/sql/dyntest.pgc
+++ b/src/interfaces/ecpg/test/sql/dyntest.pgc
@@ -54,7 +54,7 @@ main (int argc, char **argv)
   exec sql insert into dyntest values ('first entry', 14.7, 14, 123045607890, true, 'The world''''s most advanced open source database.', '1987-07-14');
   exec sql insert into dyntest values ('second entry', 1407.87, 1407, 987065403210, false, 'The elephant never forgets.', '1999-11-5');
 
-  exec sql prepare MYQUERY from:QUERY;
+  exec sql prepare MYQUERY from :QUERY;
   exec sql declare MYCURS cursor for MYQUERY;
 
   exec sql open MYCURS;
diff --git a/src/interfaces/ecpg/test/sql/execute.pgc b/src/interfaces/ecpg/test/sql/execute.pgc
index 5c23bb36a49bf7ce78a7d673730b03f7f2128a91..486a70db08e23e2e433a4239e61f68fdf1335316 100644
--- a/src/interfaces/ecpg/test/sql/execute.pgc
+++ b/src/interfaces/ecpg/test/sql/execute.pgc
@@ -36,7 +36,7 @@ exec sql end declare section;
 
 	printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
 
-	sprintf(command, "insert into test (name, amount, letter) select name, amount+?, letter from test");
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
 	exec sql prepare I from :command;
 	exec sql execute I using :increment;
 
@@ -46,8 +46,8 @@ exec sql end declare section;
 
 	sprintf (command, "select * from test");
 
-	exec sql prepare F from :command;
-	exec sql declare CUR cursor for F;
+	exec sql prepare f from :command;
+	exec sql declare CUR cursor for f;
 
 	exec sql open CUR;
 	exec sql fetch 8 in CUR into :name, :amount, :letter;
@@ -64,11 +64,12 @@ exec sql end declare section;
 	}
 
 	exec sql close CUR;
+	exec sql deallocate f;
 
-	sprintf (command, "select * from test where amount = ?");
+	sprintf (command, "select * from test where amount = $1");
 
-	exec sql prepare F from :command;
-	exec sql declare CUR2 cursor for F;
+	exec sql prepare f from :command;
+	exec sql declare CUR2 cursor for f;
 
 	exec sql open CUR2 using 1;
 	exec sql fetch in CUR2 into :name, :amount, :letter;
diff --git a/src/interfaces/ecpg/test/sql/fetch.pgc b/src/interfaces/ecpg/test/sql/fetch.pgc
index 936a4f8cd2dcef9ca5bbbea2da970db6274c9282..a65d393748e90d65f136732a4c3520d515befd16 100644
--- a/src/interfaces/ecpg/test/sql/fetch.pgc
+++ b/src/interfaces/ecpg/test/sql/fetch.pgc
@@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
 int main(int argc, char* argv[]) {
   EXEC SQL BEGIN DECLARE SECTION;
     char str[25];
-    int i, how_many = 1;
+    int i; 
   EXEC SQL END DECLARE SECTION;
 
   ECPGdebug(1, stderr);
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
   EXEC SQL WHENEVER NOT FOUND CONTINUE;
   EXEC SQL MOVE BACKWARD 2 IN C;
 
-  EXEC SQL FETCH :how_many IN C INTO :i, :str;
+  EXEC SQL FETCH 1 IN C INTO :i, :str;
   printf("%d: %s\n", i, str);
 
   EXEC SQL CLOSE C;
diff --git a/src/interfaces/ecpg/test/sql/func.pgc b/src/interfaces/ecpg/test/sql/func.pgc
index 71835a316d3cb5a4e0f91ed55bd811942a30de0b..19c4ba7cc646e38d435a757ff211bb693f759c1b 100644
--- a/src/interfaces/ecpg/test/sql/func.pgc
+++ b/src/interfaces/ecpg/test/sql/func.pgc
@@ -5,6 +5,7 @@
 EXEC SQL INCLUDE ../regression;
 
 int main(int argc, char* argv[]) {
+  EXEC SQL char text[25];
 
   ECPGdebug(1, stderr);
   EXEC SQL CONNECT TO REGRESSDB1;
@@ -14,11 +15,12 @@ int main(int argc, char* argv[]) {
   EXEC SQL WHENEVER SQLERROR SQLPRINT;
 
   EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text );
+  EXEC SQL CREATE TABLE Log (name text, w text);
 
   EXEC SQL CREATE FUNCTION My_Table_Check() RETURNS trigger
     AS $test$
     BEGIN
-	RAISE WARNING 'Notice: TG_NAME=%, TG WHEN=%', TG_NAME, TG_WHEN;
+	INSERT INTO Log VALUES(TG_NAME, TG_WHEN);
 	RETURN NEW;
     END; $test$
     LANGUAGE plpgsql;
@@ -31,9 +33,12 @@ int main(int argc, char* argv[]) {
 
   EXEC SQL INSERT INTO My_Table VALUES (1234, 'Some random text');
   EXEC SQL INSERT INTO My_Table VALUES (5678, 'The Quick Brown');
+  EXEC SQL SELECT name INTO :text FROM Log LIMIT 1;
+  printf("Trigger %s fired.\n", text);
 
   EXEC SQL DROP TRIGGER My_Table_Check_Trigger ON My_Table;
   EXEC SQL DROP FUNCTION My_Table_Check();
+  EXEC SQL DROP TABLE Log;
   EXEC SQL DROP TABLE My_Table;
 
   EXEC SQL DISCONNECT ALL;
diff --git a/src/interfaces/ecpg/test/sql/indicators.pgc b/src/interfaces/ecpg/test/sql/indicators.pgc
index 96c312b506ad1794009768b0c291166ea4aa782c..6ccf568afb445f309a96eda218ff974e488cdec1 100644
--- a/src/interfaces/ecpg/test/sql/indicators.pgc
+++ b/src/interfaces/ecpg/test/sql/indicators.pgc
@@ -16,34 +16,34 @@ int main(int argc, char **argv)
 	exec sql connect to REGRESSDB1;
 	exec sql set autocommit to off;
 
-	exec sql create table test (
+	exec sql create table indicator_test (
 	     "id" int primary key,
 	     "str" text NOT NULL,
 	      val int null);
 	exec sql commit work;
 
-	exec sql insert into test (id, str, val) values ( 1, 'Hello', 0);
+	exec sql insert into indicator_test (id, str, val) values ( 1, 'Hello', 0);
 
 	/* use indicator in insert */
-	exec sql insert into test (id, str, val) values ( 2, 'Hi there', :intvar :nullind);
+	exec sql insert into indicator_test (id, str, val) values ( 2, 'Hi there', :intvar :nullind);
 	nullind = 0;
-	exec sql insert into test (id, str, val) values ( 3, 'Good evening', :intvar :nullind);
+	exec sql insert into indicator_test (id, str, val) values ( 3, 'Good evening', :intvar :nullind);
 	exec sql commit work;
 
 	/* use indicators to get information about selects */
-	exec sql select val into :intvar from test where id = 1;
-	exec sql select val into :intvar :nullind from test where id = 2;
+	exec sql select val into :intvar from indicator_test where id = 1;
+	exec sql select val into :intvar :nullind from indicator_test where id = 2;
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
-	exec sql select val into :intvar :nullind from test where id = 3;
+	exec sql select val into :intvar :nullind from indicator_test where id = 3;
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
 
 	/* use indicators for update */
 	intvar = 5; nullind = -1;
-	exec sql update test set val = :intvar :nullind where id = 1;
-	exec sql select val into :intvar :nullind from test where id = 1;
+	exec sql update indicator_test set val = :intvar :nullind where id = 1;
+	exec sql select val into :intvar :nullind from indicator_test where id = 1;
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
 
-	exec sql drop table test;
+	exec sql drop table indicator_test;
 	exec sql commit work;
 
 	exec sql disconnect;
diff --git a/src/interfaces/ecpg/test/sql/insupd.pgc b/src/interfaces/ecpg/test/sql/insupd.pgc
index c406c3aba20d92ee8daa7e4ccba1a12d4ae45565..9be1af498f772a41dbcbe4bc29accefb6d01ddfa 100644
--- a/src/interfaces/ecpg/test/sql/insupd.pgc
+++ b/src/interfaces/ecpg/test/sql/insupd.pgc
@@ -15,17 +15,17 @@ int main(int argc, char* argv[]) {
   EXEC SQL WHENEVER SQLWARNING SQLPRINT;
   EXEC SQL WHENEVER SQLERROR SQLPRINT;
 
-  EXEC SQL CREATE TABLE test(a int, b int);
+  EXEC SQL CREATE TABLE insupd_test(a int, b int);
 
-  EXEC SQL INSERT INTO test (a,b) values (1, 1);
-  EXEC SQL INSERT INTO test (a,b) values (2, 2);
-  EXEC SQL INSERT INTO test (a,b) values (3, 3);
+  EXEC SQL INSERT INTO insupd_test (a,b) values (1, 1);
+  EXEC SQL INSERT INTO insupd_test (a,b) values (2, 2);
+  EXEC SQL INSERT INTO insupd_test (a,b) values (3, 3);
 
-  EXEC SQL UPDATE test set a=a+1;
-  EXEC SQL UPDATE test set (a,b)=(5,5) where a = 4;
-  EXEC SQL UPDATE test set a=4 where a=3;;
+  EXEC SQL UPDATE insupd_test set a=a+1;
+  EXEC SQL UPDATE insupd_test set (a,b)=(5,5) where a = 4;
+  EXEC SQL UPDATE insupd_test set a=4 where a=3;;
 
-  EXEC SQL SELECT a,b into :i1,:i2 from test order by a;
+  EXEC SQL SELECT a,b into :i1,:i2 from insupd_test order by a;
 
   printf("test\na b\n%d %d\n%d %d\n%d %d\n", i1[0], i2[0], i1[1], i2[1], i1[2], i2[2]);
 
diff --git a/src/interfaces/ecpg/test/sql/oldexec.pgc b/src/interfaces/ecpg/test/sql/oldexec.pgc
new file mode 100644
index 0000000000000000000000000000000000000000..a740aeb7de06a4c70cfea4ad0d7bddb467f2350a
--- /dev/null
+++ b/src/interfaces/ecpg/test/sql/oldexec.pgc
@@ -0,0 +1,93 @@
+#include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+exec sql include ../regression;
+
+exec sql whenever sqlerror sqlprint;
+
+int
+main(void)
+{
+exec sql begin declare section;
+	int amount[8];
+	int increment=100;
+	char name[8][8];
+	char letter[8][1];
+	char command[128];
+exec sql end declare section;
+	int i,j;
+
+	ECPGdebug(1, stderr);
+
+	exec sql connect to REGRESSDB1 as main;
+	exec sql create table test (name char(8), amount int, letter char(1));
+	exec sql commit;
+
+	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
+	exec sql execute immediate :command;
+
+	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
+	exec sql execute immediate :command;
+
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
+	exec sql execute immediate :command;
+
+	printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
+
+	sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
+	exec sql prepare I from :command;
+	exec sql execute I using :increment;
+
+	printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
+
+	exec sql commit;
+
+	sprintf (command, "select * from test");
+
+	exec sql prepare F from :command;
+	exec sql declare CUR cursor for F;
+
+	exec sql open CUR;
+	exec sql fetch 8 in CUR into :name, :amount, :letter;
+
+	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
+	{
+		exec sql begin declare section;
+		char n[8], l = letter[i][0];
+		int a = amount[i];
+		exec sql end declare section;
+
+		strncpy(n, name[i], 8);
+		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
+	}
+
+	exec sql close CUR;
+
+	sprintf (command, "select * from test where ? = amount");
+
+	exec sql prepare F from :command;
+	exec sql declare CUR3 cursor for F;
+
+	exec sql open CUR3 using 1;
+	exec sql fetch in CUR3 into :name, :amount, :letter;
+
+	for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
+	{
+		exec sql begin declare section;
+		char n[8], l = letter[i][0];
+		int a = amount[i];
+		exec sql end declare section;
+
+		strncpy(n, name[i], 8);
+		printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
+	}
+
+	exec sql close CUR3;
+	exec sql drop table test;
+	exec sql commit;
+	exec sql disconnect;
+
+	return (0);
+}
diff --git a/src/interfaces/ecpg/test/sql/quote.pgc b/src/interfaces/ecpg/test/sql/quote.pgc
index 1349a181941297ab495bdd603b7dd3d342b6035a..25aca500caa023fc77ba55856a345c9fb6745660 100644
--- a/src/interfaces/ecpg/test/sql/quote.pgc
+++ b/src/interfaces/ecpg/test/sql/quote.pgc
@@ -7,6 +7,7 @@ EXEC SQL INCLUDE ../regression;
 int main(int argc, char* argv[]) {
   EXEC SQL BEGIN DECLARE SECTION;
     char var[25];
+    int i;
   EXEC SQL END DECLARE SECTION;
 
   ECPGdebug(1, stderr);
@@ -23,18 +24,30 @@ int main(int argc, char* argv[]) {
 
   /* this is a\\b actually */
   EXEC SQL INSERT INTO "My_Table" VALUES ( 1, 'a\\\\b' );
-  /* this is a\b */
+  /* this is a\\b */
   EXEC SQL INSERT INTO "My_Table" VALUES ( 1, E'a\\\\b' );
 
   EXEC SQL SET standard_conforming_strings TO on;
 
-  /* this is a\\b actually */
-  EXEC SQL INSERT INTO "My_Table" VALUES ( 1, 'a\\\\b' );
-  /* this is a\b */
-  EXEC SQL INSERT INTO "My_Table" VALUES ( 1, E'a\\\\b' );
+  /* this is a\\\\b actually */
+  EXEC SQL INSERT INTO "My_Table" VALUES ( 2, 'a\\\\b' );
+  /* this is a\\b */
+  EXEC SQL INSERT INTO "My_Table" VALUES ( 2, E'a\\\\b' );
+
+  EXEC SQL BEGIN;
+  EXEC SQL DECLARE C CURSOR FOR SELECT * FROM "My_Table";
+
+  EXEC SQL OPEN C;
+
+  EXEC SQL WHENEVER NOT FOUND DO BREAK;
 
-  EXEC SQL SELECT * FROM "My_Table";
+  while (true)
+  {
+  	EXEC SQL FETCH C INTO :i, :var;
+	printf("value: %d %s\n", i, var);
+  }
 
+  EXEC SQL ROLLBACK;
   EXEC SQL DROP TABLE "My_Table";
 
   EXEC SQL DISCONNECT ALL;