commit a5cb7ed8d0c5dc131721f000c40b4586784ad4ad
Author: Böszörményi Zoltán <zb@cybertec.at>
Date:   Wed Nov 20 11:35:45 2013 +0100

    ECPG: Pass the SCROLL/NO SCROLL/unspecified to ECPGopen() and pass
    the direction and the amount of tuples to ECPGfetch().
    Use this information to reduce network roundtrip to the backend
    in case a known-non-scrollable cursor and backward movement
    are used together. Use the recently exposed ecpg_prologue(), etc.

diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index c6e1667..45ae1f6 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -5289,9 +5289,16 @@ while (1)
      <term>-231 (<symbol>ECPG_INVALID_CURSOR</symbol>)</term>
      <listitem>
       <para>
+       This error code may occur in the following conditions.
+      </para>
+      <para>
        The cursor name you are trying to use is invalid.
        (SQLSTATE 34000)
       </para>
+      <para>
+       The cursor was declared to be non-scrollable and you are
+       trying to move or fetch backward. (SQLSTATE 55000)
+      </para>
      </listitem>
     </varlistentry>
 
diff --git a/src/interfaces/ecpg/ecpglib/cursor.c b/src/interfaces/ecpg/ecpglib/cursor.c
index 44b6b37..b9b3500 100644
--- a/src/interfaces/ecpg/ecpglib/cursor.c
+++ b/src/interfaces/ecpg/ecpglib/cursor.c
@@ -97,7 +97,8 @@ static struct cursor_descriptor *
 add_cursor(int lineno, struct connection *con,
 					const char *name,
 					int subxact_level,
-					bool with_hold)
+					bool with_hold,
+					enum ECPG_cursor_scroll scrollable)
 {
 	struct cursor_descriptor *desc, *prev;
 
@@ -123,6 +124,7 @@ add_cursor(int lineno, struct connection *con,
 
 	desc->subxact_level = subxact_level;
 	desc->with_hold = with_hold;
+	desc->scrollable = scrollable;
 
 	if (prev)
 	{
@@ -243,7 +245,8 @@ ecpg_commit_cursors(int lineno, struct connection * conn,
 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, ...)
+			const bool with_hold, enum ECPG_cursor_scroll scrollable,
+			const char *curname, const int st, const char *query, ...)
 {
 	struct connection *con = ecpg_get_connection(connection_name);
 	int		subxact_level;
@@ -270,26 +273,89 @@ ECPGopen(const int lineno, const int compat, const int force_indicator,
 		subxact_level =
 			(PQtransactionStatus(con->connection) != PQTRANS_IDLE ?
 										1 : 0);
-	add_cursor(lineno, con, curname, subxact_level, with_hold);
+	add_cursor(lineno, con, curname, subxact_level, with_hold, scrollable);
 
 	return true;
 }
 
 /*
+ * Canonicalize the amount of cursor movement.
+ */
+static bool
+ecpg_canonical_cursor_movement(enum ECPG_cursor_direction *direction, const char *amount,
+				bool *fetchall, int64 *amount_out)
+{
+	bool		negate = false;
+	int64		amount1;
+
+	/*
+	 * We might have got a constant string from the grammar.
+	 * We have to handle the negative and explicitely positive constants
+	 * here because e.g. '-2' arrives as '- 2' from the grammar.
+	 * strtoll() under Linux stops processing at the space.
+	 */
+	if (amount[0] == '-' || amount[0] == '+')
+	{
+		negate = (amount[0] == '-');
+		amount++;
+		while (*amount == ' ')
+			amount++;
+	}
+
+	/* FETCH/MOVE [ FORWARD | BACKWARD ] ALL */
+	if (strcmp(amount, "all") == 0)
+	{
+		*fetchall = true;
+		amount1 = 0;
+	}
+	else
+	{
+		char	   *endptr;
+
+		amount1 = strtoll(amount, &endptr, 10);
+
+		if (*endptr)
+			return false;
+
+		if (negate)
+			amount1 = -amount1;
+		*fetchall = false;
+	}
+
+	/*
+	 * Canonicalize ECPGc_backward but don't lose
+	 * FETCH BACKWARD ALL semantics.
+	 */
+	if ((*fetchall == false) && (*direction == ECPGc_backward))
+	{
+		amount1 = -amount1;
+		*direction = ECPGc_forward;
+	}
+
+	*amount_out = amount1;
+	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.
+ * reduces the the network roundtrip by:
+ * - returning early for an unknown cursor name
+ * - checking whether the cursor is scrollable against the direction
  */
 bool
 ECPGfetch(const int lineno, const int compat, const int force_indicator,
 				const char *connection_name, const bool questionmarks,
+				enum ECPG_cursor_direction dir, const char *amount,
 				const char *curname, const int st, const char *query, ...)
 {
 	struct connection  *con = ecpg_get_connection(connection_name);
 	struct cursor_descriptor *cur;
+	struct statement   *stmt;
+	int64		amount1;
+	bool		fetchall;
 	bool		ret;
 	va_list		args;
 
@@ -297,12 +363,67 @@ ECPGfetch(const int lineno, const int compat, const int force_indicator,
 		return false;
 
 	va_start(args, query);
-	ret = ecpg_do(lineno, compat, force_indicator, connection_name, questionmarks,
-									st,
-									query,
-									args);
+
+	if (!ecpg_do_prologue(lineno, compat, force_indicator,
+				connection_name, questionmarks,
+				(enum ECPG_statement_type) st,
+				query, args, &stmt))
+	{
+		ecpg_do_epilogue(stmt);
+		va_end(args);
+		return false;
+	}
+
 	va_end(args);
 
+	if (!ecpg_build_params(stmt, (dir >= ECPGc_absolute_in_var)))
+	{
+		ecpg_do_epilogue(stmt);
+		return false;
+	}
+
+	if (dir >= ECPGc_absolute_in_var)
+	{
+		dir -= ECPGc_absolute_in_var;
+		amount = stmt->cursor_amount;
+	}
+
+	if (!ecpg_canonical_cursor_movement(&dir, amount, &fetchall, &amount1))
+	{
+		ecpg_do_epilogue(stmt);
+		ecpg_raise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, amount);
+		con->client_side_error = true;
+		return false;
+	}
+
+	if (cur->scrollable == ECPGcs_no_scroll && (amount1 < 0 || dir == ECPGc_backward))
+	{
+		ecpg_do_epilogue(stmt);
+		ecpg_raise(lineno, ECPG_NUMERIC_FORMAT, ECPG_SQLSTATE_DATATYPE_MISMATCH, amount);
+		con->client_side_error = true;
+		return false;
+	}
+
+	if (!ecpg_autostart_transaction(stmt))
+	{
+		ecpg_do_epilogue(stmt);
+		return false;
+	}
+
+	if (!ecpg_execute(stmt))
+	{
+		ecpg_do_epilogue(stmt);
+		return false;
+	}
+
+	if (!ecpg_process_output(stmt, 0, PQntuples(stmt->results), LOOP_FORWARD, 0, true, false))
+	{
+		ecpg_do_epilogue(stmt);
+		return false;
+	}
+
+	ecpg_do_epilogue(stmt);
+
 	return ret;
 }
 
diff --git a/src/interfaces/ecpg/ecpglib/error.c b/src/interfaces/ecpg/ecpglib/error.c
index 70da2b9..b5b5550 100644
--- a/src/interfaces/ecpg/ecpglib/error.c
+++ b/src/interfaces/ecpg/ecpglib/error.c
@@ -218,6 +218,13 @@ ecpg_raise(int line, int code, const char *sqlstate, const char *str)
 			   translator: this string will be truncated at 149 characters expanded.  */
 					 ecpg_gettext("invalid cursorname \"%s\" on line %d"), str, line);
 			}
+			else if (strcmp(sqlstate, ECPG_SQLSTATE_OBJECT_NOT_IN_PREREQUISITE_STATE) == 0)
+			{
+				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
+			/*
+			   translator: this string will be truncated at 149 characters expanded.  */
+					 ecpg_gettext("cursor \"%s\" can only scan forward on line %d"), str, line);
+			}
 			else
 			{
 				snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 3f5997c..18e3461 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -105,6 +105,7 @@ free_statement(struct statement * stmt)
 	ecpg_free(stmt->command);
 	ecpg_free(stmt->name);
 	ecpg_free(stmt->oldlocale);
+	ecpg_free(stmt->cursor_amount);
 	ecpg_free(stmt);
 }
 
@@ -1133,7 +1134,7 @@ insert_tobeinserted(int position, int ph_len, struct statement * stmt, char *tob
  *	an array of strings for PQexecParams().
  */
 bool
-ecpg_build_params(struct statement * stmt)
+ecpg_build_params(struct statement * stmt, bool first_0_is_cursor_amount)
 {
 	struct variable *var;
 	int			desc_counter = 0;
@@ -1365,6 +1366,17 @@ ecpg_build_params(struct statement * stmt)
 		 */
 		else if (stmt->command[position] == '0')
 		{
+			if (first_0_is_cursor_amount)
+			{
+				stmt->cursor_amount = ecpg_strdup(tobeinserted, stmt->lineno);
+				if (stmt->cursor_amount == NULL)
+				{
+					ecpg_free_params(stmt, false);
+					return false;
+				}
+				first_0_is_cursor_amount = false;
+			}
+
 			if (!insert_tobeinserted(position, 2, stmt, tobeinserted))
 			{
 				ecpg_free_params(stmt, false);
@@ -2069,7 +2081,7 @@ ecpg_do(const int lineno, const int compat, const int force_indicator, const cha
 		return false;
 	}
 
-	if (!ecpg_build_params(stmt))
+	if (!ecpg_build_params(stmt, false))
 	{
 		ecpg_do_epilogue(stmt);
 		return false;
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index 5bb7ecd..bc54a84 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -66,6 +66,7 @@ struct statement
 	char	   *oldlocale;
 	int		nparams;
 	char	  **paramvalues;
+	char	   *cursor_amount;
 	PGresult   *results;
 };
 
@@ -98,6 +99,7 @@ struct cursor_descriptor {
 	 */
 	int		subxact_level;
 	bool		with_hold;
+	enum ECPG_cursor_scroll scrollable;
 };
 
 /* structure to store connections */
@@ -202,7 +204,7 @@ void		ecpg_free_params(struct statement *stmt, bool print);
 bool		ecpg_do_prologue(int, const int, const int, const char *, const bool,
 				  enum ECPG_statement_type, const char *, va_list,
 				  struct statement **);
-bool		ecpg_build_params(struct statement *);
+bool		ecpg_build_params(struct statement *, bool);
 bool		ecpg_autostart_transaction(struct statement * stmt);
 bool		ecpg_execute(struct statement * stmt);
 bool		ecpg_process_output(struct statement *, int, int, int, int, bool, bool);
@@ -249,6 +251,7 @@ void		ecpg_commit_cursors(int lineno, struct connection * conn, bool rollback, i
 #define ECPG_SQLSTATE_SYNTAX_ERROR			"42601"
 #define ECPG_SQLSTATE_DATATYPE_MISMATCH		"42804"
 #define ECPG_SQLSTATE_DUPLICATE_CURSOR		"42P03"
+#define ECPG_SQLSTATE_OBJECT_NOT_IN_PREREQUISITE_STATE	"55000"
 
 /* implementation-defined internal errors of ecpg */
 #define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR	"YE000"
diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h
index 1ac15d5..ace2d2c 100644
--- a/src/interfaces/ecpg/include/ecpglib.h
+++ b/src/interfaces/ecpg/include/ecpglib.h
@@ -65,8 +65,10 @@ char	   *ECPGerrmsg(void);
 
 /* Cursor functions */
 bool		ECPGopen(const int, const int, const int, const char *, const bool, const bool,
+				enum ECPG_cursor_scroll,
 				const char *, const int, const char *, ...);
 bool		ECPGfetch(const int, const int, const int, const char *, const bool,
+				enum ECPG_cursor_direction, const char *,
 				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 *, ...);
diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h
index 7cc47e9..72b8596 100644
--- a/src/interfaces/ecpg/include/ecpgtype.h
+++ b/src/interfaces/ecpg/include/ecpgtype.h
@@ -99,6 +99,25 @@ enum ECPG_statement_type
 	ECPGst_prepnormal
 };
 
+enum ECPG_cursor_direction
+{
+	ECPGc_absolute,
+	ECPGc_relative,
+	ECPGc_forward,
+	ECPGc_backward,
+	ECPGc_absolute_in_var,
+	ECPGc_relative_in_var,
+	ECPGc_forward_in_var,
+	ECPGc_backward_in_var
+};
+
+enum ECPG_cursor_scroll
+{
+	ECPGcs_unspecified,
+	ECPGcs_no_scroll,
+	ECPGcs_scroll
+};
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/interfaces/ecpg/preproc/ecpg.addons b/src/interfaces/ecpg/preproc/ecpg.addons
index df85424..a3bc1ad 100644
--- a/src/interfaces/ecpg/preproc/ecpg.addons
+++ b/src/interfaces/ecpg/preproc/ecpg.addons
@@ -130,6 +130,12 @@ ECPG: TransactionStmtROLLBACKPREPAREDSconst addon
 		transact_start = false;
 		transact_rollback = true;
 		transact_name = NULL;
+ECPG: cursor_options addon
+		current_cursor_scrollable = ECPGcs_unspecified;
+ECPG: cursor_optionscursor_optionsNOSCROLL addon
+		current_cursor_scrollable = ECPGcs_no_scroll;
+ECPG: cursor_optionscursor_optionsSCROLL addon
+		current_cursor_scrollable = ECPGcs_scroll;
 ECPG: stmtViewStmt rule
 	| ECPGAllocateDescr
 	{
@@ -303,6 +309,8 @@ ECPG: fetch_argscursor_name addon
 			free($1);
 			$1 = mm_strdup("$0");
 		}
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 ECPG: fetch_argsfrom_incursor_name addon
 		add_additional_variables($2, false);
 		if ($2[0] == ':')
@@ -310,10 +318,44 @@ ECPG: fetch_argsfrom_incursor_name addon
 			free($2);
 			$2 = mm_strdup("$0");
 		}
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 ECPG: fetch_argsNEXTopt_from_incursor_name addon
+		add_additional_variables($3, false);
+		if ($3[0] == ':')
+		{
+			free($3);
+			$3 = mm_strdup("$0");
+		}
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 ECPG: fetch_argsPRIORopt_from_incursor_name addon
+		add_additional_variables($3, false);
+		if ($3[0] == ':')
+		{
+			free($3);
+			$3 = mm_strdup("$0");
+		}
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("1"); 
 ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
+		add_additional_variables($3, false);
+		if ($3[0] == ':')
+		{
+			free($3);
+			$3 = mm_strdup("$0");
+		}
+		current_cursor_direction = ECPGc_absolute;
+		current_cursor_amount = mm_strdup("1");
 ECPG: fetch_argsLAST_Popt_from_incursor_name addon
+		add_additional_variables($3, false);
+		if ($3[0] == ':')
+		{
+			free($3);
+			$3 = mm_strdup("$0");
+		}
+		current_cursor_direction = ECPGc_absolute;
+		current_cursor_amount = mm_strdup("-1");
 ECPG: fetch_argsALLopt_from_incursor_name addon
 		add_additional_variables($3, false);
 		if ($3[0] == ':')
@@ -321,6 +363,8 @@ ECPG: fetch_argsALLopt_from_incursor_name addon
 			free($3);
 			$3 = mm_strdup("$0");
 		}
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("all");
 ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
 		add_additional_variables($3, false);
 		if ($3[0] == ':')
@@ -332,8 +376,23 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
 		{
 			free($1);
 			$1 = mm_strdup("$0");
+			current_cursor_direction = ECPGc_forward_in_var;
+			current_cursor_amount = NULL;
+		}
+		else
+		{
+			current_cursor_direction = ECPGc_forward;
+			current_cursor_amount = mm_strdup($1);
 		}
 ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
+		add_additional_variables($4, false);
+		if ($4[0] == ':')
+		{
+			free($4);
+			$4 = mm_strdup("$0");
+		}
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("all");
 ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
 		add_additional_variables($4, false);
 		if ($4[0] == ':')
@@ -341,9 +400,65 @@ ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
 			free($4);
 			$4 = mm_strdup("$0");
 		}
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("all");
 ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
+		add_additional_variables($4, false);
+		if ($4[0] == ':')
+		{
+			free($4);
+			$4 = mm_strdup("$0");
+		}
+		if ($2[0] == '$')
+		{
+			free($2);
+			$2 = mm_strdup("$0");
+			current_cursor_direction = ECPGc_absolute_in_var;
+			current_cursor_amount = NULL;
+		}
+		else
+		{
+			current_cursor_direction = ECPGc_absolute;
+			current_cursor_amount = mm_strdup($2);
+		}
 ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
+		add_additional_variables($4, false);
+		if ($4[0] == ':')
+		{
+			free($4);
+			$4 = mm_strdup("$0");
+		}
+		if ($2[0] == '$')
+		{
+			free($2);
+			$2 = mm_strdup("$0");
+			current_cursor_direction = ECPGc_relative_in_var;
+			current_cursor_amount = NULL;
+		}
+		else
+		{
+			current_cursor_direction = ECPGc_relative;
+			current_cursor_amount = mm_strdup($2);
+		}
 ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
+		add_additional_variables($4, false);
+		if ($4[0] == ':')
+		{
+			free($4);
+			$4 = mm_strdup("$0");
+		}
+		if ($2[0] == '$')
+		{
+			free($2);
+			$2 = mm_strdup("$0");
+			current_cursor_direction = ECPGc_forward_in_var;
+			current_cursor_amount = NULL;
+		}
+		else
+		{
+			current_cursor_direction = ECPGc_forward;
+			current_cursor_amount = mm_strdup($2);
+		}
 ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
 		add_additional_variables($4, false);
 		if ($4[0] == ':')
@@ -355,6 +470,13 @@ ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
 		{
 			free($2);
 			$2 = mm_strdup("$0");
+			current_cursor_direction = ECPGc_backward_in_var;
+			current_cursor_amount = NULL;
+		}
+		else
+		{
+			current_cursor_direction = ECPGc_backward;
+			current_cursor_amount = mm_strdup($2);
 		}
 ECPG: cursor_namename block
 		{
@@ -411,6 +533,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
 		this->connection = connection;
 		this->opened = false;
 		this->with_hold = (strncmp($5, "with ", 5) == 0);
+		this->scrollable = current_cursor_scrollable;
 		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;
@@ -518,48 +641,64 @@ ECPG: FetchStmtMOVEfetch_args rule
 	{
 		char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
 		add_additional_variables($3, false);
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("fetch forward"), cursor_marker);
 	}
 	| FETCH FORWARD from_in cursor_name opt_ecpg_fetch_into
 	{
 		char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
 		add_additional_variables($4, false);
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("fetch forward from"), cursor_marker);
 	}
 	| FETCH BACKWARD cursor_name opt_ecpg_fetch_into
 	{
 		char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
 		add_additional_variables($3, false);
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("fetch backward"), cursor_marker);
 	}
 	| FETCH BACKWARD from_in cursor_name opt_ecpg_fetch_into
 	{
 		char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
 		add_additional_variables($4, false);
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("fetch backward from"), cursor_marker);
 	}
 	| MOVE FORWARD cursor_name
 	{
 		char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
 		add_additional_variables($3, false);
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("move forward"), cursor_marker);
 	}
 	| MOVE FORWARD from_in cursor_name
 	{
 		char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
 		add_additional_variables($4, false);
+		current_cursor_direction = ECPGc_forward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("move forward from"), cursor_marker);
 	}
 	| MOVE BACKWARD cursor_name
 	{
 		char *cursor_marker = $3[0] == ':' ? mm_strdup("$0") : $3;
 		add_additional_variables($3, false);
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("move backward"), cursor_marker);
 	}
 	| MOVE BACKWARD from_in cursor_name
 	{
 		char *cursor_marker = $4[0] == ':' ? mm_strdup("$0") : $4;
 		add_additional_variables($4, false);
+		current_cursor_direction = ECPGc_backward;
+		current_cursor_amount = mm_strdup("1");
 		$$ = cat_str(2, mm_strdup("move backward from"), cursor_marker);
 	}
 ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header
index eb3511c..30dac39 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -36,6 +36,10 @@ int struct_level = 0;
 int braces_open; /* brace level counter */
 char *current_function;
 char *current_cursor = NULL;
+enum ECPGttype current_cursor_vartype;
+enum ECPG_cursor_direction current_cursor_direction;
+enum ECPG_cursor_scroll current_cursor_scrollable;
+char *current_cursor_amount = NULL;
 bool transact_prepared = false;
 bool transact_start = false;
 bool transact_rollback = false;
diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 71a802f..276735a 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -317,6 +317,7 @@ ECPGCursorStmt:  DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared
 			this->connection = connection;
 			this->opened = false;
 			this->with_hold = (strncmp($5, "with ", 5) == 0);
+			this->scrollable = current_cursor_scrollable;
 			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;
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index f3d39ce..134b581 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -31,7 +31,10 @@ extern int	braces_open,
 			ecpg_internal_var;
 extern char *current_function;
 extern char *current_cursor;
-enum ECPGttype current_cursor_vartype;
+extern enum ECPGttype current_cursor_vartype;
+extern enum ECPG_cursor_direction current_cursor_direction;
+extern enum ECPG_cursor_scroll current_cursor_scrollable;
+extern char *current_cursor_amount;
 extern char *descriptor_index;
 extern char *descriptor_name;
 extern char *connection;
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index a49b89c..22fb67e 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -125,6 +125,23 @@ static char *ecpg_statement_type_name[] = {
 	"ECPGst_prepnormal"
 };
 
+static char *ecpg_cursor_direction_name[] = {
+	"ECPGc_absolute",
+	"ECPGc_relative",
+	"ECPGc_forward",
+	"ECPGc_backward",
+	"ECPGc_absolute_in_var",
+	"ECPGc_relative_in_var",
+	"ECPGc_forward_in_var",
+	"ECPGc_backward_in_var"
+};
+
+static char *ecpg_cursor_scroll_name[] = {
+	"ECPGcs_unspecified",
+	"ECPGcs_no_scroll",
+	"ECPGcs_scroll"
+};
+
 static void output_cursor_name(struct cursor *ptr)
 {
 	if (current_cursor[0] == ':')
@@ -226,7 +243,9 @@ 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);
+	fprintf(yyout, "{ ECPGopen(__LINE__, %d, %d, %s, %d, %d, %s, ",
+						compat, force_indicator, connection ? connection : "NULL", questionmarks,
+						ptr->with_hold, ecpg_cursor_scroll_name[ptr->scrollable]);
 	output_cursor_name(ptr);
 	output_statement_epilogue(stmt, whenever_mode, st);
 }
@@ -235,10 +254,24 @@ void
 output_fetch_statement(char *stmt, int whenever_mode, enum ECPG_statement_type st)
 {
 	struct cursor *ptr = get_cursor(current_cursor);
+	char	   *amount;
+
+	if (current_cursor_amount)
+	{
+		amount = mm_alloc(strlen(current_cursor_amount) + 3);
+		sprintf(amount, "\"%s\"", current_cursor_amount);
+		free(current_cursor_amount);
+	}
+	else
+		amount = mm_strdup("NULL");
 
-	fprintf(yyout, "{ ECPGfetch(__LINE__, %d, %d, %s, %d, ", compat, force_indicator, connection ? connection : "NULL", questionmarks);
+	fprintf(yyout, "{ ECPGfetch(__LINE__, %d, %d, %s, %d, %s, %s, ",
+						compat, force_indicator, connection ? connection : "NULL", questionmarks,
+						ecpg_cursor_direction_name[current_cursor_direction], amount);
 	output_cursor_name(ptr);
 	output_statement_epilogue(stmt, whenever_mode, st);
+	free(amount);
+	current_cursor_amount = NULL;
 }
 
 void
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index a293e9e..f0a26f5 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -131,6 +131,7 @@ struct cursor
 	bool		opened;
 	bool		with_hold;
 	enum ECPGttype	vartype;
+	enum ECPG_cursor_scroll scrollable;
 	struct arguments *argsinsert;
 	struct arguments *argsinsert_oos;
 	struct arguments *argsresult;
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
index e47b373..ceb95c1 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.c
@@ -241,7 +241,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "mycur1", ECPGst_normal, "declare mycur1 cursor for $1", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -258,7 +258,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "mycur1", ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, ECPGc_forward, "1", "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"
@@ -316,7 +316,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "mycur2", ECPGst_normal, "declare mycur2 cursor for $1", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -333,7 +333,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "mycur2", ECPGst_normal, "fetch from mycur2", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, ECPGc_forward, "1", "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"
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 f88f9f2..8258bcc 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
+++ b/src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
@@ -158,7 +158,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
 
 	while (1)
 	{
-		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, "c", ECPGst_normal, "fetch forward c", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 1, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -244,7 +244,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
 
 static void openit(void)
 {
-	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, "c", ECPGst_normal, "declare c cursor for select * from test where i <= $1 ", 
+	{ ECPGopen(__LINE__, 1, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
diff --git a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
index 715f960..f055ae6 100644
--- a/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
+++ b/src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c
@@ -82,7 +82,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	/* declare cur cursor for select id , d , d from nantest1 */
 #line 33 "nan_test.pgc"
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur", ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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 ( );}
@@ -90,7 +90,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 
 	while (1)
 	{
-		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -137,7 +137,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 #line 48 "nan_test.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur", ECPGst_normal, "declare cur cursor for select id , d , d from nantest1", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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 ( );}
@@ -145,7 +145,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 
 	while (1)
 	{
-		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch from cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -221,7 +221,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 	/* declare cur1 cursor for select id , d , d from nantest2 */
 #line 75 "nan_test.pgc"
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur1", ECPGst_normal, "declare cur1 cursor for select id , d , d from nantest2", ECPGt_EOIT, ECPGt_EORT);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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 ( );}
@@ -229,7 +229,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
 
 	while (1)
 	{
-		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "fetch from cur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
diff --git a/src/interfaces/ecpg/test/expected/preproc-autoprep.c b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
index 8872986..2a9d890 100644
--- a/src/interfaces/ecpg/test/expected/preproc-autoprep.c
+++ b/src/interfaces/ecpg/test/expected/preproc-autoprep.c
@@ -133,7 +133,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 35 "autoprep.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select Item1 from T", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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();
@@ -143,7 +143,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "autoprep.pgc"
 
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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"
@@ -180,7 +180,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 46 "autoprep.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "cur1", ECPGst_normal, "declare cur1 cursor for $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -199,7 +199,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   i = 0;
   while (1)
   {
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur1", ECPGst_normal, "fetch cur1", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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"
diff --git a/src/interfaces/ecpg/test/expected/preproc-cursor.c b/src/interfaces/ecpg/test/expected/preproc-cursor.c
index 6f92797..8ba2987 100644
--- a/src/interfaces/ecpg/test/expected/preproc-cursor.c
+++ b/src/interfaces/ecpg/test/expected/preproc-cursor.c
@@ -187,7 +187,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname1, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, ECPGcs_unspecified, 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"
@@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch forward from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -212,7 +212,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch forward $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -227,7 +227,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -243,7 +243,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -260,7 +260,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move in");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "move absolute 0 in $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_absolute, "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"
@@ -270,7 +270,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -286,7 +286,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname1, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -323,7 +323,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname2, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, ECPGcs_unspecified, 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), 
@@ -337,7 +337,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -352,7 +352,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -367,7 +367,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -383,7 +383,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -400,7 +400,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_absolute, "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), 
@@ -414,7 +414,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -430,7 +430,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname2, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -483,7 +483,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname3, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, ECPGcs_unspecified, 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), 
@@ -493,7 +493,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 if (sqlca.sqlcode < 0) exit (1);}
 #line 153 "cursor.pgc"
 
-	{ ECPGopen(__LINE__, 0, 1, "test2", 0, 0, curname5, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test2", 0, 0, ECPGcs_unspecified, 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), 
@@ -505,7 +505,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch");
-	{ ECPGfetch(__LINE__, 0, 1, "test2", 0, curname5, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test2", 0, ECPGc_forward, "1", 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), 
@@ -520,7 +520,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -535,7 +535,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -551,7 +551,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -568,7 +568,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_absolute, "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"
@@ -578,7 +578,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -594,7 +594,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname3, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -663,7 +663,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, curname4.arr, ECPGst_normal, "declare $0 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, "test1", 0, 0, ECPGcs_unspecified, 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), 
@@ -675,7 +675,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -690,7 +690,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -705,7 +705,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "fetch 1 from");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch 1 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -721,7 +721,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count from");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0 from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
@@ -738,7 +738,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	printf("%d %s\n", id, t);
 
 	strcpy(msg, "move");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "move absolute 0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_absolute, "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"
@@ -748,7 +748,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch 1");
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch 1 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward, "1", 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), 
@@ -764,7 +764,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 	strcpy(msg, "fetch :count");
 	count = 1;
-	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, curname4.arr, ECPGst_normal, "fetch $0 $0", 
+	{ ECPGfetch(__LINE__, 0, 1, "test1", 0, ECPGc_forward_in_var, NULL, 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), 
diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.c b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
index 99d181e..36dbea7 100644
--- a/src/interfaces/ecpg/test/expected/preproc-outofscope.c
+++ b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
@@ -201,7 +201,7 @@ get_var1(MYTYPE **myvar0, MYNULLTYPE **mynullvar0)
 static void
 open_cur1(void)
 {
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur", ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "mycur", ECPGst_normal, "declare mycur cursor for select * from a1", ECPGt_EOIT, 
 	ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
@@ -225,7 +225,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 static void
 get_record1(void)
 {
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur", ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "mycur", ECPGst_normal, "fetch mycur", ECPGt_EOIT, 
 	ECPGt_int,&((*( MYTYPE  *)(ECPGget_var( 0)) ).id),(long)1,(long)1,sizeof(int), 
 	ECPGt_int,&((*( MYNULLTYPE  *)(ECPGget_var( 1)) ).id),(long)1,(long)1,sizeof(int), 
 	ECPGt_char,&((*( MYTYPE  *)(ECPGget_var( 0)) ).t),(long)64,(long)1,(64)*sizeof(char), 
diff --git a/src/interfaces/ecpg/test/expected/preproc-variable.c b/src/interfaces/ecpg/test/expected/preproc-variable.c
index 67d66a5..b227d31 100644
--- a/src/interfaces/ecpg/test/expected/preproc-variable.c
+++ b/src/interfaces/ecpg/test/expected/preproc-variable.c
@@ -190,7 +190,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ 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);
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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);}
@@ -206,7 +206,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	memset(i, 0, sizeof(ind_personal));
 	while (1) {
 		strcpy(msg, "fetch");
-		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "cur", ECPGst_normal, "fetch cur", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "cur", ECPGst_normal, "fetch cur", ECPGt_EOIT, 
 	ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)1,sizeof(struct varchar_1), 
 	ECPGt_int,&(i->ind_name),(long)1,(long)1,sizeof(int), 
 	ECPGt_long,&(p->birth.born),(long)1,(long)1,sizeof(long), 
diff --git a/src/interfaces/ecpg/test/expected/sql-binary.c b/src/interfaces/ecpg/test/expected/sql-binary.c
index 8826cca..26e9655 100644
--- a/src/interfaces/ecpg/test/expected/sql-binary.c
+++ b/src/interfaces/ecpg/test/expected/sql-binary.c
@@ -111,12 +111,12 @@ main (void)
  /* declare C cursor for select name , accs , byte from empl where idnum = $1  */
 #line 58 "binary.pgc"
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select name , accs , byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch C", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -142,12 +142,12 @@ main (void)
  /* declare B binary cursor for select name , accs , byte from empl where idnum = $1  */
 #line 72 "binary.pgc"
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "B", ECPGst_normal, "declare B binary cursor for select name , accs , byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "B", ECPGst_normal, "fetch B", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -176,12 +176,12 @@ main (void)
  /* declare A binary cursor for select byte from empl where idnum = $1  */
 #line 89 "binary.pgc"
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "A", ECPGst_normal, "declare A binary cursor for select byte from empl where idnum = $1 ", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "A", ECPGst_normal, "fetch A", ECPGt_EOIT, 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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"
diff --git a/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c
index 25eaa02..6dca2e6 100644
--- a/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c
+++ b/src/interfaces/ecpg/test/expected/sql-cursorsubxact.c
@@ -90,7 +90,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "cursorsubxact.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 39 "cursorsubxact.pgc"
@@ -122,7 +122,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
 	curname = QUOTED_CURNAME;
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 57 "cursorsubxact.pgc"
@@ -181,7 +181,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 83 "cursorsubxact.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 85 "cursorsubxact.pgc"
@@ -232,7 +232,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("savepoint (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 107 "cursorsubxact.pgc"
@@ -288,7 +288,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("rollback to (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", 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), 
@@ -351,7 +351,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("savepoint (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 158 "cursorsubxact.pgc"
@@ -362,7 +362,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("open 5 failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", 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), 
@@ -388,7 +388,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("rollback to (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", 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), 
@@ -405,7 +405,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	else
 		printf("fetch result (2) %d '%s'\n", id[1], t[2].arr);
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 178 "cursorsubxact.pgc"
@@ -425,7 +425,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("rollback to (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, curname, ECPGst_normal, "declare $0 cursor for select id , t from t1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, 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 186 "cursorsubxact.pgc"
@@ -445,7 +445,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	if (sqlca.sqlcode < 0)
 		printf("release savepoint (a) failed with SQLSTATE %5s\n", sqlca.sqlstate);
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, curname, ECPGst_normal, "fetch from $0", 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", 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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-desc.c b/src/interfaces/ecpg/test/expected/sql-desc.c
index 6999768..2007112 100644
--- a/src/interfaces/ecpg/test/expected/sql-desc.c
+++ b/src/interfaces/ecpg/test/expected/sql-desc.c
@@ -245,7 +245,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	/* declare c1 cursor for $1 */
 #line 57 "desc.pgc"
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "c1", ECPGst_normal, "declare c1 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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", 0L, 0L, 0L, 
@@ -256,7 +256,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 58 "desc.pgc"
 
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "c1", ECPGst_normal, "fetch next from c1", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -295,7 +295,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 	/* declare c2 cursor for $1 */
 #line 69 "desc.pgc"
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "c2", ECPGst_normal, "declare c2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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", 0L, 0L, 0L, 
@@ -306,7 +306,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 70 "desc.pgc"
 
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "c2", ECPGst_normal, "fetch next from c2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-dyntest.c b/src/interfaces/ecpg/test/expected/sql-dyntest.c
index 7856a51..4571aee 100644
--- a/src/interfaces/ecpg/test/expected/sql-dyntest.c
+++ b/src/interfaces/ecpg/test/expected/sql-dyntest.c
@@ -261,7 +261,7 @@ if (sqlca.sqlcode < 0) error ( );}
 #line 58 "dyntest.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "MYCURS", ECPGst_normal, "declare MYCURS cursor for $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -272,7 +272,7 @@ if (sqlca.sqlcode < 0) error ( );}
 
   while (1)
     {
-      { ECPGfetch(__LINE__, 0, 1, NULL, 0, "MYCURS", ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT, 
+      { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "MYCURS", ECPGst_normal, "fetch in MYCURS", ECPGt_EOIT, 
 	ECPGt_descriptor, "MYDESC", 0L, 0L, 0L, 
 	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
 #line 64 "dyntest.pgc"
diff --git a/src/interfaces/ecpg/test/expected/sql-execute.c b/src/interfaces/ecpg/test/expected/sql-execute.c
index 326a3c3..ef1e4dd 100644
--- a/src/interfaces/ecpg/test/expected/sql-execute.c
+++ b/src/interfaces/ecpg/test/expected/sql-execute.c
@@ -140,7 +140,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 50 "execute.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "CUR", ECPGst_normal, "declare CUR cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -148,7 +148,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 52 "execute.pgc"
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "CUR", ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "8", "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), 
@@ -205,7 +205,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 72 "execute.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "CUR2", ECPGst_normal, "declare CUR2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"), 
@@ -215,7 +215,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 74 "execute.pgc"
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "CUR2", ECPGst_normal, "fetch in CUR2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-fetch.c b/src/interfaces/ecpg/test/expected/sql-fetch.c
index 48bdaaf..70a50ba 100644
--- a/src/interfaces/ecpg/test/expected/sql-fetch.c
+++ b/src/interfaces/ecpg/test/expected/sql-fetch.c
@@ -99,7 +99,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 26 "fetch.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select * from My_Table", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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();
@@ -113,7 +113,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 30 "fetch.pgc"
 
   while (1) {
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch 1 in C", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
@@ -135,7 +135,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
   /* exec sql whenever not found  continue ; */
 #line 36 "fetch.pgc"
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_backward, "2", "C", ECPGst_normal, "move backward 2 in C", ECPGt_EOIT, ECPGt_EORT);
 #line 37 "fetch.pgc"
 
 if (sqlca.sqlwarn[0] == 'W') sqlprint();
@@ -145,7 +145,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 37 "fetch.pgc"
 
 
-  { ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch $0 in C", 
+  { ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward_in_var, NULL, "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), 
@@ -176,7 +176,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 44 "fetch.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "D", ECPGst_normal, "declare D cursor for select * from My_Table where Item1 = $1", 
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -192,7 +192,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 48 "fetch.pgc"
 
   while (1) {
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "D", ECPGst_normal, "fetch 1 in D", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-oldexec.c b/src/interfaces/ecpg/test/expected/sql-oldexec.c
index a3f8948..361091f 100644
--- a/src/interfaces/ecpg/test/expected/sql-oldexec.c
+++ b/src/interfaces/ecpg/test/expected/sql-oldexec.c
@@ -140,7 +140,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 50 "oldexec.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, "CUR", ECPGst_normal, "declare CUR cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, ECPGcs_unspecified, "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"
@@ -148,7 +148,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 52 "oldexec.pgc"
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, "CUR", ECPGst_normal, "fetch 8 in CUR", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, ECPGc_forward, "8", "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), 
@@ -199,7 +199,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 71 "oldexec.pgc"
 
 
-	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, "CUR3", ECPGst_normal, "declare CUR3 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 1, 0, ECPGcs_unspecified, "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"), 
@@ -209,7 +209,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 if (sqlca.sqlcode < 0) sqlprint();}
 #line 73 "oldexec.pgc"
 
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, "CUR3", ECPGst_normal, "fetch in CUR3", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 1, ECPGc_forward, "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-quote.c b/src/interfaces/ecpg/test/expected/sql-quote.c
index bfb75ca..eae10d4 100644
--- a/src/interfaces/ecpg/test/expected/sql-quote.c
+++ b/src/interfaces/ecpg/test/expected/sql-quote.c
@@ -162,7 +162,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 #line 43 "quote.pgc"
 
 
-  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "C", ECPGst_normal, "declare C cursor for select * from \"My_Table\"", ECPGt_EOIT, ECPGt_EORT);
+  { ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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();
@@ -178,7 +178,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
 
   while (true)
   {
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "C", ECPGst_normal, "fetch C", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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), 
diff --git a/src/interfaces/ecpg/test/expected/sql-sqlda.c b/src/interfaces/ecpg/test/expected/sql-sqlda.c
index 83804f5..253ccc3 100644
--- a/src/interfaces/ecpg/test/expected/sql-sqlda.c
+++ b/src/interfaces/ecpg/test/expected/sql-sqlda.c
@@ -251,7 +251,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur1", ECPGst_normal, "declare mycur1 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -268,7 +268,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 	while (1)
 	{
 		strcpy(msg, "fetch");
-		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur1", ECPGst_normal, "fetch 1 from mycur1", ECPGt_EOIT, 
+		{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "1", "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"
@@ -324,7 +324,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "open");
-	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, "mycur2", ECPGst_normal, "declare mycur2 cursor for $1", 
+	{ ECPGopen(__LINE__, 0, 1, NULL, 0, 0, ECPGcs_unspecified, "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"
@@ -334,7 +334,7 @@ if (sqlca.sqlcode < 0) exit (1);}
 
 
 	strcpy(msg, "fetch");
-	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, "mycur2", ECPGst_normal, "fetch all from mycur2", ECPGt_EOIT, 
+	{ ECPGfetch(__LINE__, 0, 1, NULL, 0, ECPGc_forward, "all", "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"
