datasette/tests/build_small_spatialite_db.py
Simon Willison da0b3ce2b7 New run_sanity_checks mechanism, for SpatiLite
Moved VirtualSpatialIndex check into a new mechanism that should allow
us to add further sanity checks in the future.

To test this I've had to commit a binary sample SpatiaLite database to
the repository. I included a build script for creating that database.

Closes #466
2019-05-11 15:55:30 -07:00

23 lines
796 B
Python

import sqlite3
# This script generates the spatialite.db file in our tests directory.
def generate_it(filename):
conn = sqlite3.connect(filename)
# Lead the spatialite extension:
conn.enable_load_extension(True)
conn.load_extension("/usr/local/lib/mod_spatialite.dylib")
conn.execute("select InitSpatialMetadata(1)")
conn.executescript("create table museums (name text)")
conn.execute("SELECT AddGeometryColumn('museums', 'point_geom', 4326, 'POINT', 2);")
# At this point it is around 5MB - we can shrink it dramatically by doing thisO
conn.execute("delete from spatial_ref_sys")
conn.execute("delete from spatial_ref_sys_aux")
conn.commit()
conn.execute("vacuum")
conn.close()
if __name__ == "__main__":
generate_it("spatialite.db")