Commits

Anthony Tuininga committed 6ca65af

Remove usage of PyString_AS_STRING which is no longer usable in Python 3.x.

Comments (0)

Files changed (1)

     udt_Cursor *self,                   // cursor to perform prepare on
     PyObject *statement)                // statement to prepare
 {
+    PyObject *format, *formatArgs, *message;
     udt_StringBuffer buffer;
     SQLRETURN rc;
 
         return -1;
     }
 
-    // log the statement, if applicable
-    if (self->logSql) {
-        if (statement == Py_None)
-            statement = self->statement;
-        LogMessageV(LOG_LEVEL_DEBUG, "SQL\n%s", PyString_AS_STRING(statement));
-    }
-
     // close original statement if necessary in order to discard results
     if (self->statement)
         SQLCloseCursor(self->handle);
         self->statement = statement;
     }
 
+    // log the statement, if applicable
+    if (self->logSql) {
+        format = ceString_FromAscii("SQL\n%s");
+        if (!format)
+            return -1;
+        formatArgs = PyTuple_Pack(1, statement);
+        if (!formatArgs) {
+            Py_DECREF(format);
+            return -1;
+        }
+        message = ceString_Format(format, formatArgs);
+        Py_DECREF(format);
+        Py_DECREF(formatArgs);
+        if (!message)
+            return -1;
+        WriteMessageForPython(LOG_LEVEL_DEBUG, message);
+    }
+
     // clear previous result set parameters
     Py_XDECREF(self->resultSetVars);
     self->resultSetVars = NULL;
 
     // prepare statement
     if (StringBuffer_FromString(&buffer, self->statement,
-                "statement must be a string or None") < 0)
+            "statement must be a string or None") < 0)
         return -1;
     Py_BEGIN_ALLOW_THREADS
     rc = SQLPrepare(self->handle, (CEODBC_CHAR*) buffer.ptr, buffer.size);
     udt_Cursor *self,                   // cursor to execute
     PyObject *args)                     // arguments
 {
+    PyObject *statement, *format, *formatArgs, *message;
     udt_StringBuffer buffer;
-    PyObject *statement;
     SQLRETURN rc;
 
     // parse arguments
         return NULL;
 
     // log the statement, if applicable
-    if (self->logSql)
-        LogMessageV(LOG_LEVEL_DEBUG, "SQL\n%s", PyString_AS_STRING(statement));
+    if (self->logSql) {
+        format = ceString_FromAscii("SQL\n%s");
+        if (!format)
+            return NULL;
+        formatArgs = PyTuple_Pack(1, statement);
+        if (!formatArgs) {
+            Py_DECREF(format);
+            return NULL;
+        }
+        message = ceString_Format(format, formatArgs);
+        Py_DECREF(format);
+        Py_DECREF(formatArgs);
+        if (!message)
+            return NULL;
+        WriteMessageForPython(LOG_LEVEL_DEBUG, message);
+    }
 
     // clear previous statement, if applicable
     if (self->statement)
 
     // execute the statement
     if (StringBuffer_FromString(&buffer, statement,
-                "statement must be a string") < 0)
+            "statement must be a string") < 0)
         return NULL;
     Py_BEGIN_ALLOW_THREADS
     rc = SQLExecDirect(self->handle, (SQLCHAR*) buffer.ptr, buffer.size);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.