Created
October 22, 2012 09:26
-
-
Save GrahamDumpleton/3930594 to your computer and use it in GitHub Desktop.
Script for validating data return for explain plan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
def doit(database, query): | |
connection = MySQLdb.connect(db=database) | |
try: | |
cursor = connection.cursor() | |
try: | |
cursor.execute(query) | |
columns = [] | |
if cursor.description: | |
for column in cursor.description: | |
columns.append(column[0]) | |
rows = cursor.fetchall() | |
if not columns and not rows: | |
return None | |
return (columns, rows) | |
except: | |
pass | |
finally: | |
cursor.close() | |
finally: | |
connection.close() | |
print doit("mydbname", "EXPLAIN SELECT * FROM UERequest") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment