Back out all ODBC formatting changes, and back out removal of <6.4
authorBruce Momjian <[email protected]>
Wed, 14 Feb 2001 05:45:46 +0000 (05:45 +0000)
committerBruce Momjian <[email protected]>
Wed, 14 Feb 2001 05:45:46 +0000 (05:45 +0000)
protocol. I have left in Tom's SOCK_get_next_byte() fix, and the new
win32.mak file addition.  I have also left in the 'X' connection close
fix.

45 files changed:
src/interfaces/odbc/GNUmakefile
src/interfaces/odbc/bind.c
src/interfaces/odbc/bind.h
src/interfaces/odbc/columninfo.c
src/interfaces/odbc/columninfo.h
src/interfaces/odbc/connection.c
src/interfaces/odbc/connection.h
src/interfaces/odbc/convert.c
src/interfaces/odbc/convert.h
src/interfaces/odbc/dlg_specific.c
src/interfaces/odbc/dlg_specific.h
src/interfaces/odbc/drvconn.c
src/interfaces/odbc/environ.c
src/interfaces/odbc/environ.h
src/interfaces/odbc/execute.c
src/interfaces/odbc/gpps.c
src/interfaces/odbc/gpps.h
src/interfaces/odbc/info.c
src/interfaces/odbc/iodbc.h
src/interfaces/odbc/isql.h
src/interfaces/odbc/isqlext.h
src/interfaces/odbc/lobj.c
src/interfaces/odbc/lobj.h
src/interfaces/odbc/misc.c
src/interfaces/odbc/misc.h
src/interfaces/odbc/options.c
src/interfaces/odbc/parse.c
src/interfaces/odbc/pgtypes.c
src/interfaces/odbc/pgtypes.h
src/interfaces/odbc/psqlodbc.c
src/interfaces/odbc/psqlodbc.h
src/interfaces/odbc/psqlodbc.rc
src/interfaces/odbc/qresult.c
src/interfaces/odbc/qresult.h
src/interfaces/odbc/resource.h
src/interfaces/odbc/results.c
src/interfaces/odbc/setup.c
src/interfaces/odbc/socket.c
src/interfaces/odbc/socket.h
src/interfaces/odbc/statement.c
src/interfaces/odbc/statement.h
src/interfaces/odbc/tuple.c
src/interfaces/odbc/tuple.h
src/interfaces/odbc/tuplelist.c
src/interfaces/odbc/tuplelist.h

index 488fad6c3b534a21d738bf5794d8c6b6a691cd71..c2c1936fa5260db7c3442d839a6b0826d6187343 100644 (file)
@@ -2,7 +2,7 @@
 #
 # GNUMakefile for psqlodbc (Postgres ODBC driver)
 #
-# $Header: /cvsroot/pgsql/src/interfaces/odbc/Attic/GNUmakefile,v 1.12 2001/02/10 16:51:40 petere Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/odbc/Attic/GNUmakefile,v 1.13 2001/02/14 05:45:38 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -24,6 +24,7 @@ OBJS = info.o bind.o columninfo.o connection.o convert.o drvconn.o \
         gpps.o tuple.o tuplelist.o dlg_specific.o $(OBJX)
 
 SHLIB_LINK = $(filter -lm, $(LIBS))
+
 all: all-lib
 
 # Shared library stuff
@@ -32,7 +33,6 @@ include $(top_srcdir)/src/Makefile.shlib
 # Symbols must be resolved to the version in the shared library because
 # the driver manager (e.g., iodbc) provides some symbols with the same
 # names and we don't want those.  (This issue is probably ELF specific.)
-
 LINK.shared += $(shlib_symbolic)
 
 odbc_headers = isql.h isqlext.h iodbc.h
index 16a375301fb5c29d720ba6f31aef472c046fa912..6ec25f80d6372fc0d76451919fdb51694a7e1832 100644 (file)
@@ -1,14 +1,15 @@
-/* Module:         bind.c
+
+/* Module:          bind.c
  *
- * Description:        This module contains routines related to binding
- *                 columns and parameters.
+ * Description:     This module contains routines related to binding 
+ *                  columns and parameters.
  *
- * Classes:            BindInfoClass, ParameterInfoClass
+ * Classes:         BindInfoClass, ParameterInfoClass
  *
- * API functions:  SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
- *                 SQLParamOptions(NI)
+ * API functions:   SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
+ *                  SQLParamOptions(NI)
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #include "sqlext.h"
 #endif
 
-/*     Bind parameters on a statement handle */
-
-RETCODE SQL_API
-SQLBindParameter(
-                HSTMT hstmt,
-                UWORD ipar,
-                SWORD fParamType,
-                SWORD fCType,
-                SWORD fSqlType,
-                UDWORD cbColDef,
-                SWORD ibScale,
-                PTR rgbValue,
-                SDWORD cbValueMax,
-                SDWORD FAR *pcbValue)
+/*      Bind parameters on a statement handle */
+
+RETCODE SQL_API SQLBindParameter(
+        HSTMT      hstmt,
+        UWORD      ipar,
+        SWORD      fParamType,
+        SWORD      fCType,
+        SWORD      fSqlType,
+        UDWORD     cbColDef,
+        SWORD      ibScale,
+        PTR        rgbValue,
+        SDWORD     cbValueMax,
+        SDWORD FAR *pcbValue)
 {
-   StatementClass *stmt = (StatementClass *) hstmt;
-   static char *func = "SQLBindParameter";
+StatementClass *stmt = (StatementClass *) hstmt;
+static char *func="SQLBindParameter";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-   if (stmt->parameters_allocated < ipar)
-   {
+   if(stmt->parameters_allocated < ipar) {
        ParameterInfoClass *old_parameters;
-       int         i,
-                   old_parameters_allocated;
+       int i, old_parameters_allocated;
 
        old_parameters = stmt->parameters;
        old_parameters_allocated = stmt->parameters_allocated;
 
-       stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass) * (ipar));
-       if (!stmt->parameters)
-       {
+       stmt->parameters = (ParameterInfoClass *) malloc(sizeof(ParameterInfoClass)*(ipar));
+       if ( ! stmt->parameters) {
            stmt->errornumber = STMT_NO_MEMORY_ERROR;
            stmt->errormsg = "Could not allocate memory for statement parameters";
            SC_log_error(func, "", stmt);
@@ -80,23 +76,18 @@ SQLBindParameter(
        stmt->parameters_allocated = ipar;
 
        /* copy the old parameters over */
-       for (i = 0; i < old_parameters_allocated; i++)
-       {
+       for(i = 0; i < old_parameters_allocated; i++) {
            /* a structure copy should work */
            stmt->parameters[i] = old_parameters[i];
        }
 
        /* get rid of the old parameters, if there were any */
-       if (old_parameters)
+       if(old_parameters)
            free(old_parameters);
 
-       /*
-        * zero out the newly allocated parameters (in case they skipped
-        * some,
-        */
+       /* zero out the newly allocated parameters (in case they skipped some, */
        /* so we don't accidentally try to use them later) */
-       for (; i < stmt->parameters_allocated; i++)
-       {
+       for(; i < stmt->parameters_allocated; i++) {
            stmt->parameters[i].buflen = 0;
            stmt->parameters[i].buffer = 0;
            stmt->parameters[i].used = 0;
@@ -112,8 +103,7 @@ SQLBindParameter(
        }
    }
 
-   ipar--;                     /* use zero based column numbers for the
-                                * below part */
+   ipar--;     /* use zero based column numbers for the below part */
 
    /* store the given info */
    stmt->parameters[ipar].buflen = cbValueMax;
@@ -125,83 +115,74 @@ SQLBindParameter(
    stmt->parameters[ipar].precision = cbColDef;
    stmt->parameters[ipar].scale = ibScale;
 
-   /*
-    * If rebinding a parameter that had data-at-exec stuff in it, then
-    * free that stuff
-    */
-   if (stmt->parameters[ipar].EXEC_used)
-   {
+   /*  If rebinding a parameter that had data-at-exec stuff in it,
+       then free that stuff
+   */
+   if (stmt->parameters[ipar].EXEC_used) {
        free(stmt->parameters[ipar].EXEC_used);
        stmt->parameters[ipar].EXEC_used = NULL;
    }
 
-   if (stmt->parameters[ipar].EXEC_buffer)
-   {
+   if (stmt->parameters[ipar].EXEC_buffer) {
        if (stmt->parameters[ipar].SQLType != SQL_LONGVARBINARY)
            free(stmt->parameters[ipar].EXEC_buffer);
        stmt->parameters[ipar].EXEC_buffer = NULL;
    }
 
-   /* Data at exec macro only valid for C char/binary data */
+   /*  Data at exec macro only valid for C char/binary data */
    if ((fSqlType == SQL_LONGVARBINARY || fSqlType == SQL_LONGVARCHAR) && pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
        stmt->parameters[ipar].data_at_exec = TRUE;
    else
        stmt->parameters[ipar].data_at_exec = FALSE;
 
-   mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue : -777, stmt->parameters[ipar].data_at_exec);
+   mylog("SQLBindParamater: ipar=%d, paramType=%d, fCType=%d, fSqlType=%d, cbColDef=%d, ibScale=%d, rgbValue=%d, *pcbValue = %d, data_at_exec = %d\n", ipar, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, pcbValue ? *pcbValue: -777, stmt->parameters[ipar].data_at_exec);
 
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
-
-/*     Associate a user-supplied buffer with a database column. */
-RETCODE SQL_API
-SQLBindCol(
-          HSTMT hstmt,
-          UWORD icol,
-          SWORD fCType,
-          PTR rgbValue,
-          SDWORD cbValueMax,
-          SDWORD FAR *pcbValue)
-{
-   StatementClass *stmt = (StatementClass *) hstmt;
-   static char *func = "SQLBindCol";
+/*      -       -       -       -       -       -       -       -       - */
 
-   mylog("%s: entering...\n", func);
+/*      Associate a user-supplied buffer with a database column. */
+RETCODE SQL_API SQLBindCol(
+        HSTMT      hstmt,
+        UWORD      icol,
+        SWORD      fCType,
+        PTR        rgbValue,
+        SDWORD     cbValueMax,
+        SDWORD FAR *pcbValue)
+{
+StatementClass *stmt = (StatementClass *) hstmt;
+static char *func="SQLBindCol";
 
-   mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
+   mylog( "%s: entering...\n", func);
+    
+mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
 
-   if (!stmt)
-   {
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
 
    SC_clear_error(stmt);
-
-   if (stmt->status == STMT_EXECUTING)
-   {
+    
+   if( stmt->status == STMT_EXECUTING) {
        stmt->errormsg = "Can't bind columns while statement is still executing.";
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        SC_log_error(func, "", stmt);
        return SQL_ERROR;
    }
 
-   /* If the bookmark column is being bound, then just save it */
-   if (icol == 0)
-   {
-       if (rgbValue == NULL)
-       {
+   /*  If the bookmark column is being bound, then just save it */
+   if (icol == 0) {
+
+       if (rgbValue == NULL) {
            stmt->bookmark.buffer = NULL;
            stmt->bookmark.used = NULL;
        }
-       else
-       {
-           /* Make sure it is the bookmark data type */
-           if (fCType != SQL_C_BOOKMARK)
-           {
+       else {
+           /*  Make sure it is the bookmark data type */
+           if ( fCType != SQL_C_BOOKMARK) {
                stmt->errormsg = "Column 0 is not of type SQL_C_BOOKMARK";
                stmt->errornumber = STMT_PROGRAM_TYPE_OUT_OF_RANGE;
                SC_log_error(func, "", stmt);
@@ -214,42 +195,37 @@ SQLBindCol(
        return SQL_SUCCESS;
    }
 
-   /* allocate enough bindings if not already done */
-   /* Most likely, execution of a statement would have setup the  */
-   /* necessary bindings. But some apps call BindCol before any */
-   /* statement is executed. */
-   if (icol > stmt->bindings_allocated)
+   /*  allocate enough bindings if not already done */
+   /*  Most likely, execution of a statement would have setup the  */
+   /*  necessary bindings. But some apps call BindCol before any */
+   /*  statement is executed. */
+   if ( icol > stmt->bindings_allocated)
        extend_bindings(stmt, icol);
 
-   /* check to see if the bindings were allocated */
-   if (!stmt->bindings)
-   {
+   /*  check to see if the bindings were allocated */
+   if ( ! stmt->bindings) {
        stmt->errormsg = "Could not allocate memory for bindings.";
        stmt->errornumber = STMT_NO_MEMORY_ERROR;
        SC_log_error(func, "", stmt);
        return SQL_ERROR;
    }
 
-   icol--;                     /* use zero based col numbers from here
-                                * out */
+   icol--;     /* use zero based col numbers from here out */
 
-   /* Reset for SQLGetData */
+   /*  Reset for SQLGetData */
    stmt->bindings[icol].data_left = -1;
 
-   if (rgbValue == NULL)
-   {
+   if (rgbValue == NULL) {
        /* we have to unbind the column */
        stmt->bindings[icol].buflen = 0;
        stmt->bindings[icol].buffer = NULL;
-       stmt->bindings[icol].used = NULL;
+       stmt->bindings[icol].used =   NULL;
        stmt->bindings[icol].returntype = SQL_C_CHAR;
-   }
-   else
-   {
+   } else {
        /* ok, bind that column */
-       stmt->bindings[icol].buflen = cbValueMax;
-       stmt->bindings[icol].buffer = rgbValue;
-       stmt->bindings[icol].used = pcbValue;
+       stmt->bindings[icol].buflen     = cbValueMax;
+       stmt->bindings[icol].buffer     = rgbValue;
+       stmt->bindings[icol].used       = pcbValue;
        stmt->bindings[icol].returntype = fCType;
 
        mylog("       bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
@@ -258,37 +234,34 @@ SQLBindCol(
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/* Returns the description of a parameter marker. */
+/*  Returns the description of a parameter marker. */
 /* This function is listed as not being supported by SQLGetFunctions() because it is  */
 /* used to describe "parameter markers" (not bound parameters), in which case,  */
 /* the dbms should return info on the markers.  Since Postgres doesn't support that, */
 /* it is best to say this function is not supported and let the application assume a  */
 /* data type (most likely varchar). */
 
-RETCODE SQL_API
-SQLDescribeParam(
-                HSTMT hstmt,
-                UWORD ipar,
-                SWORD FAR *pfSqlType,
-                UDWORD FAR *pcbColDef,
-                SWORD FAR *pibScale,
-                SWORD FAR *pfNullable)
+RETCODE SQL_API SQLDescribeParam(
+        HSTMT      hstmt,
+        UWORD      ipar,
+        SWORD  FAR *pfSqlType,
+        UDWORD FAR *pcbColDef,
+        SWORD  FAR *pibScale,
+        SWORD  FAR *pfNullable)
 {
-   StatementClass *stmt = (StatementClass *) hstmt;
-   static char *func = "SQLDescribeParam";
+StatementClass *stmt = (StatementClass *) hstmt;
+static char *func = "SQLDescribeParam";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-   if ((ipar < 1) || (ipar > stmt->parameters_allocated))
-   {
+   if( (ipar < 1) || (ipar > stmt->parameters_allocated) ) {
        stmt->errormsg = "Invalid parameter number for SQLDescribeParam.";
        stmt->errornumber = STMT_BAD_PARAMETER_NUMBER_ERROR;
        SC_log_error(func, "", stmt);
@@ -297,45 +270,41 @@ SQLDescribeParam(
 
    ipar--;
 
-   /*
-    * This implementation is not very good, since it is supposed to
-    * describe
-    */
-   /* parameter markers, not bound parameters.  */
-   if (pfSqlType)
+   /*  This implementation is not very good, since it is supposed to describe */
+   /*  parameter markers, not bound parameters.  */
+   if(pfSqlType)
        *pfSqlType = stmt->parameters[ipar].SQLType;
 
-   if (pcbColDef)
+   if(pcbColDef)
        *pcbColDef = stmt->parameters[ipar].precision;
 
-   if (pibScale)
+   if(pibScale)
        *pibScale = stmt->parameters[ipar].scale;
 
-   if (pfNullable)
+   if(pfNullable)
        *pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
 
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/*     Sets multiple values (arrays) for the set of parameter markers. */
+/*      Sets multiple values (arrays) for the set of parameter markers. */
 
-RETCODE SQL_API
-SQLParamOptions(
-               HSTMT hstmt,
-               UDWORD crow,
-               UDWORD FAR *pirow)
+RETCODE SQL_API SQLParamOptions(
+        HSTMT      hstmt,
+        UDWORD     crow,
+        UDWORD FAR *pirow)
 {
-   static char *func = "SQLParamOptions";
+static char *func = "SQLParamOptions";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
    SC_log_error(func, "Function not implemented", (StatementClass *) hstmt);
    return SQL_ERROR;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
 /* This function should really talk to the dbms to determine the number of  */
 /* "parameter markers" (not bound parameters) in the statement.  But, since */
@@ -344,49 +313,43 @@ SQLParamOptions(
 /* like it does for SQLDescribeParam is that some applications don't care and try  */
 /* to call it anyway. */
 /* If the statement does not have parameters, it should just return 0. */
-RETCODE SQL_API
-SQLNumParams(
-            HSTMT hstmt,
-            SWORD FAR *pcpar)
+RETCODE SQL_API SQLNumParams(
+        HSTMT      hstmt,
+        SWORD  FAR *pcpar)
 {
-   StatementClass *stmt = (StatementClass *) hstmt;
-   char        in_quote = FALSE;
-   unsigned int i;
-   static char *func = "SQLNumParams";
+StatementClass *stmt = (StatementClass *) hstmt;
+char in_quote = FALSE;
+unsigned int i;
+static char *func = "SQLNumParams";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if(!stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
    if (pcpar)
        *pcpar = 0;
-   else
-   {
+   else {
        SC_log_error(func, "pcpar was null", stmt);
        return SQL_ERROR;
    }
 
 
-   if (!stmt->statement)
-   {
+   if(!stmt->statement) {
        /* no statement has been allocated */
        stmt->errormsg = "SQLNumParams called with no statement ready.";
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        SC_log_error(func, "", stmt);
        return SQL_ERROR;
-   }
-   else
-   {
-       for (i = 0; i < strlen(stmt->statement); i++)
-       {
-           if (stmt->statement[i] == '?' && !in_quote)
+   } else {
+
+       for(i=0; i < strlen(stmt->statement); i++) {
+
+           if(stmt->statement[i] == '?' && !in_quote)
                (*pcpar)++;
-           else
-           {
+           else {
                if (stmt->statement[i] == '\'')
                    in_quote = (in_quote ? FALSE : TRUE);
            }
@@ -397,20 +360,20 @@ SQLNumParams(
 }
 
 /********************************************************************
- *  Bindings Implementation
+ *   Bindings Implementation
  */
 BindInfoClass *
 create_empty_bindings(int num_columns)
 {
-   BindInfoClass *new_bindings;
-   int         i;
+BindInfoClass *new_bindings;
+int i;
 
-   new_bindings = (BindInfoClass *) malloc(num_columns * sizeof(BindInfoClass));
-   if (!new_bindings)
+   new_bindings = (BindInfoClass *)malloc(num_columns * sizeof(BindInfoClass));
+   if(!new_bindings) {
        return 0;
+   }
 
-   for (i = 0; i < num_columns; i++)
-   {
+   for(i=0; i < num_columns; i++) {
        new_bindings[i].buflen = 0;
        new_bindings[i].buffer = NULL;
        new_bindings[i].used = NULL;
@@ -423,23 +386,21 @@ create_empty_bindings(int num_columns)
 void
 extend_bindings(StatementClass *stmt, int num_columns)
 {
-   static char *func = "extend_bindings";
-   BindInfoClass *new_bindings;
-   int         i;
+static char *func="extend_bindings";
+BindInfoClass *new_bindings;
+int i;
 
-   mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
+mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
 
    /* if we have too few, allocate room for more, and copy the old */
    /* entries into the new structure */
-   if (stmt->bindings_allocated < num_columns)
-   {
+   if(stmt->bindings_allocated < num_columns) {
+
        new_bindings = create_empty_bindings(num_columns);
-       if (!new_bindings)
-       {
-           mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, stmt->bindings_allocated);
+       if ( ! new_bindings) {
+           mylog("%s: unable to create %d new bindings from %d old bindings\n", func, num_columns, stmt->bindings_allocated);
 
-           if (stmt->bindings)
-           {
+           if (stmt->bindings) {
                free(stmt->bindings);
                stmt->bindings = NULL;
            }
@@ -447,9 +408,8 @@ extend_bindings(StatementClass *stmt, int num_columns)
            return;
        }
 
-       if (stmt->bindings)
-       {
-           for (i = 0; i < stmt->bindings_allocated; i++)
+       if(stmt->bindings) {
+           for(i=0; i<stmt->bindings_allocated; i++)
                new_bindings[i] = stmt->bindings[i];
 
            free(stmt->bindings);
@@ -457,14 +417,15 @@ extend_bindings(StatementClass *stmt, int num_columns)
 
        stmt->bindings = new_bindings;
        stmt->bindings_allocated = num_columns;
-   }
-   /* There is no reason to zero out extra bindings if there are */
-   /* more than needed.  If an app has allocated extra bindings,  */
-   /* let it worry about it by unbinding those columns. */
 
-   /* SQLBindCol(1..) ... SQLBindCol(10...)   # got 10 bindings */
-   /* SQLExecDirect(...)  # returns 5 cols */
-   /* SQLExecDirect(...)  # returns 10 cols  (now OK) */
+    } 
+   /*  There is no reason to zero out extra bindings if there are */
+   /*  more than needed.  If an app has allocated extra bindings,  */
+   /*  let it worry about it by unbinding those columns. */
+
+   /*  SQLBindCol(1..) ... SQLBindCol(10...)   # got 10 bindings */
+   /*  SQLExecDirect(...)  # returns 5 cols */
+   /*  SQLExecDirect(...)  # returns 10 cols  (now OK) */
 
    mylog("exit extend_bindings\n");
 }
index 58e5fb190ab21ef5b67c5186bac4452ce2215a18..39e594f34601c286b0d92123541b99e682f286d9 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           bind.h
+/* File:            bind.h
  *
- * Description:        See "bind.c"
+ * Description:     See "bind.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 /*
  * BindInfoClass -- stores information about a bound column
  */
-struct BindInfoClass_
-{
-   Int4        buflen;         /* size of buffer */
-   Int4        data_left;      /* amount of data left to read
-                                * (SQLGetData) */
-   char       *buffer;         /* pointer to the buffer */
-   Int4       *used;           /* used space in the buffer (for strings
-                                * not counting the '\0') */
-   Int2        returntype;     /* kind of conversion to be applied when
-                                * returning (SQL_C_DEFAULT,
-                                * SQL_C_CHAR...) */
+struct BindInfoClass_ {
+   Int4 buflen;        /* size of buffer */
+   Int4 data_left;     /* amount of data left to read (SQLGetData) */
+   char *buffer;       /* pointer to the buffer */
+   Int4 *used;         /* used space in the buffer (for strings not counting the '\0') */
+   Int2 returntype;    /* kind of conversion to be applied when returning (SQL_C_DEFAULT, SQL_C_CHAR...) */
 };
 
 /*
  * ParameterInfoClass -- stores information about a bound parameter
  */
-struct ParameterInfoClass_
-{
-   Int4        buflen;
-   char       *buffer;
-   Int4       *used;
-   Int2        paramType;
-   Int2        CType;
-   Int2        SQLType;
-   UInt4       precision;
-   Int2        scale;
-   Oid         lobj_oid;
-   Int4       *EXEC_used;      /* amount of data OR the oid of the large
-                                * object */
-   char       *EXEC_buffer;    /* the data or the FD of the large object */
-   char        data_at_exec;
+struct ParameterInfoClass_ {
+   Int4 buflen;
+   char *buffer;
+   Int4 *used;
+   Int2 paramType;
+   Int2 CType;
+   Int2 SQLType;
+   UInt4 precision;
+   Int2 scale;
+   Oid  lobj_oid;
+   Int4 *EXEC_used;        /* amount of data OR the oid of the large object */
+   char *EXEC_buffer;      /* the data or the FD of the large object */
+   char data_at_exec;
 };
 
 BindInfoClass *create_empty_bindings(int num_columns);
-void       extend_bindings(StatementClass *stmt, int num_columns);
+void extend_bindings(StatementClass *stmt, int num_columns);
 
 #endif
index 91a4a7a44ac89665d383ef2bf9544e5a5071d24d..9e5223b83b39b306c98666fd0c8f2d43c50503a0 100644 (file)
@@ -1,13 +1,14 @@
-/* Module:         columninfo.c
+
+/* Module:          columninfo.c
  *
- * Description:        This module contains routines related to
- *                 reading and storing the field information from a query.
+ * Description:     This module contains routines related to 
+ *                  reading and storing the field information from a query.
  *
- * Classes:            ColumnInfoClass (Functions prefix: "CI_")
+ * Classes:         ColumnInfoClass (Functions prefix: "CI_")
  *
- * API functions:  none
+ * API functions:   none
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 ColumnInfoClass *
 CI_Constructor()
 {
-   ColumnInfoClass *rv;
+ColumnInfoClass *rv;
 
    rv = (ColumnInfoClass *) malloc(sizeof(ColumnInfoClass));
 
-   if (rv)
-   {
+   if (rv) {
        rv->num_fields = 0;
        rv->name = NULL;
        rv->adtid = NULL;
@@ -45,21 +45,21 @@ CI_Destructor(ColumnInfoClass *self)
    free(self);
 }
 
-/* Read in field descriptions.
-   If self is not null, then also store the information.
+/*  Read in field descriptions.
+    If self is not null, then also store the information.
    If self is null, then just read, don't store.
 */
 char
 CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
 {
-   Int2        lf;
-   int         new_num_fields;
-   Oid         new_adtid;
-   Int2        new_adtsize;
-   Int4        new_atttypmod = -1;
-   char        new_field_name[MAX_MESSAGE_LEN + 1];
-   SocketClass *sock;
-   ConnInfo   *ci;
+Int2 lf;
+int new_num_fields;
+Oid new_adtid;
+Int2 new_adtsize;
+Int4 new_atttypmod = -1;
+char new_field_name[MAX_MESSAGE_LEN+1];
+SocketClass *sock;
+ConnInfo *ci;
 
    sock = CC_get_socket(conn);
    ci = &conn->connInfo;
@@ -69,28 +69,28 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
 
    mylog("num_fields = %d\n", new_num_fields);
 
-   if (self)
-   {                           /* according to that allocate memory */
+   if (self) {     /* according to that allocate memory */
        CI_set_num_fields(self, new_num_fields);
    }
 
    /* now read in the descriptions */
-   for (lf = 0; lf < new_num_fields; lf++)
-   {
+   for(lf = 0; lf < new_num_fields; lf++) {
+
        SOCK_get_string(sock, new_field_name, MAX_MESSAGE_LEN);
        new_adtid = (Oid) SOCK_get_int(sock, 4);
        new_adtsize = (Int2) SOCK_get_int(sock, 2);
 
-       /* If 6.4 protocol, then read the atttypmod field */
-       if (PG_VERSION_GE(conn, 6.4))
-       {
+       /*  If 6.4 protocol, then read the atttypmod field */
+       if (PG_VERSION_GE(conn, 6.4)) {
+
            mylog("READING ATTTYPMOD\n");
            new_atttypmod = (Int4) SOCK_get_int(sock, 4);
 
-           /* Subtract the header length */
+           /*  Subtract the header length */
            new_atttypmod -= 4;
            if (new_atttypmod < 0)
                new_atttypmod = -1;
+
        }
 
        mylog("CI_read_fields: fieldname='%s', adtid=%d, adtsize=%d, atttypmod=%d\n", new_field_name, new_adtid, new_adtsize, new_atttypmod);
@@ -107,16 +107,15 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
 void
 CI_free_memory(ColumnInfoClass *self)
 {
-   register Int2 lf;
-   int         num_fields = self->num_fields;
+register Int2 lf;
+int num_fields = self->num_fields;
 
-   for (lf = 0; lf < num_fields; lf++)
-   {
-       if (self->name[lf])
-           free(self->name[lf]);
+   for (lf = 0; lf < num_fields; lf++) {
+       if( self->name[lf])
+           free (self->name[lf]);
    }
 
-   /* Safe to call even if null */
+   /*  Safe to call even if null */
    free(self->name);
    free(self->adtid);
    free(self->adtsize);
@@ -128,30 +127,33 @@ CI_free_memory(ColumnInfoClass *self)
 void
 CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
 {
-   CI_free_memory(self);       /* always safe to call */
+   CI_free_memory(self);   /* always safe to call */
 
    self->num_fields = new_num_fields;
 
-   self->name = (char **) malloc(sizeof(char *) * self->num_fields);
-   self->adtid = (Oid *) malloc(sizeof(Oid) * self->num_fields);
-   self->adtsize = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
+   self->name = (char **) malloc (sizeof(char *) * self->num_fields);
+   self->adtid = (Oid *) malloc (sizeof(Oid) * self->num_fields);
+   self->adtsize = (Int2 *) malloc (sizeof(Int2) * self->num_fields);
    self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
    self->atttypmod = (Int4 *) malloc(sizeof(Int4) * self->num_fields);
 }
 
 void
-CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
-                 Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
+CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name, 
+                                      Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
 {
+    
    /* check bounds */
-   if ((field_num < 0) || (field_num >= self->num_fields))
+   if((field_num < 0) || (field_num >= self->num_fields)) {
        return;
+   }
 
    /* store the info */
-   self->name[field_num] = strdup(new_name);
+   self->name[field_num] = strdup(new_name);  
    self->adtid[field_num] = new_adtid;
    self->adtsize[field_num] = new_adtsize;
    self->atttypmod[field_num] = new_atttypmod;
 
    self->display_size[field_num] = 0;
 }
+
index 964ebc7617b905718efb885ed294772a90be4c0c..3ec1cc92d50e3edee351f108a9dfed30f65f091c 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           columninfo.h
+/* File:            columninfo.h
  *
- * Description:        See "columninfo.c"
+ * Description:     See "columninfo.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 
 #include "psqlodbc.h"
 
-struct ColumnInfoClass_
-{
-   Int2        num_fields;
-   char      **name;           /* list of type names */
-   Oid        *adtid;          /* list of type ids */
-   Int2       *adtsize;        /* list type sizes */
-   Int2       *display_size;   /* the display size (longest row) */
-   Int4       *atttypmod;      /* the length of bpchar/varchar */
+struct ColumnInfoClass_ {
+   Int2    num_fields;
+   char    **name;             /* list of type names */
+   Oid     *adtid;             /* list of type ids */
+   Int2    *adtsize;           /* list type sizes */
+   Int2    *display_size;      /* the display size (longest row) */
+   Int4    *atttypmod;         /* the length of bpchar/varchar */
 };
 
 #define CI_get_num_fields(self)            (self->num_fields)
@@ -30,15 +29,15 @@ struct ColumnInfoClass_
 #define CI_get_atttypmod(self, col)        (self->atttypmod[col])
 
 ColumnInfoClass *CI_Constructor(void);
-void       CI_Destructor(ColumnInfoClass *self);
-void       CI_free_memory(ColumnInfoClass *self);
-char       CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn);
+void CI_Destructor(ColumnInfoClass *self);
+void CI_free_memory(ColumnInfoClass *self);
+char CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn);
 
 /* functions for setting up the fields from within the program, */
 /* without reading from a socket */
-void       CI_set_num_fields(ColumnInfoClass *self, int new_num_fields);
-void CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
-                 Oid new_adtid, Int2 new_adtsize, Int4 atttypmod);
+void CI_set_num_fields(ColumnInfoClass *self, int new_num_fields);
+void CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name, 
+                       Oid new_adtid, Int2 new_adtsize, Int4 atttypmod);
 
 
 #endif
index 2a4b62ef5ce435b6a31cccba112c3d3b534e0605..b528a69ea03ab2415677a2b99f05b6e2662d38a3 100644 (file)
@@ -1,14 +1,15 @@
-/* Module:         connection.c
+
+/* Module:          connection.c
  *
- * Description:        This module contains routines related to
- *                 connecting to and disconnecting from the Postgres DBMS.
+ * Description:     This module contains routines related to 
+ *                  connecting to and disconnecting from the Postgres DBMS.
  *
- * Classes:            ConnectionClass (Functions prefix: "CC_")
+ * Classes:         ConnectionClass (Functions prefix: "CC_")
  *
- * API functions:  SQLAllocConnect, SQLConnect, SQLDisconnect, SQLFreeConnect,
- *                 SQLBrowseConnect(NI)
+ * API functions:   SQLAllocConnect, SQLConnect, SQLDisconnect, SQLFreeConnect,
+ *                  SQLBrowseConnect(NI)
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #include <odbcinst.h>
 #endif
 
-#define STMT_INCREMENT 16      /* how many statement holders to allocate
-                                * at a time */
+#define STMT_INCREMENT 16  /* how many statement holders to allocate at a time */
 
 #define PRN_NULLCHECK
 
 extern GLOBAL_VALUES globals;
 
 
-RETCODE SQL_API
-SQLAllocConnect(
-               HENV henv,
-               HDBC FAR *phdbc)
+RETCODE SQL_API SQLAllocConnect(
+                                HENV     henv,
+                                HDBC FAR *phdbc)
 {
-   EnvironmentClass *env = (EnvironmentClass *) henv;
-   ConnectionClass *conn;
-   static char *func = "SQLAllocConnect";
+EnvironmentClass *env = (EnvironmentClass *)henv;
+ConnectionClass *conn;
+static char *func="SQLAllocConnect";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
    conn = CC_Constructor();
    mylog("**** %s: henv = %u, conn = %u\n", func, henv, conn);
 
-   if (!conn)
-   {
-       env->errormsg = "Couldn't allocate memory for Connection object.";
-       env->errornumber = ENV_ALLOC_ERROR;
+    if( ! conn) {
+        env->errormsg = "Couldn't allocate memory for Connection object.";
+        env->errornumber = ENV_ALLOC_ERROR;
        *phdbc = SQL_NULL_HDBC;
        EN_log_error(func, "", env);
-       return SQL_ERROR;
-   }
+        return SQL_ERROR;
+    }
 
-   if (!EN_add_connection(env, conn))
-   {
-       env->errormsg = "Maximum number of connections exceeded.";
-       env->errornumber = ENV_ALLOC_ERROR;
-       CC_Destructor(conn);
+    if ( ! EN_add_connection(env, conn)) {
+        env->errormsg = "Maximum number of connections exceeded.";
+        env->errornumber = ENV_ALLOC_ERROR;
+        CC_Destructor(conn);
        *phdbc = SQL_NULL_HDBC;
        EN_log_error(func, "", env);
-       return SQL_ERROR;
-   }
+        return SQL_ERROR;
+    }
 
    *phdbc = (HDBC) conn;
 
-   return SQL_SUCCESS;
+    return SQL_SUCCESS;
 }
 
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLConnect(
-          HDBC hdbc,
-          UCHAR FAR *szDSN,
-          SWORD cbDSN,
-          UCHAR FAR *szUID,
-          SWORD cbUID,
-          UCHAR FAR *szAuthStr,
-          SWORD cbAuthStr)
+RETCODE SQL_API SQLConnect(
+                           HDBC      hdbc,
+                           UCHAR FAR *szDSN,
+                           SWORD     cbDSN,
+                           UCHAR FAR *szUID,
+                           SWORD     cbUID,
+                           UCHAR FAR *szAuthStr,
+                           SWORD     cbAuthStr)
 {
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   ConnInfo   *ci;
-   static char *func = "SQLConnect";
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+ConnInfo *ci;
+static char *func = "SQLConnect";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!conn)
-   {
+   if ( ! conn) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
@@ -101,15 +96,14 @@ SQLConnect(
 
    make_string(szDSN, cbDSN, ci->dsn);
 
-   /* get the values for the DSN from the registry */
+   /*  get the values for the DSN from the registry */
    getDSNinfo(ci, CONN_OVERWRITE);
-   /* initialize pg_version from connInfo.protocol    */
-   CC_initialize_pg_version(conn);
-
-   /*
-    * override values from DSN info with UID and authStr(pwd) This only
-    * occurs if the values are actually there.
-    */
+   /*  initialize pg_version from connInfo.protocol    */
+   CC_initialize_pg_version(conn); 
+   
+   /*  override values from DSN info with UID and authStr(pwd) 
+       This only occurs if the values are actually there.
+   */
    make_string(szUID, cbUID, ci->username);
    make_string(szAuthStr, cbAuthStr, ci->password);
 
@@ -118,59 +112,54 @@ SQLConnect(
 
    qlog("conn = %u, %s(DSN='%s', UID='%s', PWD='%s')\n", conn, func, ci->dsn, ci->username, ci->password);
 
-   if (CC_connect(conn, FALSE) <= 0)
-   {
-       /* Error messages are filled in */
+   if ( CC_connect(conn, FALSE) <= 0) {
+       /*  Error messages are filled in */
        CC_log_error(func, "Error on CC_connect", conn);
        return SQL_ERROR;
    }
 
-   mylog("%s: returning...\n", func);
+   mylog( "%s: returning...\n", func);
 
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLBrowseConnect(
-                HDBC hdbc,
-                UCHAR FAR *szConnStrIn,
-                SWORD cbConnStrIn,
-                UCHAR FAR *szConnStrOut,
-                SWORD cbConnStrOutMax,
-                SWORD FAR *pcbConnStrOut)
+RETCODE SQL_API SQLBrowseConnect(
+        HDBC      hdbc,
+        UCHAR FAR *szConnStrIn,
+        SWORD     cbConnStrIn,
+        UCHAR FAR *szConnStrOut,
+        SWORD     cbConnStrOutMax,
+        SWORD FAR *pcbConnStrOut)
 {
-   static char *func = "SQLBrowseConnect";
+static char *func="SQLBrowseConnect";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
 /* Drop any hstmts open on hdbc and disconnect from database */
-RETCODE SQL_API
-SQLDisconnect(
-             HDBC hdbc)
+RETCODE SQL_API SQLDisconnect(
+        HDBC      hdbc)
 {
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   static char *func = "SQLDisconnect";
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+static char *func = "SQLDisconnect";
 
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!conn)
-   {
+   if ( ! conn) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
    qlog("conn=%u, %s\n", conn, func);
 
-   if (conn->status == CONN_EXECUTING)
-   {
+   if (conn->status == CONN_EXECUTING) {
        conn->errornumber = CONN_IN_USE;
        conn->errormsg = "A transaction is currently being executed";
        CC_log_error(func, "", conn);
@@ -179,7 +168,7 @@ SQLDisconnect(
 
    mylog("%s: about to CC_cleanup\n", func);
 
-   /* Close the connection and free statements */
+   /*  Close the connection and free statements */
    CC_cleanup(conn);
 
    mylog("%s: done CC_cleanup\n", func);
@@ -189,27 +178,24 @@ SQLDisconnect(
 }
 
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLFreeConnect(
-              HDBC hdbc)
+RETCODE SQL_API SQLFreeConnect(
+        HDBC      hdbc)
 {
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   static char *func = "SQLFreeConnect";
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+static char *func = "SQLFreeConnect";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
    mylog("**** in %s: hdbc=%u\n", func, hdbc);
 
-   if (!conn)
-   {
+   if ( ! conn) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-   /* Remove the connection from the environment */
-   if (!EN_remove_connection(conn->henv, conn))
-   {
+   /*  Remove the connection from the environment */
+   if ( ! EN_remove_connection(conn->henv, conn)) {
        conn->errornumber = CONN_IN_USE;
        conn->errormsg = "A transaction is currently being executed";
        CC_log_error(func, "", conn);
@@ -226,36 +212,35 @@ SQLFreeConnect(
 
 /*
 *
-*      IMPLEMENTATION CONNECTION CLASS
+*       IMPLEMENTATION CONNECTION CLASS
 *
 */
 
-ConnectionClass *
-CC_Constructor()
+ConnectionClass *CC_Constructor()
 {
-   ConnectionClass *rv;
+ConnectionClass *rv;
 
-   rv = (ConnectionClass *) malloc(sizeof(ConnectionClass));
+    rv = (ConnectionClass *)malloc(sizeof(ConnectionClass));
 
-   if (rv != NULL)
-   {
-       rv->henv = NULL;        /* not yet associated with an environment */
+    if (rv != NULL) {
 
-       rv->errormsg = NULL;
-       rv->errornumber = 0;
+       rv->henv = NULL; /* not yet associated with an environment */
+
+        rv->errormsg = NULL;
+        rv->errornumber = 0;
        rv->errormsg_created = FALSE;
 
-       rv->status = CONN_NOT_CONNECTED;
-       rv->transact_status = CONN_IN_AUTOCOMMIT;       /* autocommit by default */
+        rv->status = CONN_NOT_CONNECTED;
+        rv->transact_status = CONN_IN_AUTOCOMMIT; /* autocommit by default */
 
        memset(&rv->connInfo, 0, sizeof(ConnInfo));
 
        rv->sock = SOCK_Constructor();
-       if (!rv->sock)
+       if ( ! rv->sock)
            return NULL;
 
-       rv->stmts = (StatementClass **) malloc(sizeof(StatementClass *) * STMT_INCREMENT);
-       if (!rv->stmts)
+       rv->stmts = (StatementClass **) malloc( sizeof(StatementClass *) * STMT_INCREMENT);
+       if ( ! rv->stmts)
            return NULL;
        memset(rv->stmts, 0, sizeof(StatementClass *) * STMT_INCREMENT);
 
@@ -275,44 +260,43 @@ CC_Constructor()
        rv->pg_version_major = 0;
        rv->pg_version_minor = 0;
 
-       /* Initialize statement options to defaults */
-       /* Statements under this conn will inherit these options */
+
+       /*  Initialize statement options to defaults */
+       /*  Statements under this conn will inherit these options */
 
        InitializeStatementOptions(&rv->stmtOptions);
-   }
-   return rv;
+
+
+    } 
+    return rv;
 }
 
 
 char
 CC_Destructor(ConnectionClass *self)
 {
+
    mylog("enter CC_Destructor, self=%u\n", self);
 
    if (self->status == CONN_EXECUTING)
        return 0;
 
-   CC_cleanup(self);           /* cleanup socket and statements */
+   CC_cleanup(self);   /* cleanup socket and statements */
 
    mylog("after CC_Cleanup\n");
 
-   /* Free up statement holders */
-   if (self->stmts)
-   {
+   /*  Free up statement holders */
+   if (self->stmts) {
        free(self->stmts);
        self->stmts = NULL;
    }
    mylog("after free statement holders\n");
 
-   /* Free cached table info */
-   if (self->col_info)
-   {
-       int         i;
-
-       for (i = 0; i < self->ntables; i++)
-       {
-           if (self->col_info[i]->result)      /* Free the SQLColumns
-                                                * result structure */
+   /*  Free cached table info */
+   if (self->col_info) {
+       int i;
+       for (i = 0; i < self->ntables; i++) {
+           if (self->col_info[i]->result)      /*  Free the SQLColumns result structure */
                QR_Destructor(self->col_info[i]->result);
 
            free(self->col_info[i]);
@@ -320,6 +304,7 @@ CC_Destructor(ConnectionClass *self)
        free(self->col_info);
    }
 
+
    free(self);
 
    mylog("exit CC_Destructor\n");
@@ -331,14 +316,12 @@ CC_Destructor(ConnectionClass *self)
 int
 CC_cursor_count(ConnectionClass *self)
 {
-   StatementClass *stmt;
-   int         i,
-               count = 0;
+StatementClass *stmt;
+int i, count = 0;
 
    mylog("CC_cursor_count: self=%u, num_stmts=%d\n", self, self->num_stmts);
 
-   for (i = 0; i < self->num_stmts; i++)
-   {
+   for (i = 0; i < self->num_stmts; i++) {
        stmt = self->stmts[i];
        if (stmt && stmt->result && stmt->result->cursor)
            count++;
@@ -349,11 +332,11 @@ CC_cursor_count(ConnectionClass *self)
    return count;
 }
 
-void
+void 
 CC_clear_error(ConnectionClass *self)
 {
-   self->errornumber = 0;
-   self->errormsg = NULL;
+   self->errornumber = 0; 
+   self->errormsg = NULL; 
    self->errormsg_created = FALSE;
 }
 
@@ -362,10 +345,9 @@ CC_clear_error(ConnectionClass *self)
 char
 CC_abort(ConnectionClass *self)
 {
-   QResultClass *res;
+QResultClass *res;
 
-   if (CC_is_in_trans(self))
-   {
+   if ( CC_is_in_trans(self)) {
        res = NULL;
 
        mylog("CC_abort:  sending ABORT!\n");
@@ -377,6 +359,7 @@ CC_abort(ConnectionClass *self)
            QR_Destructor(res);
        else
            return FALSE;
+
    }
 
    return TRUE;
@@ -386,8 +369,8 @@ CC_abort(ConnectionClass *self)
 char
 CC_cleanup(ConnectionClass *self)
 {
-   int         i;
-   StatementClass *stmt;
+int i;
+StatementClass *stmt;
 
    if (self->status == CONN_EXECUTING)
        return FALSE;
@@ -402,32 +385,31 @@ CC_cleanup(ConnectionClass *self)
 
    mylog("after CC_abort\n");
 
-   /* This actually closes the connection to the dbase */
-   if (self->sock)
-   {
-       SOCK_Destructor(self->sock);
+   /*  This actually closes the connection to the dbase */
+   if (self->sock) {
+       SOCK_Destructor(self->sock);
        self->sock = NULL;
    }
 
    mylog("after SOCK destructor\n");
 
-   /* Free all the stmts on this connection */
-   for (i = 0; i < self->num_stmts; i++)
-   {
+   /*  Free all the stmts on this connection */
+   for (i = 0; i < self->num_stmts; i++) {
        stmt = self->stmts[i];
-       if (stmt)
-       {
+       if (stmt) {
+
            stmt->hdbc = NULL;  /* prevent any more dbase interactions */
+
            SC_Destructor(stmt);
+
            self->stmts[i] = NULL;
        }
    }
 
-   /* Check for translation dll */
+   /*  Check for translation dll */
 #ifdef WIN32
-   if (self->translation_handle)
-   {
-       FreeLibrary(self->translation_handle);
+   if ( self->translation_handle) {
+       FreeLibrary (self->translation_handle);
        self->translation_handle = NULL;
    }
 #endif
@@ -437,40 +419,37 @@ CC_cleanup(ConnectionClass *self)
 }
 
 int
-CC_set_translation(ConnectionClass *self)
+CC_set_translation (ConnectionClass *self)
 {
 
 #ifdef WIN32
 
-   if (self->translation_handle != NULL)
-   {
-       FreeLibrary(self->translation_handle);
+   if (self->translation_handle != NULL) {
+       FreeLibrary (self->translation_handle);
        self->translation_handle = NULL;
    }
 
    if (self->connInfo.translation_dll[0] == 0)
        return TRUE;
 
-   self->translation_option = atoi(self->connInfo.translation_option);
-   self->translation_handle = LoadLibrary(self->connInfo.translation_dll);
+   self->translation_option = atoi (self->connInfo.translation_option);
+   self->translation_handle = LoadLibrary (self->connInfo.translation_dll);
 
-   if (self->translation_handle == NULL)
-   {
+   if (self->translation_handle == NULL) {
        self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
        self->errormsg = "Could not load the translation DLL.";
        return FALSE;
    }
 
    self->DataSourceToDriver
-       = (DataSourceToDriverProc) GetProcAddress(self->translation_handle,
+    = (DataSourceToDriverProc) GetProcAddress (self->translation_handle,
                                                "SQLDataSourceToDriver");
 
    self->DriverToDataSource
-       = (DriverToDataSourceProc) GetProcAddress(self->translation_handle,
+    = (DriverToDataSourceProc) GetProcAddress (self->translation_handle,
                                                "SQLDriverToDataSource");
 
-   if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL)
-   {
+   if (self->DataSourceToDriver == NULL || self->DriverToDataSource == NULL) {
        self->errornumber = CONN_UNABLE_TO_LOAD_DLL;
        self->errormsg = "Could not find translation DLL functions.";
        return FALSE;
@@ -479,55 +458,55 @@ CC_set_translation(ConnectionClass *self)
    return TRUE;
 }
 
-char
+char 
 CC_connect(ConnectionClass *self, char do_password)
 {
-   StartupPacket sp;
-   QResultClass *res;
-   SocketClass *sock;
-   ConnInfo   *ci = &(self->connInfo);
-   int         areq = -1;
-   int         beresp;
-   char        msgbuffer[ERROR_MSG_LENGTH];
-   char        salt[2];
-   static char *func = "CC_connect";
+StartupPacket sp;
+StartupPacket6_2 sp62;
+QResultClass *res;
+SocketClass *sock;
+ConnInfo *ci = &(self->connInfo);
+int areq = -1;
+int beresp;
+char msgbuffer[ERROR_MSG_LENGTH]; 
+char salt[2];
+static char *func="CC_connect";
 
    mylog("%s: entering...\n", func);
 
-   if (do_password)
+   if ( do_password)
+
        sock = self->sock;      /* already connected, just authenticate */
 
-   else
-   {
+   else {
+
        qlog("Global Options: Version='%s', fetch=%d, socket=%d, unknown_sizes=%d, max_varchar_size=%d, max_longvarchar_size=%d\n",
-            POSTGRESDRIVERVERSION,
-            globals.fetch_max,
-            globals.socket_buffersize,
-            globals.unknown_sizes,
-            globals.max_varchar_size,
-            globals.max_longvarchar_size);
+           POSTGRESDRIVERVERSION,
+           globals.fetch_max, 
+           globals.socket_buffersize, 
+           globals.unknown_sizes, 
+           globals.max_varchar_size, 
+           globals.max_longvarchar_size);
        qlog("                disable_optimizer=%d, ksqo=%d, unique_index=%d, use_declarefetch=%d\n",
-            globals.disable_optimizer,
-            globals.ksqo,
-            globals.unique_index,
-            globals.use_declarefetch);
+           globals.disable_optimizer,
+           globals.ksqo,
+           globals.unique_index,
+           globals.use_declarefetch);
        qlog("                text_as_longvarchar=%d, unknowns_as_longvarchar=%d, bools_as_char=%d\n",
-            globals.text_as_longvarchar,
-            globals.unknowns_as_longvarchar,
-            globals.bools_as_char);
+           globals.text_as_longvarchar, 
+           globals.unknowns_as_longvarchar, 
+           globals.bools_as_char);
        qlog("                extra_systable_prefixes='%s', conn_settings='%s'\n",
-            globals.extra_systable_prefixes,
-            globals.conn_settings);
+           globals.extra_systable_prefixes, 
+           globals.conn_settings);
 
-       if (self->status != CONN_NOT_CONNECTED)
-       {
+       if (self->status != CONN_NOT_CONNECTED) {
            self->errormsg = "Already connected.";
            self->errornumber = CONN_OPENDB_ERROR;
            return 0;
        }
 
-       if (ci->server[0] == '\0' || ci->port[0] == '\0' || ci->database[0] == '\0')
-       {
+       if ( ci->server[0] == '\0' || ci->port[0] == '\0' || ci->database[0] == '\0') {
            self->errornumber = CONN_INIREAD_ERROR;
            self->errormsg = "Missing server name, port, or database name in call to CC_connect.";
            return 0;
@@ -535,18 +514,15 @@ CC_connect(ConnectionClass *self, char do_password)
 
        mylog("CC_connect(): DSN = '%s', server = '%s', port = '%s', database = '%s', username = '%s', password='%s'\n", ci->dsn, ci->server, ci->port, ci->database, ci->username, ci->password);
 
-       /*
-        * If the socket was closed for some reason (like a SQLDisconnect,
-        * but no SQLFreeConnect then create a socket now.
-        */
-       if (!self->sock)
-       {
+       /* If the socket was closed for some reason (like a SQLDisconnect, but no SQLFreeConnect
+           then create a socket now.
+       */
+       if ( ! self->sock) {
            self->sock = SOCK_Constructor();
-           if (!self->sock)
-           {
-               self->errornumber = CONNECTION_SERVER_NOT_REACHED;
-               self->errormsg = "Could not open a socket to the server";
-               return 0;
+           if ( ! self->sock) {
+                self->errornumber = CONNECTION_SERVER_NOT_REACHED;
+                self->errormsg = "Could not open a socket to the server";
+                return 0;
            }
        }
 
@@ -555,8 +531,7 @@ CC_connect(ConnectionClass *self, char do_password)
        mylog("connecting to the server socket...\n");
 
        SOCK_connect_to(sock, (short) atoi(ci->port), ci->server);
-       if (SOCK_get_errcode(sock) != 0)
-       {
+       if (SOCK_get_errcode(sock) != 0) {
            mylog("connection to the server socket failed.\n");
            self->errornumber = CONNECTION_SERVER_NOT_REACHED;
            self->errormsg = "Could not connect to the server";
@@ -564,25 +539,40 @@ CC_connect(ConnectionClass *self, char do_password)
        }
        mylog("connection to the server socket succeeded.\n");
 
-       memset(&sp, 0, sizeof(StartupPacket));
+       if ( PROTOCOL_62(ci)) {
+           sock->reverse = TRUE;       /* make put_int and get_int work for 6.2 */
+
+           memset(&sp62, 0, sizeof(StartupPacket6_2));
+           SOCK_put_int(sock, htonl(4+sizeof(StartupPacket6_2)), 4);
+           sp62.authtype = htonl(NO_AUTHENTICATION);
+           strncpy(sp62.database, ci->database, PATH_SIZE);
+           strncpy(sp62.user, ci->username, NAMEDATALEN);
+           SOCK_put_n_char(sock, (char *) &sp62, sizeof(StartupPacket6_2));
+           SOCK_flush_output(sock);
+       }
+       else {
+           memset(&sp, 0, sizeof(StartupPacket));
 
-       mylog("sizeof startup packet = %d\n", sizeof(StartupPacket));
+           mylog("sizeof startup packet = %d\n", sizeof(StartupPacket));
 
-       /* Send length of Authentication Block */
-       SOCK_put_int(sock, 4 + sizeof(StartupPacket), 4);
+           /* Send length of Authentication Block */
+           SOCK_put_int(sock, 4+sizeof(StartupPacket), 4); 
 
-       sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LATEST);
+           if ( PROTOCOL_63(ci))
+               sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_63);
+           else
+               sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LATEST);
 
-       strncpy(sp.database, ci->database, SM_DATABASE);
-       strncpy(sp.user, ci->username, SM_USER);
+           strncpy(sp.database, ci->database, SM_DATABASE);
+           strncpy(sp.user, ci->username, SM_USER);
 
-       SOCK_put_n_char(sock, (char *) &sp, sizeof(StartupPacket));
-       SOCK_flush_output(sock);
+           SOCK_put_n_char(sock, (char *) &sp, sizeof(StartupPacket));
+           SOCK_flush_output(sock);
+       }
 
        mylog("sent the authentication block.\n");
 
-       if (sock->errornumber != 0)
-       {
+       if (sock->errornumber != 0) {
            mylog("couldn't send the authentication block properly.\n");
            self->errornumber = CONN_INVALID_AUTHENTICATION;
            self->errormsg = "Sending the authentication packet failed";
@@ -591,109 +581,106 @@ CC_connect(ConnectionClass *self, char do_password)
        mylog("sent the authentication block successfully.\n");
    }
 
+
    mylog("gonna do authentication\n");
 
 
    /* *************************************************** */
-   /* Now get the authentication request from backend */
+   /*  Now get the authentication request from backend */
    /* *************************************************** */
 
-   do
-   {
+   if ( ! PROTOCOL_62(ci)) do {
+
        if (do_password)
            beresp = 'R';
        else
            beresp = SOCK_get_char(sock);
 
-       switch (beresp)
-       {
-           case 'E':
-               mylog("auth got 'E'\n");
+       switch(beresp) {
+       case 'E':
+           mylog("auth got 'E'\n");
 
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
-               self->errornumber = CONN_INVALID_AUTHENTICATION;
-               self->errormsg = msgbuffer;
-               qlog("ERROR from backend during authentication: '%s'\n", self->errormsg);
-               return 0;
-           case 'R':
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+           self->errornumber = CONN_INVALID_AUTHENTICATION;
+           self->errormsg = msgbuffer;
+           qlog("ERROR from backend during authentication: '%s'\n", self->errormsg);
+           return 0;
+       case 'R':
 
-               if (do_password)
-               {
-                   mylog("in 'R' do_password\n");
-                   areq = AUTH_REQ_PASSWORD;
-                   do_password = FALSE;
-               }
-               else
-               {
-                   mylog("auth got 'R'\n");
+           if (do_password) {
+               mylog("in 'R' do_password\n");
+               areq = AUTH_REQ_PASSWORD;
+               do_password = FALSE;
+           }
+           else {
+               mylog("auth got 'R'\n");
 
-                   areq = SOCK_get_int(sock, 4);
-                   if (areq == AUTH_REQ_CRYPT)
-                       SOCK_get_n_char(sock, salt, 2);
+               areq = SOCK_get_int(sock, 4);
+               if (areq == AUTH_REQ_CRYPT)
+                   SOCK_get_n_char(sock, salt, 2);
 
-                   mylog("areq = %d\n", areq);
-               }
-               switch (areq)
-               {
-                   case AUTH_REQ_OK:
-                       break;
+               mylog("areq = %d\n", areq);
+           }
+           switch(areq) {
+           case AUTH_REQ_OK:
+               break;
 
-                   case AUTH_REQ_KRB4:
-                       self->errormsg = "Kerberos 4 authentication not supported";
-                       self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
-                       return 0;
+           case AUTH_REQ_KRB4:
+               self->errormsg = "Kerberos 4 authentication not supported";
+               self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
+               return 0;
 
-                   case AUTH_REQ_KRB5:
-                       self->errormsg = "Kerberos 5 authentication not supported";
-                       self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
-                       return 0;
+           case AUTH_REQ_KRB5:
+               self->errormsg = "Kerberos 5 authentication not supported";
+               self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
+               return 0;
 
-                   case AUTH_REQ_PASSWORD:
-                       mylog("in AUTH_REQ_PASSWORD\n");
+           case AUTH_REQ_PASSWORD:
+               mylog("in AUTH_REQ_PASSWORD\n");
 
-                       if (ci->password[0] == '\0')
-                       {
-                           self->errornumber = CONNECTION_NEED_PASSWORD;
-                           self->errormsg = "A password is required for this connection.";
-                           return -1;  /* need password */
-                       }
+               if (ci->password[0] == '\0') {
+                   self->errornumber = CONNECTION_NEED_PASSWORD;
+                   self->errormsg = "A password is required for this connection.";
+                   return -1;  /* need password */
+               }
 
-                       mylog("past need password\n");
+               mylog("past need password\n");
 
-                       SOCK_put_int(sock, 4 + strlen(ci->password) + 1, 4);
-                       SOCK_put_n_char(sock, ci->password, strlen(ci->password) + 1);
-                       SOCK_flush_output(sock);
+               SOCK_put_int(sock, 4+strlen(ci->password)+1, 4);
+               SOCK_put_n_char(sock, ci->password, strlen(ci->password) + 1);
+               SOCK_flush_output(sock);
 
-                       mylog("past flush\n");
-                       break;
+               mylog("past flush\n");
+               break;
 
-                   case AUTH_REQ_CRYPT:
-                       self->errormsg = "Password crypt authentication not supported";
-                       self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
-                       return 0;
+           case AUTH_REQ_CRYPT:
+               self->errormsg = "Password crypt authentication not supported";
+               self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
+               return 0;
 
-                   default:
-                       self->errormsg = "Unknown authentication type";
-                       self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
-                       return 0;
-               }
-               break;
            default:
-               self->errormsg = "Unexpected protocol character during authentication";
-               self->errornumber = CONN_INVALID_AUTHENTICATION;
+               self->errormsg = "Unknown authentication type";
+               self->errornumber = CONN_AUTH_TYPE_UNSUPPORTED;
                return 0;
+           }
+           break;
+       default:
+           self->errormsg = "Unexpected protocol character during authentication";
+           self->errornumber = CONN_INVALID_AUTHENTICATION;
+           return 0;
        }
-   } while (areq != AUTH_REQ_OK);
 
-   CC_clear_error(self);       /* clear any password error */
+   } while (areq != AUTH_REQ_OK);      
+
+
+   CC_clear_error(self);   /* clear any password error */
 
    /* send an empty query in order to find out whether the specified */
    /* database really exists on the server machine */
    mylog("sending an empty query...\n");
 
    res = CC_send_query(self, " ", NULL);
-   if (res == NULL || QR_get_status(res) != PGRES_EMPTY_QUERY)
-   {
+   if ( res == NULL || QR_get_status(res) != PGRES_EMPTY_QUERY) {
        mylog("got no result from the empty query.  (probably database does not exist)\n");
        self->errornumber = CONNECTION_NO_SUCH_DATABASE;
        self->errormsg = "The database does not exist on the server\nor user authentication failed.";
@@ -706,43 +693,38 @@ CC_connect(ConnectionClass *self, char do_password)
 
    mylog("empty query seems to be OK.\n");
 
-   CC_set_translation(self);
+   CC_set_translation (self);
 
    /**********************************************/
    /*******   Send any initial settings  *********/
    /**********************************************/
 
-   /*
-    * Since these functions allocate statements, and since the connection
-    * is not established yet, it would violate odbc state transition
-    * rules.  Therefore, these functions call the corresponding local
-    * function instead.
-    */
+   /*  Since these functions allocate statements, and since the connection is not
+       established yet, it would violate odbc state transition rules.  Therefore,
+       these functions call the corresponding local function instead.
+   */
    CC_send_settings(self);
-   CC_lookup_lo(self);         /* a hack to get the oid of our large
-                                * object oid type */
-   CC_lookup_pg_version(self); /* Get PostgreSQL version for SQLGetInfo
-                                * use */
+   CC_lookup_lo(self);     /* a hack to get the oid of our large object oid type */
+   CC_lookup_pg_version(self); /* Get PostgreSQL version for SQLGetInfo use */
 
-   CC_clear_error(self);       /* clear any initial command errors */
+   CC_clear_error(self);   /* clear any initial command errors */
    self->status = CONN_CONNECTED;
 
    mylog("%s: returning...\n", func);
 
    return 1;
+
 }
 
 char
 CC_add_statement(ConnectionClass *self, StatementClass *stmt)
 {
-   int         i;
+int i;
 
    mylog("CC_add_statement: self=%u, stmt=%u\n", self, stmt);
 
-   for (i = 0; i < self->num_stmts; i++)
-   {
-       if (!self->stmts[i])
-       {
+   for (i = 0; i < self->num_stmts; i++) {
+       if ( ! self->stmts[i]) {
            stmt->hdbc = self;
            self->stmts[i] = stmt;
            return TRUE;
@@ -750,8 +732,8 @@ CC_add_statement(ConnectionClass *self, StatementClass *stmt)
    }
 
    /* no more room -- allocate more memory */
-   self->stmts = (StatementClass **) realloc(self->stmts, sizeof(StatementClass *) * (STMT_INCREMENT + self->num_stmts));
-   if (!self->stmts)
+   self->stmts = (StatementClass **) realloc( self->stmts, sizeof(StatementClass *) * (STMT_INCREMENT + self->num_stmts));
+   if ( ! self->stmts)
        return FALSE;
 
    memset(&self->stmts[self->num_stmts], 0, sizeof(StatementClass *) * STMT_INCREMENT);
@@ -764,15 +746,13 @@ CC_add_statement(ConnectionClass *self, StatementClass *stmt)
    return TRUE;
 }
 
-char
+char 
 CC_remove_statement(ConnectionClass *self, StatementClass *stmt)
 {
-   int         i;
+int i;
 
-   for (i = 0; i < self->num_stmts; i++)
-   {
-       if (self->stmts[i] == stmt && stmt->status != STMT_EXECUTING)
-       {
+   for (i = 0; i < self->num_stmts; i++) {
+       if (self->stmts[i] == stmt && stmt->status != STMT_EXECUTING) {
            self->stmts[i] = NULL;
            return TRUE;
        }
@@ -787,9 +767,9 @@ CC_remove_statement(ConnectionClass *self, StatementClass *stmt)
 char *
 CC_create_errormsg(ConnectionClass *self)
 {
-   SocketClass *sock = self->sock;
-   int         pos;
-   static char msg[4096];
+SocketClass *sock = self->sock;
+int pos;
+static char msg[4096];
 
    mylog("enter CC_create_errormsg\n");
 
@@ -800,8 +780,7 @@ CC_create_errormsg(ConnectionClass *self)
 
    mylog("msg = '%s'\n", msg);
 
-   if (sock && sock->errormsg && sock->errormsg[0] != '\0')
-   {
+   if (sock && sock->errormsg && sock->errormsg[0] != '\0') {
        pos = strlen(msg);
        sprintf(&msg[pos], ";\n%s", sock->errormsg);
    }
@@ -811,22 +790,20 @@ CC_create_errormsg(ConnectionClass *self)
 }
 
 
-char
+char 
 CC_get_error(ConnectionClass *self, int *number, char **message)
 {
-   int         rv;
+int rv;
 
    mylog("enter CC_get_error\n");
 
-   /* Create a very informative errormsg if it hasn't been done yet. */
-   if (!self->errormsg_created)
-   {
+   /*  Create a very informative errormsg if it hasn't been done yet. */
+   if ( ! self->errormsg_created) {
        self->errormsg = CC_create_errormsg(self);
        self->errormsg_created = TRUE;
    }
 
-   if (self->errornumber)
-   {
+   if (self->errornumber) {
        *number = self->errornumber;
        *message = self->errormsg;
    }
@@ -845,29 +822,25 @@ CC_get_error(ConnectionClass *self, int *number, char **message)
    needs to be re-filled).
 
    The "cursor" is used by SQLExecute to associate a statement handle as the cursor name
-   (i.e., C3326857) for SQL select statements.  This cursor is then used in future
+   (i.e., C3326857) for SQL select statements.  This cursor is then used in future 
    'declare cursor C3326857 for ...' and 'fetch 100 in C3326857' statements.
 */
 QResultClass *
 CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 {
-   QResultClass *result_in,
-              *res = NULL;
-   char        swallow;
-   int         id;
-   SocketClass *sock = self->sock;
-   static char msgbuffer[MAX_MESSAGE_LEN + 1];
-   char        cmdbuffer[MAX_MESSAGE_LEN + 1]; /* QR_set_command() dups
-                                                * this string so dont
-                                                * need static */
+QResultClass *result_in, *res = NULL;
+char swallow;
+int id;
+SocketClass *sock = self->sock;
+static char msgbuffer[MAX_MESSAGE_LEN+1];
+char cmdbuffer[MAX_MESSAGE_LEN+1]; /* QR_set_command() dups this string so dont need static */
 
 
    mylog("send_query(): conn=%u, query='%s'\n", self, query);
    qlog("conn=%u, query='%s'\n", self, query);
 
    /* Indicate that we are sending a query to the backend */
-   if (strlen(query) > MAX_MESSAGE_LEN - 2)
-   {
+   if(strlen(query) > MAX_MESSAGE_LEN-2) {
        self->errornumber = CONNECTION_MSG_TOO_LONG;
        self->errormsg = "Query string is too long";
        return NULL;
@@ -876,8 +849,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
    if ((NULL == query) || (query[0] == '\0'))
        return NULL;
 
-   if (SOCK_get_errcode(sock) != 0)
-   {
+   if (SOCK_get_errcode(sock) != 0) {
        self->errornumber = CONNECTION_COULD_NOT_SEND;
        self->errormsg = "Could not send Query to backend";
        CC_set_no_trans(self);
@@ -885,8 +857,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
    }
 
    SOCK_put_char(sock, 'Q');
-   if (SOCK_get_errcode(sock) != 0)
-   {
+   if (SOCK_get_errcode(sock) != 0) {
        self->errornumber = CONNECTION_COULD_NOT_SEND;
        self->errormsg = "Could not send Query to backend";
        CC_set_no_trans(self);
@@ -896,8 +867,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
    SOCK_put_string(sock, query);
    SOCK_flush_output(sock);
 
-   if (SOCK_get_errcode(sock) != 0)
-   {
+   if (SOCK_get_errcode(sock) != 0) {
        self->errornumber = CONNECTION_COULD_NOT_SEND;
        self->errormsg = "Could not send Query to backend";
        CC_set_no_trans(self);
@@ -906,13 +876,11 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 
    mylog("send_query: done sending query\n");
 
-   while (1)
-   {
+   while(1) {
        /* what type of message is coming now ? */
        id = SOCK_get_char(sock);
 
-       if ((SOCK_get_errcode(sock) != 0) || (id == EOF))
-       {
+       if ((SOCK_get_errcode(sock) != 0) || (id == EOF)) {
            self->errornumber = CONNECTION_NO_RESPONSE;
            self->errormsg = "No response from the backend";
            if (res)
@@ -925,218 +893,197 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 
        mylog("send_query: got id = '%c'\n", id);
 
-       switch (id)
-       {
-           case 'A':           /* Asynchronous Messages are ignored */
-               (void) SOCK_get_int(sock, 4);   /* id of notification */
-               SOCK_get_string(sock, msgbuffer, MAX_MESSAGE_LEN);
-               /* name of the relation the message comes from */
-               break;
-           case 'C':           /* portal query command, no tuples
-                                * returned */
-               /* read in the return message from the backend */
-               SOCK_get_string(sock, cmdbuffer, MAX_MESSAGE_LEN);
-               if (SOCK_get_errcode(sock) != 0)
-               {
-                   self->errornumber = CONNECTION_NO_RESPONSE;
-                   self->errormsg = "No response from backend while receiving a portal query command";
-                   mylog("send_query: 'C' - %s\n", self->errormsg);
-                   CC_set_no_trans(self);
-                   return NULL;
-               }
-               else
-               {
-                   char        clear = 0;
-
-                   mylog("send_query: ok - 'C' - %s\n", cmdbuffer);
-
-                   if (res == NULL)    /* allow for "show" style notices */
-                       res = QR_Constructor();
-
-                   mylog("send_query: setting cmdbuffer = '%s'\n", cmdbuffer);
-
-                   /* Only save the first command */
-                   QR_set_status(res, PGRES_COMMAND_OK);
-                   QR_set_command(res, cmdbuffer);
-
-                   /*
-                    * (Quotation from the original comments) since
-                    * backend may produce more than one result for some
-                    * commands we need to poll until clear so we send an
-                    * empty query, and keep reading out of the pipe until
-                    * an 'I' is received
-                    */
-
-                   SOCK_put_string(sock, "Q ");
-                   SOCK_flush_output(sock);
-
-                   while (!clear)
-                   {
-                       id = SOCK_get_char(sock);
-                       switch (id)
-                       {
-                           case 'I':
-                               (void) SOCK_get_char(sock);
-                               clear = TRUE;
-                               break;
-                           case 'Z':
-                               break;
-                           case 'C':
-                               SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
-                               qlog("Command response: '%s'\n", cmdbuffer);
-                               break;
-                           case 'N':
-                               SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
-                               qlog("NOTICE from backend during clear: '%s'\n", cmdbuffer);
-                               break;
-                           case 'E':
-                               SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
-                               qlog("ERROR from backend during clear: '%s'\n", cmdbuffer);
-
-                               /*
-                                * We must report this type of error as
-                                * well (practically for reference
-                                * integrity violation error reporting,
-                                * from PostgreSQL 7.0). (Zoltan Kovacs,
-                                * 04/26/2000)
-                                */
-                               self->errormsg = cmdbuffer;
-                               if (!strncmp(self->errormsg, "FATAL", 5))
-                               {
-                                   self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
-                                   CC_set_no_trans(self);
-                               }
-                               else
-                                   self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
-                               QR_set_status(res, PGRES_NONFATAL_ERROR);
-                               break;
-                       }
-                   }
-
-                   mylog("send_query: returning res = %u\n", res);
-                   return res;
-               }
-           case 'K':           /* Secret key (6.4 protocol) */
-               (void) SOCK_get_int(sock, 4);   /* pid */
-               (void) SOCK_get_int(sock, 4);   /* key */
-
-               break;
-           case 'Z':           /* Backend is ready for new query (6.4) */
-               break;
-           case 'N':           /* NOTICE: */
-               SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
-
-               res = QR_Constructor();
-               QR_set_status(res, PGRES_NONFATAL_ERROR);
-               QR_set_notice(res, cmdbuffer);  /* will dup this string */
+       switch (id) {
+       case 'A' : /* Asynchronous Messages are ignored */
+           (void)SOCK_get_int(sock, 4); /* id of notification */
+           SOCK_get_string(sock, msgbuffer, MAX_MESSAGE_LEN);
+           /* name of the relation the message comes from */
+           break;
+       case 'C' : /* portal query command, no tuples returned */
+           /* read in the return message from the backend */
+           SOCK_get_string(sock, cmdbuffer, MAX_MESSAGE_LEN);
+           if (SOCK_get_errcode(sock) != 0) {
+               self->errornumber = CONNECTION_NO_RESPONSE;
+               self->errormsg = "No response from backend while receiving a portal query command";
+               mylog("send_query: 'C' - %s\n", self->errormsg);
+               CC_set_no_trans(self);
+               return NULL;
+           } else {
 
-               mylog("~~~ NOTICE: '%s'\n", cmdbuffer);
-               qlog("NOTICE from backend during send_query: '%s'\n", cmdbuffer);
+               char clear = 0;
 
-               continue;       /* dont return a result -- continue
-                                * reading */
+               mylog("send_query: ok - 'C' - %s\n", cmdbuffer);
 
-           case 'I':           /* The server sends an empty query */
-               /* There is a closing '\0' following the 'I', so we eat it */
-               swallow = SOCK_get_char(sock);
-               if ((swallow != '\0') || SOCK_get_errcode(sock) != 0)
-               {
-                   self->errornumber = CONNECTION_BACKEND_CRAZY;
-                   self->errormsg = "Unexpected protocol character from backend (send_query - I)";
-                   res = QR_Constructor();
-                   QR_set_status(res, PGRES_FATAL_ERROR);
-                   return res;
-               }
-               else
-               {
-                   /* We return the empty query */
+               if (res == NULL)    /* allow for "show" style notices */
                    res = QR_Constructor();
-                   QR_set_status(res, PGRES_EMPTY_QUERY);
-                   return res;
-               }
-               break;
-           case 'E':
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
 
-               /* Remove a newline */
-               if (msgbuffer[0] != '\0' && msgbuffer[strlen(msgbuffer) - 1] == '\n')
-                   msgbuffer[strlen(msgbuffer) - 1] = '\0';
+               mylog("send_query: setting cmdbuffer = '%s'\n", cmdbuffer);
 
-               self->errormsg = msgbuffer;
+               /*  Only save the first command */
+               QR_set_status(res, PGRES_COMMAND_OK);
+               QR_set_command(res, cmdbuffer);
 
-               mylog("send_query: 'E' - %s\n", self->errormsg);
-               qlog("ERROR from backend during send_query: '%s'\n", self->errormsg);
+               /* (Quotation from the original comments)
+                   since backend may produce more than one result for some commands
+                   we need to poll until clear
+                   so we send an empty query, and keep reading out of the pipe
+                   until an 'I' is received
+               */
 
-               /* We should report that an error occured. Zoltan */
-               res = QR_Constructor();
 
-               if (!strncmp(self->errormsg, "FATAL", 5))
-               {
-                   self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
-                   CC_set_no_trans(self);
-                   QR_set_status(res, PGRES_FATAL_ERROR);
-               }
-               else
-               {
-                   self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
-                   QR_set_status(res, PGRES_NONFATAL_ERROR);
+               SOCK_put_string(sock, "Q ");
+               SOCK_flush_output(sock);
+
+               while( ! clear) {
+                   id = SOCK_get_char(sock);
+                   switch(id) {
+                   case 'I':
+                       (void) SOCK_get_char(sock);
+                       clear = TRUE;
+                       break;
+                   case 'Z':
+                       break;
+                   case 'C':
+                       SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+                       qlog("Command response: '%s'\n", cmdbuffer);
+                       break;
+                   case 'N':
+                       SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+                       qlog("NOTICE from backend during clear: '%s'\n", cmdbuffer);
+                       break;
+                   case 'E':
+                       SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+                       qlog("ERROR from backend during clear: '%s'\n", cmdbuffer);
+                       /* We must report this type of error as well
+                          (practically for reference integrity violation
+                          error reporting, from PostgreSQL 7.0).
+                          (Zoltan Kovacs, 04/26/2000)
+                       */
+                       self->errormsg = cmdbuffer;
+                       if ( ! strncmp(self->errormsg, "FATAL", 5)) {
+                           self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
+                           CC_set_no_trans(self);
+                           }
+                       else 
+                           self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
+                       QR_set_status(res, PGRES_NONFATAL_ERROR);
+                       break;
+                   }
                }
+               
+               mylog("send_query: returning res = %u\n", res);
+               return res;
+           }
+       case 'K':   /* Secret key (6.4 protocol) */
+           (void)SOCK_get_int(sock, 4); /* pid */
+           (void)SOCK_get_int(sock, 4); /* key */
 
-               return res;     /* instead of NULL. Zoltan */
+           break;
+       case 'Z':   /* Backend is ready for new query (6.4) */
+           break;
+       case 'N' : /* NOTICE: */
+           SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
 
-           case 'P':           /* get the Portal name */
-               SOCK_get_string(sock, msgbuffer, MAX_MESSAGE_LEN);
-               break;
-           case 'T':           /* Tuple results start here */
-               result_in = qi ? qi->result_in : NULL;
-
-               if (result_in == NULL)
-               {
-                   result_in = QR_Constructor();
-                   mylog("send_query: 'T' no result_in: res = %u\n", result_in);
-                   if (!result_in)
-                   {
-                       self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
-                       self->errormsg = "Could not create result info in send_query.";
-                       return NULL;
-                   }
+           res = QR_Constructor();
+           QR_set_status(res, PGRES_NONFATAL_ERROR);
+           QR_set_notice(res, cmdbuffer);  /* will dup this string */
 
-                   if (qi)
-                       QR_set_cache_size(result_in, qi->row_size);
+           mylog("~~~ NOTICE: '%s'\n", cmdbuffer);
+           qlog("NOTICE from backend during send_query: '%s'\n", cmdbuffer);
 
-                   if (!QR_fetch_tuples(result_in, self, qi ? qi->cursor : NULL))
-                   {
-                       self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
-                       self->errormsg = QR_get_message(result_in);
-                       return NULL;
-                   }
-               }
-               else
-               {               /* next fetch, so reuse an existing result */
-                   if (!QR_fetch_tuples(result_in, NULL, NULL))
-                   {
-                       self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
-                       self->errormsg = QR_get_message(result_in);
-                       return NULL;
-                   }
-               }
+           continue;       /* dont return a result -- continue reading */
 
-               return result_in;
-           case 'D':           /* Copy in command began successfully */
+       case 'I' : /* The server sends an empty query */
+               /* There is a closing '\0' following the 'I', so we eat it */
+           swallow = SOCK_get_char(sock);
+           if ((swallow != '\0') || SOCK_get_errcode(sock) != 0) {
+               self->errornumber = CONNECTION_BACKEND_CRAZY;
+               self->errormsg = "Unexpected protocol character from backend (send_query - I)";
                res = QR_Constructor();
-               QR_set_status(res, PGRES_COPY_IN);
+               QR_set_status(res, PGRES_FATAL_ERROR);
                return res;
-           case 'B':           /* Copy out command began successfully */
+           } else {
+               /* We return the empty query */
                res = QR_Constructor();
-               QR_set_status(res, PGRES_COPY_OUT);
+               QR_set_status(res, PGRES_EMPTY_QUERY);
                return res;
-           default:
-               self->errornumber = CONNECTION_BACKEND_CRAZY;
-               self->errormsg = "Unexpected protocol character from backend (send_query)";
+           }
+           break;
+       case 'E' : 
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+
+           /*  Remove a newline */
+           if (msgbuffer[0] != '\0' && msgbuffer[strlen(msgbuffer)-1] == '\n')
+               msgbuffer[strlen(msgbuffer)-1] = '\0';
+
+           self->errormsg = msgbuffer;
+
+           mylog("send_query: 'E' - %s\n", self->errormsg);
+           qlog("ERROR from backend during send_query: '%s'\n", self->errormsg);
+
+           /* We should report that an error occured. Zoltan */
+           res = QR_Constructor();
+
+           if ( ! strncmp(self->errormsg, "FATAL", 5)) {
+               self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
                CC_set_no_trans(self);
+               QR_set_status(res, PGRES_FATAL_ERROR);
+           }
+           else {
+               self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
+               QR_set_status(res, PGRES_NONFATAL_ERROR);
+           }
 
-               mylog("send_query: error - %s\n", self->errormsg);
-               return NULL;
+           return res; /* instead of NULL. Zoltan */
+
+       case 'P' : /* get the Portal name */
+           SOCK_get_string(sock, msgbuffer, MAX_MESSAGE_LEN);
+           break;
+       case 'T': /* Tuple results start here */
+           result_in = qi ? qi->result_in : NULL;
+
+           if ( result_in == NULL) {
+               result_in = QR_Constructor();
+               mylog("send_query: 'T' no result_in: res = %u\n", result_in);
+               if ( ! result_in) {
+                   self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
+                   self->errormsg = "Could not create result info in send_query.";
+                   return NULL;
+               }
+
+               if (qi)
+                   QR_set_cache_size(result_in, qi->row_size);
+
+               if ( ! QR_fetch_tuples(result_in, self, qi ? qi->cursor : NULL)) {
+                   self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
+                   self->errormsg = QR_get_message(result_in);
+                   return NULL;
+               }
+           }
+           else {  /* next fetch, so reuse an existing result */
+               if ( ! QR_fetch_tuples(result_in, NULL, NULL)) {
+                   self->errornumber = CONNECTION_COULD_NOT_RECEIVE;
+                   self->errormsg = QR_get_message(result_in);
+                   return NULL;
+               }
+           }
+
+           return result_in;
+       case 'D': /* Copy in command began successfully */
+           res = QR_Constructor();
+           QR_set_status(res, PGRES_COPY_IN);
+           return res;
+       case 'B': /* Copy out command began successfully */
+           res = QR_Constructor();
+           QR_set_status(res, PGRES_COPY_OUT);
+           return res;
+       default:
+           self->errornumber = CONNECTION_BACKEND_CRAZY;
+           self->errormsg = "Unexpected protocol character from backend (send_query)";
+           CC_set_no_trans(self);
+
+           mylog("send_query: error - %s\n", self->errormsg);
+           return NULL;
        }
    }
 }
@@ -1144,17 +1091,14 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 int
 CC_send_function(ConnectionClass *self, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *args, int nargs)
 {
-   char        id,
-               c,
-               done;
-   SocketClass *sock = self->sock;
-   static char msgbuffer[MAX_MESSAGE_LEN + 1];
-   int         i;
+char id, c, done;
+SocketClass *sock = self->sock;
+static char msgbuffer[MAX_MESSAGE_LEN+1];
+int i;
 
    mylog("send_function(): conn=%u, fnid=%d, result_is_int=%d, nargs=%d\n", self, fnid, result_is_int, nargs);
 
-   if (SOCK_get_errcode(sock) != 0)
-   {
+   if (SOCK_get_errcode(sock) != 0) {
        self->errornumber = CONNECTION_COULD_NOT_SEND;
        self->errormsg = "Could not send function to backend";
        CC_set_no_trans(self);
@@ -1162,28 +1106,30 @@ CC_send_function(ConnectionClass *self, int fnid, void *result_buf, int *actual_
    }
 
    SOCK_put_string(sock, "F ");
-   if (SOCK_get_errcode(sock) != 0)
-   {
+   if (SOCK_get_errcode(sock) != 0) {
        self->errornumber = CONNECTION_COULD_NOT_SEND;
        self->errormsg = "Could not send function to backend";
        CC_set_no_trans(self);
        return FALSE;
    }
 
-   SOCK_put_int(sock, fnid, 4);
-   SOCK_put_int(sock, nargs, 4);
+   SOCK_put_int(sock, fnid, 4); 
+   SOCK_put_int(sock, nargs, 4); 
+
 
    mylog("send_function: done sending function\n");
 
-   for (i = 0; i < nargs; ++i)
-   {
+   for (i = 0; i < nargs; ++i) {
+
        mylog("  arg[%d]: len = %d, isint = %d, integer = %d, ptr = %u\n", i, args[i].len, args[i].isint, args[i].u.integer, args[i].u.ptr);
 
        SOCK_put_int(sock, args[i].len, 4);
-       if (args[i].isint)
+       if (args[i].isint) 
            SOCK_put_int(sock, args[i].u.integer, 4);
        else
            SOCK_put_n_char(sock, (char *) args[i].u.ptr, args[i].len);
+
+
    }
 
    mylog("    done sending args\n");
@@ -1192,97 +1138,92 @@ CC_send_function(ConnectionClass *self, int fnid, void *result_buf, int *actual_
    mylog("  after flush output\n");
 
    done = FALSE;
-   while (!done)
-   {
+   while ( ! done) {
        id = SOCK_get_char(sock);
        mylog("   got id = %c\n", id);
 
-       switch (id)
-       {
-           case 'V':
-               done = TRUE;
-               break;          /* ok */
+       switch(id) {
+       case 'V':
+           done = TRUE;
+           break;      /* ok */
 
-           case 'N':
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
-               mylog("send_function(V): 'N' - %s\n", msgbuffer);
-               /* continue reading */
-               break;
+       case 'N':
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+           mylog("send_function(V): 'N' - %s\n", msgbuffer);
+           /*  continue reading */
+           break;
 
-           case 'E':
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
-               self->errormsg = msgbuffer;
+       case 'E':
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+           self->errormsg = msgbuffer;
 
-               mylog("send_function(V): 'E' - %s\n", self->errormsg);
-               qlog("ERROR from backend during send_function: '%s'\n", self->errormsg);
+           mylog("send_function(V): 'E' - %s\n", self->errormsg);
+           qlog("ERROR from backend during send_function: '%s'\n", self->errormsg);
 
-               return FALSE;
+           return FALSE;
 
-           case 'Z':
-               break;
+       case 'Z':
+           break;
 
-           default:
-               self->errornumber = CONNECTION_BACKEND_CRAZY;
-               self->errormsg = "Unexpected protocol character from backend (send_function, args)";
-               CC_set_no_trans(self);
+       default:
+           self->errornumber = CONNECTION_BACKEND_CRAZY;
+           self->errormsg = "Unexpected protocol character from backend (send_function, args)";
+           CC_set_no_trans(self);
 
-               mylog("send_function: error - %s\n", self->errormsg);
-               return FALSE;
+           mylog("send_function: error - %s\n", self->errormsg);
+           return FALSE;
        }
    }
 
    id = SOCK_get_char(sock);
-   for (;;)
-   {
-       switch (id)
-       {
-           case 'G':           /* function returned properly */
-               mylog("  got G!\n");
+   for (;;) {
+       switch (id) {
+       case 'G':   /* function returned properly */
+           mylog("  got G!\n");
 
-               *actual_result_len = SOCK_get_int(sock, 4);
-               mylog("  actual_result_len = %d\n", *actual_result_len);
+           *actual_result_len = SOCK_get_int(sock, 4);
+           mylog("  actual_result_len = %d\n", *actual_result_len);
 
-               if (result_is_int)
-                   *((int *) result_buf) = SOCK_get_int(sock, 4);
-               else
-                   SOCK_get_n_char(sock, (char *) result_buf, *actual_result_len);
+           if (result_is_int)
+               *((int *) result_buf) = SOCK_get_int(sock, 4);
+           else
+               SOCK_get_n_char(sock, (char *) result_buf, *actual_result_len);
 
-               mylog("  after get result\n");
+           mylog("  after get result\n");
 
-               c = SOCK_get_char(sock);        /* get the last '0' */
+           c = SOCK_get_char(sock);    /* get the last '0' */
 
-               mylog("   after get 0\n");
+           mylog("   after get 0\n");
 
-               return TRUE;
+           return TRUE;
 
-           case 'E':
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
-               self->errormsg = msgbuffer;
+       case 'E':
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+           self->errormsg = msgbuffer;
 
-               mylog("send_function(G): 'E' - %s\n", self->errormsg);
-               qlog("ERROR from backend during send_function: '%s'\n", self->errormsg);
+           mylog("send_function(G): 'E' - %s\n", self->errormsg);
+           qlog("ERROR from backend during send_function: '%s'\n", self->errormsg);
 
-               return FALSE;
+           return FALSE;
 
-           case 'N':
-               SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+       case 'N':
+           SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
 
-               mylog("send_function(G): 'N' - %s\n", msgbuffer);
-               qlog("NOTICE from backend during send_function: '%s'\n", msgbuffer);
+           mylog("send_function(G): 'N' - %s\n", msgbuffer);
+           qlog("NOTICE from backend during send_function: '%s'\n", msgbuffer);
 
-               continue;       /* dont return a result -- continue
-                                * reading */
+           continue;       /* dont return a result -- continue reading */
 
-           case '0':           /* empty result */
-               return TRUE;
+       case '0':   /* empty result */
+           return TRUE;
 
-           default:
-               self->errornumber = CONNECTION_BACKEND_CRAZY;
-               self->errormsg = "Unexpected protocol character from backend (send_function, result)";
-               CC_set_no_trans(self);
+       default:
+           self->errornumber = CONNECTION_BACKEND_CRAZY;
+           self->errormsg = "Unexpected protocol character from backend (send_function, result)";
+           CC_set_no_trans(self);
 
-               mylog("send_function: error - %s\n", self->errormsg);
-               return FALSE;
+           mylog("send_function: error - %s\n", self->errormsg);
+           return FALSE;
        }
    }
 }
@@ -1291,68 +1232,65 @@ CC_send_function(ConnectionClass *self, int fnid, void *result_buf, int *actual_
 char
 CC_send_settings(ConnectionClass *self)
 {
-   /* char ini_query[MAX_MESSAGE_LEN]; */
-   ConnInfo   *ci = &(self->connInfo);
-
+  /* char ini_query[MAX_MESSAGE_LEN]; */
+ConnInfo *ci = &(self->connInfo);
 /* QResultClass *res; */
-   HSTMT       hstmt;
-   StatementClass *stmt;
-   RETCODE     result;
-   char        status = TRUE;
-   char       *cs,
-              *ptr;
-   static char *func = "CC_send_settings";
+HSTMT hstmt;
+StatementClass *stmt;
+RETCODE result;
+char status = TRUE;
+char *cs, *ptr;
+static char *func="CC_send_settings";
 
 
    mylog("%s: entering...\n", func);
 
-/* This function must use the local odbc API functions since the odbc state
+/* This function must use the local odbc API functions since the odbc state 
    has not transitioned to "connected" yet.
 */
 
-   result = SQLAllocStmt(self, &hstmt);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+   result = SQLAllocStmt( self, &hstmt);
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        return FALSE;
+   }
    stmt = (StatementClass *) hstmt;
 
-   stmt->internal = TRUE;      /* ensure no BEGIN/COMMIT/ABORT stuff */
+   stmt->internal = TRUE;  /* ensure no BEGIN/COMMIT/ABORT stuff */
 
-   /* Set the Datestyle to the format the driver expects it to be in */
+   /*  Set the Datestyle to the format the driver expects it to be in */
    result = SQLExecDirect(hstmt, "set DateStyle to 'ISO'", SQL_NTS);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
        status = FALSE;
 
    mylog("%s: result %d, status %d from set DateStyle\n", func, result, status);
 
-   /* Disable genetic optimizer based on global flag */
-   if (globals.disable_optimizer)
-   {
+   /*  Disable genetic optimizer based on global flag */
+   if (globals.disable_optimizer) {
        result = SQLExecDirect(hstmt, "set geqo to 'OFF'", SQL_NTS);
-       if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+       if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
            status = FALSE;
 
        mylog("%s: result %d, status %d from set geqo\n", func, result, status);
+   
    }
 
-   /* KSQO */
-   if (globals.ksqo)
-   {
+   /*  KSQO */
+   if (globals.ksqo) {
        result = SQLExecDirect(hstmt, "set ksqo to 'ON'", SQL_NTS);
-       if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+       if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
            status = FALSE;
 
        mylog("%s: result %d, status %d from set ksqo\n", func, result, status);
+   
    }
 
-   /* Global settings */
-   if (globals.conn_settings[0] != '\0')
-   {
+   /*  Global settings */
+   if (globals.conn_settings[0] != '\0') {
        cs = strdup(globals.conn_settings);
        ptr = strtok(cs, ";");
-       while (ptr)
-       {
+       while (ptr) {
            result = SQLExecDirect(hstmt, ptr, SQL_NTS);
-           if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+           if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
                status = FALSE;
 
            mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr);
@@ -1362,16 +1300,14 @@ CC_send_settings(ConnectionClass *self)
 
        free(cs);
    }
-
-   /* Per Datasource settings */
-   if (ci->conn_settings[0] != '\0')
-   {
+   
+   /*  Per Datasource settings */
+   if (ci->conn_settings[0] != '\0') {
        cs = strdup(ci->conn_settings);
        ptr = strtok(cs, ";");
-       while (ptr)
-       {
+       while (ptr) {
            result = SQLExecDirect(hstmt, ptr, SQL_NTS);
-           if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+           if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
                status = FALSE;
 
            mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr);
@@ -1393,40 +1329,38 @@ CC_send_settings(ConnectionClass *self)
    will go away and the define 'PG_TYPE_LO' will be updated.
 */
 void
-CC_lookup_lo(ConnectionClass *self)
+CC_lookup_lo(ConnectionClass *self) 
 {
-   HSTMT       hstmt;
-   StatementClass *stmt;
-   RETCODE     result;
-   static char *func = "CC_lookup_lo";
+HSTMT hstmt;
+StatementClass *stmt;
+RETCODE result;
+static char *func = "CC_lookup_lo";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-/* This function must use the local odbc API functions since the odbc state
+/* This function must use the local odbc API functions since the odbc state 
    has not transitioned to "connected" yet.
 */
-   result = SQLAllocStmt(self, &hstmt);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+   result = SQLAllocStmt( self, &hstmt);
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        return;
+   }
    stmt = (StatementClass *) hstmt;
 
    result = SQLExecDirect(hstmt, "select oid from pg_type where typname='" PG_TYPE_LO_NAME "'", SQL_NTS);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
 
    result = SQLFetch(hstmt);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
 
    result = SQLGetData(hstmt, 1, SQL_C_SLONG, &self->lobj_type, sizeof(self->lobj_type), NULL);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
@@ -1442,57 +1376,63 @@ CC_lookup_lo(ConnectionClass *self)
    h-inoue 01-2-2001
 */
 void
-CC_initialize_pg_version(ConnectionClass *self)
+CC_initialize_pg_version(ConnectionClass *self) 
 {
-   strcpy(self->pg_version, self->connInfo.protocol);
-   self->pg_version_number = (float) 6.4;
-   self->pg_version_major = 6;
-   self->pg_version_minor = 4;
+   strcpy(self->pg_version, self->connInfo.protocol); 
+   if (PROTOCOL_62(&self->connInfo)) {
+       self->pg_version_number = (float) 6.2;
+       self->pg_version_major = 6;
+       self->pg_version_minor = 2;
+   } else if (PROTOCOL_63(&self->connInfo)) {
+       self->pg_version_number = (float) 6.3;
+       self->pg_version_major = 6;
+       self->pg_version_minor = 3;
+   } else {
+       self->pg_version_number = (float) 6.4;
+       self->pg_version_major = 6;
+       self->pg_version_minor = 4;
+   }
 }
-
 /* This function gets the version of PostgreSQL that we're connected to.
-   This is used to return the correct info in SQLGetInfo
+    This is used to return the correct info in SQLGetInfo
    DJP - 25-1-2001
 */
 void
-CC_lookup_pg_version(ConnectionClass *self)
+CC_lookup_pg_version(ConnectionClass *self) 
 {
-   HSTMT       hstmt;
-   StatementClass *stmt;
-   RETCODE     result;
-   char        szVersion[32];
-   int         major,
-               minor;
-   static char *func = "CC_lookup_pg_version";
+HSTMT hstmt;
+StatementClass *stmt;
+RETCODE result;
+char   szVersion[32];
+int    major, minor;
+static char *func = "CC_lookup_pg_version";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-/* This function must use the local odbc API functions since the odbc state
+/* This function must use the local odbc API functions since the odbc state 
    has not transitioned to "connected" yet.
 */
-   result = SQLAllocStmt(self, &hstmt);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+   result = SQLAllocStmt( self, &hstmt);
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        return;
+   }
    stmt = (StatementClass *) hstmt;
 
-   /* get the server's version if possible  */
+   /*  get the server's version if possible    */
    result = SQLExecDirect(hstmt, "select version()", SQL_NTS);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
 
    result = SQLFetch(hstmt);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
 
    result = SQLGetData(hstmt, 1, SQL_C_CHAR, self->pg_version, MAX_INFO_STRING, NULL);
-   if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
-   {
+   if((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
        SQLFreeStmt(hstmt, SQL_DROP);
        return;
    }
@@ -1500,8 +1440,7 @@ CC_lookup_pg_version(ConnectionClass *self)
    /* Extract the Major and Minor numbers from the string. */
    /* This assumes the string starts 'Postgresql X.X' */
    strcpy(szVersion, "0.0");
-   if (sscanf(self->pg_version, "%*s %d.%d", &major, &minor) >= 2)
-   {
+   if (sscanf(self->pg_version, "%*s %d.%d", &major, &minor) >= 2) {
        sprintf(szVersion, "%d.%d", major, minor);
        self->pg_version_major = major;
        self->pg_version_minor = minor;
@@ -1523,25 +1462,23 @@ CC_log_error(char *func, char *desc, ConnectionClass *self)
 #define nullcheck(a) (a ? a : "(NULL)")
 #endif
 
-   if (self)
-   {
-       qlog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
-       mylog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck(self->errormsg));
+   if (self) {
+       qlog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck (self->errormsg));
+       mylog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, nullcheck (self->errormsg));
        qlog("            ------------------------------------------------------------\n");
        qlog("            henv=%u, conn=%u, status=%u, num_stmts=%d\n", self->henv, self, self->status, self->num_stmts);
        qlog("            sock=%u, stmts=%u, lobj_type=%d\n", self->sock, self->stmts, self->lobj_type);
 
        qlog("            ---------------- Socket Info -------------------------------\n");
-       if (self->sock)
-       {
-           SocketClass *sock = self->sock;
-
-           qlog("            socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n", sock->socket, sock->reverse, sock->errornumber, nullcheck(sock->errormsg));
-           qlog("            buffer_in=%u, buffer_out=%u\n", sock->buffer_in, sock->buffer_out);
-           qlog("            buffer_filled_in=%d, buffer_filled_out=%d, buffer_read_in=%d\n", sock->buffer_filled_in, sock->buffer_filled_out, sock->buffer_read_in);
+       if (self->sock) {
+       SocketClass *sock = self->sock;
+       qlog("            socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n", sock->socket, sock->reverse, sock->errornumber, nullcheck(sock->errormsg));
+       qlog("            buffer_in=%u, buffer_out=%u\n", sock->buffer_in, sock->buffer_out);
+       qlog("            buffer_filled_in=%d, buffer_filled_out=%d, buffer_read_in=%d\n", sock->buffer_filled_in, sock->buffer_filled_out, sock->buffer_read_in);
        }
    }
    else
        qlog("INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
 #undef PRN_NULLCHECK
 }
+
index 706420ef56824d39096c07afc86ef794f85eadca..8222d98518039bbe4b73b39e6a532ffff237d870 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           connection.h
+/* File:            connection.h
  *
- * Description:        See "connection.c"
+ * Description:     See "connection.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #endif
 
 
-typedef enum
-{
-   CONN_NOT_CONNECTED,     /* Connection has not been established */
-   CONN_CONNECTED,         /* Connection is up and has been
-                            * established */
-   CONN_DOWN,              /* Connection is broken */
-   CONN_EXECUTING          /* the connection is currently executing a
-                            * statement */
+typedef enum {
+    CONN_NOT_CONNECTED,      /* Connection has not been established */
+    CONN_CONNECTED,      /* Connection is up and has been established */
+    CONN_DOWN,            /* Connection is broken */
+    CONN_EXECUTING     /* the connection is currently executing a statement */
 } CONN_Status;
 
 /* These errors have general sql error state */
@@ -53,7 +50,7 @@ typedef enum
 #define CONN_INIREAD_ERROR 201
 #define CONN_OPENDB_ERROR 202
 #define CONN_STMT_ALLOC_ERROR 203
-#define CONN_IN_USE 204
+#define CONN_IN_USE 204 
 #define CONN_UNSUPPORTED_OPTION 205
 /* Used by SetConnectoption to indicate unsupported options */
 #define CONN_INVALID_ARGUMENT_NO 206
@@ -93,11 +90,11 @@ typedef enum
 #define AUTH_REQ_CRYPT     4
 
 /* Startup Packet sizes */
-#define SM_DATABASE            64
-#define SM_USER                32
-#define SM_OPTIONS         64
-#define SM_UNUSED          64
-#define SM_TTY             64
+#define SM_DATABASE        64
+#define SM_USER            32
+#define SM_OPTIONS     64
+#define SM_UNUSED      64
+#define SM_TTY         64
 
 /* Old 6.2 protocol defines */
 #define NO_AUTHENTICATION  7
@@ -109,44 +106,63 @@ typedef unsigned int ProtocolVersion;
 
 #define PG_PROTOCOL(major, minor)  (((major) << 16) | (minor))
 #define PG_PROTOCOL_LATEST     PG_PROTOCOL(2, 0)
+#define PG_PROTOCOL_63         PG_PROTOCOL(1, 0)
+#define PG_PROTOCOL_62         PG_PROTOCOL(0, 0)
 
-/* This startup packet is to support latest Postgres protocol */
+/* This startup packet is to support latest Postgres protocol (6.4, 6.3) */
 typedef struct _StartupPacket
 {
-   ProtocolVersion protoVersion;
-   char        database[SM_DATABASE];
-   char        user[SM_USER];
-   char        options[SM_OPTIONS];
-   char        unused[SM_UNUSED];
-   char        tty[SM_TTY];
+   ProtocolVersion protoVersion;
+   char            database[SM_DATABASE];
+   char            user[SM_USER];
+   char            options[SM_OPTIONS];
+   char            unused[SM_UNUSED];
+   char            tty[SM_TTY];
 } StartupPacket;
 
 
+/* This startup packet is to support pre-Postgres 6.3 protocol */
+typedef struct _StartupPacket6_2
+{
+   unsigned int    authtype;
+   char            database[PATH_SIZE];
+   char            user[NAMEDATALEN];
+   char            options[ARGV_SIZE];
+   char            execfile[ARGV_SIZE];
+   char            tty[PATH_SIZE];
+} StartupPacket6_2;
+
+
 /* Structure to hold all the connection attributes for a specific
    connection (used for both registry and file, DSN and DRIVER)
 */
-typedef struct
-{
-   char        dsn[MEDIUM_REGISTRY_LEN];
-   char        desc[MEDIUM_REGISTRY_LEN];
-   char        driver[MEDIUM_REGISTRY_LEN];
-   char        server[MEDIUM_REGISTRY_LEN];
-   char        database[MEDIUM_REGISTRY_LEN];
-   char        username[MEDIUM_REGISTRY_LEN];
-   char        password[MEDIUM_REGISTRY_LEN];
-   char        conn_settings[LARGE_REGISTRY_LEN];
-   char        protocol[SMALL_REGISTRY_LEN];
-   char        port[SMALL_REGISTRY_LEN];
-   char        onlyread[SMALL_REGISTRY_LEN];
-   char        fake_oid_index[SMALL_REGISTRY_LEN];
-   char        show_oid_column[SMALL_REGISTRY_LEN];
-   char        row_versioning[SMALL_REGISTRY_LEN];
-   char        show_system_tables[SMALL_REGISTRY_LEN];
-   char        translation_dll[MEDIUM_REGISTRY_LEN];
-   char        translation_option[SMALL_REGISTRY_LEN];
-   char        focus_password;
+typedef struct {
+   char    dsn[MEDIUM_REGISTRY_LEN];
+   char    desc[MEDIUM_REGISTRY_LEN];
+   char    driver[MEDIUM_REGISTRY_LEN];
+   char    server[MEDIUM_REGISTRY_LEN];
+   char    database[MEDIUM_REGISTRY_LEN];
+   char    username[MEDIUM_REGISTRY_LEN];
+   char    password[MEDIUM_REGISTRY_LEN];
+   char    conn_settings[LARGE_REGISTRY_LEN];
+   char    protocol[SMALL_REGISTRY_LEN];
+   char    port[SMALL_REGISTRY_LEN];
+   char    onlyread[SMALL_REGISTRY_LEN];   
+   char    fake_oid_index[SMALL_REGISTRY_LEN];
+   char    show_oid_column[SMALL_REGISTRY_LEN];
+   char    row_versioning[SMALL_REGISTRY_LEN];
+   char    show_system_tables[SMALL_REGISTRY_LEN];
+   char    translation_dll[MEDIUM_REGISTRY_LEN];
+   char    translation_option[SMALL_REGISTRY_LEN];
+   char    focus_password;
 } ConnInfo;
 
+/* Macro to determine is the connection using 6.2 protocol? */
+#define PROTOCOL_62(conninfo_)     (strncmp((conninfo_)->protocol, PG62, strlen(PG62)) == 0)
+
+/* Macro to determine is the connection using 6.3 protocol? */
+#define PROTOCOL_63(conninfo_)     (strncmp((conninfo_)->protocol, PG63, strlen(PG63)) == 0)
+
 /*
  * Macros to compare the server's version with a specified version
  *     1st parameter: pointer to a ConnectionClass object
@@ -164,15 +180,15 @@ typedef struct
 #define SERVER_VERSION_LE(conn, major, minor) (! SERVER_VERSION_GT(conn, major, minor))
 #define SERVER_VERSION_LT(conn, major, minor) (! SERVER_VERSION_GE(conn, major, minor))
 /*#if ! defined(HAVE_CONFIG_H) || defined(HAVE_STRINGIZE)*/
-#define STRING_AFTER_DOT(string)   (strchr(#string, '.') + 1)
+#define    STRING_AFTER_DOT(string)    (strchr(#string, '.') + 1)
 /*#else
-#define STRING_AFTER_DOT(str)  (strchr("str", '.') + 1)
+#define    STRING_AFTER_DOT(str)   (strchr("str", '.') + 1)
 #endif*/
 /*
  * Simplified macros to compare the server's version with a
  *     specified version
  * Note: Never pass a variable as the second parameter.
- *       It must be a decimal constant of the form %d.%d .
+ *       It must be a decimal constant of the form %d.%d . 
  */
 #define PG_VERSION_GT(conn, ver) \
  (SERVER_VERSION_GT(conn, (int) ver, atoi(STRING_AFTER_DOT(ver))))
@@ -184,10 +200,9 @@ typedef struct
 #define PG_VERSION_LT(conn, ver) (! PG_VERSION_GE(conn, ver))
 
 /* This is used to store cached table information in the connection */
-struct col_info
-{
-   QResultClass *result;
-   char        name[MAX_TABLE_LEN + 1];
+struct col_info {
+   QResultClass    *result;
+   char            name[MAX_TABLE_LEN+1];
 };
 
  /* Translation DLL entry points */
@@ -199,95 +214,89 @@ struct col_info
 #define HINSTANCE void *
 #endif
 
-typedef BOOL (FAR WINAPI * DataSourceToDriverProc) (UDWORD,
-                                                               SWORD,
-                                                               PTR,
-                                                               SDWORD,
-                                                               PTR,
-                                                               SDWORD,
-                                                           SDWORD FAR *,
-                                                            UCHAR FAR *,
-                                                               SWORD,
-                                                           SWORD FAR *);
-
-typedef BOOL (FAR WINAPI * DriverToDataSourceProc) (UDWORD,
-                                                               SWORD,
-                                                               PTR,
-                                                               SDWORD,
-                                                               PTR,
-                                                               SDWORD,
-                                                           SDWORD FAR *,
-                                                            UCHAR FAR *,
-                                                               SWORD,
-                                                           SWORD FAR *);
+typedef BOOL (FAR WINAPI *DataSourceToDriverProc) (UDWORD,
+                   SWORD,
+                   PTR,
+                   SDWORD,
+                   PTR,
+                   SDWORD,
+                   SDWORD FAR *,
+                   UCHAR FAR *,
+                   SWORD,
+                   SWORD FAR *);
+
+typedef BOOL (FAR WINAPI *DriverToDataSourceProc) (UDWORD,
+                   SWORD,
+                   PTR,
+                   SDWORD,
+                   PTR,
+                   SDWORD,
+                   SDWORD FAR *,
+                   UCHAR FAR *,
+                   SWORD,
+                   SWORD FAR *);
 
 /*******   The Connection handle   ************/
-struct ConnectionClass_
-{
-   HENV        henv;           /* environment this connection was created
-                                * on */
+struct ConnectionClass_ {
+   HENV            henv;                   /* environment this connection was created on */
    StatementOptions stmtOptions;
-   char       *errormsg;
-   int         errornumber;
-   CONN_Status status;
-   ConnInfo    connInfo;
-   StatementClass **stmts;
-   int         num_stmts;
-   SocketClass *sock;
-   int         lobj_type;
-   int         ntables;
-   COL_INFO  **col_info;
-   long        translation_option;
-   HINSTANCE   translation_handle;
-   DataSourceToDriverProc DataSourceToDriver;
-   DriverToDataSourceProc DriverToDataSource;
-   char        transact_status;/* Is a transaction is currently in
-                                * progress */
-   char        errormsg_created;       /* has an informative error msg
-                                        * been created?  */
-   char        pg_version[MAX_INFO_STRING];    /* Version of PostgreSQL
-                                                * we're connected to -
-                                                * DJP 25-1-2001 */
-   float       pg_version_number;
-   Int2        pg_version_major;
-   Int2        pg_version_minor;
+   char            *errormsg;
+   int             errornumber;
+   CONN_Status     status;
+   ConnInfo        connInfo;
+   StatementClass  **stmts;
+   int             num_stmts;
+   SocketClass     *sock;
+   int             lobj_type;
+   int             ntables;
+   COL_INFO        **col_info;
+   long            translation_option;
+   HINSTANCE       translation_handle;
+   DataSourceToDriverProc  DataSourceToDriver;
+   DriverToDataSourceProc  DriverToDataSource;
+   char            transact_status;        /* Is a transaction is currently in progress */
+   char            errormsg_created;       /* has an informative error msg been created?  */
+   char            pg_version[MAX_INFO_STRING];    /* Version of PostgreSQL we're connected to - DJP 25-1-2001 */
+   float           pg_version_number;
+   Int2            pg_version_major;
+   Int2            pg_version_minor;
 };
 
 
 /* Accessor functions */
-#define CC_get_socket(x)       (x->sock)
-#define CC_get_database(x)     (x->connInfo.database)
-#define CC_get_server(x)       (x->connInfo.server)
-#define CC_get_DSN(x)          (x->connInfo.dsn)
-#define CC_get_username(x)     (x->connInfo.username)
-#define CC_is_onlyread(x)      (x->connInfo.onlyread[0] == '1')
+#define CC_get_socket(x)   (x->sock)
+#define CC_get_database(x) (x->connInfo.database)
+#define CC_get_server(x)   (x->connInfo.server)
+#define CC_get_DSN(x)      (x->connInfo.dsn)
+#define CC_get_username(x) (x->connInfo.username)
+#define CC_is_onlyread(x)  (x->connInfo.onlyread[0] == '1')
 
 
-/* for CC_DSN_info */
+/*  for CC_DSN_info */
 #define CONN_DONT_OVERWRITE        0
-#define CONN_OVERWRITE         1
+#define CONN_OVERWRITE         1 
 
 
 /* prototypes */
 ConnectionClass *CC_Constructor(void);
-char       CC_Destructor(ConnectionClass *self);
-int            CC_cursor_count(ConnectionClass *self);
-char       CC_cleanup(ConnectionClass *self);
-char       CC_abort(ConnectionClass *self);
-int            CC_set_translation(ConnectionClass *self);
-char       CC_connect(ConnectionClass *self, char do_password);
-char       CC_add_statement(ConnectionClass *self, StatementClass *stmt);
-char       CC_remove_statement(ConnectionClass *self, StatementClass *stmt);
-char       CC_get_error(ConnectionClass *self, int *number, char **message);
+char CC_Destructor(ConnectionClass *self);
+int CC_cursor_count(ConnectionClass *self);
+char CC_cleanup(ConnectionClass *self);
+char CC_abort(ConnectionClass *self);
+int CC_set_translation (ConnectionClass *self);
+char CC_connect(ConnectionClass *self, char do_password);
+char CC_add_statement(ConnectionClass *self, StatementClass *stmt);
+char CC_remove_statement(ConnectionClass *self, StatementClass *stmt);
+char CC_get_error(ConnectionClass *self, int *number, char **message);
 QResultClass *CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi);
-void       CC_clear_error(ConnectionClass *self);
-char      *CC_create_errormsg(ConnectionClass *self);
-int            CC_send_function(ConnectionClass *conn, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
-char       CC_send_settings(ConnectionClass *self);
-void       CC_lookup_lo(ConnectionClass *conn);
-void       CC_lookup_pg_version(ConnectionClass *conn);
-void       CC_initialize_pg_version(ConnectionClass *conn);
-void       CC_log_error(char *func, char *desc, ConnectionClass *self);
+void CC_clear_error(ConnectionClass *self);
+char *CC_create_errormsg(ConnectionClass *self);
+int CC_send_function(ConnectionClass *conn, int fnid, void *result_buf, int *actual_result_len, int result_is_int, LO_ARG *argv, int nargs);
+char CC_send_settings(ConnectionClass *self);
+void CC_lookup_lo(ConnectionClass *conn);
+void CC_lookup_pg_version(ConnectionClass *conn);
+void CC_initialize_pg_version(ConnectionClass *conn);
+void CC_log_error(char *func, char *desc, ConnectionClass *self);
 
 
 #endif
index 532f58a7c57e9fa745078c299ea6a649b060728e..95ac701247b41e7b5896cfd8d87f9f6ec9d31391 100644 (file)
@@ -1,17 +1,18 @@
-/* Module:        convert.c
+
+/* Module:         convert.c
  *
- * Description:    This module contains routines related to
- *                converting parameters and columns into requested data types.
- *                Parameters are converted from their SQL_C data types into
- *                the appropriate postgres type.  Columns are converted from
- *                their postgres type (SQL type) into the appropriate SQL_C
- *                data type.
+ * Description:       This module contains routines related to 
+ *                 converting parameters and columns into requested data types.
+ *                 Parameters are converted from their SQL_C data types into
+ *                 the appropriate postgres type.  Columns are converted from
+ *                 their postgres type (SQL type) into the appropriate SQL_C 
+ *                 data type.
  *
- * Classes:           n/a
+ * Classes:        n/a
  *
  * API functions:  none
  *
- * Comments:      See "notice.txt" for copyright and license information.
+ * Comments:       See "notice.txt" for copyright and license information.
  *
  */
 
@@ -52,7 +53,6 @@
 #endif
 #ifndef SCHAR
 typedef signed char SCHAR;
-
 #endif
 #endif
 
@@ -64,76 +64,76 @@ extern GLOBAL_VALUES globals;
  *  http://www.merant.com/datadirect/download/docs/odbc16/Odbcref/rappc.htm
  * - thomas 2000-04-03
  */
-char      *mapFuncs[][2] = {
-/* { "ASCII",       "ascii"      }, */
-   {"CHAR", "ichar"},
-   {"CONCAT", "textcat"},
+char *mapFuncs[][2] = {
+/* { "ASCII",       "ascii"      }, */
+   { "CHAR",        "ichar"      },
+   { "CONCAT",      "textcat"    },
 /* { "DIFFERENCE",  "difference" }, */
-/* { "INSERT",      "insert"     }, */
-   {"LCASE", "lower"},
-   {"LEFT", "ltrunc"},
-   {"LOCATE", "strpos"},
-   {"LENGTH", "char_length"},
-/* { "LTRIM",       "ltrim"      }, */
-   {"RIGHT", "rtrunc"},
-/* { "REPEAT",      "repeat"     }, */
-/* { "REPLACE",     "replace"    }, */
-/* { "RTRIM",       "rtrim"      }, */
-/* { "SOUNDEX",     "soundex"    }, */
-   {"SUBSTRING", "substr"},
-   {"UCASE", "upper"},
-
-/* { "ABS",         "abs"        }, */
-/* { "ACOS",        "acos"       }, */
-/* { "ASIN",        "asin"       }, */
-/* { "ATAN",        "atan"       }, */
-/* { "ATAN2",       "atan2"      }, */
-   {"CEILING", "ceil"},
-/* { "COS",         "cos"        }, */
-/* { "COT",         "cot"        }, */
-/* { "DEGREES",     "degrees"    }, */
-/* { "EXP",         "exp"        }, */
-/* { "FLOOR",       "floor"      }, */
-   {"LOG", "ln"},
-   {"LOG10", "log"},
-/* { "MOD",         "mod"        }, */
-/* { "PI",          "pi"         }, */
-   {"POWER", "pow"},
-/* { "RADIANS",     "radians"    }, */
-   {"RAND", "random"},
-/* { "ROUND",       "round"      }, */
-/* { "SIGN",        "sign"       }, */
-/* { "SIN",         "sin"        }, */
-/* { "SQRT",        "sqrt"       }, */
-/* { "TAN",         "tan"        }, */
-   {"TRUNCATE", "trunc"},
-
-/* { "CURDATE",     "curdate"    }, */
-/* { "CURTIME",     "curtime"    }, */
-/* { "DAYNAME",     "dayname"    }, */
+/* { "INSERT",      "insert"     }, */
+   { "LCASE",       "lower"      },
+   { "LEFT",        "ltrunc"     },
+   { "LOCATE",      "strpos"     },
+   { "LENGTH",      "char_length"},
+/* { "LTRIM",       "ltrim"      }, */
+   { "RIGHT",       "rtrunc"     },
+/* { "REPEAT",      "repeat"     }, */
+/* { "REPLACE",     "replace"    }, */
+/* { "RTRIM",       "rtrim"      }, */
+/* { "SOUNDEX",     "soundex"    }, */
+   { "SUBSTRING",   "substr"     },
+   { "UCASE",       "upper"      },
+
+/* { "ABS",         "abs"        }, */
+/* { "ACOS",        "acos"       }, */
+/* { "ASIN",        "asin"       }, */
+/* { "ATAN",        "atan"       }, */
+/* { "ATAN2",       "atan2"      }, */
+   { "CEILING",     "ceil"       },
+/* { "COS",         "cos"        }, */
+/* { "COT",         "cot"        }, */
+/* { "DEGREES",     "degrees"    }, */
+/* { "EXP",         "exp"        }, */
+/* { "FLOOR",       "floor"      }, */
+   { "LOG",         "ln"         },
+   { "LOG10",       "log"        },
+/* { "MOD",         "mod"        }, */
+/* { "PI",          "pi"         }, */
+   { "POWER",       "pow"        },
+/* { "RADIANS",     "radians"    }, */
+   { "RAND",        "random"     },
+/* { "ROUND",       "round"      }, */
+/* { "SIGN",        "sign"       }, */
+/* { "SIN",         "sin"        }, */
+/* { "SQRT",        "sqrt"       }, */
+/* { "TAN",         "tan"        }, */
+   { "TRUNCATE",    "trunc"      },
+
+/* { "CURDATE",     "curdate"    }, */
+/* { "CURTIME",     "curtime"    }, */
+/* { "DAYNAME",     "dayname"    }, */
 /* { "DAYOFMONTH",  "dayofmonth" }, */
-/* { "DAYOFWEEK",   "dayofweek"  }, */
-/* { "DAYOFYEAR",   "dayofyear"  }, */
-/* { "HOUR",        "hour"       }, */
-/* { "MINUTE",      "minute"     }, */
-/* { "MONTH",       "month"      }, */
-/* { "MONTHNAME",   "monthname"  }, */
-/* { "NOW",         "now"        }, */
-/* { "QUARTER",     "quarter"    }, */
-/* { "SECOND",      "second"     }, */
-/* { "WEEK",        "week"       }, */
-/* { "YEAR",        "year"       }, */
-
-/* { "DATABASE",    "database"   }, */
-   {"IFNULL", "coalesce"},
-   {"USER", "odbc_user"},
-   {0, 0}
+/* { "DAYOFWEEK",   "dayofweek"  }, */
+/* { "DAYOFYEAR",   "dayofyear"  }, */
+/* { "HOUR",        "hour"       }, */
+/* { "MINUTE",      "minute"     }, */
+/* { "MONTH",       "month"      }, */
+/* { "MONTHNAME",   "monthname"  }, */
+/* { "NOW",         "now"        }, */
+/* { "QUARTER",     "quarter"    }, */
+/* { "SECOND",      "second"     }, */
+/* { "WEEK",        "week"       }, */
+/* { "YEAR",        "year"       }, */
+
+/* { "DATABASE",    "database"   }, */
+   { "IFNULL",      "coalesce"   },
+   { "USER",        "odbc_user"  },
+   {    0,             0         }
 };
 
-char      *mapFunction(char *func);
+char *mapFunction(char *func);
 unsigned int conv_from_octal(unsigned char *s);
 unsigned int conv_from_hex(unsigned char *s);
-char      *conv_to_octal(unsigned char val);
+char *conv_to_octal(unsigned char val);
 
 /********      A Guide for date/time/timestamp conversions    **************
 
@@ -145,10 +145,10 @@ char     *conv_to_octal(unsigned char val);
            PG_TYPE_TIME    SQL_C_DEFAULT       SQL_C_TIME
            PG_TYPE_TIME    SQL_C_TIME          SQL_C_TIME
            PG_TYPE_TIME    SQL_C_TIMESTAMP     SQL_C_TIMESTAMP     (date = current date)
-           PG_TYPE_ABSTIME SQL_C_DEFAULT       SQL_C_TIMESTAMP
-           PG_TYPE_ABSTIME SQL_C_DATE          SQL_C_DATE          (time is truncated)
-           PG_TYPE_ABSTIME SQL_C_TIME          SQL_C_TIME          (date is truncated)
-           PG_TYPE_ABSTIME SQL_C_TIMESTAMP     SQL_C_TIMESTAMP
+           PG_TYPE_ABSTIME SQL_C_DEFAULT       SQL_C_TIMESTAMP
+           PG_TYPE_ABSTIME SQL_C_DATE          SQL_C_DATE          (time is truncated)
+           PG_TYPE_ABSTIME SQL_C_TIME          SQL_C_TIME          (date is truncated)
+           PG_TYPE_ABSTIME SQL_C_TIMESTAMP     SQL_C_TIMESTAMP     
 ******************************************************************************/
 
 
@@ -156,71 +156,69 @@ char     *conv_to_octal(unsigned char val);
 int
 copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col)
 {
-   BindInfoClass *bic = &(stmt->bindings[col]);
+BindInfoClass *bic = &(stmt->bindings[col]);
 
-   return copy_and_convert_field(stmt, field_type, value, (Int2) bic->returntype, (PTR) bic->buffer,
-                            (SDWORD) bic->buflen, (SDWORD *) bic->used);
+   return copy_and_convert_field(stmt, field_type, value, (Int2)bic->returntype, (PTR)bic->buffer,
+                                (SDWORD)bic->buflen, (SDWORD *)bic->used);
 }
 
 /* This is called by SQLGetData() */
 int
-copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
+copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType, 
                       PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue)
 {
-   Int4        len = 0,
-               copy_len = 0;
+   Int4 len = 0, copy_len = 0;
    SIMPLE_TIME st;
-   time_t      t = time(NULL);
-   struct tm  *tim;
-   int         pcbValueOffset,
-               rgbValueOffset;
-   char       *rgbValueBindRow,
-              *ptr;
-   int         bind_row = stmt->bind_row;
-   int         bind_size = stmt->options.bind_size;
-   int         result = COPY_OK;
-   char        tempBuf[TEXT_FIELD_SIZE + 5];
+   time_t t = time(NULL);
+   struct tm *tim;
+   int pcbValueOffset, rgbValueOffset;
+   char *rgbValueBindRow, *ptr;
+   int bind_row = stmt->bind_row;
+   int bind_size = stmt->options.bind_size;
+   int result = COPY_OK;
+   char tempBuf[TEXT_FIELD_SIZE+5];
 
 /* rgbValueOffset is *ONLY* for character and binary data */
 /* pcbValueOffset is for computing any pcbValue location */
 
-   if (bind_size > 0)
+   if (bind_size > 0) {
+
        pcbValueOffset = rgbValueOffset = (bind_size * bind_row);
-   else
-   {
+   }
+   else {
+
        pcbValueOffset = bind_row * sizeof(SDWORD);
        rgbValueOffset = bind_row * cbValueMax;
+
    }
 
    memset(&st, 0, sizeof(SIMPLE_TIME));
 
-   /* Initialize current date */
+   /*  Initialize current date */
    tim = localtime(&t);
    st.m = tim->tm_mon + 1;
    st.d = tim->tm_mday;
    st.y = tim->tm_year + 1900;
 
-   mylog("copy_and_convert: field_type = %d, fctype = %d, value = '%s', cbValueMax=%d\n", field_type, fCType, (value == NULL) ? "<NULL>" : value, cbValueMax);
+   mylog("copy_and_convert: field_type = %d, fctype = %d, value = '%s', cbValueMax=%d\n", field_type, fCType,  (value==NULL)?"<NULL>":value, cbValueMax);
 
-   if (!value)
-   {
-       /* handle a null just by returning SQL_NULL_DATA in pcbValue, */
-       /* and doing nothing to the buffer.                           */
-       if (pcbValue)
+   if ( ! value) {
+        /* handle a null just by returning SQL_NULL_DATA in pcbValue, */
+        /* and doing nothing to the buffer.                           */
+        if(pcbValue) {
            *(SDWORD *) ((char *) pcbValue + pcbValueOffset) = SQL_NULL_DATA;
+        }
        return COPY_OK;
    }
 
 
-   if (stmt->hdbc->DataSourceToDriver != NULL)
-   {
-       int         length = strlen(value);
-
-       stmt->hdbc->DataSourceToDriver(stmt->hdbc->translation_option,
-                                      SQL_CHAR,
-                                      value, length,
-                                      value, length, NULL,
-                                      NULL, 0, NULL);
+   if (stmt->hdbc->DataSourceToDriver != NULL) {
+       int length = strlen (value);
+       stmt->hdbc->DataSourceToDriver (stmt->hdbc->translation_option,
+                                       SQL_CHAR,
+                                       value, length,
+                                       value, length, NULL,
+                                       NULL, 0, NULL);
    }
 
 
@@ -228,125 +226,108 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
        First convert any specific postgres types into more
        useable data.
 
-       NOTE: Conversions from PG char/varchar of a date/time/timestamp
-       value to SQL_C_DATE,SQL_C_TIME, SQL_C_TIMESTAMP not supported
+       NOTE: Conversions from PG char/varchar of a date/time/timestamp 
+       value to SQL_C_DATE,SQL_C_TIME, SQL_C_TIMESTAMP not supported 
    *********************************************************************/
-   switch (field_type)
-   {
-
-           /*
-            * $$$ need to add parsing for date/time/timestamp strings in
-            * PG_TYPE_CHAR,VARCHAR $$$
-            */
-       case PG_TYPE_DATE:
-           sscanf(value, "%4d-%2d-%2d", &st.y, &st.m, &st.d);
-           break;
-
-       case PG_TYPE_TIME:
-           sscanf(value, "%2d:%2d:%2d", &st.hh, &st.mm, &st.ss);
-           break;
-
-       case PG_TYPE_ABSTIME:
-       case PG_TYPE_DATETIME:
-       case PG_TYPE_TIMESTAMP:
-           if (strnicmp(value, "invalid", 7) != 0)
-               sscanf(value, "%4d-%2d-%2d %2d:%2d:%2d", &st.y, &st.m, &st.d, &st.hh, &st.mm, &st.ss);
-           else
-           {                   /* The timestamp is invalid so set
-                                * something conspicuous, like the epoch */
-               t = 0;
-               tim = localtime(&t);
-               st.m = tim->tm_mon + 1;
-               st.d = tim->tm_mday;
-               st.y = tim->tm_year + 1900;
-               st.hh = tim->tm_hour;
-               st.mm = tim->tm_min;
-               st.ss = tim->tm_sec;
-           }
-           break;
-
-       case PG_TYPE_BOOL:
-           {                   /* change T/F to 1/0 */
-               char       *s = (char *) value;
+   switch(field_type) {
+   /*  $$$ need to add parsing for date/time/timestamp strings in PG_TYPE_CHAR,VARCHAR $$$ */
+   case PG_TYPE_DATE:
+       sscanf(value, "%4d-%2d-%2d", &st.y, &st.m, &st.d);
+       break;
+
+   case PG_TYPE_TIME:
+       sscanf(value, "%2d:%2d:%2d", &st.hh, &st.mm, &st.ss);
+       break;
+
+   case PG_TYPE_ABSTIME:
+   case PG_TYPE_DATETIME:
+   case PG_TYPE_TIMESTAMP:
+       if (strnicmp(value, "invalid", 7) != 0) {
+           sscanf(value, "%4d-%2d-%2d %2d:%2d:%2d", &st.y, &st.m, &st.d, &st.hh, &st.mm, &st.ss);
+
+       } else {    /* The timestamp is invalid so set something conspicuous, like the epoch */
+           t = 0;
+           tim = localtime(&t);
+           st.m = tim->tm_mon + 1;
+           st.d = tim->tm_mday;
+           st.y = tim->tm_year + 1900;
+           st.hh = tim->tm_hour;
+           st.mm = tim->tm_min;
+           st.ss = tim->tm_sec;
+       }
+       break;
+
+   case PG_TYPE_BOOL: {        /* change T/F to 1/0 */
+       char *s = (char *) value;
+       if (s[0] == 'T' || s[0] == 't') 
+           s[0] = '1';
+       else 
+           s[0] = '0';
+       }
+       break;
+
+   /* This is for internal use by SQLStatistics() */
+   case PG_TYPE_INT2VECTOR: {
+       int nval, i;
+       char *vp;
+       /* this is an array of eight integers */
+       short *short_array = (short *) ( (char *) rgbValue + rgbValueOffset);
+
+       len = 16;
+       vp = value;
+       nval = 0;
+       for (i = 0; i < 8; i++)
+       {
+           if (sscanf(vp, "%hd", &short_array[i]) != 1)
+               break;
 
-               if (s[0] == 'T' || s[0] == 't')
-                   s[0] = '1';
-               else
-                   s[0] = '0';
-           }
-           break;
+           nval++;
 
-           /* This is for internal use by SQLStatistics() */
-       case PG_TYPE_INT2VECTOR:
-           {
-               int         nval,
-                           i;
-               char       *vp;
-
-               /* this is an array of eight integers */
-               short      *short_array = (short *) ((char *) rgbValue + rgbValueOffset);
-
-               len = 16;
-               vp = value;
-               nval = 0;
-               for (i = 0; i < 8; i++)
-               {
-                   if (sscanf(vp, "%hd", &short_array[i]) != 1)
-                       break;
-
-                   nval++;
-
-                   /* skip the current token */
-                   while ((*vp != '\0') && (!isspace((unsigned char) *vp)))
-                       vp++;
-                   /* and skip the space to the next token */
-                   while ((*vp != '\0') && (isspace((unsigned char) *vp)))
-                       vp++;
-                   if (*vp == '\0')
-                       break;
-               }
+           /* skip the current token */
+           while ((*vp != '\0') && (! isspace((unsigned char) *vp))) vp++;
+           /* and skip the space to the next token */
+           while ((*vp != '\0') && (isspace((unsigned char) *vp))) vp++;
+           if (*vp == '\0')
+               break;
+       }
 
-               for (i = nval; i < 8; i++)
-                   short_array[i] = 0;
+       for (i = nval; i < 8; i++)
+       {
+           short_array[i] = 0;
+       }
 
 #if 0
-               sscanf(value, "%hd %hd %hd %hd %hd %hd %hd %hd",
-                      &short_array[0],
-                      &short_array[1],
-                      &short_array[2],
-                      &short_array[3],
-                      &short_array[4],
-                      &short_array[5],
-                      &short_array[6],
-                      &short_array[7]);
+       sscanf(value, "%hd %hd %hd %hd %hd %hd %hd %hd",
+           &short_array[0],
+           &short_array[1],
+           &short_array[2],
+           &short_array[3],
+           &short_array[4],
+           &short_array[5],
+           &short_array[6],
+           &short_array[7]);
 #endif
 
-               /* There is no corresponding fCType for this. */
-               if (pcbValue)
-                   *(SDWORD *) ((char *) pcbValue + pcbValueOffset) = len;
+       /*  There is no corresponding fCType for this. */
+       if(pcbValue)
+           *(SDWORD *) ((char *) pcbValue + pcbValueOffset) = len;
 
-               return COPY_OK; /* dont go any further or the data will be
-                                * trashed */
-           }
+       return COPY_OK;     /* dont go any further or the data will be trashed */
+   }
 
-           /*
-            * This is a large object OID, which is used to store
-            * LONGVARBINARY objects.
-            */
-       case PG_TYPE_LO:
+   /* This is a large object OID, which is used to store LONGVARBINARY objects. */
+   case PG_TYPE_LO:
 
-           return convert_lo(stmt, value, fCType, ((char *) rgbValue + rgbValueOffset), cbValueMax, (SDWORD *) ((char *) pcbValue + pcbValueOffset));
+       return convert_lo( stmt, value, fCType, ((char *) rgbValue + rgbValueOffset), cbValueMax, (SDWORD *) ((char *) pcbValue + pcbValueOffset));
 
-       default:
+   default:
 
-           if (field_type == stmt->hdbc->lobj_type)    /* hack until permanent
-                                                        * type available */
-               return convert_lo(stmt, value, fCType, ((char *) rgbValue + rgbValueOffset), cbValueMax, (SDWORD *) ((char *) pcbValue + pcbValueOffset));
+       if (field_type == stmt->hdbc->lobj_type)    /* hack until permanent type available */
+           return convert_lo( stmt, value, fCType, ((char *) rgbValue + rgbValueOffset), cbValueMax, (SDWORD *) ((char *) pcbValue + pcbValueOffset));
    }
 
-   /* Change default into something useable */
-   if (fCType == SQL_C_DEFAULT)
-   {
+   /*  Change default into something useable */
+   if (fCType == SQL_C_DEFAULT) {
        fCType = pgtype_to_ctype(stmt, field_type);
 
        mylog("copy_and_convert, SQL_C_DEFAULT: fCType = %d\n", fCType);
@@ -355,315 +336,300 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
 
    rgbValueBindRow = (char *) rgbValue + rgbValueOffset;
 
-   if (fCType == SQL_C_CHAR)
-   {
-       /* Special character formatting as required */
+    if(fCType == SQL_C_CHAR) {
 
-       /*
-        * These really should return error if cbValueMax is not big
-        * enough.
-        */
-       switch (field_type)
-       {
-           case PG_TYPE_DATE:
-               len = 10;
-               if (cbValueMax > len)
-                   sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d", st.y, st.m, st.d);
-               break;
 
-           case PG_TYPE_TIME:
-               len = 8;
-               if (cbValueMax > len)
-                   sprintf(rgbValueBindRow, "%.2d:%.2d:%.2d", st.hh, st.mm, st.ss);
-               break;
+       /*  Special character formatting as required */
+       /*  These really should return error if cbValueMax is not big enough. */
+       switch(field_type) {
+       case PG_TYPE_DATE:
+           len = 10;
+           if (cbValueMax > len)
+               sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d", st.y, st.m, st.d);
+           break;
 
-           case PG_TYPE_ABSTIME:
-           case PG_TYPE_DATETIME:
-           case PG_TYPE_TIMESTAMP:
-               len = 19;
-               if (cbValueMax > len)
-                   sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
-                           st.y, st.m, st.d, st.hh, st.mm, st.ss);
-               break;
+       case PG_TYPE_TIME:
+           len = 8;
+           if (cbValueMax > len)
+               sprintf(rgbValueBindRow, "%.2d:%.2d:%.2d", st.hh, st.mm, st.ss);
+           break;
 
-           case PG_TYPE_BOOL:
-               len = 1;
-               if (cbValueMax > len)
-               {
-                   strcpy(rgbValueBindRow, value);
-                   mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow);
-               }
-               break;
+       case PG_TYPE_ABSTIME:
+       case PG_TYPE_DATETIME:
+       case PG_TYPE_TIMESTAMP:
+           len = 19;
+           if (cbValueMax > len)
+               sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", 
+                   st.y, st.m, st.d, st.hh, st.mm, st.ss);
+           break;
 
-               /*
-                * Currently, data is SILENTLY TRUNCATED for BYTEA and
-                * character data types if there is not enough room in
-                * cbValueMax because the driver can't handle multiple
-                * calls to SQLGetData for these, yet.  Most likely, the
-                * buffer passed in will be big enough to handle the
-                * maximum limit of postgres, anyway.
-                *
-                * LongVarBinary types are handled correctly above, observing
-                * truncation and all that stuff since there is
-                * essentially no limit on the large object used to store
-                * those.
-                */
-           case PG_TYPE_BYTEA:/* convert binary data to hex strings
-                                * (i.e, 255 = "FF") */
-               len = convert_pgbinary_to_char(value, rgbValueBindRow, cbValueMax);
-
-               /***** THIS IS NOT PROPERLY IMPLEMENTED *****/
-               break;
+       case PG_TYPE_BOOL:
+           len = 1;
+           if (cbValueMax > len) {
+               strcpy(rgbValueBindRow, value);
+               mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow);
+           }
+           break;
 
-           default:
-               /* convert linefeeds to carriage-return/linefeed */
-               len = convert_linefeeds(value, tempBuf, sizeof(tempBuf));
-               ptr = tempBuf;
-
-               mylog("DEFAULT: len = %d, ptr = '%s'\n", len, ptr);
-
-               if (stmt->current_col >= 0)
-               {
-                   if (stmt->bindings[stmt->current_col].data_left == 0)
-                       return COPY_NO_DATA_FOUND;
-                   else if (stmt->bindings[stmt->current_col].data_left > 0)
-                   {
-                       ptr += len - stmt->bindings[stmt->current_col].data_left;
-                       len = stmt->bindings[stmt->current_col].data_left;
-                   }
-                   else
-                       stmt->bindings[stmt->current_col].data_left = strlen(ptr);
+       /*  Currently, data is SILENTLY TRUNCATED for BYTEA and character data
+           types if there is not enough room in cbValueMax because the driver 
+           can't handle multiple calls to SQLGetData for these, yet.  Most likely,
+           the buffer passed in will be big enough to handle the maximum limit of 
+           postgres, anyway.
+
+           LongVarBinary types are handled correctly above, observing truncation
+           and all that stuff since there is essentially no limit on the large
+           object used to store those.
+       */
+       case PG_TYPE_BYTEA:     /* convert binary data to hex strings (i.e, 255 = "FF") */
+           len = convert_pgbinary_to_char(value, rgbValueBindRow, cbValueMax);
+
+           /***** THIS IS NOT PROPERLY IMPLEMENTED *****/
+           break;
+
+       default:
+           /*  convert linefeeds to carriage-return/linefeed */
+           len = convert_linefeeds(value, tempBuf, sizeof(tempBuf));
+           ptr = tempBuf;
+
+           mylog("DEFAULT: len = %d, ptr = '%s'\n", len, ptr);
+
+           if (stmt->current_col >= 0) {
+               if (stmt->bindings[stmt->current_col].data_left == 0)
+                   return COPY_NO_DATA_FOUND;
+               else if (stmt->bindings[stmt->current_col].data_left > 0) {
+                   ptr += len - stmt->bindings[stmt->current_col].data_left;
+                   len = stmt->bindings[stmt->current_col].data_left;
                }
+               else
+                   stmt->bindings[stmt->current_col].data_left = strlen(ptr);
+           }
 
-               if (cbValueMax > 0)
-               {
-                   copy_len = (len >= cbValueMax) ? cbValueMax - 1 : len;
+           if (cbValueMax > 0) {
+               
+               copy_len = (len >= cbValueMax) ? cbValueMax -1 : len;
 
-                   /* Copy the data */
-                   strncpy_null(rgbValueBindRow, ptr, copy_len + 1);
+               /*  Copy the data */
+               strncpy_null(rgbValueBindRow, ptr, copy_len + 1);
 
-                   /* Adjust data_left for next time */
-                   if (stmt->current_col >= 0)
-                       stmt->bindings[stmt->current_col].data_left -= copy_len;
+               /*  Adjust data_left for next time */
+               if (stmt->current_col >= 0) {
+                   stmt->bindings[stmt->current_col].data_left -= copy_len;
                }
+           }
 
-               /*
-                * Finally, check for truncation so that proper status can
-                * be returned
-                */
-               if (len >= cbValueMax)
-                   result = COPY_RESULT_TRUNCATED;
+           /*  Finally, check for truncation so that proper status can be returned */
+           if ( len >= cbValueMax)
+               result = COPY_RESULT_TRUNCATED;
 
 
-               mylog("    SQL_C_CHAR, default: len = %d, cbValueMax = %d, rgbValueBindRow = '%s'\n", len, cbValueMax, rgbValueBindRow);
-               break;
+           mylog("    SQL_C_CHAR, default: len = %d, cbValueMax = %d, rgbValueBindRow = '%s'\n", len, cbValueMax, rgbValueBindRow);
+           break;
        }
 
 
-   }
-   else
-   {
+    } else {
 
-       /*
-        * for SQL_C_CHAR, it's probably ok to leave currency symbols in.
-        * But to convert to numeric types, it is necessary to get rid of
-        * those.
-        */
+       /*  for SQL_C_CHAR, it's probably ok to leave currency symbols in.  But
+           to convert to numeric types, it is necessary to get rid of those.
+       */
        if (field_type == PG_TYPE_MONEY)
            convert_money(value);
 
-       switch (fCType)
-       {
-           case SQL_C_DATE:
-               len = 6;
-               {
-                   DATE_STRUCT *ds;
-
-                   if (bind_size > 0)
-                       ds = (DATE_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
-                   else
-                       ds = (DATE_STRUCT *) rgbValue + bind_row;
-                   ds->year = st.y;
-                   ds->month = st.m;
-                   ds->day = st.d;
-               }
-               break;
-
-           case SQL_C_TIME:
-               len = 6;
-               {
-                   TIME_STRUCT *ts;
-
-                   if (bind_size > 0)
-                       ts = (TIME_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
-                   else
-                       ts = (TIME_STRUCT *) rgbValue + bind_row;
-                   ts->hour = st.hh;
-                   ts->minute = st.mm;
-                   ts->second = st.ss;
-               }
-               break;
+       switch(fCType) {
+       case SQL_C_DATE:
+           len = 6;
+           {
+           DATE_STRUCT *ds;
+           
+           if (bind_size > 0) {
+               ds = (DATE_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
+           } else {
+               ds = (DATE_STRUCT *) rgbValue + bind_row;
+           }
+           ds->year = st.y;
+           ds->month = st.m;
+           ds->day = st.d;
+           }
+           break;
 
-           case SQL_C_TIMESTAMP:
-               len = 16;
-               {
-                   TIMESTAMP_STRUCT *ts;
-
-                   if (bind_size > 0)
-                       ts = (TIMESTAMP_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
-                   else
-                       ts = (TIMESTAMP_STRUCT *) rgbValue + bind_row;
-                   ts->year = st.y;
-                   ts->month = st.m;
-                   ts->day = st.d;
-                   ts->hour = st.hh;
-                   ts->minute = st.mm;
-                   ts->second = st.ss;
-                   ts->fraction = 0;
-               }
-               break;
+       case SQL_C_TIME:
+           len = 6;
+           {
+           TIME_STRUCT *ts;
+           
+           if (bind_size > 0) {
+               ts = (TIME_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
+           } else {
+               ts = (TIME_STRUCT *) rgbValue + bind_row;
+           }
+           ts->hour = st.hh;
+           ts->minute = st.mm;
+           ts->second = st.ss;
+           }
+           break;
 
-           case SQL_C_BIT:
-               len = 1;
-               if (bind_size > 0)
-                   *(UCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
-               else
-                   *((UCHAR *) rgbValue + bind_row) = atoi(value);
+       case SQL_C_TIMESTAMP:                   
+           len = 16;
+           {
+           TIMESTAMP_STRUCT *ts;
+           if (bind_size > 0) {
+               ts = (TIMESTAMP_STRUCT *) ((char *) rgbValue + (bind_row * bind_size));
+           } else {
+               ts = (TIMESTAMP_STRUCT *) rgbValue + bind_row;
+           }
+           ts->year = st.y;
+           ts->month = st.m;
+           ts->day = st.d;
+           ts->hour = st.hh;
+           ts->minute = st.mm;
+           ts->second = st.ss;
+           ts->fraction = 0;
+           }
+           break;
 
-               /*
-                * mylog("SQL_C_BIT: val = %d, cb = %d, rgb=%d\n",
-                * atoi(value), cbValueMax, *((UCHAR *)rgbValue));
-                */
-               break;
+       case SQL_C_BIT:
+           len = 1;
+           if (bind_size > 0) {
+               *(UCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
+           } else {
+               *((UCHAR *)rgbValue + bind_row) = atoi(value);
+           }
+           /* mylog("SQL_C_BIT: val = %d, cb = %d, rgb=%d\n", atoi(value), cbValueMax, *((UCHAR *)rgbValue)); */
+           break;
 
-           case SQL_C_STINYINT:
-           case SQL_C_TINYINT:
-               len = 1;
-               if (bind_size > 0)
-                   *(SCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
-               else
-                   *((SCHAR *) rgbValue + bind_row) = atoi(value);
-               break;
+       case SQL_C_STINYINT:
+       case SQL_C_TINYINT:
+           len = 1;
+           if (bind_size > 0) {
+               *(SCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
+           } else {
+               *((SCHAR *) rgbValue + bind_row) = atoi(value);
+           }
+           break;
 
-           case SQL_C_UTINYINT:
-               len = 1;
-               if (bind_size > 0)
-                   *(UCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
-               else
-                   *((UCHAR *) rgbValue + bind_row) = atoi(value);
-               break;
+       case SQL_C_UTINYINT:
+           len = 1;
+           if (bind_size > 0) {
+               *(UCHAR *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
+           } else {
+               *((UCHAR *) rgbValue + bind_row) = atoi(value);
+           }
+           break;
 
-           case SQL_C_FLOAT:
-               len = 4;
-               if (bind_size > 0)
-                   *(SFLOAT *) ((char *) rgbValue + (bind_row * bind_size)) = (float) atof(value);
-               else
-                   *((SFLOAT *) rgbValue + bind_row) = (float) atof(value);
-               break;
+       case SQL_C_FLOAT:
+           len = 4;
+           if (bind_size > 0) {
+               *(SFLOAT *) ((char *) rgbValue + (bind_row * bind_size)) = (float) atof(value);
+           } else {
+               *((SFLOAT *)rgbValue + bind_row) = (float) atof(value);
+           }
+           break;
 
-           case SQL_C_DOUBLE:
-               len = 8;
-               if (bind_size > 0)
-                   *(SDOUBLE *) ((char *) rgbValue + (bind_row * bind_size)) = atof(value);
-               else
-                   *((SDOUBLE *) rgbValue + bind_row) = atof(value);
-               break;
+       case SQL_C_DOUBLE:
+           len = 8;
+           if (bind_size > 0) {
+               *(SDOUBLE *) ((char *) rgbValue + (bind_row * bind_size)) = atof(value);
+           } else {
+               *((SDOUBLE *)rgbValue + bind_row) = atof(value);
+           }
+           break;
 
-           case SQL_C_SSHORT:
-           case SQL_C_SHORT:
-               len = 2;
-               if (bind_size > 0)
-                   *(SWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
-               else
-                   *((SWORD *) rgbValue + bind_row) = atoi(value);
-               break;
+       case SQL_C_SSHORT:
+       case SQL_C_SHORT:
+           len = 2;
+           if (bind_size > 0) {
+               *(SWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
+           } else {
+               *((SWORD *)rgbValue + bind_row) = atoi(value);
+           }
+           break;
 
-           case SQL_C_USHORT:
-               len = 2;
-               if (bind_size > 0)
-                   *(UWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
-               else
-                   *((UWORD *) rgbValue + bind_row) = atoi(value);
-               break;
+       case SQL_C_USHORT:
+           len = 2;
+           if (bind_size > 0) {
+               *(UWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atoi(value);
+           } else {
+               *((UWORD *)rgbValue + bind_row) = atoi(value);
+           }
+           break;
 
-           case SQL_C_SLONG:
-           case SQL_C_LONG:
-               len = 4;
-               if (bind_size > 0)
-                   *(SDWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atol(value);
-               else
-                   *((SDWORD *) rgbValue + bind_row) = atol(value);
-               break;
+       case SQL_C_SLONG:
+       case SQL_C_LONG:
+           len = 4;
+           if (bind_size > 0) {
+               *(SDWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atol(value);
+           } else {
+               *((SDWORD *)rgbValue + bind_row) = atol(value);
+           }
+           break;
 
-           case SQL_C_ULONG:
-               len = 4;
-               if (bind_size > 0)
-                   *(UDWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atol(value);
-               else
-                   *((UDWORD *) rgbValue + bind_row) = atol(value);
-               break;
+       case SQL_C_ULONG:
+           len = 4;
+           if (bind_size > 0) {
+               *(UDWORD *) ((char *) rgbValue + (bind_row * bind_size)) = atol(value);
+           } else {
+               *((UDWORD *)rgbValue + bind_row) = atol(value);
+           }
+           break;
 
-           case SQL_C_BINARY:
+       case SQL_C_BINARY:  
 
-               /* truncate if necessary */
-               /* convert octal escapes to bytes */
+           /*  truncate if necessary */
+           /*  convert octal escapes to bytes */
 
-               len = convert_from_pgbinary(value, tempBuf, sizeof(tempBuf));
-               ptr = tempBuf;
+           len = convert_from_pgbinary(value, tempBuf, sizeof(tempBuf));
+           ptr = tempBuf;
 
-               if (stmt->current_col >= 0)
-               {
-                   /* No more data left for this column */
-                   if (stmt->bindings[stmt->current_col].data_left == 0)
-                       return COPY_NO_DATA_FOUND;
+           if (stmt->current_col >= 0) {
 
-                   /*
-                    * Second (or more) call to SQLGetData so move the
-                    * pointer
-                    */
-                   else if (stmt->bindings[stmt->current_col].data_left > 0)
-                   {
-                       ptr += len - stmt->bindings[stmt->current_col].data_left;
-                       len = stmt->bindings[stmt->current_col].data_left;
-                   }
+               /*  No more data left for this column */
+               if (stmt->bindings[stmt->current_col].data_left == 0)
+                   return COPY_NO_DATA_FOUND;
 
-                   /* First call to SQLGetData so initialize data_left */
-                   else
-                       stmt->bindings[stmt->current_col].data_left = len;
+               /*  Second (or more) call to SQLGetData so move the pointer */
+               else if (stmt->bindings[stmt->current_col].data_left > 0) {
+                   ptr += len - stmt->bindings[stmt->current_col].data_left;
+                   len = stmt->bindings[stmt->current_col].data_left;
                }
 
-               if (cbValueMax > 0)
-               {
-                   copy_len = (len > cbValueMax) ? cbValueMax : len;
+               /*  First call to SQLGetData so initialize data_left */
+               else    
+                   stmt->bindings[stmt->current_col].data_left = len;
 
-                   /* Copy the data */
-                   memcpy(rgbValueBindRow, ptr, copy_len);
+           }
 
-                   /* Adjust data_left for next time */
-                   if (stmt->current_col >= 0)
-                       stmt->bindings[stmt->current_col].data_left -= copy_len;
-               }
+           if (cbValueMax > 0) {
+               copy_len = (len > cbValueMax) ? cbValueMax : len;
 
-               /*
-                * Finally, check for truncation so that proper status can
-                * be returned
-                */
-               if (len > cbValueMax)
-                   result = COPY_RESULT_TRUNCATED;
+               /*  Copy the data */
+               memcpy(rgbValueBindRow, ptr, copy_len);
 
-               mylog("SQL_C_BINARY: len = %d, copy_len = %d\n", len, copy_len);
-               break;
+               /*  Adjust data_left for next time */
+               if (stmt->current_col >= 0) {
+                   stmt->bindings[stmt->current_col].data_left -= copy_len;
+               }
+           }
 
-           default:
-               return COPY_UNSUPPORTED_TYPE;
+           /*  Finally, check for truncation so that proper status can be returned */
+           if ( len > cbValueMax)
+               result = COPY_RESULT_TRUNCATED;
+
+           mylog("SQL_C_BINARY: len = %d, copy_len = %d\n", len, copy_len);
+           break;
+           
+       default:
+           return COPY_UNSUPPORTED_TYPE;
        }
    }
 
-   /* store the length of what was copied, if there's a place for it */
-   if (pcbValue)
-       *(SDWORD *) ((char *) pcbValue + pcbValueOffset) = len;
+    /* store the length of what was copied, if there's a place for it */
+    if(pcbValue) {
+        *(SDWORD *) ((char *)pcbValue + pcbValueOffset) = len;
+   }
 
    return result;
+
 }
 
 
@@ -674,95 +640,80 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2
 int
 copy_statement_with_parameters(StatementClass *stmt)
 {
-   static char *func = "copy_statement_with_parameters";
-   unsigned int opos,
-               npos,
-               oldstmtlen;
-   char        param_string[128],
-               tmp[256],
-               cbuf[TEXT_FIELD_SIZE + 5];
-   int         param_number;
-   Int2        param_ctype,
-               param_sqltype;
-   char       *old_statement = stmt->statement;
-   char       *new_statement = stmt->stmt_with_params;
-   SIMPLE_TIME st;
-   time_t      t = time(NULL);
-   struct tm  *tim;
-   SDWORD      used;
-   char       *buffer,
-              *buf;
-   char        in_quote = FALSE;
-   Oid         lobj_oid;
-   int         lobj_fd,
-               retval;
-
-
-   if (!old_statement)
-   {
+static char *func="copy_statement_with_parameters";
+unsigned int opos, npos, oldstmtlen;
+char param_string[128], tmp[256], cbuf[TEXT_FIELD_SIZE+5];
+int param_number;
+Int2 param_ctype, param_sqltype;
+char *old_statement = stmt->statement;
+char *new_statement = stmt->stmt_with_params;
+SIMPLE_TIME st;
+time_t t = time(NULL);
+struct tm *tim;
+SDWORD used;
+char *buffer, *buf;
+char in_quote = FALSE;
+Oid  lobj_oid;
+int lobj_fd, retval;
+
+
+   if ( ! old_statement) {
        SC_log_error(func, "No statement string", stmt);
        return SQL_ERROR;
    }
 
    memset(&st, 0, sizeof(SIMPLE_TIME));
 
-   /* Initialize current date */
+   /*  Initialize current date */
    tim = localtime(&t);
    st.m = tim->tm_mon + 1;
    st.d = tim->tm_mday;
    st.y = tim->tm_year + 1900;
 
-   /* If the application hasn't set a cursor name, then generate one */
-   if (stmt->cursor_name[0] == '\0')
+   /*  If the application hasn't set a cursor name, then generate one */
+   if ( stmt->cursor_name[0] == '\0')
        sprintf(stmt->cursor_name, "SQL_CUR%p", stmt);
 
-   /* For selects, prepend a declare cursor to the statement */
-   if (stmt->statement_type == STMT_TYPE_SELECT && globals.use_declarefetch)
-   {
+   /*  For selects, prepend a declare cursor to the statement */
+   if (stmt->statement_type == STMT_TYPE_SELECT && globals.use_declarefetch) {
        sprintf(new_statement, "declare %s cursor for ", stmt->cursor_name);
        npos = strlen(new_statement);
    }
-   else
-   {
+   else {
        new_statement[0] = '0';
        npos = 0;
    }
 
-   param_number = -1;
+    param_number = -1;
 
    oldstmtlen = strlen(old_statement);
 
-   for (opos = 0; opos < oldstmtlen; opos++)
-   {
-       /* Squeeze carriage-return/linefeed pairs to linefeed only */
-       if (old_statement[opos] == '\r' && opos + 1 < oldstmtlen &&
-           old_statement[opos + 1] == '\n')
+    for (opos = 0; opos < oldstmtlen; opos++) {
+
+       /*  Squeeze carriage-return/linefeed pairs to linefeed only */
+       if (old_statement[opos] == '\r' && opos+1 < oldstmtlen &&
+           old_statement[opos+1] == '\n') {
            continue;
+       }
 
-       /*
-        * Handle literals (date, time, timestamp) and ODBC scalar
-        * functions
-        */
-       else if (old_statement[opos] == '{')
-       {
-           char       *esc;
-           char       *begin = &old_statement[opos + 1];
-           char       *end = strchr(begin, '}');
+       /*  Handle literals (date, time, timestamp) and ODBC scalar functions */
+       else if (old_statement[opos] == '{') {
+           char *esc;
+           char *begin = &old_statement[opos + 1];
+           char *end = strchr(begin, '}');
 
-           if (!end)
+           if ( ! end)
                continue;
 
            *end = '\0';
 
            esc = convert_escape(begin);
-           if (esc)
-           {
+           if (esc) {
                memcpy(&new_statement[npos], esc, strlen(esc));
                npos += strlen(esc);
            }
-           else
-           {                   /* it's not a valid literal so just copy */
-               *end = '}';
+           else {      /* it's not a valid literal so just copy */
+               *end = '}'; 
                new_statement[npos++] = old_statement[opos];
                continue;
            }
@@ -774,15 +725,12 @@ copy_statement_with_parameters(StatementClass *stmt)
            continue;
        }
 
-       /*
-        * Can you have parameter markers inside of quotes?  I dont think
-        * so. All the queries I've seen expect the driver to put quotes
-        * if needed.
-        */
+       /*  Can you have parameter markers inside of quotes?  I dont think so.
+           All the queries I've seen expect the driver to put quotes if needed.
+       */
        else if (old_statement[opos] == '?' && !in_quote)
-           ;                   /* ok */
-       else
-       {
+           ;   /* ok */
+       else {
            if (old_statement[opos] == '\'')
                in_quote = (in_quote ? FALSE : TRUE);
 
@@ -793,396 +741,363 @@ copy_statement_with_parameters(StatementClass *stmt)
 
 
        /****************************************************/
-       /* Its a '?' parameter alright                */
+       /*       Its a '?' parameter alright                */
        /****************************************************/
 
        param_number++;
 
-       if (param_number >= stmt->parameters_allocated)
+       if (param_number >= stmt->parameters_allocated)
            break;
 
-       /* Assign correct buffers based on data at exec param or not */
-       if (stmt->parameters[param_number].data_at_exec)
-       {
+       /*  Assign correct buffers based on data at exec param or not */
+       if ( stmt->parameters[param_number].data_at_exec) {
            used = stmt->parameters[param_number].EXEC_used ? *stmt->parameters[param_number].EXEC_used : SQL_NTS;
            buffer = stmt->parameters[param_number].EXEC_buffer;
        }
-       else
-       {
+       else {
            used = stmt->parameters[param_number].used ? *stmt->parameters[param_number].used : SQL_NTS;
            buffer = stmt->parameters[param_number].buffer;
        }
 
-       /* Handle NULL parameter data */
-       if (used == SQL_NULL_DATA)
-       {
+       /*  Handle NULL parameter data */
+       if (used == SQL_NULL_DATA) {
            strcpy(&new_statement[npos], "NULL");
            npos += 4;
            continue;
        }
 
-       /*
-        * If no buffer, and it's not null, then what the hell is it? Just
-        * leave it alone then.
-        */
-       if (!buffer)
-       {
+       /*  If no buffer, and it's not null, then what the hell is it? 
+           Just leave it alone then.
+       */
+       if ( ! buffer) {
            new_statement[npos++] = '?';
            continue;
        }
 
        param_ctype = stmt->parameters[param_number].CType;
        param_sqltype = stmt->parameters[param_number].SQLType;
-
+       
        mylog("copy_statement_with_params: from(fcType)=%d, to(fSqlType)=%d\n", param_ctype, param_sqltype);
-
+       
        /* replace DEFAULT with something we can use */
-       if (param_ctype == SQL_C_DEFAULT)
+       if(param_ctype == SQL_C_DEFAULT)
            param_ctype = sqltype_to_default_ctype(param_sqltype);
 
        buf = NULL;
        param_string[0] = '\0';
        cbuf[0] = '\0';
 
+       
+       /*  Convert input C type to a neutral format */
+       switch(param_ctype) {
+       case SQL_C_BINARY:
+       case SQL_C_CHAR:
+           buf = buffer;
+           break;
 
-       /* Convert input C type to a neutral format */
-       switch (param_ctype)
-       {
-           case SQL_C_BINARY:
-           case SQL_C_CHAR:
-               buf = buffer;
-               break;
+       case SQL_C_DOUBLE:
+           sprintf(param_string, "%f", 
+                *((SDOUBLE *) buffer));
+           break;
 
-           case SQL_C_DOUBLE:
-               sprintf(param_string, "%f",
-                       *((SDOUBLE *) buffer));
-               break;
+       case SQL_C_FLOAT:
+           sprintf(param_string, "%f", 
+                *((SFLOAT *) buffer));
+           break;
 
-           case SQL_C_FLOAT:
-               sprintf(param_string, "%f",
-                       *((SFLOAT *) buffer));
-               break;
+       case SQL_C_SLONG:
+       case SQL_C_LONG:
+           sprintf(param_string, "%ld",
+               *((SDWORD *) buffer));
+           break;
 
-           case SQL_C_SLONG:
-           case SQL_C_LONG:
-               sprintf(param_string, "%ld",
-                       *((SDWORD *) buffer));
-               break;
+       case SQL_C_SSHORT:
+       case SQL_C_SHORT:
+           sprintf(param_string, "%d",
+               *((SWORD *) buffer));
+           break;
 
-           case SQL_C_SSHORT:
-           case SQL_C_SHORT:
-               sprintf(param_string, "%d",
-                       *((SWORD *) buffer));
-               break;
+       case SQL_C_STINYINT:
+       case SQL_C_TINYINT:
+           sprintf(param_string, "%d",
+               *((SCHAR *) buffer));
+           break;
 
-           case SQL_C_STINYINT:
-           case SQL_C_TINYINT:
-               sprintf(param_string, "%d",
-                       *((SCHAR *) buffer));
-               break;
+       case SQL_C_ULONG:
+           sprintf(param_string, "%lu",
+               *((UDWORD *) buffer));
+           break;
 
-           case SQL_C_ULONG:
-               sprintf(param_string, "%lu",
-                       *((UDWORD *) buffer));
-               break;
+       case SQL_C_USHORT:
+           sprintf(param_string, "%u",
+               *((UWORD *) buffer));
+           break;
 
-           case SQL_C_USHORT:
-               sprintf(param_string, "%u",
-                       *((UWORD *) buffer));
-               break;
+       case SQL_C_UTINYINT:
+           sprintf(param_string, "%u",
+               *((UCHAR *) buffer));
+           break;
 
-           case SQL_C_UTINYINT:
-               sprintf(param_string, "%u",
-                       *((UCHAR *) buffer));
-               break;
+       case SQL_C_BIT: {
+           int i = *((UCHAR *) buffer);
+           
+           sprintf(param_string, "%d", i ? 1 : 0);
+           break;
+                       }
 
-           case SQL_C_BIT:
-               {
-                   int         i = *((UCHAR *) buffer);
+       case SQL_C_DATE: {
+           DATE_STRUCT *ds = (DATE_STRUCT *) buffer;
+           st.m = ds->month;
+           st.d = ds->day;
+           st.y = ds->year;
 
-                   sprintf(param_string, "%d", i ? 1 : 0);
-                   break;
-               }
+           break;
+                        }
 
-           case SQL_C_DATE:
-               {
-                   DATE_STRUCT *ds = (DATE_STRUCT *) buffer;
+       case SQL_C_TIME: {
+           TIME_STRUCT *ts = (TIME_STRUCT *) buffer;
+           st.hh = ts->hour;
+           st.mm = ts->minute;
+           st.ss = ts->second;
 
-                   st.m = ds->month;
-                   st.d = ds->day;
-                   st.y = ds->year;
+           break;
+                        }
 
-                   break;
-               }
+       case SQL_C_TIMESTAMP: {
+           TIMESTAMP_STRUCT *tss = (TIMESTAMP_STRUCT *) buffer;
+           st.m = tss->month;
+           st.d = tss->day;
+           st.y = tss->year;
+           st.hh = tss->hour;
+           st.mm = tss->minute;
+           st.ss = tss->second;
 
-           case SQL_C_TIME:
-               {
-                   TIME_STRUCT *ts = (TIME_STRUCT *) buffer;
+           mylog("m=%d,d=%d,y=%d,hh=%d,mm=%d,ss=%d\n", st.m, st.d, st.y, st.hh, st.mm, st.ss);
 
-                   st.hh = ts->hour;
-                   st.mm = ts->minute;
-                   st.ss = ts->second;
+           break;
 
-                   break;
-               }
+                             }
+       default:
+           /* error */
+           stmt->errormsg = "Unrecognized C_parameter type in copy_statement_with_parameters";
+           stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
+           new_statement[npos] = '\0';   /* just in case */
+           SC_log_error(func, "", stmt);
+           return SQL_ERROR;
+       }
 
-           case SQL_C_TIMESTAMP:
-               {
-                   TIMESTAMP_STRUCT *tss = (TIMESTAMP_STRUCT *) buffer;
+       /*  Now that the input data is in a neutral format, convert it to
+           the desired output format (sqltype)
+       */
 
-                   st.m = tss->month;
-                   st.d = tss->day;
-                   st.y = tss->year;
-                   st.hh = tss->hour;
-                   st.mm = tss->minute;
-                   st.ss = tss->second;
+       switch(param_sqltype) {
+       case SQL_CHAR:
+       case SQL_VARCHAR:
+       case SQL_LONGVARCHAR:
 
-                   mylog("m=%d,d=%d,y=%d,hh=%d,mm=%d,ss=%d\n", st.m, st.d, st.y, st.hh, st.mm, st.ss);
+           new_statement[npos++] = '\'';   /*    Open Quote */
 
-                   break;
-               }
-           default:
-               /* error */
-               stmt->errormsg = "Unrecognized C_parameter type in copy_statement_with_parameters";
-               stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
-               new_statement[npos] = '\0';     /* just in case */
-               SC_log_error(func, "", stmt);
-               return SQL_ERROR;
-       }
+           /* it was a SQL_C_CHAR */
+           if (buf) {
+               convert_special_chars(buf, &new_statement[npos], used);
+               npos += strlen(&new_statement[npos]);
+           }
 
-       /*
-        * Now that the input data is in a neutral format, convert it to
-        * the desired output format (sqltype)
-        */
+           /* it was a numeric type */
+           else if (param_string[0] != '\0') { 
+               strcpy(&new_statement[npos], param_string);
+               npos += strlen(param_string);
+           }
 
-       switch (param_sqltype)
-       {
-           case SQL_CHAR:
-           case SQL_VARCHAR:
-           case SQL_LONGVARCHAR:
+           /* it was date,time,timestamp -- use m,d,y,hh,mm,ss */
+           else {
+               sprintf(tmp, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
+                   st.y, st.m, st.d, st.hh, st.mm, st.ss);
 
-               new_statement[npos++] = '\'';   /* Open Quote */
+               strcpy(&new_statement[npos], tmp);
+               npos += strlen(tmp);
+           }
 
-               /* it was a SQL_C_CHAR */
-               if (buf)
-               {
-                   convert_special_chars(buf, &new_statement[npos], used);
-                   npos += strlen(&new_statement[npos]);
-               }
+           new_statement[npos++] = '\'';   /*    Close Quote */
 
-               /* it was a numeric type */
-               else if (param_string[0] != '\0')
-               {
-                   strcpy(&new_statement[npos], param_string);
-                   npos += strlen(param_string);
-               }
+           break;
 
-               /* it was date,time,timestamp -- use m,d,y,hh,mm,ss */
-               else
-               {
-                   sprintf(tmp, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
-                           st.y, st.m, st.d, st.hh, st.mm, st.ss);
+       case SQL_DATE:
+           if (buf) {  /* copy char data to time */
+               my_strcpy(cbuf, sizeof(cbuf), buf, used);
+               parse_datetime(cbuf, &st);
+           }
 
-                   strcpy(&new_statement[npos], tmp);
-                   npos += strlen(tmp);
-               }
+           sprintf(tmp, "'%.4d-%.2d-%.2d'", st.y, st.m, st.d);
 
-               new_statement[npos++] = '\'';   /* Close Quote */
+           strcpy(&new_statement[npos], tmp);
+           npos += strlen(tmp);
+           break;
 
-               break;
+       case SQL_TIME:
+           if (buf) {  /* copy char data to time */
+               my_strcpy(cbuf, sizeof(cbuf), buf, used);
+               parse_datetime(cbuf, &st);
+           }
 
-           case SQL_DATE:
-               if (buf)
-               {               /* copy char data to time */
-                   my_strcpy(cbuf, sizeof(cbuf), buf, used);
-                   parse_datetime(cbuf, &st);
-               }
+           sprintf(tmp, "'%.2d:%.2d:%.2d'", st.hh, st.mm, st.ss);
 
-               sprintf(tmp, "'%.4d-%.2d-%.2d'", st.y, st.m, st.d);
+           strcpy(&new_statement[npos], tmp);
+           npos += strlen(tmp);
+           break;
 
-               strcpy(&new_statement[npos], tmp);
-               npos += strlen(tmp);
-               break;
+       case SQL_TIMESTAMP:
 
-           case SQL_TIME:
-               if (buf)
-               {               /* copy char data to time */
-                   my_strcpy(cbuf, sizeof(cbuf), buf, used);
-                   parse_datetime(cbuf, &st);
-               }
+           if (buf) {
+               my_strcpy(cbuf, sizeof(cbuf), buf, used);
+               parse_datetime(cbuf, &st);
+           }
 
-               sprintf(tmp, "'%.2d:%.2d:%.2d'", st.hh, st.mm, st.ss);
+           sprintf(tmp, "'%.4d-%.2d-%.2d %.2d:%.2d:%.2d'",
+               st.y, st.m, st.d, st.hh, st.mm, st.ss);
 
-               strcpy(&new_statement[npos], tmp);
-               npos += strlen(tmp);
-               break;
+           strcpy(&new_statement[npos], tmp);
+           npos += strlen(tmp);
 
-           case SQL_TIMESTAMP:
+           break;
 
-               if (buf)
-               {
-                   my_strcpy(cbuf, sizeof(cbuf), buf, used);
-                   parse_datetime(cbuf, &st);
-               }
+       case SQL_BINARY:
+       case SQL_VARBINARY:         /* non-ascii characters should be converted to octal */
+           new_statement[npos++] = '\'';   /*    Open Quote */
 
-               sprintf(tmp, "'%.4d-%.2d-%.2d %.2d:%.2d:%.2d'",
-                       st.y, st.m, st.d, st.hh, st.mm, st.ss);
+           mylog("SQL_VARBINARY: about to call convert_to_pgbinary, used = %d\n", used);
 
-               strcpy(&new_statement[npos], tmp);
-               npos += strlen(tmp);
+           npos += convert_to_pgbinary(buf, &new_statement[npos], used);
 
-               break;
+           new_statement[npos++] = '\'';   /*    Close Quote */
+           
+           break;
+
+       case SQL_LONGVARBINARY:     
+
+           if ( stmt->parameters[param_number].data_at_exec) {
 
-           case SQL_BINARY:
-           case SQL_VARBINARY:/* non-ascii characters should be
-                                * converted to octal */
-               new_statement[npos++] = '\'';   /* Open Quote */
+               lobj_oid = stmt->parameters[param_number].lobj_oid;
 
-               mylog("SQL_VARBINARY: about to call convert_to_pgbinary, used = %d\n", used);
+           }
+           else {
+  
+               /* begin transaction if needed */
+               if(!CC_is_in_trans(stmt->hdbc)) {
+                   QResultClass *res;
+                   char ok;
+
+                   res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
+                   if (!res) {
+                       stmt->errormsg = "Could not begin (in-line) a transaction";
+                       stmt->errornumber = STMT_EXEC_ERROR;
+                       SC_log_error(func, "", stmt);
+                       return SQL_ERROR;
+                   }
+                   ok = QR_command_successful(res);
+                   QR_Destructor(res);
+                   if (!ok) {
+                       stmt->errormsg = "Could not begin (in-line) a transaction";
+                       stmt->errornumber = STMT_EXEC_ERROR;
+                       SC_log_error(func, "", stmt);
+                       return SQL_ERROR;
+                   }
 
-               npos += convert_to_pgbinary(buf, &new_statement[npos], used);
+                   CC_set_in_trans(stmt->hdbc);
+               }
 
-               new_statement[npos++] = '\'';   /* Close Quote */
+               /*  store the oid */
+               lobj_oid = lo_creat(stmt->hdbc, INV_READ | INV_WRITE);
+               if (lobj_oid == 0) {
+                   stmt->errornumber = STMT_EXEC_ERROR;
+                   stmt->errormsg = "Couldnt create (in-line) large object.";
+                   SC_log_error(func, "", stmt);
+                   return SQL_ERROR;
+               }
 
-               break;
+               /*  store the fd */
+               lobj_fd = lo_open(stmt->hdbc, lobj_oid, INV_WRITE);
+               if ( lobj_fd < 0) {
+                   stmt->errornumber = STMT_EXEC_ERROR;
+                   stmt->errormsg = "Couldnt open (in-line) large object for writing.";
+                   SC_log_error(func, "", stmt);
+                   return SQL_ERROR;
+               }
 
-           case SQL_LONGVARBINARY:
+               retval = lo_write(stmt->hdbc, lobj_fd, buffer, used);
 
-               if (stmt->parameters[param_number].data_at_exec)
-                   lobj_oid = stmt->parameters[param_number].lobj_oid;
-               else
-               {
-                   /* begin transaction if needed */
-                   if (!CC_is_in_trans(stmt->hdbc))
-                   {
-                       QResultClass *res;
-                       char        ok;
-
-                       res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
-                       if (!res)
-                       {
-                           stmt->errormsg = "Could not begin (in-line) a transaction";
-                           stmt->errornumber = STMT_EXEC_ERROR;
-                           SC_log_error(func, "", stmt);
-                           return SQL_ERROR;
-                       }
-                       ok = QR_command_successful(res);
-                       QR_Destructor(res);
-                       if (!ok)
-                       {
-                           stmt->errormsg = "Could not begin (in-line) a transaction";
-                           stmt->errornumber = STMT_EXEC_ERROR;
-                           SC_log_error(func, "", stmt);
-                           return SQL_ERROR;
-                       }
+               lo_close(stmt->hdbc, lobj_fd);
 
-                       CC_set_in_trans(stmt->hdbc);
-                   }
+               /* commit transaction if needed */
+               if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc)) {
+                   QResultClass *res;
+                   char ok;
 
-                   /* store the oid */
-                   lobj_oid = lo_creat(stmt->hdbc, INV_READ | INV_WRITE);
-                   if (lobj_oid == 0)
-                   {
+                   res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
+                   if (!res) {
+                       stmt->errormsg = "Could not commit (in-line) a transaction";
                        stmt->errornumber = STMT_EXEC_ERROR;
-                       stmt->errormsg = "Couldnt create (in-line) large object.";
                        SC_log_error(func, "", stmt);
                        return SQL_ERROR;
                    }
-
-                   /* store the fd */
-                   lobj_fd = lo_open(stmt->hdbc, lobj_oid, INV_WRITE);
-                   if (lobj_fd < 0)
-                   {
+                   ok = QR_command_successful(res);
+                   QR_Destructor(res);
+                   if (!ok) {
+                       stmt->errormsg = "Could not commit (in-line) a transaction";
                        stmt->errornumber = STMT_EXEC_ERROR;
-                       stmt->errormsg = "Couldnt open (in-line) large object for writing.";
                        SC_log_error(func, "", stmt);
                        return SQL_ERROR;
                    }
 
-                   retval = lo_write(stmt->hdbc, lobj_fd, buffer, used);
+                   CC_set_no_trans(stmt->hdbc);
+               }
+           }
 
-                   lo_close(stmt->hdbc, lobj_fd);
+           /*  the oid of the large object -- just put that in for the
+               parameter marker -- the data has already been sent to the large object
+           */
+           sprintf(param_string, "'%d'", lobj_oid);
+           strcpy(&new_statement[npos], param_string);
+           npos += strlen(param_string);
 
-                   /* commit transaction if needed */
-                   if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
-                   {
-                       QResultClass *res;
-                       char        ok;
+           break;
 
-                       res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
-                       if (!res)
-                       {
-                           stmt->errormsg = "Could not commit (in-line) a transaction";
-                           stmt->errornumber = STMT_EXEC_ERROR;
-                           SC_log_error(func, "", stmt);
-                           return SQL_ERROR;
-                       }
-                       ok = QR_command_successful(res);
-                       QR_Destructor(res);
-                       if (!ok)
-                       {
-                           stmt->errormsg = "Could not commit (in-line) a transaction";
-                           stmt->errornumber = STMT_EXEC_ERROR;
-                           SC_log_error(func, "", stmt);
-                           return SQL_ERROR;
-                       }
+           /*  because of no conversion operator for bool and int4, SQL_BIT */
+           /*  must be quoted (0 or 1 is ok to use inside the quotes) */
 
-                       CC_set_no_trans(stmt->hdbc);
-                   }
-               }
+       default:        /* a numeric type or SQL_BIT */
+           if (param_sqltype == SQL_BIT)
+               new_statement[npos++] = '\'';   /*    Open Quote */
 
-               /*
-                * the oid of the large object -- just put that in for the
-                * parameter marker -- the data has already been sent to
-                * the large object
-                */
-               sprintf(param_string, "'%d'", lobj_oid);
+           if (buf) {
+               my_strcpy(&new_statement[npos], sizeof(stmt->stmt_with_params) - npos, buf, used);
+               npos += strlen(&new_statement[npos]);
+           }
+           else {
                strcpy(&new_statement[npos], param_string);
                npos += strlen(param_string);
+           }
 
-               break;
-
-               /*
-                * because of no conversion operator for bool and int4,
-                * SQL_BIT
-                */
-               /* must be quoted (0 or 1 is ok to use inside the quotes) */
-
-           default:            /* a numeric type or SQL_BIT */
-               if (param_sqltype == SQL_BIT)
-                   new_statement[npos++] = '\'';       /* Open Quote */
+           if (param_sqltype == SQL_BIT)
+               new_statement[npos++] = '\'';   /*    Close Quote */
 
-               if (buf)
-               {
-                   my_strcpy(&new_statement[npos], sizeof(stmt->stmt_with_params) - npos, buf, used);
-                   npos += strlen(&new_statement[npos]);
-               }
-               else
-               {
-                   strcpy(&new_statement[npos], param_string);
-                   npos += strlen(param_string);
-               }
-
-               if (param_sqltype == SQL_BIT)
-                   new_statement[npos++] = '\'';       /* Close Quote */
+           break;
 
-               break;
        }
-   }                           /* end, for */
+
+   }   /* end, for */
 
    /* make sure new_statement is always null-terminated */
    new_statement[npos] = '\0';
 
 
-   if (stmt->hdbc->DriverToDataSource != NULL)
-   {
-       int         length = strlen(new_statement);
-
-       stmt->hdbc->DriverToDataSource(stmt->hdbc->translation_option,
-                                      SQL_CHAR,
-                                      new_statement, length,
-                                      new_statement, length, NULL,
-                                      NULL, 0, NULL);
+   if(stmt->hdbc->DriverToDataSource != NULL) {
+       int length = strlen (new_statement);
+       stmt->hdbc->DriverToDataSource (stmt->hdbc->translation_option,
+                                       SQL_CHAR,
+                                       new_statement, length,
+                                       new_statement, length, NULL,
+                                       NULL, 0, NULL);
    }
 
 
@@ -1192,10 +1107,10 @@ copy_statement_with_parameters(StatementClass *stmt)
 char *
 mapFunction(char *func)
 {
-   int         i;
+int i;
 
    for (i = 0; mapFuncs[i][0]; i++)
-       if (!stricmp(mapFuncs[i][0], func))
+       if ( ! stricmp(mapFuncs[i][0], func))
            return mapFuncs[i][1];
 
    return NULL;
@@ -1207,40 +1122,34 @@ mapFunction(char *func)
 char *
 convert_escape(char *value)
 {
-   static char escape[1024];
-   char        key[33];
+static char escape[1024];
+char key[33];
 
    /* Separate off the key, skipping leading and trailing whitespace */
-   while ((*value != '\0') && isspace((unsigned char) *value))
-       value++;
+   while ((*value != '\0') && isspace((unsigned char) *value)) value++;
    sscanf(value, "%32s", key);
-   while ((*value != '\0') && (!isspace((unsigned char) *value)))
-       value++;
-   while ((*value != '\0') && isspace((unsigned char) *value))
-       value++;
+   while ((*value != '\0') && (! isspace((unsigned char) *value))) value++;
+   while ((*value != '\0') && isspace((unsigned char) *value)) value++;
 
    mylog("convert_escape: key='%s', val='%s'\n", key, value);
 
-   if ((strcmp(key, "d") == 0) ||
-       (strcmp(key, "t") == 0) ||
-       (strcmp(key, "ts") == 0))
-   {
+   if ( (strcmp(key, "d") == 0) ||
+        (strcmp(key, "t") == 0) ||
+        (strcmp(key, "ts") == 0)) {
        /* Literal; return the escape part as-is */
-       strncpy(escape, value, sizeof(escape) - 1);
+       strncpy(escape, value, sizeof(escape)-1);
    }
-   else if (strcmp(key, "fn") == 0)
-   {
-
-       /*
-        * Function invocation Separate off the func name, skipping
-        * trailing whitespace.
+   else if (strcmp(key, "fn") == 0) {
+       /* Function invocation
+        * Separate off the func name,
+        * skipping trailing whitespace.
         */
-       char       *funcEnd = value;
-       char        svchar;
-       char       *mapFunc;
+       char *funcEnd = value;
+       char svchar;
+       char *mapFunc;
 
        while ((*funcEnd != '\0') && (*funcEnd != '(') &&
-              (!isspace((unsigned char) *funcEnd)))
+              (! isspace((unsigned char) *funcEnd)))
            funcEnd++;
        svchar = *funcEnd;
        *funcEnd = '\0';
@@ -1249,51 +1158,45 @@ convert_escape(char *value)
        while ((*funcEnd != '\0') && isspace((unsigned char) *funcEnd))
            funcEnd++;
 
-       /*
-        * We expect left parenthesis here, else return fn body as-is
-        * since it is one of those "function constants".
+       /* We expect left parenthesis here,
+        * else return fn body as-is since it is
+        * one of those "function constants".
         */
-       if (*funcEnd != '(')
-       {
-           strncpy(escape, value, sizeof(escape) - 1);
+       if (*funcEnd != '(') {
+           strncpy(escape, value, sizeof(escape)-1);
            return escape;
        }
        mapFunc = mapFunction(key);
-
-       /*
-        * We could have mapFunction() return key if not in table... -
-        * thomas 2000-04-03
+       /* We could have mapFunction() return key if not in table...
+        * - thomas 2000-04-03
         */
-       if (mapFunc == NULL)
-       {
+       if (mapFunc == NULL) {
            /* If unrecognized function name, return fn body as-is */
-           strncpy(escape, value, sizeof(escape) - 1);
+           strncpy(escape, value, sizeof(escape)-1);
            return escape;
        }
        /* copy mapped name and remaining input string */
        strcpy(escape, mapFunc);
-       strncat(escape, funcEnd, sizeof(escape) - 1 - strlen(mapFunc));
+       strncat(escape, funcEnd, sizeof(escape)-1-strlen(mapFunc));
    }
-   else
-   {
+   else {
        /* Bogus key, leave untranslated */
        return NULL;
    }
 
    return escape;
+
 }
 
 
 char *
 convert_money(char *s)
 {
-   size_t      i = 0,
-               out = 0;
+size_t i = 0, out = 0;
 
-   for (i = 0; i < strlen(s); i++)
-   {
+   for (i = 0; i < strlen(s); i++) {
        if (s[i] == '$' || s[i] == ',' || s[i] == ')')
-           ;                   /* skip these characters */
+           ; /* skip these characters */
        else if (s[i] == '(')
            s[out++] = '-';
        else
@@ -1310,23 +1213,17 @@ convert_money(char *s)
 char
 parse_datetime(char *buf, SIMPLE_TIME *st)
 {
-   int         y,
-               m,
-               d,
-               hh,
-               mm,
-               ss;
-   int         nf;
-
+int y,m,d,hh,mm,ss;
+int nf;
+   
    y = m = d = hh = mm = ss = 0;
 
-   if (buf[4] == '-')          /* year first */
-       nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y, &m, &d, &hh, &mm, &ss);
+   if (buf[4] == '-')  /* year first */
+       nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y,&m,&d,&hh,&mm,&ss);
    else
-       nf = sscanf(buf, "%2d-%2d-%4d %2d:%2d:%2d", &m, &d, &y, &hh, &mm, &ss);
+       nf = sscanf(buf, "%2d-%2d-%4d %2d:%2d:%2d", &m,&d,&y,&hh,&mm,&ss);
 
-   if (nf == 5 || nf == 6)
-   {
+   if (nf == 5 || nf == 6) {
        st->y = y;
        st->m = m;
        st->d = d;
@@ -1337,13 +1234,12 @@ parse_datetime(char *buf, SIMPLE_TIME *st)
        return TRUE;
    }
 
-   if (buf[4] == '-')          /* year first */
+   if (buf[4] == '-')  /* year first */
        nf = sscanf(buf, "%4d-%2d-%2d", &y, &m, &d);
    else
        nf = sscanf(buf, "%2d-%2d-%4d", &m, &d, &y);
 
-   if (nf == 3)
-   {
+   if (nf == 3) {
        st->y = y;
        st->m = m;
        st->d = d;
@@ -1352,8 +1248,7 @@ parse_datetime(char *buf, SIMPLE_TIME *st)
    }
 
    nf = sscanf(buf, "%2d:%2d:%2d", &hh, &mm, &ss);
-   if (nf == 2 || nf == 3)
-   {
+   if (nf == 2 || nf == 3) {
        st->hh = hh;
        st->mm = mm;
        st->ss = ss;
@@ -1368,16 +1263,12 @@ parse_datetime(char *buf, SIMPLE_TIME *st)
 int
 convert_linefeeds(char *si, char *dst, size_t max)
 {
-   size_t      i = 0,
-               out = 0;
+size_t i = 0, out = 0;
 
-   for (i = 0; i < strlen(si) && out < max - 1; i++)
-   {
-       if (si[i] == '\n')
-       {
-           /* Only add the carriage-return if needed */
-           if (i > 0 && si[i - 1] == '\r')
-           {
+   for (i = 0; i < strlen(si) && out < max - 1; i++) {
+       if (si[i] == '\n') {
+           /*  Only add the carriage-return if needed */
+           if (i > 0 && si[i-1] == '\r') {
                dst[out++] = si[i];
                continue;
            }
@@ -1392,17 +1283,15 @@ convert_linefeeds(char *si, char *dst, size_t max)
    return out;
 }
 
-/* Change carriage-return/linefeed to just linefeed
+/* Change carriage-return/linefeed to just linefeed 
    Plus, escape any special characters.
 */
 char *
 convert_special_chars(char *si, char *dst, int used)
 {
-   size_t      i = 0,
-               out = 0,
-               max;
-   static char sout[TEXT_FIELD_SIZE + 5];
-   char       *p;
+size_t i = 0, out = 0, max;
+static char sout[TEXT_FIELD_SIZE+5];
+char *p;
 
    if (dst)
        p = dst;
@@ -1416,9 +1305,8 @@ convert_special_chars(char *si, char *dst, int used)
    else
        max = used;
 
-   for (i = 0; i < max; i++)
-   {
-       if (si[i] == '\r' && i + 1 < strlen(si) && si[i + 1] == '\n')
+   for (i = 0; i < max; i++) {
+       if (si[i] == '\r' && i+1 < strlen(si) && si[i+1] == '\n') 
            continue;
        else if (si[i] == '\'' || si[i] == '\\')
            p[out++] = '\\';
@@ -1442,32 +1330,31 @@ convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax)
 unsigned int
 conv_from_octal(unsigned char *s)
 {
-   int         i,
-               y = 0;
+int i, y=0;
 
-   for (i = 1; i <= 3; i++)
-       y += (s[i] - 48) * (int) pow(8, 3 - i);
+   for (i = 1; i <= 3; i++) {
+       y += (s[i] - 48) * (int) pow(8, 3-i);
+   }
 
    return y;
+
 }
 
 unsigned int
 conv_from_hex(unsigned char *s)
 {
-   int         i,
-               y = 0,
-               val;
-
-   for (i = 1; i <= 2; i++)
-   {
-       if (s[i] >= 'a' && s[i] <= 'f')
-           val = s[i] - 'a' + 10;
-       else if (s[i] >= 'A' && s[i] <= 'F')
-           val = s[i] - 'A' + 10;
-       else
-           val = s[i] - '0';
+int i, y=0, val;
+
+   for (i = 1; i <= 2; i++) {
+
+        if (s[i] >= 'a' && s[i] <= 'f')
+            val = s[i] - 'a' + 10;
+        else if (s[i] >= 'A' && s[i] <= 'F')
+            val = s[i] - 'A' + 10;
+        else
+            val = s[i] - '0';
 
-       y += val * (int) pow(16, 2 - i);
+       y += val * (int) pow(16, 2-i);
    }
 
    return y;
@@ -1477,24 +1364,23 @@ conv_from_hex(unsigned char *s)
 int
 convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax)
 {
-   size_t      i;
-   int         o = 0;
+size_t i;
+int o=0;
 
-
-   for (i = 0; i < strlen(value);)
-   {
-       if (value[i] == '\\')
-       {
+   
+   for (i = 0; i < strlen(value); ) {
+       if (value[i] == '\\') {
            rgbValue[o] = conv_from_octal(&value[i]);
            i += 4;
        }
-       else
+       else {
            rgbValue[o] = value[i++];
+       }
        mylog("convert_from_pgbinary: i=%d, rgbValue[%d] = %d, %c\n", i, o, rgbValue[o], rgbValue[o]);
        o++;
    }
 
-   rgbValue[o] = '\0';         /* extra protection */
+   rgbValue[o] = '\0'; /* extra protection */
 
    return o;
 }
@@ -1503,15 +1389,14 @@ convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValue
 char *
 conv_to_octal(unsigned char val)
 {
-   int         i;
-   static char x[6];
+int i;
+static char x[6];
 
    x[0] = '\\';
    x[1] = '\\';
    x[5] = '\0';
 
-   for (i = 4; i > 1; i--)
-   {
+   for (i = 4; i > 1; i--) {
        x[i] = (val & 7) + 48;
        val >>= 3;
    }
@@ -1523,20 +1408,19 @@ conv_to_octal(unsigned char val)
 int
 convert_to_pgbinary(unsigned char *in, char *out, int len)
 {
-   int         i,
-               o = 0;
+int i, o=0;
 
 
-   for (i = 0; i < len; i++)
-   {
+   for (i = 0; i < len; i++) {
        mylog("convert_to_pgbinary: in[%d] = %d, %c\n", i, in[i], in[i]);
-       if (isalnum(in[i]) || in[i] == ' ')
+       if ( isalnum(in[i]) || in[i] == ' ') {
            out[o++] = in[i];
-       else
-       {
-           strcpy(&out[o], conv_to_octal(in[i]));
+       }
+       else {
+           strcpy(&out[o], conv_to_octal(in[i])); 
            o += 5;
        }
+
    }
 
    mylog("convert_to_pgbinary: returning %d, out='%.*s'\n", o, o, out);
@@ -1548,20 +1432,17 @@ convert_to_pgbinary(unsigned char *in, char *out, int len)
 void
 encode(char *in, char *out)
 {
-   unsigned int i,
-               o = 0;
+   unsigned int i, o = 0;
 
-   for (i = 0; i < strlen(in); i++)
-   {
-       if (in[i] == '+')
-       {
+   for (i = 0; i < strlen(in); i++) {
+       if ( in[i] == '+') {
            sprintf(&out[o], "%%2B");
            o += 3;
        }
-       else if (isspace((unsigned char) in[i]))
+       else if ( isspace((unsigned char) in[i])) {
            out[o++] = '+';
-       else if (!isalnum((unsigned char) in[i]))
-       {
+       }
+       else if ( ! isalnum((unsigned char) in[i])) {
            sprintf(&out[o], "%%%02x", (unsigned char) in[i]);
            o += 3;
        }
@@ -1575,17 +1456,14 @@ encode(char *in, char *out)
 void
 decode(char *in, char *out)
 {
-   unsigned int i,
-               o = 0;
+unsigned int i, o = 0;
 
-   for (i = 0; i < strlen(in); i++)
-   {
+   for (i = 0; i < strlen(in); i++) { 
        if (in[i] == '+')
            out[o++] = ' ';
-       else if (in[i] == '%')
-       {
+       else if (in[i] == '%') {
            sprintf(&out[o++], "%c", conv_from_hex(&in[i]));
-           i += 2;
+           i+=2;
        }
        else
            out[o++] = in[i];
@@ -1605,52 +1483,45 @@ decode(char *in, char *out)
 
    CURRENTLY, ONLY LONGVARBINARY is handled, since that is the only
    data type currently mapped to a PG_TYPE_LO.  But, if any other types
-   are desired to map to a large object (PG_TYPE_LO), then that would
+   are desired to map to a large object (PG_TYPE_LO), then that would 
    need to be handled here.  For example, LONGVARCHAR could possibly be
    mapped to PG_TYPE_LO someday, instead of PG_TYPE_TEXT as it is now.
 */
 int
-convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
+convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue, 
           SDWORD cbValueMax, SDWORD *pcbValue)
 {
-   Oid         oid;
-   int         retval,
-               result,
-               left = -1;
+   Oid oid;
+   int retval, result, left = -1;
    BindInfoClass *bindInfo = NULL;
 
 
 /* If using SQLGetData, then current_col will be set */
-   if (stmt->current_col >= 0)
-   {
+   if (stmt->current_col >= 0) {
        bindInfo = &stmt->bindings[stmt->current_col];
        left = bindInfo->data_left;
    }
 
-   /*
-    * if this is the first call for this column, open the large object
-    * for reading
-    */
+   /*  if this is the first call for this column,
+       open the large object for reading 
+   */
+
+   if ( ! bindInfo || bindInfo->data_left == -1) {
 
-   if (!bindInfo || bindInfo->data_left == -1)
-   {
        /* begin transaction if needed */
-       if (!CC_is_in_trans(stmt->hdbc))
-       {
+       if(!CC_is_in_trans(stmt->hdbc)) {
            QResultClass *res;
-           char        ok;
+           char ok;
 
            res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
-           if (!res)
-           {
+           if (!res) {
                stmt->errormsg = "Could not begin (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
            }
            ok = QR_command_successful(res);
            QR_Destructor(res);
-           if (!ok)
-           {
+           if (!ok) {
                stmt->errormsg = "Could not begin (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
@@ -1661,58 +1532,53 @@ convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
 
        oid = atoi(value);
        stmt->lobj_fd = lo_open(stmt->hdbc, oid, INV_READ);
-       if (stmt->lobj_fd < 0)
-       {
+       if (stmt->lobj_fd < 0) {
            stmt->errornumber = STMT_EXEC_ERROR;
            stmt->errormsg = "Couldnt open large object for reading.";
            return COPY_GENERAL_ERROR;
        }
 
-       /* Get the size */
+       /*  Get the size */
        retval = lo_lseek(stmt->hdbc, stmt->lobj_fd, 0L, SEEK_END);
-       if (retval >= 0)
-       {
+       if (retval >= 0) {
+
            left = lo_tell(stmt->hdbc, stmt->lobj_fd);
            if (bindInfo)
                bindInfo->data_left = left;
 
-           /* return to beginning */
+           /*  return to beginning */
            lo_lseek(stmt->hdbc, stmt->lobj_fd, 0L, SEEK_SET);
        }
    }
 
-   if (left == 0)
+   if (left == 0) {
        return COPY_NO_DATA_FOUND;
+   }
 
-   if (stmt->lobj_fd < 0)
-   {
+   if (stmt->lobj_fd < 0) {
        stmt->errornumber = STMT_EXEC_ERROR;
        stmt->errormsg = "Large object FD undefined for multiple read.";
        return COPY_GENERAL_ERROR;
    }
 
    retval = lo_read(stmt->hdbc, stmt->lobj_fd, (char *) rgbValue, cbValueMax);
-   if (retval < 0)
-   {
+   if (retval < 0) {
        lo_close(stmt->hdbc, stmt->lobj_fd);
 
        /* commit transaction if needed */
-       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
-       {
+       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc)) {
            QResultClass *res;
-           char        ok;
+           char ok;
 
            res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
-           if (!res)
-           {
+           if (!res) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
            }
            ok = QR_command_successful(res);
            QR_Destructor(res);
-           if (!ok)
-           {
+           if (!ok) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
@@ -1737,31 +1603,27 @@ convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
        *pcbValue = left < 0 ? SQL_NO_TOTAL : left;
 
 
-   if (bindInfo && bindInfo->data_left > 0)
+   if (bindInfo && bindInfo->data_left > 0) 
        bindInfo->data_left -= retval;
 
 
-   if (!bindInfo || bindInfo->data_left == 0)
-   {
+   if (! bindInfo || bindInfo->data_left == 0) {
        lo_close(stmt->hdbc, stmt->lobj_fd);
 
        /* commit transaction if needed */
-       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
-       {
+       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc)) {
            QResultClass *res;
-           char        ok;
+           char ok;
 
            res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
-           if (!res)
-           {
+           if (!res) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
            }
            ok = QR_command_successful(res);
            QR_Destructor(res);
-           if (!ok)
-           {
+           if (!ok) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                return COPY_GENERAL_ERROR;
@@ -1770,9 +1632,10 @@ convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
            CC_set_no_trans(stmt->hdbc);
        }
 
-       stmt->lobj_fd = -1;     /* prevent further reading */
+       stmt->lobj_fd = -1; /* prevent further reading */
    }
 
 
    return result;
+
 }
index ae903bbafb6bbea95e090299ba82bf7b18bf095d..7fd8254779075d9b2e4caa6fdc65e0d08024f51d 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           convert.h
+/* File:            convert.h
  *
- * Description:        See "convert.c"
+ * Description:     See "convert.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #include "psqlodbc.h"
 
 /* copy_and_convert results */
-#define COPY_OK                         0
-#define COPY_UNSUPPORTED_TYPE       1
+#define COPY_OK                      0
+#define COPY_UNSUPPORTED_TYPE        1
 #define COPY_UNSUPPORTED_CONVERSION  2
-#define COPY_RESULT_TRUNCATED       3
-#define COPY_GENERAL_ERROR          4
-#define COPY_NO_DATA_FOUND          5
-
-typedef struct
-{
-   int         m;
-   int         d;
-   int         y;
-   int         hh;
-   int         mm;
-   int         ss;
+#define COPY_RESULT_TRUNCATED        3
+#define COPY_GENERAL_ERROR           4
+#define COPY_NO_DATA_FOUND           5
+
+typedef struct {
+   int m;
+   int d;
+   int y;
+   int hh;
+   int mm;
+   int ss;
 } SIMPLE_TIME;
 
-int            copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
-int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType,
-                      PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue);
-
-int            copy_statement_with_parameters(StatementClass *stmt);
-char      *convert_escape(char *value);
-char      *convert_money(char *s);
-char       parse_datetime(char *buf, SIMPLE_TIME *st);
-int            convert_linefeeds(char *s, char *dst, size_t max);
-char      *convert_special_chars(char *si, char *dst, int used);
-
-int            convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax);
-int            convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax);
-int            convert_to_pgbinary(unsigned char *in, char *out, int len);
-void       encode(char *in, char *out);
-void       decode(char *in, char *out);
-int convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue,
+int copy_and_convert_field_bindinfo(StatementClass *stmt, Int4 field_type, void *value, int col);
+int copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 fCType, 
+                          PTR rgbValue, SDWORD cbValueMax, SDWORD *pcbValue);
+
+int copy_statement_with_parameters(StatementClass *stmt);
+char *convert_escape(char *value);
+char *convert_money(char *s);
+char parse_datetime(char *buf, SIMPLE_TIME *st);
+int convert_linefeeds(char *s, char *dst, size_t max);
+char *convert_special_chars(char *si, char *dst, int used);
+
+int convert_pgbinary_to_char(char *value, char *rgbValue, int cbValueMax);
+int convert_from_pgbinary(unsigned char *value, unsigned char *rgbValue, int cbValueMax);
+int convert_to_pgbinary(unsigned char *in, char *out, int len);
+void encode(char *in, char *out);
+void decode(char *in, char *out);
+int convert_lo(StatementClass *stmt, void *value, Int2 fCType, PTR rgbValue, 
           SDWORD cbValueMax, SDWORD *pcbValue);
 
 #endif
index 1f5c7dba5eaecaf67215d38690644d7ecc12e02b..13e8b44e6189deb4382b000efb3a9a1f1226d409 100644 (file)
@@ -1,17 +1,18 @@
-/* Module:         dlg_specific.c
+
+/* Module:          dlg_specific.c
  *
- * Description:        This module contains any specific code for handling
- *                 dialog boxes such as driver/datasource options.  Both the
- *                 ConfigDSN() and the SQLDriverConnect() functions use
- *                 functions in this module.  If you were to add a new option
- *                 to any dialog box, you would most likely only have to change
- *                 things in here rather than in 2 separate places as before.
+ * Description:     This module contains any specific code for handling
+ *                  dialog boxes such as driver/datasource options.  Both the
+ *                  ConfigDSN() and the SQLDriverConnect() functions use 
+ *                  functions in this module.  If you were to add a new option
+ *                  to any dialog box, you would most likely only have to change
+ *                  things in here rather than in 2 separate places as before.
  *
- * Classes:            none
+ * Classes:         none
  *
- * API functions:  none
+ * API functions:   none
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #endif
 
 #ifndef WIN32
-#include <string.h>
-#include "gpps.h"
-#define SQLGetPrivateProfileString(a,b,c,d,e,f) GetPrivateProfileString(a,b,c,d,e,f)
-#define SQLWritePrivateProfileString(a,b,c,d) WritePrivateProfileString(a,b,c,d)
-#ifndef HAVE_STRICMP
-#define stricmp(s1,s2)     strcasecmp(s1,s2)
-#define strnicmp(s1,s2,n)  strncasecmp(s1,s2,n)
-#endif
+# include <string.h>
+# include "gpps.h"
+# define SQLGetPrivateProfileString(a,b,c,d,e,f) GetPrivateProfileString(a,b,c,d,e,f)
+# define SQLWritePrivateProfileString(a,b,c,d) WritePrivateProfileString(a,b,c,d)
+# ifndef HAVE_STRICMP
+#  define stricmp(s1,s2)      strcasecmp(s1,s2)
+#  define strnicmp(s1,s2,n)   strncasecmp(s1,s2,n)
+# endif
 #endif
 
 #include "dlg_specific.h"
@@ -49,13 +50,8 @@ extern GLOBAL_VALUES globals;
 void
 SetDlgStuff(HWND hdlg, ConnInfo *ci)
 {
-
-   /*
-    * If driver attribute NOT present, then set the datasource name and
-    * description
-    */
-   if (ci->driver[0] == '\0')
-   {
+   /*  If driver attribute NOT present, then set the datasource name and description */
+   if (ci->driver[0] == '\0') {
        SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);
        SetDlgItemText(hdlg, IDC_DESC, ci->desc);
    }
@@ -67,7 +63,7 @@ SetDlgStuff(HWND hdlg, ConnInfo *ci)
    SetDlgItemText(hdlg, IDC_PORT, ci->port);
 }
 
-void
+void 
 GetDlgStuff(HWND hdlg, ConnInfo *ci)
 {
    GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc));
@@ -81,294 +77,296 @@ GetDlgStuff(HWND hdlg, ConnInfo *ci)
 
 
 
-int            CALLBACK
-driver_optionsProc(HWND hdlg,
-                  WORD wMsg,
-                  WPARAM wParam,
-                  LPARAM lParam)
+int CALLBACK driver_optionsProc(HWND   hdlg,
+                           WORD   wMsg,
+                           WPARAM wParam,
+                           LPARAM lParam)
 {
-   switch (wMsg)
-   {
-           case WM_INITDIALOG:
-
-           CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
-           CheckDlgButton(hdlg, DRV_OPTIMIZER, globals.disable_optimizer);
-           CheckDlgButton(hdlg, DRV_KSQO, globals.ksqo);
-           CheckDlgButton(hdlg, DRV_UNIQUEINDEX, globals.unique_index);
-           CheckDlgButton(hdlg, DRV_READONLY, globals.onlyread);
-           CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, globals.use_declarefetch);
-
-           /* Unknown (Default) Data Type sizes */
-           switch (globals.unknown_sizes)
-           {
-               case UNKNOWNS_AS_DONTKNOW:
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
-                   break;
-               case UNKNOWNS_AS_LONGEST:
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
-                   break;
-               case UNKNOWNS_AS_MAX:
-               default:
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
-                   break;
-           }
+   switch (wMsg) {
+   case WM_INITDIALOG:
+
+       CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
+       CheckDlgButton(hdlg, DRV_OPTIMIZER, globals.disable_optimizer);
+       CheckDlgButton(hdlg, DRV_KSQO, globals.ksqo);
+       CheckDlgButton(hdlg, DRV_UNIQUEINDEX, globals.unique_index);
+       CheckDlgButton(hdlg, DRV_READONLY, globals.onlyread);
+       CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, globals.use_declarefetch);
+
+       /*  Unknown (Default) Data Type sizes */
+       switch(globals.unknown_sizes) {
+       case UNKNOWNS_AS_DONTKNOW:
+           CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
+           break;
+       case UNKNOWNS_AS_LONGEST:
+           CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
+           break;
+       case UNKNOWNS_AS_MAX:
+       default:
+           CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
+           break;
+       }
 
-           CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, globals.text_as_longvarchar);
-           CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, globals.unknowns_as_longvarchar);
-           CheckDlgButton(hdlg, DRV_BOOLS_CHAR, globals.bools_as_char);
+       CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, globals.text_as_longvarchar);
+       CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, globals.unknowns_as_longvarchar);
+       CheckDlgButton(hdlg, DRV_BOOLS_CHAR, globals.bools_as_char);
 
-           CheckDlgButton(hdlg, DRV_PARSE, globals.parse);
+       CheckDlgButton(hdlg, DRV_PARSE, globals.parse);
 
-           CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, globals.cancel_as_freestmt);
+       CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, globals.cancel_as_freestmt);
 
-           SetDlgItemInt(hdlg, DRV_CACHE_SIZE, globals.fetch_max, FALSE);
-           SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, globals.max_varchar_size, FALSE);
-           SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, globals.max_longvarchar_size, TRUE);
+       SetDlgItemInt(hdlg, DRV_CACHE_SIZE, globals.fetch_max, FALSE);
+       SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, globals.max_varchar_size, FALSE);
+       SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, globals.max_longvarchar_size, TRUE);
 
-           SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes);
+       SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes);
 
-           /* Driver Connection Settings */
-           SetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings);
+       /*  Driver Connection Settings */
+       SetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings);
 
-           break;
+       break; 
+
+   case WM_COMMAND:
+       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
+       case IDOK:
 
-       case WM_COMMAND:
-           switch (GET_WM_COMMAND_ID(wParam, lParam))
-           {
-               case IDOK:
-
-                   globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
-                   globals.disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
-                   globals.ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
-                   globals.unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
-                   globals.onlyread = IsDlgButtonChecked(hdlg, DRV_READONLY);
-                   globals.use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);
-
-                   /* Unknown (Default) Data Type sizes */
-                   if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))
-                       globals.unknown_sizes = UNKNOWNS_AS_MAX;
-                   else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))
-                       globals.unknown_sizes = UNKNOWNS_AS_DONTKNOW;
-                   else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))
-                       globals.unknown_sizes = UNKNOWNS_AS_LONGEST;
-                   else
-                       globals.unknown_sizes = UNKNOWNS_AS_MAX;
-
-                   globals.text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);
-                   globals.unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);
-                   globals.bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);
-
-                   globals.parse = IsDlgButtonChecked(hdlg, DRV_PARSE);
-
-                   globals.cancel_as_freestmt = IsDlgButtonChecked(hdlg, DRV_CANCELASFREESTMT);
-
-                   globals.fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
-                   globals.max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
-                   globals.max_longvarchar_size = GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE);       /* allows for
-                                                                                                                * SQL_NO_TOTAL */
-
-                   GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, sizeof(globals.extra_systable_prefixes));
-
-                   /* Driver Connection Settings */
-                   GetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings, sizeof(globals.conn_settings));
-
-                   updateGlobals();
-
-                   /* fall through */
-
-               case IDCANCEL:
-                   EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
-                   return TRUE;
-
-               case IDDEFAULTS:
-                   CheckDlgButton(hdlg, DRV_COMMLOG, DEFAULT_COMMLOG);
-                   CheckDlgButton(hdlg, DRV_OPTIMIZER, DEFAULT_OPTIMIZER);
-                   CheckDlgButton(hdlg, DRV_KSQO, DEFAULT_KSQO);
-                   CheckDlgButton(hdlg, DRV_UNIQUEINDEX, DEFAULT_UNIQUEINDEX);
-                   CheckDlgButton(hdlg, DRV_READONLY, DEFAULT_READONLY);
-                   CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, DEFAULT_USEDECLAREFETCH);
-
-                   CheckDlgButton(hdlg, DRV_PARSE, DEFAULT_PARSE);
-                   CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, DEFAULT_CANCELASFREESTMT);
-
-                   /* Unknown Sizes */
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
-                   CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
-                   switch (DEFAULT_UNKNOWNSIZES)
-                   {
-                       case UNKNOWNS_AS_DONTKNOW:
-                           CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
-                           break;
-                       case UNKNOWNS_AS_LONGEST:
-                           CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
-                           break;
-                       case UNKNOWNS_AS_MAX:
-                           CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
-                           break;
-                   }
-
-                   CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, DEFAULT_TEXTASLONGVARCHAR);
-                   CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, DEFAULT_UNKNOWNSASLONGVARCHAR);
-                   CheckDlgButton(hdlg, DRV_BOOLS_CHAR, DEFAULT_BOOLSASCHAR);
-
-                   SetDlgItemInt(hdlg, DRV_CACHE_SIZE, FETCH_MAX, FALSE);
-                   SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, MAX_VARCHAR_SIZE, FALSE);
-                   SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, TEXT_FIELD_SIZE, TRUE);
-
-                   SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, DEFAULT_EXTRASYSTABLEPREFIXES);
-
-                   /* Driver Connection Settings */
-                   SetDlgItemText(hdlg, DRV_CONNSETTINGS, "");
-
-                   break;
+           globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
+           globals.disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
+           globals.ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
+           globals.unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);
+           globals.onlyread = IsDlgButtonChecked(hdlg, DRV_READONLY);
+           globals.use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);
+
+           /*  Unknown (Default) Data Type sizes */
+           if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))
+               globals.unknown_sizes = UNKNOWNS_AS_MAX;
+           else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))
+               globals.unknown_sizes = UNKNOWNS_AS_DONTKNOW;
+           else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))
+               globals.unknown_sizes = UNKNOWNS_AS_LONGEST;
+           else
+               globals.unknown_sizes = UNKNOWNS_AS_MAX;
+
+           globals.text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);
+           globals.unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);
+           globals.bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);
+
+           globals.parse = IsDlgButtonChecked(hdlg, DRV_PARSE);
+
+           globals.cancel_as_freestmt = IsDlgButtonChecked(hdlg, DRV_CANCELASFREESTMT);
+
+           globals.fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);
+           globals.max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);
+           globals.max_longvarchar_size= GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE);    /* allows for SQL_NO_TOTAL */
+
+           GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, sizeof(globals.extra_systable_prefixes));
+
+           /*  Driver Connection Settings */
+           GetDlgItemText(hdlg, DRV_CONNSETTINGS, globals.conn_settings, sizeof(globals.conn_settings));
+
+           updateGlobals();
+
+           /*  fall through */
+
+       case IDCANCEL:
+           EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
+           return TRUE;
+
+       case IDDEFAULTS:
+           CheckDlgButton(hdlg, DRV_COMMLOG, DEFAULT_COMMLOG);
+           CheckDlgButton(hdlg, DRV_OPTIMIZER, DEFAULT_OPTIMIZER);
+           CheckDlgButton(hdlg, DRV_KSQO, DEFAULT_KSQO);
+           CheckDlgButton(hdlg, DRV_UNIQUEINDEX, DEFAULT_UNIQUEINDEX);
+           CheckDlgButton(hdlg, DRV_READONLY, DEFAULT_READONLY);
+           CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, DEFAULT_USEDECLAREFETCH);
+   
+           CheckDlgButton(hdlg, DRV_PARSE, DEFAULT_PARSE);
+           CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, DEFAULT_CANCELASFREESTMT);
+
+           /*  Unknown Sizes */
+           CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);
+           CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);
+           CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);
+           switch(DEFAULT_UNKNOWNSIZES) {
+           case UNKNOWNS_AS_DONTKNOW:
+               CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);
+               break;
+           case UNKNOWNS_AS_LONGEST:
+               CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);
+               break;
+           case UNKNOWNS_AS_MAX:
+               CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);
+               break;
            }
+
+           CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, DEFAULT_TEXTASLONGVARCHAR);
+           CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, DEFAULT_UNKNOWNSASLONGVARCHAR);
+           CheckDlgButton(hdlg, DRV_BOOLS_CHAR, DEFAULT_BOOLSASCHAR);
+
+           SetDlgItemInt(hdlg, DRV_CACHE_SIZE, FETCH_MAX, FALSE);
+           SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, MAX_VARCHAR_SIZE, FALSE);
+           SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, TEXT_FIELD_SIZE, TRUE);
+
+           SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, DEFAULT_EXTRASYSTABLEPREFIXES);
+
+           /*  Driver Connection Settings */
+           SetDlgItemText(hdlg, DRV_CONNSETTINGS, "");
+
+           break;
+       }
+
    }
 
    return FALSE;
 }
 
-int            CALLBACK
-ds_optionsProc(HWND hdlg,
-              WORD wMsg,
-              WPARAM wParam,
-              LPARAM lParam)
+int CALLBACK ds_optionsProc(HWND   hdlg,
+                           WORD   wMsg,
+                           WPARAM wParam,
+                           LPARAM lParam)
 {
-   ConnInfo   *ci;
-   char        buf[128];
-
-   switch (wMsg)
-   {
-       case WM_INITDIALOG:
-           ci = (ConnInfo *) lParam;
-           SetWindowLong(hdlg, DWL_USER, lParam);      /* save for OK */
-
-           /* Change window caption */
-           if (ci->driver[0])
-               SetWindowText(hdlg, "Advanced Options (Connection)");
-           else
-           {
-               sprintf(buf, "Advanced Options (%s)", ci->dsn);
-               SetWindowText(hdlg, buf);
-           }
-
-           /* Readonly */
-           CheckDlgButton(hdlg, DS_READONLY, atoi(ci->onlyread));
-
-           /* Protocol */
+ConnInfo *ci;
+char buf[128];
+
+   switch (wMsg) {
+   case WM_INITDIALOG:
+       ci = (ConnInfo *) lParam;       
+       SetWindowLong(hdlg, DWL_USER, lParam);  /* save for OK */
+
+       /*  Change window caption */
+       if (ci->driver[0])
+           SetWindowText(hdlg, "Advanced Options (Connection)");
+       else {
+           sprintf(buf, "Advanced Options (%s)", ci->dsn);
+           SetWindowText(hdlg, buf);
+       }
+
+       /*  Readonly */
+       CheckDlgButton(hdlg, DS_READONLY, atoi(ci->onlyread));
+
+       /*  Protocol */
+       if (strncmp(ci->protocol, PG62, strlen(PG62)) == 0)
+           CheckDlgButton(hdlg, DS_PG62, 1);
+       else if (strncmp(ci->protocol, PG63, strlen(PG63)) == 0)
+           CheckDlgButton(hdlg, DS_PG63, 1);
+       else /* latest */
            CheckDlgButton(hdlg, DS_PG64, 1);
 
 
 
-           CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
-           CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
-           CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
-           CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
+       CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
+       CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
+       CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
+       CheckDlgButton(hdlg, DS_SHOWSYSTEMTABLES, atoi(ci->show_system_tables));
 
-           EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
+       EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
 
-           /* Datasource Connection Settings */
-           SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
-           break;
+       /*  Datasource Connection Settings */
+       SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
+       break; 
 
 
-       case WM_COMMAND:
-           switch (GET_WM_COMMAND_ID(wParam, lParam))
-           {
-               case DS_SHOWOIDCOLUMN:
-                   mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
-                   EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
-                   return TRUE;
+   case WM_COMMAND:
+       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
+       case DS_SHOWOIDCOLUMN:
+           mylog("WM_COMMAND: DS_SHOWOIDCOLUMN\n");
+           EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
+           return TRUE;
 
 
-               case IDOK:
+       case IDOK: 
 
-                   ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
-                   mylog("IDOK: got ci = %u\n", ci);
+           ci = (ConnInfo *)GetWindowLong(hdlg, DWL_USER);
+           mylog("IDOK: got ci = %u\n", ci);
 
-                   /* Readonly */
-                   sprintf(ci->onlyread, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
+           /*  Readonly */
+           sprintf(ci->onlyread, "%d", IsDlgButtonChecked(hdlg, DS_READONLY));
 
-                   /* Protocol */
-                   strcpy(ci->protocol, PG64);
+           /*  Protocol */
+           if ( IsDlgButtonChecked(hdlg, DS_PG62))
+               strcpy(ci->protocol, PG62);
+           else if ( IsDlgButtonChecked(hdlg, DS_PG63))
+               strcpy(ci->protocol, PG63);
+           else    /* latest */
+               strcpy(ci->protocol, PG64);
 
-                   sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
+           sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
 
-                   sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
+           sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
 
-                   /* OID Options */
-                   sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
-                   sprintf(ci->show_oid_column, "%d", IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
+           /*  OID Options*/
+           sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
+           sprintf(ci->show_oid_column, "%d", IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
 
-                   /* Datasource Connection Settings */
-                   GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
+           /*  Datasource Connection Settings */
+           GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
 
 
-                   /* fall through */
+           /*  fall through */
 
-               case IDCANCEL:
-                   EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
-                   return TRUE;
-           }
+       case IDCANCEL:
+           EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
+           return TRUE;
+       }
    }
 
    return FALSE;
 }
 
-#endif  /* WIN32 */
+#endif /* WIN32 */
 
 void
 makeConnectString(char *connect_string, ConnInfo *ci)
 {
-   char        got_dsn = (ci->dsn[0] != '\0');
-   char        encoded_conn_settings[LARGE_REGISTRY_LEN];
+char got_dsn = (ci->dsn[0] != '\0');
+char encoded_conn_settings[LARGE_REGISTRY_LEN];
 
-   /* fundamental info */
+   /*  fundamental info */
    sprintf(connect_string, "%s=%s;DATABASE=%s;SERVER=%s;PORT=%s;UID=%s;PWD=%s",
-           got_dsn ? "DSN" : "DRIVER",
-           got_dsn ? ci->dsn : ci->driver,
-           ci->database,
-           ci->server,
-           ci->port,
-           ci->username,
-           ci->password);
+       got_dsn ? "DSN" : "DRIVER", 
+       got_dsn ? ci->dsn : ci->driver,
+       ci->database,
+       ci->server,
+       ci->port,
+       ci->username,
+       ci->password);
 
    encode(ci->conn_settings, encoded_conn_settings);
 
-   /* extra info */
-   sprintf(&connect_string[strlen(connect_string)],
-           ";READONLY=%s;PROTOCOL=%s;FAKEOIDINDEX=%s;SHOWOIDCOLUMN=%s;ROWVERSIONING=%s;SHOWSYSTEMTABLES=%s;CONNSETTINGS=%s",
-           ci->onlyread,
-           ci->protocol,
-           ci->fake_oid_index,
-           ci->show_oid_column,
-           ci->row_versioning,
-           ci->show_system_tables,
-           encoded_conn_settings);
+   /*  extra info */
+   sprintf(&connect_string[strlen(connect_string)], 
+       ";READONLY=%s;PROTOCOL=%s;FAKEOIDINDEX=%s;SHOWOIDCOLUMN=%s;ROWVERSIONING=%s;SHOWSYSTEMTABLES=%s;CONNSETTINGS=%s", 
+       ci->onlyread,
+       ci->protocol,
+       ci->fake_oid_index,
+       ci->show_oid_column,
+       ci->row_versioning,
+       ci->show_system_tables,
+       encoded_conn_settings);
 }
 
 void
 copyAttributes(ConnInfo *ci, char *attribute, char *value)
 {
-   if (stricmp(attribute, "DSN") == 0)
+
+   if(stricmp(attribute, "DSN") == 0)
        strcpy(ci->dsn, value);
 
-   else if (stricmp(attribute, "driver") == 0)
+   else if(stricmp(attribute, "driver") == 0)
        strcpy(ci->driver, value);
 
-   else if (stricmp(attribute, INI_DATABASE) == 0)
+   else if(stricmp(attribute, INI_DATABASE) == 0)
        strcpy(ci->database, value);
 
-   else if (stricmp(attribute, INI_SERVER) == 0 || stricmp(attribute, "server") == 0)
+   else if(stricmp(attribute, INI_SERVER) == 0 || stricmp(attribute, "server") == 0)
        strcpy(ci->server, value);
 
-   else if (stricmp(attribute, INI_USER) == 0 || stricmp(attribute, "uid") == 0)
+   else if(stricmp(attribute, INI_USER) == 0 || stricmp(attribute, "uid") == 0)
        strcpy(ci->username, value);
 
-   else if (stricmp(attribute, INI_PASSWORD) == 0 || stricmp(attribute, "pwd") == 0)
+   else if(stricmp(attribute, INI_PASSWORD) == 0 || stricmp(attribute, "pwd") == 0)
        strcpy(ci->password, value);
 
-   else if (stricmp(attribute, INI_PORT) == 0)
+   else if(stricmp(attribute, INI_PORT) == 0)
        strcpy(ci->port, value);
 
    else if (stricmp(attribute, INI_READONLY) == 0)
@@ -389,13 +387,13 @@ copyAttributes(ConnInfo *ci, char *attribute, char *value)
    else if (stricmp(attribute, INI_SHOWSYSTEMTABLES) == 0)
        strcpy(ci->show_system_tables, value);
 
-   else if (stricmp(attribute, INI_CONNSETTINGS) == 0)
-   {
+   else if (stricmp(attribute, INI_CONNSETTINGS) == 0) {
        decode(value, ci->conn_settings);
        /* strcpy(ci->conn_settings, value); */
    }
 
-   mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s', conn_settings='%s')\n", ci->dsn, ci->server, ci->database, ci->username, ci->password, ci->port, ci->onlyread, ci->protocol, ci->conn_settings);
+   mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s', conn_settings='%s')\n", ci->dsn, ci->server,ci->database,ci->username,ci->password,ci->port,ci->onlyread,ci->protocol,ci->conn_settings);
+
 }
 
 void
@@ -424,99 +422,97 @@ getDSNdefaults(ConnInfo *ci)
 }
 
 
-void
+void 
 getDSNinfo(ConnInfo *ci, char overwrite)
 {
-   char       *DSN = ci->dsn;
-   char        encoded_conn_settings[LARGE_REGISTRY_LEN];
+char *DSN = ci->dsn;
+char encoded_conn_settings[LARGE_REGISTRY_LEN];
 
 /* If a driver keyword was present, then dont use a DSN and return. */
 /* If DSN is null and no driver, then use the default datasource. */
-   if (DSN[0] == '\0')
-   {
-       if (ci->driver[0] != '\0')
+   if ( DSN[0] == '\0') {
+       if ( ci->driver[0] != '\0')
            return;
        else
            strcpy(DSN, INI_DSN);
    }
 
    /* brute-force chop off trailing blanks... */
-   while (*(DSN + strlen(DSN) - 1) == ' ')
-       *(DSN + strlen(DSN) - 1) = '\0';
+   while (*(DSN+strlen(DSN)-1) == ' ') *(DSN+strlen(DSN)-1) = '\0';
 
-   /* Proceed with getting info for the given DSN. */
+   /*  Proceed with getting info for the given DSN. */
 
-   if (ci->desc[0] == '\0' || overwrite)
+   if ( ci->desc[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_KDESC, "", ci->desc, sizeof(ci->desc), ODBC_INI);
 
-   if (ci->server[0] == '\0' || overwrite)
+   if ( ci->server[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_SERVER, "", ci->server, sizeof(ci->server), ODBC_INI);
 
-   if (ci->database[0] == '\0' || overwrite)
-       SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);
+   if ( ci->database[0] == '\0' || overwrite)
+       SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);
 
-   if (ci->username[0] == '\0' || overwrite)
+   if ( ci->username[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_USER, "", ci->username, sizeof(ci->username), ODBC_INI);
 
-   if (ci->password[0] == '\0' || overwrite)
+   if ( ci->password[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_PASSWORD, "", ci->password, sizeof(ci->password), ODBC_INI);
 
-   if (ci->port[0] == '\0' || overwrite)
+   if ( ci->port[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);
 
-   if (ci->onlyread[0] == '\0' || overwrite)
+   if ( ci->onlyread[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->onlyread, sizeof(ci->onlyread), ODBC_INI);
 
-   if (ci->show_oid_column[0] == '\0' || overwrite)
+   if ( ci->show_oid_column[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_SHOWOIDCOLUMN, "", ci->show_oid_column, sizeof(ci->show_oid_column), ODBC_INI);
 
-   if (ci->fake_oid_index[0] == '\0' || overwrite)
+   if ( ci->fake_oid_index[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_FAKEOIDINDEX, "", ci->fake_oid_index, sizeof(ci->fake_oid_index), ODBC_INI);
 
-   if (ci->row_versioning[0] == '\0' || overwrite)
+   if ( ci->row_versioning[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_ROWVERSIONING, "", ci->row_versioning, sizeof(ci->row_versioning), ODBC_INI);
 
-   if (ci->show_system_tables[0] == '\0' || overwrite)
+   if ( ci->show_system_tables[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);
 
-   if (ci->protocol[0] == '\0' || overwrite)
+   if ( ci->protocol[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
 
-   if (ci->conn_settings[0] == '\0' || overwrite)
-   {
+   if ( ci->conn_settings[0] == '\0' || overwrite) {
        SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_conn_settings, sizeof(encoded_conn_settings), ODBC_INI);
        decode(encoded_conn_settings, ci->conn_settings);
    }
 
-   if (ci->translation_dll[0] == '\0' || overwrite)
+   if ( ci->translation_dll[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_TRANSLATIONDLL, "", ci->translation_dll, sizeof(ci->translation_dll), ODBC_INI);
 
-   if (ci->translation_option[0] == '\0' || overwrite)
+   if ( ci->translation_option[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
 
 
-   /* Allow override of odbcinst.ini parameters here */
+   /*  Allow override of odbcinst.ini parameters here */
    getGlobalDefaults(DSN, ODBC_INI, TRUE);
 
 
-   qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
-        DSN,
-        ci->server,
-        ci->port,
-        ci->database,
-        ci->username,
-        ci->password);
+   qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n", 
+       DSN, 
+       ci->server,
+       ci->port,
+       ci->database,
+       ci->username,
+       ci->password);
    qlog("          onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
-        ci->onlyread,
-        ci->protocol,
-        ci->show_oid_column,
-        ci->fake_oid_index,
-        ci->show_system_tables);
+       ci->onlyread,
+       ci->protocol,
+       ci->show_oid_column,
+       ci->fake_oid_index,
+       ci->show_system_tables);
    qlog("          conn_settings='%s'\n",
-        ci->conn_settings);
+       ci->conn_settings);
    qlog("          translation_dll='%s',translation_option='%s'\n",
-        ci->translation_dll,
-        ci->translation_option);
+       ci->translation_dll,
+       ci->translation_option);
+
 }
 
 
@@ -524,358 +520,347 @@ getDSNinfo(ConnInfo *ci, char overwrite)
 void
 writeDSNinfo(ConnInfo *ci)
 {
-   char       *DSN = ci->dsn;
-   char        encoded_conn_settings[LARGE_REGISTRY_LEN];
+char *DSN = ci->dsn;
+char encoded_conn_settings[LARGE_REGISTRY_LEN];
+
+       encode(ci->conn_settings, encoded_conn_settings);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_KDESC,
+           ci->desc,
+           ODBC_INI);
+                        
+       SQLWritePrivateProfileString(DSN,
+           INI_DATABASE,
+           ci->database,
+           ODBC_INI);
+                        
+       SQLWritePrivateProfileString(DSN,
+           INI_SERVER,
+           ci->server,
+           ODBC_INI);
 
-   encode(ci->conn_settings, encoded_conn_settings);
+       SQLWritePrivateProfileString(DSN,
+           INI_PORT,
+           ci->port,
+           ODBC_INI);
 
-   SQLWritePrivateProfileString(DSN,
-                                INI_KDESC,
-                                ci->desc,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_DATABASE,
-                                ci->database,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_SERVER,
-                                ci->server,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_PORT,
-                                ci->port,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_USER,
-                                ci->username,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_PASSWORD,
-                                ci->password,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_READONLY,
-                                ci->onlyread,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_SHOWOIDCOLUMN,
-                                ci->show_oid_column,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_FAKEOIDINDEX,
-                                ci->fake_oid_index,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_ROWVERSIONING,
-                                ci->row_versioning,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_SHOWSYSTEMTABLES,
-                                ci->show_system_tables,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_PROTOCOL,
-                                ci->protocol,
-                                ODBC_INI);
-
-   SQLWritePrivateProfileString(DSN,
-                                INI_CONNSETTINGS,
-                                encoded_conn_settings,
-                                ODBC_INI);
+       SQLWritePrivateProfileString(DSN,
+           INI_USER,
+           ci->username,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_PASSWORD,
+           ci->password,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_READONLY,
+           ci->onlyread,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_SHOWOIDCOLUMN,
+           ci->show_oid_column,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_FAKEOIDINDEX,
+           ci->fake_oid_index,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_ROWVERSIONING,
+           ci->row_versioning,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_SHOWSYSTEMTABLES,
+           ci->show_system_tables,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_PROTOCOL,
+           ci->protocol,
+           ODBC_INI);
+
+       SQLWritePrivateProfileString(DSN,
+           INI_CONNSETTINGS,
+           encoded_conn_settings,
+           ODBC_INI);
 }
 
 
 /* This function reads the ODBCINST.INI portion of
    the registry and gets any driver defaults.
 */
-void
-getGlobalDefaults(char *section, char *filename, char override)
+void getGlobalDefaults(char *section, char *filename, char override)
 {
-   char        temp[256];
+char temp[256];
 
 
-   /* Fetch Count is stored in driver section */
-   SQLGetPrivateProfileString(section, INI_FETCH, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
-   {
+    /* Fetch Count is stored in driver section */
+    SQLGetPrivateProfileString(section, INI_FETCH, "",
+                            temp, sizeof(temp), filename);
+   if ( temp[0] ) {
        globals.fetch_max = atoi(temp);
-       /* sanity check if using cursors */
+       /*  sanity check if using cursors */
        if (globals.fetch_max <= 0)
            globals.fetch_max = FETCH_MAX;
    }
-   else if (!override)
+   else if ( ! override)
        globals.fetch_max = FETCH_MAX;
 
 
-   /* Socket Buffersize is stored in driver section */
-   SQLGetPrivateProfileString(section, INI_SOCKET, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Socket Buffersize is stored in driver section */
+    SQLGetPrivateProfileString(section, INI_SOCKET, "",
+                            temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.socket_buffersize = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.socket_buffersize = SOCK_BUFFER_SIZE;
 
 
-   /* Debug is stored in the driver section */
-   SQLGetPrivateProfileString(section, INI_DEBUG, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Debug is stored in the driver section */
+   SQLGetPrivateProfileString(section, INI_DEBUG, "", 
+                           temp, sizeof(temp), filename);
+   if ( temp[0] )
        globals.debug = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.debug = DEFAULT_DEBUG;
 
 
-   /* CommLog is stored in the driver section */
-   SQLGetPrivateProfileString(section, INI_COMMLOG, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  CommLog is stored in the driver section */
+   SQLGetPrivateProfileString(section, INI_COMMLOG, "", 
+                           temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.commlog = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.commlog = DEFAULT_COMMLOG;
 
 
-   /* Optimizer is stored in the driver section only */
-   SQLGetPrivateProfileString(section, INI_OPTIMIZER, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Optimizer is stored in the driver section only */
+   SQLGetPrivateProfileString(section, INI_OPTIMIZER, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.disable_optimizer = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.disable_optimizer = DEFAULT_OPTIMIZER;
 
-   /* KSQO is stored in the driver section only */
-   SQLGetPrivateProfileString(section, INI_KSQO, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  KSQO is stored in the driver section only */
+   SQLGetPrivateProfileString(section, INI_KSQO, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.ksqo = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.ksqo = DEFAULT_KSQO;
 
-   /* Recognize Unique Index is stored in the driver section only */
-   SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Recognize Unique Index is stored in the driver section only */
+   SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.unique_index = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.unique_index = DEFAULT_UNIQUEINDEX;
 
 
-   /* Unknown Sizes is stored in the driver section only */
-   SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Unknown Sizes is stored in the driver section only */
+   SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] )
        globals.unknown_sizes = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.unknown_sizes = DEFAULT_UNKNOWNSIZES;
 
 
-   /* Lie about supported functions? */
-   SQLGetPrivateProfileString(section, INI_LIE, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Lie about supported functions? */
+   SQLGetPrivateProfileString(section, INI_LIE, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.lie = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.lie = DEFAULT_LIE;
 
-   /* Parse statements */
-   SQLGetPrivateProfileString(section, INI_PARSE, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Parse statements */
+   SQLGetPrivateProfileString(section, INI_PARSE, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.parse = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.parse = DEFAULT_PARSE;
 
-   /* SQLCancel calls SQLFreeStmt in Driver Manager */
-   SQLGetPrivateProfileString(section, INI_CANCELASFREESTMT, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  SQLCancel calls SQLFreeStmt in Driver Manager */
+   SQLGetPrivateProfileString(section, INI_CANCELASFREESTMT, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.cancel_as_freestmt = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
 
 
 
-   /* UseDeclareFetch is stored in the driver section only */
-   SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  UseDeclareFetch is stored in the driver section only */
+   SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.use_declarefetch = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.use_declarefetch = DEFAULT_USEDECLAREFETCH;
 
 
-   /* Max Varchar Size */
-   SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Max Varchar Size */
+   SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.max_varchar_size = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.max_varchar_size = MAX_VARCHAR_SIZE;
 
-   /* Max TextField Size */
-   SQLGetPrivateProfileString(section, INI_MAXLONGVARCHARSIZE, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Max TextField Size */
+   SQLGetPrivateProfileString(section, INI_MAXLONGVARCHARSIZE, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.max_longvarchar_size = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.max_longvarchar_size = TEXT_FIELD_SIZE;
 
-   /* Text As LongVarchar  */
-   SQLGetPrivateProfileString(section, INI_TEXTASLONGVARCHAR, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Text As LongVarchar  */
+   SQLGetPrivateProfileString(section, INI_TEXTASLONGVARCHAR, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.text_as_longvarchar = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;
 
-   /* Unknowns As LongVarchar  */
-   SQLGetPrivateProfileString(section, INI_UNKNOWNSASLONGVARCHAR, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Unknowns As LongVarchar  */
+   SQLGetPrivateProfileString(section, INI_UNKNOWNSASLONGVARCHAR, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.unknowns_as_longvarchar = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;
 
-   /* Bools As Char */
-   SQLGetPrivateProfileString(section, INI_BOOLSASCHAR, "",
-                              temp, sizeof(temp), filename);
-   if (temp[0])
+   /*  Bools As Char */
+   SQLGetPrivateProfileString(section, INI_BOOLSASCHAR, "", 
+               temp, sizeof(temp), filename);
+   if ( temp[0] ) 
        globals.bools_as_char = atoi(temp);
-   else if (!override)
+   else if ( ! override)
        globals.bools_as_char = DEFAULT_BOOLSASCHAR;
 
-   /* Extra Systable prefixes */
-
-   /*
-    * Use @@@ to distinguish between blank extra prefixes and no key
-    * entry
-    */
-   SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@",
-                              temp, sizeof(temp), filename);
-   if (strcmp(temp, "@@@"))
+   /*  Extra Systable prefixes */
+   /*  Use @@@ to distinguish between blank extra prefixes and no key entry */
+   SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@", 
+           temp, sizeof(temp), filename);
+   if ( strcmp(temp, "@@@" ))  
        strcpy(globals.extra_systable_prefixes, temp);
-   else if (!override)
+   else if ( ! override)
        strcpy(globals.extra_systable_prefixes, DEFAULT_EXTRASYSTABLEPREFIXES);
 
    mylog("globals.extra_systable_prefixes = '%s'\n", globals.extra_systable_prefixes);
 
 
-   /* Dont allow override of an override! */
-   if (!override)
-   {
+   /*  Dont allow override of an override! */
+   if ( ! override) {
 
-       /*
-        * ConnSettings is stored in the driver section and per datasource
-        * for override
-        */
-       SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "",
-        globals.conn_settings, sizeof(globals.conn_settings), filename);
+       /*  ConnSettings is stored in the driver section and per datasource for override */
+       SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "", 
+                   globals.conn_settings, sizeof(globals.conn_settings), filename);
 
-       /* Default state for future DSN's Readonly attribute */
-       SQLGetPrivateProfileString(section, INI_READONLY, "",
-                                  temp, sizeof(temp), filename);
-       if (temp[0])
+       /*  Default state for future DSN's Readonly attribute */
+       SQLGetPrivateProfileString(section, INI_READONLY, "", 
+                   temp, sizeof(temp), filename);
+       if ( temp[0] ) 
            globals.onlyread = atoi(temp);
        else
            globals.onlyread = DEFAULT_READONLY;
 
-       /*
-        * Default state for future DSN's protocol attribute This isn't a
-        * real driver option YET.  This is more intended for
-        * customization from the install.
-        */
-       SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
-                                  temp, sizeof(temp), filename);
-       if (strcmp(temp, "@@@"))
+       /*  Default state for future DSN's protocol attribute
+           This isn't a real driver option YET.  This is more
+           intended for customization from the install.
+       */
+       SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@", 
+               temp, sizeof(temp), filename);
+       if ( strcmp(temp, "@@@" ))  
            strcpy(globals.protocol, temp);
-       else
+       else 
            strcpy(globals.protocol, DEFAULT_PROTOCOL);
+   
    }
 }
 
 
 /* This function writes any global parameters (that can be manipulated)
-   to the ODBCINST.INI portion of the registry
+   to the ODBCINST.INI portion of the registry 
 */
-void
-updateGlobals(void)
+void updateGlobals(void)
 {
-   char        tmp[128];
+char tmp[128];
 
    sprintf(tmp, "%d", globals.fetch_max);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_FETCH, tmp, ODBCINST_INI);
+       INI_FETCH, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.commlog);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_COMMLOG, tmp, ODBCINST_INI);
+       INI_COMMLOG, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.disable_optimizer);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_OPTIMIZER, tmp, ODBCINST_INI);
+       INI_OPTIMIZER, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.ksqo);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_KSQO, tmp, ODBCINST_INI);
+       INI_KSQO, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.unique_index);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_UNIQUEINDEX, tmp, ODBCINST_INI);
+       INI_UNIQUEINDEX, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.onlyread);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_READONLY, tmp, ODBCINST_INI);
+       INI_READONLY, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.use_declarefetch);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_USEDECLAREFETCH, tmp, ODBCINST_INI);
+       INI_USEDECLAREFETCH, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.unknown_sizes);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_UNKNOWNSIZES, tmp, ODBCINST_INI);
+       INI_UNKNOWNSIZES, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.text_as_longvarchar);
    SQLWritePrivateProfileString(DBMS_NAME,
-                              INI_TEXTASLONGVARCHAR, tmp, ODBCINST_INI);
+       INI_TEXTASLONGVARCHAR, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.unknowns_as_longvarchar);
    SQLWritePrivateProfileString(DBMS_NAME,
-                          INI_UNKNOWNSASLONGVARCHAR, tmp, ODBCINST_INI);
+       INI_UNKNOWNSASLONGVARCHAR, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.bools_as_char);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_BOOLSASCHAR, tmp, ODBCINST_INI);
+       INI_BOOLSASCHAR, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.parse);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_PARSE, tmp, ODBCINST_INI);
+       INI_PARSE, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.cancel_as_freestmt);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_CANCELASFREESTMT, tmp, ODBCINST_INI);
+       INI_CANCELASFREESTMT, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.max_varchar_size);
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_MAXVARCHARSIZE, tmp, ODBCINST_INI);
+       INI_MAXVARCHARSIZE, tmp, ODBCINST_INI);
 
    sprintf(tmp, "%d", globals.max_longvarchar_size);
    SQLWritePrivateProfileString(DBMS_NAME,
-                             INI_MAXLONGVARCHARSIZE, tmp, ODBCINST_INI);
+       INI_MAXLONGVARCHARSIZE, tmp, ODBCINST_INI);
 
    SQLWritePrivateProfileString(DBMS_NAME,
-                                INI_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, ODBCINST_INI);
+       INI_EXTRASYSTABLEPREFIXES, globals.extra_systable_prefixes, ODBCINST_INI);
 
    SQLWritePrivateProfileString(DBMS_NAME,
-                 INI_CONNSETTINGS, globals.conn_settings, ODBCINST_INI);
+       INI_CONNSETTINGS, globals.conn_settings, ODBCINST_INI);
 }
index 3d493089540728883b4d0fb4479436c81cab6285..5be8b4fa50801acec880dc19f0ac0feb59e79b61 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           dlg_specific.h
+/* File:            dlg_specific.h
  *
- * Description:        See "dlg_specific.c"
+ * Description:     See "dlg_specific.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 
 /* INI File Stuff */
 #ifndef WIN32
-#define ODBC_INI           ".odbc.ini"
-#ifdef ODBCINSTDIR
-#define ODBCINST_INI       ODBCINSTDIR "/odbcinst.ini"
-#else
-#define ODBCINST_INI       "/etc/odbcinst.ini"
-#warning "location of odbcinst.ini file defaulted to /etc"
-#endif
-#else                          /* WIN32 */
-#define ODBC_INI           "ODBC.INI"  /* ODBC initialization file */
-#define ODBCINST_INI       "ODBCINST.INI"      /* ODBC Installation file */
-#endif  /* WIN32 */
-
-
-#define INI_DSN                DBMS_NAME   /* Name of default Datasource in
-                                        * ini file (not used?) */
-#define INI_KDESC          "Description"       /* Data source description */
-#define INI_SERVER         "Servername"        /* Name of Server running
-                                                * the Postgres service */
-#define INI_PORT           "Port"      /* Port on which the Postmaster is
-                                        * listening */
-#define INI_DATABASE       "Database"  /* Database Name */
-#define INI_USER           "Username"  /* Default User Name */
-#define INI_PASSWORD       "Password"  /* Default Password */
-#define INI_DEBUG          "Debug"     /* Debug flag */
-#define INI_FETCH          "Fetch"     /* Fetch Max Count */
-#define INI_SOCKET         "Socket"    /* Socket buffer size */
-#define INI_READONLY       "ReadOnly"  /* Database is read only */
-#define INI_COMMLOG            "CommLog"   /* Communication to backend
-                                        * logging */
-#define INI_PROTOCOL       "Protocol"  /* What protocol (6.2) */
-#define INI_OPTIMIZER      "Optimizer" /* Use backend genetic optimizer */
-#define INI_KSQO           "Ksqo"      /* Keyset query optimization */
-#define INI_CONNSETTINGS   "ConnSettings"      /* Anything to send to
-                                                * backend on successful
-                                                * connection */
-#define INI_UNIQUEINDEX        "UniqueIndex"       /* Recognize unique
-                                                * indexes */
-#define INI_UNKNOWNSIZES   "UnknownSizes"      /* How to handle unknown
-                                                * result set sizes */
-
-#define INI_CANCELASFREESTMT   "CancelAsFreeStmt"
-
-#define INI_USEDECLAREFETCH "UseDeclareFetch"  /* Use Declare/Fetch
-                                                * cursors */
+# define ODBC_INI        ".odbc.ini"
+# ifdef ODBCINSTDIR
+#  define ODBCINST_INI    ODBCINSTDIR "/odbcinst.ini"
+# else
+#  define ODBCINST_INI    "/etc/odbcinst.ini"
+#  warning "location of odbcinst.ini file defaulted to /etc"
+# endif
+#else /* WIN32 */
+# define ODBC_INI        "ODBC.INI"         /* ODBC initialization file */
+# define ODBCINST_INI    "ODBCINST.INI"     /* ODBC Installation file */
+#endif /* WIN32 */
+
+
+#define INI_DSN           DBMS_NAME         /* Name of default Datasource in ini file (not used?) */
+#define INI_KDESC         "Description"     /* Data source description */
+#define INI_SERVER        "Servername"      /* Name of Server running the Postgres service */
+#define INI_PORT          "Port"            /* Port on which the Postmaster is listening */ 
+#define INI_DATABASE      "Database"        /* Database Name */
+#define INI_USER          "Username"        /* Default User Name */
+#define INI_PASSWORD      "Password"       /* Default Password */
+#define INI_DEBUG         "Debug"          /* Debug flag */
+#define INI_FETCH         "Fetch"          /* Fetch Max Count */
+#define INI_SOCKET        "Socket"         /* Socket buffer size */
+#define INI_READONLY      "ReadOnly"       /* Database is read only */
+#define INI_COMMLOG       "CommLog"            /* Communication to backend logging */
+#define INI_PROTOCOL      "Protocol"       /* What protocol (6.2) */
+#define INI_OPTIMIZER     "Optimizer"      /* Use backend genetic optimizer */
+#define INI_KSQO          "Ksqo"            /* Keyset query optimization */
+#define INI_CONNSETTINGS  "ConnSettings"   /* Anything to send to backend on successful connection */
+#define INI_UNIQUEINDEX   "UniqueIndex"        /* Recognize unique indexes */
+#define INI_UNKNOWNSIZES  "UnknownSizes"   /* How to handle unknown result set sizes */
+
+#define INI_CANCELASFREESTMT  "CancelAsFreeStmt"
+
+#define INI_USEDECLAREFETCH "UseDeclareFetch"      /* Use Declare/Fetch cursors */
 
 /* More ini stuff */
 #define INI_TEXTASLONGVARCHAR      "TextAsLongVarchar"
 #define INI_PARSE                  "Parse"
 #define INI_EXTRASYSTABLEPREFIXES  "ExtraSysTablePrefixes"
 
-#define INI_TRANSLATIONNAME            "TranslationName"
-#define INI_TRANSLATIONDLL         "TranslationDLL"
-#define INI_TRANSLATIONOPTION      "TranslationOption"
+#define INI_TRANSLATIONNAME       "TranslationName"
+#define INI_TRANSLATIONDLL        "TranslationDLL"
+#define INI_TRANSLATIONOPTION     "TranslationOption"
 
 
 /* Connection Defaults */
 #define DEFAULT_PORT                   "5432"
 #define DEFAULT_READONLY               1
-#define DEFAULT_PROTOCOL               "6.4"   /* the latest protocol is
-                                                * the default */
+#define DEFAULT_PROTOCOL               "6.4"       /* the latest protocol is the default */
 #define DEFAULT_USEDECLAREFETCH            0
 #define DEFAULT_TEXTASLONGVARCHAR      1
 #define DEFAULT_UNKNOWNSASLONGVARCHAR  0
 
 #define DEFAULT_EXTRASYSTABLEPREFIXES  "dd_;"
 
-/* prototypes */
-void       getGlobalDefaults(char *section, char *filename, char override);
+/*  prototypes */
+void getGlobalDefaults(char *section, char *filename, char override);
 
 #ifdef WIN32
-void       SetDlgStuff(HWND hdlg, ConnInfo *ci);
-void       GetDlgStuff(HWND hdlg, ConnInfo *ci);
-
-int CALLBACK driver_optionsProc(HWND hdlg,
-                  WORD wMsg,
-                  WPARAM wParam,
-                  LPARAM lParam);
-int CALLBACK ds_optionsProc(HWND hdlg,
-              WORD wMsg,
-              WPARAM wParam,
-              LPARAM lParam);
-
-#endif  /* WIN32 */
-
-void       updateGlobals(void);
-void       writeDSNinfo(ConnInfo *ci);
-void       getDSNdefaults(ConnInfo *ci);
-void       getDSNinfo(ConnInfo *ci, char overwrite);
-void       makeConnectString(char *connect_string, ConnInfo *ci);
-void       copyAttributes(ConnInfo *ci, char *attribute, char *value);
+void SetDlgStuff(HWND hdlg, ConnInfo *ci);
+void GetDlgStuff(HWND hdlg, ConnInfo *ci);
+
+int CALLBACK driver_optionsProc(HWND   hdlg,
+                           WORD   wMsg,
+                           WPARAM wParam,
+                           LPARAM lParam);
+int CALLBACK ds_optionsProc(HWND   hdlg,
+                           WORD   wMsg,
+                           WPARAM wParam,
+                           LPARAM lParam);
+#endif /* WIN32 */
+
+void updateGlobals(void);
+void writeDSNinfo(ConnInfo *ci);
+void getDSNdefaults(ConnInfo *ci);
+void getDSNinfo(ConnInfo *ci, char overwrite);
+void makeConnectString(char *connect_string, ConnInfo *ci);
+void copyAttributes(ConnInfo *ci, char *attribute, char *value);
 
 
 #endif
index 4204913e0b319beb56739faf5184045795387ad0..2cbe6e6a87a639be1148f75d0bcc32d2fec222b6 100644 (file)
@@ -1,13 +1,14 @@
-/* Module:         drvconn.c
+
+/* Module:          drvconn.c
  *
- * Description:        This module contains only routines related to
- *                 implementing SQLDriverConnect.
+ * Description:     This module contains only routines related to 
+ *                  implementing SQLDriverConnect.
  *
- * Classes:            n/a
+ * Classes:         n/a
  *
- * API functions:  SQLDriverConnect
+ * API functions:   SQLDriverConnect
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #include "dlg_specific.h"
 
 /* prototypes */
-void       dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
+void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci);
 
 #ifdef WIN32
 BOOL FAR PASCAL dconn_FDriverConnectProc(HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
-RETCODE        dconn_DoDialog(HWND hwnd, ConnInfo *ci);
-
-extern HINSTANCE NEAR s_hModule;/* Saved module handle. */
+RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci);
 
+extern HINSTANCE NEAR s_hModule;               /* Saved module handle. */
 #endif
 
 extern GLOBAL_VALUES globals;
 
 
-RETCODE SQL_API
-SQLDriverConnect(
-                HDBC hdbc,
-                HWND hwnd,
-                UCHAR FAR *szConnStrIn,
-                SWORD cbConnStrIn,
-                UCHAR FAR *szConnStrOut,
-                SWORD cbConnStrOutMax,
-                SWORD FAR *pcbConnStrOut,
-                UWORD fDriverCompletion)
+RETCODE SQL_API SQLDriverConnect(
+                                 HDBC      hdbc,
+                                 HWND      hwnd,
+                                 UCHAR FAR *szConnStrIn,
+                                 SWORD     cbConnStrIn,
+                                 UCHAR FAR *szConnStrOut,
+                                 SWORD     cbConnStrOutMax,
+                                 SWORD FAR *pcbConnStrOut,
+                                 UWORD     fDriverCompletion)
 {
-   static char *func = "SQLDriverConnect";
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   ConnInfo   *ci;
-
+static char *func = "SQLDriverConnect";
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+ConnInfo *ci;
 #ifdef WIN32
-   RETCODE     dialog_result;
-
+RETCODE dialog_result;
 #endif
-   RETCODE     result;
-   char        connStrIn[MAX_CONNECT_STRING];
-   char        connStrOut[MAX_CONNECT_STRING];
-   int         retval;
-   char        password_required = FALSE;
-   int         len = 0;
+RETCODE result;
+char connStrIn[MAX_CONNECT_STRING];
+char connStrOut[MAX_CONNECT_STRING];
+int retval;
+char password_required = FALSE;
+int len = 0;
 
 
    mylog("%s: entering...\n", func);
 
-   if (!conn)
-   {
+   if ( ! conn) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
@@ -107,17 +103,17 @@ SQLDriverConnect(
 
    ci = &(conn->connInfo);
 
-   /* Parse the connect string and fill in conninfo for this hdbc. */
+   /*  Parse the connect string and fill in conninfo for this hdbc. */
    dconn_get_connect_attributes(connStrIn, ci);
 
-   /* If the ConnInfo in the hdbc is missing anything, */
-   /* this function will fill them in from the registry (assuming */
-   /* of course there is a DSN given -- if not, it does nothing!) */
+   /*  If the ConnInfo in the hdbc is missing anything, */
+   /*  this function will fill them in from the registry (assuming */
+   /*  of course there is a DSN given -- if not, it does nothing!) */
    getDSNinfo(ci, CONN_DONT_OVERWRITE);
 
-   /* Fill in any default parameters if they are not there. */
+   /*  Fill in any default parameters if they are not there. */
    getDSNdefaults(ci);
-   /* initialize pg_version */
+   /*  initialize pg_version */
    CC_initialize_pg_version(conn);
 
 #ifdef WIN32
@@ -125,53 +121,51 @@ dialog:
 #endif
    ci->focus_password = password_required;
 
-   switch (fDriverCompletion)
-   {
+   switch(fDriverCompletion) {
 #ifdef WIN32
-       case SQL_DRIVER_PROMPT:
-           dialog_result = dconn_DoDialog(hwnd, ci);
-           if (dialog_result != SQL_SUCCESS)
-               return dialog_result;
-           break;
+   case SQL_DRIVER_PROMPT:
+       dialog_result = dconn_DoDialog(hwnd, ci);
+       if(dialog_result != SQL_SUCCESS) {
+           return dialog_result;
+       }
+       break;
+
+   case SQL_DRIVER_COMPLETE_REQUIRED:
 
-       case SQL_DRIVER_COMPLETE_REQUIRED:
+       /*  Fall through */
 
-           /* Fall through */
+   case SQL_DRIVER_COMPLETE:
 
-       case SQL_DRIVER_COMPLETE:
+       /* Password is not a required parameter. */
+       if( ci->username[0] == '\0' ||
+           ci->server[0] == '\0' ||
+           ci->database[0] == '\0' ||
+           ci->port[0] == '\0' ||
+           password_required) { 
 
-           /* Password is not a required parameter. */
-           if (ci->username[0] == '\0' ||
-               ci->server[0] == '\0' ||
-               ci->database[0] == '\0' ||
-               ci->port[0] == '\0' ||
-               password_required)
-           {
-               dialog_result = dconn_DoDialog(hwnd, ci);
-               if (dialog_result != SQL_SUCCESS)
-                   return dialog_result;
+           dialog_result = dconn_DoDialog(hwnd, ci);
+           if(dialog_result != SQL_SUCCESS) {
+               return dialog_result;
            }
-           break;
+       }
+       break;
 #else
-       case SQL_DRIVER_PROMPT:
-       case SQL_DRIVER_COMPLETE:
-       case SQL_DRIVER_COMPLETE_REQUIRED:
+   case SQL_DRIVER_PROMPT:
+   case SQL_DRIVER_COMPLETE:
+   case SQL_DRIVER_COMPLETE_REQUIRED:
 #endif
-       case SQL_DRIVER_NOPROMPT:
-           break;
+   case SQL_DRIVER_NOPROMPT:
+       break;
    }
 
-   /*
-    * Password is not a required parameter unless authentication asks for
-    * it. For now, I think it's better to just let the application ask
-    * over and over until a password is entered (the user can always hit
-    * Cancel to get out)
-    */
-   if (ci->username[0] == '\0' ||
+   /*  Password is not a required parameter unless authentication asks for it.
+       For now, I think it's better to just let the application ask over and over until
+       a password is entered (the user can always hit Cancel to get out)
+   */
+   if( ci->username[0] == '\0' ||
        ci->server[0] == '\0' ||
-       ci->database[0] == '\0' ||
-       ci->port[0] == '\0')
-   {
+       ci->database[0] == '\0' || 
+       ci->port[0] == '\0') {
 /*     (password_required && ci->password[0] == '\0')) */
 
        return SQL_NO_DATA_FOUND;
@@ -180,16 +174,12 @@ dialog:
 
    /* do the actual connect */
    retval = CC_connect(conn, password_required);
-   if (retval < 0)
-   {                           /* need a password */
-       if (fDriverCompletion == SQL_DRIVER_NOPROMPT)
-       {
+   if (retval < 0) {       /* need a password */
+       if (fDriverCompletion == SQL_DRIVER_NOPROMPT) {
            CC_log_error(func, "Need password but Driver_NoPrompt", conn);
-           return SQL_ERROR;   /* need a password but not allowed to
-                                * prompt so error */
+           return SQL_ERROR;   /* need a password but not allowed to prompt so error */
        }
-       else
-       {
+       else {
 #ifdef WIN32
            password_required = TRUE;
            goto dialog;
@@ -198,44 +188,39 @@ dialog:
 #endif
        }
    }
-   else if (retval == 0)
-   {
-       /* error msg filled in above */
+   else if (retval == 0) {
+       /*  error msg filled in above */
        CC_log_error(func, "Error from CC_Connect", conn);
        return SQL_ERROR;
    }
 
    /*********************************************/
-   /* Create the Output Connection String   */
+   /*     Create the Output Connection String   */
    /*********************************************/
    result = SQL_SUCCESS;
 
    makeConnectString(connStrOut, ci);
    len = strlen(connStrOut);
 
-   if (szConnStrOut)
-   {
-
-       /*
-        * Return the completed string to the caller. The correct method
-        * is to only construct the connect string if a dialog was put up,
-        * otherwise, it should just copy the connection input string to
-        * the output. However, it seems ok to just always construct an
-        * output string.  There are possible bad side effects on working
-        * applications (Access) by implementing the correct behavior,
-        * anyway.
-        */
+   if(szConnStrOut) {
+
+       /*  Return the completed string to the caller. The correct method is to 
+           only construct the connect string if a dialog was put up, otherwise, 
+           it should just copy the connection input string to the output.  
+           However, it seems ok to just always construct an output string.  There
+           are possible bad side effects on working applications (Access) by 
+           implementing the correct behavior, anyway. 
+       */
        strncpy_null(szConnStrOut, connStrOut, cbConnStrOutMax);
 
-       if (len >= cbConnStrOutMax)
-       {
+       if (len >= cbConnStrOutMax) {
            result = SQL_SUCCESS_WITH_INFO;
            conn->errornumber = CONN_TRUNCATED;
            conn->errormsg = "The buffer was too small for the result.";
        }
    }
 
-   if (pcbConnStrOut)
+   if(pcbConnStrOut)
        *pcbConnStrOut = len;
 
    mylog("szConnStrOut = '%s'\n", szConnStrOut);
@@ -247,117 +232,108 @@ dialog:
 }
 
 #ifdef WIN32
-RETCODE
-dconn_DoDialog(HWND hwnd, ConnInfo *ci)
+RETCODE dconn_DoDialog(HWND hwnd, ConnInfo *ci)
 {
-   int         dialog_result;
+int dialog_result;
 
-   mylog("dconn_DoDialog: ci = %u\n", ci);
+mylog("dconn_DoDialog: ci = %u\n", ci);
 
-   if (hwnd)
-   {
+   if(hwnd) {
        dialog_result = DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_CONFIG),
-                           hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
-       if (!dialog_result || (dialog_result == -1))
+                                   hwnd, dconn_FDriverConnectProc, (LPARAM) ci);
+       if(!dialog_result || (dialog_result == -1)) {
            return SQL_NO_DATA_FOUND;
-       else
+       } else {
            return SQL_SUCCESS;
+       }
    }
 
    return SQL_ERROR;
 }
 
 
-BOOL FAR   PASCAL
-dconn_FDriverConnectProc(
-                        HWND hdlg,
-                        UINT wMsg,
-                        WPARAM wParam,
-                        LPARAM lParam)
+BOOL FAR PASCAL dconn_FDriverConnectProc(
+                                         HWND    hdlg,
+                                         UINT    wMsg,
+                                         WPARAM  wParam,
+                                         LPARAM  lParam)
 {
-   ConnInfo   *ci;
+ConnInfo *ci;
 
-   switch (wMsg)
-   {
-       case WM_INITDIALOG:
-           ci = (ConnInfo *) lParam;
+   switch (wMsg) {
+   case WM_INITDIALOG:
+       ci = (ConnInfo *) lParam;       
 
-           /* Change the caption for the setup dialog */
-           SetWindowText(hdlg, "PostgreSQL Connection");
+       /*  Change the caption for the setup dialog */
+       SetWindowText(hdlg, "PostgreSQL Connection");
 
-           SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
+       SetWindowText(GetDlgItem(hdlg, IDC_DATASOURCE), "Connection");
 
-           /* Hide the DSN and description fields */
-           ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
-           ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
-           ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
-           ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
+       /*  Hide the DSN and description fields */
+       ShowWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), SW_HIDE);
+       ShowWindow(GetDlgItem(hdlg, IDC_DSNAME), SW_HIDE);
+       ShowWindow(GetDlgItem(hdlg, IDC_DESCTEXT), SW_HIDE);
+       ShowWindow(GetDlgItem(hdlg, IDC_DESC), SW_HIDE);
 
-           SetWindowLong(hdlg, DWL_USER, lParam);      /* Save the ConnInfo for
-                                                        * the "OK" */
+       SetWindowLong(hdlg, DWL_USER, lParam);/* Save the ConnInfo for the "OK" */
 
-           SetDlgStuff(hdlg, ci);
+       SetDlgStuff(hdlg, ci);
 
-           if (ci->database[0] == '\0')
-               ;               /* default focus */
-           else if (ci->server[0] == '\0')
-               SetFocus(GetDlgItem(hdlg, IDC_SERVER));
-           else if (ci->port[0] == '\0')
-               SetFocus(GetDlgItem(hdlg, IDC_PORT));
-           else if (ci->username[0] == '\0')
-               SetFocus(GetDlgItem(hdlg, IDC_USER));
-           else if (ci->focus_password)
-               SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
+       if (ci->database[0] == '\0')        
+           ;   /* default focus */
+       else if (ci->server[0] == '\0')
+           SetFocus(GetDlgItem(hdlg, IDC_SERVER));
+       else if (ci->port[0] == '\0')
+           SetFocus(GetDlgItem(hdlg, IDC_PORT));
+       else if (ci->username[0] == '\0')
+           SetFocus(GetDlgItem(hdlg, IDC_USER));
+       else if (ci->focus_password)
+           SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
 
 
-           break;
+       break; 
 
-       case WM_COMMAND:
-           switch (GET_WM_COMMAND_ID(wParam, lParam))
-           {
-               case IDOK:
+   case WM_COMMAND:
+       switch (GET_WM_COMMAND_ID(wParam, lParam)) {
+       case IDOK:
 
-                   ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
+           ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
 
-                   GetDlgStuff(hdlg, ci);
+           GetDlgStuff(hdlg, ci);
 
 
-               case IDCANCEL:
-                   EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
-                   return TRUE;
+       case IDCANCEL:
+           EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
+           return TRUE;
 
-               case IDC_DRIVER:
+       case IDC_DRIVER:
 
-                   DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
-                               hdlg, driver_optionsProc, (LPARAM) NULL);
+           DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
+                                   hdlg, driver_optionsProc, (LPARAM) NULL);
 
 
-                   break;
+           break;
 
-               case IDC_DATASOURCE:
+       case IDC_DATASOURCE:
 
-                   ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
-                   DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
-                                  hdlg, ds_optionsProc, (LPARAM) ci);
+           ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
+           DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
+                                   hdlg, ds_optionsProc, (LPARAM) ci);
 
-                   break;
-           }
+           break;
+       }
    }
 
    return FALSE;
 }
 
-#endif  /* WIN32 */
+#endif /* WIN32 */
 
-void
-dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
+void dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
 {
-   char       *our_connect_string;
-   char       *pair,
-              *attribute,
-              *value,
-              *equals;
-   char       *strtok_arg;
+char *our_connect_string;
+char *pair, *attribute, *value, *equals;
+char *strtok_arg;
 
    memset(ci, 0, sizeof(ConnInfo));
 
@@ -366,31 +342,34 @@ dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
 
    mylog("our_connect_string = '%s'\n", our_connect_string);
 
-   while (1)
-   {
+   while(1) {
        pair = strtok(strtok_arg, ";");
-       if (strtok_arg)
+       if(strtok_arg) {
            strtok_arg = 0;
-       if (!pair)
+       }
+       if(!pair) {
            break;
+       }
 
        equals = strchr(pair, '=');
-       if (!equals)
+       if ( ! equals)
            continue;
 
        *equals = '\0';
-       attribute = pair;       /* ex. DSN */
-       value = equals + 1;     /* ex. 'CEO co1' */
+       attribute = pair;       /*  ex. DSN */
+       value = equals + 1;     /*  ex. 'CEO co1' */
 
        mylog("attribute = '%s', value = '%s'\n", attribute, value);
 
-       if (!attribute || !value)
-           continue;
+       if!attribute || !value)
+           continue;          
 
-       /* Copy the appropriate value to the conninfo  */
+       /*  Copy the appropriate value to the conninfo  */
        copyAttributes(ci, attribute, value);
+
    }
 
 
    free(our_connect_string);
 }
+
index d0353531c0dcc4784a55b0c66d10ea4e007dbe7f..080a8026d5e6947dc0c3f855766596f467951426 100644 (file)
@@ -1,14 +1,15 @@
-/* Module:         environ.c
+
+/* Module:          environ.c
  *
- * Description:        This module contains routines related to
- *                 the environment, such as storing connection handles,
- *                 and returning errors.
+ * Description:     This module contains routines related to 
+ *                  the environment, such as storing connection handles,
+ *                  and returning errors.
  *
- * Classes:            EnvironmentClass (Functions prefix: "EN_")
+ * Classes:         EnvironmentClass (Functions prefix: "EN_")
  *
- * API functions:  SQLAllocEnv, SQLFreeEnv, SQLError
+ * API functions:   SQLAllocEnv, SQLFreeEnv, SQLError
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 ConnectionClass *conns[MAX_CONNECTIONS];
 
 
-RETCODE SQL_API
-SQLAllocEnv(HENV FAR *phenv)
+RETCODE SQL_API SQLAllocEnv(HENV FAR *phenv)
 {
-   static char *func = "SQLAllocEnv";
+static char *func = "SQLAllocEnv";
 
-   mylog("**** in SQLAllocEnv ** \n");
+mylog("**** in SQLAllocEnv ** \n");
 
    *phenv = (HENV) EN_Constructor();
-   if (!*phenv)
-   {
+   if ( ! *phenv) {
        *phenv = SQL_NULL_HENV;
        EN_log_error(func, "Error allocating environment", NULL);
        return SQL_ERROR;
    }
-
    mylog("** exit SQLAllocEnv: phenv = %u **\n", *phenv);
    return SQL_SUCCESS;
 }
 
-RETCODE SQL_API
-SQLFreeEnv(HENV henv)
+RETCODE SQL_API SQLFreeEnv(HENV henv)
 {
-   static char *func = "SQLFreeEnv";
-   EnvironmentClass *env = (EnvironmentClass *) henv;
+static char *func = "SQLFreeEnv";
+EnvironmentClass *env = (EnvironmentClass *) henv;
 
-   mylog("**** in SQLFreeEnv: env = %u ** \n", env);
+mylog("**** in SQLFreeEnv: env = %u ** \n", env);
 
-   if (env && EN_Destructor(env))
-   {
+   if (env && EN_Destructor(env)) {
        mylog("   ok\n");
        return SQL_SUCCESS;
    }
@@ -60,345 +57,321 @@ SQLFreeEnv(HENV henv)
    return SQL_ERROR;
 }
 
-/*     Returns the next SQL error information. */
-
-RETCODE SQL_API
-SQLError(
-        HENV henv,
-        HDBC hdbc,
-        HSTMT hstmt,
-        UCHAR FAR *szSqlState,
-        SDWORD FAR *pfNativeError,
-        UCHAR FAR *szErrorMsg,
-        SWORD cbErrorMsgMax,
-        SWORD FAR *pcbErrorMsg)
+/*      Returns the next SQL error information. */
+
+RETCODE SQL_API SQLError(
+        HENV       henv,
+        HDBC       hdbc,
+        HSTMT      hstmt,
+        UCHAR  FAR *szSqlState,
+        SDWORD FAR *pfNativeError,
+        UCHAR  FAR *szErrorMsg,
+        SWORD      cbErrorMsgMax,
+        SWORD  FAR *pcbErrorMsg)
 {
-   char       *msg;
-   int         status;
-
+char *msg;
+int status;
+    
    mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u\n", henv, hdbc, hstmt);
 
-   if (SQL_NULL_HSTMT != hstmt)
-   {
-       /* CC: return an error of a hstmt  */
-       StatementClass *stmt = (StatementClass *) hstmt;
-
-       if (SC_get_error(stmt, &status, &msg))
-       {
+    if (SQL_NULL_HSTMT != hstmt) {
+   /* CC: return an error of a hstmt  */
+        StatementClass *stmt = (StatementClass *) hstmt;
+        
+        if (SC_get_error(stmt, &status, &msg)) {
            mylog("SC_get_error: status = %d, msg = #%s#\n", status, msg);
-           if (NULL == msg)
-           {
-               if (NULL != szSqlState)
-                   strcpy(szSqlState, "00000");
-               if (NULL != pcbErrorMsg)
-                   *pcbErrorMsg = 0;
-               if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-                   szErrorMsg[0] = '\0';
-
-               return SQL_NO_DATA_FOUND;
-           }
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = (SWORD) strlen(msg);
-
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
-
-           if (NULL != pfNativeError)
-               *pfNativeError = status;
-
-           if (NULL != szSqlState)
-
-               switch (status)
-               {
-                       /* now determine the SQLSTATE to be returned */
-                   case STMT_TRUNCATED:
-                       strcpy(szSqlState, "01004");
-                       /* data truncated */
-                       break;
-                   case STMT_INFO_ONLY:
-                       strcpy(szSqlState, "00000");
-                       /* just information that is returned, no error */
-                       break;
-                   case STMT_BAD_ERROR:
-                       strcpy(szSqlState, "08S01");
-                       /* communication link failure */
-                       break;
-                   case STMT_CREATE_TABLE_ERROR:
-                       strcpy(szSqlState, "S0001");
-                       /* table already exists */
-                       break;
-                   case STMT_STATUS_ERROR:
-                   case STMT_SEQUENCE_ERROR:
-                       strcpy(szSqlState, "S1010");
-                       /* Function sequence error */
-                       break;
-                   case STMT_NO_MEMORY_ERROR:
-                       strcpy(szSqlState, "S1001");
-                       /* memory allocation failure */
-                       break;
-                   case STMT_COLNUM_ERROR:
-                       strcpy(szSqlState, "S1002");
-                       /* invalid column number */
-                       break;
-                   case STMT_NO_STMTSTRING:
-                       strcpy(szSqlState, "S1001");
-                       /* having no stmtstring is also a malloc problem */
-                       break;
-                   case STMT_ERROR_TAKEN_FROM_BACKEND:
-                       strcpy(szSqlState, "S1000");
-                       /* general error */
-                       break;
-                   case STMT_INTERNAL_ERROR:
-                       strcpy(szSqlState, "S1000");
-                       /* general error */
-                       break;
-                   case STMT_ROW_OUT_OF_RANGE:
-                       strcpy(szSqlState, "S1107");
-                       break;
-
-                   case STMT_OPERATION_CANCELLED:
-                       strcpy(szSqlState, "S1008");
-                       break;
-
-                   case STMT_NOT_IMPLEMENTED_ERROR:
-                       strcpy(szSqlState, "S1C00");    /* == 'driver not
-                                                        * capable' */
-                       break;
-                   case STMT_OPTION_OUT_OF_RANGE_ERROR:
-                       strcpy(szSqlState, "S1092");
-                       break;
-                   case STMT_BAD_PARAMETER_NUMBER_ERROR:
-                       strcpy(szSqlState, "S1093");
-                       break;
-                   case STMT_INVALID_COLUMN_NUMBER_ERROR:
-                       strcpy(szSqlState, "S1002");
-                       break;
-                   case STMT_RESTRICTED_DATA_TYPE_ERROR:
-                       strcpy(szSqlState, "07006");
-                       break;
-                   case STMT_INVALID_CURSOR_STATE_ERROR:
-                       strcpy(szSqlState, "24000");
-                       break;
-                   case STMT_OPTION_VALUE_CHANGED:
-                       strcpy(szSqlState, "01S02");
-                       break;
-                   case STMT_INVALID_CURSOR_NAME:
-                       strcpy(szSqlState, "34000");
-                       break;
-                   case STMT_NO_CURSOR_NAME:
-                       strcpy(szSqlState, "S1015");
-                       break;
-                   case STMT_INVALID_ARGUMENT_NO:
-                       strcpy(szSqlState, "S1009");
-                       /* invalid argument value */
-                       break;
-                   case STMT_INVALID_CURSOR_POSITION:
-                       strcpy(szSqlState, "S1109");
-                       break;
-
-                   case STMT_VALUE_OUT_OF_RANGE:
-                       strcpy(szSqlState, "22003");
-                       break;
-
-                   case STMT_OPERATION_INVALID:
-                       strcpy(szSqlState, "S1011");
-                       break;
-
-                   case STMT_EXEC_ERROR:
-                   default:
-                       strcpy(szSqlState, "S1000");
-                       /* also a general error */
-                       break;
-               }
-
-           mylog("       szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
-       }
-       else
-       {
-           if (NULL != szSqlState)
-               strcpy(szSqlState, "00000");
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = 0;
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               szErrorMsg[0] = '\0';
-
+            if (NULL == msg) {
+                if (NULL != szSqlState)
+                    strcpy(szSqlState, "00000");
+                if (NULL != pcbErrorMsg)
+                    *pcbErrorMsg = 0;
+                if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                    szErrorMsg[0] = '\0';
+                
+                return SQL_NO_DATA_FOUND;
+            }                
+            if (NULL != pcbErrorMsg)                
+                *pcbErrorMsg = (SWORD)strlen(msg);
+            
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
+                strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
+            
+            if (NULL != pfNativeError) 
+                *pfNativeError = status;
+            
+            if (NULL != szSqlState)    
+                
+                switch (status) {
+       /* now determine the SQLSTATE to be returned */
+                case STMT_TRUNCATED:
+                    strcpy(szSqlState, "01004");
+                    /* data truncated */
+                    break;
+                case STMT_INFO_ONLY:
+                    strcpy(szSqlState, "00000");
+                    /* just information that is returned, no error */
+                    break;
+                case STMT_BAD_ERROR:
+                    strcpy(szSqlState, "08S01");
+                    /* communication link failure */
+                    break;
+                case STMT_CREATE_TABLE_ERROR:
+                    strcpy(szSqlState, "S0001");
+                    /* table already exists */
+                    break;
+                case STMT_STATUS_ERROR:
+                case STMT_SEQUENCE_ERROR:
+                    strcpy(szSqlState, "S1010");
+                    /* Function sequence error */
+                    break;
+                case STMT_NO_MEMORY_ERROR:
+                    strcpy(szSqlState, "S1001");
+                    /* memory allocation failure */
+                    break;
+                case STMT_COLNUM_ERROR:
+                    strcpy(szSqlState, "S1002");
+                    /* invalid column number */
+                    break;
+                case STMT_NO_STMTSTRING:
+                    strcpy(szSqlState, "S1001");
+                    /* having no stmtstring is also a malloc problem */
+                    break;
+                case STMT_ERROR_TAKEN_FROM_BACKEND:
+                    strcpy(szSqlState, "S1000");
+                    /* general error */
+                    break;
+                case STMT_INTERNAL_ERROR:
+                    strcpy(szSqlState, "S1000");
+                    /* general error */
+                    break;  
+               case STMT_ROW_OUT_OF_RANGE:
+                   strcpy(szSqlState, "S1107");
+                   break;
+
+               case STMT_OPERATION_CANCELLED:
+                   strcpy(szSqlState, "S1008");
+                   break;
+
+                case STMT_NOT_IMPLEMENTED_ERROR:
+                    strcpy(szSqlState, "S1C00"); /* == 'driver not capable' */
+                    break;
+                case STMT_OPTION_OUT_OF_RANGE_ERROR:
+                    strcpy(szSqlState, "S1092");
+                    break;
+                case STMT_BAD_PARAMETER_NUMBER_ERROR:
+                    strcpy(szSqlState, "S1093");
+                    break;
+                case STMT_INVALID_COLUMN_NUMBER_ERROR:
+                    strcpy(szSqlState, "S1002");
+                    break;
+                case STMT_RESTRICTED_DATA_TYPE_ERROR:
+                    strcpy(szSqlState, "07006");
+                    break;
+                case STMT_INVALID_CURSOR_STATE_ERROR:
+                    strcpy(szSqlState, "24000");
+                    break;
+                case STMT_OPTION_VALUE_CHANGED:
+                    strcpy(szSqlState, "01S02");
+                    break;
+               case STMT_INVALID_CURSOR_NAME:
+                    strcpy(szSqlState, "34000");
+                    break;
+               case STMT_NO_CURSOR_NAME:
+                    strcpy(szSqlState, "S1015");
+                    break;
+                case STMT_INVALID_ARGUMENT_NO:
+                    strcpy(szSqlState, "S1009");
+                    /* invalid argument value */
+                    break;
+               case STMT_INVALID_CURSOR_POSITION:
+                    strcpy(szSqlState, "S1109");
+                    break;
+                
+               case STMT_VALUE_OUT_OF_RANGE:
+                   strcpy(szSqlState, "22003");
+                   break;
+
+               case STMT_OPERATION_INVALID:
+                   strcpy(szSqlState, "S1011");
+                   break;
+
+               case STMT_EXEC_ERROR:
+               default:
+                    strcpy(szSqlState, "S1000");
+                    /* also a general error */
+                    break;
+                }         
+
+               mylog("       szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
+            
+        } else {
+            if (NULL != szSqlState)
+                strcpy(szSqlState, "00000");
+            if (NULL != pcbErrorMsg)
+                *pcbErrorMsg = 0;
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                szErrorMsg[0] = '\0';
+            
            mylog("       returning NO_DATA_FOUND\n");
-           return SQL_NO_DATA_FOUND;
-       }
-       return SQL_SUCCESS;
-   }
-   else if (SQL_NULL_HDBC != hdbc)
-   {
-       ConnectionClass *conn = (ConnectionClass *) hdbc;
-
+            return SQL_NO_DATA_FOUND;
+        }
+        return SQL_SUCCESS;    
+        
+    } else if (SQL_NULL_HDBC != hdbc) {
+        ConnectionClass *conn = (ConnectionClass *) hdbc;
+        
        mylog("calling CC_get_error\n");
-       if (CC_get_error(conn, &status, &msg))
-       {
+        if (CC_get_error(conn, &status, &msg)) {
            mylog("CC_get_error: status = %d, msg = #%s#\n", status, msg);
-           if (NULL == msg)
-           {
-               if (NULL != szSqlState)
-                   strcpy(szSqlState, "00000");
-               if (NULL != pcbErrorMsg)
-                   *pcbErrorMsg = 0;
-               if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-                   szErrorMsg[0] = '\0';
-
-               return SQL_NO_DATA_FOUND;
-           }
-
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = (SWORD) strlen(msg);
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
-           if (NULL != pfNativeError)
-               *pfNativeError = status;
-
-           if (NULL != szSqlState)
-               switch (status)
-               {
-                   case STMT_OPTION_VALUE_CHANGED:
-                   case CONN_OPTION_VALUE_CHANGED:
-                       strcpy(szSqlState, "01S02");
-                       break;
-                   case STMT_TRUNCATED:
-                   case CONN_TRUNCATED:
-                       strcpy(szSqlState, "01004");
-                       /* data truncated */
-                       break;
-                   case CONN_INIREAD_ERROR:
-                       strcpy(szSqlState, "IM002");
-                       /* data source not found */
-                       break;
-                   case CONN_OPENDB_ERROR:
-                       strcpy(szSqlState, "08001");
-                       /* unable to connect to data source */
-                       break;
-                   case CONN_INVALID_AUTHENTICATION:
-                   case CONN_AUTH_TYPE_UNSUPPORTED:
-                       strcpy(szSqlState, "28000");
-                       break;
-                   case CONN_STMT_ALLOC_ERROR:
-                       strcpy(szSqlState, "S1001");
-                       /* memory allocation failure */
-                       break;
-                   case CONN_IN_USE:
-                       strcpy(szSqlState, "S1000");
-                       /* general error */
-                       break;
-                   case CONN_UNSUPPORTED_OPTION:
-                       strcpy(szSqlState, "IM001");
-                       /* driver does not support this function */
-                   case CONN_INVALID_ARGUMENT_NO:
-                       strcpy(szSqlState, "S1009");
-                       /* invalid argument value */
-                       break;
-                   case CONN_TRANSACT_IN_PROGRES:
-                       strcpy(szSqlState, "S1010");
-
-                       /*
-                        * when the user tries to switch commit mode in a
-                        * transaction
-                        */
-                       /* -> function sequence error */
-                       break;
-                   case CONN_NO_MEMORY_ERROR:
-                       strcpy(szSqlState, "S1001");
-                       break;
-                   case CONN_NOT_IMPLEMENTED_ERROR:
-                   case STMT_NOT_IMPLEMENTED_ERROR:
-                       strcpy(szSqlState, "S1C00");
-                       break;
-
-                   case CONN_VALUE_OUT_OF_RANGE:
-                   case STMT_VALUE_OUT_OF_RANGE:
-                       strcpy(szSqlState, "22003");
-                       break;
-
-                   default:
-                       strcpy(szSqlState, "S1000");
-                       /* general error */
-                       break;
-               }
-       }
-       else
-       {
+            if (NULL == msg) {
+                if (NULL != szSqlState)
+                    strcpy(szSqlState, "00000");
+                if (NULL != pcbErrorMsg)
+                    *pcbErrorMsg = 0;
+                if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                    szErrorMsg[0] = '\0';
+                
+                return SQL_NO_DATA_FOUND;
+            }                
+            
+            if (NULL != pcbErrorMsg)
+                *pcbErrorMsg = (SWORD)strlen(msg);
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))    
+                strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
+            if (NULL != pfNativeError)    
+                *pfNativeError = status;
+            
+            if (NULL != szSqlState) 
+                switch(status) {
+               case STMT_OPTION_VALUE_CHANGED:
+               case CONN_OPTION_VALUE_CHANGED:
+                    strcpy(szSqlState, "01S02");
+                   break;
+                case STMT_TRUNCATED:
+               case CONN_TRUNCATED:
+                    strcpy(szSqlState, "01004");
+                    /* data truncated */
+                    break;
+                case CONN_INIREAD_ERROR:
+                    strcpy(szSqlState, "IM002");
+                    /* data source not found */
+                    break;
+                case CONN_OPENDB_ERROR:
+                    strcpy(szSqlState, "08001");
+                    /* unable to connect to data source */
+                    break;
+               case CONN_INVALID_AUTHENTICATION:
+               case CONN_AUTH_TYPE_UNSUPPORTED:
+                   strcpy(szSqlState, "28000");
+                   break;
+                case CONN_STMT_ALLOC_ERROR:
+                    strcpy(szSqlState, "S1001");
+                    /* memory allocation failure */
+                    break;
+                case CONN_IN_USE:
+                    strcpy(szSqlState, "S1000");
+                    /* general error */
+                    break;
+                case CONN_UNSUPPORTED_OPTION:
+                    strcpy(szSqlState, "IM001");
+                    /* driver does not support this function */
+                case CONN_INVALID_ARGUMENT_NO:
+                    strcpy(szSqlState, "S1009");
+                    /* invalid argument value */
+                    break;
+                case CONN_TRANSACT_IN_PROGRES:
+                    strcpy(szSqlState, "S1010");
+                    /* when the user tries to switch commit mode in a transaction */
+                    /* -> function sequence error */
+                    break;
+                case CONN_NO_MEMORY_ERROR:
+                    strcpy(szSqlState, "S1001");
+                    break;
+                case CONN_NOT_IMPLEMENTED_ERROR:
+               case STMT_NOT_IMPLEMENTED_ERROR:
+                    strcpy(szSqlState, "S1C00");
+                    break;
+
+               case CONN_VALUE_OUT_OF_RANGE:
+               case STMT_VALUE_OUT_OF_RANGE:
+                   strcpy(szSqlState, "22003");
+                   break;
+
+                default:
+                    strcpy(szSqlState, "S1000");
+                    /* general error */
+                    break;
+                }
+       
+        } else {
            mylog("CC_Get_error returned nothing.\n");
-           if (NULL != szSqlState)
-               strcpy(szSqlState, "00000");
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = 0;
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               szErrorMsg[0] = '\0';
-
-           return SQL_NO_DATA_FOUND;
-       }
-       return SQL_SUCCESS;
-   }
-   else if (SQL_NULL_HENV != henv)
-   {
-       EnvironmentClass *env = (EnvironmentClass *) henv;
-
-       if (EN_get_error(env, &status, &msg))
-       {
+            if (NULL != szSqlState)
+                strcpy(szSqlState, "00000");
+            if (NULL != pcbErrorMsg)
+                *pcbErrorMsg = 0;
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                szErrorMsg[0] = '\0';
+            
+            return SQL_NO_DATA_FOUND;
+        }
+        return SQL_SUCCESS;
+        
+    } else if (SQL_NULL_HENV != henv) {
+        EnvironmentClass *env = (EnvironmentClass *)henv;
+        if(EN_get_error(env, &status, &msg)) {
            mylog("EN_get_error: status = %d, msg = #%s#\n", status, msg);
-           if (NULL == msg)
-           {
-               if (NULL != szSqlState)
-                   strcpy(szSqlState, "00000");
-               if (NULL != pcbErrorMsg)
-                   *pcbErrorMsg = 0;
-               if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-                   szErrorMsg[0] = '\0';
-
-               return SQL_NO_DATA_FOUND;
-           }
-
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = (SWORD) strlen(msg);
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
-           if (NULL != pfNativeError)
-               *pfNativeError = status;
-
-           if (szSqlState)
-           {
-               switch (status)
-               {
-                   case ENV_ALLOC_ERROR:
-                       /* memory allocation failure */
-                       strcpy(szSqlState, "S1001");
-                       break;
-                   default:
-                       strcpy(szSqlState, "S1000");
-                       /* general error */
-                       break;
-               }
-           }
-       }
-       else
-       {
-           if (NULL != szSqlState)
-               strcpy(szSqlState, "00000");
-           if (NULL != pcbErrorMsg)
-               *pcbErrorMsg = 0;
-           if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-               szErrorMsg[0] = '\0';
-
-           return SQL_NO_DATA_FOUND;
-       }
-
-       return SQL_SUCCESS;
-   }
-
-   if (NULL != szSqlState)
-       strcpy(szSqlState, "00000");
-   if (NULL != pcbErrorMsg)
-       *pcbErrorMsg = 0;
-   if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
-       szErrorMsg[0] = '\0';
-
-   return SQL_NO_DATA_FOUND;
+            if (NULL == msg) {
+                if (NULL != szSqlState)
+                    strcpy(szSqlState, "00000");
+                if (NULL != pcbErrorMsg)
+                    *pcbErrorMsg = 0;
+                if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                    szErrorMsg[0] = '\0';
+
+                return SQL_NO_DATA_FOUND;
+            }                
+
+            if (NULL != pcbErrorMsg)                
+                *pcbErrorMsg = (SWORD)strlen(msg);
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
+                strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
+            if (NULL != pfNativeError) 
+                *pfNativeError = status;
+            
+            if(szSqlState) {
+                switch(status) {
+                case ENV_ALLOC_ERROR:
+           /* memory allocation failure */
+                    strcpy(szSqlState, "S1001");
+                    break;
+                default:
+                    strcpy(szSqlState, "S1000");
+                    /* general error */
+                    break;
+                }
+            }
+        } else {
+            if (NULL != szSqlState)
+                strcpy(szSqlState, "00000");
+            if (NULL != pcbErrorMsg)
+                *pcbErrorMsg = 0;
+            if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+                szErrorMsg[0] = '\0';
+            
+            return SQL_NO_DATA_FOUND;
+        }
+
+        return SQL_SUCCESS;
+    }
+    
+    if (NULL != szSqlState)
+        strcpy(szSqlState, "00000");
+    if (NULL != pcbErrorMsg)
+        *pcbErrorMsg = 0;
+    if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) 
+        szErrorMsg[0] = '\0';
+    
+    return SQL_NO_DATA_FOUND;
 }
 
 
@@ -410,27 +383,25 @@ SQLError(
 
 
 EnvironmentClass
-          *
-EN_Constructor(void)
+*EN_Constructor(void)
 {
-   EnvironmentClass *rv;
+EnvironmentClass *rv;
 
-   rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
-   if (rv)
-   {
+    rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
+    if( rv) {
        rv->errormsg = 0;
        rv->errornumber = 0;
    }
 
-   return rv;
+    return rv;
 }
 
 
 char
 EN_Destructor(EnvironmentClass *self)
 {
-   int         lf;
-   char        rv = 1;
+int lf;
+char rv = 1;
 
    mylog("in EN_Destructor, self=%u\n", self);
 
@@ -438,8 +409,7 @@ EN_Destructor(EnvironmentClass *self)
    /* the source--they should not be freed */
 
    /* Free any connections belonging to this environment */
-   for (lf = 0; lf < MAX_CONNECTIONS; lf++)
-   {
+   for (lf = 0; lf < MAX_CONNECTIONS; lf++) {
        if (conns[lf] && conns[lf]->henv == self)
            rv = rv && CC_Destructor(conns[lf]);
    }
@@ -451,29 +421,26 @@ EN_Destructor(EnvironmentClass *self)
 char
 EN_get_error(EnvironmentClass *self, int *number, char **message)
 {
-   if (self && self->errormsg && self->errornumber)
-   {
+   if(self && self->errormsg && self->errornumber) {
        *message = self->errormsg;
        *number = self->errornumber;
        self->errormsg = 0;
        self->errornumber = 0;
        return 1;
-   }
-   else
+   } else {
        return 0;
+   }
 }
 
 char
 EN_add_connection(EnvironmentClass *self, ConnectionClass *conn)
 {
-   int         i;
+int i;
 
-   mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
+mylog("EN_add_connection: self = %u, conn = %u\n", self, conn);
 
-   for (i = 0; i < MAX_CONNECTIONS; i++)
-   {
-       if (!conns[i])
-       {
+   for (i = 0; i < MAX_CONNECTIONS; i++) {
+       if ( ! conns[i]) {
            conn->henv = self;
            conns[i] = conn;
 
@@ -489,11 +456,10 @@ EN_add_connection(EnvironmentClass *self, ConnectionClass *conn)
 char
 EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
 {
-   int         i;
+int i;
 
    for (i = 0; i < MAX_CONNECTIONS; i++)
-       if (conns[i] == conn && conns[i]->status != CONN_EXECUTING)
-       {
+       if (conns[i] == conn && conns[i]->status != CONN_EXECUTING) {
            conns[i] = NULL;
            return TRUE;
        }
@@ -504,8 +470,9 @@ EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
 void
 EN_log_error(char *func, char *desc, EnvironmentClass *self)
 {
-   if (self)
+   if (self) {
        qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg);
+   }
    else
        qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
 }
index c236e575c1e933f1c2b87d37e17f20aadda97a5b..47018e7b38f2f5f108e8c1fab1431cc884541df8 100644 (file)
@@ -1,9 +1,9 @@
 
-/* File:           environ.h
+/* File:            environ.h
  *
- * Description:        See "environ.c"
+ * Description:     See "environ.c"
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 #define ENV_ALLOC_ERROR 1
 
 /**********        Environment Handle  *************/
-struct EnvironmentClass_
-{
-   char       *errormsg;
-   int         errornumber;
+struct EnvironmentClass_ {
+   char *errormsg;
+   int errornumber;
 };
 
 /* Environment prototypes */
 EnvironmentClass *EN_Constructor(void);
-char       EN_Destructor(EnvironmentClass *self);
-char       EN_get_error(EnvironmentClass *self, int *number, char **message);
-char       EN_add_connection(EnvironmentClass *self, ConnectionClass *conn);
-char       EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn);
-void       EN_log_error(char *func, char *desc, EnvironmentClass *self);
+char EN_Destructor(EnvironmentClass *self);
+char EN_get_error(EnvironmentClass *self, int *number, char **message);
+char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn);
+char EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn);
+void EN_log_error(char *func, char *desc, EnvironmentClass *self);
 
 #endif
index ac7f2ee30f43b32748d2bc392bd96c105e46dd42..ac5d0b19c38dd17c7430ca69239f444e0606a4eb 100644 (file)
@@ -1,14 +1,15 @@
-/* Module:         execute.c
+
+/* Module:          execute.c
  *
- * Description:        This module contains routines related to
- *                 preparing and executing an SQL statement.
+ * Description:     This module contains routines related to 
+ *                  preparing and executing an SQL statement.
  *
- * Classes:            n/a
+ * Classes:         n/a
  *
- * API functions:  SQLPrepare, SQLExecute, SQLExecDirect, SQLTransact,
- *                 SQLCancel, SQLNativeSql, SQLParamData, SQLPutData
+ * API functions:   SQLPrepare, SQLExecute, SQLExecDirect, SQLTransact,
+ *                  SQLCancel, SQLNativeSql, SQLParamData, SQLPutData
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
 extern GLOBAL_VALUES globals;
 
 
-/*     Perform a Prepare on the SQL statement */
-RETCODE SQL_API
-SQLPrepare(HSTMT hstmt,
-          UCHAR FAR *szSqlStr,
-          SDWORD cbSqlStr)
+/*      Perform a Prepare on the SQL statement */
+RETCODE SQL_API SQLPrepare(HSTMT     hstmt,
+                           UCHAR FAR *szSqlStr,
+                           SDWORD    cbSqlStr)
 {
-   static char *func = "SQLPrepare";
-   StatementClass *self = (StatementClass *) hstmt;
+static char *func = "SQLPrepare";
+StatementClass *self = (StatementClass *) hstmt;
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!self)
-   {
+   if ( ! self) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
+    
+   /*  According to the ODBC specs it is valid to call SQLPrepare mulitple times.
+       In that case, the bound SQL statement is replaced by the new one 
+   */
 
-   /*
-    * According to the ODBC specs it is valid to call SQLPrepare mulitple
-    * times. In that case, the bound SQL statement is replaced by the new
-    * one
-    */
-
-   switch (self->status)
-   {
-       case STMT_PREMATURE:
-           mylog("**** SQLPrepare: STMT_PREMATURE, recycle\n");
-           SC_recycle_statement(self); /* recycle the statement, but do
-                                        * not remove parameter bindings */
-           break;
+   switch(self->status) {
+   case STMT_PREMATURE:
+       mylog("**** SQLPrepare: STMT_PREMATURE, recycle\n");
+       SC_recycle_statement(self); /* recycle the statement, but do not remove parameter bindings */
+       break;
 
-       case STMT_FINISHED:
-           mylog("**** SQLPrepare: STMT_FINISHED, recycle\n");
-           SC_recycle_statement(self); /* recycle the statement, but do
-                                        * not remove parameter bindings */
-           break;
+   case STMT_FINISHED:
+       mylog("**** SQLPrepare: STMT_FINISHED, recycle\n");
+       SC_recycle_statement(self); /* recycle the statement, but do not remove parameter bindings */
+       break;
 
-       case STMT_ALLOCATED:
-           mylog("**** SQLPrepare: STMT_ALLOCATED, copy\n");
-           self->status = STMT_READY;
-           break;
+   case STMT_ALLOCATED:
+       mylog("**** SQLPrepare: STMT_ALLOCATED, copy\n");
+       self->status = STMT_READY;
+       break;
 
-       case STMT_READY:
-           mylog("**** SQLPrepare: STMT_READY, change SQL\n");
-           break;
+   case STMT_READY:
+       mylog("**** SQLPrepare: STMT_READY, change SQL\n");
+       break;
 
-       case STMT_EXECUTING:
-           mylog("**** SQLPrepare: STMT_EXECUTING, error!\n");
+   case STMT_EXECUTING:
+       mylog("**** SQLPrepare: STMT_EXECUTING, error!\n");
 
-           self->errornumber = STMT_SEQUENCE_ERROR;
-           self->errormsg = "SQLPrepare(): The handle does not point to a statement that is ready to be executed";
-           SC_log_error(func, "", self);
+       self->errornumber = STMT_SEQUENCE_ERROR;
+       self->errormsg = "SQLPrepare(): The handle does not point to a statement that is ready to be executed";
+       SC_log_error(func, "", self);
 
-           return SQL_ERROR;
+       return SQL_ERROR;
 
-       default:
-           self->errornumber = STMT_INTERNAL_ERROR;
-           self->errormsg = "An Internal Error has occured -- Unknown statement status.";
-           SC_log_error(func, "", self);
-           return SQL_ERROR;
+   default:
+       self->errornumber = STMT_INTERNAL_ERROR;
+       self->errormsg = "An Internal Error has occured -- Unknown statement status.";
+       SC_log_error(func, "", self);
+       return SQL_ERROR;
    }
 
    if (self->statement)
        free(self->statement);
 
    self->statement = make_string(szSqlStr, cbSqlStr, NULL);
-   if (!self->statement)
-   {
+   if ( ! self->statement) {
        self->errornumber = STMT_NO_MEMORY_ERROR;
        self->errormsg = "No memory available to store statement";
        SC_log_error(func, "", self);
@@ -115,9 +108,8 @@ SQLPrepare(HSTMT hstmt,
    self->prepare = TRUE;
    self->statement_type = statement_type(self->statement);
 
-   /* Check if connection is onlyread (only selects are allowed) */
-   if (CC_is_onlyread(self->hdbc) && STMT_UPDATE(self))
-   {
+   /*  Check if connection is onlyread (only selects are allowed) */
+   if ( CC_is_onlyread(self->hdbc) && STMT_UPDATE(self)) {
        self->errornumber = STMT_EXEC_ERROR;
        self->errormsg = "Connection is readonly, only select statements are allowed.";
        SC_log_error(func, "", self);
@@ -129,24 +121,22 @@ SQLPrepare(HSTMT hstmt,
 
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/*     Performs the equivalent of SQLPrepare, followed by SQLExecute. */
+/*      Performs the equivalent of SQLPrepare, followed by SQLExecute. */
 
-RETCODE SQL_API
-SQLExecDirect(
-             HSTMT hstmt,
-             UCHAR FAR *szSqlStr,
-             SDWORD cbSqlStr)
+RETCODE SQL_API SQLExecDirect(
+        HSTMT     hstmt,
+        UCHAR FAR *szSqlStr,
+        SDWORD    cbSqlStr)
 {
-   StatementClass *stmt = (StatementClass *) hstmt;
-   RETCODE     result;
-   static char *func = "SQLExecDirect";
+StatementClass *stmt = (StatementClass *) hstmt;
+RETCODE result;
+static char *func = "SQLExecDirect";
 
-   mylog("%s: entering...\n", func);
-
-   if (!stmt)
-   {
+   mylog( "%s: entering...\n", func);
+    
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
@@ -157,8 +147,7 @@ SQLExecDirect(
    /* keep a copy of the un-parametrized statement, in case */
    /* they try to execute this statement again */
    stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
-   if (!stmt->statement)
-   {
+   if ( ! stmt->statement) {
        stmt->errornumber = STMT_NO_MEMORY_ERROR;
        stmt->errormsg = "No memory available to store statement";
        SC_log_error(func, "", stmt);
@@ -172,20 +161,19 @@ SQLExecDirect(
    /* If an SQLPrepare was performed prior to this, but was left in  */
    /* the premature state because an error occurred prior to SQLExecute */
    /* then set the statement to finished so it can be recycled. */
-   if (stmt->status == STMT_PREMATURE)
+   if ( stmt->status == STMT_PREMATURE )
        stmt->status = STMT_FINISHED;
 
    stmt->statement_type = statement_type(stmt->statement);
 
-   /* Check if connection is onlyread (only selects are allowed) */
-   if (CC_is_onlyread(stmt->hdbc) && STMT_UPDATE(stmt))
-   {
+   /*  Check if connection is onlyread (only selects are allowed) */
+   if ( CC_is_onlyread(stmt->hdbc) && STMT_UPDATE(stmt)) {
        stmt->errornumber = STMT_EXEC_ERROR;
        stmt->errormsg = "Connection is readonly, only select statements are allowed.";
        SC_log_error(func, "", stmt);
        return SQL_ERROR;
    }
-
+   
    mylog("%s: calling SQLExecute...\n", func);
 
    result = SQLExecute(hstmt);
@@ -194,55 +182,47 @@ SQLExecDirect(
    return result;
 }
 
-/*     Execute a prepared SQL statement */
-RETCODE SQL_API
-SQLExecute(
-          HSTMT hstmt)
+/*      Execute a prepared SQL statement */
+RETCODE SQL_API SQLExecute(
+        HSTMT   hstmt)
 {
-   static char *func = "SQLExecute";
-   StatementClass *stmt = (StatementClass *) hstmt;
-   ConnectionClass *conn;
-   int         i,
-               retval;
+static char *func="SQLExecute";
+StatementClass *stmt = (StatementClass *) hstmt;
+ConnectionClass *conn;
+int i, retval;
 
 
    mylog("%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        mylog("%s: NULL statement so return SQL_INVALID_HANDLE\n", func);
        return SQL_INVALID_HANDLE;
    }
 
-   /*
-    * If the statement is premature, it means we already executed it from
-    * an SQLPrepare/SQLDescribeCol type of scenario.  So just return
-    * success.
-    */
-   if (stmt->prepare && stmt->status == STMT_PREMATURE)
-   {
-       stmt->status = STMT_FINISHED;
-       if (stmt->errormsg == NULL)
-       {
+   /*  If the statement is premature, it means we already executed
+       it from an SQLPrepare/SQLDescribeCol type of scenario.  So
+       just return success.
+   */
+   if ( stmt->prepare && stmt->status == STMT_PREMATURE) {
+       stmt->status = STMT_FINISHED;       
+       if (stmt->errormsg == NULL) {
            mylog("%s: premature statement but return SQL_SUCCESS\n", func);
            return SQL_SUCCESS;
        }
-       else
-       {
+       else {
            SC_log_error(func, "", stmt);
            mylog("%s: premature statement so return SQL_ERROR\n", func);
            return SQL_ERROR;
        }
-   }
+   }  
 
    mylog("%s: clear errors...\n", func);
 
    SC_clear_error(stmt);
 
    conn = SC_get_conn(stmt);
-   if (conn->status == CONN_EXECUTING)
-   {
+   if (conn->status == CONN_EXECUTING) {
        stmt->errormsg = "Connection is already in use.";
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        SC_log_error(func, "", stmt);
@@ -250,8 +230,7 @@ SQLExecute(
        return SQL_ERROR;
    }
 
-   if (!stmt->statement)
-   {
+   if ( ! stmt->statement) {
        stmt->errornumber = STMT_NO_STMTSTRING;
        stmt->errormsg = "This handle does not have a SQL statement stored in it";
        SC_log_error(func, "", stmt);
@@ -259,21 +238,19 @@ SQLExecute(
        return SQL_ERROR;
    }
 
-   /*
-    * If SQLExecute is being called again, recycle the statement. Note
-    * this should have been done by the application in a call to
-    * SQLFreeStmt(SQL_CLOSE) or SQLCancel.
-    */
-   if (stmt->status == STMT_FINISHED)
-   {
+   /*  If SQLExecute is being called again, recycle the statement.
+       Note this should have been done by the application in a call
+       to SQLFreeStmt(SQL_CLOSE) or SQLCancel.
+   */
+   if (stmt->status == STMT_FINISHED) {
        mylog("%s: recycling statement (should have been done by app)...\n", func);
        SC_recycle_statement(stmt);
    }
 
-   /* Check if the statement is in the correct state */
-   if ((stmt->prepare && stmt->status != STMT_READY) ||
-       (stmt->status != STMT_ALLOCATED && stmt->status != STMT_READY))
-   {
+   /*  Check if the statement is in the correct state */
+   if ((stmt->prepare && stmt->status != STMT_READY) || 
+       (stmt->status != STMT_ALLOCATED && stmt->status != STMT_READY)) {
+       
        stmt->errornumber = STMT_STATUS_ERROR;
        stmt->errormsg = "The handle does not point to a statement that is ready to be executed";
        SC_log_error(func, "", stmt);
@@ -282,37 +259,30 @@ SQLExecute(
    }
 
 
-   /*
-    * The bound parameters could have possibly changed since the last
-    * execute of this statement?  Therefore check for params and re-copy.
-    */
+   /*  The bound parameters could have possibly changed since the last execute
+       of this statement?  Therefore check for params and re-copy.
+   */
    stmt->data_at_exec = -1;
-   for (i = 0; i < stmt->parameters_allocated; i++)
-   {
-       /* Check for data at execution parameters */
-       if (stmt->parameters[i].data_at_exec == TRUE)
-       {
+   for (i = 0; i < stmt->parameters_allocated; i++) {
+       /*  Check for data at execution parameters */
+       if ( stmt->parameters[i].data_at_exec == TRUE) {
            if (stmt->data_at_exec < 0)
                stmt->data_at_exec = 1;
            else
                stmt->data_at_exec++;
        }
    }
-   /* If there are some data at execution parameters, return need data */
-
-   /*
-    * SQLParamData and SQLPutData will be used to send params and execute
-    * the statement.
-    */
+   /*  If there are some data at execution parameters, return need data */
+   /*  SQLParamData and SQLPutData will be used to send params and execute the statement. */
    if (stmt->data_at_exec > 0)
        return SQL_NEED_DATA;
 
 
    mylog("%s: copying statement params: trans_status=%d, len=%d, stmt='%s'\n", func, conn->transact_status, strlen(stmt->statement), stmt->statement);
 
-   /* Create the statement with parameters substituted. */
+   /*  Create the statement with parameters substituted. */
    retval = copy_statement_with_parameters(stmt);
-   if (retval != SQL_SUCCESS)
+   ifretval != SQL_SUCCESS)
        /* error msg passed from above */
        return retval;
 
@@ -320,144 +290,131 @@ SQLExecute(
 
 
    return SC_execute(stmt);
+
 }
 
 
 
 
-/*     -       -       -       -       -       -       -       -       - */
-RETCODE SQL_API
-SQLTransact(
-           HENV henv,
-           HDBC hdbc,
-           UWORD fType)
+/*      -       -       -       -       -       -       -       -       - */
+RETCODE SQL_API SQLTransact(
+        HENV    henv,
+        HDBC    hdbc,
+        UWORD   fType)
 {
-   static char *func = "SQLTransact";
-   extern ConnectionClass *conns[];
-   ConnectionClass *conn;
-   QResultClass *res;
-   char        ok,
-              *stmt_string;
-   int         lf;
+static char *func = "SQLTransact";
+extern ConnectionClass *conns[];
+ConnectionClass *conn;
+QResultClass *res;
+char ok, *stmt_string;
+int lf;
 
    mylog("entering %s: hdbc=%u, henv=%u\n", func, hdbc, henv);
 
-   if (hdbc == SQL_NULL_HDBC && henv == SQL_NULL_HENV)
-   {
+   if (hdbc == SQL_NULL_HDBC && henv == SQL_NULL_HENV) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-   /*
-    * If hdbc is null and henv is valid, it means transact all
-    * connections on that henv.
-    */
-   if (hdbc == SQL_NULL_HDBC && henv != SQL_NULL_HENV)
-   {
-       for (lf = 0; lf < MAX_CONNECTIONS; lf++)
-       {
+   /* If hdbc is null and henv is valid,
+   it means transact all connections on that henv.  
+   */
+   if (hdbc == SQL_NULL_HDBC && henv != SQL_NULL_HENV) {
+       for (lf=0; lf <MAX_CONNECTIONS; lf++) {
            conn = conns[lf];
 
            if (conn && conn->henv == henv)
-               if (SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
+               if ( SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
                    return SQL_ERROR;
+
        }
-       return SQL_SUCCESS;
+       return SQL_SUCCESS;       
    }
 
    conn = (ConnectionClass *) hdbc;
 
-   if (fType == SQL_COMMIT)
+   if (fType == SQL_COMMIT) {
        stmt_string = "COMMIT";
-   else if (fType == SQL_ROLLBACK)
+
+   } else if (fType == SQL_ROLLBACK) {
        stmt_string = "ROLLBACK";
-   else
-   {
+
+   } else {
        conn->errornumber = CONN_INVALID_ARGUMENT_NO;
-       conn->errormsg = "SQLTransact can only be called with SQL_COMMIT or SQL_ROLLBACK as parameter";
+       conn->errormsg ="SQLTransact can only be called with SQL_COMMIT or SQL_ROLLBACK as parameter";
        CC_log_error(func, "", conn);
        return SQL_ERROR;
-   }
+   }    
+
+   /*  If manual commit and in transaction, then proceed. */
+   if ( ! CC_is_in_autocommit(conn) &&  CC_is_in_trans(conn)) {
 
-   /* If manual commit and in transaction, then proceed. */
-   if (!CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
-   {
        mylog("SQLTransact: sending on conn %d '%s'\n", conn, stmt_string);
 
        res = CC_send_query(conn, stmt_string, NULL);
        CC_set_no_trans(conn);
 
-       if (!res)
-       {
-           /* error msg will be in the connection */
+       if ( ! res) {
+           /*  error msg will be in the connection */
            CC_log_error(func, "", conn);
            return SQL_ERROR;
        }
 
-       ok = QR_command_successful(res);
+       ok = QR_command_successful(res);   
        QR_Destructor(res);
 
-       if (!ok)
-       {
+       if (!ok) {
            CC_log_error(func, "", conn);
            return SQL_ERROR;
        }
-   }
+   }    
    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLCancel(
-         HSTMT hstmt)          /* Statement to cancel. */
+RETCODE SQL_API SQLCancel(
+        HSTMT   hstmt)  /* Statement to cancel. */
 {
-   static char *func = "SQLCancel";
-   StatementClass *stmt = (StatementClass *) hstmt;
-   RETCODE     result;
-
+static char *func="SQLCancel";
+StatementClass *stmt = (StatementClass *) hstmt;
+RETCODE result;
 #ifdef WIN32
-   HMODULE     hmodule;
-   FARPROC     addr;
-
+HMODULE hmodule;
+FARPROC addr;
 #endif
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   /* Check if this can handle canceling in the middle of a SQLPutData? */
-   if (!stmt)
-   {
+   /*  Check if this can handle canceling in the middle of a SQLPutData? */
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-   /*
-    * Not in the middle of SQLParamData/SQLPutData so cancel like a
-    * close.
-    */
-   if (stmt->data_at_exec < 0)
-   {
-
-       /*
-        * MAJOR HACK for Windows to reset the driver manager's cursor
-        * state: Because of what seems like a bug in the Odbc driver
-        * manager, SQLCancel does not act like a SQLFreeStmt(CLOSE), as
-        * many applications depend on this behavior.  So, this brute
-        * force method calls the driver manager's function on behalf of
-        * the application.
-        */
+   /*  Not in the middle of SQLParamData/SQLPutData so cancel like a close. */
+   if (stmt->data_at_exec < 0) {
+
+
+       /*  MAJOR HACK for Windows to reset the driver manager's cursor state:
+           Because of what seems like a bug in the Odbc driver manager,
+           SQLCancel does not act like a SQLFreeStmt(CLOSE), as many
+           applications depend on this behavior.  So, this 
+           brute force method calls the driver manager's function on
+           behalf of the application.  
+       */
 
 #ifdef WIN32
-       if (globals.cancel_as_freestmt)
-       {
+       if (globals.cancel_as_freestmt) {
            hmodule = GetModuleHandle("ODBC32");
            addr = GetProcAddress(hmodule, "SQLFreeStmt");
-           result = addr((char *) (stmt->phstmt) - 96, SQL_CLOSE);
+           result = addr( (char *) (stmt->phstmt) - 96, SQL_CLOSE);
+       }
+       else {
+           result = SQLFreeStmt( hstmt, SQL_CLOSE);
        }
-       else
-           result = SQLFreeStmt(hstmt, SQL_CLOSE);
 #else
-       result = SQLFreeStmt(hstmt, SQL_CLOSE);
+       result = SQLFreeStmt( hstmt, SQL_CLOSE);
 #endif
 
        mylog("SQLCancel:  SQLFreeStmt returned %d\n", result);
@@ -466,46 +423,41 @@ SQLCancel(
        return SQL_SUCCESS;
    }
 
-   /* In the middle of SQLParamData/SQLPutData, so cancel that. */
-
-   /*
-    * Note, any previous data-at-exec buffers will be freed in the
-    * recycle
-    */
-   /* if they call SQLExecDirect or SQLExecute again. */
+   /*  In the middle of SQLParamData/SQLPutData, so cancel that. */
+   /*  Note, any previous data-at-exec buffers will be freed in the recycle */
+   /*  if they call SQLExecDirect or SQLExecute again. */
 
    stmt->data_at_exec = -1;
    stmt->current_exec_param = -1;
    stmt->put_data = FALSE;
 
    return SQL_SUCCESS;
+
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/*     Returns the SQL string as modified by the driver. */
+/*      Returns the SQL string as modified by the driver. */
 /*     Currently, just copy the input string without modification */
 /*     observing buffer limits and truncation. */
-RETCODE SQL_API
-SQLNativeSql(
-            HDBC hdbc,
-            UCHAR FAR *szSqlStrIn,
-            SDWORD cbSqlStrIn,
-            UCHAR FAR *szSqlStr,
-            SDWORD cbSqlStrMax,
-            SDWORD FAR *pcbSqlStr)
+RETCODE SQL_API SQLNativeSql(
+        HDBC      hdbc,
+        UCHAR FAR *szSqlStrIn,
+        SDWORD     cbSqlStrIn,
+        UCHAR FAR *szSqlStr,
+        SDWORD     cbSqlStrMax,
+        SDWORD FAR *pcbSqlStr)
 {
-   static char *func = "SQLNativeSql";
-   int         len = 0;
-   char       *ptr;
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   RETCODE     result;
+static char *func="SQLNativeSql";
+int len = 0;
+char *ptr;
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+RETCODE result;
 
-   mylog("%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
+   mylog( "%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
 
    ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL);
-   if (!ptr)
-   {
+   if ( ! ptr) {
        conn->errornumber = CONN_NO_MEMORY_ERROR;
        conn->errormsg = "No memory available to store native sql string";
        CC_log_error(func, "", conn);
@@ -515,12 +467,10 @@ SQLNativeSql(
    result = SQL_SUCCESS;
    len = strlen(ptr);
 
-   if (szSqlStr)
-   {
+   if (szSqlStr) {
        strncpy_null(szSqlStr, ptr, cbSqlStrMax);
 
-       if (len >= cbSqlStrMax)
-       {
+       if (len >= cbSqlStrMax)  {
            result = SQL_SUCCESS_WITH_INFO;
            conn->errornumber = STMT_TRUNCATED;
            conn->errormsg = "The buffer was too small for the result.";
@@ -532,44 +482,39 @@ SQLNativeSql(
 
    free(ptr);
 
-   return result;
+    return result;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/*     Supplies parameter data at execution time.      Used in conjuction with */
-/*     SQLPutData. */
+/*      Supplies parameter data at execution time.      Used in conjuction with */
+/*      SQLPutData. */
 
-RETCODE SQL_API
-SQLParamData(
-            HSTMT hstmt,
-            PTR FAR *prgbValue)
+RETCODE SQL_API SQLParamData(
+        HSTMT   hstmt,
+        PTR FAR *prgbValue)
 {
-   static char *func = "SQLParamData";
-   StatementClass *stmt = (StatementClass *) hstmt;
-   int         i,
-               retval;
+static char *func = "SQLParamData";
+StatementClass *stmt = (StatementClass *) hstmt;
+int i, retval;
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
    mylog("%s: data_at_exec=%d, params_alloc=%d\n", func, stmt->data_at_exec, stmt->parameters_allocated);
 
-   if (stmt->data_at_exec < 0)
-   {
+   if (stmt->data_at_exec < 0) {
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        stmt->errormsg = "No execution-time parameters for this statement";
        SC_log_error(func, "", stmt);
        return SQL_ERROR;
    }
 
-   if (stmt->data_at_exec > stmt->parameters_allocated)
-   {
+   if (stmt->data_at_exec > stmt->parameters_allocated) {
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        stmt->errormsg = "Too many execution-time parameters were present";
        SC_log_error(func, "", stmt);
@@ -577,19 +522,16 @@ SQLParamData(
    }
 
    /* close the large object */
-   if (stmt->lobj_fd >= 0)
-   {
+   if ( stmt->lobj_fd >= 0) {
        lo_close(stmt->hdbc, stmt->lobj_fd);
 
        /* commit transaction if needed */
-       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc))
-       {
+       if (!globals.use_declarefetch && CC_is_in_autocommit(stmt->hdbc)) {
            QResultClass *res;
-           char        ok;
+           char ok;
 
            res = CC_send_query(stmt->hdbc, "COMMIT", NULL);
-           if (!res)
-           {
+           if (!res) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                SC_log_error(func, "", stmt);
@@ -597,8 +539,7 @@ SQLParamData(
            }
            ok = QR_command_successful(res);
            QR_Destructor(res);
-           if (!ok)
-           {
+           if (!ok) {
                stmt->errormsg = "Could not commit (in-line) a transaction";
                stmt->errornumber = STMT_EXEC_ERROR;
                SC_log_error(func, "", stmt);
@@ -612,9 +553,8 @@ SQLParamData(
    }
 
 
-   /* Done, now copy the params and then execute the statement */
-   if (stmt->data_at_exec == 0)
-   {
+   /*  Done, now copy the params and then execute the statement */
+   if (stmt->data_at_exec == 0) {
        retval = copy_statement_with_parameters(stmt);
        if (retval != SQL_SUCCESS)
            return retval;
@@ -624,17 +564,14 @@ SQLParamData(
        return SC_execute(stmt);
    }
 
-   /*
-    * Set beginning param;  if first time SQLParamData is called , start
-    * at 0. Otherwise, start at the last parameter + 1.
-    */
-   i = stmt->current_exec_param >= 0 ? stmt->current_exec_param + 1 : 0;
-
-   /* At least 1 data at execution parameter, so Fill in the token value */
-   for (; i < stmt->parameters_allocated; i++)
-   {
-       if (stmt->parameters[i].data_at_exec == TRUE)
-       {
+   /*  Set beginning param;  if first time SQLParamData is called , start at 0.
+       Otherwise, start at the last parameter + 1.
+   */
+   i = stmt->current_exec_param >= 0 ? stmt->current_exec_param+1 : 0;
+
+   /*  At least 1 data at execution parameter, so Fill in the token value */
+   for ( ; i < stmt->parameters_allocated; i++) {
+       if (stmt->parameters[i].data_at_exec == TRUE) {
            stmt->data_at_exec--;
            stmt->current_exec_param = i;
            stmt->put_data = FALSE;
@@ -646,35 +583,31 @@ SQLParamData(
    return SQL_NEED_DATA;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-/*     Supplies parameter data at execution time.      Used in conjunction with */
-/*     SQLParamData. */
+/*      Supplies parameter data at execution time.      Used in conjunction with */
+/*      SQLParamData. */
 
-RETCODE SQL_API
-SQLPutData(
-          HSTMT hstmt,
-          PTR rgbValue,
-          SDWORD cbValue)
+RETCODE SQL_API SQLPutData(
+        HSTMT   hstmt,
+        PTR     rgbValue,
+        SDWORD  cbValue)
 {
-   static char *func = "SQLPutData";
-   StatementClass *stmt = (StatementClass *) hstmt;
-   int         old_pos,
-               retval;
-   ParameterInfoClass *current_param;
-   char       *buffer;
+static char *func = "SQLPutData";
+StatementClass *stmt = (StatementClass *) hstmt;
+int old_pos, retval;
+ParameterInfoClass *current_param;
+char *buffer;
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (!stmt)
-   {
+   if ( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
-
-   if (stmt->current_exec_param < 0)
-   {
+   
+   if (stmt->current_exec_param < 0) {
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        stmt->errormsg = "Previous call was not SQLPutData or SQLParamData";
        SC_log_error(func, "", stmt);
@@ -683,16 +616,14 @@ SQLPutData(
 
    current_param = &(stmt->parameters[stmt->current_exec_param]);
 
-   if (!stmt->put_data)
-   {                           /* first call */
+   if ( ! stmt->put_data) {    /* first call */
 
        mylog("SQLPutData: (1) cbValue = %d\n", cbValue);
 
        stmt->put_data = TRUE;
 
        current_param->EXEC_used = (SDWORD *) malloc(sizeof(SDWORD));
-       if (!current_param->EXEC_used)
-       {
+       if ( ! current_param->EXEC_used) {
            stmt->errornumber = STMT_NO_MEMORY_ERROR;
            stmt->errormsg = "Out of memory in SQLPutData (1)";
            SC_log_error(func, "", stmt);
@@ -705,18 +636,16 @@ SQLPutData(
            return SQL_SUCCESS;
 
 
-       /* Handle Long Var Binary with Large Objects */
-       if (current_param->SQLType == SQL_LONGVARBINARY)
-       {
+       /*  Handle Long Var Binary with Large Objects */
+       if ( current_param->SQLType == SQL_LONGVARBINARY) {
+
            /* begin transaction if needed */
-           if (!CC_is_in_trans(stmt->hdbc))
-           {
+           if(!CC_is_in_trans(stmt->hdbc)) {
                QResultClass *res;
-               char        ok;
+               char ok;
 
                res = CC_send_query(stmt->hdbc, "BEGIN", NULL);
-               if (!res)
-               {
+               if (!res) {
                    stmt->errormsg = "Could not begin (in-line) a transaction";
                    stmt->errornumber = STMT_EXEC_ERROR;
                    SC_log_error(func, "", stmt);
@@ -724,8 +653,7 @@ SQLPutData(
                }
                ok = QR_command_successful(res);
                QR_Destructor(res);
-               if (!ok)
-               {
+               if (!ok) {
                    stmt->errormsg = "Could not begin (in-line) a transaction";
                    stmt->errornumber = STMT_EXEC_ERROR;
                    SC_log_error(func, "", stmt);
@@ -735,24 +663,22 @@ SQLPutData(
                CC_set_in_trans(stmt->hdbc);
            }
 
-           /* store the oid */
+           /*  store the oid */
            current_param->lobj_oid = lo_creat(stmt->hdbc, INV_READ | INV_WRITE);
-           if (current_param->lobj_oid == 0)
-           {
+           if (current_param->lobj_oid == 0) {
                stmt->errornumber = STMT_EXEC_ERROR;
                stmt->errormsg = "Couldnt create large object.";
                SC_log_error(func, "", stmt);
                return SQL_ERROR;
            }
 
-           /* major hack -- to allow convert to see somethings there */
-           /* have to modify convert to handle this better */
+           /*  major hack -- to allow convert to see somethings there */
+           /*                  have to modify convert to handle this better */
            current_param->EXEC_buffer = (char *) &current_param->lobj_oid;
 
-           /* store the fd */
+           /*  store the fd */
            stmt->lobj_fd = lo_open(stmt->hdbc, current_param->lobj_oid, INV_WRITE);
-           if (stmt->lobj_fd < 0)
-           {
+           if ( stmt->lobj_fd < 0) {
                stmt->errornumber = STMT_EXEC_ERROR;
                stmt->errormsg = "Couldnt open large object for writing.";
                SC_log_error(func, "", stmt);
@@ -761,27 +687,22 @@ SQLPutData(
 
            retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
            mylog("lo_write: cbValue=%d, wrote %d bytes\n", cbValue, retval);
+
        }
-       else
-       {                       /* for handling text fields and small
-                                * binaries */
+       else {  /* for handling text fields and small binaries */
 
-           if (cbValue == SQL_NTS)
-           {
+           if (cbValue == SQL_NTS) {
                current_param->EXEC_buffer = strdup(rgbValue);
-               if (!current_param->EXEC_buffer)
-               {
+               if ( ! current_param->EXEC_buffer) {
                    stmt->errornumber = STMT_NO_MEMORY_ERROR;
                    stmt->errormsg = "Out of memory in SQLPutData (2)";
                    SC_log_error(func, "", stmt);
                    return SQL_ERROR;
                }
            }
-           else
-           {
+           else {
                current_param->EXEC_buffer = malloc(cbValue + 1);
-               if (!current_param->EXEC_buffer)
-               {
+               if ( ! current_param->EXEC_buffer) {
                    stmt->errornumber = STMT_NO_MEMORY_ERROR;
                    stmt->errormsg = "Out of memory in SQLPutData (2)";
                    SC_log_error(func, "", stmt);
@@ -793,28 +714,25 @@ SQLPutData(
        }
    }
 
-   else
-   {                           /* calling SQLPutData more than once */
+   else {  /* calling SQLPutData more than once */
 
        mylog("SQLPutData: (>1) cbValue = %d\n", cbValue);
 
-       if (current_param->SQLType == SQL_LONGVARBINARY)
-       {
+       if (current_param->SQLType == SQL_LONGVARBINARY) {
+
            /* the large object fd is in EXEC_buffer */
            retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
            mylog("lo_write(2): cbValue = %d, wrote %d bytes\n", cbValue, retval);
 
            *current_param->EXEC_used += cbValue;
-       }
-       else
-       {
+
+       } else {
+
            buffer = current_param->EXEC_buffer;
 
-           if (cbValue == SQL_NTS)
-           {
+           if (cbValue == SQL_NTS) {
                buffer = realloc(buffer, strlen(buffer) + strlen(rgbValue) + 1);
-               if (!buffer)
-               {
+               if ( ! buffer) {
                    stmt->errornumber = STMT_NO_MEMORY_ERROR;
                    stmt->errormsg = "Out of memory in SQLPutData (3)";
                    SC_log_error(func, "", stmt);
@@ -826,11 +744,12 @@ SQLPutData(
 
                *current_param->EXEC_used = cbValue;
 
-               /* reassign buffer incase realloc moved it */
+               /*  reassign buffer incase realloc moved it */
                current_param->EXEC_buffer = buffer;
+
            }
-           else if (cbValue > 0)
-           {
+           else if (cbValue > 0) {
+
                old_pos = *current_param->EXEC_used;
 
                *current_param->EXEC_used += cbValue;
@@ -839,8 +758,7 @@ SQLPutData(
 
                /* dont lose the old pointer in case out of memory */
                buffer = realloc(current_param->EXEC_buffer, *current_param->EXEC_used + 1);
-               if (!buffer)
-               {
+               if ( ! buffer) {
                    stmt->errornumber = STMT_NO_MEMORY_ERROR;
                    stmt->errormsg = "Out of memory in SQLPutData (3)";
                    SC_log_error(func, "", stmt);
@@ -850,14 +768,15 @@ SQLPutData(
                memcpy(&buffer[old_pos], rgbValue, cbValue);
                buffer[*current_param->EXEC_used] = '\0';
 
-               /* reassign buffer incase realloc moved it */
+               /*  reassign buffer incase realloc moved it */
                current_param->EXEC_buffer = buffer;
+               
            }
-           else
-           {
+           else {
                SC_log_error(func, "bad cbValue", stmt);
                return SQL_ERROR;
            }
+
        }
    }
 
index 6f693009659584324e0452415301b2780fa9595c..f14e95f2ce4176da77e61dc78043eda0539eb716 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef WIN32
 
 #if HAVE_CONFIG_H
-#include "config.h"                /* produced by configure */
+#include "config.h"    /* produced by configure */
 #endif
 
 #include <stdio.h>
 
 
 DWORD
-GetPrivateProfileString(char *theSection,      /* section name */
-                       char *theKey,   /* search key name */
-                       char *theDefault,       /* default value if not
-                                                * found */
-                       char *theReturnBuffer,  /* return value stored
-                                                * here */
-                       size_t theReturnBufferLength,   /* byte length of return
-                                                        * buffer */
-                       char *theIniFileName)   /* pathname of ini file to
-                                                * search */
+GetPrivateProfileString(char *theSection,  /* section name */
+           char *theKey,       /* search key name */
+           char *theDefault,   /* default value if not found */
+           char *theReturnBuffer,  /* return value stored here */
+           size_t theReturnBufferLength,   /* byte length of return buffer */
+           char *theIniFileName)       /* pathname of ini file to search */
 {
-   char        buf[MAXPGPATH];
-   char       *ptr = 0;
-   FILE       *aFile = 0;
-   size_t      aLength;
-   char        aLine[2048];
-   char       *aValue;
-   char       *aStart;
-   char       *aString;
-   size_t      aLineLength;
-   size_t      aReturnLength = 0;
-
-   BOOL        aSectionFound = FALSE;
-   BOOL        aKeyFound = FALSE;
-   int         j = 0;
+   char buf[MAXPGPATH];
+   charptr = 0;
+   FILEaFile = 0;
+   size_t aLength;
+   char aLine[2048];
+   char *aValue;
+   char *aStart;
+   char *aString;
+   size_t aLineLength;
+   size_t aReturnLength = 0;
+
+   BOOL aSectionFound = FALSE;
+   BOOL aKeyFound = FALSE;
+   int j = 0;
 
    j = strlen(theIniFileName) + 1;
-   ptr = (char *) getpwuid(getuid());  /* get user info */
+   ptr = (char*)getpwuid(getuid());    /* get user info */
 
-   if (ptr == NULL)
+   ifptr == NULL)
    {
-       if (MAXPGPATH - 1 < j)
-           theIniFileName[MAXPGPATH - 1] = '\0';
+       if( MAXPGPATH-1 < j )
+           theIniFileName[MAXPGPATH-1] = '\0';
 
-       sprintf(buf, "%s", theIniFileName);
+       sprintf(buf,"%s",theIniFileName);
    }
-   ptr = ((struct passwd *) ptr)->pw_dir;      /* get user home dir */
-   if (ptr == NULL || *ptr == '\0')
+   ptr = ((struct passwd*)ptr)->pw_dir;    /* get user home dir */
+   if( ptr == NULL || *ptr == '\0' )
        ptr = "/home";
 
-   /*
-    * This doesn't make it so we find an ini file but allows normal
-    * processing to continue further on down. The likelihood is that the
-    * file won't be found and thus the default value will be returned.
-    */
-   if (MAXPGPATH - 1 < strlen(ptr) + j)
+   /* This doesn't make it so we find an ini file but allows normal
+    * processing to continue further on down. The likelihood is that
+    * the file won't be found and thus the default value will be
+    * returned.
+   */
+   if( MAXPGPATH-1 < strlen(ptr) + j )
    {
-       if (MAXPGPATH - 1 < strlen(ptr))
-           ptr[MAXPGPATH - 1] = '\0';
+       if( MAXPGPATH-1 < strlen(ptr) )
+           ptr[MAXPGPATH-1] = '\0';
        else
-           theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0';
+           theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
    }
 
-   sprintf(buf, "%s/%s", ptr, theIniFileName);
+   sprintf( buf, "%s/%s",ptr,theIniFileName );
 
-   /*
-    * This code makes it so that a file in the users home dir overrides a
-    * the "default" file as passed in
-    */
-   aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
-   if (!aFile)
-   {
-       sprintf(buf, "%s", theIniFileName);
-       aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
+     /* This code makes it so that a file in the users home dir
+      * overrides a the "default" file as passed in
+     */
+   aFile = (FILE*)(buf ? fopen(buf, PG_BINARY_R) : NULL);
+   if(!aFile) {
+       sprintf(buf,"%s",theIniFileName);
+       aFile = (FILE*)(buf ? fopen(buf, PG_BINARY_R) : NULL);
    }
 
 
    aLength = (theDefault == NULL) ? 0 : strlen(theDefault);
 
-   if (theReturnBufferLength == 0 || theReturnBuffer == NULL)
+   if(theReturnBufferLength == 0 || theReturnBuffer == NULL)
    {
-       if (aFile)
+       if(aFile)
+       {
            fclose(aFile);
+       }
        return 0;
    }
 
-   if (aFile == NULL)
+   if(aFile == NULL)
    {
        /* no ini file specified, return the default */
 
-       ++aLength;              /* room for NULL char */
+       ++aLength;  /* room for NULL char */
        aLength = theReturnBufferLength < aLength ?
            theReturnBufferLength : aLength;
        strncpy(theReturnBuffer, theDefault, aLength);
@@ -127,77 +123,86 @@ GetPrivateProfileString(char *theSection,     /* section name */
    }
 
 
-   while (fgets(aLine, sizeof(aLine), aFile) != NULL)
+   while(fgets(aLine, sizeof(aLine), aFile) != NULL)
    {
        aLineLength = strlen(aLine);
        /* strip final '\n' */
-       if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
+       if(aLineLength > 0 && aLine[aLineLength - 1] == '\n')
+       {
            aLine[aLineLength - 1] = '\0';
-       switch (*aLine)
+       }
+       switch(*aLine)
        {
-           case ' ':           /* blank line */
-           case ';':           /* comment line */
+           case ' ': /* blank line */
+           case ';': /* comment line */
                continue;
-               break;
+           break;
 
-           case '[':           /* section marker */
+           case '[':   /* section marker */
 
-               if ((aString = strchr(aLine, ']')))
+               if( (aString = strchr(aLine, ']')) )
                {
                    aStart = aLine + 1;
                    aString--;
-                   while (isspace((unsigned char) *aStart))
-                       aStart++;
-                   while (isspace((unsigned char) *aString))
-                       aString--;
-                   *(aString + 1) = '\0';
+                   while (isspace((unsigned char) *aStart)) aStart++;
+                   while (isspace((unsigned char) *aString)) aString--;
+                   *(aString+1) = '\0';
 
                    /* accept as matched if NULL key or exact match */
 
-                   if (!theSection || !strcmp(aStart, theSection))
+                   if(!theSection || !strcmp(aStart, theSection))
+                   {
                        aSectionFound = TRUE;
+                   }
                }
 
-               break;
+           break;
 
            default:
 
                /* try to match value keys if in proper section */
 
-               if (aSectionFound)
+               if(aSectionFound)
                {
                    /* try to match requested key */
 
-                   if ((aString = aValue = strchr(aLine, '=')))
+                   if( (aString = aValue = strchr(aLine, '=')) )
                    {
                        *aValue = '\0';
                        ++aValue;
 
                        /* strip leading blanks in value field */
 
-                       while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
+                       while(*aValue == ' ' && aValue < aLine + sizeof(aLine))
+                       {
                            *aValue++ = '\0';
-                       if (aValue >= aLine + sizeof(aLine))
+                       }
+                       if(aValue >= aLine + sizeof(aLine))
+                       {
                            aValue = "";
+                       }
                    }
                    else
+                   {
                        aValue = "";
+                   }
 
                    aStart = aLine;
-                   while (isspace((unsigned char) *aStart))
-                       aStart++;
+                   while (isspace((unsigned char) *aStart)) aStart++;
 
                    /* strip trailing blanks from key */
 
-                   if (aString)
+                   if(aString)
                    {
-                       while (--aString >= aStart && *aString == ' ')
+                       while(--aString >= aStart && *aString == ' ')
+                       {
                            *aString = '\0';
+                       }
                    }
 
                    /* see if key is matched */
 
-                   if (theKey == NULL || !strcmp(theKey, aStart))
+                   if(theKey == NULL || !strcmp(theKey, aStart))
                    {
                        /* matched -- first, terminate value part */
 
@@ -208,7 +213,7 @@ GetPrivateProfileString(char *theSection,       /* section name */
 
                        aString = aValue + aLength - 1;
 
-                       while (--aString > aValue && *aString == ' ')
+                       while(--aString > aValue && *aString == ' ')
                        {
                            *aString = '\0';
                            --aLength;
@@ -216,7 +221,7 @@ GetPrivateProfileString(char *theSection,       /* section name */
 
                        /* unquote value if quoted */
 
-                       if (aLength >= 2 && aValue[0] == '"' &&
+                       if(aLength >= 2 && aValue[0] == '"' &&
                            aValue[aLength - 1] == '"')
                        {
                            /* string quoted with double quotes */
@@ -229,7 +234,7 @@ GetPrivateProfileString(char *theSection,       /* section name */
                        {
                            /* single quotes allowed also... */
 
-                           if (aLength >= 2 && aValue[0] == '\'' &&
+                           if(aLength >= 2 && aValue[0] == '\'' &&
                                aValue[aLength - 1] == '\'')
                            {
                                aValue[aLength - 1] = '\0';
@@ -241,23 +246,23 @@ GetPrivateProfileString(char *theSection,     /* section name */
                        /* compute maximum length copyable */
 
                        aLineLength = (aLength <
-                       theReturnBufferLength - aReturnLength) ? aLength :
+                           theReturnBufferLength - aReturnLength) ? aLength :
                            theReturnBufferLength - aReturnLength;
 
                        /* do the copy to return buffer */
 
-                       if (aLineLength)
+                       if(aLineLength)
                        {
                            strncpy(&theReturnBuffer[aReturnLength],
-                                   aValue, aLineLength);
+                               aValue, aLineLength);
                            aReturnLength += aLineLength;
-                           if (aReturnLength < theReturnBufferLength)
+                           if(aReturnLength < theReturnBufferLength)
                            {
                                theReturnBuffer[aReturnLength] = '\0';
                                ++aReturnLength;
                            }
                        }
-                       if (aFile)
+                       if(aFile)
                        {
                            fclose(aFile);
                            aFile = NULL;
@@ -267,16 +272,17 @@ GetPrivateProfileString(char *theSection,     /* section name */
                    }
                }
 
-               break;
+           break;
        }
    }
 
-   if (aFile)
+   if(aFile)
+   {
        fclose(aFile);
+   }
 
-   if (!aKeyFound)
-   {                           /* key wasn't found return default */
-       ++aLength;              /* room for NULL char */
+   if(!aKeyFound) {    /* key wasn't found return default */
+       ++aLength;  /* room for NULL char */
        aLength = theReturnBufferLength < aLength ?
            theReturnBufferLength : aLength;
        strncpy(theReturnBuffer, theDefault, aLength);
@@ -287,11 +293,10 @@ GetPrivateProfileString(char *theSection,     /* section name */
 }
 
 DWORD
-WritePrivateProfileString(char *theSection,        /* section name */
-                         char *theKey, /* write key name */
-                         char *theBuffer,      /* input buffer */
-                         char *theIniFileName) /* pathname of ini file to
-                                                * write */
+WritePrivateProfileString(char *theSection,    /* section name */
+             char *theKey,     /* write key name */
+             char *theBuffer,  /* input buffer */
+             char *theIniFileName) /* pathname of ini file to write */
 {
    return 0;
 }
@@ -302,74 +307,69 @@ WritePrivateProfileString(char *theSection,       /* section name */
  * I find out different.
  */
 DWORD
-WritePrivateProfileString(char *theSection,        /* section name */
-                         char *theKey, /* write key name */
-                         char *theBuffer,      /* input buffer */
-                         char *theIniFileName) /* pathname of ini file to
-                                                * write */
+WritePrivateProfileString(char *theSection,    /* section name */
+             char *theKey,     /* write key name */
+             char *theBuffer,  /* input buffer */
+             char *theIniFileName) /* pathname of ini file to write */
 {
-   char        buf[MAXPGPATH];
-   char       *ptr = 0;
-   FILE       *aFile = 0;
-   size_t      aLength;
-   char        aLine[2048];
-   char       *aValue;
-   char       *aString;
-   size_t      aLineLength;
-   size_t      aReturnLength = 0;
-
-   BOOL        aSectionFound = FALSE;
-   BOOL        keyFound = FALSE;
-   int         j = 0;
+   char buf[MAXPGPATH];
+   charptr = 0;
+   FILEaFile = 0;
+   size_t aLength;
+   char aLine[2048];
+   char *aValue;
+   char *aString;
+   size_t aLineLength;
+   size_t aReturnLength = 0;
+
+   BOOL aSectionFound = FALSE;
+   BOOL keyFound = FALSE;
+   int j = 0;
 
    /* If this isn't correct processing we'll change it later  */
-   if (theSection == NULL || theKey == NULL || theBuffer == NULL ||
-       theIniFileName == NULL)
-       return 0;
+   if(theSection == NULL || theKey == NULL || theBuffer == NULL ||
+       theIniFileName == NULL) return 0;
 
    aLength = strlen(theBuffer);
-   if (aLength == 0)
-       return 0;
+   if(aLength == 0) return 0;
 
    j = strlen(theIniFileName) + 1;
-   ptr = (char *) getpwuid(getuid());  /* get user info */
+   ptr = (char*)getpwuid(getuid());    /* get user info */
 
-   if (ptr == NULL)
+   ifptr == NULL)
    {
-       if (MAXPGPATH - 1 < j)
-           theIniFileName[MAXPGPATH - 1] = '\0';
+       if( MAXPGPATH-1 < j )
+           theIniFileName[MAXPGPATH-1] = '\0';
 
-       sprintf(buf, "%s", theIniFileName);
+       sprintf(buf,"%s",theIniFileName);
    }
-   ptr = ((struct passwd *) ptr)->pw_dir;      /* get user home dir */
-   if (ptr == NULL || *ptr == '\0')
+   ptr = ((struct passwd*)ptr)->pw_dir;    /* get user home dir */
+   if( ptr == NULL || *ptr == '\0' )
        ptr = "/home";
 
    /* This doesn't make it so we find an ini file but allows normal */
-   /* processing to continue further on down. The likelihood is that */
+   /*  processing to continue further on down. The likelihood is that */
    /* the file won't be found and thus the default value will be */
    /* returned. */
    /* */
-   if (MAXPGPATH - 1 < strlen(ptr) + j)
+   if( MAXPGPATH-1 < strlen(ptr) + j )
    {
-       if (MAXPGPATH - 1 < strlen(ptr))
-           ptr[MAXPGPATH - 1] = '\0';
+       if( MAXPGPATH-1 < strlen(ptr) )
+           ptr[MAXPGPATH-1] = '\0';
        else
-           theIniFileName[MAXPGPATH - 1 - strlen(ptr)] = '\0';
+           theIniFileName[MAXPGPATH-1-strlen(ptr)] = '\0';
    }
 
-   sprintf(buf, "%s/%s", ptr, theIniFileName);
+   sprintf( buf, "%s/%s",ptr,theIniFileName );
 
    /* This code makes it so that a file in the users home dir */
-   /* overrides a the "default" file as passed in */
+   /*  overrides a the "default" file as passed in */
    /* */
-   aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
-   if (!aFile)
-   {
-       sprintf(buf, "%s", theIniFileName);
-       aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
-       if (!aFile)
-           return 0;
+   aFile = (FILE*)(buf ? fopen(buf, "r+") : NULL);
+   if(!aFile) {
+       sprintf(buf,"%s",theIniFileName);
+       aFile = (FILE*)(buf ? fopen(buf, "r+") : NULL);
+       if(!aFile) return 0;
    }
 
 
@@ -379,92 +379,104 @@ WritePrivateProfileString(char *theSection,      /* section name */
    /* exists we have to overwrite it. If it doesn't exist */
    /* we just write a new line to the file. */
    /* */
-   while (fgets(aLine, sizeof(aLine), aFile) != NULL)
+   while(fgets(aLine, sizeof(aLine), aFile) != NULL)
    {
        aLineLength = strlen(aLine);
        /* strip final '\n' */
-       if (aLineLength > 0 && aLine[aLineLength - 1] == '\n')
+       if(aLineLength > 0 && aLine[aLineLength - 1] == '\n')
+       {
            aLine[aLineLength - 1] = '\0';
-       switch (*aLine)
+       }
+       switch(*aLine)
        {
-           case ' ':           /* blank line */
-           case ';':           /* comment line */
+           case ' ': /* blank line */
+           case ';': /* comment line */
                continue;
-               break;
+           break;
 
-           case '[':           /* section marker */
+           case '[':   /* section marker */
 
-               if ((aString = strchr(aLine, ']')))
+               if( (aString = strchr(aLine, ']')) )
                {
                    *aString = '\0';
 
                    /* accept as matched if key exact match */
 
-                   if (!strcmp(aLine + 1, theSection))
+                   if(!strcmp(aLine + 1, theSection))
+                   {
                        aSectionFound = TRUE;
+                   }
                }
 
-               break;
+           break;
 
            default:
 
                /* try to match value keys if in proper section */
 
-               if (aSectionFound)
+               if(aSectionFound)
                {
                    /* try to match requested key */
 
-                   if ((aString = aValue = strchr(aLine, '=')))
+                   if( (aString = aValue = strchr(aLine, '=')) )
                    {
                        *aValue = '\0';
                        ++aValue;
 
                        /* strip leading blanks in value field */
 
-                       while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
+                       while(*aValue == ' ' && aValue < aLine + sizeof(aLine))
+                       {
                            *aValue++ = '\0';
-                       if (aValue >= aLine + sizeof(aLine))
+                       }
+                       if(aValue >= aLine + sizeof(aLine))
+                       {
                            aValue = "";
+                       }
                    }
                    else
+                   {
                        aValue = "";
+                   }
 
                    /* strip trailing blanks from key */
 
-                   if (aString)
+                   if(aString)
                    {
-                       while (--aString >= aLine && *aString == ' ')
+                       while(--aString >= aLine && *aString == ' ')
+                       {
                            *aString = '\0';
+                       }
                    }
 
                    /* see if key is matched */
 
-                   if (!strcmp(theKey, aLine))
+                   if(!strcmp(theKey, aLine))
                    {
                        keyFound = TRUE;
                        /* matched -- first, terminate value part */
 
                        /* overwrite current value */
-                       fseek(aFile, -aLineLength, SEEK_CUR);
+                       fseek(aFile,-aLineLength,SEEK_CUR);
                        /* overwrite key and value */
-                       sprintf(aLine, "%s = %s\n", theKey, theBuffer);
-                       fputs(aLine, aFile);
+                       sprintf(aLine,"%s = %s\n",theKey,theBuffer);
+                       fputs(aLine,aFile);
+                       }
                    }
                }
-       }
 
-       break;
+           break;
+       }
    }
-}
 
-if (!keyFound)
-{                              /* theKey wasn't in file so  */
-   if (aFile)
+   if(!keyFound) {     /* theKey wasn't in file so  */
+   if(aFile)
+   {
        fclose(aFile);
+   }
 
    return aReturnLength > 0 ? aReturnLength - 1 : 0;
 }
-
 #endif
 
 
index c6d1d38ec2387804ebf48cec16825bbb0f924b01..c2c81965f09c95077bd6d2092a84b4202d067bae 100644 (file)
 #endif
 
 #ifdef __cplusplus
-extern     "C"
-{
+extern "C" {
 #endif
 
-   DWORD       GetPrivateProfileString(char *theSection,       /* section name */
-                                                   char *theKey,       /* search key name */
-                                                   char *theDefault,   /* default value if not
-                                                                        * found */
-                                                   char *theReturnBuffer,      /* return valuse stored
-                                                                                * here */
-                                                 size_t theBufferLength,       /* byte length of return
-                                                                                * buffer */
-                                                   char *theIniFileName);      /* pathname of ini file
-                                                                                * to search */
+DWORD
+GetPrivateProfileString(char *theSection,   /* section name */
+           char *theKey, /* search key name */
+           char *theDefault, /* default value if not found */
+           char *theReturnBuffer, /* return valuse stored here */
+           size_t theBufferLength, /* byte length of return buffer */
+           char *theIniFileName); /* pathname of ini file to search */
 
-   DWORD       WritePrivateProfileString(char *theSection,     /* section name */
-                                                     char *theKey,     /* write key name */
-                                                     char *theBuffer,  /* input buffer */
-                                                  char *theIniFileName);       /* pathname of ini file
-                                                                                * to write */
+DWORD
+WritePrivateProfileString(char *theSection,    /* section name */
+             char *theKey,     /* write key name */
+             char *theBuffer,  /* input buffer */
+             char *theIniFileName); /* pathname of ini file to write */
 
 #ifdef __cplusplus
 }
-
 #endif
 
 #ifndef WIN32
index 884ee4afcd3e3f4f1c777b383806a32086e0d885..bf43d6522b57b7e5b4f9558f67b9903021a59629 100644 (file)
@@ -1,17 +1,18 @@
-/* Module:         info.c
+
+/* Module:          info.c
  *
- * Description:        This module contains routines related to
- *                 ODBC informational functions.
+ * Description:     This module contains routines related to
+ *                  ODBC informational functions.
  *
- * Classes:            n/a
+ * Classes:         n/a
  *
- * API functions:  SQLGetInfo, SQLGetTypeInfo, SQLGetFunctions,
- *                 SQLTables, SQLColumns, SQLStatistics, SQLSpecialColumns,
- *                 SQLPrimaryKeys, SQLForeignKeys,
- *                 SQLProcedureColumns(NI), SQLProcedures(NI),
- *                 SQLTablePrivileges(NI), SQLColumnPrivileges(NI)
+ * API functions:   SQLGetInfo, SQLGetTypeInfo, SQLGetFunctions, 
+ *                  SQLTables, SQLColumns, SQLStatistics, SQLSpecialColumns,
+ *                  SQLPrimaryKeys, SQLForeignKeys, 
+ *                  SQLProcedureColumns(NI), SQLProcedures(NI), 
+ *                  SQLTablePrivileges(NI), SQLColumnPrivileges(NI)
  *
- * Comments:       See "notice.txt" for copyright and license information.
+ * Comments:        See "notice.txt" for copyright and license information.
  *
  */
 
@@ -30,7 +31,7 @@
 #include <ctype.h>
 #else
 #include <windows.h>
-#include <sql.h>
+#include <sql.h> 
 #include <sqlext.h>
 #endif
 
 extern GLOBAL_VALUES globals;
 
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLGetInfo(
-          HDBC hdbc,
-          UWORD fInfoType,
-          PTR rgbInfoValue,
-          SWORD cbInfoValueMax,
-          SWORD FAR *pcbInfoValue)
+RETCODE SQL_API SQLGetInfo(
+        HDBC      hdbc,
+        UWORD     fInfoType,
+        PTR       rgbInfoValue,
+        SWORD     cbInfoValueMax,
+        SWORD FAR *pcbInfoValue)
 {
-   static char *func = "SQLGetInfo";
-   ConnectionClass *conn = (ConnectionClass *) hdbc;
-   ConnInfo   *ci;
-   char       *p = NULL,
-               tmp[MAX_INFO_STRING];
-   int         len = 0,
-               value = 0;
-   RETCODE     result;
-
-   mylog("%s: entering...fInfoType=%d\n", func, fInfoType);
-
-   if (!conn)
-   {
+static char *func = "SQLGetInfo";
+ConnectionClass *conn = (ConnectionClass *) hdbc;
+ConnInfo *ci;
+char *p = NULL, tmp[MAX_INFO_STRING];
+int len = 0, value = 0;
+RETCODE result;
+
+   mylog( "%s: entering...fInfoType=%d\n", func, fInfoType);
+
+   if ( ! conn) {
        CC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
 
    ci = &conn->connInfo;
 
-   switch (fInfoType)
-   {
-       case SQL_ACCESSIBLE_PROCEDURES: /* ODBC 1.0 */
-           p = "N";
-           break;
-
-       case SQL_ACCESSIBLE_TABLES:     /* ODBC 1.0 */
-           p = "N";
-           break;
-
-       case SQL_ACTIVE_CONNECTIONS:    /* ODBC 1.0 */
-           len = 2;
-           value = MAX_CONNECTIONS;
-           break;
-
-       case SQL_ACTIVE_STATEMENTS:     /* ODBC 1.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_ALTER_TABLE:   /* ODBC 2.0 */
-           len = 4;
-           value = SQL_AT_ADD_COLUMN;
-           break;
-
-       case SQL_BOOKMARK_PERSISTENCE:  /* ODBC 2.0 */
-           /* very simple bookmark support */
-           len = 4;
-           value = globals.use_declarefetch ? 0 : (SQL_BP_SCROLL);
-           break;
-
-       case SQL_COLUMN_ALIAS:  /* ODBC 2.0 */
-           p = "N";
-           break;
-
-       case SQL_CONCAT_NULL_BEHAVIOR:  /* ODBC 1.0 */
-           len = 2;
-           value = SQL_CB_NON_NULL;
-           break;
-
-       case SQL_CONVERT_BIGINT:
-       case SQL_CONVERT_BINARY:
-       case SQL_CONVERT_BIT:
-       case SQL_CONVERT_CHAR:
-       case SQL_CONVERT_DATE:
-       case SQL_CONVERT_DECIMAL:
-       case SQL_CONVERT_DOUBLE:
-       case SQL_CONVERT_FLOAT:
-       case SQL_CONVERT_INTEGER:
-       case SQL_CONVERT_LONGVARBINARY:
-       case SQL_CONVERT_LONGVARCHAR:
-       case SQL_CONVERT_NUMERIC:
-       case SQL_CONVERT_REAL:
-       case SQL_CONVERT_SMALLINT:
-       case SQL_CONVERT_TIME:
-       case SQL_CONVERT_TIMESTAMP:
-       case SQL_CONVERT_TINYINT:
-       case SQL_CONVERT_VARBINARY:
-       case SQL_CONVERT_VARCHAR:       /* ODBC 1.0 */
-           len = 4;
-           value = fInfoType;
-           break;
-
-       case SQL_CONVERT_FUNCTIONS:     /* ODBC 1.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_CORRELATION_NAME:      /* ODBC 1.0 */
-
-           /*
-            * Saying no correlation name makes Query not work right.
-            * value = SQL_CN_NONE;
-            */
-           len = 2;
-           value = SQL_CN_ANY;
-           break;
-
-       case SQL_CURSOR_COMMIT_BEHAVIOR:        /* ODBC 1.0 */
-           len = 2;
-           value = SQL_CB_CLOSE;
-           break;
-
-       case SQL_CURSOR_ROLLBACK_BEHAVIOR:      /* ODBC 1.0 */
-           len = 2;
-           value = SQL_CB_CLOSE;
-           break;
-
-       case SQL_DATA_SOURCE_NAME:      /* ODBC 1.0 */
-           p = CC_get_DSN(conn);
-           break;
-
-       case SQL_DATA_SOURCE_READ_ONLY: /* ODBC 1.0 */
-           p = CC_is_onlyread(conn) ? "Y" : "N";
-           break;
-
-       case SQL_DATABASE_NAME:/* Support for old ODBC 1.0 Apps */
-
-           /*
-            * Returning the database name causes problems in MS Query. It
-            * generates query like: "SELECT DISTINCT a FROM byronncrap3
-            * crap3"
-            *
-            * p = CC_get_database(conn);
-            */
-           p = "";
-           break;
-
-       case SQL_DBMS_NAME:     /* ODBC 1.0 */
-           p = DBMS_NAME;
-           break;
-
-       case SQL_DBMS_VER:      /* ODBC 1.0 */
-
-           /*
-            * The ODBC spec wants ##.##.#### ...whatever... so prepend
-            * the driver version number to the dbms version string
-            */
-           sprintf(tmp, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
-           p = tmp;
-           break;
-
-       case SQL_DEFAULT_TXN_ISOLATION: /* ODBC 1.0 */
-           len = 4;
-           value = SQL_TXN_READ_COMMITTED;     /* SQL_TXN_SERIALIZABLE; */
-           break;
-
-       case SQL_DRIVER_NAME:   /* ODBC 1.0 */
-           p = DRIVER_FILE_NAME;
-           break;
-
-       case SQL_DRIVER_ODBC_VER:
-           p = DRIVER_ODBC_VER;
-           break;
-
-       case SQL_DRIVER_VER:    /* ODBC 1.0 */
-           p = POSTGRESDRIVERVERSION;
-           break;
-
-       case SQL_EXPRESSIONS_IN_ORDERBY:        /* ODBC 1.0 */
-           p = "N";
-           break;
-
-       case SQL_FETCH_DIRECTION:       /* ODBC 1.0 */
-           len = 4;
-           value = globals.use_declarefetch ? (SQL_FD_FETCH_NEXT) : (SQL_FD_FETCH_NEXT |
-                                                    SQL_FD_FETCH_FIRST |
-                                                     SQL_FD_FETCH_LAST |
-                                                    SQL_FD_FETCH_PRIOR |
-                                                 SQL_FD_FETCH_ABSOLUTE |
-                                                 SQL_FD_FETCH_RELATIVE |
-                                                 SQL_FD_FETCH_BOOKMARK);
-           break;
-
-       case SQL_FILE_USAGE:    /* ODBC 2.0 */
-           len = 2;
-           value = SQL_FILE_NOT_SUPPORTED;
-           break;
-
-       case SQL_GETDATA_EXTENSIONS:    /* ODBC 2.0 */
-           len = 4;
-           value = (SQL_GD_ANY_COLUMN | SQL_GD_ANY_ORDER | SQL_GD_BOUND | SQL_GD_BLOCK);
-           break;
-
-       case SQL_GROUP_BY:      /* ODBC 2.0 */
-           len = 2;
-           value = SQL_GB_GROUP_BY_EQUALS_SELECT;
-           break;
-
-       case SQL_IDENTIFIER_CASE:       /* ODBC 1.0 */
-
-           /*
-            * are identifiers case-sensitive (yes, but only when quoted.
-            * If not quoted, they default to lowercase)
-            */
-           len = 2;
-           value = SQL_IC_LOWER;
-           break;
-
-       case SQL_IDENTIFIER_QUOTE_CHAR: /* ODBC 1.0 */
-           /* the character used to quote "identifiers" */
-           p = PG_VERSION_LE(conn, 6.2) ? " " : "\"";
-           break;
-
-       case SQL_KEYWORDS:      /* ODBC 2.0 */
-           p = "";
-           break;
-
-       case SQL_LIKE_ESCAPE_CLAUSE:    /* ODBC 2.0 */
-
-           /*
-            * is there a character that escapes '%' and '_' in a LIKE
-            * clause? not as far as I can tell
-            */
-           p = "N";
-           break;
-
-       case SQL_LOCK_TYPES:    /* ODBC 2.0 */
-           len = 4;
-           value = globals.lie ? (SQL_LCK_NO_CHANGE | SQL_LCK_EXCLUSIVE | SQL_LCK_UNLOCK) : SQL_LCK_NO_CHANGE;
-           break;
-
-       case SQL_MAX_BINARY_LITERAL_LEN:        /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_MAX_CHAR_LITERAL_LEN:  /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_MAX_COLUMN_NAME_LEN:   /* ODBC 1.0 */
-           len = 2;
-           value = MAX_COLUMN_LEN;
-           break;
-
-       case SQL_MAX_COLUMNS_IN_GROUP_BY:       /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_COLUMNS_IN_INDEX:  /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_COLUMNS_IN_ORDER_BY:       /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_COLUMNS_IN_SELECT: /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_COLUMNS_IN_TABLE:  /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_CURSOR_NAME_LEN:   /* ODBC 1.0 */
-           len = 2;
-           value = MAX_CURSOR_LEN;
-           break;
-
-       case SQL_MAX_INDEX_SIZE:        /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_MAX_OWNER_NAME_LEN:    /* ODBC 1.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_PROCEDURE_NAME_LEN:        /* ODBC 1.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_QUALIFIER_NAME_LEN:        /* ODBC 1.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_ROW_SIZE:  /* ODBC 2.0 */
-           len = 4;
-           if (PG_VERSION_GE(conn, 7.1))
-           {                   /* Large Rowa in 7.1+ */
-               value = MAX_ROW_SIZE;
-           }
-           else
-           {                   /* Without the Toaster we're limited to
-                                * the blocksize */
-               value = BLCKSZ;
-           }
-           break;
-
-       case SQL_MAX_ROW_SIZE_INCLUDES_LONG:    /* ODBC 2.0 */
-
-           /*
-            * does the preceding value include LONGVARCHAR and
-            * LONGVARBINARY fields?   Well, it does include longvarchar,
-            * but not longvarbinary.
-            */
-           p = "Y";
-           break;
-
-       case SQL_MAX_STATEMENT_LEN:     /* ODBC 2.0 */
-           /* maybe this should be 0? */
-           len = 4;
-           if (PG_VERSION_GE(conn, 7.0))
-           {                   /* Long Queries in 7.0+ */
-               value = MAX_STATEMENT_LEN;
-           }
-           else if (PG_VERSION_GE(conn, 6.5))  /* Prior to 7.0 we used
-                                                * 2*BLCKSZ */
-               value = (2 * BLCKSZ);
-           else
-/* Prior to 6.5 we used BLCKSZ */
-               value = BLCKSZ;
-
-           break;
-
-       case SQL_MAX_TABLE_NAME_LEN:    /* ODBC 1.0 */
-           len = 2;
-           value = MAX_TABLE_LEN;
-           break;
-
-       case SQL_MAX_TABLES_IN_SELECT:  /* ODBC 2.0 */
-           len = 2;
-           value = 0;
-           break;
-
-       case SQL_MAX_USER_NAME_LEN:
-           len = 2;
+    switch (fInfoType) {
+    case SQL_ACCESSIBLE_PROCEDURES: /* ODBC 1.0 */
+       p = "N";
+        break;
+
+    case SQL_ACCESSIBLE_TABLES: /* ODBC 1.0 */
+       p = "N";
+        break;
+
+    case SQL_ACTIVE_CONNECTIONS: /* ODBC 1.0 */
+        len = 2;
+        value = MAX_CONNECTIONS;
+        break;
+
+    case SQL_ACTIVE_STATEMENTS: /* ODBC 1.0 */
+        len = 2;
+        value = 0;
+        break;
+
+    case SQL_ALTER_TABLE: /* ODBC 2.0 */
+        len = 4;
+        value = SQL_AT_ADD_COLUMN;
+        break;
+
+    case SQL_BOOKMARK_PERSISTENCE: /* ODBC 2.0 */
+       /* very simple bookmark support */        
+       len = 4;
+        value = globals.use_declarefetch ? 0 : (SQL_BP_SCROLL);        
+        break;
+
+    case SQL_COLUMN_ALIAS: /* ODBC 2.0 */
+       p = "N";
+        break;
+
+    case SQL_CONCAT_NULL_BEHAVIOR: /* ODBC 1.0 */
+        len = 2;
+        value = SQL_CB_NON_NULL;
+        break;
+
+    case SQL_CONVERT_BIGINT:
+    case SQL_CONVERT_BINARY:
+    case SQL_CONVERT_BIT:
+    case SQL_CONVERT_CHAR:
+    case SQL_CONVERT_DATE:
+    case SQL_CONVERT_DECIMAL:
+    case SQL_CONVERT_DOUBLE:
+    case SQL_CONVERT_FLOAT:
+    case SQL_CONVERT_INTEGER:
+    case SQL_CONVERT_LONGVARBINARY:
+    case SQL_CONVERT_LONGVARCHAR:
+    case SQL_CONVERT_NUMERIC:
+    case SQL_CONVERT_REAL:
+    case SQL_CONVERT_SMALLINT:
+    case SQL_CONVERT_TIME:
+    case SQL_CONVERT_TIMESTAMP:
+    case SQL_CONVERT_TINYINT:
+    case SQL_CONVERT_VARBINARY:
+    case SQL_CONVERT_VARCHAR: /* ODBC 1.0 */
+       len = 4;
+        value = fInfoType;
+        break;
+
+    case SQL_CONVERT_FUNCTIONS: /* ODBC 1.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_CORRELATION_NAME: /* ODBC 1.0 */
+
+       /*  Saying no correlation name makes Query not work right.
+           value = SQL_CN_NONE;
+       */
+       len = 2;
+        value = SQL_CN_ANY;
+        break;
+
+    case SQL_CURSOR_COMMIT_BEHAVIOR: /* ODBC 1.0 */
+        len = 2;
+        value = SQL_CB_CLOSE;
+        break;
+
+    case SQL_CURSOR_ROLLBACK_BEHAVIOR: /* ODBC 1.0 */
+        len = 2;
+        value = SQL_CB_CLOSE;
+        break;
+
+    case SQL_DATA_SOURCE_NAME: /* ODBC 1.0 */
+       p = CC_get_DSN(conn);
+        break;
+
+    case SQL_DATA_SOURCE_READ_ONLY: /* ODBC 1.0 */
+       p = CC_is_onlyread(conn) ? "Y" : "N";
+        break;
+
+    case SQL_DATABASE_NAME: /* Support for old ODBC 1.0 Apps */
+
+       /*  Returning the database name causes problems in MS Query.
+           It generates query like: "SELECT DISTINCT a FROM byronncrap3 crap3"
+
+           p = CC_get_database(conn);
+       */
+       p = "";    
+       break;
+
+    case SQL_DBMS_NAME: /* ODBC 1.0 */
+       p = DBMS_NAME;
+        break;
+
+    case SQL_DBMS_VER: /* ODBC 1.0 */
+       /* The ODBC spec wants ##.##.#### ...whatever... so prepend the driver */
+       /* version number to the dbms version string */
+       sprintf(tmp, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
+       p = tmp;
+        break;
+
+    case SQL_DEFAULT_TXN_ISOLATION: /* ODBC 1.0 */
+       len = 4;
+        value = SQL_TXN_READ_COMMITTED; /*SQL_TXN_SERIALIZABLE; */
+        break;
+
+    case SQL_DRIVER_NAME: /* ODBC 1.0 */
+        p = DRIVER_FILE_NAME;
+        break;
+
+    case SQL_DRIVER_ODBC_VER:
+       p = DRIVER_ODBC_VER;
+        break;
+
+    case SQL_DRIVER_VER: /* ODBC 1.0 */
+        p = POSTGRESDRIVERVERSION;
+        break;
+
+    case SQL_EXPRESSIONS_IN_ORDERBY: /* ODBC 1.0 */
+       p = "N";
+        break;
+
+    case SQL_FETCH_DIRECTION: /* ODBC 1.0 */
+       len = 4;
+        value = globals.use_declarefetch ? (SQL_FD_FETCH_NEXT) : (SQL_FD_FETCH_NEXT |
+                                   SQL_FD_FETCH_FIRST |
+                                   SQL_FD_FETCH_LAST |
+                                   SQL_FD_FETCH_PRIOR |
+                                   SQL_FD_FETCH_ABSOLUTE |
+                                  SQL_FD_FETCH_RELATIVE | 
+                                  SQL_FD_FETCH_BOOKMARK);
+        break;
+
+    case SQL_FILE_USAGE: /* ODBC 2.0 */
+       len = 2;
+        value = SQL_FILE_NOT_SUPPORTED;
+        break;
+
+    case SQL_GETDATA_EXTENSIONS: /* ODBC 2.0 */
+       len = 4;
+        value = (SQL_GD_ANY_COLUMN | SQL_GD_ANY_ORDER | SQL_GD_BOUND | SQL_GD_BLOCK);
+        break;
+
+    case SQL_GROUP_BY: /* ODBC 2.0 */
+       len = 2;
+        value = SQL_GB_GROUP_BY_EQUALS_SELECT;
+        break;
+
+    case SQL_IDENTIFIER_CASE: /* ODBC 1.0 */
+        /* are identifiers case-sensitive (yes, but only when quoted.  If not quoted, they
+           default to lowercase)
+       */
+       len = 2;
+        value = SQL_IC_LOWER;
+        break;
+
+    case SQL_IDENTIFIER_QUOTE_CHAR: /* ODBC 1.0 */
+        /* the character used to quote "identifiers" */
+       p = PG_VERSION_LE(conn, 6.2) ? " " : "\"";
+        break;
+
+    case SQL_KEYWORDS: /* ODBC 2.0 */
+       p = "";
+        break;
+
+    case SQL_LIKE_ESCAPE_CLAUSE: /* ODBC 2.0 */
+       /*  is there a character that escapes '%' and '_' in a LIKE clause?
+           not as far as I can tell
+       */
+        p = "N";
+        break;
+
+    case SQL_LOCK_TYPES: /* ODBC 2.0 */
+       len = 4;
+        value = globals.lie ? (SQL_LCK_NO_CHANGE | SQL_LCK_EXCLUSIVE | SQL_LCK_UNLOCK) : SQL_LCK_NO_CHANGE;
+        break;
+
+    case SQL_MAX_BINARY_LITERAL_LEN: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_MAX_CHAR_LITERAL_LEN: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_MAX_COLUMN_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = MAX_COLUMN_LEN;
+        break;
+
+    case SQL_MAX_COLUMNS_IN_GROUP_BY: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_COLUMNS_IN_INDEX: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_COLUMNS_IN_ORDER_BY: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_COLUMNS_IN_SELECT: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_COLUMNS_IN_TABLE: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_CURSOR_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = MAX_CURSOR_LEN;
+        break;
+
+    case SQL_MAX_INDEX_SIZE: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_MAX_OWNER_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_PROCEDURE_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_QUALIFIER_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_ROW_SIZE: /* ODBC 2.0 */
+       len = 4;
+       if (PG_VERSION_GE(conn, 7.1)) { /* Large Rowa in 7.1+ */
+           value = MAX_ROW_SIZE;
+       } else { /* Without the Toaster we're limited to the blocksize */
+           value = BLCKSZ;
+       }
+        break;
+
+    case SQL_MAX_ROW_SIZE_INCLUDES_LONG: /* ODBC 2.0 */
+        /* does the preceding value include LONGVARCHAR and LONGVARBINARY
+           fields?   Well, it does include longvarchar, but not longvarbinary.
+       */
+       p = "Y";
+        break;
+
+    case SQL_MAX_STATEMENT_LEN: /* ODBC 2.0 */
+        /* maybe this should be 0? */
+       len = 4;
+       if (PG_VERSION_GE(conn, 7.0)) { /* Long Queries in 7.0+ */
+           value = MAX_STATEMENT_LEN;
+       } else if (PG_VERSION_GE(conn, 6.5)) /* Prior to 7.0 we used 2*BLCKSZ */
+           value = (2*BLCKSZ);
+       else /* Prior to 6.5 we used BLCKSZ */
+           value = BLCKSZ;
+
+        break;
+
+    case SQL_MAX_TABLE_NAME_LEN: /* ODBC 1.0 */
+       len = 2;
+        value = MAX_TABLE_LEN;
+        break;
+
+    case SQL_MAX_TABLES_IN_SELECT: /* ODBC 2.0 */
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MAX_USER_NAME_LEN:
+       len = 2;
+        value = 0;
+        break;
+
+    case SQL_MULT_RESULT_SETS: /* ODBC 1.0 */
+        /* Don't support multiple result sets but say yes anyway? */
+       p = "Y";
+        break;
+
+    case SQL_MULTIPLE_ACTIVE_TXN: /* ODBC 1.0 */
+       p = "Y";
+        break;
+
+    case SQL_NEED_LONG_DATA_LEN: /* ODBC 2.0 */
+       /*  Dont need the length, SQLPutData can handle any size and multiple calls */
+       p = "N";
+        break;
+
+    case SQL_NON_NULLABLE_COLUMNS: /* ODBC 1.0 */
+       len = 2;
+        value = SQL_NNC_NON_NULL;
+        break;
+
+    case SQL_NULL_COLLATION: /* ODBC 2.0 */
+        /* where are nulls sorted? */
+       len = 2;
+        value = SQL_NC_END;
+        break;
+
+    case SQL_NUMERIC_FUNCTIONS: /* ODBC 1.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_ODBC_API_CONFORMANCE: /* ODBC 1.0 */
+       len = 2;
+        value = SQL_OAC_LEVEL1;
+        break;
+
+    case SQL_ODBC_SAG_CLI_CONFORMANCE: /* ODBC 1.0 */
+       len = 2;
+        value = SQL_OSCC_NOT_COMPLIANT;
+        break;
+
+    case SQL_ODBC_SQL_CONFORMANCE: /* ODBC 1.0 */
+       len = 2;
+        value = SQL_OSC_CORE;
+        break;
+
+    case SQL_ODBC_SQL_OPT_IEF: /* ODBC 1.0 */
+       p = "N";
+        break;
+
+   case SQL_OJ_CAPABILITIES: /* ODBC 2.01 */
+       len = 4;
+       if (PG_VERSION_GE(conn, 7.1)) { /* OJs in 7.1+ */
+           value = (SQL_OJ_LEFT |
+                   SQL_OJ_RIGHT |
+                   SQL_OJ_FULL |
+                   SQL_OJ_NESTED |
+                   SQL_OJ_NOT_ORDERED |
+                   SQL_OJ_INNER |
+                   SQL_OJ_ALL_COMPARISON_OPS);
+       } else { /* OJs not in <7.1 */
            value = 0;
-           break;
+       }
+       break;
 
-       case SQL_MULT_RESULT_SETS:      /* ODBC 1.0 */
-           /* Don't support multiple result sets but say yes anyway? */
-           p = "Y";
-           break;
+    case SQL_ORDER_BY_COLUMNS_IN_SELECT: /* ODBC 2.0 */
+       p = (PG_VERSION_LE(conn, 6.3)) ? "Y" : "N";     
+        break;
 
-       case SQL_MULTIPLE_ACTIVE_TXN:   /* ODBC 1.0 */
+    case SQL_OUTER_JOINS: /* ODBC 1.0 */
+       if (PG_VERSION_GE(conn, 7.1)) { /* OJs in 7.1+ */
            p = "Y";
-           break;
-
-       case SQL_NEED_LONG_DATA_LEN:    /* ODBC 2.0 */
-
-           /*
-            * Dont need the length, SQLPutData can handle any size and
-            * multiple calls
-            */
-           p = "N";
-           break;
-
-       case SQL_NON_NULLABLE_COLUMNS:  /* ODBC 1.0 */
-           len = 2;
-           value = SQL_NNC_NON_NULL;
-           break;
-
-       case SQL_NULL_COLLATION:        /* ODBC 2.0 */
-           /* where are nulls sorted? */
-           len = 2;
-           value = SQL_NC_END;
-           break;
-
-       case SQL_NUMERIC_FUNCTIONS:     /* ODBC 1.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_ODBC_API_CONFORMANCE:  /* ODBC 1.0 */
-           len = 2;
-           value = SQL_OAC_LEVEL1;
-           break;
-
-       case SQL_ODBC_SAG_CLI_CONFORMANCE:      /* ODBC 1.0 */
-           len = 2;
-           value = SQL_OSCC_NOT_COMPLIANT;
-           break;
-
-       case SQL_ODBC_SQL_CONFORMANCE:  /* ODBC 1.0 */
-           len = 2;
-           value = SQL_OSC_CORE;
-           break;
-
-       case SQL_ODBC_SQL_OPT_IEF:      /* ODBC 1.0 */
+       } else { /* OJs not in <7.1 */
            p = "N";
-           break;
-
-       case SQL_OJ_CAPABILITIES:       /* ODBC 2.01 */
-           len = 4;
-           if (PG_VERSION_GE(conn, 7.1))
-           {                   /* OJs in 7.1+ */
-               value = (SQL_OJ_LEFT |
-                        SQL_OJ_RIGHT |
-                        SQL_OJ_FULL |
-                        SQL_OJ_NESTED |
-                        SQL_OJ_NOT_ORDERED |
-                        SQL_OJ_INNER |
-                        SQL_OJ_ALL_COMPARISON_OPS);
-           }
-           else
-           {                   /* OJs not in <7.1 */
-               value = 0;
-           }
-           break;
-
-       case SQL_ORDER_BY_COLUMNS_IN_SELECT:    /* ODBC 2.0 */
-           p = (PG_VERSION_LE(conn, 6.3)) ? "Y" : "N";
-           break;
-
-       case SQL_OUTER_JOINS:   /* ODBC 1.0 */
-           if (PG_VERSION_GE(conn, 7.1))
-           {                   /* OJs in 7.1+ */
-               p = "Y";
-           }
-           else
-           {                   /* OJs not in <7.1 */
-               p = "N";
-           }
-           break;
-
-       case SQL_OWNER_TERM:    /* ODBC 1.0 */
-           p = "owner";
-           break;
-
-       case SQL_OWNER_USAGE:   /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_POS_OPERATIONS:        /* ODBC 2.0 */
-           len = 4;
-           value = globals.lie ? (SQL_POS_POSITION | SQL_POS_REFRESH | SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD) : (SQL_POS_POSITION | SQL_POS_REFRESH);
-           break;
-
-       case SQL_POSITIONED_STATEMENTS: /* ODBC 2.0 */
-           len = 4;
-           value = globals.lie ? (SQL_PS_POSITIONED_DELETE |
-                                  SQL_PS_POSITIONED_UPDATE |
-                                  SQL_PS_SELECT_FOR_UPDATE) : 0;
-           break;
-
-       case SQL_PROCEDURE_TERM:        /* ODBC 1.0 */
-           p = "procedure";
-           break;
-
-       case SQL_PROCEDURES:    /* ODBC 1.0 */
-           p = "Y";
-           break;
-
-       case SQL_QUALIFIER_LOCATION:    /* ODBC 2.0 */
-           len = 2;
-           value = SQL_QL_START;
-           break;
-
-       case SQL_QUALIFIER_NAME_SEPARATOR:      /* ODBC 1.0 */
-           p = "";
-           break;
-
-       case SQL_QUALIFIER_TERM:        /* ODBC 1.0 */
-           p = "";
-           break;
-
-       case SQL_QUALIFIER_USAGE:       /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_QUOTED_IDENTIFIER_CASE:        /* ODBC 2.0 */
-           /* are "quoted" identifiers case-sensitive?  YES! */
-           len = 2;
-           value = SQL_IC_SENSITIVE;
-           break;
-
-       case SQL_ROW_UPDATES:   /* ODBC 1.0 */
-
-           /*
-            * Driver doesn't support keyset-driven or mixed cursors, so
-            * not much point in saying row updates are supported
-            */
-           p = globals.lie ? "Y" : "N";
-           break;
-
-       case SQL_SCROLL_CONCURRENCY:    /* ODBC 1.0 */
-           len = 4;
-           value = globals.lie ? (SQL_SCCO_READ_ONLY |
-                                  SQL_SCCO_LOCK |
-                                  SQL_SCCO_OPT_ROWVER |
-                            SQL_SCCO_OPT_VALUES) : (SQL_SCCO_READ_ONLY);
-           break;
-
-       case SQL_SCROLL_OPTIONS:        /* ODBC 1.0 */
-           len = 4;
-           value = globals.lie ? (SQL_SO_FORWARD_ONLY |
-                                  SQL_SO_STATIC |
-                                  SQL_SO_KEYSET_DRIVEN |
-                                  SQL_SO_DYNAMIC |
-                                  SQL_SO_MIXED) : (globals.use_declarefetch ? SQL_SO_FORWARD_ONLY : (SQL_SO_FORWARD_ONLY | SQL_SO_STATIC));
-           break;
-
-       case SQL_SEARCH_PATTERN_ESCAPE: /* ODBC 1.0 */
-           p = "";
-           break;
-
-       case SQL_SERVER_NAME:   /* ODBC 1.0 */
-           p = CC_get_server(conn);
-           break;
-
-       case SQL_SPECIAL_CHARACTERS:    /* ODBC 2.0 */
-           p = "_";
-           break;
-
-       case SQL_STATIC_SENSITIVITY:    /* ODBC 2.0 */
-           len = 4;
-           value = globals.lie ? (SQL_SS_ADDITIONS | SQL_SS_DELETIONS | SQL_SS_UPDATES) : 0;
-           break;
-
-       case SQL_STRING_FUNCTIONS:      /* ODBC 1.0 */
-           len = 4;
-           value = (SQL_FN_STR_CONCAT |
-                    SQL_FN_STR_LCASE |
-                    SQL_FN_STR_LENGTH |
-                    SQL_FN_STR_LOCATE |
-                    SQL_FN_STR_LTRIM |
-                    SQL_FN_STR_RTRIM |
-                    SQL_FN_STR_SUBSTRING |
-                    SQL_FN_STR_UCASE);
-           break;
-
-       case SQL_SUBQUERIES:    /* ODBC 2.0 */
-           /* postgres 6.3 supports subqueries */
-           len = 4;
-           value = (SQL_SQ_QUANTIFIED |
-                    SQL_SQ_IN |
-                    SQL_SQ_EXISTS |
-                    SQL_SQ_COMPARISON);
-           break;
-
-       case SQL_SYSTEM_FUNCTIONS:      /* ODBC 1.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_TABLE_TERM:    /* ODBC 1.0 */
-           p = "table";
-           break;
-
-       case SQL_TIMEDATE_ADD_INTERVALS:        /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_TIMEDATE_DIFF_INTERVALS:       /* ODBC 2.0 */
-           len = 4;
-           value = 0;
-           break;
-
-       case SQL_TIMEDATE_FUNCTIONS:    /* ODBC 1.0 */
-           len = 4;
-           value = (SQL_FN_TD_NOW);
-           break;
-
-       case SQL_TXN_CAPABLE:   /* ODBC 1.0 */
-
-           /*
-            * Postgres can deal with create or drop table statements in a
-            * transaction
-            */
-           len = 2;
-           value = SQL_TC_ALL;
-           break;
-
-       case SQL_TXN_ISOLATION_OPTION:  /* ODBC 1.0 */
-           len = 4;
-           value = SQL_TXN_READ_COMMITTED;     /* SQL_TXN_SERIALIZABLE; */
-           break;
-
-       case SQL_UNION: /* ODBC 2.0 */
-           /* unions with all supported in postgres 6.3 */
-           len = 4;
-           value = (SQL_U_UNION | SQL_U_UNION_ALL);
-           break;
-
-       case SQL_USER_NAME:     /* ODBC 1.0 */
-           p = CC_get_username(conn);
-           break;
-
-       default:
-           /* unrecognized key */
-           conn->errormsg = "Unrecognized key passed to SQLGetInfo.";
-           conn->errornumber = CONN_NOT_IMPLEMENTED_ERROR;
-           CC_log_error(func, "", conn);
-           return SQL_ERROR;
-   }
+       }
+        break;
+
+    case SQL_OWNER_TERM: /* ODBC 1.0 */
+       p = "owner";
+        break;
+
+    case SQL_OWNER_USAGE: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_POS_OPERATIONS: /* ODBC 2.0 */
+       len = 4;
+        value = globals.lie ? (SQL_POS_POSITION | SQL_POS_REFRESH | SQL_POS_UPDATE | SQL_POS_DELETE | SQL_POS_ADD) : (SQL_POS_POSITION | SQL_POS_REFRESH);
+        break;
+
+    case SQL_POSITIONED_STATEMENTS: /* ODBC 2.0 */
+       len = 4;
+        value = globals.lie ? (SQL_PS_POSITIONED_DELETE | 
+                               SQL_PS_POSITIONED_UPDATE | 
+                               SQL_PS_SELECT_FOR_UPDATE) : 0;
+        break;
+
+    case SQL_PROCEDURE_TERM: /* ODBC 1.0 */
+        p = "procedure";
+        break;
+
+    case SQL_PROCEDURES: /* ODBC 1.0 */
+       p = "Y";
+        break;
+
+    case SQL_QUALIFIER_LOCATION: /* ODBC 2.0 */
+       len = 2;
+        value = SQL_QL_START;
+        break;
+
+    case SQL_QUALIFIER_NAME_SEPARATOR: /* ODBC 1.0 */
+       p = "";
+        break;
+
+    case SQL_QUALIFIER_TERM: /* ODBC 1.0 */
+       p = "";
+        break;
+
+    case SQL_QUALIFIER_USAGE: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_QUOTED_IDENTIFIER_CASE: /* ODBC 2.0 */
+        /* are "quoted" identifiers case-sensitive?  YES! */
+       len = 2;
+        value = SQL_IC_SENSITIVE;
+        break;
+
+    case SQL_ROW_UPDATES: /* ODBC 1.0 */
+        /*  Driver doesn't support keyset-driven or mixed cursors, so
+           not much point in saying row updates are supported
+       */
+        p = globals.lie ? "Y" : "N";
+        break;
+
+    case SQL_SCROLL_CONCURRENCY: /* ODBC 1.0 */
+       len = 4;
+        value = globals.lie ? (SQL_SCCO_READ_ONLY | 
+                               SQL_SCCO_LOCK | 
+                               SQL_SCCO_OPT_ROWVER | 
+                               SQL_SCCO_OPT_VALUES) : (SQL_SCCO_READ_ONLY);
+        break;
+
+    case SQL_SCROLL_OPTIONS: /* ODBC 1.0 */
+       len = 4;
+        value = globals.lie ? (SQL_SO_FORWARD_ONLY | 
+                               SQL_SO_STATIC | 
+                               SQL_SO_KEYSET_DRIVEN | 
+                               SQL_SO_DYNAMIC | 
+                               SQL_SO_MIXED) : (globals.use_declarefetch ? SQL_SO_FORWARD_ONLY : (SQL_SO_FORWARD_ONLY | SQL_SO_STATIC));
+        break;
+
+    case SQL_SEARCH_PATTERN_ESCAPE: /* ODBC 1.0 */
+       p = "";
+        break;
+
+    case SQL_SERVER_NAME: /* ODBC 1.0 */
+       p = CC_get_server(conn);
+        break;
+
+    case SQL_SPECIAL_CHARACTERS: /* ODBC 2.0 */
+        p = "_";
+        break;
+
+    case SQL_STATIC_SENSITIVITY: /* ODBC 2.0 */
+       len = 4;
+        value = globals.lie ? (SQL_SS_ADDITIONS | SQL_SS_DELETIONS | SQL_SS_UPDATES) : 0;
+        break;
+
+    case SQL_STRING_FUNCTIONS: /* ODBC 1.0 */
+       len = 4;
+        value = (SQL_FN_STR_CONCAT |
+               SQL_FN_STR_LCASE | 
+               SQL_FN_STR_LENGTH | 
+               SQL_FN_STR_LOCATE | 
+               SQL_FN_STR_LTRIM | 
+               SQL_FN_STR_RTRIM |
+               SQL_FN_STR_SUBSTRING |
+               SQL_FN_STR_UCASE);
+        break;
+
+    case SQL_SUBQUERIES: /* ODBC 2.0 */
+       /* postgres 6.3 supports subqueries */
+       len = 4;
+        value = (SQL_SQ_QUANTIFIED |
+               SQL_SQ_IN |
+               SQL_SQ_EXISTS |
+               SQL_SQ_COMPARISON);
+        break;
+
+    case SQL_SYSTEM_FUNCTIONS: /* ODBC 1.0 */
+       len = 4;
+       value = 0;
+        break;
+
+    case SQL_TABLE_TERM: /* ODBC 1.0 */
+       p = "table";
+        break;
+
+    case SQL_TIMEDATE_ADD_INTERVALS: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_TIMEDATE_DIFF_INTERVALS: /* ODBC 2.0 */
+       len = 4;
+        value = 0;
+        break;
+
+    case SQL_TIMEDATE_FUNCTIONS: /* ODBC 1.0 */
+       len = 4;
+        value = (SQL_FN_TD_NOW);
+        break;
+
+    case SQL_TXN_CAPABLE: /* ODBC 1.0 */
+        /* Postgres can deal with create or drop table statements in a transaction */
+       len = 2;
+        value = SQL_TC_ALL;
+        break;
+
+    case SQL_TXN_ISOLATION_OPTION: /* ODBC 1.0 */
+       len = 4;
+        value = SQL_TXN_READ_COMMITTED; /* SQL_TXN_SERIALIZABLE; */
+        break;
+
+    case SQL_UNION: /* ODBC 2.0 */
+       /*  unions with all supported in postgres 6.3 */
+       len = 4;
+        value = (SQL_U_UNION | SQL_U_UNION_ALL);
+        break;
+
+    case SQL_USER_NAME: /* ODBC 1.0 */
+       p = CC_get_username(conn);
+        break;
+
+    default:
+        /* unrecognized key */
+        conn->errormsg = "Unrecognized key passed to SQLGetInfo.";
+        conn->errornumber = CONN_NOT_IMPLEMENTED_ERROR;
+       CC_log_error(func, "", conn);
+        return SQL_ERROR;
+    }
 
    result = SQL_SUCCESS;
 
-   mylog("SQLGetInfo: p='%s', len=%d, value=%d, cbMax=%d\n", p ? p : "<NULL>", len, value, cbInfoValueMax);
+   mylog("SQLGetInfo: p='%s', len=%d, value=%d, cbMax=%d\n", p?p:"<NULL>", len, value, cbInfoValueMax);
 
-   /*
-    * NOTE, that if rgbInfoValue is NULL, then no warnings or errors
-    * should result and just pcbInfoValue is returned, which indicates
-    * what length would be required if a real buffer had been passed in.
-    */
-   if (p)
-   {                           /* char/binary data */
+   /*  NOTE, that if rgbInfoValue is NULL, then no warnings or errors should
+       result and just pcbInfoValue is returned, which indicates what length 
+       would be required if a real buffer had been passed in.
+   */
+   if (p) {  /* char/binary data */
        len = strlen(p);
 
-       if (rgbInfoValue)
-       {
-           strncpy_null((char *) rgbInfoValue, p, (size_t) cbInfoValueMax);
+       if (rgbInfoValue) {
+           strncpy_null((char *)rgbInfoValue, p, (size_t)cbInfoValueMax);
 
-           if (len >= cbInfoValueMax)
-           {
+           if (len >= cbInfoValueMax)  {
                result = SQL_SUCCESS_WITH_INFO;
                conn->errornumber = STMT_TRUNCATED;
                conn->errormsg = "The buffer was too small for the result.";
@@ -692,45 +647,41 @@ SQLGetInfo(
        }
    }
 
-   else
-   {                           /* numeric data */
-
-       if (rgbInfoValue)
-       {
-           if (len == 2)
-               *((WORD *) rgbInfoValue) = (WORD) value;
+   else {  /* numeric data */
+       
+       if (rgbInfoValue) {
+       
+           if (len == 2 ) 
+               *((WORD *)rgbInfoValue) = (WORD) value;
            else if (len == 4)
-               *((DWORD *) rgbInfoValue) = (DWORD) value;
+               *((DWORD *)rgbInfoValue) = (DWORD) value;
        }
    }
 
-   if (pcbInfoValue)
+   if (pcbInfoValue) 
        *pcbInfoValue = len;
 
    return result;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
 
-RETCODE SQL_API
-SQLGetTypeInfo(
-              HSTMT hstmt,
-              SWORD fSqlType)
+RETCODE SQL_API SQLGetTypeInfo(
+        HSTMT   hstmt,
+        SWORD   fSqlType)
 {
-   static char *func = "SQLGetTypeInfo";
-   StatementClass *stmt = (StatementClass *) hstmt;
-   TupleNode  *row;
-   int         i;
-
+static char *func = "SQLGetTypeInfo";
+StatementClass *stmt = (StatementClass *) hstmt;
+TupleNode *row;
+int i;
 /* Int4 type; */
-   Int4        pgType;
-   Int2        sqlType;
+Int4 pgType; 
+Int2 sqlType;
 
    mylog("%s: entering...fSqlType = %d\n", func, fSqlType);
 
-   if (!stmt)
-   {
+   if( ! stmt) {
        SC_log_error(func, "", NULL);
        return SQL_INVALID_HANDLE;
    }
@@ -738,8 +689,7 @@ SQLGetTypeInfo(
 
    stmt->manual_result = TRUE;
    stmt->result = QR_Constructor();
-   if (!stmt->result)
-   {
+   if( ! stmt->result) {
        SC_log_error(func, "Error creating result.", stmt);
        return SQL_ERROR;
    }
@@ -763,15 +713,13 @@ SQLGetTypeInfo(
    QR_set_field_info(stmt->result, 13, "MINIMUM_SCALE", PG_TYPE_INT2, 2);
    QR_set_field_info(stmt->result, 14, "MAXIMUM_SCALE", PG_TYPE_INT2, 2);
 
-   for (i = 0, sqlType = sqlTypes[0]; sqlType; sqlType = sqlTypes[++i])
-   {
+   for(i=0, sqlType = sqlTypes[0]; sqlType; sqlType = sqlTypes[++i]) {
        pgType = sqltype_to_pgtype(sqlType);
 
-       if (fSqlType == SQL_ALL_TYPES || fSqlType == sqlType)
-       {
-           row = (TupleNode *) malloc(sizeof(TupleNode) + (15 - 1) *sizeof(TupleField));
+       if (fSqlType == SQL_ALL_TYPES || fSqlType == sqlType) {
+           row = (TupleNode *)malloc(sizeof(TupleNode) + (15 - 1)*sizeof(TupleField));
 
-           /* These values can't be NULL */
+           /*  These values can't be NULL */
            set_tuplefield_string(&row->tuple[0], pgtype_to_name(stmt, pgType));
            set_tuplefield_int2(&row->tuple[1], (Int2) sqlType);
            set_tuplefield_int2(&row->tuple[6], pgtype_nullable(stmt, pgType));
@@ -779,13 +727,10 @@ SQLGetTypeInfo(
            set_tuplefield_int2(&row->tuple[8], pgtype_searchable(stmt, pgType));
            set_tuplefield_int2(&row->tuple[10], pgtype_money(stmt, pgType));
 
-           /*
-            * Localized data-source dependent data type name (always
-            * NULL)
-            */
-           set_tuplefield_null(&row->tuple[12]);
+           /*  Localized data-source dependent data type name (always NULL) */
+           set_tuplefield_null(&row->tuple[12]);   
 
-           /* These values can be NULL */
+           /*  These values can be NULL */
            set_nullfield_int4(&row->tuple[2], pgtype_precision(stmt, pgType, PG_STATIC, PG_STATIC));
            set_nullfield_string(&row->tuple[3], pgtype_literal_prefix(stmt, pgType));
            set_nullfield_string(&row->tuple[4], pgtype_literal_suffix(stmt, pgType));
@@ -800,33 +745,30 @@ SQLGetTypeInfo(
    }
 
 
-   stmt->status = STMT_FINISHED;
-   stmt->currTuple = -1;
+    stmt->status = STMT_FINISHED;
+    stmt->currTuple = -1;
    stmt->rowset_start = -1;
    stmt->current_col = -1;
 
-   return SQL_SUCCESS;
+    return SQL_SUCCESS;
 }
 
-/*     -       -       -       -       -       -       -       -       - */
+/*      -       -       -       -       -       -       -       -       - */
 
-RETCODE SQL_API
-SQLGetFunctions(
-               HDBC hdbc,
-               UWORD fFunction,
-               UWORD FAR *pfExists)
+RETCODE SQL_API SQLGetFunctions(
+        HDBC      hdbc,
+        UWORD     fFunction,
+        UWORD FAR *pfExists)
 {
-   static char *func = "SQLGetFunctions";
+static char *func="SQLGetFunctions";
 
-   mylog("%s: entering...\n", func);
+   mylog( "%s: entering...\n", func);
 
-   if (fFunction == SQL_API_ALL_FUNCTIONS)
-   {
-       if (globals.lie)
-       {
-           int         i;
+    if (fFunction == SQL_API_ALL_FUNCTIONS) {
 
-           memset(pfExists, 0, sizeof(UWORD) * 100);
+       if (globals.lie) {
+           int i;
+           memset(pfExists, 0, sizeof(UWORD)*100);
 
            pfExists[SQL_API_SQLALLOCENV] = TRUE;
            pfExists[SQL_API_SQLFREEENV] = TRUE;
@@ -835,306 +777,179 @@ SQLGetFunctions(
            for (i = SQL_EXT_API_START; i <= SQL_EXT_API_LAST; i++)
                pfExists[i] = TRUE;
        }
-       else
-       {
-           memset(pfExists, 0, sizeof(UWORD) * 100);
+       else {
+           memset(pfExists, 0, sizeof(UWORD)*100);
 
            /* ODBC core functions */
-           pfExists[SQL_API_SQLALLOCCONNECT] = TRUE;
-           pfExists[SQL_API_SQLALLOCENV] = TRUE;
-           pfExists[SQL_API_SQLALLOCSTMT] = TRUE;
-           pfExists[SQL_API_SQLBINDCOL] = TRUE;
-           pfExists[SQL_API_SQLCANCEL] = TRUE;
-           pfExists[SQL_API_SQLCOLATTRIBUTES] = TRUE;
-           pfExists[SQL_API_SQLCONNECT] = TRUE;
-           pfExists[SQL_API_SQLDESCRIBECOL] = TRUE;    /* partial */
-           pfExists[SQL_API_SQLDISCONNECT] = TRUE;
-           pfExists[SQL_API_SQLERROR] = TRUE;
-           pfExists[SQL_API_SQLEXECDIRECT] = TRUE;
-           pfExists[SQL_API_SQLEXECUTE] = TRUE;
-           pfExists[SQL_API_SQLFETCH] = TRUE;
-           pfExists[SQL_API_SQLFREECONNECT] = TRUE;
-           pfExists[SQL_API_SQLFREEENV] = TRUE;
-           pfExists[SQL_API_SQLFREESTMT] = TRUE;
-           pfExists[SQL_API_SQLGETCURSORNAME] = TRUE;
-           pfExists[SQL_API_SQLNUMRESULTCOLS] = TRUE;
-           pfExists[SQL_API_SQLPREPARE] = TRUE;        /* complete? */
-           pfExists[SQL_API_SQLROWCOUNT] = TRUE;
-           pfExists[SQL_API_SQLSETCURSORNAME] = TRUE;
-           pfExists[SQL_API_SQLSETPARAM] = FALSE;      /* odbc 1.0 */
-           pfExists[SQL_API_SQLTRANSACT] = TRUE;
+           pfExists[SQL_API_SQLALLOCCONNECT]     = TRUE;
+           pfExists[SQL_API_SQLALLOCENV]         = TRUE;
+           pfExists[SQL_API_SQLALLOCSTMT]        = TRUE;
+           pfExists[SQL_API_SQLBINDCOL]          = TRUE;  
+           pfExists[SQL_API_SQLCANCEL]           = TRUE;
+           pfExists[SQL_API_SQLCOLATTRIBUTES]    = TRUE;
+           pfExists[SQL_API_SQLCONNECT]          = TRUE;
+           pfExists[SQL_API_SQLDESCRIBECOL]      = TRUE;  /* partial */
+           pfExists[SQL_API_SQLDISCONNECT]       = TRUE;
+           pfExists[SQL_API_SQLERROR]            = TRUE;
+           pfExists[SQL_API_SQLEXECDIRECT]       = TRUE;
+           pfExists[SQL_API_SQLEXECUTE]          = TRUE;
+           pfExists[SQL_API_SQLFETCH]            = TRUE;
+           pfExists[SQL_API_SQLFREECONNECT]      = TRUE;
+           pfExists[SQL_API_SQLFREEENV]          = TRUE;
+           pfExists[SQL_API_SQLFREESTMT]         = TRUE;
+           pfExists[SQL_API_SQLGETCURSORNAME]    = TRUE;
+           pfExists[SQL_API_SQLNUMRESULTCOLS]    = TRUE;
+           pfExists[SQL_API_SQLPREPARE]          = TRUE;  /* complete? */
+           pfExists[SQL_API_SQLROWCOUNT]         = TRUE;
+           pfExists[SQL_API_SQLSETCURSORNAME]    = TRUE;
+           pfExists[SQL_API_SQLSETPARAM]         = FALSE; /* odbc 1.0 */
+           pfExists[SQL_API_SQLTRANSACT]         = TRUE;
 
            /* ODBC level 1 functions */
-           pfExists[SQL_API_SQLBINDPARAMETER] = TRUE;
-           pfExists[SQL_API_SQLCOLUMNS] = TRUE;
-           pfExists[SQL_API_SQLDRIVERCONNECT] = TRUE;
-           pfExists[SQL_API_SQLGETCONNECTOPTION] = TRUE;       /* partial */
-           pfExists[SQL_API_SQLGETDATA] = TRUE;
-           pfExists[SQL_API_SQLGETFUNCTIONS] = TRUE;
-           pfExists[SQL_API_SQLGETINFO] = TRUE;
-           pfExists[SQL_API_SQLGETSTMTOPTION] = TRUE;  /* partial */
-           pfExists[SQL_API_SQLGETTYPEINFO] = TRUE;
-           pfExists[SQL_API_SQLPARAMDATA] = TRUE;
-           pfExists[SQL_API_SQLPUTDATA] = TRUE;
-           pfExists[SQL_API_SQLSETCONNECTOPTION] = TRUE;       /* partial */
-           pfExists[SQL_API_SQLSETSTMTOPTION] = TRUE;
-           pfExists[SQL_API_SQLSPECIALCOLUMNS] = TRUE;
-           pfExists[SQL_API_SQLSTATISTICS] = TRUE;
-           pfExists[SQL_API_SQLTABLES] = TRUE;
+           pfExists[SQL_API_SQLBINDPARAMETER]    = TRUE;
+           pfExists[SQL_API_SQLCOLUMNS]          = TRUE;
+           pfExists[SQL_API_SQLDRIVERCONNECT]    = TRUE;
+           pfExists[SQL_API_SQLGETCONNECTOPTION] = TRUE;  /* partial */
+           pfExists[SQL_API_SQLGETDATA]          = TRUE;
+           pfExists[SQL_API_SQLGETFUNCTIONS]     = TRUE;                                                       
+           pfExists[SQL_API_SQLGETINFO]          = TRUE;
+           pfExists[SQL_API_SQLGETSTMTOPTION]    = TRUE;  /* partial */
+           pfExists[SQL_API_SQLGETTYPEINFO]      = TRUE;
+           pfExists[SQL_API_SQLPARAMDATA]        = TRUE;
+           pfExists[SQL_API_SQLPUTDATA]          = TRUE;
+           pfExists[SQL_API_SQLSETCONNECTOPTION] = TRUE;  /* partial */
+           pfExists[SQL_API_SQLSETSTMTOPTION]    = TRUE;
+           pfExists[SQL_API_SQLSPECIALCOLUMNS]   = TRUE;
+           pfExists[SQL_API_SQLSTATISTICS]       = TRUE;
+           pfExists[SQL_API_SQLTABLES]           = TRUE;
 
            /* ODBC level 2 functions */
-           pfExists[SQL_API_SQLBROWSECONNECT] = FALSE;
+           pfExists[SQL_API_SQLBROWSECONNECT]    = FALSE;
            pfExists[SQL_API_SQLCOLUMNPRIVILEGES] = FALSE;
-           pfExists[SQL_API_SQLDATASOURCES] = FALSE;   /* only implemented by
-                                                        * DM */
-           pfExists[SQL_API_SQLDESCRIBEPARAM] = FALSE; /* not properly
-                                                        * implemented */
-           pfExists[SQL_API_SQLDRIVERS] = FALSE;       /* only implemented by
-                                                        * DM */
-           pfExists[SQL_API_SQLEXTENDEDFETCH] = TRUE;
-           pfExists[SQL_API_SQLFOREIGNKEYS] = TRUE;
-           pfExists[SQL_API_SQLMORERESULTS] = TRUE;
-           pfExists[SQL_API_SQLNATIVESQL] = TRUE;
-           pfExists[SQL_API_SQLNUMPARAMS] = TRUE;
-           pfExists[SQL_API_SQLPARAMOPTIONS] = FALSE;
-           pfExists[SQL_API_SQLPRIMARYKEYS] = TRUE;
+           pfExists[SQL_API_SQLDATASOURCES]      = FALSE;  /* only implemented by DM */
+           pfExists[SQL_API_SQLDESCRIBEPARAM]    = FALSE;  /* not properly implemented */
+           pfExists[SQL_API_SQLDRIVERS]          = FALSE;  /* only implemented by DM */
+           pfExists[SQL_API_SQLEXTENDEDFETCH]    = TRUE;
+           pfExists[SQL_API_SQLFOREIGNKEYS]      = TRUE;
+           pfExists[SQL_API_SQLMORERESULTS]      = TRUE;
+           pfExists[SQL_API_SQLNATIVESQL]        = TRUE;
+           pfExists[SQL_API_SQLNUMPARAMS]        = TRUE;
+           pfExists[SQL_API_SQLPARAMOPTIONS]     = FALSE;
+           pfExists[SQL_API_SQLPRIMARYKEYS]      = TRUE;
            pfExists[SQL_API_SQLPROCEDURECOLUMNS] = FALSE;
-           pfExists[SQL_API_SQLPROCEDURES] = FALSE;
-           pfExists[SQL_API_SQLSETPOS] = TRUE;
-           pfExists[SQL_API_SQLSETSCROLLOPTIONS] = TRUE;       /* odbc 1.0 */
-           pfExists[SQL_API_SQLTABLEPRIVILEGES] = FALSE;
+           pfExists[SQL_API_SQLPROCEDURES]       = FALSE;
+           pfExists[SQL_API_SQLSETPOS]           = TRUE;
+           pfExists[SQL_API_SQLSETSCROLLOPTIONS] = TRUE;   /* odbc 1.0 */
+           pfExists[SQL_API_SQLTABLEPRIVILEGES]  = FALSE;
        }
-   }
-   else
-   {
+    } else {
+
        if (globals.lie)
            *pfExists = TRUE;
-       else
-       {
-           switch (fFunction)
-           {
-               case SQL_API_SQLALLOCCONNECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLALLOCENV:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLALLOCSTMT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLBINDCOL:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLCANCEL:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLCOLATTRIBUTES:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLCONNECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLDESCRIBECOL:
-                   *pfExists = TRUE;
-                   break;      /* partial */
-               case SQL_API_SQLDISCONNECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLERROR:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLEXECDIRECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLEXECUTE:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLFETCH:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLFREECONNECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLFREEENV:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLFREESTMT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLGETCURSORNAME:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLNUMRESULTCOLS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLPREPARE:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLROWCOUNT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLSETCURSORNAME:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLSETPARAM:
-                   *pfExists = FALSE;
-                   break;      /* odbc 1.0 */
-               case SQL_API_SQLTRANSACT:
-                   *pfExists = TRUE;
-                   break;
 
-                   /* ODBC level 1 functions */
-               case SQL_API_SQLBINDPARAMETER:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLCOLUMNS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLDRIVERCONNECT:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLGETCONNECTOPTION:
-                   *pfExists = TRUE;
-                   break;      /* partial */
-               case SQL_API_SQLGETDATA:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLGETFUNCTIONS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLGETINFO:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLGETSTMTOPTION:
-                   *pfExists = TRUE;
-                   break;      /* partial */
-               case SQL_API_SQLGETTYPEINFO:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLPARAMDATA:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLPUTDATA:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLSETCONNECTOPTION:
-                   *pfExists = TRUE;
-                   break;      /* partial */
-               case SQL_API_SQLSETSTMTOPTION:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLSPECIALCOLUMNS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLSTATISTICS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLTABLES:
-                   *pfExists = TRUE;
-                   break;
-
-                   /* ODBC level 2 functions */
-               case SQL_API_SQLBROWSECONNECT:
-                   *pfExists = FALSE;
-                   break;
-               case SQL_API_SQLCOLUMNPRIVILEGES:
-                   *pfExists = FALSE;
-                   break;
-               case SQL_API_SQLDATASOURCES:
-                   *pfExists = FALSE;
-                   break;      /* only implemented by DM */
-               case SQL_API_SQLDESCRIBEPARAM:
-                   *pfExists = FALSE;
-                   break;      /* not properly implemented */
-               case SQL_API_SQLDRIVERS:
-                   *pfExists = FALSE;
-                   break;      /* only implemented by DM */
-               case SQL_API_SQLEXTENDEDFETCH:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLFOREIGNKEYS:
-                   *pfExists = TRUE;
-                   break;
-               case SQL_API_SQLMORERESULTS:
-                   *pfExists = TRUE;
-                   break;
-