Add an option to explicitly force/avoid the use of libpq library.
authorHiroshi Inoue <inoue@tpf.co.jp>
Tue, 16 Sep 2014 07:51:38 +0000 (16:51 +0900)
committerHiroshi Inoue <inoue@tpf.co.jp>
Tue, 23 Sep 2014 13:31:33 +0000 (22:31 +0900)
connection.c
connection.h
dlg_specific.c
dlg_specific.h

index bea8a8cdb2182ea951458e8a3dc90b68c474fc78..ba64dbdbee44a3724e3b3583ab884db178de0caf 100644 (file)
@@ -300,6 +300,7 @@ CC_conninfo_init(ConnInfo *conninfo, UInt4 option)
    conninfo->gssauth_use_gssapi = -1;
    conninfo->keepalive_idle = -1;
    conninfo->keepalive_interval = -1;
+   conninfo->prefer_libpq = -1;
 #ifdef _HANDLE_ENLIST_IN_DTC_
    conninfo->xa_opt = -1;
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
@@ -333,6 +334,7 @@ CC_copy_conninfo(ConnInfo *ci, const ConnInfo *sci)
    CORR_STRCPY(translation_dll);
    CORR_STRCPY(translation_option);
    CORR_VALCPY(focus_password);
+   CORR_VALCPY(prefer_libpq);
    NAME_TO_NAME(ci->conn_settings, sci->conn_settings);
    CORR_VALCPY(disallow_premature);
    CORR_VALCPY(allow_keyset);
@@ -2183,6 +2185,11 @@ CC_connect(ConnectionClass *self, char password_req, char *salt_para)
 
    mylog("sslmode=%s\n", self->connInfo.sslmode);
 #ifdef USE_LIBPQ
+   if (0 < ci->prefer_libpq)
+       call_libpq = TRUE;
+   else if (0 == ci->prefer_libpq)
+       call_libpq = FALSE;
+   else
 #ifdef USE_SSPI
    if (0 != self->svcs_allowed)
        ;
index 5bc3df95697aa93e360c62271807ea354d05ea99..89d4ce44f82fb7b306469203b2b47b7ae7d76e00 100644 (file)
@@ -298,6 +298,7 @@ typedef struct
    char        translation_dll[MEDIUM_REGISTRY_LEN];
    char        translation_option[SMALL_REGISTRY_LEN];
    char        focus_password;
+   signed char prefer_libpq;
    pgNAME      conn_settings;
    signed char disallow_premature;
    signed char allow_keyset;
index 85e45470b932fc7eacc8bc4eed0daea2189c52fa..078c54e5945c69964946540da533f70e112b2175 100644 (file)
@@ -220,11 +220,27 @@ makeKeepaliveConnectString(char *target, const ConnInfo *ci, BOOL abbrev)
    return target;
 }
 
+static char *
+makePreferLibpqConnectString(char *target, const ConnInfo *ci, BOOL abbrev)
+{
+   char    *buf = target;
+   *buf = '\0';
+
+   if (ci->prefer_libpq < 0)
+       return target;
+
+   if (abbrev)
+       sprintf(buf, ABBR_PREFERLIBPQ "=%u;", ci->prefer_libpq);
+   else
+       sprintf(buf, INI_PREFERLIBPQ "=%u;", ci->prefer_libpq);
+   return target;
+}
+
 void
 makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len)
 {
    char        got_dsn = (ci->dsn[0] != '\0');
-   char        encoded_item[LARGE_REGISTRY_LEN], keepaliveStr[64];
+   char        encoded_item[LARGE_REGISTRY_LEN], keepaliveStr[64], preferLibpqStr[64];
    ssize_t     hlen, nlen, olen;
    /*BOOL      abbrev = (len <= 400);*/
    BOOL        abbrev = (len < 1024) || 0 < ci->force_abbrev_connstr;
@@ -296,6 +312,7 @@ inolog("hlen=%d", hlen);
            INI_USESERVERSIDEPREPARE "=%d;"
            INI_LOWERCASEIDENTIFIER "=%d;"
            "%s"
+           "%s"
 #ifdef WIN32
            INI_GSSAUTHUSEGSSAPI "=%d;"
 #endif /* WIN32 */
@@ -335,6 +352,7 @@ inolog("hlen=%d", hlen);
            ,ci->use_server_side_prepare
            ,ci->lower_case_identifier
            ,makeKeepaliveConnectString(keepaliveStr, ci, FALSE)
+           ,makePreferLibpqConnectString(preferLibpqStr, ci, FALSE)
 #ifdef WIN32
            ,ci->gssauth_use_gssapi
 #endif /* WIN32 */
@@ -429,6 +447,7 @@ inolog("hlen=%d", hlen);
                INI_INT8AS "=%d;"
                ABBR_EXTRASYSTABLEPREFIXES "=%s;"
                "%s"
+               "%s"
                INI_ABBREVIATE "=%02x%x",
                encoded_item,
                ci->drivers.fetch_max,
@@ -438,6 +457,7 @@ inolog("hlen=%d", hlen);
                ci->int8_as,
                ci->drivers.extra_systable_prefixes,
                makeKeepaliveConnectString(keepaliveStr, ci, TRUE),
+               makePreferLibpqConnectString(preferLibpqStr, ci, TRUE),
                EFFECTIVE_BIT_COUNT, flag);
        if (olen < nlen && (PROTOCOL_74(ci) || ci->rollback_on_error >= 0))
        {
@@ -637,6 +657,8 @@ copyAttributes(ConnInfo *ci, const char *attribute, const char *value)
        ci->keepalive_idle = atoi(value);
    else if (stricmp(attribute, INI_KEEPALIVEINTERVAL) == 0 || stricmp(attribute, ABBR_KEEPALIVEINTERVAL) == 0)
        ci->keepalive_interval = atoi(value);
+   else if (stricmp(attribute, INI_PREFERLIBPQ) == 0 || stricmp(attribute, ABBR_PREFERLIBPQ) == 0)
+       ci->prefer_libpq = atoi(value);
    else if (stricmp(attribute, INI_SSLMODE) == 0 || stricmp(attribute, ABBR_SSLMODE) == 0)
    {
        switch (value[0])
@@ -1032,6 +1054,12 @@ getDSNinfo(ConnInfo *ci, char overwrite)
            if (0 == (ci->keepalive_interval = atoi(temp)))
                ci->keepalive_interval = -1;
    }
+   if (ci->prefer_libpq < 0 || overwrite)
+   {
+       SQLGetPrivateProfileString(DSN, INI_PREFERLIBPQ, "-1", temp, sizeof(temp), ODBC_INI);
+       if (temp[0])
+           ci->prefer_libpq = atoi(temp);
+   }
 
    if (ci->sslmode[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_SSLMODE, "", ci->sslmode, sizeof(ci->sslmode), ODBC_INI);
@@ -1334,6 +1362,11 @@ writeDSNinfo(const ConnInfo *ci)
                                 INI_KEEPALIVEINTERVAL,
                                 temp,
                                 ODBC_INI);
+   sprintf(temp, "%d", ci->prefer_libpq);
+   SQLWritePrivateProfileString(DSN,
+                                INI_PREFERLIBPQ,
+                                temp,
+                                ODBC_INI);
 #ifdef _HANDLE_ENLIST_IN_DTC_
    sprintf(temp, "%d", ci->xa_opt);
    SQLWritePrivateProfileString(DSN, INI_XAOPT, temp, ODBC_INI);
index 80022cfefb421de6059eaa66e86d2a4e0b8e6f6b..c1106c8162787cdda589e54d5189d0a48d8b1fd7 100644 (file)
@@ -152,6 +152,8 @@ extern "C" {
 #define INI_KEEPALIVEINTERVAL      "KeepaliveInterval"
 #define ABBR_KEEPALIVEINTERVAL     "D2"
 #define INI_DTCLOG         "Dtclog"
+#define INI_PREFERLIBPQ            "PreferLibpq"
+#define ABBR_PREFERLIBPQ       "D3"
 
 #define    SSLMODE_DISABLE     "disable"
 #define    SSLMODE_ALLOW       "allow"