Use pysqlite3 if available

This commit is contained in:
Simon Willison 2019-07-22 15:39:35 -07:00
commit 152eb2afaf
6 changed files with 10 additions and 6 deletions

View file

@ -7,7 +7,7 @@ import json
import sys
import csv as csv_std
import tabulate
import sqlite3
from .utils import sqlite3
def output_options(fn):

View file

@ -1,4 +1,4 @@
import sqlite3
from .utils import sqlite3
from collections import namedtuple
import datetime
import hashlib

4
sqlite_utils/utils.py Normal file
View file

@ -0,0 +1,4 @@
try:
import pysqlite3 as sqlite3
except ImportError:
import sqlite3

View file

@ -1,5 +1,5 @@
from sqlite_utils import Database
import sqlite3
from sqlite_utils.utils import sqlite3
import pytest

View file

@ -4,7 +4,7 @@ from click.testing import CliRunner
import json
import os
import pytest
import sqlite3
from sqlite_utils.utils import sqlite3
from .utils import collapse_whitespace

View file

@ -549,7 +549,7 @@ def test_create_index_if_not_exists(fresh_db):
assert [] == dogs.indexes
dogs.create_index(["name"])
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"], 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):
fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id")
# 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")
# Using ignore=True should cause our insert to be silently ignored
fresh_db["test"].insert({"id": 1, "bar": 3}, pk="id", ignore=True)