From a6562ab1bc01961795bf1fb8fcfcf6262c6da1ad Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 15 Nov 2022 13:38:38 +0100 Subject: [PATCH] Export sorted --- wgmaster/wgexport.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wgmaster/wgexport.py b/wgmaster/wgexport.py index 9ce862d..96155e3 100644 --- a/wgmaster/wgexport.py +++ b/wgmaster/wgexport.py @@ -38,8 +38,11 @@ if __name__ == '__main__': tbls = tbls.fetchall() for file, _, t_name, t_type, _ in tbls: print(t_name) - cur.execute(f"SELECT * FROM {t_name};") - print([(t[0], t[1]) for t in cur.description]) + cur.execute(f"SELECT TOP 1 * FROM {t_name};") + desc = [(t[0], t[1]) for t in cur.description] + cur.fetchall() + print(desc) + cur.execute(f"SELECT * FROM {t_name} ORDER BY `{desc[0][0]}`;") cols = [t[0] for t in cur.description] with open(f'tables/{t_name}.csv', 'wb+') as f: