mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 19:04:32 +02:00
Compare commits
8 commits
main
...
pysqlite3-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a7ef2fe20 | ||
|
|
4beb87f446 | ||
|
|
71b6c3803e | ||
|
|
f990e134aa | ||
|
|
93b059dd23 | ||
|
|
c91f1e6957 | ||
|
|
e02c8f35d4 |
||
|
|
2cfffbd33d |
5 changed files with 35 additions and 21 deletions
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
|
|
@ -13,6 +13,11 @@ jobs:
|
||||||
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
|
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
|
||||||
numpy: [0, 1]
|
numpy: [0, 1]
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
include:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
python-version: "3.10"
|
||||||
|
numpy: 0
|
||||||
|
pysqlite3_sqlite_3_37: 1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
|
@ -32,6 +37,20 @@ jobs:
|
||||||
- name: Optionally install numpy
|
- name: Optionally install numpy
|
||||||
if: matrix.numpy == 1
|
if: matrix.numpy == 1
|
||||||
run: pip install numpy
|
run: pip install numpy
|
||||||
|
- name: Optionally install pysqlite3 with SQLite 3.37
|
||||||
|
if: matrix.pysqlite3_sqlite_3_37 == 1
|
||||||
|
run: |-
|
||||||
|
cd /tmp
|
||||||
|
mkdir sqlite-3.37
|
||||||
|
cd sqlite-3.37
|
||||||
|
wget 'https://www.sqlite.org/2021/sqlite-amalgamation-3370000.zip'
|
||||||
|
unzip sqlite-amalgamation-3370000.zip
|
||||||
|
git clone https://github.com/coleifer/pysqlite3
|
||||||
|
cp sqlite-amalgamation-3370000/sqlite3.[ch] pysqlite3
|
||||||
|
cd pysqlite3
|
||||||
|
pip install wheel
|
||||||
|
python setup.py build_static build bdist_wheel
|
||||||
|
pip install /tmp/sqlite-3.37/pysqlite3/dist/*.whl
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
pytest -v
|
pytest -v
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import tabulate
|
||||||
from .utils import (
|
from .utils import (
|
||||||
file_progress,
|
file_progress,
|
||||||
find_spatialite,
|
find_spatialite,
|
||||||
|
iterdump,
|
||||||
sqlite3,
|
sqlite3,
|
||||||
decode_base64_values,
|
decode_base64_values,
|
||||||
progressbar,
|
progressbar,
|
||||||
|
|
@ -326,7 +327,7 @@ def dump(path, load_extension):
|
||||||
"""Output a SQL dump of the schema and full contents of the database"""
|
"""Output a SQL dump of the schema and full contents of the database"""
|
||||||
db = sqlite_utils.Database(path)
|
db = sqlite_utils.Database(path)
|
||||||
_load_extensions(db, load_extension)
|
_load_extensions(db, load_extension)
|
||||||
for line in db.conn.iterdump():
|
for line in iterdump(db.conn):
|
||||||
click.echo(line)
|
click.echo(line)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1320,7 +1321,7 @@ def memory(
|
||||||
return
|
return
|
||||||
|
|
||||||
if dump:
|
if dump:
|
||||||
for line in db.conn.iterdump():
|
for line in iterdump(db.conn):
|
||||||
click.echo(line)
|
click.echo(line)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -1330,7 +1331,7 @@ def memory(
|
||||||
|
|
||||||
if save:
|
if save:
|
||||||
db2 = sqlite_utils.Database(save)
|
db2 = sqlite_utils.Database(save)
|
||||||
for line in db.conn.iterdump():
|
for line in iterdump(db.conn):
|
||||||
db2.execute(line)
|
db2.execute(line)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import enum
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from sqlite3.dump import _iterdump as iterdump # type: ignore # noqa: F401
|
||||||
from typing import cast, BinaryIO, Iterable, Optional, Tuple, Type
|
from typing import cast, BinaryIO, Iterable, Optional, Tuple, Type
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from sqlite_utils.db import Database, ColumnDetails
|
from sqlite_utils.db import Database, ColumnDetails
|
||||||
from sqlite_utils import cli
|
from sqlite_utils import cli
|
||||||
|
from sqlite_utils.utils import iterdump
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
import pytest
|
import pytest
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
@ -79,7 +80,7 @@ def test_analyze_column(db_to_analyze, column, expected):
|
||||||
def db_to_analyze_path(db_to_analyze, tmpdir):
|
def db_to_analyze_path(db_to_analyze, tmpdir):
|
||||||
path = str(tmpdir / "test.db")
|
path = str(tmpdir / "test.db")
|
||||||
db = sqlite3.connect(path)
|
db = sqlite3.connect(path)
|
||||||
db.executescript("\n".join(db_to_analyze.conn.iterdump()))
|
db.executescript("\n".join(iterdump(db_to_analyze.conn)))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -254,13 +254,12 @@ def test_disable_fts(fresh_db, create_triggers):
|
||||||
assert ["searchable"] == fresh_db.table_names()
|
assert ["searchable"] == fresh_db.table_names()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("table_to_fix", ["searchable", "searchable_fts"])
|
def test_rebuild_fts(fresh_db):
|
||||||
def test_rebuild_fts(fresh_db, table_to_fix):
|
|
||||||
table = fresh_db["searchable"]
|
table = fresh_db["searchable"]
|
||||||
table.insert(search_records[0])
|
table.insert(search_records[0])
|
||||||
table.enable_fts(["text", "country"])
|
table.enable_fts(["text", "country"])
|
||||||
# Run a search
|
# Run a search
|
||||||
rows = list(table.search("tanuki"))
|
rows = list(table.search("are"))
|
||||||
assert len(rows) == 1
|
assert len(rows) == 1
|
||||||
assert {
|
assert {
|
||||||
"rowid": 1,
|
"rowid": 1,
|
||||||
|
|
@ -268,21 +267,14 @@ def test_rebuild_fts(fresh_db, table_to_fix):
|
||||||
"country": "Japan",
|
"country": "Japan",
|
||||||
"not_searchable": "foo",
|
"not_searchable": "foo",
|
||||||
}.items() <= rows[0].items()
|
}.items() <= rows[0].items()
|
||||||
# Delete from searchable_fts_data
|
# Insert another record
|
||||||
fresh_db["searchable_fts_data"].delete_where()
|
table.insert(search_records[1])
|
||||||
# This should have broken the index
|
# This should NOT show up in a searchs
|
||||||
with pytest.raises(sqlite3.DatabaseError):
|
assert len(list(table.search("are"))) == 1
|
||||||
list(table.search("tanuki"))
|
|
||||||
# Running rebuild_fts() should fix it
|
# Running rebuild_fts() should fix it
|
||||||
fresh_db[table_to_fix].rebuild_fts()
|
table.rebuild_fts()
|
||||||
rows2 = list(table.search("tanuki"))
|
rows2 = list(table.search("are"))
|
||||||
assert len(rows2) == 1
|
assert len(rows2) == 2
|
||||||
assert {
|
|
||||||
"rowid": 1,
|
|
||||||
"text": "tanuki are running tricksters",
|
|
||||||
"country": "Japan",
|
|
||||||
"not_searchable": "foo",
|
|
||||||
}.items() <= rows2[0].items()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("invalid_table", ["does_not_exist", "not_searchable"])
|
@pytest.mark.parametrize("invalid_table", ["does_not_exist", "not_searchable"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue