Skip to content

Commit

Permalink
Fix the Issues bdarnell#43
Browse files Browse the repository at this point in the history
  • Loading branch information
linsir committed Aug 1, 2017
1 parent e7bd428 commit 075b458
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions torndb.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Connection(object):
MySQLdb version >= 1.2.5 and MySQL version > 5.1.12.
"""
def __init__(self, host, database, user=None, password=None,
max_idle_time=7 * 3600, connect_timeout=0,
max_idle_time=7 * 3600, connect_timeout=10,
time_zone="+0:00", charset = "utf8", sql_mode="TRADITIONAL",
**kwargs):
self.host = host
Expand Down Expand Up @@ -253,17 +253,21 @@ def __getattr__(self, name):
raise AttributeError(name)

if MySQLdb is not None:
# Fix the access conversions to properly recognize unicode/binary
FIELD_TYPE = MySQLdb.constants.FIELD_TYPE
FLAG = MySQLdb.constants.FLAG
CONVERSIONS = copy.copy(MySQLdb.converters.conversions)
if MySQLdb.__package__ != 'pymysql':
# Fix the access conversions to properly recognize unicode/binary
FIELD_TYPE = MySQLdb.constants.FIELD_TYPE
FLAG = MySQLdb.constants.FLAG
CONVERSIONS = copy.copy(MySQLdb.converters.conversions)

field_types = [FIELD_TYPE.BLOB, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING]
if 'VARCHAR' in vars(FIELD_TYPE):
field_types.append(FIELD_TYPE.VARCHAR)
field_types = [FIELD_TYPE.BLOB, FIELD_TYPE.STRING, FIELD_TYPE.VAR_STRING]
if 'VARCHAR' in vars(FIELD_TYPE):
field_types.append(FIELD_TYPE.VARCHAR)

for field_type in field_types:
CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type]
else:
CONVERSIONS = {}

for field_type in field_types:
CONVERSIONS[field_type] = [(FLAG.BINARY, str)] + CONVERSIONS[field_type]

# Alias some common MySQL exceptions
IntegrityError = MySQLdb.IntegrityError
Expand Down

0 comments on commit 075b458

Please sign in to comment.