diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index d25b1df..3d4f767 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -1407,7 +1407,7 @@ def create_database(path, enable_wal, init_spatialite, load_extension): # load spatialite from expected locations and initialize metadata if init_spatialite: - db.init_spatialite() + db.init_spatialite(find_spatialite() or load_extension) db.vacuum() @@ -2902,7 +2902,7 @@ def add_geometry_column( # load spatialite, one way or another if load_extension: _load_extensions(db, load_extension) - db.init_spatialite() + db.init_spatialite(find_spatialite() or load_extension) if db[table].add_geometry_column( column_name, geometry_type, srid, coord_dimension, not_null @@ -2934,7 +2934,7 @@ def create_spatial_index(db_path, table, column_name, load_extension): # load spatialite if load_extension: _load_extensions(db, load_extension) - db.init_spatialite() + db.init_spatialite(find_spatialite() or load_extension) if column_name not in db[table].columns_dict: raise click.ClickException( diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index e819d17..c06e6a0 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -2876,7 +2876,6 @@ class Table(Queryable): self.add_missing_columns(chunk) result = self.db.execute(query, params) elif e.args[0] == "too many SQL variables": - first_half = chunk[: len(chunk) // 2] second_half = chunk[len(chunk) // 2 :] diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index 4e5bbcc..87d573d 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -28,6 +28,8 @@ except ImportError: SPATIALITE_PATHS = ( "/usr/lib/x86_64-linux-gnu/mod_spatialite.so", "/usr/local/lib/mod_spatialite.dylib", + "/usr/local/lib/mod_spatialite.so", + "/opt/homebrew/lib/mod_spatialite.dylib", ) # Mainly so we can restore it if needed in the tests: diff --git a/tests/test_gis.py b/tests/test_gis.py index 3b1fbf1..8a4a028 100644 --- a/tests/test_gis.py +++ b/tests/test_gis.py @@ -234,3 +234,30 @@ def test_cli_create_spatial_index(tmpdir): assert 0 == result.exit_code assert "idx_locations_geometry" in db.table_names() + + +def test_cli_create_spatial_index_with_path(tmpdir): + # create a rowid table with one column + db_path = tmpdir / "spatial.db" + db = Database(str(db_path)) + db.init_spatialite() + + table = db["locations"].create({"name": str}) + table.add_geometry_column("geometry", "POINT") + + path = find_spatialite() + result = CliRunner().invoke( + cli, + [ + "create-spatial-index", + str(db_path), + table.name, + "geometry", + "--load-extension", + path, + ], + ) + + assert 0 == result.exit_code + + assert "idx_locations_geometry" in db.table_names()