Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize SpatiaLite without KNN virtual table #11

Open
simonw opened this issue Mar 8, 2021 · 4 comments
Open

Initialize SpatiaLite without KNN virtual table #11

simonw opened this issue Mar 8, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Mar 8, 2021

Now that Homebrew has upgraded SpatiaLite on my laptop to 5.0 this tool seems to be creating databases that aren't compatible with SpatiaLite 4.3.x - which currently breaks datasette publish (see simonw/datasette#1249).

I think the problem is that a KNN virtual table is being created - CREATE VIRTUAL TABLE KNN USING VirtualKNN();

Since the databases created by this tool don't necessarily need KNN it would be better if it didn't create that.

@simonw simonw added the enhancement New feature or request label Mar 8, 2021
@simonw
Copy link
Owner Author

simonw commented Mar 8, 2021

I think this is the revelant code:

db.conn.enable_load_extension(True)
db.conn.load_extension(lib)
# Initialize SpatiaLite if not yet initialized
if "spatial_ref_sys" in db.table_names():
return
db.conn.execute("select InitSpatialMetadata(1)")
def ensure_table_has_geometry(db, table, table_srid):
if "geometry" not in db[table].columns_dict:
db.conn.execute(
"SELECT AddGeometryColumn(?, 'geometry', ?, 'GEOMETRY', 2);",
[table, table_srid],
)

@simonw
Copy link
Owner Author

simonw commented Mar 8, 2021

https://www.gaia-gis.it/fossil/libspatialite/wiki?name=KNN says:

Every new db-file being created with 4.4.0 will always automatically define a KNN virtual table.
On any earlier version of a SpatiaLite db-file, you can add the KNN support by manually executing the above SQL statement.
Note: VirtualKNN necessarily requires 4.4.0 binary support, so any attempt to open a db-file including a VirtualKNN table by using some previous version (<= 4.3.0a) will surely raise an error condition.

@simonw
Copy link
Owner Author

simonw commented Mar 8, 2021

Maybe the fix is to run DROP TABLE KNN;?

@simonw
Copy link
Owner Author

simonw commented Mar 8, 2021

I tried using this against my broken DB file:

spatialite /tmp/counties.db 'drop table KNN';

And it worked - I could then deploy that database using an older version of SpatiaLite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant