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

Move "no such module: VirtualSpatialIndex" code elsewhere #466

Closed
simonw opened this issue May 11, 2019 · 2 comments
Closed

Move "no such module: VirtualSpatialIndex" code elsewhere #466

simonw opened this issue May 11, 2019 · 2 comments

Comments

@simonw
Copy link
Owner

simonw commented May 11, 2019

We currently show a useful warning (from #331) when the user tries to open a spatialite database without first loading the module:

datasette/datasette/app.py

Lines 547 to 554 in c692cd2

except sqlite3.OperationalError as e:
if e.args[0] == "no such module: VirtualSpatialIndex":
raise click.UsageError(
"It looks like you're trying to load a SpatiaLite"
" database without first loading the SpatiaLite module."
"\n\nRead more: https://datasette.readthedocs.io/en/latest/spatialite.html"
)
else:

This code is part of .inspect() which is going away - see #462 - so I need to find somewhere else for it to live.

@simonw simonw added the small label May 11, 2019
@simonw simonw added this to the 0.28 milestone May 11, 2019
@simonw
Copy link
Owner Author

simonw commented May 11, 2019

This is a little bit tricky. This SQL looks like it may detect Spatialite tables:

select * from sqlite_master where type = "table"
and sql like "%CREATE VIRTUAL TABLE%"
and sql like "%USING VirtualSpatialIndex%"

But where to put it? I think this should go in a new "checks" mechanism, where we run checks against every connected database on Datasette startup.

@simonw
Copy link
Owner Author

simonw commented May 11, 2019

To build a unit test for this I'm going to have to ship a small spatialite.db binary database as part of the git repo.

This is because I need the tests to run even when the spatialite module is not available - but you cannot create a spatialite database without having access to that module.

I'll include a build script in the repo for constructing that database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant