Hide Spatialite system tables

They were getting on my nerves.
pull/200/head
Russ Garrett 2018-04-11 22:20:25 +01:00
rodzic bfb4e45a7b
commit 765b5d6771
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 68880BB652AB0570
2 zmienionych plików z 18 dodań i 3 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ from .utils import (
CustomJSONEncoder,
compound_keys_after_sql,
detect_fts_sql,
detect_spatialite,
escape_css_string,
escape_sqlite,
filters_should_redirect,
@ -1121,7 +1122,7 @@ class Datasette:
tables[table]['foreign_keys'] = info
# Mark tables 'hidden' if they relate to FTS virtual tables
fts_tables = [
hidden_tables = [
r['name']
for r in conn.execute(
'''
@ -1131,9 +1132,18 @@ class Datasette:
'''
)
]
if detect_spatialite(conn):
# Also hide Spatialite internal tables
hidden_tables += [
'ElementaryGeometries', 'SpatialIndex', 'geometry_columns',
'spatial_ref_sys', 'spatialite_history', 'sql_statements_log',
'sqlite_sequence', 'views_geometry_columns', 'virts_geometry_columns'
]
for t in tables.keys():
for fts_table in fts_tables:
if t == fts_table or t.startswith(fts_table):
for hidden_table in hidden_tables:
if t == hidden_table or t.startswith(hidden_table):
tables[t]['hidden'] = True
continue

Wyświetl plik

@ -370,6 +370,11 @@ def get_all_foreign_keys(conn):
return table_to_foreign_keys
def detect_spatialite(conn):
rows = conn.execute('select 1 from sqlite_master where tbl_name = "geometry_columns"').fetchall()
return len(rows) > 0
def detect_fts(conn, table, return_sql=False):
"Detect if table has a corresponding FTS virtual table and return it"
rows = conn.execute(detect_fts_sql(table)).fetchall()