Database: Update plz and template creation

This commit is contained in:
2023-09-17 21:26:00 +02:00
parent 8f78c8ce89
commit 5ca6cb2093
4 changed files with 10 additions and 6 deletions

View File

@ -279,20 +279,20 @@ def write_sql(plz_rows: List[PlzRow], plz_dest_rows: List[PlzDestRow], kgv_rows:
pr = set()
with open('90.plz.sql', 'wb') as f:
f.write(b"\nINSERT INTO AT_gem VALUES\n")
for gkz, (name, _, _) in gemeinden.items():
for gkz, (name, _, _) in sorted(gemeinden.items(), key=lambda i: i[0]):
f.write(f"({gkz:5}, '{name}'),\n".encode('utf-8'))
f.seek(-2, 1)
f.write(b';\n')
f.write(b"\nINSERT INTO AT_kg VALUES\n")
for kgnr, name, gkz, _ in kgv_rows:
for kgnr, name, gkz, _ in sorted(kgv_rows, key=lambda i: i[0]):
gemeinden[gkz][1].append(kgnr)
f.write(f"({kgnr:5}, {gkz:5}, '{name}'),\n".encode('utf-8'))
f.seek(-2, 1)
f.write(b';\n')
f.write(b"\nINSERT INTO AT_ort VALUES\n")
for okz, (name, gkz) in ov.items():
for okz, (name, gkz) in sorted(ov.items(), key=lambda i: i[0]):
kgnr_o = None
if name.startswith('Wien '):
@ -323,14 +323,14 @@ def write_sql(plz_rows: List[PlzRow], plz_dest_rows: List[PlzDestRow], kgv_rows:
f.write(b';\n')
f.write(b"\nINSERT INTO AT_plz VALUES\n")
for plz, ort, blnr, plz_type, internal, addr, po_box in plz_rows:
for plz, ort, blnr, plz_type, internal, addr, po_box in sorted(plz_rows, key=lambda i: i[0]):
f.write(f"({plz:4}, '{ort}', {blnr}, '{plz_type}', {internal and 'TRUE' or 'FALSE'}, "
f"{addr and 'TRUE' or 'FALSE'}, {po_box and 'TRUE' or 'FALSE'}),\n".encode('utf-8'))
f.seek(-2, 1)
f.write(b';\n')
f.write(b"\nINSERT INTO AT_plz_dest VALUES\n")
for plz, dest, okz, _, _, _ in plz_dest_rows:
for plz, dest, okz, _, _, _ in sorted(plz_dest_rows, key=lambda i: (i[0], i[2])):
f.write(f"({plz:4}, {okz:5}, '{dest}'),\n".encode('utf-8'))
f.seek(-2, 1)
f.write(b';\n')

View File

@ -5,7 +5,7 @@ INSERT INTO wb_gl VALUES
(3, 'Falkensteiner Hügelland');
INSERT INTO branch VALUES
('M', 'Matzen', 'AT', 224303541, 'Winzerstraße 1', '+43 2289 12345', '+43 2289 12345', NULL);
('M', 'Matzen', 40, 224303541, 'Winzerstraße 1', '+43 2289 12345', '+43 2289 12345', NULL);
INSERT INTO wine_attribute VALUES
('B', 'BIO AT-BIO-302', 10000, TRUE),

View File

@ -3,10 +3,12 @@
SET dir=.
sqlite3 -box^
-cmd ".read %dir%/sql/v01/10.create.sql"^
-cmd ".read %dir%/sql/v01/11.timestamp-trigger.sql"^
-cmd ".read %dir%/sql/v01/20.view.sql"^
-cmd ".read %dir%/sql/v01/50.base.sql"^
-cmd ".read %dir%/data/90.plz.sql"^
-cmd ".read %dir%/sql/91.plz-fix.sql"^
-cmd ".read %dir%/sql/v01/92.wb_gem.sql"^
-cmd ".read %dir%/sql/v01/99.schema_version.sql"^
-cmd ".read %dir%/sql/sample.sql"^
%@%

View File

@ -2,10 +2,12 @@
dir="."
sqlite3 -box \
-cmd ".read $dir/sql/v01/10.create.sql" \
-cmd ".read $dir/sql/v01/11.timestamp-trigger.sql" \
-cmd ".read $dir/sql/v01/20.view.sql" \
-cmd ".read $dir/sql/v01/50.base.sql" \
-cmd ".read $dir/data/90.plz.sql" \
-cmd ".read $dir/sql/91.plz-fix.sql" \
-cmd ".read $dir/sql/v01/92.wb_gem.sql" \
-cmd ".read $dir/sql/v01/99.schema_version.sql" \
-cmd ".read $dir/sql/sample.sql" \
$@