From 7f882742d13e8371cbdff2e564d455234e97952d Mon Sep 17 00:00:00 2001 From: Brian Lewis Date: Tue, 14 Nov 2017 10:49:17 -0800 Subject: [PATCH] Improve performance of _getRow and fetchall --- teradata/tdodbc.py | 6 ++++-- teradata/util.py | 10 +++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/teradata/tdodbc.py b/teradata/tdodbc.py index cfabf16..54d1ac2 100644 --- a/teradata/tdodbc.py +++ b/teradata/tdodbc.py @@ -85,6 +85,8 @@ SQLPOINTER = ctypes.c_void_p SQLHANDLE = ctypes.c_void_p +SQLWCHAR_SIZE = ctypes.sizeof(SQLWCHAR) + ADDR = ctypes.byref PTR = ctypes.POINTER ERROR_BUFFER_SIZE = 2 ** 10 @@ -766,7 +768,7 @@ def _executeManyBatch(self, params, numParams, dataTypes): paramArrays.append((SQLDOUBLE * paramSetSize)()) else: maxLen += 1 - valueSize = SQLLEN(ctypes.sizeof(SQLWCHAR) * maxLen) + valueSize = SQLLEN(SQLWCHAR_SIZE * maxLen) paramArrays.append(_createBuffer(paramSetSize * maxLen)) lengthArrays.append((SQLLEN * paramSetSize)()) for paramSetNum in range(0, paramSetSize): @@ -1125,7 +1127,7 @@ def _getRow(cursor, buffers, bufSizes, dataTypes, indicators, rowIndex): elif dataType == SQL_LONGVARBINARY: val = _getLobData(cursor, col, buf, True) else: - chLen = (int)(bufSize / ctypes.sizeof(SQLWCHAR)) + chLen = (bufSize // SQLWCHAR_SIZE) chBuf = (SQLWCHAR * chLen) val = _outputStr(chBuf.from_buffer(buf, bufSize * rowIndex)) diff --git a/teradata/util.py b/teradata/util.py index 1cb7214..c514985 100644 --- a/teradata/util.py +++ b/teradata/util.py @@ -42,6 +42,7 @@ def trace(self, message, *args, **kws): # Yes, logger takes its '*args' as 'args'. if self.isEnabledFor(TRACE): self._log(TRACE, message, args, **kws) + logging.TRACE = TRACE logging.Logger.trace = trace @@ -125,20 +126,15 @@ def fetchmany(self, size=None): size = self.arraysize self.fetchSize = size rows = [] - count = 0 - for row in self: + for row, count in enumerate(self): rows.append(row) - count += 1 if count == size: break return rows def fetchall(self): self.fetchSize = self.arraysize - rows = [] - for row in self: - rows.append(row) - return rows + return list(self) def nextset(self): # Abstract method, defined by convention only