Further improvement of qlog.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 30 Aug 2017 05:20:35 +0000 (14:20 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Wed, 30 Aug 2017 05:20:36 +0000 (14:20 +0900)
mylog.c
pgapi30.c
statement.c

diff --git a/mylog.c b/mylog.c
index 8a9417220b19b05880ca3b34230ab3e07ae508c7..7271695fa9e558e47a528e78b554398b096395ad 100644 (file)
--- a/mylog.c
+++ b/mylog.c
@@ -237,7 +237,6 @@ logs_on_off(int cnopen, int mylog_onoff, int qlog_onoff)
            qlog_off_count = 0;
 
    ENTER_MYLOG_CS;
-   ENTER_QLOG_CS;
    if (mylog_onoff)
        mylog_on_count += cnopen;
    else
@@ -253,18 +252,26 @@ logs_on_off(int cnopen, int mylog_onoff, int qlog_onoff)
        mylog_on = 0;
    else if (getGlobalDebug() > 0)
        mylog_on = getGlobalDebug();
+   LEAVE_MYLOG_CS;
+
+   ENTER_QLOG_CS;
    if (qlog_onoff)
        qlog_on_count += cnopen;
    else
        qlog_off_count += cnopen;
    if (qlog_on_count > 0)
-       qlog_on = 1;
+   {
+       if (qlog_onoff > qlog_on)
+           qlog_on = qlog_onoff;
+       else if (qlog_on < 1)
+           qlog_on = 1;
+   }
    else if (qlog_off_count > 0)
        qlog_on = 0;
    else if (getGlobalCommlog() > 0)
        qlog_on = getGlobalCommlog();
    LEAVE_QLOG_CS;
-   LEAVE_MYLOG_CS;
+MYLOG(0, "mylog_on=%d qlog_on=%d\n", mylog_on, qlog_on);
 }
 
 #ifdef WIN32
index 01c0e64eff8fbd6e1abc6d47d7cccda7b391d2f8..cccf379640bd16139b0c2142d47aca69578b68f0 100644 (file)
--- a/pgapi30.c
+++ b/pgapi30.c
@@ -1720,9 +1720,9 @@ PGAPI_SetConnectAttr(HDBC ConnectionHandle,
            break;
        case SQL_ATTR_PGOPT_COMMLOG:
            newValue = CAST_UPTR(SQLCHAR, Value);
-           if (newValue > 0 && conn->connInfo.drivers.commlog <= 0)
+           if (newValue > 0)
            {
-               logs_on_off(-1, 0, 0);
+               logs_on_off(-1, 0, conn->connInfo.drivers.commlog);
                conn->connInfo.drivers.commlog = newValue;
                logs_on_off(1, 0, conn->connInfo.drivers.commlog);
                MYLOG(0, "commlog => %d\n", conn->connInfo.drivers.commlog);
index 2616fc11541ab715a05d49814bf4934d0f5c2881..c6e78f47f1e3ec621e7cf7304535baf1b20b0333 100644 (file)
@@ -2429,6 +2429,28 @@ RequestStart(StatementClass *stmt, ConnectionClass *conn, const char *func)
    return ret;
 }
 
+static log_params(int nParams, const Oid *paramTypes, const UCHAR * const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
+{
+   const int   level = 1;
+   int i, j;
+   BOOL    isBinary;
+
+   for (i = 0; i < nParams; i++)
+   {
+       isBinary = paramFormats ? paramFormats[i] : FALSE;
+       if (!paramValues[i])
+           QLOG(level, "\t%c (null) OID=%u\n", isBinary ? 'b' : 't', paramTypes ? paramTypes[i] : 0);
+       else if (isBinary)
+       {
+           QLOG(level, "\tb '");
+           for (j = 0; j < paramLengths[i]; j++)
+               QPRINTF(level, "%02x", paramValues[i][j]);
+           QPRINTF(level, " OID=%u\n", paramTypes ? paramTypes[i] : 0);
+       }
+       else
+           QLOG(level, "\tt '%s' OID=%u\n", paramValues[i], paramTypes ? paramTypes[i] : 0);
+   }
+}
 
 static QResultClass *
 libpq_bind_and_exec(StatementClass *stmt)
@@ -2503,6 +2525,7 @@ libpq_bind_and_exec(StatementClass *stmt)
        pstmt = stmt->processed_statements;
        MYLOG(0, "execParams query=%s nParams=%d\n", pstmt->query, nParams);
        QLOG(0, "PQexecParams: %p '%s' nParams=%d\n", conn->pqconn, pstmt->query, nParams);
+       log_params(nParams, paramTypes, (const UCHAR * const *) paramValues, paramLengths, paramFormats, resultFormat);
        pgres = PQexecParams(conn->pqconn,
                             pstmt->query,
                             nParams,
@@ -2528,6 +2551,7 @@ libpq_bind_and_exec(StatementClass *stmt)
        /* already prepared */
        MYLOG(0, "execPrepared plan=%s nParams=%d\n", plan_name, nParams);
        QLOG(0, "PQexecPrepared: %p plan=%s nParams=%d\n", conn->pqconn, plan_name, nParams);
+       log_params(nParams, paramTypes, (const UCHAR * const *) paramValues, paramLengths, paramFormats, resultFormat);
        pgres = PQexecPrepared(conn->pqconn,
                               plan_name,   /* portal name == plan name */
                               nParams,