Remove REFCUR_SUPPORT, add FetchRefcursors setting
authorAdrian Grucza <adrian.grucza@iress.com>
Wed, 12 May 2021 13:16:35 +0000 (23:16 +1000)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Tue, 25 May 2021 10:13:49 +0000 (19:13 +0900)
dlg_specific.c
dlg_specific.h
dlg_wingui.c
psqlodbc.h
psqlodbc.rc
resource.h
statement.c

index 3f2192c91f9d454f39230709ac346992a49137b4..45662a679271b1ab199d9906659823742e4f0f7a 100644 (file)
@@ -369,6 +369,7 @@ MYLOG(DETAIL_LOG_LEVEL, "hlen=" FORMAT_SSIZE_T "\n", hlen);
            "%s"        /* INIKEEPALIVE TIME/INTERVAL */
            ABBR_NUMERIC_AS "=%d;"
            INI_OPTIONAL_ERRORS "=%d;"
+           INI_FETCHREFCURSORS "=%d;"
 #ifdef _HANDLE_ENLIST_IN_DTC_
            INI_XAOPT "=%d" /* XAOPT */
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
@@ -403,6 +404,7 @@ MYLOG(DETAIL_LOG_LEVEL, "hlen=" FORMAT_SSIZE_T "\n", hlen);
            ,makeKeepaliveConnectString(keepaliveStr, sizeof(keepaliveStr), ci, FALSE)
            ,ci->numeric_as
            ,ci->optional_errors
+           ,ci->fetch_refcursors
 #ifdef _HANDLE_ENLIST_IN_DTC_
            ,ci->xa_opt
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
@@ -461,6 +463,8 @@ MYLOG(DETAIL_LOG_LEVEL, "hlen=" FORMAT_SSIZE_T "\n", hlen);
            flag |= BIT_LOWERCASEIDENTIFIER;
        if (ci->optional_errors)
            flag |= BIT_OPTIONALERRORS;
+       if (ci->fetch_refcursors)
+           flag |= BIT_FETCHREFCURSORS;
 
        if (ci->sslmode[0])
        {
@@ -583,6 +587,7 @@ unfoldCXAttribute(ConnInfo *ci, const char *value)
    ci->use_server_side_prepare = (char)((flag & BIT_USESERVERSIDEPREPARE) != 0);
    ci->lower_case_identifier = (char)((flag & BIT_LOWERCASEIDENTIFIER) != 0);
    ci->optional_errors = (char)((flag & BIT_OPTIONALERRORS) != 0);
+   ci->fetch_refcursors = (char)((flag & BIT_FETCHREFCURSORS) != 0);
 }
 
 BOOL
@@ -793,6 +798,8 @@ copyConnAttributes(ConnInfo *ci, const char *attribute, const char *value)
        ci->drivers.bools_as_char = atoi(value);
    else if (stricmp(attribute, INI_EXTRASYSTABLEPREFIXES) == 0 || stricmp(attribute, ABBR_EXTRASYSTABLEPREFIXES) == 0)
        STRCPY_FIXED(ci->drivers.extra_systable_prefixes, value);
+   else if (stricmp(attribute, INI_FETCHREFCURSORS) == 0 || stricmp(attribute, ABBR_FETCHREFCURSORS) == 0)
+       ci->fetch_refcursors = atoi(value);
    else
        found = FALSE;
 
@@ -842,6 +849,7 @@ getCiDefaults(ConnInfo *ci)
                ci->wcs_debug = 1;
    }
    ci->disable_convert_func = 0;
+   ci->fetch_refcursors = DEFAULT_FETCHREFCURSORS;
 #ifdef _HANDLE_ENLIST_IN_DTC_
    ci->xa_opt = DEFAULT_XAOPT;
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
@@ -1082,6 +1090,9 @@ MYLOG(0, "drivername=%s\n", drivername);
    if (SQLGetPrivateProfileString(DSN, INI_SSLMODE, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
        STRCPY_FIXED(ci->sslmode, temp);
 
+   if (SQLGetPrivateProfileString(DSN, INI_FETCHREFCURSORS, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
+       ci->fetch_refcursors = atoi(temp);
+
 #ifdef _HANDLE_ENLIST_IN_DTC_
    if (SQLGetPrivateProfileString(DSN, INI_XAOPT, NULL_STRING, temp, sizeof(temp), ODBC_INI) > 0)
        ci->xa_opt = atoi(temp);
@@ -1374,6 +1385,11 @@ writeDSNinfo(const ConnInfo *ci)
                                 INI_IGNORETIMEOUT,
                                 temp,
                                 ODBC_INI);
+   ITOA_FIXED(temp, ci->fetch_refcursors);
+   SQLWritePrivateProfileString(DSN,
+                                INI_FETCHREFCURSORS,
+                                temp,
+                                ODBC_INI);
 #ifdef _HANDLE_ENLIST_IN_DTC_
    ITOA_FIXED(temp, ci->xa_opt);
    SQLWritePrivateProfileString(DSN, INI_XAOPT, temp, ODBC_INI);
@@ -1789,6 +1805,7 @@ CC_conninfo_init(ConnInfo *conninfo, UInt4 option)
    conninfo->batch_size = DEFAULT_BATCH_SIZE;
    conninfo->ignore_timeout = DEFAULT_IGNORETIMEOUT;
    conninfo->wcs_debug = -1;
+   conninfo->fetch_refcursors = -1;
 #ifdef _HANDLE_ENLIST_IN_DTC_
    conninfo->xa_opt = -1;
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
@@ -1890,6 +1907,7 @@ CC_copy_conninfo(ConnInfo *ci, const ConnInfo *sci)
    CORR_VALCPY(keepalive_interval);
    CORR_VALCPY(batch_size);
    CORR_VALCPY(ignore_timeout);
+   CORR_VALCPY(fetch_refcursors);
 #ifdef _HANDLE_ENLIST_IN_DTC_
    CORR_VALCPY(xa_opt);
 #endif
index c5857501ca3ad2c449abbd7c00f35acf668d4767..87d32c756610165b1a5d3dc7a50e73f2e8f96b84 100644 (file)
@@ -173,6 +173,8 @@ extern "C" {
 #define INI_IGNORETIMEOUT      "IgnoreTimeout"
 #define ABBR_IGNORETIMEOUT     "D9"
 #define INI_DTCLOG         "Dtclog"
+#define INI_FETCHREFCURSORS        "FetchRefcursors"
+#define ABBR_FETCHREFCURSORS       "DA"
 /* "PreferLibpq", abbreviated "D4", used to mean whether to prefer libpq.
  * libpq is now required
 #define INI_PREFERLIBPQ            "PreferLibpq"
@@ -220,6 +222,7 @@ extern "C" {
 #define BIT_USESERVERSIDEPREPARE       (1L<<25)
 #define BIT_LOWERCASEIDENTIFIER            (1L<<26)
 #define BIT_OPTIONALERRORS         (1L<<27)
+#define BIT_FETCHREFCURSORS            (1L<<28)
 
 #define EFFECTIVE_BIT_COUNT            28
 
@@ -274,6 +277,7 @@ extern "C" {
 #define DEFAULT_OPTIONAL_ERRORS        0
 #define DEFAULT_BATCH_SIZE     100
 #define DEFAULT_IGNORETIMEOUT      0
+#define DEFAULT_FETCHREFCURSORS        0
 
 #ifdef _HANDLE_ENLIST_IN_DTC_
 #define DEFAULT_XAOPT          1
index 276d8f160e784fc9920b446606a28306e917326e..c348ccc258c1eb48f63daabb00666a47f8de3d92 100644 (file)
@@ -571,6 +571,7 @@ ds_options_update(HWND hdlg, ConnInfo *ci)
    ci->allow_keyset = IsDlgButtonChecked(hdlg, DS_UPDATABLECURSORS);
    ci->use_server_side_prepare = IsDlgButtonChecked(hdlg, DS_SERVERSIDEPREPARE);
    ci->bytea_as_longvarbinary = IsDlgButtonChecked(hdlg, DS_BYTEAASLONGVARBINARY);
+   ci->fetch_refcursors = IsDlgButtonChecked(hdlg, DS_FETCH_REFCURSORS);
    /*ci->lower_case_identifier = IsDlgButtonChecked(hdlg, DS_LOWERCASEIDENTIFIER);*/
 
    /* OID Options */
@@ -721,6 +722,7 @@ ds_options2Proc(HWND hdlg,
            CheckDlgButton(hdlg, DS_UPDATABLECURSORS, ci->allow_keyset);
            CheckDlgButton(hdlg, DS_SERVERSIDEPREPARE, ci->use_server_side_prepare);
            CheckDlgButton(hdlg, DS_BYTEAASLONGVARBINARY, ci->bytea_as_longvarbinary);
+           CheckDlgButton(hdlg, DS_FETCH_REFCURSORS, ci->fetch_refcursors);
            /*CheckDlgButton(hdlg, DS_LOWERCASEIDENTIFIER, ci->lower_case_identifier);*/
 
            EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), atoi(ci->show_oid_column));
index f41ff9b199b1f760b98df281740321466272ed17..ca8bab55a2855aa62ca64c8f1eea2f0e48bdcce8 100644 (file)
@@ -645,6 +645,7 @@ typedef struct
    signed char numeric_as;
    signed char optional_errors;
    signed char ignore_timeout;
+   signed char fetch_refcursors;
    UInt4       extra_opts;
    Int4        keepalive_idle;
    Int4        keepalive_interval;
index 2c76ed65eb1e5de4ecc93b5586fde49154d2c7a3..75269c9d4ee6e36a7923124f49731ea8d9315ec5 100644 (file)
@@ -221,6 +221,8 @@ BEGIN
     PUSHBUTTON      "\93K\97p",IDAPPLY,128,ENDLINE_Y,50,14
     CONTROL         "bytea\82รฐLO\82ร†\82ยต\82ร„\88ยต\82ยค",DS_BYTEAASLONGVARBINARY,"Button",
                     BS_AUTOCHECKBOX | WS_TABSTOP,15,85,87,10
+    CONTROL         "\8aerefcursor\82ยฉ\82รง\8c\8b\89รŠ\82รฐ\8eรฆ\93ยพ\82ยต\82รœ\82ยท",DS_FETCH_REFCURSORS,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,85,140,10
 END
 
 #define    DTC_GRP_X   10
@@ -638,6 +640,8 @@ BEGIN
     GROUPBOX        "Int8 As",IDC_STATIC,5,97,256,25
     CONTROL         "default",DS_INT8_AS_DEFAULT,"Button",BS_AUTORADIOBUTTON | 
                     WS_GROUP,12,107,40,10
+    CONTROL         "Fetch result from each refcursor",DS_FETCH_REFCURSORS,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,163,84,122,10
     CONTROL         "bigint",DS_INT8_AS_BIGINT,"Button",BS_AUTORADIOBUTTON | 
                     WS_TABSTOP,55,107,35,10
     CONTROL         "numeric",DS_INT8_AS_NUMERIC,"Button",BS_AUTORADIOBUTTON | 
index fac1fbb5b8509d181229c57c2198e459adaa994a..483e623456ad5fa375285b16a579fabc96c72bea 100644 (file)
 #define DS_NUMERIC_AS_LONGVARCHAR  1111
 #define DS_BATCH_SIZE          1112
 #define DS_IGNORETIMEOUT       1113
+#define DS_FETCH_REFCURSORS        1114
 
 // Next default values for new objects
 //
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        106
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1114
+#define _APS_NEXT_CONTROL_VALUE         1115
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
index 972aa50f49484c540b7a2b48ad6f3fe99dd93f10..9f47b40fa3e0c38da719049d29943c9667642c9d 100644 (file)
@@ -2243,33 +2243,30 @@ MYLOG(DETAIL_LOG_LEVEL, "!!%p->miscinfo=%x res=%p\n", self, self->miscinfo, firs
    {
        Int2    io, out;
        has_out_para = (CountParameters(self, NULL, &io, &out) > 0);
-/*
- * I'm not sure if the following REFCUR_SUPPORT stuff is valuable
- * or not.
- */
-#ifdef REFCUR_SUPPORT
+if (ci->fetch_refcursors)
+{
 
-MYLOG(DETAIL_LOG_LEVEL, "!!! numfield=%d field_type=%u\n", QR_NumResultCols(res), QR_get_field_type(res, 0));
+MYLOG(DETAIL_LOG_LEVEL, "!!! numfield=%d field_type=%u\n", QR_NumResultCols(rhold.first), QR_get_field_type(rhold.first, 0));
        if (!has_out_para &&
-           0 < QR_NumResultCols(res) &&
-           PG_TYPE_REFCURSOR == QR_get_field_type(res, 0))
+           0 < QR_NumResultCols(rhold.first) &&
+           PG_TYPE_REFCURSOR == QR_get_field_type(rhold.first, 0))
        {
            char    fetch[128];
            int stmt_type = self->statement_type;
 
-           STR_TO_NAME(self->cursor_name, QR_get_value_backend_text(res, 0, 0));
-           QR_Destructor(res);
+           STR_TO_NAME(self->cursor_name, QR_get_value_backend_text(rhold.first, 0, 0));
+           QR_Destructor(rhold.first);
            SC_init_Result(self);
            SC_set_fetchcursor(self);
            qi.result_in = NULL;
            qi.cursor = SC_cursor_name(self);
-           qi.cache_size = qi.row_size = ci->drivers.fetch_max;
+           qi.fetch_size = qi.row_size = ci->drivers.fetch_max;
            SPRINTF_FIXED(fetch, "fetch " FORMAT_LEN " in \"%s\"", qi.fetch_size, SC_cursor_name(self));
-           res = CC_send_query(conn, fetch, &qi, qflag | READ_ONLY_QUERY, SC_get_ancestor(self));
-           if (NULL != res)
-               SC_set_Result(self, res);
+           rhold.first = CC_send_query(conn, fetch, &qi, qflag | READ_ONLY_QUERY, SC_get_ancestor(self));
+           if (NULL != rhold.first)
+               SC_set_Result(self, rhold.first);
        }
-#endif /* REFCUR_SUPPORT */
+}
    }
    if (has_out_para)
    {   /* get the return value of the procedure call */