diff --git a/lib/Connection.cpp b/lib/Connection.cpp index fcacef6..a5aeb84 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -83,6 +83,7 @@ Connection::Connection (UMConnectionCAPI *_capi) m_errno = -1; memcpy (&m_capi, _capi, sizeof (UMConnectionCAPI)); m_dbgMethodProgress = 0; + m_dbgFailedRecv = 0; m_errorType = UME_OTHER; } @@ -736,6 +737,18 @@ void *Connection::query(const char *_query, size_t _cbQuery) return NULL; } + if (m_dbgFailedRecv > 0) + { + if (!recvPacket()) + { + m_dbgMethodProgress --; + return NULL; + } + + m_reader.skip(); // pop dirty packages sent succ but recv failed + m_dbgFailedRecv --; + } + size_t len = _cbQuery; if (len > m_writer.getSize () - (MYSQL_PACKET_HEADER_SIZE + 1)) @@ -762,6 +775,7 @@ void *Connection::query(const char *_query, size_t _cbQuery) { PRINTMARK(); m_dbgMethodProgress --; + m_dbgFailedRecv ++; return NULL; } diff --git a/lib/Connection.h b/lib/Connection.h index 2d410fe..7aec623 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -108,6 +108,7 @@ class Connection UMConnectionCAPI m_capi; int m_dbgMethodProgress; + int m_dbgFailedRecv; public: @@ -145,4 +146,4 @@ class Connection protected: }; -#endif \ No newline at end of file +#endif diff --git a/python/umysql.c b/python/umysql.c index 2564e97..c12d12e 100644 --- a/python/umysql.c +++ b/python/umysql.c @@ -1082,7 +1082,11 @@ PyObject *EscapeQueryArguments(Connection *self, PyObject *inQuery, PyObject *it if (PyUnicode_Check(arg)) cbOutQuery += (PyUnicode_GET_SIZE(arg) * 6); else - cbOutQuery += 64; + { + int len = PyString_GET_SIZE(PyObject_Str(arg)); + if (len < 64) len = 64; + cbOutQuery += len; + } Py_DECREF(arg); } diff --git a/tests/tests.py b/tests/tests.py index d969578..2f8dacb 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -827,6 +827,15 @@ def testUnsignedInt(self): self.assertEquals([values1, values2, values3, ], rs.rows) cnn.close() + def testLongStrReprObjParam(self): + cnn = umysql.Connection() + cnn.connect (DB_HOST, DB_PORT, DB_USER, DB_PASSWD, DB_DB) + obj = range(1000) + result = cnn.query("SELECT '%s'", (obj,)) + self.assertEqual(result.rows[0][0], str(obj)) + cnn.close() + + if __name__ == '__main__': from guppy import hpy hp = hpy()