11# This file is from sqlite-utils and copyright and license is the same as that project
22__all__ = ['Database' , 'Queryable' , 'Table' , 'View' ]
33
4- from .utils import ( chunks , hash_record , sqlite3 , OperationalError , suggest_column_types , types_for_column_types , column_affinity , find_spatialite ,)
4+ from .utils import ( chunks , hash_record , OperationalError , suggest_column_types , types_for_column_types , column_affinity , find_spatialite ,)
55import binascii
66from collections import namedtuple
77from collections .abc import Mapping
88import contextlib , datetime , decimal , inspect , itertools , json , os , pathlib , re , secrets , textwrap
99from typing import ( cast , Any , Callable , Dict , Generator , Iterable , Union , Optional , List , Tuple ,Iterator )
1010from functools import cache
1111import uuid
12+ import apsw
1213import apsw .ext
1314import apsw .bestpractice
1415
@@ -219,7 +220,7 @@ class Database:
219220 dB = Database(memory=True)
220221
221222 :param filename_or_conn: String path to a file, or a ``pathlib.Path`` object, or a
222- ``sqlite3 `` connection
223+ ``apsw `` connection
223224 :param memory: set to ``True`` to create an in-memory database
224225 :param memory_name: creates a named in-memory database that can be shared across multiple connections
225226 :param recreate: set to ``True`` to delete and recreate a file database (**dangerous**)
@@ -237,7 +238,7 @@ class Database:
237238
238239 def __init__ (
239240 self ,
240- filename_or_conn : Optional [Union [str , pathlib .Path , sqlite3 .Connection ]] = None ,
241+ filename_or_conn : Optional [Union [str , pathlib .Path , apsw .Connection ]] = None ,
241242 memory : bool = False ,
242243 memory_name : Optional [str ] = None ,
243244 recreate : bool = False ,
@@ -253,21 +254,21 @@ def __init__(
253254 uri = "file:{}?mode=memory&cache=shared" .format (memory_name )
254255 # The flags being set allow apswutils to maintain the same behavior here
255256 # as sqlite-minutils
256- self .conn = sqlite3 .Connection (
257+ self .conn = apsw .Connection (
257258 uri , flags = apsw .SQLITE_OPEN_URI | apsw .SQLITE_OPEN_READWRITE
258259 )
259260 elif memory or filename_or_conn == ":memory:" :
260- self .conn = sqlite3 .Connection (":memory:" )
261+ self .conn = apsw .Connection (":memory:" )
261262 elif isinstance (filename_or_conn , (str , pathlib .Path )):
262263 if recreate and os .path .exists (filename_or_conn ):
263264 try :
264265 os .remove (filename_or_conn )
265266 except OSError :
266267 # Avoid mypy and __repr__ errors, see:
267268 # https://github.com/simonw/sqlite-utils/issues/503
268- self .conn = sqlite3 .Connection (":memory:" )
269+ self .conn = apsw .Connection (":memory:" )
269270 raise
270- self .conn = sqlite3 .Connection (str (filename_or_conn ))
271+ self .conn = apsw .Connection (str (filename_or_conn ))
271272 else :
272273 assert not recreate , "recreate cannot be used with connections, only paths"
273274 self .conn = filename_or_conn
@@ -368,7 +369,7 @@ def register(fn):
368369 fn_name , fn , arity , ** dict (kwargs , deterministic = True )
369370 )
370371 registered = True
371- except sqlite3 .Error : # Remember, sqlite3 here is actually apsw
372+ except apsw .Error :
372373 # TODO Find the precise error, sqlite-minutils used sqlite3.NotSupportedError
373374 # but as this isn't defined in APSW we fall back to apsw.Error
374375 pass
@@ -422,9 +423,9 @@ def query(
422423
423424 def execute (
424425 self , sql : str , parameters : Optional [Union [Iterable , dict ]] = None
425- ) -> sqlite3 .Cursor :
426+ ) -> apsw .Cursor :
426427 """
427- Execute SQL query and return a ``sqlite3 .Cursor``.
428+ Execute SQL query and return a ``apsw .Cursor``.
428429
429430 :param sql: SQL query to execute
430431 :param parameters: Parameters to use in that query - an iterable for ``where id = ?``
@@ -435,9 +436,9 @@ def execute(
435436 if parameters : return self .conn .execute (sql , parameters )
436437 else : return self .conn .execute (sql )
437438
438- def executescript (self , sql : str ) -> sqlite3 .Cursor :
439+ def executescript (self , sql : str ) -> apsw .Cursor :
439440 """
440- Execute multiple SQL statements separated by ; and return the ``sqlite3 .Cursor``.
441+ Execute multiple SQL statements separated by ; and return the ``apsw .Cursor``.
441442
442443 :param sql: SQL to execute
443444 """
@@ -1353,7 +1354,7 @@ def schema(self) -> str:
13531354
13541355class Table (Queryable ):
13551356 """
1356- A Table class instance represents a sqlite3 table that may or may not exist
1357+ A Table class instance represents a table that may or may not exist
13571358 in the database. The Table class instance may or may not represent some of
13581359 the rows of the database table. After some mutations (INSERT/UPDATE/UPSERT)
13591360 the changed records the Table class instance can be iterated over, returning
0 commit comments