Skip to content
Permalink
Browse files

Support PyMySQL driver for MySQL

  • Loading branch information...
varunpurohit76 committed Feb 18, 2017
1 parent 1702bd0 commit f85221ddc7d4a7a31effb0289a760c6e55c59ee9
Showing with 16 additions and 5 deletions.
  1. +6 −1 test/db.py
  2. +10 −4 web/db.py
@@ -23,6 +23,7 @@ def tearDown(self):
def _testable(self):
try:
webtest.setup_database(self.dbname, driver=self.driver)
print("Running tests for %s" % self.__class__.__name__, file=web.debug)
return True
except ImportError as e:
print(str(e), "(ignoring %s)" % self.__class__.__name__, file=web.debug)
@@ -156,8 +157,9 @@ def testPooling(self):
class SqliteTest_pysqlite2(SqliteTest):
driver = "pysqlite2.dbapi2"

class MySQLTest(DBTest):
class MySQLTest_MySQLdb(DBTest):
dbname = "mysql"
driver = "MySQLdb"

def setUp(self):
self.db = webtest.setup_database(self.dbname)
@@ -168,6 +170,9 @@ def testBoolean(self):
# boolean datatype is not suppoted in MySQL (at least until v5.0)
pass

class MySQLTest_PyMySQL(MySQLTest_MySQLdb):
driver="pymysql"

del DBTest

def is_test(cls):
@@ -1000,10 +1000,16 @@ def _connect_with_pooling(self, keywords):

class MySQLDB(DB):
def __init__(self, **keywords):
import MySQLdb as db
if 'pw' in keywords:
keywords['passwd'] = keywords['pw']
del keywords['pw']

db = import_driver(["MySQLdb", "pymysql"], preferred=keywords.pop('driver', None))
if db.__name__ == "MySQLdb":
if 'pw' in keywords:
keywords['passwd'] = keywords['pw']
del keywords['pw']
if db.__name__ == "pymysql":
if 'pw' in keywords:
keywords['password'] = keywords['pw']
del keywords['pw']

if 'charset' not in keywords:
keywords['charset'] = 'utf8'

0 comments on commit f85221d

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