Skip to content

Commit 414cbaf

Browse files
committed
Print SELECT results in run_sql_file.py
1 parent 169805e commit 414cbaf

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

labs/travelapp/run_sql_file.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ def resolve_region():
7171
batch_num += 1
7272
try:
7373
cursor.execute(batch)
74-
# Fetch and print messages
75-
while cursor.nextset():
76-
pass
74+
# Print any result sets
75+
while True:
76+
if cursor.description:
77+
cols = [d[0] for d in cursor.description]
78+
rows = cursor.fetchall()
79+
if rows:
80+
print(' '.join(cols))
81+
print(' '.join(['-' * len(c) for c in cols]))
82+
for row in rows:
83+
print(' '.join([str(v) if v is not None else 'NULL' for v in row]))
84+
print()
85+
if not cursor.nextset():
86+
break
7787
except Exception as e:
7888
print(f"Error in batch {batch_num}: {e}")
7989

0 commit comments

Comments
 (0)