Created
October 13, 2017 01:15
-
-
Save ivanjr0/02892cf61efd532597f9d93382f72804 to your computer and use it in GitHub Desktop.
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 re | |
import shlex | |
from glob import glob | |
from subprocess import Popen, PIPE | |
r = [] | |
for f in glob('questao*.sql'): | |
n = int(f[len('questao'):-len('.sql')]) | |
r.append((n, f)) | |
r = sorted(r) | |
for n, f in r: | |
p = Popen(shlex.split('mysql -u root --database=IMDB'), stdin=PIPE, stdout=PIPE, stderr=PIPE) | |
sql = open(f).readlines() | |
sql = ' '.join([l.strip() for l in sql if l.strip() and not l.strip().startswith('--')]) | |
sql = re.sub('\s+', ' ', sql) | |
sql = sql.replace('( ', '(') | |
sql = sql.replace(' )', ')') | |
out, _ = p.communicate(sql) | |
header, body = out.split('\n', 1) | |
columns = header.count('\t') + 1 | |
rows = body.count('\n') | |
print('#%d | %d | %d | %s' % (n, rows, columns, sql)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment