commit ac1659834783f8b10ec4f1100bbb9612f88bc7a5
Author: Böszörményi Zoltán <zboszor@pr.hu>
Date:   Wed Apr 16 10:12:33 2014 +0200

    ECPG: Start tracking subtransactions and cursors in the runtime
    library to reduce network turnaround.
    
    For this purpose, the arguments to ECPGtrans() have changed and
    4 new public functions were introduced: ECPGopen(), ECPGfetch(),
    ECPGcursor_dml() and ECPGclose(). The previously exposed ecpg_do()
    is used to drive all these functions. The library version was
    changed to 7.0 from 6.6 because of the ECPGtrans change.
    
    New error handling is added to the client side to mimic the server
    behaviour if a previous statement failed, if the error happened
    to be a result of a failed check for the savepoint or cursor name.
    
    A new regression test was added to exercise certain aspects of
    the client-side tracking of cursors and subtransactions.

diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index f9536ee..7b825ef 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -5267,20 +5267,30 @@ while (1)
      <term>-230 (<symbol>ECPG_INVALID_STMT</symbol>)</term>
      <listitem>
       <para>
        The statement you are trying to use has not been prepared.
        (SQLSTATE 26000)
       </para>
      </listitem>
     </varlistentry>
 
     <varlistentry>
+     <term>-231 (<symbol>ECPG_INVALID_CURSOR</symbol>)</term>
+     <listitem>
+      <para>
+       The cursor name you are trying to use is invalid.
+       (SQLSTATE 34000)
+      </para>
+     </listitem>
+    </varlistentry>
+
+    <varlistentry>
      <term>-239 (<symbol>ECPG_INFORMIX_DUPLICATE_KEY</symbol>)</term>
      <listitem>
       <para>
        Duplicate key error, violation of unique constraint (Informix
        compatibility mode).  (SQLSTATE 23505)
       </para>
      </listitem>
     </varlistentry>
 
     <varlistentry>
@@ -5353,24 +5363,37 @@ while (1)
        server.  The message contains the error message from the
        <productname>PostgreSQL</productname> server.
       </para>
      </listitem>
     </varlistentry>
 
     <varlistentry>
      <term>-401 (<symbol>ECPG_TRANS</symbol>)</term>
      <listitem>
       <para>
+       This error code may occur in the following conditions.
+      </para>
+      <para>
        The <productname>PostgreSQL</productname> server signaled that
        we cannot start, commit, or rollback the transaction.
        (SQLSTATE 08007)
       </para>
+      <para>
+       While processing a previous command, a client side error happened:
+       invalid savepoint name or invalid cursor name. The actual command
+       was not sent to the server because of this error. To mimic the
+       server behaviour, all subsequent commands return the error for
+       an aborted transaction. (SQLSTATE 25P02)
+      </para>
+      <para>
+       The savepoint name you are trying to use is invalid. (SQLSTATE 3B001)
+      </para>
      </listitem>
     </varlistentry>
 
     <varlistentry>
      <term>-402 (<symbol>ECPG_CONNECT</symbol>)</term>
      <listitem>
       <para>
        The connection attempt to the database did not succeed.
        (SQLSTATE 08001)
       </para>
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index ae4474f..12d96a7 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -7,32 +7,32 @@
 #
 # src/interfaces/ecpg/ecpglib/Makefile
 #
 #-------------------------------------------------------------------------
 
 subdir = src/interfaces/ecpg/ecpglib
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 NAME= ecpg
-SO_MAJOR_VERSION= 6
-SO_MINOR_VERSION= 6
+SO_MAJOR_VERSION= 7
+SO_MINOR_VERSION= 0
 
 override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(libpq_srcdir) -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
 # Need to recompile any libpgport object files
 LIBS := $(filter-out -lpgport, $(LIBS))
 
 OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
-	connect.o misc.o path.o pgstrcasecmp.o \
+	connect.o misc.o path.o cursor.o pgstrcasecmp.o \
 	$(filter snprintf.o strlcpy.o win32setlocale.o isinf.o, $(LIBOBJS))
 
 # thread.c is needed only for non-WIN32 implementation of path.c
 ifneq ($(PORTNAME), win32)
 OBJS += thread.o
 endif
 
 SHLIB_LINK = -L../pgtypeslib -lpgtypes $(libpq) $(filter -lintl -lm, $(LIBS)) $(PTHREAD_LIBS)
 SHLIB_PREREQS = submake-libpq submake-pgtypeslib
 
diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/ecpglib/connect.c
index 55c5680..0c4af66 100644
--- a/src/interfaces/ecpg/ecpglib/connect.c
+++ b/src/interfaces/ecpg/ecpglib/connect.c
@@ -471,20 +471,23 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
 #ifdef ENABLE_THREAD_SAFETY
 	pthread_mutex_lock(&connections_mutex);
 #endif
 	if (connection_name != NULL)
 		this->name = ecpg_strdup(connection_name, lineno);
 	else
 		this->name = ecpg_strdup(realname, lineno);
 
 	this->cache_head = NULL;
 	this->prep_stmts = NULL;
+	this->subxact_desc = NULL;
+	this->cursor_desc = NULL;
+	this->client_side_error = false;
 
 	if (all_connections == NULL)
 		this->next = NULL;
 	else
 		this->next = all_connections;
 
 	all_connections = this;
 #ifdef ENABLE_THREAD_SAFETY
 	pthread_setspecific(actual_connection_key, all_connections);
 #endif
diff --git a/src/interfaces/ecpg/ecpglib/cursor.c b/src/interfaces/ecpg/ecpglib/cursor.c
new file mode 100644
index 0000000..44b6b37
--- /dev/null
+++ b/src/interfaces/ecpg/ecpglib/cursor.c
@@ -0,0 +1,358 @@
+/* src/interfaces/ecpg/ecpglib/cursor.c */
+
+/*
+ * ECPG client-side cursor support routines
+ */
+
+#define POSTGRES_ECPG_INTERNAL
+#include "postgres_fe.h"
+
+#include <stdlib.h>
+#include <limits.h>
+
+#include "ecpgtype.h"
+#include "ecpglib.h"
+#include "ecpgerrno.h"
+#include "extern.h"
+
+static void
+raise_cursor_error(struct connection *con, int lineno, const char *name)
+{
+	con->client_side_error = true;
+	ecpg_raise(lineno, ECPG_INVALID_CURSOR,
+						ECPG_SQLSTATE_INVALID_CURSOR_NAME,
+						(name ? name : ecpg_gettext("<empty>")));
+}
+
+/*
+ * Find the cursor with the given name.
+ * Optionally, return the previous one in the list.
+ */
+static bool
+find_cursor(struct connection *con, int lineno, const char *name, bool ignore,
+				struct cursor_descriptor **out,
+				struct cursor_descriptor **out_prev)
+{
+	struct cursor_descriptor *desc = con->cursor_desc,
+					*prev = NULL;
+	int (* strcmp_fn)(const char *, const char *);
+	bool	found = false;
+
+	if (!name)
+	{
+		raise_cursor_error(con, lineno, name);
+		if (out)
+			*out = NULL;
+		if (out_prev)
+			*out_prev = NULL;
+		return false;
+	}
+
+	/*
+	 * This will ensure that:
+	 * - quoted cursor names will be the first ones in the list ordered case-sensitively
+	 * - unquoted cursor names at the end, ordered case-insensitively.
+	 */
+	strcmp_fn = (name[0] == '"' ? strcmp : pg_strcasecmp);
+
+	while (desc)
+	{
+		int ret = strcmp_fn(desc->name, name);
+
+		if (ret == 0)
+		{
+			found = true;
+			break;
+		}
+		/*
+		 * The cursor list is ordered quasi alphabetically,
+		 * don't search the whole list.
+		 */
+		if (ret > 0)
+			break;
+		prev = desc;
+		desc = desc->next;
+	}
+
+	if (!found)
+	{
+		if (!ignore)
+			raise_cursor_error(con, lineno, name);
+		desc = NULL;
+	}
+
+	if (out)
+		*out = desc;
+	if (out_prev)
+		*out_prev = prev;
+	return found;
+}
+
+/*
+ * Add a new cursor descriptor, maintain "mostly" alphabetic order.
+ * - case sensitive alphabetic order for quoted cursor names
+ * - case insensitive alphabetic order for non-quoted cursor names
+ */
+static struct cursor_descriptor *
+add_cursor(int lineno, struct connection *con,
+					const char *name,
+					int subxact_level,
+					bool with_hold)
+{
+	struct cursor_descriptor *desc, *prev;
+
+	if (!name || name[0] == '\0')
+		return NULL;
+
+	if (find_cursor(con, lineno, name, true, &desc, &prev))
+		return desc;
+
+	desc = (struct cursor_descriptor *)
+			ecpg_alloc(sizeof(struct cursor_descriptor),
+								lineno);
+	if (!desc)
+		return NULL;
+
+	/* Copy the name */
+	desc->name = ecpg_strdup(name, lineno);
+	if (!desc->name)
+	{
+		ecpg_free(desc);
+		return NULL;
+	}
+
+	desc->subxact_level = subxact_level;
+	desc->with_hold = with_hold;
+
+	if (prev)
+	{
+		desc->next = prev->next;
+		prev->next = desc;
+	}
+	else
+	{
+		desc->next = con->cursor_desc;
+		con->cursor_desc = desc;
+	}
+
+	return desc;
+}
+
+/*
+ * Delete the cursor from the list of descriptors.
+ */
+static void
+del_cursor(struct connection *con, int lineno, const char *name)
+{
+	struct cursor_descriptor *desc, *prev;
+
+	if (find_cursor(con, lineno, name, true, &desc, &prev))
+	{
+		if (prev)
+			prev->next = desc->next;
+		else
+			con->cursor_desc = desc->next;
+
+		ecpg_free((void *)desc->name);
+		ecpg_free(desc);
+	}
+}
+
+/*
+ * Commit or roll back cursors:
+ * - all transactional (non-WITH HOLD) cursors are forgotten at
+ *   the end of the transaction, no matter if COMMIT or ROLLBACK
+ * - at RELEASE SAVEPOINT, the cursors are propagated one
+ *   subtransaction level up.
+ * - at ROLLBACK TO SAVEPOINT, all cursors are forgotten that were
+ *   created in this subtransaction or below that level
+ * - WITH HOLD cursors are kept after the transaction in case of
+ *   toplevel COMMIT. The caller checks for the transaction in error
+ *   and sets the rollback flag accordingly.
+ */
+void
+ecpg_commit_cursors(int lineno, struct connection * conn,
+						bool rollback, int level)
+{
+	struct cursor_descriptor *desc, *tmp,
+					*prev = NULL;
+
+	desc = conn->cursor_desc;
+	while (desc)
+	{
+		/* Keep already COMMITted WITH HOLD cursors */
+		if (desc->with_hold && desc->subxact_level == 0)
+			;
+		else if (rollback)
+		{
+			/*
+			 * On ROLLBACK [ TO SAVEPOINT ... ] forget about
+			 * every cursor DECLAREd under this level.
+			 */
+			if (desc->subxact_level >= level)
+			{
+				tmp = desc->next;
+				ecpg_free(desc->name);
+				ecpg_free(desc);
+				desc = tmp;
+				if (prev)
+					prev->next = tmp;
+				else
+					conn->cursor_desc = tmp;
+				continue;
+			}
+		}
+		else
+		{
+			/*
+			 * If this is a WITH HOLD cursor or we're in a
+			 * subtransaction, COMMIT the cursor one level up.
+			 */
+			if (desc->with_hold || level > 1)
+			{
+				if (level > 0)
+					desc->subxact_level = level - 1;
+			}
+			/*
+			 * Otherwise (not WITH HOLD cursor AND it's the
+			 * toplevel transaction) free the cursor.
+			 */
+			else
+			{
+				tmp = desc->next;
+				ecpg_free(desc->name);
+				ecpg_free(desc);
+				desc = tmp;
+				if (prev)
+					prev->next = tmp;
+				else
+					conn->cursor_desc = tmp;
+				continue;
+			}
+		}
+		prev = desc;
+		desc = desc->next;
+	}
+}
+
+/*
+ * Declare the cursor in the backend and create a
+ * minimalistic descriptor to make tracking possible.
+ * This function is called when the ECPG code OPENs the cursor.
+ */
+bool
+ECPGopen(const int lineno, const int compat, const int force_indicator,
+			const char *connection_name, const bool questionmarks,
+			const bool with_hold, const char *curname, const int st, const char *query, ...)
+{
+	struct connection *con = ecpg_get_connection(connection_name);
+	int		subxact_level;
+	bool		ret;
+	va_list		args;
+
+	/*
+	 * Execute the DECLARE query in the backend.
+	 */
+	va_start(args, query);
+	ret = ecpg_do(lineno, compat, force_indicator, connection_name, questionmarks,
+										st,
+										query,
+										args);
+	va_end(args);
+
+	if (!ret)
+		return false;
+
+	/* Finally add the cursor to the connection. */
+	if (con->subxact_desc)
+		subxact_level = con->subxact_desc->level;
+	else
+		subxact_level =
+			(PQtransactionStatus(con->connection) != PQTRANS_IDLE ?
+										1 : 0);
+	add_cursor(lineno, con, curname, subxact_level, with_hold);
+
+	return true;
+}
+
+/*
+ * ECPGfetch
+ * Execute a FETCH or MOVE statement for the application.
+ *
+ * This function maintains the internal cursor descriptor and
+ * reduces the the network roundtrip by returning early for
+ * an unknown cursor name.
+ */
+bool
+ECPGfetch(const int lineno, const int compat, const int force_indicator,
+				const char *connection_name, const bool questionmarks,
+				const char *curname, const int st, const char *query, ...)
+{
+	struct connection  *con = ecpg_get_connection(connection_name);
+	struct cursor_descriptor *cur;
+	bool		ret;
+	va_list		args;
+
+	if (!find_cursor(con, lineno, curname, false, &cur, NULL))
+		return false;
+
+	va_start(args, query);
+	ret = ecpg_do(lineno, compat, force_indicator, connection_name, questionmarks,
+									st,
+									query,
+									args);
+	va_end(args);
+
+	return ret;
+}
+
+/*
+ * ECPGcursor_dml
+ * Called for DELETE / UPDATE ... WHERE CURRENT OF cursorname
+ */
+bool
+ECPGcursor_dml(const int lineno, const int compat, const int force_indicator,
+				const char *connection_name, const bool questionmarks,
+				const char *curname, const int st, const char *query, ...)
+{
+	struct connection  *con = ecpg_get_connection(connection_name);
+	struct cursor_descriptor *cur;
+	bool		ret;
+	va_list		args;
+
+	if (!find_cursor(con, lineno, curname, false, &cur, NULL))
+		return false;
+
+	va_start(args, query);
+	ret = ecpg_do(lineno, compat, force_indicator, connection_name, questionmarks,
+									st, query, args);
+	va_end(args);
+	return ret;
+}
+
+/*
+ * ECPGclose
+ * Close and free a cursor.
+ */
+bool
+ECPGclose(const int lineno, const int compat, const int force_indicator,
+				const char *connection_name, const bool questionmarks,
+				const char *curname, const int st, const char *query, ...)
+{
+	struct connection  *con = ecpg_get_connection(connection_name);
+	struct cursor_descriptor *cur;
+	bool		ret;
+	va_list		args;
+
+	if (!find_cursor(con, lineno, curname, false, &cur, NULL))
+		return false;
+
+	va_start(args, query);
+	ret = ecpg_do(lineno, compat, force_indicator, connection_name, questionmarks,
+									st, query, args);
+	va_end(args);
+
+	del_cursor(con, lineno, curname);
+
+	return ret;
+}
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index 715bedb..0e5c2e1 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -173,33 +173,67 @@ ecpg_raise(int line, int code, const char *sqlstate, const char *str)
 			break;
 
 		case ECPG_VAR_NOT_CHAR:
 			snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
 			/*------
 			   translator: this string will be truncated at 149 characters expanded.  */
 					 ecpg_gettext("variable does not have a character type on line %d"), line);
 			break;
 
 		case ECPG_TRANS:
-			snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			if (strcmp(sqlstate, ECPG_SQLSTATE_IN_FAILED_SQL_TRANSACTION) == 0)
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			/*------
+			   translator: this string will be truncated at 149 characters expanded.  */
+					 ecpg_gettext("current transaction is aborted, commands ignored until end of transaction block on line %d"), line);
+			}
+			else if (strcmp(sqlstate, ECPG_SQLSTATE_S_E_INVALID_SPECIFICATION) == 0)
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			/*------
+			   translator: this string will be truncated at 149 characters expanded.  */
+					 ecpg_gettext("no such savepoint \"%s\" on line %d"), str, line);
+			}
+			else
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
 			/*------
 			   translator: this string will be truncated at 149 characters expanded.  */
-			ecpg_gettext("error in transaction processing on line %d"), line);
+					 ecpg_gettext("error in transaction processing on line %d"), line);
+			}
 			break;
 
 		case ECPG_CONNECT:
 			snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
 			/*------
 			   translator: this string will be truncated at 149 characters expanded.  */
 					 ecpg_gettext("could not connect to database \"%s\" on line %d"), str, line);
 			break;
 
+		case ECPG_INVALID_CURSOR:
+			if (strcmp(sqlstate, ECPG_SQLSTATE_INVALID_CURSOR_NAME) == 0)
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			/*------
+			   translator: this string will be truncated at 149 characters expanded.  */
+					 ecpg_gettext("invalid cursorname \"%s\" on line %d"), str, line);
+			}
+			else
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			/*------
+			   translator: this string will be truncated at 149 characters expanded.  */
+					 ecpg_gettext("invalid cursor error %d on line %d"), code, line);
+			}
+			break;
+
 		default:
 			snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
 			/*------
 			   translator: this string will be truncated at 149 characters expanded.  */
 					 ecpg_gettext("SQL error %d on line %d"), code, line);
 			break;
 	}
 
 	sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
 	ecpg_log("raising sqlcode %d on line %d: %s\n", code, line, sqlca->sqlerrm.sqlerrmc);
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index ef5824a..499143a 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -1891,20 +1891,27 @@ ecpg_do_prologue(int lineno, const int compat, const int force_indicator,
 #endif
 
 	con = ecpg_get_connection(connection_name);
 
 	if (!ecpg_init(con, connection_name, lineno))
 	{
 		ecpg_do_epilogue(stmt);
 		return false;
 	}
 
+	if (con->client_side_error)
+	{
+		ecpg_do_epilogue(stmt);
+		ecpg_raise(lineno, ECPG_TRANS, ECPG_SQLSTATE_IN_FAILED_SQL_TRANSACTION, NULL);
+		return false;
+	}
+
 	/*
 	 * If statement type is ECPGst_prepnormal we are supposed to prepare the
 	 * statement before executing them
 	 */
 	if (statement_type == ECPGst_prepnormal)
 	{
 		if (!ecpg_auto_prepare(lineno, connection_name, compat, &prepname, query))
 		{
 			ecpg_do_epilogue(stmt);
 			return false;
diff --git a/src/interfaces/ecpg/ecpglib/exports.txt b/src/interfaces/ecpg/ecpglib/exports.txt
index 69e9617..dec587e 100644
--- a/src/interfaces/ecpg/ecpglib/exports.txt
+++ b/src/interfaces/ecpg/ecpglib/exports.txt
@@ -22,10 +22,14 @@ ECPGset_desc_header              19
 ECPGset_noind_null               20
 ECPGsetcommit                    21
 ECPGsetconn                      22
 ECPGstatus                       23
 ECPGtrans                        24
 sqlprint                         25
 ECPGget_PGconn			 26
 ECPGtransactionStatus		 27
 ECPGset_var			 28
 ECPGget_var			 29
+ECPGopen			 30
+ECPGfetch			 31
+ECPGcursor_dml			 32
+ECPGclose			 33
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index ff12acb..5bb7ecd 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -71,28 +71,53 @@ struct statement
 
 /* structure to store prepared statements for a connection */
 struct prepared_statement
 {
 	char	   *name;
 	bool		prepared;
 	struct statement *stmt;
 	struct prepared_statement *next;
 };
 
+struct subxact_descriptor
+{
+	char	   *name;
+	struct subxact_descriptor *next;
+	int		level;
+};
+
+struct cursor_descriptor {
+	struct cursor_descriptor *next;
+
+	char	   *name;
+
+	/*
+	 * The cursor was created in this level of * (sub-)transaction.
+	 * 0: WITH HOLD, committed successfully in a previous transaction
+	 * 1: cursor declared in the toplevel transaction
+	 * >=2: cursor declared in a named SAVEPOINT at the specified level
+	 */
+	int		subxact_level;
+	bool		with_hold;
+};
+
 /* structure to store connections */
 struct connection
 {
 	char	   *name;
 	PGconn	   *connection;
 	bool		autocommit;
+	bool		client_side_error;
 	struct ECPGtype_information_cache *cache_head;
 	struct prepared_statement *prep_stmts;
+	struct subxact_descriptor *subxact_desc;
+	struct cursor_descriptor *cursor_desc;
 	struct connection *next;
 };
 
 /* structure to store descriptors */
 struct descriptor
 {
 	char	   *name;
 	PGresult   *result;
 	struct descriptor *next;
 	int			count;
@@ -192,37 +217,41 @@ char	   *ecpg_prepared(const char *, struct connection *);
 bool		ecpg_deallocate_all_conn(int lineno, enum COMPAT_MODE c, struct connection * conn);
 void		ecpg_log(const char *format,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
 bool		ecpg_auto_prepare(int, const char *, const int, char **, const char *);
 void		ecpg_init_sqlca(struct sqlca_t * sqlca);
 
 struct sqlda_compat *ecpg_build_compat_sqlda(int, PGresult *, int, enum COMPAT_MODE);
 void		ecpg_set_compat_sqlda(int, struct sqlda_compat **, const PGresult *, int, enum COMPAT_MODE);
 struct sqlda_struct *ecpg_build_native_sqlda(int, PGresult *, int, enum COMPAT_MODE);
 void		ecpg_set_native_sqlda(int, struct sqlda_struct **, const PGresult *, int, enum COMPAT_MODE);
 
+void		ecpg_commit_cursors(int lineno, struct connection * conn, bool rollback, int level);
+
 /* SQLSTATE values generated or processed by ecpglib (intentionally
  * not exported -- users should refer to the codes directly) */
 
 #define ECPG_SQLSTATE_NO_DATA				"02000"
 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_PARAMETERS	"07001"
 #define ECPG_SQLSTATE_USING_CLAUSE_DOES_NOT_MATCH_TARGETS		"07002"
 #define ECPG_SQLSTATE_RESTRICTED_DATA_TYPE_ATTRIBUTE_VIOLATION	"07006"
 #define ECPG_SQLSTATE_INVALID_DESCRIPTOR_INDEX		"07009"
 #define ECPG_SQLSTATE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION	"08001"
 #define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST		"08003"
 #define ECPG_SQLSTATE_TRANSACTION_RESOLUTION_UNKNOWN	"08007"
 #define ECPG_SQLSTATE_CARDINALITY_VIOLATION "21000"
 #define ECPG_SQLSTATE_NULL_VALUE_NO_INDICATOR_PARAMETER "22002"
 #define ECPG_SQLSTATE_ACTIVE_SQL_TRANSACTION		"25001"
 #define ECPG_SQLSTATE_NO_ACTIVE_SQL_TRANSACTION		"25P01"
+#define ECPG_SQLSTATE_IN_FAILED_SQL_TRANSACTION		"25P02"
 #define ECPG_SQLSTATE_INVALID_SQL_STATEMENT_NAME	"26000"
 #define ECPG_SQLSTATE_INVALID_SQL_DESCRIPTOR_NAME	"33000"
-#define ECPG_SQLSTATE_INVALID_CURSOR_NAME	"34000"
+#define ECPG_SQLSTATE_INVALID_CURSOR_NAME		"34000"
+#define ECPG_SQLSTATE_S_E_INVALID_SPECIFICATION		"3B001"
 #define ECPG_SQLSTATE_SYNTAX_ERROR			"42601"
 #define ECPG_SQLSTATE_DATATYPE_MISMATCH		"42804"
 #define ECPG_SQLSTATE_DUPLICATE_CURSOR		"42P03"
 
 /* implementation-defined internal errors of ecpg */
 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR	"YE000"
 #define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY	"YE001"
 
 #endif   /* _ECPG_LIB_EXTERN_H */
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 9371f71..44ce5a9 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -176,57 +176,263 @@ ECPGtransactionStatus(const char *connection_name)
 	const struct connection *con;
 
 	con = ecpg_get_connection(connection_name);
 	if (con == NULL)
 	{
 		/* transaction status is unknown */
 		return PQTRANS_UNKNOWN;
 	}
 
 	return PQtransactionStatus(con->connection);
+}
+
+static void
+raise_xact_error(struct connection *con, int lineno, const char *name)
+{
+	con->client_side_error = true;
+	ecpg_raise(lineno, ECPG_TRANS, ECPG_SQLSTATE_S_E_INVALID_SPECIFICATION,
+					(name ? name : ecpg_gettext("<empty>")));
+}
+
+static bool
+find_subxact(struct connection *con, int lineno, const char *name, bool ignore,
+					struct subxact_descriptor **out)
+{
+	struct subxact_descriptor *desc = con->subxact_desc;
+	bool    found = false;
+
+	if (!name)
+	{
+		raise_xact_error(con, lineno, name);
+		if (out)
+			*out = NULL;
+		return false;
+	}
+
+	while (desc)
+	{
+		int ret = pg_strcasecmp(desc->name, name);
+
+		if (ret == 0)
+		{
+			found = true;
+			break;
+		}
+
+		desc = desc->next;
+	}
+
+	if (!found && !ignore)
+		raise_xact_error(con, lineno, name);
+	if (out)
+		*out = desc;
+	return found;
+}
+
+static void
+add_savepoint(struct connection *con, int lineno, const char *savepoint_name)
+{
+	struct subxact_descriptor *desc, *oldptr;
+
+	oldptr = con->subxact_desc;
+	desc = (struct subxact_descriptor *)
+		ecpg_alloc(sizeof(struct subxact_descriptor), lineno);
+	desc->level = (oldptr ? oldptr->level + 1 : 2);
+	desc->name = ecpg_strdup(savepoint_name, lineno);
+	desc->next = oldptr;
+	con->subxact_desc = desc;
+}
+
+static void
+release_savepoint(struct connection *con, struct subxact_descriptor *ptr, bool rollback)
+{
+	struct subxact_descriptor *desc, *next = NULL;
+
+	desc = con->subxact_desc;
+	while (desc != ptr)
+	{
+		next = desc->next;
+		ecpg_free(desc->name);
+		ecpg_free(desc);
+		desc = next;
+	}
 
+	if (desc)
+	{
+		/* ROLLBACK TO SAVEPOINT leaves the savepoint in place */
+		if (rollback)
+			con->subxact_desc = desc;
+		else
+		{
+			/* RELEASE SAVEPOINT forgets about the savepoint */
+			con->subxact_desc = desc->next;
+			ecpg_free(desc->name);
+			ecpg_free(desc);
+		}
+	}
+	else
+		con->subxact_desc = NULL;
 }
 
+/*
+ * ECPGtrans
+ * Track (sub-)transactions by flags.
+ * Parameters
+ *	connection_name:connection
+ *	transaction:	the SQL string
+ *	prepared:	prepared transaction or not
+ *	begin:		start or finish transaction
+ *	rollback:	valid if begin is false: commit or rollback
+ *	savepoint_name:	NULL -> top level transaction,
+ *			subtransaction otherwise
+ *
+ * The following table shows the combination of flags (x is ignored):
+ * prepared | begin | rollback | savepoint_name | command
+ * ---------+-------+----------+----------------+-----------------------
+ *   false  | false |   false  |       NULL     | COMMIT
+ *   false  | false |   false  |  valid pointer | RELEASE SAVEPOINT
+ *   false  | false |   true   |       NULL     | ROLLBACK
+ *   false  | false |   true   |  valid pointer | ROLLBACK TO SAVEPOINT
+ *   false  | true  |     x    |       NULL     | BEGIN
+ *   false  | true  |     x    |  valid pointer | SAVEPOINT
+ *   true   | false |   false  |        x       | COMMIT PREPARED
+ *   true   | false |   true   |        x       | ROLLBACK PREPARED
+ *   true   | true  |     x    |        x       | PREPARE TRANSACTION
+ */
 bool
-ECPGtrans(int lineno, const char *connection_name, const char *transaction)
+ECPGtrans(int lineno, const char *connection_name, const char *transaction,
+				bool prepared, bool begin, bool rollback,
+				const char *savepoint_name)
 {
 	PGresult   *res;
 	struct connection *con = ecpg_get_connection(connection_name);
+	bool		rollback_override = false;
 
 	if (!ecpg_init(con, connection_name, lineno))
 		return (false);
 
+	if (con && (con->client_side_error || PQtransactionStatus(con->connection) == PQTRANS_INERROR))
+	{
+		/*
+		 * Follow the backend behaviour for failed transactions:
+		 * - override PREPARE TRANSACTION and COMMIT as ROLLBACK
+		 *   so they don't fail
+		 * - allow ROLLBACK and ROLLBACK TO SAVEPOINT to get through
+		 * - emit "current transaction is aborted..." for everything else
+		 */
+		if ((prepared && begin) ||
+				(!prepared && !begin && !rollback && savepoint_name == NULL))
+		{
+			transaction = "rollback";
+			rollback_override = true;
+		}
+		else if (!(!prepared && !begin && rollback))
+		{
+			ecpg_raise(lineno, ECPG_TRANS, ECPG_SQLSTATE_IN_FAILED_SQL_TRANSACTION, NULL);
+			return false;
+		}
+	}
+
 	ecpg_log("ECPGtrans on line %d: action \"%s\"; connection \"%s\"\n", lineno, transaction, con ? con->name : "null");
 
 	/* if we have no connection we just simulate the command */
 	if (con && con->connection)
 	{
 		/*
 		 * If we got a transaction command but have no open transaction, we
 		 * have to start one, unless we are in autocommit, where the
-		 * developers have to take care themselves. However, if the command is
-		 * a begin statement, we just execute it once.
+		 * developers have to take care themselves. However:
+		 * - if the command is a begin statement, we just execute it once
+		 * - the command is COMMIT/ROLLBACK PREPARED, it must be executed
+		 *   outside of a transaction.
 		 */
-		if (PQtransactionStatus(con->connection) == PQTRANS_IDLE && !con->autocommit && strncmp(transaction, "begin", 5) != 0 && strncmp(transaction, "start", 5) != 0)
+		if (PQtransactionStatus(con->connection) == PQTRANS_IDLE && !con->autocommit &&
+			/* exclude BEGIN */
+			!(!prepared && begin && savepoint_name == NULL) &&
+			/* exclude COMMIT/ROLLBACK PREPARED */
+			!(prepared && !begin))
 		{
 			res = PQexec(con->connection, "begin transaction");
 			if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
-				return FALSE;
+				return false;
 			PQclear(res);
 		}
 
 		res = PQexec(con->connection, transaction);
 		if (!ecpg_check_PQresult(res, lineno, con->connection, ECPG_COMPAT_PGSQL))
-			return FALSE;
+			return false;
 		PQclear(res);
 	}
 
+	if (con)
+	{
+		struct subxact_descriptor *desc;
+
+		/* Simplify checking rollback conditions for ecpg_commit_cursors() later */
+		if (rollback_override)
+		{
+			prepared = false;
+			begin = false;
+			rollback = true;
+		}
+
+		/*
+		 * We keep track of subtransactions to be able to correctly
+		 * account for transactional cursors as well.
+		 */
+		if (!prepared && savepoint_name)
+		{
+			int	level;
+
+			if (begin)
+			{
+				/* SAVEPOINT nnn */
+				if (find_subxact(con, lineno, savepoint_name, true, &desc))
+				{
+					/*
+					 * SAVEPOINT nnn with an already existing savepoint name
+					 * does an implicit RELEASE SAVEPOINT nnn
+					 */
+					level = desc->level;
+					release_savepoint(con, desc, false);
+					ecpg_commit_cursors(lineno, con, false, level);
+				}
+
+				add_savepoint(con, lineno, savepoint_name);
+			}
+			else
+			{
+				/*
+				 * ROLLBACK TO / RELEASE SAVEPOINT nnn
+				 *
+				 * The above PQexec() already succeeded for savepoint_name
+				 * but check for completeness anyway.
+				 */
+				if (!find_subxact(con, lineno, savepoint_name, false, &desc))
+					return false;
+
+				level = desc->level;
+				release_savepoint(con, desc, rollback);
+				ecpg_commit_cursors(lineno, con, rollback, level);
+			}
+		}
+		/* Toplevel COMMIT / ROLLBACK */
+		else if (!prepared && !begin && savepoint_name == NULL)
+		{
+			release_savepoint(con, NULL, rollback);
+			ecpg_commit_cursors(lineno, con, rollback, 1);
+		}
+
+		/* At this point there's no error anymore. */
+		con->client_side_error = false;
+	}
+
 	return true;
 }
 
 
 void
 ECPGdebug(int n, FILE *dbgs)
 {
 #ifdef ENABLE_THREAD_SAFETY
 	pthread_mutex_lock(&debug_init_mutex);
 #endif
diff --git a/src/interfaces/ecpg/include/ecpgerrno.h b/src/interfaces/ecpg/include/ecpgerrno.h
index 36b15b7..f21dad2 100644
--- a/src/interfaces/ecpg/include/ecpgerrno.h
+++ b/src/interfaces/ecpg/include/ecpgerrno.h
@@ -30,20 +30,21 @@
 #define ECPG_EMPTY			-212
 #define ECPG_MISSING_INDICATOR		-213
 #define ECPG_NO_ARRAY			-214
 #define ECPG_DATA_NOT_ARRAY		-215
 #define ECPG_ARRAY_INSERT		-216
 
 #define ECPG_NO_CONN			-220
 #define ECPG_NOT_CONN			-221
 
 #define ECPG_INVALID_STMT		-230
+#define ECPG_INVALID_CURSOR		-231
 
 /* dynamic SQL related */
 #define ECPG_UNKNOWN_DESCRIPTOR		-240
 #define ECPG_INVALID_DESCRIPTOR_INDEX	-241
 #define ECPG_UNKNOWN_DESCRIPTOR_ITEM	-242
 #define ECPG_VAR_NOT_NUMERIC		-243
 #define ECPG_VAR_NOT_CHAR		-244
 
 /* finally the backend error messages, they start at 400 */
 #define ECPG_PGSQL			-400
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index 3b8ed4c..02f319d 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -45,31 +45,41 @@ __attribute__((format_arg(1)));
 extern		"C"
 {
 #endif
 
 void		ECPGdebug(int, FILE *);
 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(const int, const int, const int, const char *, const bool, const int, const char *,...);
-bool		ECPGtrans(int, const char *, const char *);
+bool		ECPGtrans(int, const char *, const char *, bool, bool, bool, const char *);
 bool		ECPGdisconnect(int, const char *);
 bool		ECPGprepare(int, const char *, const bool, const char *, const char *);
 bool		ECPGdeallocate(int, int, const char *, const char *);
 bool		ECPGdeallocate_all(int, int, const char *);
 char	   *ECPGprepared_statement(const char *, const char *, int);
 PGconn	   *ECPGget_PGconn(const char *);
 PGTransactionStatusType ECPGtransactionStatus(const char *);
 
 char	   *ECPGerrmsg(void);
 
+/* Cursor functions */
+bool		ECPGopen(const int, const int, const int, const char *, const bool, const bool,
+				const char *, const int, const char *, ...);
+bool		ECPGfetch(const int, const int, const int, const char *, const bool,
+				const char *, const int, const char *, ...);
+bool		ECPGcursor_dml(const int, const int, const int, const char *, const bool,
+				const char *, const int, const char *, ...);
+bool		ECPGclose(const int, const int, const int, const char *, const bool,
+				const char *, const int, const char *, ...);
+
  /* print an error message */
 void		sqlprint(void);
 
 /* define this for simplicity as well as compatibility */
 
 #define		SQLCODE		sqlca.sqlcode
 #define		SQLSTATE		sqlca.sqlstate
 
 /* dynamic SQL */
 
diff --git a/src/interfaces/ecpg/preproc/ecpg.addons b/src/interfaces/ecpg/preproc/ecpg.addons
index b3b36cf..ebc9b16 100644
--- a/src/interfaces/ecpg/preproc/ecpg.addons
+++ b/src/interfaces/ecpg/preproc/ecpg.addons
@@ -8,51 +8,135 @@ ECPG: stmtClosePortalStmt block
 				if (connection)
 					mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in CLOSE DATABASE statement");
 
 				fprintf(yyout, "{ ECPGdisconnect(__LINE__, \"CURRENT\");");
 				whenever_action(2);
 				free($1);
 				break;
 			}
 		}
 
-		output_statement($1, 0, ECPGst_normal);
+		output_close_statement($1, 0, ECPGst_normal);
 	}
 ECPG: stmtDeallocateStmt block
 	{
 		output_deallocate_prepare_statement($1);
 	}
 ECPG: stmtDeclareCursorStmt block
 	{ output_simple_statement($1); }
 ECPG: stmtDiscardStmt block
-ECPG: stmtFetchStmt block
 	{ output_statement($1, 1, ECPGst_normal); }
-ECPG: stmtDeleteStmt block
+ECPG: stmtFetchStmt block
+	{ output_fetch_statement($1, 1, ECPGst_normal); }
 ECPG: stmtInsertStmt block
 ECPG: stmtSelectStmt block
-ECPG: stmtUpdateStmt block
 	{ output_statement($1, 1, ECPGst_prepnormal); }
+ECPG: stmtDeleteStmt block
+ECPG: stmtUpdateStmt block
+	{
+		if (current_cursor)
+			output_cursor_dml_statement($1, 1, ECPGst_prepnormal);
+		else
+			output_statement($1, 1, ECPGst_prepnormal);
+	}
 ECPG: stmtExecuteStmt block
 	{ output_statement($1, 1, ECPGst_execute); }
 ECPG: stmtPrepareStmt block
 	{
 		if ($1.type == NULL || strlen($1.type) == 0)
 			output_prepare_statement($1.name, $1.stmt);
 		else
 			output_statement(cat_str(5, mm_strdup("prepare"), $1.name, $1.type, mm_strdup("as"), $1.stmt), 0, ECPGst_normal);
 	}
 ECPG: stmtTransactionStmt block
 	{
-		fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", $1);
+		char *tr_name;
+
+		if (transact_name)
+		{
+			tr_name = mm_alloc(4 + strlen(transact_name));
+			sprintf(tr_name, "\"%s\"", transact_name);
+		}
+		else
+			tr_name = mm_strdup("NULL");
+
+		fprintf(yyout, "{ ECPGtrans(__LINE__, %s, \"%s\", %d, %d, %d, %s);",
+					connection ? connection : "NULL",
+					$1,
+					transact_prepared,
+					transact_start,
+					transact_rollback,
+					tr_name);
+		free(tr_name);
+		free(transact_name);
+		transact_name = NULL;
 		whenever_action(2);
 		free($1);
 	}
+ECPG: TransactionStmtABORT_Popt_transaction addon
+ECPG: TransactionStmtROLLBACKopt_transaction addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = true;
+		transact_name = NULL;
+ECPG: TransactionStmtBEGIN_Popt_transactiontransaction_mode_list_or_empty addon
+ECPG: TransactionStmtSTARTTRANSACTIONtransaction_mode_list_or_empty addon
+		transact_prepared = false;
+		transact_start = true;
+		transact_rollback = false;
+		transact_name = NULL;
+ECPG: TransactionStmtCOMMITopt_transaction addon
+ECPG: TransactionStmtEND_Popt_transaction addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = false;
+		transact_name = NULL;
+ECPG: TransactionStmtSAVEPOINTColId addon
+		transact_prepared = false;
+		transact_start = true;
+		transact_rollback = false;
+		transact_name = mm_strdup($2);
+ECPG: TransactionStmtRELEASESAVEPOINTColId addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = false;
+		transact_name = mm_strdup($3);
+ECPG: TransactionStmtRELEASEColId addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = false;
+		transact_name = mm_strdup($2);
+ECPG: TransactionStmtROLLBACKopt_transactionTOSAVEPOINTColId addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = true;
+		transact_name = mm_strdup($5);
+ECPG: TransactionStmtROLLBACKopt_transactionTOColId addon
+		transact_prepared = false;
+		transact_start = false;
+		transact_rollback = true;
+		transact_name = mm_strdup($4);
+ECPG: TransactionStmtPREPARETRANSACTIONSconst addon
+		transact_prepared = true;
+		transact_start = true;
+		transact_rollback = false;
+		transact_name = NULL;
+ECPG: TransactionStmtCOMMITPREPAREDSconst addon
+		transact_prepared = true;
+		transact_start = false;
+		transact_rollback = false;
+		transact_name = NULL;
+ECPG: TransactionStmtROLLBACKPREPAREDSconst addon
+		transact_prepared = true;
+		transact_start = false;
+		transact_rollback = true;
+		transact_name = NULL;
 ECPG: stmtViewStmt rule
 	| ECPGAllocateDescr
 	{
 		fprintf(yyout,"ECPGallocate_desc(__LINE__, %s);",$1);
 		whenever_action(0);
 		free($1);
 	}
 	| ECPGConnect
 	{
 		if (connection)
@@ -125,21 +209,21 @@ ECPG: stmtViewStmt rule
 		output_get_descr_header($1);
 		free($1);
 	}
 	| ECPGOpen
 	{
 		struct cursor *ptr;
 
 		if ((ptr = add_additional_variables($1, true)) != NULL)
 		{
 			connection = ptr->connection ? mm_strdup(ptr->connection) : NULL;
-			output_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
+			output_open_statement(mm_strdup(ptr->command), 0, ECPGst_normal);
 			ptr->opened = true;
 		}
 	}
 	| ECPGSetAutocommit
 	{
 		fprintf(yyout, "{ ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
 		whenever_action(2);
 		free($1);
 	}
 	| ECPGSetConnection
@@ -183,20 +267,30 @@ ECPG: stmtViewStmt rule
 	| ECPGWhenever
 	{
 		if (connection)
 			mmerror(PARSE_ERROR, ET_ERROR, "AT option not allowed in WHENEVER statement");
 
 		output_simple_statement($1);
 	}
 ECPG: where_or_current_clauseWHERECURRENT_POFcursor_name block
 	{
 		char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
+		struct cursor *ptr;
+
+		for (ptr = cur; ptr != NULL; ptr = ptr->next)
+		{
+			if (strcmp(ptr->name, $4) == 0)
+				break;
+		}
+		if (!ptr)
+			mmfatal(PARSE_ERROR, "cursor \"%s\" does not exist", $4);
+
 		$$ = cat_str(2,mm_strdup("where current of"), cursor_marker);
 	}
 ECPG: CopyStmtCOPYopt_binaryqualified_nameopt_column_listopt_oidscopy_fromopt_programcopy_file_namecopy_delimiteropt_withcopy_options addon
 			if (strcmp($6, "from") == 0 &&
 			   (strcmp($7, "stdin") == 0 || strcmp($7, "stdout") == 0))
 				mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
 ECPG: var_valueNumericOnly addon
 		if ($1[0] == '$')
 		{
 			free($1);
@@ -255,27 +349,33 @@ ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
 		if ($4[0] == ':')
 		{
 			free($4);
 			$4 = mm_strdup("$0");
 		}
 		if ($2[0] == '$')
 		{
 			free($2);
 			$2 = mm_strdup("$0");
 		}
-ECPG: cursor_namename rule
+ECPG: cursor_namename block
+		{
+			current_cursor = mm_strdup($1);
+			current_cursor_vartype = ECPGt_const;
+			$$ = $1;
+		}
 	| char_civar
 		{
 			char *curname = mm_alloc(strlen($1) + 2);
 			sprintf(curname, ":%s", $1);
 			free($1);
 			$1 = curname;
+			current_cursor = mm_strdup(curname);
 			$$ = $1;
 		}
 ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
 	{
 		$$.name = $2;
 		$$.type = $3;
 		$$.stmt = cat_str(3, mm_strdup("\""), $5, mm_strdup("\""));
 	}
 	| PREPARE prepared_name FROM execstring
 	{
@@ -303,20 +403,22 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
 			}
 		}
 
 		this = (struct cursor *) mm_alloc(sizeof(struct cursor));
 
 		this->next = cur;
 		this->name = $2;
 		this->function = (current_function ? mm_strdup(current_function) : NULL);
 		this->connection = connection;
 		this->opened = false;
+		this->with_hold = (strncmp($5, "with ", 5) == 0);
+		this->vartype = current_cursor_vartype;
 		this->command =  cat_str(7, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for"), $7);
 		this->argsinsert = argsinsert;
 		this->argsinsert_oos = NULL;
 		this->argsresult = argsresult;
 		this->argsresult_oos = NULL;
 		argsinsert = argsresult = NULL;
 		cur = this;
 
 		c1 = mm_strdup(this->command);
 		if ((c2 = strstr(c1, "*/")) != NULL)
diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header
index 64e7600..eb3511c 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -28,20 +28,25 @@
  * internally.
  */
 #define bison_gettext_dummy gettext_noop("syntax error")
 
 /*
  * Variables containing simple states.
  */
 int struct_level = 0;
 int braces_open; /* brace level counter */
 char *current_function;
+char *current_cursor = NULL;
+bool transact_prepared = false;
+bool transact_start = false;
+bool transact_rollback = false;
+char *transact_name = NULL;
 int ecpg_internal_var = 0;
 char	*connection = NULL;
 char	*input_filename = NULL;
 
 static int	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];
@@ -119,20 +124,39 @@ mmfatal(int error_code, const char *error, ...)
 		fclose(yyin);
 	if (yyout)
 		fclose(yyout);
 
 	if (strcmp(output_filename, "-") != 0 && unlink(output_filename) != 0)
 		fprintf(stderr, _("could not remove output file \"%s\"\n"), output_filename);
 	exit(error_code);
 }
 
 /*
+ * Find a cursor
+ */
+struct cursor *
+get_cursor(const char *curname)
+{
+	int (* strcmp_fn)(const char *, const char *) = ((curname[0] == ':' || curname[0] == '"') ? strcmp : pg_strcasecmp);
+	struct cursor *ptr;
+
+	for (ptr = cur; ptr != NULL; ptr = ptr->next)
+	{
+		if (strcmp_fn(ptr->name, curname) == 0)
+			break;
+	}
+	if (!ptr)
+		mmfatal(PARSE_ERROR, "cursor \"%s\" does not exist", curname);
+	return ptr;
+}
+
+/*
  * string concatenation
  */
 
 static char *
 cat2_str(char *str1, char *str2)
 {
 	char * res_str	= (char *)mm_alloc(strlen(str1) + strlen(str2) + 2);
 
 	strcpy(res_str, str1);
 	if (strlen(str1) != 0 && strlen(str2) != 0)
diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 3b6d1e5..de77ece 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -308,20 +308,23 @@ ECPGCursorStmt:  DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared
 				}
 			}
 
 			this = (struct cursor *) mm_alloc(sizeof(struct cursor));
 
 			/* initial definition */
 			this->next = cur;
 			this->name = $2;
 			this->function = (current_function ? mm_strdup(current_function) : NULL);
 			this->connection = connection;
+			this->opened = false;
+			this->with_hold = (strncmp($5, "with ", 5) == 0);
+			this->vartype = current_cursor_vartype;
 			this->command =  cat_str(6, mm_strdup("declare"), cursor_marker, $3, mm_strdup("cursor"), $5, mm_strdup("for $1"));
 			this->argsresult = NULL;
 			this->argsresult_oos = NULL;
 
 			thisquery->type = &ecpg_query;
 			thisquery->brace_level = 0;
 			thisquery->next = NULL;
 			thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(, , __LINE__)") + strlen(con) + strlen($7));
 			sprintf(thisquery->name, "ECPGprepared_statement(%s, %s, __LINE__)", con, $7);
 
@@ -1655,21 +1658,26 @@ civarind: cvariable indicator
 			add_variable_to_head(&argsinsert, find_variable($1), find_variable($2));
 			$$ = create_questionmarks($1, false);
 		}
 		;
 
 char_civar: char_variable
 		{
 			char *ptr = strstr($1, ".arr");
 
 			if (ptr) /* varchar, we need the struct name here, not the struct element */
+			{
 				*ptr = '\0';
+				current_cursor_vartype = ECPGt_varchar;
+			}
+			else
+				current_cursor_vartype = ECPGt_char;
 			add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
 			$$ = $1;
 		}
 		;
 
 civar: cvariable
 		{
 			add_variable_to_head(&argsinsert, find_variable($1), &no_indicator);
 			$$ = create_questionmarks($1, false);
 		}
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index 3bbb6a4..f3d39ce 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -23,20 +23,22 @@ extern bool autocommit,
 			system_includes,
 			force_indicator,
 			questionmarks,
 			regression_mode,
 			auto_prepare;
 extern int	braces_open,
 			ret_value,
 			struct_level,
 			ecpg_internal_var;
 extern char *current_function;
+extern char *current_cursor;
+enum ECPGttype current_cursor_vartype;
 extern char *descriptor_index;
 extern char *descriptor_name;
 extern char *connection;
 extern char *input_filename;
 extern char *yytext,
 		   *token_start;
 
 #ifdef YYDEBUG
 extern int	yydebug;
 #endif
@@ -60,20 +62,24 @@ extern struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH];
 
 /* functions */
 
 extern const char *get_dtype(enum ECPGdtype);
 extern void lex_init(void);
 extern void output_line_number(void);
 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 void output_open_statement(char *, int, enum ECPG_statement_type);
+extern void output_fetch_statement(char *, int, enum ECPG_statement_type);
+extern void output_cursor_dml_statement(char *, int, enum ECPG_statement_type);
+extern void output_close_statement(char *, int, enum ECPG_statement_type);
 extern char *hashline_number(void);
 extern int	base_yyparse(void);
 extern int	base_yylex(void);
 extern void base_yyerror(const char *);
 extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
 extern char *mm_strdup(const char *);
 extern void mmerror(int errorcode, enum errortype type, const char *error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 extern void mmfatal(int errorcode, const char *error, ...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3),noreturn));
 extern void output_get_descr_header(char *);
 extern void output_get_descr(char *, char *);
@@ -97,20 +103,21 @@ extern void reset_variables(void);
 extern void check_indicator(struct ECPGtype *);
 extern void remove_typedefs(int);
 extern void remove_variables(int);
 extern struct variable *new_variable(const char *, struct ECPGtype *, int);
 extern const ScanKeyword *ScanCKeywordLookup(const char *);
 extern const ScanKeyword *ScanECPGKeywordLookup(const char *text);
 extern void scanner_init(const char *);
 extern void parser_init(void);
 extern void scanner_finish(void);
 extern int	filtered_base_yylex(void);
+extern struct cursor *get_cursor(const char *);
 
 /* return codes */
 
 #define ILLEGAL_OPTION		1
 #define NO_INCLUDE_FILE		2
 #define PARSE_ERROR			3
 #define INDICATOR_NOT_ARRAY 4
 #define OUT_OF_MEMORY		5
 #define INDICATOR_NOT_STRUCT	6
 #define INDICATOR_NOT_SIMPLE	7
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 007c07c..a49b89c 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -118,24 +118,42 @@ hashline_number(void)
 	return EMPTY;
 }
 
 static char *ecpg_statement_type_name[] = {
 	"ECPGst_normal",
 	"ECPGst_execute",
 	"ECPGst_exec_immediate",
 	"ECPGst_prepnormal"
 };
 
-void
-output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+static void output_cursor_name(struct cursor *ptr)
+{
+	if (current_cursor[0] == ':')
+	{
+		char *curname = current_cursor + 1;
+
+		fputs(curname, yyout);
+		if (ptr->vartype == ECPGt_varchar)
+			fputs(".arr", yyout);
+		fputs(", ", yyout);
+	}
+	else
+	{
+		fputs("\"", yyout);
+		output_escaped_str(current_cursor, false);
+		fputs("\", ", yyout);
+	}
+}
+
+static void
+output_statement_epilogue(char *stmt, int whenever_mode, enum ECPG_statement_type st)
 {
-	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
 	if (st == ECPGst_execute || st == ECPGst_exec_immediate)
 	{
 		fprintf(yyout, "%s, %s, ", ecpg_statement_type_name[st], stmt);
 	}
 	else
 	{
 		if (st == ECPGst_prepnormal && auto_prepare)
 			fputs("ECPGst_prepnormal, \"", yyout);
 		else
 			fputs("ECPGst_normal, \"", yyout);
@@ -146,25 +164,37 @@ output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
 
 	/* dump variables to C file */
 	dump_variables(argsinsert, 1);
 	fputs("ECPGt_EOIT, ", yyout);
 	dump_variables(argsresult, 1);
 	fputs("ECPGt_EORT);", yyout);
 	reset_variables();
 
 	whenever_action(whenever_mode | 2);
 	free(stmt);
+	if (current_cursor)
+	{
+		free(current_cursor);
+		current_cursor = NULL;
+	}
 	if (connection != NULL)
 		free(connection);
 }
 
 void
+output_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+{
+	fprintf(yyout, "{ ECPGdo(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	output_statement_epilogue(stmt, whenever_mode, st);
+}
+
+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)
@@ -184,20 +214,60 @@ output_deallocate_prepare_statement(char *name)
 	}
 	else
 		fprintf(yyout, "{ ECPGdeallocate_all(__LINE__, %d, %s);", compat, con);
 
 	whenever_action(2);
 	free(name);
 	if (connection != NULL)
 		free(connection);
 }
 
+void
+output_open_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+{
+	struct cursor *ptr = get_cursor(current_cursor);
+
+	fprintf(yyout, "{ ECPGopen(__LINE__, %d, %d, %s, %d, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks, ptr->with_hold);
+	output_cursor_name(ptr);
+	output_statement_epilogue(stmt, whenever_mode, st);
+}
+
+void
+output_fetch_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+{
+	struct cursor *ptr = get_cursor(current_cursor);
+
+	fprintf(yyout, "{ ECPGfetch(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	output_cursor_name(ptr);
+	output_statement_epilogue(stmt, whenever_mode, st);
+}
+
+void
+output_cursor_dml_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+{
+	struct cursor *ptr = get_cursor(current_cursor);
+
+	fprintf(yyout, "{ ECPGcursor_dml(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	output_cursor_name(ptr);
+	output_statement_epilogue(stmt, whenever_mode, st);
+}
+
+void
+output_close_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
+{
+	struct cursor *ptr = get_cursor(current_cursor);
+
+	fprintf(yyout, "{ ECPGclose(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	output_cursor_name(ptr);
+	output_statement_epilogue(stmt, whenever_mode, st);
+}
+
 static void
 output_escaped_str(char *str, bool quoted)
 {
 	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 */
 	{
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index cd0d1da..a293e9e 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -122,20 +122,22 @@ struct _include_path
 	struct _include_path *next;
 };
 
 struct cursor
 {
 	char	   *name;
 	char	   *function;
 	char	   *command;
 	char	   *connection;
 	bool		opened;
+	bool		with_hold;
+	enum ECPGttype	vartype;
 	struct arguments *argsinsert;
 	struct arguments *argsinsert_oos;
 	struct arguments *argsresult;
 	struct arguments *argsresult_oos;
 	struct cursor *next;
 };
 
 struct typedefs
 {
 	char	   *name;
diff --git a/src/interfaces/ecpg/test/ecpg_schedule b/src/interfaces/ecpg/test/ecpg_schedule
index c3ec125..033f63a 100644
--- a/src/interfaces/ecpg/test/ecpg_schedule
+++ b/src/interfaces/ecpg/test/ecpg_schedule
@@ -25,20 +25,21 @@ test: preproc/define
 test: preproc/init
 test: preproc/strings
 test: preproc/type
 test: preproc/variable
 test: preproc/outofscope
 test: preproc/whenever
 test: sql/array
 test: sql/binary
 test: sql/code100
 test: sql/copystdout
+test: sql/cursorsubxact
 test: sql/define
 test: sql/desc
 test: sql/sqlda
 test: sql/describe
 test: sql/dynalloc
 test: sql/dynalloc2
 test: sql/dyntest
 test: sql/execute
 test: sql/fetch
 test: sql/func
diff --git a/src/interfaces/ecpg/test/ecpg_schedule_tcp b/src/interfaces/ecpg/test/ecpg_schedule_tcp
index 77481b5..26a4bae 100644
--- a/src/interfaces/ecpg/test/ecpg_schedule_tcp
+++ b/src/interfaces/ecpg/test/ecpg_schedule_tcp
@@ -24,20 +24,21 @@ test: preproc/define
 test: preproc/init
 test: preproc/strings
 test: preproc/type
 test: preproc/variable
 test: preproc/outofscope
 test: preproc/whenever
 test: sql/array
 test: sql/binary
 test: sql/code100
 test: sql/copystdout
+test: sql/cursorsubxact
 test: sql/define
 test: sql/desc
 test: sql/sqlda
 test: sql/describe
 test: sql/dynalloc
 test: sql/dynalloc2
 test: sql/dyntest
 test: sql/execute
 test: sql/fetch
 test: sql/func
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-describe.c b/src/interfaces/ecpg/test/expected/compat_informix-describe.c
index 59002fb..c0e083c 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-describe.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-describe.c
@@ -128,21 +128,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 38 "describe.pgc"
 
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into descr_t1 ( id , t ) values ( default , 'd' )", ECPGt_EOIT, ECPGt_EORT);
 #line 39 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 39 "describe.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 42 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 42 "describe.pgc"
 
 
 	/*
 	 * Test DESCRIBE with a query producing tuples.
 	 * DESCRIPTOR and SQL DESCRIPTOR are NOT the same in
 	 * Informix-compat mode.
@@ -441,21 +441,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table descr_t1", ECPGt_EOIT, ECPGt_EORT);
 #line 190 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 190 "describe.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 193 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 193 "describe.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 196 "describe.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
index e90a291..f164c3f 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-rnull.c
@@ -104,21 +104,21 @@ int main(void)
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 29 "rnull.pgc"
 
 
 	{ ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "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 ( );}
 #line 33 "rnull.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 34 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 34 "rnull.pgc"
 
 
 	{ ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "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), 
@@ -131,21 +131,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_long,&(l),(long)1,(long)1,sizeof(long), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_double,&(dbl),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 38 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 38 "rnull.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 39 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 39 "rnull.pgc"
 
 
 	rsetnull(CCHARTYPE, (char *) c);
 	rsetnull(CSHORTTYPE, (char *) &s);
 	rsetnull(CINTTYPE, (char *) &i);
 	rsetnull(CBOOLTYPE, (char *) &b);
@@ -175,21 +175,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_date,&(dat),(long)1,(long)1,sizeof(date), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_timestamp,&(tmp),(long)1,(long)1,sizeof(timestamp), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 54 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 54 "rnull.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 55 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 55 "rnull.pgc"
 
 
 	printf("first select\n");
 
 	{ ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "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), 
@@ -268,21 +268,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	test_null(CDECIMALTYPE, (char *) &dec);
 	test_null(CDATETYPE, (char *) &dat);
 	test_null(CDTIMETYPE, (char *) &tmp);
 
 	{ ECPGdo(__LINE__, 1, 0, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 91 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 91 "rnull.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 92 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 92 "rnull.pgc"
 
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 94 "rnull.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
index a013be9..e47b373 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
@@ -209,21 +209,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "insert");
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
 #line 85 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 85 "sqlda.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 88 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 88 "sqlda.pgc"
 
 
 	/* SQLDA test for getting all records from a table */
 
 	outp_sqlda = NULL;
 
@@ -234,59 +234,59 @@ if (sqlca.sqlcode < 0) exit (1);}
 if (sqlca.sqlcode < 0) exit (1);}
 #line 95 "sqlda.pgc"
 
 
 	strcpy(msg, "declare");
 	ECPG_informix_reset_sqlca(); /* declare mycur1 cursor for $1 */
 #line 98 "sqlda.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "mycur1", ECPGst_normal, "declare mycur1 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 101 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 101 "sqlda.pgc"
 
 
 	/* exec sql whenever not found  break ; */
 #line 103 "sqlda.pgc"
 
 
 	rec = 0;
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "mycur1", ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 109 "sqlda.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 109 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 109 "sqlda.pgc"
 
 
 		printf("FETCH RECORD %d\n", ++rec);
 		dump_sqlda(outp_sqlda);
 	}
 
 	/* exec sql whenever not found  continue ; */
 #line 115 "sqlda.pgc"
 
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 1, 1, NULL, 0, "mycur1", ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
 #line 118 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 118 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 1, NULL, "st_id1");
 #line 121 "sqlda.pgc"
 
@@ -309,59 +309,59 @@ if (sqlca.sqlcode < 0) exit (1);}
 if (sqlca.sqlcode < 0) exit (1);}
 #line 132 "sqlda.pgc"
 
 
 	strcpy(msg, "declare");
 	ECPG_informix_reset_sqlca(); /* declare mycur2 cursor for $1 */
 #line 135 "sqlda.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "mycur2", ECPGst_normal, "declare mycur2 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 138 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 138 "sqlda.pgc"
 
 
 	/* exec sql whenever not found  break ; */
 #line 140 "sqlda.pgc"
 
 
 	rec = 0;
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch from mycur2", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "mycur2", ECPGst_normal, "fetch from mycur2", ECPGt_EOIT, 
 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 146 "sqlda.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 146 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 146 "sqlda.pgc"
 
 
 		printf("FETCH RECORD %d\n", ++rec);
 		dump_sqlda(outp_sqlda);
 	}
 
 	/* exec sql whenever not found  continue ; */
 #line 152 "sqlda.pgc"
 
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 1, 1, NULL, 0, "mycur2", ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
 #line 155 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 155 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 1, NULL, "st_id2");
 #line 158 "sqlda.pgc"
 
@@ -466,21 +466,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 221 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 221 "sqlda.pgc"
 
 
 	dump_sqlda(outp_sqlda);
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, "con2", "commit");
+	{ ECPGtrans(__LINE__, "con2", "commit", 0, 0, 0, NULL);
 #line 226 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 226 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 1, NULL, "st_id4");
 #line 229 "sqlda.pgc"
 
@@ -504,21 +504,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
 #line 241 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 241 "sqlda.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 244 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 244 "sqlda.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 247 "sqlda.pgc"
 
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 d357c77..f88f9f2 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
@@ -73,99 +73,99 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
 	/* this INSERT works */
 	rsetnull(CDECIMALTYPE, (char *)&j);
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , $1  , 'test   ' )", 
 	ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 28 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 28 "test_informix.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 29 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 29 "test_informix.pgc"
 
 
 	/* this INSERT should fail because i is a unique column */
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , 12 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
 #line 32 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 32 "test_informix.pgc"
 
 	printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
-	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
+	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 34 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 34 "test_informix.pgc"
 
 
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( $1  , 1 , 'a      ' )", 
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 36 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 36 "test_informix.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 37 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 37 "test_informix.pgc"
 
 
 	/* this will fail (more than one row in subquery) */
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test )", ECPGt_EOIT, ECPGt_EORT);
 #line 40 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 40 "test_informix.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 41 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 41 "test_informix.pgc"
 
 
 	/* this however should be ok */
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test order by i limit 1 )", ECPGt_EOIT, ECPGt_EORT);
 #line 44 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 44 "test_informix.pgc"
 
 	printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
-	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
+	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 46 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 46 "test_informix.pgc"
 
 
 	sqlca.sqlcode = 100;
 	ECPGset_var( 0, &( i ), __LINE__);\
  ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1  */
 #line 49 "test_informix.pgc"
 
 	printf ("%ld\n", sqlca.sqlcode);
 	openit();
 
 	deccvint(0, &j);
 
 	while (1)
 	{
-		{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "c", ECPGst_normal, "fetch forward 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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 57 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 57 "test_informix.pgc"
@@ -206,50 +206,50 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
 	printf("Exists: %ld\n", sqlca.sqlcode);
 
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
 #line 81 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 81 "test_informix.pgc"
 
 	printf("Does not exist: %ld\n", sqlca.sqlcode);
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 84 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 84 "test_informix.pgc"
 
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 85 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 85 "test_informix.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 86 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 86 "test_informix.pgc"
 
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 88 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 88 "test_informix.pgc"
 
 
 	return 0;
 }
 
 static void openit(void)
 {
-	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "declare c cursor for select * from test where i <= $1 ", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "c", ECPGst_normal, "declare c cursor for select * from test where i <= $1 ", 
 	ECPGt_int,&(*( int  *)(ECPGget_var( 0))),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 95 "test_informix.pgc"
 
 if (sqlca.sqlcode < 0) dosqlprint ( );}
 #line 95 "test_informix.pgc"
 
 }
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 c1a4891..9bd62ca 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
@@ -107,21 +107,21 @@ static void sql_check(char *fn, char *caller, int ignore)
   {
     if (SQLCODE != 0)
     {
 
       sprintf(errorstring, "**SQL error %ld doing '%s' in function '%s'. [%s]",
              SQLCODE, caller, fn, sqlca.sqlerrm.sqlerrmc);
       fprintf(stderr, "%s", errorstring);
       printf("%s\n", errorstring);
 
       /* attempt a ROLLBACK */
-      { ECPGtrans(__LINE__, NULL, "rollback");}
+      { ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);}
 #line 27 "test_informix2.pgc"
 
 
       if (SQLCODE == 0)
       {
         sprintf(errorstring, "Rollback successful.\n");
       } else {
         sprintf(errorstring, "Rollback failed with code %ld.\n", SQLCODE);
       }
 
@@ -238,36 +238,36 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_timestamp,&(e),(long)1,(long)1,sizeof(timestamp), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 97 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 97 "test_informix2.pgc"
 
 	sql_check("main", "update", 0);
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 100 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 100 "test_informix2.pgc"
 
 
 	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table history", ECPGt_EOIT, ECPGt_EORT);
 #line 102 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 102 "test_informix2.pgc"
 
 	sql_check("main", "drop", 0);
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 105 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 105 "test_informix2.pgc"
 
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 107 "test_informix2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
index 78f6b3d..713748e 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
@@ -429,21 +429,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
 	free(text);
 
 	in = "1234567890";
 	fmt = "%s";
 	i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
 	text = PGTYPEStimestamp_to_asc(ts1);
 	printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
 	free(text);
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 365 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 365 "dt_test.pgc"
 
         { ECPGdisconnect(__LINE__, "CURRENT");
 #line 366 "dt_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 366 "dt_test.pgc"
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
index 077c0be..715f960 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
@@ -75,29 +75,29 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into nantest1 ( id , d ) values ( 1 , 'nan' :: float8 ) , ( 2 , 'infinity' :: float8 ) , ( 3 , '-infinity' :: float8 )", ECPGt_EOIT, ECPGt_EORT);
 #line 31 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 31 "nan_test.pgc"
 
 
 	/* declare cur cursor for select id , d , d from nantest1 */
 #line 33 "nan_test.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur", ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
 #line 34 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 34 "nan_test.pgc"
 
 	while (1)
 	{
-		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_double,&(d),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 37 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 37 "nan_test.pgc"
@@ -123,55 +123,55 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 46 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 46 "nan_test.pgc"
 
 	}
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
 #line 48 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 48 "nan_test.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur", ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
 #line 50 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 50 "nan_test.pgc"
 
 	while (1)
 	{
-		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_double,&(d),(long)1,(long)1,sizeof(double), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 53 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 53 "nan_test.pgc"
 
 		if (sqlca.sqlcode)
 			break;
 		if (isinf(d))
 			printf("%d %sInf '%s'\n", id, (d < 0 ? "-" : "+"), val);
 		if (isnan(d))
 			printf("%d  NaN '%s'\n", id, val);
 	}
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
 #line 61 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 61 "nan_test.pgc"
 
 
 	num = PGTYPESnumeric_new();
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table nantest2 ( id int4 , d numeric )", ECPGt_EOIT, ECPGt_EORT);
 #line 65 "nan_test.pgc"
@@ -214,54 +214,54 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 73 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 73 "nan_test.pgc"
 
 
 	/* declare cur1 cursor for select id , d , d from nantest2 */
 #line 75 "nan_test.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur1", ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
 #line 76 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 76 "nan_test.pgc"
 
 	while (1)
 	{
-		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "fetch from cur1", ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_numeric,&(num),(long)1,(long)0,sizeof(numeric), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(val),(long)16,(long)1,(16)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 79 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 79 "nan_test.pgc"
 
 		if (sqlca.sqlcode)
 			break;
 		printf("%d %s '%s'\n", id, (num->sign == NUMERIC_NAN ? "NaN" : "not NaN"), val);
 	}
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
 #line 84 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 84 "nan_test.pgc"
 
 
 	PGTYPESnumeric_free(num);
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 88 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 88 "nan_test.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 89 "nan_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 89 "nan_test.pgc"
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
index 6144034..c139e41 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
@@ -137,21 +137,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	value1 = PGTYPESnumeric_from_asc("2E7", NULL);
 	value2 = PGTYPESnumeric_from_asc("14", NULL);
 	i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
 	printf("to long(%d) = %ld %ld\n", i, l1, l2);
 
 	free(text);
 	PGTYPESnumeric_free(value1);
 	PGTYPESnumeric_free(value2);
 	PGTYPESnumeric_free(res);
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 93 "num_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 93 "num_test.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 94 "num_test.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 94 "num_test.pgc"
diff --git a/src/interfaces/ecpg/test/expected/preproc-autoprep.c b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
index cf5c702..8872986 100644
--- a/src/interfaces/ecpg/test/expected/preproc-autoprep.c
+++ b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
@@ -126,44 +126,44 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "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 35 "autoprep.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select Item1 from T", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select Item1 from T", ECPGt_EOIT, 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"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "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 39 "autoprep.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 39 "autoprep.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 39 "autoprep.pgc"
 
   printf("i = %d\n", i);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "close C", 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"
 
 
   { ECPGprepare(__LINE__, NULL, 0, "stmt1", sqlstr);
@@ -173,58 +173,58 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 44 "autoprep.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 44 "autoprep.pgc"
 
 
   /* declare cur1 cursor for $1 */
 #line 46 "autoprep.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur1 cursor for $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur1", ECPGst_normal, "declare cur1 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 48 "autoprep.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 48 "autoprep.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 48 "autoprep.pgc"
 
 
   /* exec sql whenever not found  break ; */
 #line 50 "autoprep.pgc"
 
 
   i = 0;
   while (1)
   {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "fetch cur1", ECPGt_EOIT, 
 	ECPGt_int,&(item1),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&(ind1),(long)1,(long)1,sizeof(int), ECPGt_EORT);
 #line 55 "autoprep.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 55 "autoprep.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 55 "autoprep.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 55 "autoprep.pgc"
 
 	printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
 	i++;
   }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "close cur1", ECPGt_EOIT, ECPGt_EORT);
 #line 60 "autoprep.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 60 "autoprep.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 60 "autoprep.pgc"
 
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table T", ECPGt_EOIT, ECPGt_EORT);
diff --git a/src/interfaces/ecpg/test/expected/preproc-cursor.c b/src/interfaces/ecpg/test/expected/preproc-cursor.c
index 150fc9a..6f92797 100644
--- a/src/interfaces/ecpg/test/expected/preproc-cursor.c
+++ b/src/interfaces/ecpg/test/expected/preproc-cursor.c
@@ -158,303 +158,303 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 53 "cursor.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, "test2", 0, ECPGst_normal, "insert into t1 ( id , t ) values ( default , 'e' )", ECPGt_EOIT, ECPGt_EORT);
 #line 54 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 54 "cursor.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, "test1", "commit");
+	{ ECPGtrans(__LINE__, "test1", "commit", 0, 0, 0, NULL);
 #line 57 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 57 "cursor.pgc"
 
-	{ ECPGtrans(__LINE__, "test2", "commit");
+	{ ECPGtrans(__LINE__, "test2", "commit", 0, 0, 0, NULL);
 #line 58 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 58 "cursor.pgc"
 
 
 	/* Dynamic cursorname test with INTO list in FETCH stmts */
 
 	strcpy(msg, "declare");
 	ECPGset_var( 0, &( curname1 ), __LINE__);\
  /* declare $0 cursor for select id , t from t1 */
 #line 64 "cursor.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname1, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 67 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 67 "cursor.pgc"
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch forward from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch forward from $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 70 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 70 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch forward $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch forward $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 74 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 74 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch 1 from $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 78 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 78 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch $0 from $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 83 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 83 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move in");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "move absolute 0 in $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "move absolute 0 in $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 87 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 87 "cursor.pgc"
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch 1 $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 90 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 90 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch $0 $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 95 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 95 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "close $0", 
+	{ ECPGclose(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "close $0", 
 	ECPGt_char,&(curname1),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 99 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 99 "cursor.pgc"
 
 
 	/* Dynamic cursorname test with INTO list in DECLARE stmt */
 
 	strcpy(msg, "declare");
 	ECPGset_var( 1, &( curname2 ), __LINE__);\
  ECPGset_var( 2, ( t ), __LINE__);\
  ECPGset_var( 3, &( id ), __LINE__);\
  /* declare $0 cursor for select id , t from t1 */
 #line 105 "cursor.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname2, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 108 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 108 "cursor.pgc"
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch from $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 111 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 111 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 115 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 115 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch 1 from $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 119 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 119 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0 from $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 124 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 124 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "move absolute 0 $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 128 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 128 "cursor.pgc"
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch 1 $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 131 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 131 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0 $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 136 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 136 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "close $0", 
+	{ ECPGclose(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "close $0", 
 	ECPGt_char,&(curname2),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 140 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 140 "cursor.pgc"
 
 
 	/* Dynamic cursorname test with PREPARED stmt */
 
@@ -476,157 +476,157 @@ if (sqlca.sqlcode < 0) exit (1);}
 	ECPGset_var( 4, &( curname3 ), __LINE__);\
  /* declare $0 cursor for $1 */
 #line 149 "cursor.pgc"
 
 	ECPGset_var( 5, &( curname5 ), __LINE__);\
  /* declare $0 cursor for $1 */
 #line 150 "cursor.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname3, ECPGst_normal, "declare $0 cursor for $1", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char_variable,(ECPGprepared_statement("test1", "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 153 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 153 "cursor.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, "test2", 0, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test2", 0, 0, curname5, ECPGst_normal, "declare $0 cursor for $1", 
 	ECPGt_char,&(curname5),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char_variable,(ECPGprepared_statement("test2", "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 154 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 154 "cursor.pgc"
 
 
 	strcpy(msg, "fetch");
-	{ ECPGdo(__LINE__, 0, 1, "test2", 0, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test2", 0, curname5, ECPGst_normal, "fetch $0", 
 	ECPGt_char,&(curname5),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 157 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 157 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch from $0", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 161 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 161 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch 1 from $0", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 165 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 165 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch $0 from $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 170 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 170 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "move absolute 0 $0", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 174 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 174 "cursor.pgc"
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch 1 $0", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 177 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 177 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch $0 $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 182 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 182 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "close $0", 
+	{ ECPGclose(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "close $0", 
 	ECPGt_char,&(curname3),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 186 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 186 "cursor.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, "test2", 0, ECPGst_normal, "close $0", 
+	{ ECPGclose(__LINE__, 0, 1, "test2", 0, curname5, ECPGst_normal, "close $0", 
 	ECPGt_char,&(curname5),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 187 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 187 "cursor.pgc"
 
 
 	strcpy(msg, "deallocate prepare");
 	{ ECPGdeallocate(__LINE__, 0, "test1", "st_id1");
@@ -656,139 +656,139 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 200 "cursor.pgc"
 
 
 	strcpy(msg, "declare");
 	ECPGset_var( 6, &( curname4 ), __LINE__);\
  /* declare $0 cursor for $1 */
 #line 203 "cursor.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname4.arr, ECPGst_normal, "declare $0 cursor for $1", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char_variable,(ECPGprepared_statement("test1", "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 206 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 206 "cursor.pgc"
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch from $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 209 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 209 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 213 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 213 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch 1 from $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 217 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 217 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0 from $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 222 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 222 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "move absolute 0 $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 226 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 226 "cursor.pgc"
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch 1 $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 229 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 229 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0 $0", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
 	ECPGt_int,&(id),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(t),(long)64,(long)1,(64)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 234 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 234 "cursor.pgc"
 
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, "test1", 0, ECPGst_normal, "close $0", 
+	{ ECPGclose(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "close $0", 
 	ECPGt_varchar,&(curname4),(long)50,(long)1,sizeof(struct varchar_1), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 238 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 238 "cursor.pgc"
 
 
 	strcpy(msg, "deallocate prepare");
 	{ ECPGdeallocate(__LINE__, 0, "test1", "st_id2");
@@ -808,21 +808,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 246 "cursor.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, "test2", 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
 #line 247 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 247 "cursor.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, "test1", "commit");
+	{ ECPGtrans(__LINE__, "test1", "commit", 0, 0, 0, NULL);
 #line 250 "cursor.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 250 "cursor.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "ALL");
 #line 253 "cursor.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/preproc-define.c b/src/interfaces/ecpg/test/expected/preproc-define.c
index 43df19c..4151571 100644
--- a/src/interfaces/ecpg/test/expected/preproc-define.c
+++ b/src/interfaces/ecpg/test/expected/preproc-define.c
@@ -76,40 +76,40 @@ main(void)
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 34 "define.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
 #line 36 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 36 "define.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 37 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "define.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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, 0, ECPGst_normal, "insert into test ( name , amount , letter ) values ( 'true' , 2 , 't' )", ECPGt_EOIT, ECPGt_EORT);
 #line 40 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 40 "define.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 41 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 41 "define.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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), 
@@ -144,21 +144,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 		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, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 57 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 57 "define.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 58 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 58 "define.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 59 "define.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 59 "define.pgc"
diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.c b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
index 475f6e7..a23522b 100644
--- a/src/interfaces/ecpg/test/expected/preproc-outofscope.c
+++ b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
@@ -194,21 +194,21 @@ get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
 	if (sqlca.sqlcode != 0)
 		exit(1);
 
 	*myvar0 = myvar;
 	*mynullvar0 = mynullvar;
 }
 
 static void
 open_cur1(void)
 {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur", ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
 	ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
@@ -218,21 +218,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 40 "outofscope.pgc"
 
 
 	if (sqlca.sqlcode != 0)
 		exit(1);
 }
 
 static void
 get_record1(void)
 {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur", ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
 	ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).t),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d1),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d1),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_double,&((*( MYTYPE  *)(ECPGget_var( 0)) ).d2),(long)1,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).d2),(long)1,(long)1,sizeof( struct mynulltype ), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).c),(long)30,(long)1,sizeof( struct mytype ), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).c),(long)1,(long)1,sizeof( struct mynulltype ), ECPGt_EORT);
@@ -242,21 +242,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 49 "outofscope.pgc"
 
 
 	if (sqlca.sqlcode != 0 && sqlca.sqlcode != ECPG_NOT_FOUND)
 		exit(1);
 }
 
 static void
 close_cur1(void)
 {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "mycur", ECPGst_normal, "close mycur", ECPGt_EOIT, ECPGt_EORT);
 #line 58 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 58 "outofscope.pgc"
 
 
 	if (sqlca.sqlcode != 0)
 		exit(1);
 }
 
@@ -308,21 +308,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 85 "outofscope.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into a1 ( id , t , d1 , d2 , c ) values ( default , 'b' , 2.0 , 3 , 'b' )", ECPGt_EOIT, ECPGt_EORT);
 #line 86 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 86 "outofscope.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 89 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 89 "outofscope.pgc"
 
 
 	/* Test out-of-scope DECLARE/OPEN/FETCH/CLOSE */
 
 	get_var1(&myvar, &mynullvar);
 	open_cur1();
@@ -352,21 +352,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table a1", ECPGt_EOIT, ECPGt_EORT);
 #line 118 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 118 "outofscope.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 121 "outofscope.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 121 "outofscope.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 124 "outofscope.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/preproc-variable.c b/src/interfaces/ecpg/test/expected/preproc-variable.c
index a93af97..7d6d0d3 100644
--- a/src/interfaces/ecpg/test/expected/preproc-variable.c
+++ b/src/interfaces/ecpg/test/expected/preproc-variable.c
@@ -175,45 +175,45 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 56 "variable.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into family ( name , age ) values ( 'Child 3' , 9 )", ECPGt_EOIT, ECPGt_EORT);
 #line 57 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 57 "variable.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 60 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 60 "variable.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur", ECPGst_normal, "declare cur cursor for select name , born , age , married , children from family", ECPGt_EOIT, ECPGt_EORT);
 #line 63 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 63 "variable.pgc"
 
 
 	/* exec sql whenever not found  break ; */
 #line 65 "variable.pgc"
 
 
 	p=&personal;
 	i=&ind_personal;
 	memset(i, 0, sizeof(ind_personal));
 	while (1) {
 		strcpy(msg, "fetch");
-		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch cur", ECPGt_EOIT, 
 	ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ), 
 	ECPGt_int,&(i->ind_name),(long)1,(long)-1,sizeof( struct birthinfo ), 
 	ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof( struct birthinfo ), 
 	ECPGt_long,&(i->ind_birth.born),(long)1,(long)1,sizeof( struct birthinfo ), 
 	ECPGt_short,&(p->birth.age),(long)1,(long)1,sizeof( struct birthinfo ), 
 	ECPGt_short,&(i->ind_birth.age),(long)1,(long)1,sizeof( struct birthinfo ), 
 	ECPGt_char,&(married),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_long,&(ind_married),(long)1,(long)1,sizeof(long), 
 	ECPGt_int,&(children.integer),(long)1,(long)1,sizeof(int), 
 	ECPGt_short,&(ind_children.smallint),(long)1,(long)1,sizeof(short), ECPGt_EORT);
@@ -234,37 +234,37 @@ if (sqlca.sqlcode < 0) exit (1);}
 			printf(", married %s", married);
 		if (ind_children.smallint >= 0)
 			printf(", children = %d", children.integer);
 		putchar('\n');
 
 		free(married);
 		married = NULL;
 	}
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "close cur", ECPGt_EOIT, ECPGt_EORT);
 #line 89 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 89 "variable.pgc"
 
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table family", ECPGt_EOIT, ECPGt_EORT);
 #line 92 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 92 "variable.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 95 "variable.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 95 "variable.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 98 "variable.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/preproc-whenever.c b/src/interfaces/ecpg/test/expected/preproc-whenever.c
index 03f596a..d07171b 100644
--- a/src/interfaces/ecpg/test/expected/preproc-whenever.c
+++ b/src/interfaces/ecpg/test/expected/preproc-whenever.c
@@ -86,42 +86,42 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	ECPGt_char,(c),(long)6,(long)1,(6)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 36 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 36 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 36 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 37 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 37 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "whenever.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 39 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 39 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 40 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 40 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 40 "whenever.pgc"
 
 
 	/* exec sql whenever sqlerror  do print ( \"select\" ) ; */
@@ -131,21 +131,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 43 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 43 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) print ( "select" );}
 #line 43 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 44 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 44 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) print ( "select" );}
 #line 44 "whenever.pgc"
 
 
 	/* exec sql whenever sqlerror  call print2 ( ) ; */
@@ -155,42 +155,42 @@ if (sqlca.sqlcode < 0) print ( "select" );}
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 47 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 47 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) print2 ( );}
 #line 47 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 48 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 48 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) print2 ( );}
 #line 48 "whenever.pgc"
 
 
 	/* exec sql whenever sqlerror  continue ; */
 #line 50 "whenever.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );}
 #line 51 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 52 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );}
 #line 52 "whenever.pgc"
 
 
 	/* exec sql whenever sqlerror  goto  error ; */
 #line 54 "whenever.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from nonexistant", ECPGt_EOIT, 
@@ -200,21 +200,21 @@ if (sqlca.sqlwarn[0] == 'W') warn ( );}
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 55 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) goto error;}
 #line 55 "whenever.pgc"
 
 	printf("Should not be reachable\n");
 
 	error:
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 59 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 59 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) goto error;}
 #line 59 "whenever.pgc"
 
 
 	/* exec sql whenever sqlerror  stop ; */
@@ -226,21 +226,21 @@ if (sqlca.sqlcode < 0) goto error;}
 	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 64 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 64 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 64 "whenever.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "rollback");
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 65 "whenever.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') warn ( );
 #line 65 "whenever.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 65 "whenever.pgc"
 
 	exit (0);
 }
diff --git a/src/interfaces/ecpg/test/expected/sql-array.c b/src/interfaces/ecpg/test/expected/sql-array.c
index 3c87956..f770c09 100644
--- a/src/interfaces/ecpg/test/expected/sql-array.c
+++ b/src/interfaces/ecpg/test/expected/sql-array.c
@@ -141,21 +141,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 27 "array.pgc"
 
 
 	{ ECPGsetcommit(__LINE__, "on", NULL);
 #line 29 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 29 "array.pgc"
 
 
-	{ ECPGtrans(__LINE__, NULL, "begin work");
+	{ ECPGtrans(__LINE__, NULL, "begin work", 0, 1, 0, NULL);
 #line 31 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 31 "array.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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();}
@@ -186,28 +186,28 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	ECPGt_int,(a),(long)1,(long)10,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,&(t),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 39 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 39 "array.pgc"
 
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 41 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 41 "array.pgc"
 
 
-	{ ECPGtrans(__LINE__, NULL, "begin work");
+	{ ECPGtrans(__LINE__, NULL, "begin work", 0, 1, 0, NULL);
 #line 43 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 43 "array.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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), 
@@ -252,21 +252,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	printf("Found text=%s\n", text);
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 70 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 70 "array.pgc"
 
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 72 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 72 "array.pgc"
 
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 74 "array.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c
index 9aa11d6..8826cca 100644
--- a/src/interfaces/ecpg/test/expected/sql-binary.c
+++ b/src/interfaces/ecpg/test/expected/sql-binary.c
@@ -104,102 +104,102 @@ main (void)
   if (sqlca.sqlcode)
     {
       printf ("insert error = %ld\n", sqlca.sqlcode);
       exit (sqlca.sqlcode);
     }
 
   ECPGset_var( 0, &( empl.idnum ), __LINE__);\
  /* declare C cursor for select name , accs , byte from empl where idnum = $1  */
 #line 58 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "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 59 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 60 "binary.pgc"
 
   if (sqlca.sqlcode)
     {
       printf ("fetch error = %ld\n", sqlca.sqlcode);
       exit (sqlca.sqlcode);
     }
 
   printf ("name=%s, accs=%d byte=%s\n", empl.name, empl.accs, empl.byte);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);}
 #line 69 "binary.pgc"
 
 
   memset(empl.name, 0, 21L);
   ECPGset_var( 1, &( empl.idnum ), __LINE__);\
  /* declare B binary cursor for select name , accs , byte from empl where idnum = $1  */
 #line 72 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "B", ECPGst_normal, "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 73 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch B", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "B", ECPGst_normal, "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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_char,(empl.byte),(long)20,(long)1,(20)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 74 "binary.pgc"
 
   if (sqlca.sqlcode)
     {
       printf ("fetch error = %ld\n", sqlca.sqlcode);
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "B", ECPGst_normal, "close B", ECPGt_EOIT, ECPGt_EORT);}
 #line 81 "binary.pgc"
 
 
   /* do not print a.accs because big/little endian will have different outputs here */
   printf ("name=%s, byte=", empl.name);
   for (i=0; i<4; i++)
 	printf("(%o)", (unsigned char)empl.byte[i]);
   printf("\n");
 
   ECPGset_var( 2, &( empl.idnum ), __LINE__);\
  /* declare A binary cursor for select byte from empl where idnum = $1  */
 #line 89 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "A", ECPGst_normal, "declare A binary cursor for select 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 90 "binary.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch A", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "A", ECPGst_normal, "fetch A", ECPGt_EOIT, 
 	ECPGt_char,&(pointer),(long)0,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
 #line 91 "binary.pgc"
 
   if (sqlca.sqlcode)
     {
       printf ("fetch error = %ld\n", sqlca.sqlcode);
       exit (sqlca.sqlcode);
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);}
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "A", ECPGst_normal, "close A", ECPGt_EOIT, ECPGt_EORT);}
 #line 98 "binary.pgc"
 
 
   printf ("pointer=");
   for (i=0; i<4; i++)
 	printf("(%o)", (unsigned char)pointer[i]);
   printf("\n");
   free(pointer);
 
   { ECPGdisconnect(__LINE__, "CURRENT");}
diff --git a/src/interfaces/ecpg/test/expected/sql-code100.c b/src/interfaces/ecpg/test/expected/sql-code100.c
index 051fc38..dda2c55 100644
--- a/src/interfaces/ecpg/test/expected/sql-code100.c
+++ b/src/interfaces/ecpg/test/expected/sql-code100.c
@@ -107,34 +107,34 @@ int main()
 
    { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 15 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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);
-   { ECPGtrans(__LINE__, NULL, "commit work");}
+   { ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 22 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
    for (index=0;index<10;++index)
    {  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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"
 
       if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
    }
-   { ECPGtrans(__LINE__, NULL, "commit work");}
+   { ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 31 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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, 0, ECPGst_normal, "delete from test where index = - 1", ECPGt_EOIT, ECPGt_EORT);}
@@ -144,21 +144,21 @@ int main()
 
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);}
 #line 44 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
-   { ECPGtrans(__LINE__, NULL, "commit work");}
+   { ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 46 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
 
    { ECPGdisconnect(__LINE__, "CURRENT");}
 #line 49 "code100.pgc"
 
    if (sqlca.sqlcode) printf("%ld:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
    return 0;
 }
diff --git a/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c
new file mode 100644
index 0000000..c13f94c
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c
@@ -0,0 +1,642 @@
+/* Processed by ecpg (regression mode) */
+/* These include files are added by the preprocessor */
+#include <ecpglib.h>
+#include <ecpgerrno.h>
+#include <sqlca.h>
+/* End of automatic include section */
+#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
+
+#line 1 "cursorsubxact.pgc"
+#include <stdlib.h>
+#include <string.h>
+
+
+#line 1 "regression.h"
+
+
+
+
+
+
+#line 4 "cursorsubxact.pgc"
+
+
+/* exec sql whenever sqlerror  sqlprint ; */
+#line 6 "cursorsubxact.pgc"
+
+
+#define CURNAME "MyCur"
+#define CURNAME_BAD "myCur"
+
+#define QUOTED_CURNAME "\"MyCur\""
+#define QUOTED_CURNAME_BAD "\"myCur\""
+
+int main(void)
+{
+/* exec sql begin declare section */
+		
+		
+		
+
+#line 17 "cursorsubxact.pgc"
+ char * curname ;
+ 
+#line 18 "cursorsubxact.pgc"
+ int id [ 4 ] ;
+ 
+#line 19 "cursorsubxact.pgc"
+  struct varchar_1  { int len; char arr[ 50 ]; }  t [ 4 ] ;
+/* exec sql end declare section */
+#line 20 "cursorsubxact.pgc"
+
+
+	ECPGdebug(1, stderr);
+
+	{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
+#line 24 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 24 "cursorsubxact.pgc"
+
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( id serial primary key , t text )", ECPGt_EOIT, ECPGt_EORT);
+#line 26 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 26 "cursorsubxact.pgc"
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 ( t ) values ( 'a' ) , ( 'b' ) , ( 'c' )", ECPGt_EOIT, ECPGt_EORT);
+#line 27 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 27 "cursorsubxact.pgc"
+
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
+#line 28 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 28 "cursorsubxact.pgc"
+
+
+	/*
+	 * Cursor name passed in a variable unquoted.
+	 * It has to be treated as case-insensitive.
+	 */
+
+	printf("test case insensitive cursor name\n\n");
+
+	curname = CURNAME;
+
+	ECPGset_var( 0, &( curname ), __LINE__);\
+ /* declare $0 cursor for select id , t from t1 */
+#line 39 "cursorsubxact.pgc"
+
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 41 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 41 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case insensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case insensitive) succeeded\n", curname);
+
+	curname = CURNAME_BAD;
+
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "close $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 49 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 49 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case insensitive)  failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case insensitive) succeeded\n", curname);
+
+	/*
+	 * Cursor name passed in a variable quoted.
+	 * It has to be treated as case-sensitive.
+	 */
+
+	printf("\ntest case sensitive cursor name\n\n");
+
+	curname = QUOTED_CURNAME;
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 64 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 64 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	curname = QUOTED_CURNAME_BAD;
+
+	/* Try to close the wrong cursor name, it has to fail with 34000. */
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "close $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 73 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 73 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	/* Try to close the right cursor name, it has to fail with 25P02 */
+	curname = QUOTED_CURNAME;
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "close $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 81 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 81 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case sensitive) failed with SQLSTATE %5s (expected 25P02)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
+#line 87 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 87 "cursorsubxact.pgc"
+
+
+	/*
+	 * Try a new transaction and watch the cursor name disappear
+	 * after ROLLBACK TO SAVEPOINT.
+	 */
+
+	printf("\ntest case sensitive cursor name in savepoint\n\n");
+
+	curname = QUOTED_CURNAME;
+
+	{ ECPGtrans(__LINE__, NULL, "savepoint a", 0, 1, 0, "a");
+#line 98 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 98 "cursorsubxact.pgc"
+
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 100 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 100 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	/*
+	 * The cursor name must be forgotten, the subsequent
+	 * CLOSE has to fail with error code 34000.
+	 */
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 110 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 110 "cursorsubxact.pgc"
+
+
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "close $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 112 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 112 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("close %s failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s succeeded unexpectedly (expected 34000)\n", curname);
+
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
+#line 118 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 118 "cursorsubxact.pgc"
+
+
+	/*
+	 * Try a new transaction and play games with savepoints.
+	 */
+
+	printf("\ntest savepoint handling\n\n");
+
+	{ ECPGtrans(__LINE__, NULL, "savepoint a", 0, 1, 0, "a");
+#line 126 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 126 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 132 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 132 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	{ ECPGtrans(__LINE__, NULL, "savepoint b", 0, 1, 0, "b");
+#line 138 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 138 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint b\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint b\" succeeded\n");
+
+	/*
+	 * Try to rollback to an unknown savepoint
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to c", 0, 0, 1, "c");
+#line 148 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 148 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to c\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to c\" succeeded unexpectedly (expected 3B001)\n");
+
+	/*
+	 * ROLLBACK TO A implicitly rolls back savepoint "B"
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 158 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 158 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * Savepoint "b" is now unknown, fails with 3B001
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to b", 0, 0, 1, "b");
+#line 168 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 168 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to b\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to b\" succeeded unexpectedly (expected 3B001)\n");
+
+	/*
+	 * ROLLBACK TO A has to succeed again, it's still alive
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 178 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 178 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * The cursor was declared under savepoint "a", was forgotten
+	 */
+
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+	ECPGt_int,&(id[0]),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_varchar,&(t[0]),(long)50,(long)1,sizeof(struct varchar_1), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 188 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 188 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) succeeded unexpectedly (expected 34000)\n", curname);
+
+	/*
+	 * ROLLBACK TO A has to succeed again, it's still alive
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 198 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 198 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * RELEASE SAVEPOINT A forgets about the savepoint name
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "release savepoint a", 0, 0, 0, "a");
+#line 208 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 208 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"release savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"release savepoint a\" succeeded\n");
+
+	/*
+	 * Prove the above
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 218 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 218 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded unexpectedly (expected 3B001)\n");
+
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
+#line 224 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 224 "cursorsubxact.pgc"
+
+
+	/*
+	 * Test the cursor's existence rolled back after
+	 * ROLLBACK TO SAVEPOINT.
+	 */
+
+	printf("\ntest implicit \"release savepoint a\" for a second \"savepoint a\"\n\n");
+
+	{ ECPGtrans(__LINE__, NULL, "savepoint a", 0, 1, 0, "a");
+#line 233 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 233 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 239 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 239 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+	ECPGt_int,&(id[0]),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_varchar,&(t[0]),(long)50,(long)1,sizeof(struct varchar_1), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 245 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 245 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) result %d '%s'\n", curname, id[0], t[0].arr);
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 251 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 251 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * There's no cursor now, fails with error code 34000
+	 */
+
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+	ECPGt_int,&(id[1]),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_varchar,&(t[1]),(long)50,(long)1,sizeof(struct varchar_1), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 261 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 261 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) unexpectedly succeeded (expected 34000)\n", curname);
+
+	/*
+	 * Try to open it again, should fail because the
+	 * transaction has failed above.
+	 */
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 272 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 272 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s (expected 25P02)\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded unexpectedly (expected 25P02)\n", curname);
+
+	/*
+	 * Test the implicit RELEASE SAVEPOINT if a SAVEPOINT
+	 * is used with an already existing name. After the
+	 * ROLLBACK TO A below, savepoint "A" still exists
+	 * as was already proven above.
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 285 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 285 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
+#line 291 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 291 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	/*
+	 * Here is the 2nd SAVEPOINT A
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "savepoint a", 0, 1, 0, "a");
+#line 301 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 301 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+	ECPGt_int,&(id[2]),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_varchar,&(t[2]),(long)50,(long)1,sizeof(struct varchar_1), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 307 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 307 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("fetch %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch %s (case sensitive) result %d '%s'\n", curname, id[2], t[2].arr);
+
+	/*
+	 * The implicit release savepoint propagated the cursor
+	 * to the toplevel transaction. It will be still accessible
+	 * after ROLLBACK TO A below.
+	 */
+
+	{ ECPGtrans(__LINE__, NULL, "rollback to a", 0, 0, 1, "a");
+#line 319 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 319 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	ECPGt_char,&(curname),(long)0,(long)1,(1)*sizeof(char), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, 
+	ECPGt_int,&(id[3]),(long)1,(long)1,sizeof(int), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
+	ECPGt_varchar,&(t[3]),(long)50,(long)1,sizeof(struct varchar_1), 
+	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
+#line 325 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 325 "cursorsubxact.pgc"
+
+	if (sqlca.sqlcode < 0)
+		printf("fetch %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch %s (case sensitive) result %d '%s'\n", curname, id[3], t[3].arr);
+
+	{ ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
+#line 331 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 331 "cursorsubxact.pgc"
+
+
+	/* Drop the test table */
+
+	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
+#line 335 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 335 "cursorsubxact.pgc"
+
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
+#line 336 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 336 "cursorsubxact.pgc"
+
+
+	{ ECPGdisconnect(__LINE__, "ALL");
+#line 338 "cursorsubxact.pgc"
+
+if (sqlca.sqlcode < 0) sqlprint();}
+#line 338 "cursorsubxact.pgc"
+
+
+	return 0;
+}
diff --git a/src/interfaces/ecpg/test/expected/sql-cursorsubxact.stderr b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.stderr
new file mode 100644
index 0000000..cc13c59
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.stderr
@@ -0,0 +1,173 @@
+[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]: ecpg_execute on line 26: query: create table t1 ( id serial primary key , t text ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 26: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 26: OK: CREATE TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 27: query: insert into t1 ( t ) values ( 'a' ) , ( 'b' ) , ( 'c' ); with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 27: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 27: OK: INSERT 0 3
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 28: action "commit"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 41: query: declare MyCur cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 41: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 41: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: query: close myCur; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 49: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 49: OK: CLOSE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 64: query: declare "MyCur" cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 64: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 64: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlcode -231 on line 73: invalid cursorname ""myCur"" on line 73
+[NO_PID]: sqlca: code: -231, state: 34000
+SQL error: invalid cursorname ""myCur"" on line 73
+[NO_PID]: raising sqlcode -401 on line 81: current transaction is aborted, commands ignored until end of transaction block on line 81
+[NO_PID]: sqlca: code: -401, state: 25P02
+SQL error: current transaction is aborted, commands ignored until end of transaction block on line 81
+[NO_PID]: ECPGtrans on line 87: action "rollback"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 98: action "savepoint a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 100: query: declare "MyCur" cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 100: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 100: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 110: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlcode -231 on line 112: invalid cursorname ""MyCur"" on line 112
+[NO_PID]: sqlca: code: -231, state: 34000
+SQL error: invalid cursorname ""MyCur"" on line 112
+[NO_PID]: ECPGtrans on line 118: action "rollback"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 126: action "savepoint a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 132: query: declare "MyCur" cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 132: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 132: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 138: action "savepoint b"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 148: action "rollback to c"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_check_PQresult on line 148: bad response - ERROR:  no such savepoint
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlstate 3B001 (sqlcode -400): no such savepoint on line 148
+[NO_PID]: sqlca: code: -400, state: 3B001
+SQL error: no such savepoint on line 148
+[NO_PID]: ECPGtrans on line 158: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 168: action "rollback to b"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_check_PQresult on line 168: bad response - ERROR:  no such savepoint
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlstate 3B001 (sqlcode -400): no such savepoint on line 168
+[NO_PID]: sqlca: code: -400, state: 3B001
+SQL error: no such savepoint on line 168
+[NO_PID]: ECPGtrans on line 178: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlcode -231 on line 188: invalid cursorname ""MyCur"" on line 188
+[NO_PID]: sqlca: code: -231, state: 34000
+SQL error: invalid cursorname ""MyCur"" on line 188
+[NO_PID]: ECPGtrans on line 198: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 208: action "release savepoint a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 218: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_check_PQresult on line 218: bad response - ERROR:  no such savepoint
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlstate 3B001 (sqlcode -400): no such savepoint on line 218
+[NO_PID]: sqlca: code: -400, state: 3B001
+SQL error: no such savepoint on line 218
+[NO_PID]: ECPGtrans on line 224: action "rollback"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 233: action "savepoint a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 239: query: declare "MyCur" cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 239: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 239: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 245: query: fetch from "MyCur"; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 245: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 245: correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 245: RESULT: 1 offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 245: RESULT: a offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 251: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: raising sqlcode -231 on line 261: invalid cursorname ""MyCur"" on line 261
+[NO_PID]: sqlca: code: -231, state: 34000
+SQL error: invalid cursorname ""MyCur"" on line 261
+[NO_PID]: raising sqlcode -401 on line 272: current transaction is aborted, commands ignored until end of transaction block on line 272
+[NO_PID]: sqlca: code: -401, state: 25P02
+SQL error: current transaction is aborted, commands ignored until end of transaction block on line 272
+[NO_PID]: ECPGtrans on line 285: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 291: query: declare "MyCur" cursor for select id , t from t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 291: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 291: OK: DECLARE CURSOR
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 301: action "savepoint a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 307: query: fetch from "MyCur"; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 307: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 307: correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 307: RESULT: 1 offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 307: RESULT: a offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 319: action "rollback to a"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 325: query: fetch from "MyCur"; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 325: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 325: correctly got 1 tuples with 2 fields
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 325: RESULT: 2 offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_get_data on line 325: RESULT: b offset: -1; array: no
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 331: action "rollback"; connection "regress1"
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 335: query: drop table t1; with 0 parameter(s) on connection regress1
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_execute on line 335: using PQexec
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ecpg_process_output on line 335: OK: DROP TABLE
+[NO_PID]: sqlca: code: 0, state: 00000
+[NO_PID]: ECPGtrans on line 336: action "commit"; connection "regress1"
+[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-cursorsubxact.stdout b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.stdout
new file mode 100644
index 0000000..80bcdf8
--- /dev/null
+++ b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.stdout
@@ -0,0 +1,44 @@
+test case insensitive cursor name
+
+open MyCur (case insensitive) succeeded
+close myCur (case insensitive) succeeded
+
+test case sensitive cursor name
+
+open "MyCur" (case sensitive) succeeded
+close "myCur" (case sensitive) failed with SQLSTATE 34000 (expected 34000)
+close "MyCur" (case sensitive) failed with SQLSTATE 25P02 (expected 25P02)
+
+test case sensitive cursor name in savepoint
+
+close "MyCur" (case sensitive) succeeded
+close "MyCur" failed with SQLSTATE 34000 (expected 34000)
+
+test savepoint handling
+
+"savepoint a" succeeded
+open "MyCur" (case sensitive) succeeded
+"savepoint b" succeeded
+"rollback to c" failed with SQLSTATE 3B001 (expected 3B001)
+"rollback to a" succeeded
+"rollback to b" failed with SQLSTATE 3B001 (expected 3B001)
+"rollback to a" succeeded
+fetch from "MyCur" (case sensitive) failed with SQLSTATE 34000 (expected 34000)
+"rollback to a" succeeded
+"release savepoint a" succeeded
+"rollback to a" failed with SQLSTATE 3B001 (expected 3B001)
+
+test implicit "release savepoint a" for a second "savepoint a"
+
+"savepoint a" succeeded
+open "MyCur" (case sensitive) succeeded
+fetch from "MyCur" (case sensitive) result 1 'a'
+"rollback to a" succeeded
+fetch from "MyCur" (case sensitive) failed with SQLSTATE 34000 (expected 34000)
+open "MyCur" (case sensitive) failed with SQLSTATE 25P02 (expected 25P02)
+"rollback to a" succeeded
+open "MyCur" (case sensitive) succeeded
+"savepoint a" succeeded
+fetch "MyCur" (case sensitive) result 1 'a'
+"rollback to a" succeeded
+fetch "MyCur" (case sensitive) result 2 'b'
diff --git a/src/interfaces/ecpg/test/expected/sql-desc.c b/src/interfaces/ecpg/test/expected/sql-desc.c
index 75c15f2..f618e33 100644
--- a/src/interfaces/ecpg/test/expected/sql-desc.c
+++ b/src/interfaces/ecpg/test/expected/sql-desc.c
@@ -242,45 +242,45 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 55 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 55 "desc.pgc"
 
 	printf("output = %s\n", val2output);
 
 	/* declare c1 cursor for $1 */
 #line 58 "desc.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare c1 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "c1", ECPGst_normal, "declare c1 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "foo2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_descriptor, "indesc", 1L, 1L, 1L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 59 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 59 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from c1", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "c1", ECPGst_normal, "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 61 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 61 "desc.pgc"
 
 	printf("val1=%d (ind1: %d) val2=%s (ind2: %d)\n",
 		val1output, ind1, val2output, ind2);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close c1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "c1", ECPGst_normal, "close c1", ECPGt_EOIT, ECPGt_EORT);
 #line 65 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 65 "desc.pgc"
 
 
 	{ ECPGset_desc_header(__LINE__, "indesc", (int)(1));
 
 #line 67 "desc.pgc"
 
@@ -292,44 +292,44 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 #line 68 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 68 "desc.pgc"
 
 
 	/* declare c2 cursor for $1 */
 #line 70 "desc.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare c2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "c2", ECPGst_normal, "declare c2 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "foo3", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
 	ECPGt_descriptor, "indesc", 1L, 1L, 1L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 71 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 71 "desc.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from c2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "c2", ECPGst_normal, "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 73 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 73 "desc.pgc"
 
 	printf("val1=%d val2=%s\n", val1output, val2i ? "null" : val2output);
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close c2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "c2", ECPGst_normal, "close c2", ECPGt_EOIT, ECPGt_EORT);
 #line 76 "desc.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 76 "desc.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-describe.c b/src/interfaces/ecpg/test/expected/sql-describe.c
index 11aadb4..4b98b25 100644
--- a/src/interfaces/ecpg/test/expected/sql-describe.c
+++ b/src/interfaces/ecpg/test/expected/sql-describe.c
@@ -126,21 +126,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 #line 38 "describe.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into descr_t2 ( id , t ) values ( default , 'd' )", ECPGt_EOIT, ECPGt_EORT);
 #line 39 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 39 "describe.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 42 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 42 "describe.pgc"
 
 
 	/*
 	 * Test DESCRIBE with a query producing tuples.
 	 * DESCRIPTOR and SQL DESCRIPTOR are NOT the same in
 	 * Informix-compat mode.
@@ -439,21 +439,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table descr_t2", ECPGt_EOIT, ECPGt_EORT);
 #line 190 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 190 "describe.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 193 "describe.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 193 "describe.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 196 "describe.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/sql-dynalloc2.c b/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
index e851892..ddc1f60 100644
--- a/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
+++ b/src/interfaces/ecpg/test/expected/sql-dynalloc2.c
@@ -233,21 +233,21 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
    }
    ECPGfree_auto_mem();
    printf("\n");
 
    ECPGdeallocate_desc(__LINE__, "mydesc");
 #line 51 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );
 #line 51 "dynalloc2.pgc"
 
-   { ECPGtrans(__LINE__, NULL, "rollback");
+   { ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 52 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 52 "dynalloc2.pgc"
 
    { ECPGdisconnect(__LINE__, "CURRENT");
 #line 53 "dynalloc2.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 53 "dynalloc2.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.c b/src/interfaces/ecpg/test/expected/sql-dyntest.c
index 537d9ff..6ed6cfe 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.c
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.c
@@ -254,32 +254,32 @@ if (sqlca.sqlcode < 0) error ( );}
   { ECPGprepare(__LINE__, NULL, 0, "myquery", QUERY);
 #line 57 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error ( );}
 #line 57 "dyntest.pgc"
 
   /* declare MYCURS cursor for $1 */
 #line 58 "dyntest.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare MYCURS cursor for $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "MYCURS", ECPGst_normal, "declare MYCURS cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "myquery", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 60 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error ( );}
 #line 60 "dyntest.pgc"
 
 
   while (1)
     {
-      { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT, 
+      { ECPGfetch(__LINE__, 0, 1, NULL, 0, "MYCURS", ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT, 
 	ECPGt_descriptor, "MYDESC", 1L, 1L, 1L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 64 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error ( );}
 #line 64 "dyntest.pgc"
 
 
       if (sqlca.sqlcode)
 	break;
@@ -461,21 +461,21 @@ if (sqlca.sqlcode < 0) error ( );}
 
 if (sqlca.sqlcode < 0) error ( );}
 #line 187 "dyntest.pgc"
 
 		printf ("<\"%s\">\n", STRINGVAR);
 		break;
 	      }
 	}
     }
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "MYCURS", ECPGst_normal, "close MYCURS", ECPGt_EOIT, ECPGt_EORT);
 #line 194 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error ( );}
 #line 194 "dyntest.pgc"
 
 
   ECPGdeallocate_desc(__LINE__, "MYDESC");
 #line 196 "dyntest.pgc"
 
 if (sqlca.sqlcode < 0) error ( );
diff --git a/src/interfaces/ecpg/test/expected/sql-execute.c b/src/interfaces/ecpg/test/expected/sql-execute.c
index cc0fd70..326a3c3 100644
--- a/src/interfaces/ecpg/test/expected/sql-execute.c
+++ b/src/interfaces/ecpg/test/expected/sql-execute.c
@@ -63,21 +63,21 @@ main(void)
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "execute.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) )", ECPGt_EOIT, ECPGt_EORT);
 #line 25 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 25 "execute.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 26 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "execute.pgc"
 
 
 	sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
 #line 29 "execute.pgc"
 
@@ -114,48 +114,48 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	ECPGt_int,&(increment),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 41 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 41 "execute.pgc"
 
 
 	printf("Inserted %ld tuples via prepared execute\n", sqlca.sqlerrd[2]);
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 45 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 45 "execute.pgc"
 
 
 	sprintf (command, "select * from test");
 
 	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
 #line 49 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 49 "execute.pgc"
 
 	/* declare CUR cursor for $1 */
 #line 50 "execute.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "CUR", ECPGst_normal, "declare CUR cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "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, 0, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "CUR", ECPGst_normal, "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 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 53 "execute.pgc"
@@ -173,21 +173,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 59 "execute.pgc"
  int a = amount [ i ] ;
 /* exec sql end declare section */
 #line 60 "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, 0, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "CUR", ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
 #line 66 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 66 "execute.pgc"
 
 	{ ECPGdeallocate(__LINE__, 0, NULL, "f");
 #line 67 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 67 "execute.pgc"
@@ -198,31 +198,31 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	{ ECPGprepare(__LINE__, NULL, 0, "f", command);
 #line 71 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 71 "execute.pgc"
 
 	/* declare CUR2 cursor for $1 */
 #line 72 "execute.pgc"
 
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare CUR2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "CUR2", ECPGst_normal, "declare CUR2 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "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 74 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 74 "execute.pgc"
 
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch in CUR2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "CUR2", ECPGst_normal, "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 75 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 75 "execute.pgc"
@@ -240,21 +240,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 81 "execute.pgc"
  int a = amount [ i ] ;
 /* exec sql end declare section */
 #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, 0, ECPGst_normal, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "CUR2", ECPGst_normal, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
 #line 88 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 88 "execute.pgc"
 
 	{ ECPGdeallocate(__LINE__, 0, NULL, "f");
 #line 89 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 89 "execute.pgc"
@@ -307,21 +307,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 107 "execute.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 108 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 108 "execute.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 109 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 109 "execute.pgc"
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 110 "execute.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 110 "execute.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.c b/src/interfaces/ecpg/test/expected/sql-fetch.c
index c6be49c..48bdaaf 100644
--- a/src/interfaces/ecpg/test/expected/sql-fetch.c
+++ b/src/interfaces/ecpg/test/expected/sql-fetch.c
@@ -92,35 +92,35 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 24 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "fetch.pgc"
 
 
   /* declare C cursor for select * from My_Table */
 #line 26 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select * from My_Table", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select * from My_Table", ECPGt_EOIT, ECPGt_EORT);
 #line 28 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 28 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 28 "fetch.pgc"
 
 
   /* exec sql whenever not found  break ; */
 #line 30 "fetch.pgc"
 
   while (1) {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 32 "fetch.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 32 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -128,96 +128,96 @@ if (sqlca.sqlwarn[0] == 'W') sqlprint();
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 32 "fetch.pgc"
 
 	printf("%d: %s\n", i, str);
   }
 
   /* exec sql whenever not found  continue ; */
 #line 36 "fetch.pgc"
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
 #line 37 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 37 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch $0 in C", 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch $0 in C", 
 	ECPGt_int,&(count),(long)1,(long)1,sizeof(int), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 39 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 39 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 39 "fetch.pgc"
 
   printf("%d: %s\n", i, str);
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "close C", ECPGt_EOIT, ECPGt_EORT);
 #line 42 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 42 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 42 "fetch.pgc"
 
 
   /* declare D cursor for select * from My_Table where Item1 = $1 */
 #line 44 "fetch.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare D cursor for select * from My_Table where Item1 = $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "D", ECPGst_normal, "declare D cursor for select * from My_Table where Item1 = $1", 
 	ECPGt_const,"1",(long)1,(long)1,strlen("1"), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 46 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 46 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 46 "fetch.pgc"
 
 
   /* exec sql whenever not found  break ; */
 #line 48 "fetch.pgc"
 
   while (1) {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "D", ECPGst_normal, "fetch 1 in D", 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), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 50 "fetch.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 50 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 50 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 50 "fetch.pgc"
 
 	printf("%d: %s\n", i, str);
   }
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close D", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGclose(__LINE__, 0, 1, NULL, 0, "D", ECPGst_normal, "close D", ECPGt_EOIT, ECPGt_EORT);
 #line 53 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 53 "fetch.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 53 "fetch.pgc"
 
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table My_Table", ECPGt_EOIT, ECPGt_EORT);
diff --git a/src/interfaces/ecpg/test/expected/sql-indicators.c b/src/interfaces/ecpg/test/expected/sql-indicators.c
index e805e4e..22aacc1 100644
--- a/src/interfaces/ecpg/test/expected/sql-indicators.c
+++ b/src/interfaces/ecpg/test/expected/sql-indicators.c
@@ -111,41 +111,41 @@ int main()
 	{ ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 15 "indicators.pgc"
 
 	{ ECPGsetcommit(__LINE__, "off", NULL);}
 #line 16 "indicators.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table indicator_test ( \"id\" int primary key , \"str\" text not null , val int null )", ECPGt_EOIT, ECPGt_EORT);}
 #line 21 "indicators.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit work");}
+	{ ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 22 "indicators.pgc"
 
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 1 , 'Hello' , 0 )", ECPGt_EOIT, ECPGt_EORT);}
 #line 24 "indicators.pgc"
 
 
 	/* use indicator in insert */
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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 27 "indicators.pgc"
 
 	nullind = 0;
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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 29 "indicators.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit work");}
+	{ ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 30 "indicators.pgc"
 
 
 	/* use indicators to get information about selects */
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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 33 "indicators.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 2", ECPGt_EOIT, 
@@ -171,19 +171,19 @@ int main()
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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 42 "indicators.pgc"
 
 	printf("intvar: %d, nullind: %d\n", intvar, nullind);
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table indicator_test", ECPGt_EOIT, ECPGt_EORT);}
 #line 45 "indicators.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit work");}
+	{ ECPGtrans(__LINE__, NULL, "commit work", 0, 0, 0, NULL);}
 #line 46 "indicators.pgc"
 
 
 	{ ECPGdisconnect(__LINE__, "CURRENT");}
 #line 48 "indicators.pgc"
 
 	return 0;
 }
diff --git a/src/interfaces/ecpg/test/expected/sql-oldexec.c b/src/interfaces/ecpg/test/expected/sql-oldexec.c
index 0c0239c..a3f8948 100644
--- a/src/interfaces/ecpg/test/expected/sql-oldexec.c
+++ b/src/interfaces/ecpg/test/expected/sql-oldexec.c
@@ -63,21 +63,21 @@ main(void)
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 24 "oldexec.pgc"
 
 	{ ECPGdo(__LINE__, 0, 1, NULL, 1, ECPGst_normal, "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");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #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, ECPGst_exec_immediate, command, ECPGt_EOIT, ECPGt_EORT);
 #line 29 "oldexec.pgc"
 
@@ -114,48 +114,48 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	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");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #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, ECPGst_normal, "declare CUR cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, "CUR", ECPGst_normal, "declare CUR cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "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, ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, "CUR", ECPGst_normal, "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"
@@ -173,50 +173,50 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #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, ECPGst_normal, "close CUR", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 1, "CUR", ECPGst_normal, "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, ECPGst_normal, "declare CUR3 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, "CUR3", ECPGst_normal, "declare CUR3 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "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, ECPGst_normal, "fetch in CUR3", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, "CUR3", ECPGst_normal, "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"
@@ -234,33 +234,33 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #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, ECPGst_normal, "close CUR3", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 1, "CUR3", ECPGst_normal, "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, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
 #line 88 "oldexec.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 88 "oldexec.pgc"
 
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #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"
diff --git a/src/interfaces/ecpg/test/expected/sql-quote.c b/src/interfaces/ecpg/test/expected/sql-quote.c
index 43f1eec..6c4d84f 100644
--- a/src/interfaces/ecpg/test/expected/sql-quote.c
+++ b/src/interfaces/ecpg/test/expected/sql-quote.c
@@ -142,69 +142,69 @@ if (sqlca.sqlcode < 0) sqlprint();}
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into \"My_Table\" values ( 2 , E'a\\\\\\\\b' )", ECPGt_EOIT, ECPGt_EORT);
 #line 40 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 40 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 40 "quote.pgc"
 
 
-  { ECPGtrans(__LINE__, NULL, "begin");
+  { ECPGtrans(__LINE__, NULL, "begin", 0, 1, 0, NULL);
 #line 42 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 42 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 42 "quote.pgc"
 
   /* declare C cursor for select * from \"My_Table\" */
 #line 43 "quote.pgc"
 
 
-  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare C cursor for select * from \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select * from \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
 #line 45 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 45 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 45 "quote.pgc"
 
 
   /* exec sql whenever not found  break ; */
 #line 47 "quote.pgc"
 
 
   while (true)
   {
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "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 51 "quote.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 51 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 51 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 51 "quote.pgc"
 
 	printf("value: %d %s\n", i, var);
   }
 
-  { ECPGtrans(__LINE__, NULL, "rollback");
+  { ECPGtrans(__LINE__, NULL, "rollback", 0, 0, 1, NULL);
 #line 55 "quote.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
 #line 55 "quote.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 55 "quote.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
 #line 56 "quote.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-sqlda.c b/src/interfaces/ecpg/test/expected/sql-sqlda.c
index e0c35b2..83804f5 100644
--- a/src/interfaces/ecpg/test/expected/sql-sqlda.c
+++ b/src/interfaces/ecpg/test/expected/sql-sqlda.c
@@ -219,21 +219,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "insert");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 , 'a' , 1.0 , 1 , 'a' ) , ( 2 , null , null , null , null ) , ( 4 , 'd' , 4.0 , 4 , 'd' )", ECPGt_EOIT, ECPGt_EORT);
 #line 87 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 87 "sqlda.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 90 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 90 "sqlda.pgc"
 
 
 	/* SQLDA test for getting all records from a table */
 
 	outp_sqlda = NULL;
 
@@ -244,59 +244,59 @@ if (sqlca.sqlcode < 0) exit (1);}
 if (sqlca.sqlcode < 0) exit (1);}
 #line 97 "sqlda.pgc"
 
 
 	strcpy(msg, "declare");
 	/* declare mycur1 cursor for $1 */
 #line 100 "sqlda.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur1 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur1", ECPGst_normal, "declare mycur1 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id1", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 103 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 103 "sqlda.pgc"
 
 
 	/* exec sql whenever not found  break ; */
 #line 105 "sqlda.pgc"
 
 
 	rec = 0;
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur1", ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 111 "sqlda.pgc"
 
 if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
 #line 111 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 111 "sqlda.pgc"
 
 
 		printf("FETCH RECORD %d\n", ++rec);
 		dump_sqlda(outp_sqlda);
 	}
 
 	/* exec sql whenever not found  continue ; */
 #line 117 "sqlda.pgc"
 
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "mycur1", ECPGst_normal, "close mycur1", ECPGt_EOIT, ECPGt_EORT);
 #line 120 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 120 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id1");
 #line 123 "sqlda.pgc"
 
@@ -317,31 +317,31 @@ if (sqlca.sqlcode < 0) exit (1);}
 if (sqlca.sqlcode < 0) exit (1);}
 #line 132 "sqlda.pgc"
 
 
 	strcpy(msg, "declare");
 	/* declare mycur2 cursor for $1 */
 #line 135 "sqlda.pgc"
 
 
 	strcpy(msg, "open");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare mycur2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur2", ECPGst_normal, "declare mycur2 cursor for $1", 
 	ECPGt_char_variable,(ECPGprepared_statement(NULL, "st_id2", __LINE__)),(long)1,(long)1,(1)*sizeof(char), 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
 #line 138 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 138 "sqlda.pgc"
 
 
 	strcpy(msg, "fetch");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur2", ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT, 
 	ECPGt_sqlda, &outp_sqlda, 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 141 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 141 "sqlda.pgc"
 
 
 	outp_sqlda1 = outp_sqlda;
 	rec = 0;
@@ -350,21 +350,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 		sqlda_t	*ptr;
 		printf("FETCH RECORD %d\n", ++rec);
 		dump_sqlda(outp_sqlda1);
 
 		ptr = outp_sqlda1;
 		outp_sqlda1 = outp_sqlda1->desc_next;
 		free(ptr);
 	}
 
 	strcpy(msg, "close");
-	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGclose(__LINE__, 0, 1, NULL, 0, "mycur2", ECPGst_normal, "close mycur2", ECPGt_EOIT, ECPGt_EORT);
 #line 157 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 157 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id2");
 #line 160 "sqlda.pgc"
 
@@ -468,21 +468,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 222 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 222 "sqlda.pgc"
 
 
 	dump_sqlda(outp_sqlda);
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, "con2", "commit");
+	{ ECPGtrans(__LINE__, "con2", "commit", 0, 0, 0, NULL);
 #line 227 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 227 "sqlda.pgc"
 
 
 	strcpy(msg, "deallocate");
 	{ ECPGdeallocate(__LINE__, 0, NULL, "st_id4");
 #line 230 "sqlda.pgc"
 
@@ -505,21 +505,21 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "drop");
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
 #line 241 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 241 "sqlda.pgc"
 
 
 	strcpy(msg, "commit");
-	{ ECPGtrans(__LINE__, NULL, "commit");
+	{ ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 244 "sqlda.pgc"
 
 if (sqlca.sqlcode < 0) exit (1);}
 #line 244 "sqlda.pgc"
 
 
 	strcpy(msg, "disconnect");
 	{ ECPGdisconnect(__LINE__, "CURRENT");
 #line 247 "sqlda.pgc"
 
diff --git a/src/interfaces/ecpg/test/expected/thread-thread.c b/src/interfaces/ecpg/test/expected/thread-thread.c
index 485f9dd..08a5811 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread.c
@@ -65,27 +65,27 @@ int main()
   * more or less random order */
  /* ECPGdebug(1, stderr); */
 
   /* setup test_thread table */
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 46 "thread.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test_thread", ECPGt_EOIT, ECPGt_EORT);}
 #line 47 "thread.pgc"
  /* DROP might fail */
-  { ECPGtrans(__LINE__, NULL, "commit");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 48 "thread.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 54 "thread.pgc"
 
   { ECPGdisconnect(__LINE__, "CURRENT");}
 #line 55 "thread.pgc"
 
 
   /* create, and start, threads */
   threads = calloc(nthreads, sizeof(threads[0]));
   if( threads == NULL )
     {
@@ -114,21 +114,21 @@ int main()
 
   /* and check results */
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 85 "thread.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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"
 
-  { ECPGtrans(__LINE__, NULL, "commit");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 87 "thread.pgc"
 
   { ECPGdisconnect(__LINE__, "CURRENT");}
 #line 88 "thread.pgc"
 
   if( l_rows == (nthreads * iterations) )
     printf("Success.\n");
   else
     printf("ERROR: Failure - expecting %d rows, got %d.\n", nthreads * iterations, l_rows);
 
@@ -164,21 +164,21 @@ void *test_thread(void *arg)
 #line 112 "thread.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 112 "thread.pgc"
 
   if( sqlca.sqlcode != 0 )
     {
       printf("%s: ERROR: cannot connect to database!\n", l_connection);
       return( NULL );
     }
-  { ECPGtrans(__LINE__, l_connection, "begin");
+  { ECPGtrans(__LINE__, l_connection, "begin", 0, 1, 0, NULL);
 #line 118 "thread.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 118 "thread.pgc"
 
 
   /* insert into test_thread table */
   for( l_i = 1; l_i <= iterations; l_i++ )
     {
       { ECPGdo(__LINE__, 0, 1, l_connection, 0, ECPGst_normal, "insert into test_thread ( thread , iteration ) values ( $1  , $2  )", 
@@ -189,21 +189,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 123 "thread.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 123 "thread.pgc"
 
       if( sqlca.sqlcode != 0 )
 	printf("%s: ERROR: insert failed!\n", l_connection);
     }
 
   /* all done */
-  { ECPGtrans(__LINE__, l_connection, "commit");
+  { ECPGtrans(__LINE__, l_connection, "commit", 0, 0, 0, NULL);
 #line 129 "thread.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 129 "thread.pgc"
 
   { ECPGdisconnect(__LINE__, l_connection);
 #line 130 "thread.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 130 "thread.pgc"
diff --git a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
index f91a098..cae6ee9 100644
--- a/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
+++ b/src/interfaces/ecpg/test/expected/thread-thread_implicit.c
@@ -66,27 +66,27 @@ int main()
   * more or less random order */
  /* ECPGdebug(1, stderr); */
 
   /* setup test_thread table */
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 47 "thread_implicit.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table test_thread", ECPGt_EOIT, ECPGt_EORT);}
 #line 48 "thread_implicit.pgc"
  /* DROP might fail */
-  { ECPGtrans(__LINE__, NULL, "commit");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 49 "thread_implicit.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 55 "thread_implicit.pgc"
 
   { ECPGdisconnect(__LINE__, "CURRENT");}
 #line 56 "thread_implicit.pgc"
 
 
   /* create, and start, threads */
   threads = calloc(nthreads, sizeof(threads[0]));
   if( threads == NULL )
     {
@@ -115,21 +115,21 @@ int main()
 
   /* and check results */
   { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
 #line 86 "thread_implicit.pgc"
 
   { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "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"
 
-  { ECPGtrans(__LINE__, NULL, "commit");}
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);}
 #line 88 "thread_implicit.pgc"
 
   { ECPGdisconnect(__LINE__, "CURRENT");}
 #line 89 "thread_implicit.pgc"
 
   if( l_rows == (nthreads * iterations) )
     printf("Success.\n");
   else
     printf("ERROR: Failure - expecting %d rows, got %d.\n", nthreads * iterations, l_rows);
 
@@ -165,21 +165,21 @@ void *test_thread(void *arg)
 #line 113 "thread_implicit.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 113 "thread_implicit.pgc"
 
   if( sqlca.sqlcode != 0 )
     {
       printf("%s: ERROR: cannot connect to database!\n", l_connection);
       return( NULL );
     }
-  { ECPGtrans(__LINE__, NULL, "begin");
+  { ECPGtrans(__LINE__, NULL, "begin", 0, 1, 0, NULL);
 #line 119 "thread_implicit.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 119 "thread_implicit.pgc"
 
 
   /* insert into test_thread table */
   for( l_i = 1; l_i <= iterations; l_i++ )
     {
       { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test_thread ( thread , iteration ) values ( $1  , $2  )", 
@@ -190,21 +190,21 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 124 "thread_implicit.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 124 "thread_implicit.pgc"
 
       if( sqlca.sqlcode != 0 )
 	printf("%s: ERROR: insert failed!\n", l_connection);
     }
 
   /* all done */
-  { ECPGtrans(__LINE__, NULL, "commit");
+  { ECPGtrans(__LINE__, NULL, "commit", 0, 0, 0, NULL);
 #line 130 "thread_implicit.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 130 "thread_implicit.pgc"
 
   { ECPGdisconnect(__LINE__, l_connection);
 #line 131 "thread_implicit.pgc"
 
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 131 "thread_implicit.pgc"
diff --git a/src/interfaces/ecpg/test/sql/.gitignore b/src/interfaces/ecpg/test/sql/.gitignore
index cd6f342..4458eb3 100644
--- a/src/interfaces/ecpg/test/sql/.gitignore
+++ b/src/interfaces/ecpg/test/sql/.gitignore
@@ -1,18 +1,20 @@
 /array
 /array.c
 /binary
 /binary.c
 /code100
 /code100.c
 /copystdout
 /copystdout.c
+/cursorsubxact
+/cursorsubxact.c
 /define
 /define.c
 /desc
 /desc.c
 /describe
 /describe.c
 /dynalloc
 /dynalloc.c
 /dynalloc2
 /dynalloc2.c
diff --git a/src/interfaces/ecpg/test/sql/Makefile b/src/interfaces/ecpg/test/sql/Makefile
index 18c37b6..f3fdff2 100644
--- a/src/interfaces/ecpg/test/sql/Makefile
+++ b/src/interfaces/ecpg/test/sql/Makefile
@@ -1,19 +1,20 @@
 subdir = src/interfaces/ecpg/test/sql
 top_builddir = ../../../../..
 include $(top_builddir)/src/Makefile.global
 include $(top_srcdir)/$(subdir)/../Makefile.regress
 
 TESTS = array array.c \
 	binary binary.c \
 	code100 code100.c \
         copystdout copystdout.c \
+        cursorsubxact cursorsubxact.c \
 	define define.c \
         desc desc.c \
         sqlda sqlda.c \
         describe describe.c \
         dyntest dyntest.c \
         dynalloc dynalloc.c \
         dynalloc2 dynalloc2.c \
         execute execute.c \
         fetch fetch.c \
         func func.c \
diff --git a/src/interfaces/ecpg/test/sql/cursorsubxact.pgc b/src/interfaces/ecpg/test/sql/cursorsubxact.pgc
new file mode 100644
index 0000000..761a40f
--- /dev/null
+++ b/src/interfaces/ecpg/test/sql/cursorsubxact.pgc
@@ -0,0 +1,341 @@
+#include <stdlib.h>
+#include <string.h>
+
+EXEC SQL INCLUDE ../regression;
+
+exec sql whenever sqlerror sqlprint;
+
+#define CURNAME "MyCur"
+#define CURNAME_BAD "myCur"
+
+#define QUOTED_CURNAME "\"MyCur\""
+#define QUOTED_CURNAME_BAD "\"myCur\""
+
+int main(void)
+{
+exec sql begin declare section;
+	char	*curname;
+	int	id[4];
+	varchar	t[4][50];
+exec sql end declare section;
+
+	ECPGdebug(1, stderr);
+
+	exec sql connect to REGRESSDB1;
+
+	exec sql create table t1 (id serial primary key, t text);
+	exec sql insert into t1 (t) values ('a'), ('b'), ('c');
+	exec sql commit;
+
+	/*
+	 * Cursor name passed in a variable unquoted.
+	 * It has to be treated as case-insensitive.
+	 */
+
+	printf("test case insensitive cursor name\n\n");
+
+	curname = CURNAME;
+
+	exec sql declare :curname cursor for select id, t from t1;
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case insensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case insensitive) succeeded\n", curname);
+
+	curname = CURNAME_BAD;
+
+	exec sql close :curname;
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case insensitive)  failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case insensitive) succeeded\n", curname);
+
+	/*
+	 * Cursor name passed in a variable quoted.
+	 * It has to be treated as case-sensitive.
+	 */
+
+	printf("\ntest case sensitive cursor name\n\n");
+
+	curname = QUOTED_CURNAME;
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	curname = QUOTED_CURNAME_BAD;
+
+	/* Try to close the wrong cursor name, it has to fail with 34000. */
+	exec sql close :curname;
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	/* Try to close the right cursor name, it has to fail with 25P02 */
+	curname = QUOTED_CURNAME;
+	exec sql close :curname;
+	if (sqlca.sqlcode < 0)
+		printf("close %s (case sensitive) failed with SQLSTATE %5s (expected 25P02)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	exec sql rollback;
+
+	/*
+	 * Try a new transaction and watch the cursor name disappear
+	 * after ROLLBACK TO SAVEPOINT.
+	 */
+
+	printf("\ntest case sensitive cursor name in savepoint\n\n");
+
+	curname = QUOTED_CURNAME;
+
+	exec sql savepoint a;
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s (case sensitive) succeeded\n", curname);
+
+	/*
+	 * The cursor name must be forgotten, the subsequent
+	 * CLOSE has to fail with error code 34000.
+	 */
+	exec sql rollback to a;
+
+	exec sql close :curname;
+	if (sqlca.sqlcode < 0)
+		printf("close %s failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("close %s succeeded unexpectedly (expected 34000)\n", curname);
+
+	exec sql rollback;
+
+	/*
+	 * Try a new transaction and play games with savepoints.
+	 */
+
+	printf("\ntest savepoint handling\n\n");
+
+	exec sql savepoint a;
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	exec sql savepoint b;
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint b\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint b\" succeeded\n");
+
+	/*
+	 * Try to rollback to an unknown savepoint
+	 */
+
+	exec sql rollback to c;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to c\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to c\" succeeded unexpectedly (expected 3B001)\n");
+
+	/*
+	 * ROLLBACK TO A implicitly rolls back savepoint "B"
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * Savepoint "b" is now unknown, fails with 3B001
+	 */
+
+	exec sql rollback to b;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to b\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to b\" succeeded unexpectedly (expected 3B001)\n");
+
+	/*
+	 * ROLLBACK TO A has to succeed again, it's still alive
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * The cursor was declared under savepoint "a", was forgotten
+	 */
+
+	exec sql fetch from :curname into :id[0], :t[0];
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) succeeded unexpectedly (expected 34000)\n", curname);
+
+	/*
+	 * ROLLBACK TO A has to succeed again, it's still alive
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * RELEASE SAVEPOINT A forgets about the savepoint name
+	 */
+
+	exec sql release savepoint a;
+	if (sqlca.sqlcode < 0)
+		printf("\"release savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"release savepoint a\" succeeded\n");
+
+	/*
+	 * Prove the above
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s (expected 3B001)\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded unexpectedly (expected 3B001)\n");
+
+	exec sql rollback;
+
+	/*
+	 * Test the cursor's existence rolled back after
+	 * ROLLBACK TO SAVEPOINT.
+	 */
+
+	printf("\ntest implicit \"release savepoint a\" for a second \"savepoint a\"\n\n");
+
+	exec sql savepoint a;
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	exec sql fetch from :curname into :id[0], :t[0];
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) result %d '%s'\n", curname, id[0], t[0].arr);
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	/*
+	 * There's no cursor now, fails with error code 34000
+	 */
+
+	exec sql fetch from :curname into :id[1], :t[1];
+	if (sqlca.sqlcode < 0)
+		printf("fetch from %s (case sensitive) failed with SQLSTATE %5s (expected 34000)\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch from %s (case sensitive) unexpectedly succeeded (expected 34000)\n", curname);
+
+	/*
+	 * Try to open it again, should fail because the
+	 * transaction has failed above.
+	 */
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s (expected 25P02)\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded unexpectedly (expected 25P02)\n", curname);
+
+	/*
+	 * Test the implicit RELEASE SAVEPOINT if a SAVEPOINT
+	 * is used with an already existing name. After the
+	 * ROLLBACK TO A below, savepoint "A" still exists
+	 * as was already proven above.
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	exec sql open :curname;
+	if (sqlca.sqlcode < 0)
+		printf("open %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("open %s (case sensitive) succeeded\n", curname);
+
+	/*
+	 * Here is the 2nd SAVEPOINT A
+	 */
+
+	exec sql savepoint a;
+	if (sqlca.sqlcode < 0)
+		printf("\"savepoint a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"savepoint a\" succeeded\n");
+
+	exec sql fetch from :curname into :id[2], :t[2];
+	if (sqlca.sqlcode < 0)
+		printf("fetch %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch %s (case sensitive) result %d '%s'\n", curname, id[2], t[2].arr);
+
+	/*
+	 * The implicit release savepoint propagated the cursor
+	 * to the toplevel transaction. It will be still accessible
+	 * after ROLLBACK TO A below.
+	 */
+
+	exec sql rollback to a;
+	if (sqlca.sqlcode < 0)
+		printf("\"rollback to a\" failed with SQLSTATE %5s\n", sqlca.sqlstate);
+	else
+		printf("\"rollback to a\" succeeded\n");
+
+	exec sql fetch from :curname into :id[3], :t[3];
+	if (sqlca.sqlcode < 0)
+		printf("fetch %s (case sensitive) failed with SQLSTATE %5s\n", curname, sqlca.sqlstate);
+	else
+		printf("fetch %s (case sensitive) result %d '%s'\n", curname, id[3], t[3].arr);
+
+	exec sql rollback;
+
+	/* Drop the test table */
+
+	exec sql drop table t1;
+	exec sql commit;
+
+	exec sql disconnect all;
+
+	return 0;
+}
