Fix migration & query runner for mysql

This commit is contained in:
Arik Fraimovich 2015-03-09 08:57:40 +02:00
parent bea11b0ac2
commit 6c716f23d9
2 changed files with 16 additions and 7 deletions

View File

@ -17,14 +17,24 @@ def update(data_source):
for value in values:
k, v = value.split("=", 1)
configuration[k] = v
if k == 'port':
configuration[k] = int(v)
data_source.options = json.dumps(configuration)
elif data_source.type == 'mysql':
mapping = {
'Server': 'host',
'User': 'user',
'Pwd': 'passwd',
'Database': 'db'
}
values = data_source.options.split(";")
configuration = {}
for value in values:
k, v = value.split("=", 1)
configuration[k] = v
configuration[mapping[k]] = v
data_source.options = json.dumps(configuration)
elif data_source.type == 'graphite':

View File

@ -44,15 +44,14 @@ class Mysql(BaseQueryRunner):
def __init__(self, configuration_json):
super(Mysql, self).__init__(configuration_json)
self.configuration.update({
"charset": "utf8",
"use_unicode": True
})
def run_query(self, query):
import MySQLdb
connection = MySQLdb.connect(**self.configuration)
connection = MySQLdb.connect(self.configuration['host'],
self.configuration['user'],
self.configuration['passwd'],
self.configuration['db'],
charset='utf8', use_unicode=True)
cursor = connection.cursor()
logger.debug("MySQL running query: %s", query)