Skip to content

Commit

Permalink
Remove sv mods; update tests for distributed database
Browse files Browse the repository at this point in the history
  • Loading branch information
kesmit13 committed Oct 19, 2022
1 parent 1d3baa3 commit 8129d10
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
40 changes: 20 additions & 20 deletions singlestoredb/clients/pymysqlsv/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
SSCursor,
DictCursor,
SSDictCursor,
SSCursorSV,
SSDictCursorSV,
# SSCursorSV,
# SSDictCursorSV,
)
from .optionfile import Parser
from .protocol import (
Expand Down Expand Up @@ -349,15 +349,15 @@ def _config(key, arg):
self.resultclass = MySQLResult

# The C extension handles these types internally.
if _pymysqlsv is not None and not self.pure_python:
self.resultclass = MySQLResultSV
if self.cursorclass is SSCursor:
self.cursorclass = SSCursorSV
elif self.cursorclass is DictCursor:
self.output_type = 'dicts'
elif self.cursorclass is SSDictCursor:
self.cursorclass = SSDictCursorSV
self.output_type = 'dicts'
# if _pymysqlsv is not None and not self.pure_python:
# self.resultclass = MySQLResultSV
# if self.cursorclass is SSCursor:
# self.cursorclass = SSCursorSV
# elif self.cursorclass is DictCursor:
# self.output_type = 'dicts'
# elif self.cursorclass is SSDictCursor:
# self.cursorclass = SSDictCursorSV
# self.output_type = 'dicts'

self._result = None
self._affected_rows = 0
Expand Down Expand Up @@ -584,15 +584,15 @@ def cursor(self, cursor=None):
:type cursor: :py:class:`Cursor`, :py:class:`SSCursor`, :py:class:`DictCursor`, or :py:class:`SSDictCursor`.
"""
if cursor:
if cursor is SSCursor:
cursor = SSCursorSV
elif cursor is DictCursor:
# TODO: Passing in a cursor shouldn't affect connection output type
self.output_type = 'dicts'
elif cursor is SSDictCursor:
cursor = SSDictCursorSV
# TODO: Passing in a cursor shouldn't affect connection output type
self.output_type = 'dicts'
# if cursor is SSCursor:
# cursor = SSCursorSV
# elif cursor is DictCursor:
# # TODO: Passing in a cursor shouldn't affect connection output type
# self.output_type = 'dicts'
# elif cursor is SSDictCursor:
# cursor = SSDictCursorSV
# # TODO: Passing in a cursor shouldn't affect connection output type
# self.output_type = 'dicts'
return cursor(self)
return self.cursorclass(self)

Expand Down
24 changes: 12 additions & 12 deletions singlestoredb/clients/pymysqlsv/tests/test_DictCursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def test_DictCursor(self):
bob, r, 'fetch a 1 row result via iteration failed via DictCursor',
)
# get all 3 row via fetchall
c.execute('SELECT * from dictcursor')
c.execute('SELECT * from dictcursor ORDER BY name')
r = c.fetchall()
self.assertEqual([bob, jim, fred], r, 'fetchall failed via DictCursor')
self.assertEqual([bob, fred, jim], r, 'fetchall failed via DictCursor')
# same test again but do a list comprehension
c.execute('SELECT * from dictcursor')
c.execute('SELECT * from dictcursor ORDER BY name')
r = list(c)
self.assertEqual([bob, jim, fred], r, 'DictCursor should be iterable')
self.assertEqual([bob, fred, jim], r, 'DictCursor should be iterable')
# get all 2 row via fetchmany
c.execute('SELECT * from dictcursor')
c.execute('SELECT * from dictcursor ORDER BY name')
r = c.fetchmany(2)
self.assertEqual([bob, jim], r, 'fetchmany failed via DictCursor')
self.assertEqual([bob, fred], r, 'fetchmany failed via DictCursor')
self._ensure_cursor_expired(c)

def test_custom_dict(self):
Expand All @@ -101,17 +101,17 @@ class MyDictCursor(self.cursor_type):
self.assertEqual(bob, r, 'fetchone() returns MyDictCursor')
self._ensure_cursor_expired(cur)

cur.execute('SELECT * FROM dictcursor')
cur.execute('SELECT * FROM dictcursor ORDER BY name')
r = cur.fetchall()
self.assertEqual([bob, jim, fred], r, 'fetchall failed via MyDictCursor')
self.assertEqual([bob, fred, jim], r, 'fetchall failed via MyDictCursor')

cur.execute('SELECT * FROM dictcursor')
cur.execute('SELECT * FROM dictcursor ORDER BY name')
r = list(cur)
self.assertEqual([bob, jim, fred], r, 'list failed via MyDictCursor')
self.assertEqual([bob, fred, jim], r, 'list failed via MyDictCursor')

cur.execute('SELECT * FROM dictcursor')
cur.execute('SELECT * FROM dictcursor ORDER BY name')
r = cur.fetchmany(2)
self.assertEqual([bob, jim], r, 'list failed via MyDictCursor')
self.assertEqual([bob, fred], r, 'list failed via MyDictCursor')
self._ensure_cursor_expired(cur)


Expand Down
2 changes: 1 addition & 1 deletion singlestoredb/clients/pymysqlsv/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_datatypes(self):
'select l from test_datatypes where i in %s order by i', (seq,),
)
r = c.fetchall()
self.assertEqual([(4,), (8,)], r)
self.assertEqual(((4,), (8,)), r)
c.execute('delete from test_datatypes')

finally:
Expand Down
3 changes: 2 additions & 1 deletion singlestoredb/clients/pymysqlsv/tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ def test_issue_321(self):
'insert into issue321 (value_1, value_2) '
'values (%(value_1)s, %(value_2)s)'
)
sql_select = 'select * from issue321 where ' 'value_1 in %s and value_2=%s'
sql_select = 'select * from issue321 ' + \
'where value_1 in %s and value_2=%s order by value_1'
data = [
[('a',), '\u0430'],
[['b'], '\u0430'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def check_data_integrity(self, columndefs, generator):
self.cursor.executemany(insert_statement, data)
self.connection.commit()
# verify
self.cursor.execute('select * from %s' % self.table)
self.cursor.execute(
'select * from %s ORDER BY %s' %
(self.table, columndefs[0].split()[0]),
)
l = self.cursor.fetchall()
if self.debug:
print(l)
Expand Down Expand Up @@ -129,7 +132,10 @@ def generator(row, col):
self.cursor.executemany(insert_statement, data)
# verify
self.connection.commit()
self.cursor.execute('select * from %s' % self.table)
self.cursor.execute(
'select * from %s ORDER BY %s' %
(self.table, columndefs[0].split()[0]),
)
l = self.cursor.fetchall()
self.assertEqual(len(l), self.rows)
for i in range(self.rows):
Expand Down

0 comments on commit 8129d10

Please sign in to comment.