mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 10:04:10 +02:00
Use pysqlite3 if available
This commit is contained in:
parent
c88f0a4d46
commit
152eb2afaf
6 changed files with 10 additions and 6 deletions
|
|
@ -7,7 +7,7 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import csv as csv_std
|
import csv as csv_std
|
||||||
import tabulate
|
import tabulate
|
||||||
import sqlite3
|
from .utils import sqlite3
|
||||||
|
|
||||||
|
|
||||||
def output_options(fn):
|
def output_options(fn):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import sqlite3
|
from .utils import sqlite3
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
|
||||||
4
sqlite_utils/utils.py
Normal file
4
sqlite_utils/utils.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
try:
|
||||||
|
import pysqlite3 as sqlite3
|
||||||
|
except ImportError:
|
||||||
|
import sqlite3
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from sqlite_utils import Database
|
from sqlite_utils import Database
|
||||||
import sqlite3
|
from sqlite_utils.utils import sqlite3
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from click.testing import CliRunner
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import sqlite3
|
from sqlite_utils.utils import sqlite3
|
||||||
|
|
||||||
from .utils import collapse_whitespace
|
from .utils import collapse_whitespace
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ def test_create_index_if_not_exists(fresh_db):
|
||||||
assert [] == dogs.indexes
|
assert [] == dogs.indexes
|
||||||
dogs.create_index(["name"])
|
dogs.create_index(["name"])
|
||||||
assert 1 == len(dogs.indexes)
|
assert 1 == len(dogs.indexes)
|
||||||
with pytest.raises(sqlite3.OperationalError):
|
with pytest.raises(Exception, match="index idx_dogs_name already exists"):
|
||||||
dogs.create_index(["name"])
|
dogs.create_index(["name"])
|
||||||
dogs.create_index(["name"], if_not_exists=True)
|
dogs.create_index(["name"], if_not_exists=True)
|
||||||
|
|
||||||
|
|
@ -593,7 +593,7 @@ def test_insert_thousands_ignores_extra_columns_after_first_100(fresh_db):
|
||||||
def test_insert_ignore(fresh_db):
|
def test_insert_ignore(fresh_db):
|
||||||
fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id")
|
fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id")
|
||||||
# Should raise an error if we try this again
|
# Should raise an error if we try this again
|
||||||
with pytest.raises(sqlite3.IntegrityError):
|
with pytest.raises(Exception, match="UNIQUE constraint failed"):
|
||||||
fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id")
|
fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id")
|
||||||
# Using ignore=True should cause our insert to be silently ignored
|
# Using ignore=True should cause our insert to be silently ignored
|
||||||
fresh_db["test"].insert({"id": 1, "bar": 3}, pk="id", ignore=True)
|
fresh_db["test"].insert({"id": 1, "bar": 3}, pk="id", ignore=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue