Remove the stuff about Debug and Commlog from getCommonDefaults().
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Tue, 16 May 2017 09:57:39 +0000 (18:57 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Fri, 19 May 2017 03:44:21 +0000 (12:44 +0900)
Now per connection Debug/Commlog info are handled in getDSNinfo().
Global Debug/Commlog info are get/set using functions get(set)GlobalDebug(Commlog)().

connection.c
dlg_specific.c
dlg_specific.h
dlg_wingui.c
execute.c
info.c
mylog.c
mylog.h
psqlodbc.c
psqlsetup.c

index a78428b4e72ce4682a0c600d227f980f39bf6d84..c0e28165937ec305a3fc60bfc30f2c9d9ab8f19b 100644 (file)
@@ -54,8 +54,6 @@ static int  CC_close_eof_cursors(ConnectionClass *self);
 
 static void LIBPQ_update_transaction_status(ConnectionClass *self);
 
-extern GLOBAL_VALUES globals;
-
 
 static void CC_set_error_if_not_set(ConnectionClass *self, int errornumber, const char *errormsg, const char *func)
 {
index 93782af43324dc629abfd6414bcbf0f1cf86210b..b8dd874b689aec7a38b4a3713b72f4270a905328 100644 (file)
@@ -800,6 +800,11 @@ getDSNdefaults(ConnInfo *ci)
 {
    mylog("calling getDSNdefaults\n");
 
+   if (ci->drivers.debug < 0)
+       ci->drivers.debug = DEFAULT_DEBUG;
+   if (ci->drivers.commlog < 0)
+       ci->drivers.commlog = DEFAULT_COMMLOG;
+
    if (ci->onlyread[0] == '\0')
        sprintf(ci->onlyread, "%d", globals.onlyread);
 
@@ -868,17 +873,6 @@ getDriverNameFromDSN(const char *dsn, char *driver_name, int namelen)
    return SQLGetPrivateProfileString(ODBC_DATASOURCES, dsn, "", driver_name, namelen, ODBC_INI);
 }
 
-int
-getLogDir(char *dir, int dirmax)
-{
-   return SQLGetPrivateProfileString(DBMS_NAME, INI_LOGDIR, "", dir, dirmax, ODBCINST_INI);
-}
-
-int
-setLogDir(const char *dir)
-{
-   return SQLWritePrivateProfileString(DBMS_NAME, INI_LOGDIR, dir, ODBCINST_INI);
-}
 
 void
 getDSNinfo(ConnInfo *ci, char overwrite)
@@ -944,6 +938,20 @@ getDSNinfo(ConnInfo *ci, char overwrite)
    if (ci->port[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);
 
+   /* It's appropriate to handle debug and commlog here */
+   if (ci->drivers.debug < 0 || overwrite)
+   {
+       SQLGetPrivateProfileString(DSN, INI_DEBUG, "", temp, sizeof(temp), ODBC_INI);
+       if (temp[0])
+           ci->drivers.debug = atoi(temp);
+   }
+   if (ci->drivers.commlog < 0 || overwrite)
+   {
+       SQLGetPrivateProfileString(DSN, INI_COMMLOG, "", temp, sizeof(temp), ODBC_INI);
+       if (temp[0])
+           ci->drivers.commlog = atoi(temp);
+   }
+
    if (ci->onlyread[0] == '\0' || overwrite)
        SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->onlyread, sizeof(ci->onlyread), ODBC_INI);
 
@@ -1165,6 +1173,9 @@ writeDriverCommoninfo(const char *fileName, const char *sectionName,
            sectionName = DBMS_NAME;
    }
 
+   if (stricmp(ODBCINST_INI, fileName) == 0)
+       return errc;
+
    sprintf(tmp, "%d", comval->commlog);
    if (!SQLWritePrivateProfileString(sectionName, INI_COMMLOG, tmp, fileName))
        errc--;
@@ -1173,9 +1184,6 @@ writeDriverCommoninfo(const char *fileName, const char *sectionName,
    if (!SQLWritePrivateProfileString(sectionName, INI_DEBUG, tmp, fileName))
        errc--;
 
-   if (stricmp(ODBCINST_INI, fileName) == 0)
-       return errc;
-
    sprintf(tmp, "%d", comval->fetch_max);
    if (!SQLWritePrivateProfileString(sectionName, INI_FETCH, tmp, fileName))
        errc--;
@@ -1392,45 +1400,16 @@ getCommonDefaults(const char *section, const char *filename, ConnInfo *ci)
    BOOL    inst_position = (stricmp(filename, ODBCINST_INI) == 0);
    const char *drivername = (inst_position ? section : ci->drivername);
 
-   mylog("%s:setting %s position of %p\n", func, filename, ci);
+   mylog("%s:setting %s position of %s(%p)\n", func, filename, section, ci);
    if (ci)
        comval = &(ci->drivers);
    else
        comval = &globals;
 
    /*
-    * globals.debug or globals.commlog means whether take mylog or commlog
-    * out of the connection time or not but doesn't mean the default of
-    * ci->drivers.debug(commlog).
+    * It's not appropriate to handle debug or commlog here.
+    * Now they are handled in getDSNinfo().
     */
-   /* Debug is stored in the driver section */
-   SQLGetPrivateProfileString(section, INI_DEBUG, "",
-                  temp, sizeof(temp), filename);
-   if (temp[0])
-   {
-       if (inst_position && ci)
-           ;
-       else
-           comval->debug = atoi(temp);
-   }
-   else if (inst_position)
-       comval->debug = DEFAULT_DEBUG;
-
-   /* CommLog is stored in the driver section */
-   SQLGetPrivateProfileString(section, INI_COMMLOG, "",
-                  temp, sizeof(temp), filename);
-   if (temp[0])
-   {
-       if (inst_position && ci)
-           ;
-       else
-           comval->commlog = atoi(temp);
-   }
-   else if (inst_position)
-       comval->commlog = DEFAULT_COMMLOG;
-
-   if (!ci)
-       logs_on_off(0, 0, 0);
 
    /*
     * If inst_position of xxxxxx is present(usually not present),
@@ -1841,6 +1820,7 @@ CC_conninfo_init(ConnInfo *conninfo, UInt4 option)
    if (0 != (CLEANUP_FOR_REUSE & option))
        CC_conninfo_release(conninfo);
    memset(conninfo, 0, sizeof(ConnInfo));
+
    conninfo->allow_keyset = -1;
    conninfo->lf_conversion = -1;
    conninfo->true_is_minus1 = -1;
@@ -1865,6 +1845,8 @@ CC_conninfo_init(ConnInfo *conninfo, UInt4 option)
 #endif /* _HANDLE_ENLIST_IN_DTC_ */
    if (0 != (COPY_GLOBALS & option))
        copy_globals(&(conninfo->drivers), &globals);
+   conninfo->drivers.debug = -1;
+   conninfo->drivers.commlog = -1;
 }
 
 #define    CORR_STRCPY(item)   strncpy_null(to->item, from->item, sizeof(to->item))
index 9b36ce8f07cc8ada6782c81baf49d9e06a5e7fb1..22d08c358ca725a1af456b2e138700952f37ac58 100644 (file)
@@ -313,8 +313,6 @@ void        makeConnectString(char *connect_string, const ConnInfo *ci, UWORD);
 BOOL       copyAttributes(ConnInfo *ci, const char *attribute, const char *value);
 BOOL       copyCommonAttributes(ConnInfo *ci, const char *attribute, const char *value);
 int    getDriverNameFromDSN(const char *dsn, char *driver_name, int namelen);
-int    getLogDir(char *dir, int dirmax);
-int    setLogDir(const char *dir);
 UInt4  getExtraOptions(const ConnInfo *);
 BOOL   setExtraOptions(ConnInfo *, const char *str, const char *format);
 char   *extract_extra_attribute_setting(const pgNAME setting, const char *attr);
index dba706dca009e1c63aa45cefed90a0edf05789ac..8ade36a0c74f414d3a2614ed6e764e67c9eeb448 100644 (file)
@@ -374,8 +374,8 @@ global_optionsProc(HWND hdlg,
    {
        case WM_INITDIALOG:
            SetWindowLongPtr(hdlg, DWLP_USER, lParam); /* save for test etc */ 
-           CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);
-           CheckDlgButton(hdlg, DRV_DEBUG, globals.debug);
+           CheckDlgButton(hdlg, DRV_COMMLOG, getGlobalCommlog());
+           CheckDlgButton(hdlg, DRV_DEBUG, getGlobalDebug());
            getLogDir(logdir, sizeof(logdir));
            SetDlgItemText(hdlg, DS_LOGDIR, logdir);
 #ifdef _HANDLE_ENLIST_IN_DTC_
@@ -405,8 +405,9 @@ global_optionsProc(HWND hdlg,
                        MessageBox(hdlg, "Folder for logging error", logmsg, MB_ICONEXCLAMATION | MB_OK);
                        break;
                    }
-                   globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
-                   globals.debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);
+                   setGlobalCommlog(IsDlgButtonChecked(hdlg, DRV_COMMLOG));
+                   setGlobalDebug(IsDlgButtonChecked(hdlg, DRV_DEBUG));
+                   writeGlobalLogs();
                    if (writeDriverCommoninfo(ODBCINST_INI, ci->drivername, &globals) < 0)
                        MessageBox(hdlg, "Sorry, impossible to update the values\nWrite permission seems to be needed", "Update Error", MB_ICONEXCLAMATION | MB_OK);
                    setLogDir(logdir[0] ? logdir : NULL);
index 2c05543cd5d8cd284dfd6b4dd2ec669e6fb2ac2d..61cfcaa09e9ccd1f3fdd5b81f821b1f461b69d5d 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -35,9 +35,6 @@
 
 static const char *next_name_token(const char *s, size_t *len);
 
-/*extern GLOBAL_VALUES globals;*/
-
-
 /*     Perform a Prepare on the SQL statement */
 RETCODE        SQL_API
 PGAPI_Prepare(HSTMT hstmt,
diff --git a/info.c b/info.c
index 333a20017044d0d8d118368cca257e7d6ffb49c0..2ad5d718d6a54b3a7b924d7042c17dc7886987ae 100644 (file)
--- a/info.c
+++ b/info.c
@@ -47,8 +47,6 @@
 #define TRIGGER_DELETE 0x01
 #define TRIGGER_UPDATE 0x02
 
-/* extern GLOBAL_VALUES globals; */
-
 static const SQLCHAR *pubstr = (SQLCHAR *) "public";
 static const char  *likeop = "like";
 static const char  *eqop = "=";
diff --git a/mylog.c b/mylog.c
index abad7ca4c73ebc2039c0b890685a36ccd6cdf130..4bc879b6e9133fb11cb947a5544be79efb776efe 100644 (file)
--- a/mylog.c
+++ b/mylog.c
@@ -186,8 +186,8 @@ logs_on_off(int cnopen, int mylog_onoff, int qlog_onoff)
    }
    else if (mylog_off_count > 0)
        mylog_on = 0;
-   else if (globals.debug > 0)
-       mylog_on = globals.debug;
+   else if (getGlobalDebug() > 0)
+       mylog_on = getGlobalDebug();
    if (qlog_onoff)
        qlog_on_count += cnopen;
    else
@@ -196,8 +196,8 @@ logs_on_off(int cnopen, int mylog_onoff, int qlog_onoff)
        qlog_on = 1;
    else if (qlog_off_count > 0)
        qlog_on = 0;
-   else if (globals.commlog > 0)
-       qlog_on = globals.commlog;
+   else if (getGlobalCommlog() > 0)
+       qlog_on = getGlobalCommlog();
    LEAVE_QLOG_CS;
    LEAVE_MYLOG_CS;
 }
@@ -358,6 +358,94 @@ static void qlog_finalize(void)
    DELETE_QLOG_CS;
 }
 
+static int globalDebug = -1;
+int
+getGlobalDebug()
+{
+   char    temp[16];
+
+   if (globalDebug >=0)
+       return globalDebug;
+   /* Debug is stored in the driver section */
+   SQLGetPrivateProfileString(DBMS_NAME, INI_DEBUG, "", temp, sizeof(temp), ODBCINST_INI);
+   if (temp[0])
+       globalDebug = atoi(temp);
+   else
+       globalDebug = DEFAULT_DEBUG;
+
+   return globalDebug;
+}
+
+int
+setGlobalDebug(int val)
+{
+   return (globalDebug = val);
+}
+
+static int globalCommlog = -1;
+int
+getGlobalCommlog()
+{
+   char    temp[16];
+
+   if (globalCommlog >= 0)
+       return globalCommlog;
+   /* Commlog is stored in the driver section */
+   SQLGetPrivateProfileString(DBMS_NAME, INI_COMMLOG, "", temp, sizeof(temp), ODBCINST_INI);
+   if (temp[0])
+       globalCommlog = atoi(temp);
+   else
+       globalCommlog = DEFAULT_COMMLOG;
+
+   return globalCommlog;
+}
+
+int
+setGlobalCommlog(int val)
+{
+   return (globalCommlog = val);
+}
+
+int
+writeGlobalLogs()
+{
+   char    temp[10];
+
+   sprintf(temp, "%d", globalDebug);
+   SQLWritePrivateProfileString(DBMS_NAME, INI_DEBUG, temp, ODBCINST_INI);
+   sprintf(temp, "%d", globalCommlog);
+   SQLWritePrivateProfileString(DBMS_NAME, INI_COMMLOG, temp, ODBCINST_INI);
+   return 0;
+}
+
+int
+getLogDir(char *dir, int dirmax)
+{
+   return SQLGetPrivateProfileString(DBMS_NAME, INI_LOGDIR, "", dir, dirmax, ODBCINST_INI);
+}
+
+int
+setLogDir(const char *dir)
+{
+   return SQLWritePrivateProfileString(DBMS_NAME, INI_LOGDIR, dir, ODBCINST_INI);
+}
+
+/*
+ * This function starts a logging out of connections according the ODBCINST.INI
+ * portion of the DBMS_NAME registry.
+ */
+static void
+start_logging()
+{
+   /*
+    * GlobalDebug or GlobalCommlog means whether take mylog or commlog
+    * out of the connection time or not but doesn't mean the default of
+    * ci->drivers.debug(commlog).
+    */
+   logs_on_off(0, 0, 0);
+   mylog("\t%s:Global.debug&commlog=%d&%d\n", __FUNCTION__, getGlobalDebug(), getGlobalCommlog());
+}
+
 void InitializeLogging(void)
 {
    char dir[PATH_MAX];
@@ -367,6 +455,7 @@ void InitializeLogging(void)
        logdir = strdup(dir);
    mylog_initialize();
    qlog_initialize();
+   start_logging();
 }
 
 void FinalizeLogging(void)
diff --git a/mylog.h b/mylog.h
index 94766a7db6b11e7f7e71f0756eee2a47e210b566..5684a7c02d42c181b9a532a07c15681ae6c54be8 100644 (file)
--- a/mylog.h
+++ b/mylog.h
@@ -42,6 +42,14 @@ extern void qlog(char *fmt,...);
 int    get_qlog(void);
 int    get_mylog(void);
 
+int    getGlobalDebug();
+int    setGlobalDebug(int val);
+int    getGlobalCommlog();
+int    setGlobalCommlog(int val);
+int    writeGlobalLogs();
+int    getLogDir(char *dir, int dirmax);
+int    setLogDir(const char *dir);
+
 void   InitializeLogging(void);
 void   FinalizeLogging(void);
 
index 27aa0944b46b791de821fbc6ccc57ee7c55f0d77..3b1b7c7d944e327f3b73e6d04db7767b4dc13934 100644 (file)
@@ -86,8 +86,9 @@ int   initialize_global_cs(void)
 #ifdef POSIX_THREADMUTEX_SUPPORT
    getMutexAttr();
 #endif /* POSIX_THREADMUTEX_SUPPORT */
-   InitializeLogging();
    memset(&globals, 0, sizeof(globals));
+   globals.debug = globals.commlog = -1;
+   InitializeLogging();
    INIT_CONNS_CS;
    INIT_COMMON_CS;
 
index 7bba4308211a34fc93cfd9355528abd52bc5ce99..18c04fb5ed59259e176dab2ec9ce8808ccc05697 100644 (file)
@@ -39,8 +39,9 @@ int   initialize_global_cs(void)
    if (!init)
        return 0;
    init = 0;
-   InitializeLogging();
    memset(&globals, 0, sizeof(globals));
+   globals.debug = globals.commlog = -1;
+   InitializeLogging();
 
    return 0;
 }