mirror of
https://github.com/getredash/redash.git
synced 2025-12-25 01:03:20 -05:00
Fixed MySQL Runner
This commit is contained in:
@@ -14,40 +14,30 @@ import select
|
||||
from .utils import JSONEncoder
|
||||
|
||||
def mysql(connection_string):
|
||||
def column_friendly_name(column_name):
|
||||
return column_name
|
||||
|
||||
if connection_string.endswith(';'):
|
||||
connection_string = connection_string[0:-1]
|
||||
|
||||
def query_runner(query):
|
||||
# # TODO: remove these lines
|
||||
# import settings
|
||||
# connection_string = settings.CONNECTION_STRING
|
||||
# # ENDTODO
|
||||
print connection_string
|
||||
|
||||
if connection_string.endswith(';'):
|
||||
connection_string = connection_string[0:-1]
|
||||
|
||||
connections_params = [entry.split('=')[1] for entry in connection_string.split(';')]
|
||||
connection = MySQLdb.connect(*connections_params)
|
||||
cursor = connection.cursor()
|
||||
|
||||
|
||||
logging.debug("mysql got query: %s", query)
|
||||
|
||||
try:
|
||||
cursor.execute(query)
|
||||
|
||||
data = cursor.fetchall()
|
||||
|
||||
|
||||
num_fields = len(cursor.description)
|
||||
column_names = [i[0] for i in cursor.description]
|
||||
|
||||
rows = [dict(zip(column_names, row)) for row in data]
|
||||
|
||||
|
||||
columns = [{'name': col_name,
|
||||
'friendly_name': column_friendly_name(col_name),
|
||||
'friendly_name': col_name,
|
||||
'type': None} for col_name in column_names]
|
||||
|
||||
|
||||
data = {'columns': columns, 'rows': rows}
|
||||
json_data = json.dumps(data, cls=JSONEncoder)
|
||||
error = None
|
||||
@@ -59,8 +49,8 @@ def mysql(connection_string):
|
||||
raise sys.exc_info()[1], None, sys.exc_info()[2]
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
return json_data, error
|
||||
|
||||
|
||||
return json_data, error
|
||||
|
||||
|
||||
return query_runner
|
||||
Reference in New Issue
Block a user