mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-04 16:34:12 +02:00
--load-extension option for sqlite-utils query, closes #134
This commit is contained in:
parent
bf4c6b7c82
commit
7e9aad7e1c
3 changed files with 50 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ from click.testing import CliRunner
|
|||
import json
|
||||
import os
|
||||
import pytest
|
||||
from sqlite_utils.utils import sqlite3
|
||||
from sqlite_utils.utils import sqlite3, find_spatialite
|
||||
|
||||
from .utils import collapse_whitespace
|
||||
|
||||
|
|
@ -885,6 +885,29 @@ def test_query_raw(db_path, content, is_binary):
|
|||
assert result.output == str(content)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not find_spatialite(), reason="Could not find SpatiaLite extension")
|
||||
@pytest.mark.skipif(
|
||||
not hasattr(sqlite3.Connection, "enable_load_extension"),
|
||||
reason="sqlite3.Connection missing enable_load_extension",
|
||||
)
|
||||
def test_query_load_extension():
|
||||
# Without --load-extension:
|
||||
result = CliRunner().invoke(cli.cli, [":memory:", "select spatialite_version()"])
|
||||
assert result.exit_code == 1
|
||||
assert "no such function: spatialite_version" in repr(result)
|
||||
# With --load-extension:
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
[
|
||||
":memory:",
|
||||
"select spatialite_version()",
|
||||
"--load-extension={}".format(find_spatialite()),
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0, result.stdout
|
||||
assert ["spatialite_version()"] == list(json.loads(result.output)[0].keys())
|
||||
|
||||
|
||||
def test_query_memory_does_not_create_file(tmpdir):
|
||||
owd = os.getcwd()
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue