Changeset: 35137b63db60 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=35137b63db60
Modified Files:
        
Branch: default
Log Message:

Merged from Dec2011


diffs (truncated from 1199 to 300 lines):

diff --git a/clients/ChangeLog.Dec2011 b/clients/ChangeLog.Dec2011
--- a/clients/ChangeLog.Dec2011
+++ b/clients/ChangeLog.Dec2011
@@ -1,6 +1,14 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Mon Oct 24 2011 Sjoerd Mullender <[email protected]>
+- ODBC: Implemented an easier way to create a log file of interactions
+  with the ODBC driver.  You can now add a connection attribute
+  "LOGFILE=filename" to the connection string parameter of
+  SQLBrowseConnect and SQLDriverConnect, and to the relevant part of
+  the Windows registry or odbc.ini file.  This value is only used if
+  there is no environment variable ODBCDEBUG.
+
 * Wed Oct 12 2011 Fabian Groffen <[email protected]>
 - Quoting of object names for mclient's \d command is now more flexible
   and consistent with standard SQL quoting rules, bug #2846.
diff --git a/clients/odbc/driver/ODBCDbc.h b/clients/odbc/driver/ODBCDbc.h
--- a/clients/odbc/driver/ODBCDbc.h
+++ b/clients/odbc/driver/ODBCDbc.h
@@ -146,8 +146,15 @@ ODBCError *getDbcError(ODBCDbc *dbc);
 void destroyODBCDbc(ODBCDbc *dbc);
 
 int ODBCGetKeyAttr(SQLCHAR **conn, SQLSMALLINT *nconn, char **key, char 
**attr);
+SQLRETURN ODBCConnectionString(SQLRETURN rc, ODBCDbc *dbc,
+                              SQLCHAR *OutConnectionString,
+                              SQLSMALLINT BufferLength,
+                              SQLSMALLINT *StringLength2Ptr,
+                              const char *dsn, const char *uid,
+                              const char *pwd, const char *host,
+                              int port, const char *database);
 SQLRETURN SQLAllocStmt_(ODBCDbc *dbc, SQLHANDLE *pnOutputHandle);
-SQLRETURN SQLConnect_(ODBCDbc *dbc, SQLCHAR *szDataSource, SQLSMALLINT 
nDataSourceLength, SQLCHAR *szUID, SQLSMALLINT nUIDLength, SQLCHAR *szPWD, 
SQLSMALLINT nPWDLength, char *host, int port, char *schema);
+SQLRETURN SQLConnect_(ODBCDbc *dbc, SQLCHAR *szDataSource, SQLSMALLINT 
nDataSourceLength, SQLCHAR *szUID, SQLSMALLINT nUIDLength, SQLCHAR *szPWD, 
SQLSMALLINT nPWDLength, const char *host, int port, const char *schema);
 SQLRETURN SQLGetConnectAttr_(ODBCDbc *dbc, SQLINTEGER Attribute, SQLPOINTER 
ValuePtr, SQLINTEGER BufferLength, SQLINTEGER *StringLength);
 SQLRETURN SQLSetConnectAttr_(ODBCDbc *dbc, SQLINTEGER Attribute, SQLPOINTER 
ValuePtr, SQLINTEGER StringLength);
 
diff --git a/clients/odbc/driver/ODBCGlobal.h b/clients/odbc/driver/ODBCGlobal.h
--- a/clients/odbc/driver/ODBCGlobal.h
+++ b/clients/odbc/driver/ODBCGlobal.h
@@ -116,18 +116,27 @@ SQLRETURN SQLFreeHandle_(SQLSMALLINT han
 SQLRETURN SQLGetDiagRec_(SQLSMALLINT handleType, SQLHANDLE handle, SQLSMALLINT 
recNumber, SQLCHAR *sqlState, SQLINTEGER *nativeErrorPtr, SQLCHAR *messageText, 
SQLSMALLINT bufferLength, SQLSMALLINT *textLengthPtr);
 
 #ifdef ODBCDEBUG
+extern const char *ODBCdebug;
+
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
-#define ODBCLOG(...)   do {                                            \
-                               char *_s = getenv("ODBCDEBUG");         \
-                               if (_s && *_s) {                        \
-                                       FILE *_f;                       \
-                                       _f = fopen(_s, "a");            \
-                                       if (_f) {                       \
-                                               fprintf(_f, __VA_ARGS__); \
-                                               fclose(_f);             \
-                                       }                               \
-                               }                                       \
-                       } while (0)
+#define ODBCLOG(...)                                                   \
+       do {                                                            \
+               if (ODBCdebug == NULL) {                                \
+                       if ((ODBCdebug = getenv("ODBCDEBUG")) == NULL)  \
+                               ODBCdebug = strdup("");                 \
+                       else                                            \
+                               ODBCdebug = strdup(ODBCdebug);          \
+               }                                                       \
+               if (ODBCdebug != NULL && *ODBCdebug != 0) {             \
+                       FILE *_f;                                       \
+                       _f = fopen(ODBCdebug, "a");                     \
+                       if (_f == NULL)                                 \
+                               _f = stderr;                            \
+                       fprintf(_f, __VA_ARGS__);                       \
+                       if (_f != stderr)                               \
+                               fclose(_f);                             \
+               }                                                       \
+       } while (0)
 #else
 extern void ODBCLOG(_In_z_ _Printf_format_string_ const char *fmt, ...)
        __attribute__((__format__(__printf__, 1, 2)));
diff --git a/clients/odbc/driver/ODBCStmt.h b/clients/odbc/driver/ODBCStmt.h
--- a/clients/odbc/driver/ODBCStmt.h
+++ b/clients/odbc/driver/ODBCStmt.h
@@ -221,5 +221,6 @@ SQLRETURN SQLPrepare_(ODBCStmt *stmt, SQ
                      SQLINTEGER nSqlStrLength);
 SQLRETURN SQLSetStmtAttr_(ODBCStmt *stmt, SQLINTEGER Attribute,
                          SQLPOINTER Value, SQLINTEGER StringLength);
+const char *ODBCErrorType(const char *msg);
 
 #endif
diff --git a/clients/odbc/driver/ODBCUtil.c b/clients/odbc/driver/ODBCUtil.c
--- a/clients/odbc/driver/ODBCUtil.c
+++ b/clients/odbc/driver/ODBCUtil.c
@@ -452,6 +452,9 @@ struct sql_types ODBC_c_types[] = {
 };
 
 #ifdef ODBCDEBUG
+
+const char *ODBCdebug;
+
 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
 #include <stdarg.h>
 
@@ -459,13 +462,18 @@ void
 ODBCLOG(const char *fmt, ...)
 {
        va_list ap;
-       char *s = getenv("ODBCDEBUG");
 
        va_start(ap, fmt);
-       if (s && *s) {
+       if (ODBCdebug == NULL) {
+               if ((ODBCdebug = getenv("ODBCDEBUG")) == NULL)
+                       ODBCdebug = strdup("");
+               else
+                       ODBCdebug = strdup(ODBCdebug);
+       }
+       if (ODBCdebug != NULL && *ODBCdebug != 0) {
                FILE *f;
 
-               f = fopen(s, "a");
+               f = fopen(ODBCdebug, "a");
                if (f) {
                        vfprintf(f, fmt, ap);
                        fclose(f);
diff --git a/clients/odbc/driver/SQLBrowseConnect.c 
b/clients/odbc/driver/SQLBrowseConnect.c
--- a/clients/odbc/driver/SQLBrowseConnect.c
+++ b/clients/odbc/driver/SQLBrowseConnect.c
@@ -108,6 +108,15 @@ SQLBrowseConnect_(ODBCDbc *dbc,
                } else if (strcasecmp(key, "database") == 0 && dbname == NULL) {
                        dbname = attr;
                        allocated |= 16;
+#ifdef ODBCDEBUG
+               } else if (strcasecmp(key, "logfile") == 0 &&
+                          getenv("ODBCDEBUG") == NULL) {
+                       /* environment trumps everything */
+                       if (ODBCdebug)
+                               free((void *) ODBCdebug); /* discard const */
+                       ODBCdebug = attr;
+                       allocated |= 32;
+#endif
                } else
                        free(attr);
                free(key);
@@ -148,10 +157,26 @@ SQLBrowseConnect_(ODBCDbc *dbc,
                                allocated |= 16;
                        }
                }
+#ifdef ODBCDEBUG
+               if ((allocated & 32) == 0 && getenv("ODBCDEBUG") == NULL) {
+                       /* if not set from InConnectionString argument
+                        * or environment, look in profile */
+                       n = SQLGetPrivateProfileString(dsn, "logfile", "", buf, 
sizeof(buf), "odbc.ini");
+                       if (n > 0 && buf[0])
+                               ODBCdebug = strdup(buf);
+               }
+#endif
        }
 
        if (uid != NULL && pwd != NULL) {
                rc = SQLConnect_(dbc, (SQLCHAR *) dsn, SQL_NTS, (SQLCHAR *) 
uid, SQL_NTS, (SQLCHAR *) pwd, SQL_NTS, host, port, dbname);
+               if (SQL_SUCCEEDED(rc)) {
+                       rc = ODBCConnectionString(rc, dbc, OutConnectionString,
+                                                 BufferLength,
+                                                 StringLength2Ptr,
+                                                 dsn, uid, pwd, host, port,
+                                                 dbname);
+               }
        } else {
                if (uid == NULL) {
                        if (BufferLength > 0)
@@ -188,6 +213,15 @@ SQLBrowseConnect_(ODBCDbc *dbc,
                        OutConnectionString += 21;
                        BufferLength -= 21;
                }
+#ifdef ODBCDEBUG
+               if (ODBCdebug == NULL) {
+                       if (BufferLength > 0)
+                               strncpy((char *) OutConnectionString, 
"*LOGFILE:Debug log file=?;", BufferLength);
+                       len += 26;
+                       OutConnectionString += 26;
+                       BufferLength -= 26;
+               }
+#endif
 
                if (StringLength2Ptr)
                        *StringLength2Ptr = len;
@@ -264,10 +298,12 @@ SQLBrowseConnectW(SQLHDBC ConnectionHand
 
        clearDbcErrors(dbc);
 
-       fixWcharIn(InConnectionString, StringLength1, SQLCHAR, in, addDbcError, 
dbc, return SQL_ERROR);
-       out = malloc(100);      /* max 80 needed */
-       rc = SQLBrowseConnect_(dbc, in, SQL_NTS, out, 100, &n);
-       fixWcharOut(rc, out, n, OutConnectionString, BufferLength, 
StringLength2Ptr, 1, addDbcError, dbc);
+       fixWcharIn(InConnectionString, StringLength1, SQLCHAR, in,
+                  addDbcError, dbc, return SQL_ERROR);
+       out = malloc(1024);
+       rc = SQLBrowseConnect_(dbc, in, SQL_NTS, out, 1024, &n);
+       fixWcharOut(rc, out, n, OutConnectionString, BufferLength,
+                   StringLength2Ptr, 1, addDbcError, dbc);
        if (in)
                free(in);
        return rc;
diff --git a/clients/odbc/driver/SQLConnect.c b/clients/odbc/driver/SQLConnect.c
--- a/clients/odbc/driver/SQLConnect.c
+++ b/clients/odbc/driver/SQLConnect.c
@@ -109,9 +109,9 @@ SQLConnect_(ODBCDbc *dbc,
            SQLSMALLINT NameLength2,
            SQLCHAR *Authentication,
            SQLSMALLINT NameLength3,
-           char *host,
+           const char *host,
            int port,
-           char *schema)
+           const char *schema)
 {
        SQLRETURN rc = SQL_SUCCESS;
        char *dsn = NULL;
diff --git a/clients/odbc/driver/SQLDriverConnect.c 
b/clients/odbc/driver/SQLDriverConnect.c
--- a/clients/odbc/driver/SQLDriverConnect.c
+++ b/clients/odbc/driver/SQLDriverConnect.c
@@ -102,6 +102,144 @@ ODBCGetKeyAttr(SQLCHAR **conn, SQLSMALLI
        return 1;
 }
 
+SQLRETURN
+ODBCConnectionString(SQLRETURN rc,
+                    ODBCDbc *dbc,
+                    SQLCHAR *OutConnectionString,
+                    SQLSMALLINT BufferLength,
+                    SQLSMALLINT *StringLength2Ptr,
+                    const char *dsn,
+                    const char *uid,
+                    const char *pwd,
+                    const char *host,
+                    int port,
+                    const char *database)
+{
+       int n;
+#ifdef ODBCDEBUG
+       SQLCHAR *buf = OutConnectionString;
+       int buflen = BufferLength;
+#endif
+
+       if (OutConnectionString == NULL)
+               BufferLength = -1;
+       if (BufferLength > 0) {
+               n = snprintf((char *) OutConnectionString, BufferLength,
+                            "DSN=%s;", dsn ? dsn : "DEFAULT");
+               /* some snprintf's return -1 if buffer too small */
+               if (n < 0)
+                       n = BufferLength + 1;   /* make sure it becomes < 0 */
+               BufferLength -= n;
+               OutConnectionString += n;
+       } else {
+               BufferLength = -1;
+       }
+       if (uid) {
+               if (BufferLength > 0) {
+                       n = snprintf((char *) OutConnectionString,
+                                    BufferLength, "UID=%s;", uid);
+                       if (n < 0)
+                               n = BufferLength + 1;
+                       BufferLength -= n;
+                       OutConnectionString += n;
+               } else {
+                       BufferLength = -1;
+               }
+       }
+       if (pwd) {
+               if (BufferLength > 0) {
+                       n = snprintf((char *) OutConnectionString,
+                                    BufferLength, "PWD=%s;", pwd);
+                       if (n < 0)
+                               n = BufferLength + 1;
+                       BufferLength -= n;
+                       OutConnectionString += n;
+               } else {
+                       BufferLength = -1;
+               }
+       }
+       if (host) {
+               if (BufferLength > 0) {
+                       n = snprintf((char *) OutConnectionString,
+                                    BufferLength, "HOST=%s;", host);
+                       if (n < 0)
+                               n = BufferLength + 1;
+                       BufferLength -= n;
+                       OutConnectionString += n;
+               } else {
+                       BufferLength = -1;
+               }
+       }
+       if (port) {
+               char portbuf[10];
+
+               if (BufferLength > 0) {
+                       n = snprintf((char *) OutConnectionString,
+                                    BufferLength, "PORT=%d;", port);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to