From 550de5db2c36badc508d8d6116643fef994b9c38 Mon Sep 17 00:00:00 2001
From: Byron Nikolaidis <byronn@insightdist.com>
Date: Tue, 29 Dec 1998 14:59:30 +0000
Subject: [PATCH] Minor fixes to compile on unix for v6-40-0002

---
 src/interfaces/odbc/execute.c   |   2 +
 src/interfaces/odbc/misc.h      |   2 +-
 src/interfaces/odbc/options.c   |   6 ++
 src/interfaces/odbc/qresult.c   |   2 +-
 src/interfaces/odbc/qresult.h   |   2 +-
 src/interfaces/odbc/results.c   | 133 -------------------------------
 src/interfaces/odbc/statement.c | 136 ++++++++++++++++++++++++++++++++
 src/interfaces/odbc/statement.h |   3 +-
 8 files changed, 149 insertions(+), 137 deletions(-)

diff --git a/src/interfaces/odbc/execute.c b/src/interfaces/odbc/execute.c
index cad5a5ca15f..59cfa450a10 100644
--- a/src/interfaces/odbc/execute.c
+++ b/src/interfaces/odbc/execute.c
@@ -372,8 +372,10 @@ RETCODE SQL_API SQLCancel(
 static char *func="SQLCancel";
 StatementClass *stmt = (StatementClass *) hstmt;
 RETCODE result;
+#ifdef WIN32
 HMODULE hmodule;
 FARPROC addr;
+#endif
 
 	mylog( "%s: entering...\n", func);
 
diff --git a/src/interfaces/odbc/misc.h b/src/interfaces/odbc/misc.h
index 8eca682d5aa..10cb5114d13 100644
--- a/src/interfaces/odbc/misc.h
+++ b/src/interfaces/odbc/misc.h
@@ -26,7 +26,7 @@
 	portion of the registry.  You may have to manually add this key.
 	This logfile is intended for development use, not for an end user!
 */
-// #define MY_LOG
+#define MY_LOG
 
 
 /*	Uncomment Q_LOG to compile in the qlog() statements (Communications log, i.e. CommLog).
diff --git a/src/interfaces/odbc/options.c b/src/interfaces/odbc/options.c
index a263c98c2dd..6621acadf54 100644
--- a/src/interfaces/odbc/options.c
+++ b/src/interfaces/odbc/options.c
@@ -36,6 +36,12 @@
 
 extern GLOBAL_VALUES globals;
 
+RETCODE set_statement_option(ConnectionClass *conn, 
+							 StatementClass *stmt, 
+							 UWORD   fOption,
+							 UDWORD  vParam);
+
+
 
 RETCODE set_statement_option(ConnectionClass *conn, 
 							 StatementClass *stmt, 
diff --git a/src/interfaces/odbc/qresult.c b/src/interfaces/odbc/qresult.c
index 8e5ffdf55c2..c13b992b9b5 100644
--- a/src/interfaces/odbc/qresult.c
+++ b/src/interfaces/odbc/qresult.c
@@ -77,7 +77,7 @@ QR_inc_base(QResultClass *self, int base_inc)
 /************************************/
 
 QResultClass *
-QR_Constructor()
+QR_Constructor(void)
 {
 QResultClass *rv;
 
diff --git a/src/interfaces/odbc/qresult.h b/src/interfaces/odbc/qresult.h
index f26381fc215..efb60eefe0e 100644
--- a/src/interfaces/odbc/qresult.h
+++ b/src/interfaces/odbc/qresult.h
@@ -98,7 +98,7 @@ struct QResultClass_ {
 #define QR_get_status(self)				(self->status)
 
 //	Core Functions
-QResultClass *QR_Constructor();
+QResultClass *QR_Constructor(void);
 void QR_Destructor(QResultClass *self);
 char QR_read_tuple(QResultClass *self, char binary);
 int QR_next_tuple(QResultClass *self);
diff --git a/src/interfaces/odbc/results.c b/src/interfaces/odbc/results.c
index 7f18f6a205f..7595fd5e3ba 100644
--- a/src/interfaces/odbc/results.c
+++ b/src/interfaces/odbc/results.c
@@ -740,139 +740,6 @@ mylog("SQLGetData: enter, stmt=%u\n", stmt);
     }
 }
 
-RETCODE
-SC_fetch(StatementClass *stmt)
-{
-static char *func = "SC_fetch";
-QResultClass *res = stmt->result;
-int retval, result;
-Int2 num_cols, lf;
-Oid type;
-char *value;
-ColumnInfoClass *ci;
-// TupleField *tupleField;
-
-	stmt->last_fetch_count = 0;
-	ci = QR_get_fields(res);		/* the column info */
-
-	mylog("manual_result = %d, use_declarefetch = %d\n", stmt->manual_result, globals.use_declarefetch);
- 
-	if ( stmt->manual_result || ! globals.use_declarefetch) {
-
-		if (stmt->currTuple >= QR_get_num_tuples(res) -1 || 
-			(stmt->options.maxRows > 0 && stmt->currTuple == stmt->options.maxRows - 1)) {
-
-			/*	if at the end of the tuples, return "no data found" 
-				and set the cursor past the end of the result set 
-			*/
-			stmt->currTuple = QR_get_num_tuples(res);	
-			return SQL_NO_DATA_FOUND;
-		}
- 
-		mylog("**** SQLFetch: manual_result\n");
-		(stmt->currTuple)++;
-	}
-	else {
-
-		// read from the cache or the physical next tuple
-		retval = QR_next_tuple(res);
-		if (retval < 0) {
-			mylog("**** SQLFetch: end_tuples\n");
-			return SQL_NO_DATA_FOUND;
-		}
-		else if (retval > 0)
-			(stmt->currTuple)++;		// all is well
-
-		else {
-			mylog("SQLFetch: error\n");
-			stmt->errornumber = STMT_EXEC_ERROR;
-			stmt->errormsg = "Error fetching next row";
-			SC_log_error(func, "", stmt);
-			return SQL_ERROR;
-		}
-	}
-
-	num_cols = QR_NumResultCols(res);
-
-	result = SQL_SUCCESS;
-	stmt->last_fetch_count = 1;
-
-	for (lf=0; lf < num_cols; lf++) {
-
-		mylog("fetch: cols=%d, lf=%d, stmt = %u, stmt->bindings = %u, buffer[] = %u\n", num_cols, lf, stmt, stmt->bindings, stmt->bindings[lf].buffer);
-
-		/*	reset for SQLGetData */
-		stmt->bindings[lf].data_left = -1;
-
-		if (stmt->bindings[lf].buffer != NULL) {
-            // this column has a binding
-
-            // type = QR_get_field_type(res, lf);
-			type = CI_get_oid(ci, lf);		/* speed things up */
-
-			mylog("type = %d\n", type);
-
-			if (stmt->manual_result) {
-				value = QR_get_value_manual(res, stmt->currTuple, lf);
-				mylog("manual_result\n");
-			}
-			else if (globals.use_declarefetch)
-				value = QR_get_value_backend(res, lf);
-			else {
-				value = QR_get_value_backend_row(res, stmt->currTuple, lf);
-			}
-
-			mylog("value = '%s'\n",  (value==NULL)?"<NULL>":value);
-
-			retval = copy_and_convert_field_bindinfo(stmt, type, value, lf);
-
-			mylog("copy_and_convert: retval = %d\n", retval);
-
-			switch(retval) {
-			case COPY_OK:
-				break;	/*	OK, do next bound column */
-
-			case COPY_UNSUPPORTED_TYPE:
-				stmt->errormsg = "Received an unsupported type from Postgres.";
-				stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
-				SC_log_error(func, "", stmt);
-				result = SQL_ERROR;
-				break;
-
-			case COPY_UNSUPPORTED_CONVERSION:
-				stmt->errormsg = "Couldn't handle the necessary data type conversion.";
-				stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
-				SC_log_error(func, "", stmt);
-				result = SQL_ERROR;
-				break;
-
-			case COPY_RESULT_TRUNCATED:
-				stmt->errornumber = STMT_TRUNCATED;
-				stmt->errormsg = "The buffer was too small for the result.";
-				result = SQL_SUCCESS_WITH_INFO;
-				break;
-
-			case COPY_GENERAL_ERROR:	/* error msg already filled in */
-				SC_log_error(func, "", stmt);
-				result = SQL_ERROR;
-				break;
-
-			/*  This would not be meaningful in SQLFetch. */
-			case COPY_NO_DATA_FOUND:
-				break;
-
-			default:
-				stmt->errormsg = "Unrecognized return value from copy_and_convert_field.";
-				stmt->errornumber = STMT_INTERNAL_ERROR;
-				SC_log_error(func, "", stmt);
-				result = SQL_ERROR;
-				break;
-			}
-		}
-	}
-
-	return result;
-}
 
 
 //      Returns data for bound columns in the current row ("hstmt->iCursor"),
diff --git a/src/interfaces/odbc/statement.c b/src/interfaces/odbc/statement.c
index f185e2220a4..86bce41a8f9 100644
--- a/src/interfaces/odbc/statement.c
+++ b/src/interfaces/odbc/statement.c
@@ -566,6 +566,142 @@ char rv;
 	return rv;
 }
 
+
+RETCODE
+SC_fetch(StatementClass *self)
+{
+static char *func = "SC_fetch";
+QResultClass *res = self->result;
+int retval, result;
+Int2 num_cols, lf;
+Oid type;
+char *value;
+ColumnInfoClass *ci;
+// TupleField *tupleField;
+
+	self->last_fetch_count = 0;
+	ci = QR_get_fields(res);		/* the column info */
+
+	mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, globals.use_declarefetch);
+ 
+	if ( self->manual_result || ! globals.use_declarefetch) {
+
+		if (self->currTuple >= QR_get_num_tuples(res) -1 || 
+			(self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1)) {
+
+			/*	if at the end of the tuples, return "no data found" 
+				and set the cursor past the end of the result set 
+			*/
+			self->currTuple = QR_get_num_tuples(res);	
+			return SQL_NO_DATA_FOUND;
+		}
+ 
+		mylog("**** SQLFetch: manual_result\n");
+		(self->currTuple)++;
+	}
+	else {
+
+		// read from the cache or the physical next tuple
+		retval = QR_next_tuple(res);
+		if (retval < 0) {
+			mylog("**** SQLFetch: end_tuples\n");
+			return SQL_NO_DATA_FOUND;
+		}
+		else if (retval > 0)
+			(self->currTuple)++;		// all is well
+
+		else {
+			mylog("SQLFetch: error\n");
+			self->errornumber = STMT_EXEC_ERROR;
+			self->errormsg = "Error fetching next row";
+			SC_log_error(func, "", self);
+			return SQL_ERROR;
+		}
+	}
+
+	num_cols = QR_NumResultCols(res);
+
+	result = SQL_SUCCESS;
+	self->last_fetch_count = 1;
+
+	for (lf=0; lf < num_cols; lf++) {
+
+		mylog("fetch: cols=%d, lf=%d, self = %u, self->bindings = %u, buffer[] = %u\n", num_cols, lf, self, self->bindings, self->bindings[lf].buffer);
+
+		/*	reset for SQLGetData */
+		self->bindings[lf].data_left = -1;
+
+		if (self->bindings[lf].buffer != NULL) {
+            // this column has a binding
+
+            // type = QR_get_field_type(res, lf);
+			type = CI_get_oid(ci, lf);		/* speed things up */
+
+			mylog("type = %d\n", type);
+
+			if (self->manual_result) {
+				value = QR_get_value_manual(res, self->currTuple, lf);
+				mylog("manual_result\n");
+			}
+			else if (globals.use_declarefetch)
+				value = QR_get_value_backend(res, lf);
+			else {
+				value = QR_get_value_backend_row(res, self->currTuple, lf);
+			}
+
+			mylog("value = '%s'\n",  (value==NULL)?"<NULL>":value);
+
+			retval = copy_and_convert_field_bindinfo(self, type, value, lf);
+
+			mylog("copy_and_convert: retval = %d\n", retval);
+
+			switch(retval) {
+			case COPY_OK:
+				break;	/*	OK, do next bound column */
+
+			case COPY_UNSUPPORTED_TYPE:
+				self->errormsg = "Received an unsupported type from Postgres.";
+				self->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
+				SC_log_error(func, "", self);
+				result = SQL_ERROR;
+				break;
+
+			case COPY_UNSUPPORTED_CONVERSION:
+				self->errormsg = "Couldn't handle the necessary data type conversion.";
+				self->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
+				SC_log_error(func, "", self);
+				result = SQL_ERROR;
+				break;
+
+			case COPY_RESULT_TRUNCATED:
+				self->errornumber = STMT_TRUNCATED;
+				self->errormsg = "The buffer was too small for the result.";
+				result = SQL_SUCCESS_WITH_INFO;
+				break;
+
+			case COPY_GENERAL_ERROR:	/* error msg already filled in */
+				SC_log_error(func, "", self);
+				result = SQL_ERROR;
+				break;
+
+			/*  This would not be meaningful in SQLFetch. */
+			case COPY_NO_DATA_FOUND:
+				break;
+
+			default:
+				self->errormsg = "Unrecognized return value from copy_and_convert_field.";
+				self->errornumber = STMT_INTERNAL_ERROR;
+				SC_log_error(func, "", self);
+				result = SQL_ERROR;
+				break;
+			}
+		}
+	}
+
+	return result;
+}
+
+
 RETCODE SC_execute(StatementClass *self)
 {
 static char *func="SC_execute";
diff --git a/src/interfaces/odbc/statement.h b/src/interfaces/odbc/statement.h
index 32a93a29659..4349e9e004b 100644
--- a/src/interfaces/odbc/statement.h
+++ b/src/interfaces/odbc/statement.h
@@ -202,7 +202,8 @@ char SC_recycle_statement(StatementClass *self);
 void SC_clear_error(StatementClass *self);
 char SC_get_error(StatementClass *self, int *number, char **message);
 char *SC_create_errormsg(StatementClass *self);
-RETCODE SC_execute(StatementClass *stmt);
+RETCODE SC_execute(StatementClass *self);
+RETCODE SC_fetch(StatementClass *self);
 void SC_free_params(StatementClass *self, char option);
 void SC_log_error(char *func, char *desc, StatementClass *self);
 
-- 
GitLab