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
55from collections import namedtuple
66from collections .abc import Mapping
77from typing import cast , Any , Callable , Dict , Generator , Iterable , Union , Optional , List , Tuple , Iterator
@@ -218,7 +218,7 @@ class Database:
218218 dB = Database(memory=True)
219219
220220 :param filename_or_conn: String path to a file, or a ``pathlib.Path`` object, or a
221- ``sqlite3 `` connection
221+ ``apsw `` connection
222222 :param memory: set to ``True`` to create an in-memory database
223223 :param memory_name: creates a named in-memory database that can be shared across multiple connections
224224 :param recreate: set to ``True`` to delete and recreate a file database (**dangerous**)
@@ -236,7 +236,7 @@ class Database:
236236
237237 def __init__ (
238238 self ,
239- filename_or_conn : Optional [Union [str , pathlib .Path , sqlite3 .Connection ]] = None ,
239+ filename_or_conn : Optional [Union [str , pathlib .Path , apsw .Connection ]] = None ,
240240 memory : bool = False ,
241241 memory_name : Optional [str ] = None ,
242242 recreate : bool = False ,
@@ -252,21 +252,21 @@ def __init__(
252252 uri = "file:{}?mode=memory&cache=shared" .format (memory_name )
253253 # The flags being set allow apswutils to maintain the same behavior here
254254 # as sqlite-minutils
255- self .conn = sqlite3 .Connection (
255+ self .conn = apsw .Connection (
256256 uri , flags = apsw .SQLITE_OPEN_URI | apsw .SQLITE_OPEN_READWRITE
257257 )
258258 elif memory or filename_or_conn == ":memory:" :
259- self .conn = sqlite3 .Connection (":memory:" )
259+ self .conn = apsw .Connection (":memory:" )
260260 elif isinstance (filename_or_conn , (str , pathlib .Path )):
261261 if recreate and os .path .exists (filename_or_conn ):
262262 try :
263263 os .remove (filename_or_conn )
264264 except OSError :
265265 # Avoid mypy and __repr__ errors, see:
266266 # https://github.com/simonw/sqlite-utils/issues/503
267- self .conn = sqlite3 .Connection (":memory:" )
267+ self .conn = apsw .Connection (":memory:" )
268268 raise
269- self .conn = sqlite3 .Connection (str (filename_or_conn ))
269+ self .conn = apsw .Connection (str (filename_or_conn ))
270270 else :
271271 assert not recreate , "recreate cannot be used with connections, only paths"
272272 self .conn = filename_or_conn
@@ -367,7 +367,7 @@ def register(fn):
367367 fn_name , fn , arity , ** dict (kwargs , deterministic = True )
368368 )
369369 registered = True
370- except sqlite3 .Error : # Remember, sqlite3 here is actually apsw
370+ except apsw .Error :
371371 # TODO Find the precise error, sqlite-minutils used sqlite3.NotSupportedError
372372 # but as this isn't defined in APSW we fall back to apsw.Error
373373 pass
@@ -421,9 +421,9 @@ def query(
421421
422422 def execute (
423423 self , sql : str , parameters : Optional [Union [Iterable , dict ]] = None
424- ) -> sqlite3 .Cursor :
424+ ) -> apsw .Cursor :
425425 """
426- Execute SQL query and return a ``sqlite3 .Cursor``.
426+ Execute SQL query and return a ``apsw .Cursor``.
427427
428428 :param sql: SQL query to execute
429429 :param parameters: Parameters to use in that query - an iterable for ``where id = ?``
@@ -434,9 +434,9 @@ def execute(
434434 if parameters : return self .conn .execute (sql , parameters )
435435 else : return self .conn .execute (sql )
436436
437- def executescript (self , sql : str ) -> sqlite3 .Cursor :
437+ def executescript (self , sql : str ) -> apsw .Cursor :
438438 """
439- Execute multiple SQL statements separated by ; and return the ``sqlite3 .Cursor``.
439+ Execute multiple SQL statements separated by ; and return the ``apsw .Cursor``.
440440
441441 :param sql: SQL to execute
442442 """
@@ -1364,7 +1364,7 @@ def schema(self) -> str:
13641364
13651365class Table (Queryable ):
13661366 """
1367- A Table class instance represents a sqlite3 table that may or may not exist
1367+ A Table class instance represents a table that may or may not exist
13681368 in the database. The Table class instance may or may not represent some of
13691369 the rows of the database table. After some mutations (INSERT/UPDATE/UPSERT)
13701370 the changed records the Table class instance can be iterated over, returning
0 commit comments