Skip to content

Commit

Permalink
解决bit类型字段查询展示异常的问题 fix #495
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Nov 2, 2019
1 parent c17e7d4 commit 056d859
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sql/engines/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sqlparse
from MySQLdb.connections import numeric_part
from MySQLdb.constants import FIELD_TYPE

from sql.engines.goinception import GoInceptionEngine
from sql.utils.sql_utils import get_syntax_type, remove_comments
Expand All @@ -18,17 +19,23 @@


class MysqlEngine(EngineBase):

def get_connection(self, db_name=None):
# https://stackoverflow.com/questions/19256155/python-mysqldb-returning-x01-for-bit-values
conversions = MySQLdb.converters.conversions
conversions[FIELD_TYPE.BIT] = lambda data: data == b'\x01'
if self.conn:
self.thread_id = self.conn.thread_id()
return self.conn
if db_name:
self.conn = MySQLdb.connect(host=self.host, port=self.port, user=self.user, passwd=self.password,
db=db_name, charset=self.instance.charset or 'utf8mb4',
conv=conversions,
connect_timeout=10)
else:
self.conn = MySQLdb.connect(host=self.host, port=self.port, user=self.user, passwd=self.password,
charset=self.instance.charset or 'utf8mb4',
conv=conversions,
connect_timeout=10)
self.thread_id = self.conn.thread_id()
return self.conn
Expand Down

0 comments on commit 056d859

Please sign in to comment.