]> granicus.if.org Git - postgresql/commitdiff
Improve declare/fetch mode a little.
authorHiroshi Inoue <inoue@tpf.co.jp>
Sat, 8 Sep 2001 16:20:16 +0000 (16:20 +0000)
committerHiroshi Inoue <inoue@tpf.co.jp>
Sat, 8 Sep 2001 16:20:16 +0000 (16:20 +0000)
Add a new DSN option for PREPARE hadling.

Hiroshi Inoue

12 files changed:
src/interfaces/odbc/connection.c
src/interfaces/odbc/connection.h
src/interfaces/odbc/convert.c
src/interfaces/odbc/dlg_specific.c
src/interfaces/odbc/dlg_specific.h
src/interfaces/odbc/execute.c
src/interfaces/odbc/psqlodbc.h
src/interfaces/odbc/psqlodbc.rc
src/interfaces/odbc/qresult.c
src/interfaces/odbc/resource.h
src/interfaces/odbc/results.c
src/interfaces/odbc/statement.c

index 9ae6a223a96b8d7c74b03c90cbbd3bac2c73aa4d..3c784ead445221bbb0faa283c121ccab2f35249f 100644 (file)
@@ -938,7 +938,7 @@ QResultClass *
 CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 {
        QResultClass *result_in = NULL, *res = NULL, *retres = NULL;
-       char            swallow;
+       char            swallow, *wq;
        int                     id;
        SocketClass *sock = self->sock;
        int             maxlen, empty_reqs;
@@ -999,7 +999,9 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
 
        ReadyToReturn = FALSE;
        empty_reqs = 0;
-       if (strcmp(query, " ") == 0)
+       for (wq = query; isspace(*wq); wq++)
+               ;
+       if (*wq == '\0')
                empty_reqs = 1;
        while (!ReadyToReturn)
        {
index 902480896fd0eeb107cab6e8f8e18e4791576883..24931cef2b26600ead245c16d752e23f31750150 100644 (file)
@@ -159,6 +159,7 @@ typedef struct
        char            translation_dll[MEDIUM_REGISTRY_LEN];
        char            translation_option[SMALL_REGISTRY_LEN];
        char            focus_password;
+       char            disallow_premature;
        GLOBAL_VALUES   drivers; /* moved from driver's option */
 } ConnInfo;
 
index 52303511e16bb0a16cfc0bfc70c379c55091d67a..9c1c6e3737add14d9bdf4f93d3cabd72334844de 100644 (file)
@@ -1001,10 +1001,8 @@ copy_statement_with_parameters(StatementClass *stmt)
 #ifdef DRIVER_CURSOR_IMPLEMENT
        BOOL search_from_pos = FALSE;
 #endif /* DRIVER_CURSOR_IMPLEMENT */
-#ifdef PREPARE_TRIAL
-       prepare_dummy_cursor = stmt->pre_executing;
-#endif /* PREPARE_TRIAL */
-
+       if (ci->disallow_premature)
+               prepare_dummy_cursor = stmt->pre_executing;
 
        if (!old_statement)
        {
@@ -1704,7 +1702,6 @@ copy_statement_with_parameters(StatementClass *stmt)
        if (search_from_pos)
                stmt->options.scroll_concurrency = SQL_CONCUR_READ_ONLY;
 #endif /* DRIVER_CURSOR_IMPLEMENT */
-#ifdef PREPARE_TRIAL
        if (prepare_dummy_cursor && SC_is_pre_executable(stmt))
        {
                char fetchstr[128];     
@@ -1715,7 +1712,6 @@ copy_statement_with_parameters(StatementClass *stmt)
                CVT_APPEND_STR(fetchstr);
                stmt->inaccurate_result = TRUE;
        }
-#endif /* PREPARE_TRIAL */
 
        return SQL_SUCCESS;
 }
index 7a8ad095b5331358e1acbb3a9d18b5407cac7a85..dcbd69be6b6d03b8b9e1a9ef3582391dec6a393a 100644 (file)
@@ -245,11 +245,13 @@ driver_optionsProc(HWND hdlg,
                        ci = (ConnInfo *) lParam;
                        if (ci && ci->dsn && ci->dsn[0])
                        {
+                               SetWindowText(hdlg, "Advanced Options (Common)");
                                driver_optionsDraw(hdlg, NULL, 0, TRUE);
                        }
                        else
                        {
                                CheckDlgButton(hdlg, DRV_OR_DSN, 1);
+                               SetWindowText(hdlg, "Advanced Options (Connection)");
                                ShowWindow(GetDlgItem(hdlg, DRV_OR_DSN), SW_HIDE);
                                driver_optionsDraw(hdlg, ci, 1, FALSE);
                        }
@@ -284,10 +286,14 @@ driver_optionsProc(HWND hdlg,
                                                if (IsDlgButtonChecked(hdlg, DRV_OR_DSN))
                                                {
                                                        ConnInfo   *ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
+                                                       SetWindowText(hdlg, "Advanced Options (per DSN)");
                                                        driver_optionsDraw(hdlg, ci, ci ? 1 : 0, ci == NULL);
                                                }
                                                else
+                                               {
+                                                       SetWindowText(hdlg, "Advanced Options (Common)");
                                                        driver_optionsDraw(hdlg, NULL, 0, TRUE);
+                                               }
                                        }
                                        break;
                        }
@@ -337,6 +343,7 @@ ds_optionsProc(HWND hdlg,
                        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_DISALLOWPREMATURE, ci->disallow_premature);
 
                        EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
 
@@ -371,6 +378,7 @@ ds_optionsProc(HWND hdlg,
                                        sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
 
                                        sprintf(ci->row_versioning, "%d", IsDlgButtonChecked(hdlg, DS_ROWVERSIONING));
+                                       ci->disallow_premature = IsDlgButtonChecked(hdlg, DS_DISALLOWPREMATURE);
 
                                        /* OID Options */
                                        sprintf(ci->fake_oid_index, "%d", IsDlgButtonChecked(hdlg, DS_FAKEOIDINDEX));
@@ -620,8 +628,13 @@ copyAttributes(ConnInfo *ci, const char *attribute, const char *value)
                decode(value, ci->conn_settings);
                /* strcpy(ci->conn_settings, value); */
        }
+       else if (stricmp(attribute, INI_DISALLOWPREMATURE) == 0 || stricmp(attribute, "C3") == 0)
+       {
+               ci->disallow_premature = atoi(value);
+               /* 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',disallow_premature=%d)\n", ci->dsn, ci->server, ci->database, ci->username, ci->password, ci->port, ci->onlyread, ci->protocol, ci->conn_settings, ci->disallow_premature);
 }
 
 void
@@ -715,7 +728,8 @@ void
 getDSNinfo(ConnInfo *ci, char overwrite)
 {
        char       *DSN = ci->dsn;
-       char            encoded_conn_settings[LARGE_REGISTRY_LEN];
+       char            encoded_conn_settings[LARGE_REGISTRY_LEN],
+                       temp[SMALL_REGISTRY_LEN];
 
 /*
  *     If a driver keyword was present, then dont use a DSN and return.
@@ -784,8 +798,13 @@ getDSNinfo(ConnInfo *ci, char overwrite)
        if (ci->translation_option[0] == '\0' || overwrite)
                SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
 
+       if (ci->disallow_premature == 0 || overwrite)
+       {
+               SQLGetPrivateProfileString(DSN, INI_DISALLOWPREMATURE, "", temp, sizeof(temp), ODBC_INI);
+               ci->disallow_premature = atoi(temp);
+       }
+
        /* Allow override of odbcinst.ini parameters here */
-       /* getGlobalDefaults(DSN, ODBC_INI, TRUE); */
        getCommonDefaults(DSN, ODBC_INI, ci);
 
        qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
@@ -823,7 +842,8 @@ void
 writeDSNinfo(const ConnInfo *ci)
 {
        const char   *DSN = ci->dsn;
-       char            encoded_conn_settings[LARGE_REGISTRY_LEN];
+       char            encoded_conn_settings[LARGE_REGISTRY_LEN],
+                       temp[SMALL_REGISTRY_LEN];
 
        encode(ci->conn_settings, encoded_conn_settings);
 
@@ -891,6 +911,12 @@ writeDSNinfo(const ConnInfo *ci)
                                                                 INI_CONNSETTINGS,
                                                                 encoded_conn_settings,
                                                                 ODBC_INI);
+
+       sprintf(temp, "%d", ci->disallow_premature); 
+       SQLWritePrivateProfileString(DSN,
+                                                                INI_DISALLOWPREMATURE,
+                                                                temp,
+                                                                ODBC_INI);
 }
 
 
index 6d9885434f5e71a006498be2c37a0f520ae642d5..8d37eb8a91a1faa9e75608853fe02fcf983f2460 100644 (file)
@@ -95,6 +95,7 @@
 #define INI_TRANSLATIONNAME                            "TranslationName"
 #define INI_TRANSLATIONDLL                             "TranslationDLL"
 #define INI_TRANSLATIONOPTION                  "TranslationOption"
+#define INI_DISALLOWPREMATURE                  "DisallowPremature"
 
 
 /*     Connection Defaults */
index 653539ddba0cbf100cd0f7c89f9f1d7edfc0cc32..b57a98b34c49c4a3f55c4f04c02148b59a636bef 100644 (file)
@@ -340,8 +340,12 @@ PGAPI_Execute(
                return retval;
 
        mylog("   stmt_with_params = '%s'\n", stmt->stmt_with_params);
-#ifdef PREPARE_TRIAL
-       if (stmt->inaccurate_result)
+       /*
+        *      Get the field info for the prepared
+        *      query using dummy backward fetch.
+        */
+       if (stmt->inaccurate_result && conn->connInfo.disallow_premature)
+       {
                if (SC_is_pre_executable(stmt))
                {
                        BOOL    in_trans = CC_is_in_trans(conn);
@@ -365,7 +369,8 @@ PGAPI_Execute(
                }
                else
                        return SQL_SUCCESS;
-#endif /* PREPARE_TRIAL */
+       }
+
        return SC_execute(stmt);
 }
 
index a6c5d9eda34122f2257c69b539ceec339369f3b6..98fd47205f9cd96c470fd92373369d0933c9ae68 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Comments:           See "notice.txt" for copyright and license information.
  *
- * $Id: psqlodbc.h,v 1.47 2001/09/07 06:02:22 inoue Exp $
+ * $Id: psqlodbc.h,v 1.48 2001/09/08 16:20:16 inoue Exp $
  *
  */
 
@@ -42,7 +42,7 @@ typedef UInt4 Oid;
 #define DRIVERNAME                                     "PostgreSQL ODBC"
 #define DBMS_NAME                                      "PostgreSQL"
 
-#define POSTGRESDRIVERVERSION          "07.01.0006"
+#define POSTGRESDRIVERVERSION          "07.01.0007"
 
 #ifdef WIN32
 #define DRIVER_FILE_NAME                       "PSQLODBC.DLL"
index aa149ade93864b1c1db2b7ba3f47c604eeea4f3e..182d7f6dbf421baa08805a6d59051ac178d8b7ab 100644 (file)
@@ -149,6 +149,8 @@ BEGIN
                     BS_AUTOCHECKBOX | WS_TABSTOP,149,13,72,10
     CONTROL         "Show System &Tables",DS_SHOWSYSTEMTABLES,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,45,28,88,10
+    CONTROL         "Disallow &Premature",DS_DISALLOWPREMATURE,"Button",
+                    BS_AUTOCHECKBOX | WS_TABSTOP,149,28,72,10
     GROUPBOX        "Protocol",IDC_STATIC,43,44,180,25
     CONTROL         "7.X,6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON | 
                     WS_GROUP,53,54,47,10
@@ -264,6 +266,8 @@ BEGIN
                     BS_AUTOCHECKBOX | WS_TABSTOP,130,10,85,10
     CONTROL         "Show System &Tables",DS_SHOWSYSTEMTABLES,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,25,25,85,10
+    CONTROL         "Disallow &Premature",DS_DISALLOWPREMATURE,"Button",
+                    BS_AUTOCHECKBOX | WS_TABSTOP,130,25,85,10
     GROUPBOX        "Protocol",IDC_STATIC,15,40,180,25
     CONTROL         "7.X,6.4+",DS_PG64,"Button",BS_AUTORADIOBUTTON | WS_GROUP,25,
                     50,35,10
@@ -350,8 +354,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 7,1,0,6
- PRODUCTVERSION 7,1,0,6
+ FILEVERSION 7,1,0,7
+ PRODUCTVERSION 7,1,0,7
  FILEFLAGSMASK 0x3L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -373,14 +377,14 @@ BEGIN
             VALUE "CompanyName", "Insight Distribution Systems\0"
 #endif
             VALUE "FileDescription", "PostgreSQL Driver\0"
-            VALUE "FileVersion", " 07.01.0006\0"
+            VALUE "FileVersion", " 07.01.0007\0"
             VALUE "InternalName", "psqlodbc\0"
             VALUE "LegalCopyright", "\0"
             VALUE "LegalTrademarks", "ODBC(TM) is a trademark of Microsoft Corporation.  Microsoft® is a registered trademark of Microsoft Corporation. Windows(TM) is a trademark of Microsoft Corporation.\0"
             VALUE "OriginalFilename", "psqlodbc.dll\0"
             VALUE "PrivateBuild", "\0"
             VALUE "ProductName", "Microsoft Open Database Connectivity\0"
-            VALUE "ProductVersion", " 07.01.0006\0"
+            VALUE "ProductVersion", " 07.01.0007\0"
             VALUE "SpecialBuild", "\0"
         END
     END
index 151f2ab2176e4c3b2fa3cf177c88a3d99b071144..103b299ed36f581225a89a8ecf22d8cf84f74d93 100644 (file)
@@ -238,6 +238,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
        if (conn != NULL)
        {
                ConnInfo *ci = &(conn->connInfo);
+               BOOL    fetch_cursor = (ci->drivers.use_declarefetch && cursor && cursor[0]);
                self->conn = conn;
 
                mylog("QR_fetch_tuples: cursor = '%s', self->cursor=%u\n", (cursor == NULL) ? "" : cursor, self->cursor);
@@ -245,7 +246,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
                if (self->cursor)
                        free(self->cursor);
 
-               if (ci->drivers.use_declarefetch)
+               if (fetch_cursor)
                {
                        if (!cursor || cursor[0] == '\0')
                        {
@@ -275,7 +276,7 @@ QR_fetch_tuples(QResultClass *self, ConnectionClass *conn, char *cursor)
 
                mylog("QR_fetch_tuples: past CI_read_fields: num_fields = %d\n", self->num_fields);
 
-               if (ci->drivers.use_declarefetch)
+               if (fetch_cursor)
                        tuple_size = self->cache_size;
                else
                        tuple_size = TUPLE_MALLOC_INC;
@@ -432,7 +433,7 @@ QR_next_tuple(QResultClass *self)
                if (!self->inTuples)
                {
                        ci = &(self->conn->connInfo);
-                       if (!ci->drivers.use_declarefetch)
+                       if (!self->cursor || !ci->drivers.use_declarefetch)
                        {
                                mylog("next_tuple: ALL_ROWS: done, fcount = %d, fetch_count = %d\n", fcount, fetch_count);
                                self->tupleField = NULL;
@@ -535,7 +536,7 @@ QR_next_tuple(QResultClass *self)
                        case 'B':                       /* Tuples in binary format */
                        case 'D':                       /* Tuples in ASCII format  */
 
-                               if (!ci->drivers.use_declarefetch && self->fcount >= self->count_allocated)
+                               if ((!self->cursor || !ci->drivers.use_declarefetch) && self->fcount >= self->count_allocated)
                                {
                                        int tuple_size = self->count_allocated;
 
index 5ac559c478d4c49c1a24d37bf90fe2f19e8de9ea..452ff929fa23fb2310275f43087bc70ff2d13532 100644 (file)
@@ -51,6 +51,7 @@
 #define DS_PG63                         1058\r
 #define DRV_OR_DSN                      1059\r
 #define DRV_DEBUG                      1060\r
+#define DS_DISALLOWPREMATURE           1061\r
 \r
 // Next default values for new objects\r
 // \r
@@ -58,7 +59,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS\r
 #define _APS_NEXT_RESOURCE_VALUE        105\r
 #define _APS_NEXT_COMMAND_VALUE         40001\r
-#define _APS_NEXT_CONTROL_VALUE         1061\r
+#define _APS_NEXT_CONTROL_VALUE         1062\r
 #define _APS_NEXT_SYMED_VALUE           101\r
 #endif\r
 #endif\r
index b63a214b816625e6c1714537c86cbb25d5bcbacb..7d29fb0ce22b3857213472424745a08ec719b0e8 100644 (file)
@@ -73,7 +73,7 @@ PGAPI_RowCount(
 
                        if (res && pcrow)
                        {
-                               *pcrow = ci->drivers.use_declarefetch ? -1 : QR_get_num_tuples(res);
+                               *pcrow = SC_is_fetchcursor(stmt) ? -1 : QR_get_num_tuples(res);
                                return SQL_SUCCESS;
                        }
                }
@@ -728,7 +728,7 @@ PGAPI_GetData(
                }
        }
 
-       if (stmt->manual_result || !ci->drivers.use_declarefetch)
+       if (stmt->manual_result || !SC_is_fetchcursor(stmt))
        {
                /* make sure we're positioned on a valid row */
                num_rows = QR_get_num_tuples(res);
@@ -929,7 +929,7 @@ PGAPI_ExtendedFetch(
        }
        ci = &(SC_get_conn(stmt)->connInfo);
 
-       if (ci->drivers.use_declarefetch && !stmt->manual_result)
+       if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
        {
                if (fFetchType != SQL_FETCH_NEXT)
                {
@@ -1108,7 +1108,7 @@ PGAPI_ExtendedFetch(
         * Handle Declare Fetch style specially because the end is not really
         * the end...
         */
-       if (ci->drivers.use_declarefetch && !stmt->manual_result)
+       if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
        {
                if (QR_end_tuples(res))
                        return SQL_NO_DATA_FOUND;
@@ -1190,7 +1190,7 @@ PGAPI_ExtendedFetch(
        stmt->currTuple = stmt->rowset_start;
 
        /* For declare/fetch, need to reset cursor to beginning of rowset */
-       if (ci->drivers.use_declarefetch && !stmt->manual_result)
+       if (SC_is_fetchcursor(stmt) && !stmt->manual_result)
                QR_set_position(res, 0);
 
        /* Set the number of rows retrieved */
index bb4fab9bccf9d62f274be212ba3d6ddae2e89f2c..584d5a710d7643d97576490ed52fd007d51dd186 100644 (file)
@@ -728,7 +728,7 @@ SC_fetch(StatementClass *self)
 
        mylog("manual_result = %d, use_declarefetch = %d\n", self->manual_result, ci->drivers.use_declarefetch);
 
-       if (self->manual_result || !ci->drivers.use_declarefetch)
+       if (self->manual_result || !SC_is_fetchcursor(self))
        {
                if (self->currTuple >= QR_get_num_tuples(res) - 1 ||
                        (self->options.maxRows > 0 && self->currTuple == self->options.maxRows - 1))
@@ -818,7 +818,7 @@ SC_fetch(StatementClass *self)
                                value = QR_get_value_manual(res, self->currTuple, lf);
                                mylog("manual_result\n");
                        }
-                       else if (ci->drivers.use_declarefetch)
+                       else if (SC_is_fetchcursor(self))
                                value = QR_get_value_backend(res, lf);
                        else
                                value = QR_get_value_backend_row(res, self->currTuple, lf);
@@ -914,7 +914,7 @@ SC_execute(StatementClass *self)
         * OTHER.
         */
        if (!self->internal && !CC_is_in_trans(conn) &&
-           ((ci->drivers.use_declarefetch && self->statement_type == STMT_TYPE_SELECT) ||
+           (SC_is_fetchcursor(self) ||
             (!CC_is_in_autocommit(conn) && self->statement_type != STMT_TYPE_OTHER)))
        {
                mylog("   about to begin a transaction on statement = %u\n", self);
@@ -964,7 +964,7 @@ SC_execute(StatementClass *self)
                /* send the declare/select */
                self->result = CC_send_query(conn, self->stmt_with_params, NULL);
 
-               if (ci->drivers.use_declarefetch && self->result != NULL &&
+               if (SC_is_fetchcursor(self) && self->result != NULL &&
                        QR_command_successful(self->result))
                {
                        QR_Destructor(self->result);