Skip to content
Permalink
Browse files

Simplify lastrowid. Update comments. Simplify build matrix.

  • Loading branch information...
jamadden committed Jan 25, 2017
1 parent c5200e8 commit a2c398e1c2768c85cbf713a1d8a34d4ee0a5f367
Showing with 18 additions and 24 deletions.
  1. +0 −6 .travis.yml
  2. +13 −11 relstorage/adapters/mysql/drivers.py
  3. +5 −7 relstorage/adapters/mysql/oidallocator.py
@@ -16,10 +16,6 @@ addons:

matrix:
include:
- python: 2.7
env:
- ENV=pymysqlconnector
- RS_MY_DRIVER=pymysqlconnector
- python: 2.7
env:
- ENV=cmysqlconnector
@@ -38,8 +34,6 @@ matrix:
- python: pypy-5.4.1
env: ENV=mysql

- python: 3.6
env: ENV=pymysql
- python: 3.5
env: ENV=pymysql
- python: 2.7
@@ -43,7 +43,8 @@

moduleProvides(IDBDriverOptions)

class _AbstractDriver(object):
class AbstractDriver(object):
# Common compatibility shims, overriden as needed.

def set_autocommit(self, conn, value):
conn.autocommit(value)
@@ -58,7 +59,7 @@ def cursor(self, conn):
else:

@implementer(IDBDriver)
class MySQLdbDriver(_AbstractDriver):
class MySQLdbDriver(AbstractDriver):
__name__ = 'MySQLdb'
disconnected_exceptions, close_exceptions, lock_exceptions = _standard_exceptions(MySQLdb)
use_replica_exceptions = (MySQLdb.OperationalError,)
@@ -80,7 +81,7 @@ class MySQLdbDriver(_AbstractDriver):
import pymysql.err

@implementer(IDBDriver)
class PyMySQLDriver(_AbstractDriver):
class PyMySQLDriver(AbstractDriver):
__name__ = 'PyMySQL'

disconnected_exceptions, close_exceptions, lock_exceptions = _standard_exceptions(pymysql)
@@ -143,7 +144,7 @@ def escape_string(value, mapping=None):
else:

@implementer(IDBDriver)
class MySQLConnectorDriver(_AbstractDriver):
class MySQLConnectorDriver(AbstractDriver):
__name__ = "mysqlconnector"

disconnected_exceptions, close_exceptions, lock_exceptions = _standard_exceptions(mysql.connector)
@@ -153,7 +154,7 @@ class MySQLConnectorDriver(_AbstractDriver):
_connect = staticmethod(mysql.connector.connect)

def connect(self, *args, **kwargs):
# It defaults to the (slow) pure-python version
# It defaults to the (slower) pure-python version
# NOTE: The C implementation doesn't support the prepared
# operations.
# NOTE: The C implementation returns bytes when the py implementation
@@ -175,26 +176,27 @@ def connect(self, *args, **kwargs):
con.set_unicode(False)

return con
#return _ConnWrapper(con)


def set_autocommit(self, conn, value):
# We use a property instead of a method
conn.autocommit = value

def cursor(self, conn):
# By default, the cursor won't buffer, so we don't know
# how many rows there are. There are asserts about that
# in several places.
# The C connection doesn't accept the 'prepared' keyword,
# and if you try to use a prepared cursor with it, it doesn't
# work correctly.
# how many rows there are. That's fine and within the DB-API spec.
# The Python implementation is much faster if we don't ask it to.
# The C connection doesn't accept the 'prepared' keyword.
# You can't have both a buffered and prepared cursor.

cursor = conn.cursor()
if not hasattr(cursor, 'connection'):
# We depend on the reverse mapping in some places.
# The python implementation keeps a weakref proxy in
# _connection, but if we try to access that on the C extension,
# we get a AttributeError, so if we then try to access 'connection',
# it aborts the process. So we go ahead and make a hard ref.
# See mysql_connection().
cursor.connection = conn
return cursor

@@ -36,13 +36,11 @@ def new_oids(self, cursor):
"""Return a sequence of new, unused OIDs."""
stmt = "INSERT INTO new_oid VALUES ()"
cursor.execute(stmt)
try:
# mysql connector extension
n = cursor.lastrowid
except AttributeError:
# mysqldb/mysqlclient extension.
conn = mysql_connection(cursor)
n = conn.insert_id()
# This is a DB-API extension. Fortunately, all
# supported drivers implement it. (In the past we used
# cursor.connection.insert_id(), which was specific to MySQLdb)
n = cursor.lastrowid

if n % 100 == 0:
# Clean out previously generated OIDs.
stmt = "DELETE FROM new_oid WHERE zoid < %s"

0 comments on commit a2c398e

Please sign in to comment.
You can’t perform that action at this time.