Commit f844fe0b authored by Julien Muchembled's avatar Julien Muchembled

mysql: minor optimization

It's been many years we don't get 'array' objects, no idea when exactly.
parent 9691459d
......@@ -221,10 +221,7 @@ class MySQLDatabaseManager(DatabaseManager):
conn.query(query)
if query.startswith("SELECT "):
r = conn.store_result()
return tuple([
tuple([d.tostring() if isinstance(d, array) else d
for d in row])
for row in r.fetch_row(r.num_rows())])
return r.fetch_row(r.num_rows())
r = query.split(None, 1)[0]
if r in ("INSERT", "REPLACE", "DELETE", "UPDATE"):
self._active = 1
......
......@@ -63,30 +63,12 @@ class StorageMySQLdbTests(StorageDBTests):
raise unittest.SkipTest(m)
return db
def test_query1(self):
# fake result object
from array import array
result_object = Mock({
"num_rows": 1,
"fetch_row": ((1, 2, array('b', (1, 2, ))), ),
})
# expected formatted result
expected_result = (
(1, 2, '\x01\x02', ),
)
self.db.conn = Mock({ 'store_result': result_object })
result = self.db.query('SELECT ')
self.assertEqual(result, expected_result)
calls = self.db.conn.mockGetNamedCalls('query')
self.assertEqual(len(calls), 1)
calls[0].checkArgs('SELECT ')
def test_query2(self):
def test_ServerGone(self):
with ServerGone(self.db) as p:
self.assertRaises(ProgrammingError, self.db.query, 'QUERY')
self.assertFalse(p.applied)
def test_query3(self):
def test_OperationalError(self):
# OperationalError > raise DatabaseFailure exception
class FakeConn(object):
def close(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment