diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-10-23 12:11:30 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-10-23 12:11:30 +0200 |
| commit | b45891d7782e8dfa9109310bfa97e5b3a81dc506 (patch) | |
| tree | fad375b18a54b9bc4d288dc343c98416cd0877da /scripts | |
| parent | aaa159247b5595b84c05f603bebc07201be335f4 (diff) | |
| download | PROJ-b45891d7782e8dfa9109310bfa97e5b3a81dc506.tar.gz PROJ-b45891d7782e8dfa9109310bfa97e5b3a81dc506.zip | |
Database: for clarity, put usage records after the object they are for
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/build_db.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/scripts/build_db.py b/scripts/build_db.py index 7346d210..848d9e5b 100755 --- a/scripts/build_db.py +++ b/scripts/build_db.py @@ -41,7 +41,7 @@ def ingest_sqlite_dump(cursor, filename): if f.read(3) != b'\xEF\xBB\xBF': f.seek(0, os.SEEK_SET) for line in f.readlines(): - line = line.replace(b'\r\n', '\n') + line = line.replace(b'\r\n', b'\n') if sys.version_info >= (3, 0, 0): line = line.decode('utf-8') #python3 else: @@ -970,10 +970,33 @@ proj_db_conn.commit() files = {} # Dump the generated database and split it one .sql file per table +# except for usage, that we append just after the record that the usage is for + +tables_with_usage = ('geodetic_datum', 'vertical_datum', 'geodetic_crs', 'vertical_crs', 'projected_crs', 'compound_crs', 'helmert_transformation', 'grid_transformation', 'other_transformation', 'conversion', 'concatenated_operation') +usages_map = {} +# INSERT INTO "usage" VALUES('EPSG','13089','geodetic_datum','EPSG','1037','EPSG','3340','EPSG','1028'); for line in proj_db_conn.iterdump(): if line.startswith('INSERT INTO "'): table_name = line[len('INSERT INTO "'):] table_name = table_name[0:table_name.find('"')] + if table_name == 'usage': + _, code, object_table_name, _, object_code, _, _, _, _ = line.split(',') + object_table_name = object_table_name[1:-1] + code = int(code[1:-1]) + object_code = int(object_code[1:-1]) + assert object_table_name in tables_with_usage, line + key = (object_table_name, object_code) + if key not in usages_map: + usages_map[key] = [(code, line)] + else: + usages_map[key].append((code, line)) + +for line in proj_db_conn.iterdump(): + if line.startswith('INSERT INTO "'): + table_name = line[len('INSERT INTO "'):] + table_name = table_name[0:table_name.find('"')] + if table_name == 'usage': + continue if table_name in files: f = files[table_name] else: @@ -981,6 +1004,17 @@ for line in proj_db_conn.iterdump(): f.write("--- This file has been generated by scripts/build_db.py. DO NOT EDIT !\n\n".encode('UTF-8')) files[table_name] = f f.write((line + '\n').encode('UTF-8')) + + if table_name in tables_with_usage: + pos = line.find("'EPSG','") + assert pos > 0 + pos += len("'EPSG','") + pos_end = line.find("'", pos) + code = int(line[pos:pos_end]) + usages = sorted(usages_map[(table_name, code)]) + for _, l in usages: + f.write((l + '\n').encode('UTF-8')) + elif line.startswith('CREATE TRIGGER conversion_method_check_insert_trigger'): table_name = 'conversion_triggers' if table_name in files: @@ -990,6 +1024,7 @@ for line in proj_db_conn.iterdump(): f.write("--- This file has been generated by scripts/build_db.py. DO NOT EDIT !\n\n".encode('UTF-8')) files[table_name] = f f.write((line + '\n').replace('BEFORE INSERT ON conversion', 'INSTEAD OF INSERT ON conversion').encode('UTF-8')) + #f = files['coordinate_operation'] #for row in non_imported_operations: # f.write(("--- Non imported: " + str(row) + '\n').encode('UTF-8')) |
