From: Hiroshi Inoue Date: Tue, 16 May 2017 09:57:39 +0000 (+0900) Subject: Remove the stuff about Debug and Commlog from getCommonDefaults(). X-Git-Tag: REL-09_06_0400~46 X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/queryCache.php?a=commitdiff_plain;h=82bd4a749ac9b368d03b643947418275d08372b0;p=psqlodbc.git Remove the stuff about Debug and Commlog from getCommonDefaults(). Now per connection Debug/Commlog info are handled in getDSNinfo(). Global Debug/Commlog info are get/set using functions get(set)GlobalDebug(Commlog)(). --- diff --git a/connection.c b/connection.c index a78428b..c0e2816 100644 --- a/connection.c +++ b/connection.c @@ -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) { diff --git a/dlg_specific.c b/dlg_specific.c index 93782af..b8dd874 100644 --- a/dlg_specific.c +++ b/dlg_specific.c @@ -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)) diff --git a/dlg_specific.h b/dlg_specific.h index 9b36ce8..22d08c3 100644 --- a/dlg_specific.h +++ b/dlg_specific.h @@ -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); diff --git a/dlg_wingui.c b/dlg_wingui.c index dba706d..8ade36a 100644 --- a/dlg_wingui.c +++ b/dlg_wingui.c @@ -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); diff --git a/execute.c b/execute.c index 2c05543..61cfcaa 100644 --- 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 333a200..2ad5d71 100644 --- 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 abad7ca..4bc879b 100644 --- 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 94766a7..5684a7c 100644 --- 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); diff --git a/psqlodbc.c b/psqlodbc.c index 27aa094..3b1b7c7 100644 --- a/psqlodbc.c +++ b/psqlodbc.c @@ -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; diff --git a/psqlsetup.c b/psqlsetup.c index 7bba430..18c04fb 100644 --- a/psqlsetup.c +++ b/psqlsetup.c @@ -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; }