Don't propgate the connection level statment options to the internal statements.
authorHiroshi Inoue <inoue@tpf.co.jp>
Mon, 8 Nov 2010 14:49:36 +0000 (14:49 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Mon, 8 Nov 2010 14:49:36 +0000 (14:49 +0000)
This fixes an infinite loop reported by Nelson Andre.

connection.c
info.c
multibyte.c
odbcapi.c
odbcapi30.c
parse.c
pgapifunc.h
results.c
statement.c
statement.h
version.h

index 423fa8f6bc94b0a84b266f4ab74c2401e37d2f14..59c38de6029b45aaa0060b9cbfbf4d5a8e451463 100644 (file)
@@ -3370,7 +3370,7 @@ CC_setenv(ConnectionClass *self)
  * has not transitioned to "connected" yet.
  */
 
-   result = PGAPI_AllocStmt(self, &hstmt);
+   result = PGAPI_AllocStmt(self, &hstmt, 0);
    if (!SQL_SUCCEEDED(result))
        return FALSE;
    stmt = (StatementClass *) hstmt;
@@ -3447,7 +3447,7 @@ CC_send_settings(ConnectionClass *self)
  * has not transitioned to "connected" yet.
  */
 
-   result = PGAPI_AllocStmt(self, &hstmt);
+   result = PGAPI_AllocStmt(self, &hstmt, 0);
    if (!SQL_SUCCEEDED(result))
        return FALSE;
    stmt = (StatementClass *) hstmt;
@@ -3610,7 +3610,7 @@ CC_lookup_pg_version(ConnectionClass *self)
  * This function must use the local odbc API functions since the odbc state
  * has not transitioned to "connected" yet.
  */
-   result = PGAPI_AllocStmt(self, &hstmt);
+   result = PGAPI_AllocStmt(self, &hstmt, 0);
    if (!SQL_SUCCEEDED(result))
        return;
    stmt = (StatementClass *) hstmt;
diff --git a/info.c b/info.c
index fe1735f9ff161ce7b768a0a198420781505c614d..df671983fcebdf2656aca1ae267b8e74ddf5045a 100644 (file)
--- a/info.c
+++ b/info.c
@@ -1565,7 +1565,7 @@ PGAPI_Tables(
    conn = SC_get_conn(stmt);
    ci = &(conn->connInfo);
 
-   result = PGAPI_AllocStmt(conn, &htbl_stmt);
+   result = PGAPI_AllocStmt(conn, &htbl_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for PGAPI_Tables result.", func);
@@ -2140,7 +2140,7 @@ retry_public_schema:
        strcat(columns_query, " order by c.relname, attnum");
    }
 
-   result = PGAPI_AllocStmt(conn, &hcol_stmt);
+   result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for PGAPI_Columns result.", func);
@@ -2777,7 +2777,7 @@ retry_public_schema:
        my_strcat1(columns_query, " and u.usename %s'%.*s'", eq_string, escSchemaName, SQL_NTS);
 
 
-   result = PGAPI_AllocStmt(conn, &hcol_stmt);
+   result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for SQLSpecialColumns result.", func);
@@ -3057,7 +3057,7 @@ PGAPI_Statistics(
     * we need to get a list of the field names first, so we can return
     * them later.
     */
-   result = PGAPI_AllocStmt(conn, &hcol_stmt);
+   result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "PGAPI_AllocStmt failed in PGAPI_Statistics for columns.", func);
@@ -3141,7 +3141,7 @@ PGAPI_Statistics(
    }
 
    /* get a list of indexes on this table */
-   result = PGAPI_AllocStmt(conn, &hindx_stmt);
+   result = PGAPI_AllocStmt(conn, &hindx_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "PGAPI_AllocStmt failed in SQLStatistics for indices.", func);
@@ -3622,7 +3622,7 @@ PGAPI_PrimaryKeys(
    QR_set_field_info_v(res, PKS_PK_NAME, "PK_NAME", PG_TYPE_VARCHAR, MAX_INFO_STRING);
 
    conn = SC_get_conn(stmt);
-   result = PGAPI_AllocStmt(conn, &htbl_stmt);
+   result = PGAPI_AllocStmt(conn, &htbl_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for Primary Key result.", func);
@@ -4124,7 +4124,7 @@ PGAPI_ForeignKeys_old(
    SC_set_current_col(stmt, -1);
 
    conn = SC_get_conn(stmt);
-   result = PGAPI_AllocStmt(conn, &htbl_stmt);
+   result = PGAPI_AllocStmt(conn, &htbl_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for PGAPI_ForeignKeys result.", func);
@@ -4350,7 +4350,7 @@ PGAPI_ForeignKeys_old(
            goto cleanup;
        }
 
-       keyresult = PGAPI_AllocStmt(conn, &hpkey_stmt);
+       keyresult = PGAPI_AllocStmt(conn, &hpkey_stmt, 0);
        if (!SQL_SUCCEEDED(keyresult))
        {
            SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for PGAPI_ForeignKeys (pkeys) result.", func);
@@ -4722,7 +4722,7 @@ PGAPI_ForeignKeys_old(
        /*
         *  get pk_name here
         */
-       keyresult = PGAPI_AllocStmt(conn, &hpkey_stmt);
+       keyresult = PGAPI_AllocStmt(conn, &hpkey_stmt, 0);
        if (!SQL_SUCCEEDED(keyresult))
        {
            SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "Couldn't allocate statement for PGAPI_ForeignKeys (pkeys) result.", func);
index 1f8ff714b800aebfe5de1f061ca1a0ae1a9fc1f8..fc8f2264a664f83be6b8ec3712491491326323e6 100644 (file)
@@ -486,7 +486,7 @@ CC_lookup_cs_old(ConnectionClass *self)
    HSTMT       hstmt;
    RETCODE     result;
 
-   result = PGAPI_AllocStmt(self, &hstmt);
+   result = PGAPI_AllocStmt(self, &hstmt, 0);
    if (!SQL_SUCCEEDED(result))
        return encstr;
 
index 4d29fd4907dbe49891eaa6d8efdd733a03d23f47..b39db60263a82bc468bae07520fcbe97f8a46d6c 100644 (file)
--- a/odbcapi.c
+++ b/odbcapi.c
@@ -72,7 +72,7 @@ SQLAllocStmt(HDBC ConnectionHandle,
    mylog("[SQLAllocStmt]");
    ENTER_CONN_CS(conn);
    CC_clear_error(conn);
-   ret = PGAPI_AllocStmt(ConnectionHandle, StatementHandle);
+   ret = PGAPI_AllocStmt(ConnectionHandle, StatementHandle, PODBC_EXTERNAL_STATEMENT | PODBC_INHERIT_CONNECT_OPTIONS);
    LEAVE_CONN_CS(conn);
    return ret;
 }
index fc0d7dbb6434de62f3edd15d18327f5c6b5b7f92..a16d851279c184a5d61927a6d64de668f4563048 100644 (file)
@@ -52,7 +52,7 @@ SQLAllocHandle(SQLSMALLINT HandleType,
            break;
        case SQL_HANDLE_STMT:
            ENTER_CONN_CS((ConnectionClass *) InputHandle);
-           ret = PGAPI_AllocStmt(InputHandle, OutputHandle);
+           ret = PGAPI_AllocStmt(InputHandle, OutputHandle, PODBC_EXTERNAL_STATEMENT | PODBC_INHERIT_CONNECT_OPTIONS);
            LEAVE_CONN_CS((ConnectionClass *) InputHandle);
            break;
        case SQL_HANDLE_DESC:
diff --git a/parse.c b/parse.c
index 0674cdf637e514266f8a44ff47f36e30ed83904b..88a11a72f7c49b740c6943d6c62cce6203adbc2f 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -789,7 +789,7 @@ getColumnsInfo(ConnectionClass *conn, TABLE_INFO *wti, OID greloid, StatementCla
 
    if (NULL == conn)
        conn = SC_get_conn(stmt);
-   result = PGAPI_AllocStmt(conn, &hcol_stmt);
+   result = PGAPI_AllocStmt(conn, &hcol_stmt, 0);
    if (!SQL_SUCCEEDED(result))
    {
        if (stmt)
@@ -1091,7 +1091,7 @@ inolog("%s:fields=%d ntab=%d\n", func, nfields, stmt->ntab);
        char        keycolnam[MAX_INFO_STRING];
        SQLLEN      keycollen;
 
-       ret = PGAPI_AllocStmt(conn, &pstmt);
+       ret = PGAPI_AllocStmt(conn, &pstmt, 0);
        if (!SQL_SUCCEEDED(ret))
            return ret;
        oneti = ti[0];
index 0de820732d8ba5b6969add80a0770bcfb99c6bcc..fc4f8ec0fe69a556256de867434ac774f888cf5e 100644 (file)
@@ -17,6 +17,9 @@ extern "C" {
 #define    PODBC_NOT_SEARCH_PATTERN    1L
 #define    PODBC_SEARCH_PUBLIC_SCHEMA  (1L << 1)
 #define    PODBC_SEARCH_BY_IDS     (1L << 2)
+/* Internal flags for PGAPI_AllocStmt functions */
+#define    PODBC_EXTERNAL_STATEMENT    1L  /* visible to the driver manager */
+#define    PODBC_INHERIT_CONNECT_OPTIONS   (1L << 1)
 /* Internal flags for PGAPI_Exec... functions */
 #define    PODBC_WITH_HOLD         1L
 #define    PODBC_PER_STATEMENT_ROLLBACK    (1L << 1)
@@ -28,7 +31,7 @@ RETCODE SQL_API PGAPI_AllocConnect(HENV EnvironmentHandle,
                   HDBC FAR * ConnectionHandle);
 RETCODE SQL_API PGAPI_AllocEnv(HENV FAR * EnvironmentHandle);
 RETCODE SQL_API PGAPI_AllocStmt(HDBC ConnectionHandle,
-               HSTMT *StatementHandle);
+               HSTMT *StatementHandle, UDWORD flag);
 RETCODE SQL_API PGAPI_BindCol(HSTMT StatementHandle,
              SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
              PTR TargetValue, SQLLEN BufferLength,
index 0344e0858018727b03cfd94017b2ee23dc38b469..20e23b51c5778fbe9861538b4441c63f18a7a5d7 100644 (file)
--- a/results.c
+++ b/results.c
@@ -3697,7 +3697,7 @@ SC_pos_update(StatementClass *stmt,
        if (PG_VERSION_GE(conn, 8.2))
            strcat(updstr, " returning ctid");
        mylog("updstr=%s\n", updstr);
-       if (PGAPI_AllocStmt(conn, &hstmt) != SQL_SUCCESS)
+       if (PGAPI_AllocStmt(conn, &hstmt, 0) != SQL_SUCCESS)
        {
            SC_set_error(s.stmt, STMT_NO_MEMORY_ERROR, "internal AllocStmt error", func);
            return SQL_ERROR;
@@ -4090,7 +4090,7 @@ SC_pos_add(StatementClass *stmt,
        sprintf(addstr, "insert into \"%s\".\"%s\" (", SAFE_NAME(s.stmt->ti[0]->schema_name), SAFE_NAME(s.stmt->ti[0]->table_name));
    else
        sprintf(addstr, "insert into \"%s\" (", SAFE_NAME(s.stmt->ti[0]->table_name));
-   if (PGAPI_AllocStmt(conn, &hstmt) != SQL_SUCCESS)
+   if (PGAPI_AllocStmt(conn, &hstmt, 0) != SQL_SUCCESS)
    {
        SC_set_error(s.stmt, STMT_NO_MEMORY_ERROR, "internal AllocStmt error", func);
        return SQL_ERROR;
index bc72bf07e6bb3e7f215b3ffd2ef495cfd84d366b..9a760ef62ed994ec0eebd9fc2395da7103d6ac2a 100644 (file)
@@ -161,7 +161,7 @@ static struct
 
 RETCODE        SQL_API
 PGAPI_AllocStmt(HDBC hdbc,
-               HSTMT FAR * phstmt)
+               HSTMT FAR * phstmt, UDWORD flag)
 {
    CSTR func = "PGAPI_AllocStmt";
    ConnectionClass *conn = (ConnectionClass *) hdbc;
@@ -198,9 +198,18 @@ PGAPI_AllocStmt(HDBC hdbc,
 
    *phstmt = (HSTMT) stmt;
 
+   stmt->iflag = flag;
    /* Copy default statement options based from Connection options */
-   stmt->options = stmt->options_orig = conn->stmtOptions;
-   stmt->ardi.ardopts = conn->ardOptions;
+   if (0 != (PODBC_INHERIT_CONNECT_OPTIONS & flag))
+   {
+       stmt->options = stmt->options_orig = conn->stmtOptions;
+       stmt->ardi.ardopts = conn->ardOptions;
+   }
+   else
+   {
+       stmt->options_orig = stmt->options;
+       InitializeARDFields(&stmt->ardi.ardopts);
+   }
    ardopts = SC_get_ARDF(stmt);
    bookmark = ARD_AllocBookmark(ardopts);
 
@@ -345,6 +354,7 @@ static void SC_init_parse_method(StatementClass *self)
 
    self->parse_method = 0;
    if (!conn)  return;
+   if (0 == (PODBC_EXTERNAL_STATEMENT & self->iflag))  return;
    if (self->catalog_result) return;
    if (conn->connInfo.drivers.parse)
        SC_set_parse_forced(self);
@@ -369,6 +379,7 @@ SC_Constructor(ConnectionClass *conn)
        rv->prepared = NOT_YET_PREPARED;
        rv->status = STMT_ALLOCATED;
        rv->internal = FALSE;
+       rv->iflag = 0;
        rv->plan_name = NULL;
        rv->transition_status = STMT_TRANSITION_UNALLOCATED;
        rv->multi_statement = -1; /* unknown */
index 78f7fec1d0f20898291ea31877ba6437743a72fe..21b4362a97c822afac682a9c053cd375ae376022 100644 (file)
@@ -226,6 +226,7 @@ struct StatementClass_
    Int2        data_at_exec; /* Number of params needing SQLPutData */
    Int2        current_exec_param; /* The current parameter for
                         * SQLPutData */
+   UDWORD      iflag;      /* PGAPI_AllocStmt parameter */
    PutDataInfo pdata_info;
    po_ind_t    parse_status;
    po_ind_t    proc_return;
index 0e4bde9d31e18a99bec6a1ce863ec92be854f048..ae1ec69733ed0505774673f013fadc917a94cf9a 100644 (file)
--- a/version.h
+++ b/version.h
@@ -12,6 +12,6 @@
 #define POSTGRESDRIVERVERSION      "09.00.0201"
 #define POSTGRES_RESOURCE_VERSION  "09.00.0201\0"
 #define PG_DRVFILE_VERSION     9,0,02,01
-#define PG_BUILD_VERSION       "201011060001"
+#define PG_BUILD_VERSION       "201011080001"
 
 #endif