Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
conn = self.connections[0]
data = [
('America', '', 'America/Jamaica'),
('America', '', 'America/Los_Angeles'),
('America', '', 'America/Lima'),
('America', '', 'America/New_York'),
('America', '', 'America/Menominee'),
('America', '', 'America/Havana'),
('America', '', 'America/El_Salvador'),
('America', '', 'America/Costa_Rica'),
('America', '', 'America/Denver'),
('America', '', 'America/Detroit'),]
try:
cursor = conn.cursor(aiomysql.cursors.SSCursor)
# Create table
cursor.execute(('CREATE TABLE tz_data ('
'region VARCHAR(64),'
'zone VARCHAR(64),'
'name VARCHAR(64))'))
# Test INSERT
for i in data:
cursor.execute('INSERT INTO tz_data VALUES (%s, %s, %s)', i)
self.assertEqual(conn.affected_rows(), 1, 'affected_rows does not match')
conn.commit()
# Test fetchone()
iter = 0
cursor.execute('SELECT * FROM tz_data')
def test_ssursor(self):
# affected_rows = 18446744073709551615
conn = self.connections[0]
cursor = yield from conn.cursor(SSCursor)
# Create table
yield from cursor.execute('DROP TABLE IF EXISTS tz_data;')
yield from cursor.execute(('CREATE TABLE tz_data ('
'region VARCHAR(64),'
'zone VARCHAR(64),'
'name VARCHAR(64))'))
# Test INSERT
for i in self.data:
yield from cursor.execute(
'INSERT INTO tz_data VALUES (%s, %s, %s)', i)
self.assertEqual(conn.affected_rows(), 1,
'affected_rows does not match')
yield from conn.commit()
# Test update, affected_rows()
def test_sscursor_scroll_errors(self):
conn = self.connections[0]
cursor = yield from conn.cursor(SSCursor)
yield from cursor.execute('SELECT * FROM tz_data;')
with self.assertRaises(NotSupportedError):
yield from cursor.scroll(-2, mode='relative')
yield from cursor.scroll(2, mode='absolute')
with self.assertRaises(NotSupportedError):
yield from cursor.scroll(1, mode='absolute')
with self.assertRaises(ProgrammingError):
yield from cursor.scroll(2, mode='not_valid_mode')
'escape_dict',
'escape_sequence',
'escape_string',
'Connection',
'Pool',
'connect',
'create_pool',
'Cursor',
'SSCursor',
'DictCursor',
'SSDictCursor'
]
(Connection, Pool, connect, create_pool, Cursor, SSCursor, DictCursor,
SSDictCursor) # pyflakes
def create_engine(minsize=1, maxsize=10, loop=None,
dialect=_dialect, pool_recycle=-1, compiled_cache=None,
**kwargs):
"""A coroutine for Engine creation.
Returns Engine instance with embedded connection pool.
The pool has *minsize* opened connections to MySQL server.
"""
deprecated_cursor_classes = [
DeserializationCursor, DictCursor, SSCursor, SSDictCursor,
]
cursorclass = kwargs.get('cursorclass', Cursor)
if not issubclass(cursorclass, Cursor) or any(
issubclass(cursorclass, cursor_class)
for cursor_class in deprecated_cursor_classes
):
raise ArgumentError('SQLAlchemy engine does not support '
'this cursor class')
coro = _create_engine(minsize=minsize, maxsize=maxsize, loop=loop,
dialect=dialect, pool_recycle=pool_recycle,
compiled_cache=compiled_cache, **kwargs)
return _EngineContextManager(coro)
yield from self._read_next()
self._rownumber += value
elif mode == 'absolute':
if value < self._rownumber:
raise NotSupportedError(
"Backwards scrolling not supported by this cursor")
end = value - self._rownumber
for _ in range(end):
yield from self._read_next()
self._rownumber = value
else:
raise ProgrammingError("unknown scroll mode %s" % mode)
class SSDictCursor(_DictCursorMixin, SSCursor):
"""An unbuffered cursor, which returns results as a dictionary """
await self._read_next()
self._rownumber += value
elif mode == 'absolute':
if value < self._rownumber:
raise NotSupportedError(
"Backwards scrolling not supported by this cursor")
end = value - self._rownumber
for _ in range(end):
await self._read_next()
self._rownumber = value
else:
raise ProgrammingError("unknown scroll mode %s" % mode)
class SSDictCursor(_DictCursorMixin, SSCursor):
"""An unbuffered cursor, which returns results as a dictionary """