2323 SQLiteCloudAccount ,
2424 SQLiteCloudConfig ,
2525 SQLiteCloudConnect ,
26- SQLiteCloudDataTypes ,
2726 SQLiteCloudException ,
2827)
2928from sqlitecloud .driver import Driver
@@ -145,7 +144,7 @@ def register_adapter(
145144
146145class Connection :
147146 """
148- Represents a DB-APi 2.0 connection to the SQLite Cloud database.
147+ Represents a DB-API 2.0 connection to the SQLite Cloud database.
149148
150149 Args:
151150 SQLiteCloud_connection (SQLiteCloudConnect): The SQLite Cloud connection object.
@@ -155,13 +154,15 @@ class Connection:
155154 SQLiteCloud_connection (SQLiteCloudConnect): The SQLite Cloud connection object.
156155 """
157156
158- row_factory : Optional [Callable [["Cursor" , Tuple ], object ]] = None
159- text_factory : Union [Type [Union [str , bytes ]], Callable [[bytes ], object ]] = str
160-
161157 def __init__ (self , sqlitecloud_connection : SQLiteCloudConnect ) -> None :
162158 self ._driver = Driver ()
163- self .row_factory = None
164159 self .sqlitecloud_connection = sqlitecloud_connection
160+
161+ self .row_factory : Optional [Callable [["Cursor" , Tuple ], object ]] = None
162+ self .text_factory : Union [
163+ Type [Union [str , bytes ]], Callable [[bytes ], object ]
164+ ] = str
165+
165166 self .detect_types = 0
166167
167168 @property
@@ -177,17 +178,15 @@ def sqlcloud_connection(self) -> SQLiteCloudConnect:
177178 def execute (
178179 self ,
179180 sql : str ,
180- parameters : Union [
181- Tuple [SQLiteCloudDataTypes ], Dict [Union [str , int ], SQLiteCloudDataTypes ]
182- ] = (),
181+ parameters : Union [Tuple [any ], Dict [Union [str , int ], any ]] = (),
183182 ) -> "Cursor" :
184183 """
185184 Shortcut for cursor.execute().
186185 See the docstring of Cursor.execute() for more information.
187186
188187 Args:
189188 sql (str): The SQL query to execute.
190- parameters (Union[Tuple[SQLiteCloudDataTypes ], Dict[Union[str, int], SQLiteCloudDataTypes ]]):
189+ parameters (Union[Tuple[any ], Dict[Union[str, int], any ]]):
191190 The parameters to be used in the query. It can be a tuple or a dictionary. (Default ())
192191 conn (SQLiteCloudConnect): The connection object to use for executing the query.
193192
@@ -200,19 +199,15 @@ def execute(
200199 def executemany (
201200 self ,
202201 sql : str ,
203- seq_of_parameters : Iterable [
204- Union [
205- Tuple [SQLiteCloudDataTypes ], Dict [Union [str , int ], SQLiteCloudDataTypes ]
206- ]
207- ],
202+ seq_of_parameters : Iterable [Union [Tuple [any ], Dict [Union [str , int ], any ]]],
208203 ) -> "Cursor" :
209204 """
210205 Shortcut for cursor.executemany().
211206 See the docstring of Cursor.executemany() for more information.
212207
213208 Args:
214209 sql (str): The SQL statement to execute.
215- seq_of_parameters (Iterable[Union[Tuple[SQLiteCloudDataTypes ], Dict[Union[str, int], SQLiteCloudDataTypes ]]]):
210+ seq_of_parameters (Iterable[Union[Tuple[any ], Dict[Union[str, int], any ]]]):
216211 The sequence of parameter sets to bind to the SQL statement.
217212
218213 Returns:
@@ -385,9 +380,7 @@ def close(self) -> None:
385380 def execute (
386381 self ,
387382 sql : str ,
388- parameters : Union [
389- Tuple [SQLiteCloudDataTypes ], Dict [Union [str , int ], SQLiteCloudDataTypes ]
390- ] = (),
383+ parameters : Union [Tuple [any ], Dict [Union [str , int ], any ]] = (),
391384 ) -> "Cursor" :
392385 """
393386 Prepare and execute a SQL statement (either a query or command) to the SQLite Cloud database.
@@ -405,7 +398,7 @@ def execute(
405398
406399 Args:
407400 sql (str): The SQL query to execute.
408- parameters (Union[Tuple[SQLiteCloudDataTypes ], Dict[Union[str, int], SQLiteCloudDataTypes ]]):
401+ parameters (Union[Tuple[any ], Dict[Union[str, int], any ]]):
409402 The parameters to be used in the query. It can be a tuple or a dictionary. (Default ())
410403 conn (SQLiteCloudConnect): The connection object to use for executing the query.
411404
@@ -428,11 +421,7 @@ def execute(
428421 def executemany (
429422 self ,
430423 sql : str ,
431- seq_of_parameters : Iterable [
432- Union [
433- Tuple [SQLiteCloudDataTypes ], Dict [Union [str , int ], SQLiteCloudDataTypes ]
434- ]
435- ],
424+ seq_of_parameters : Iterable [Union [Tuple [any ], Dict [Union [str , int ], any ]]],
436425 ) -> "Cursor" :
437426 """
438427 Executes a SQL statement multiple times, each with a different set of parameters.
@@ -441,7 +430,7 @@ def executemany(
441430
442431 Args:
443432 sql (str): The SQL statement to execute.
444- seq_of_parameters (Iterable[Union[Tuple[SQLiteCloudDataTypes ], Dict[Union[str, int], SQLiteCloudDataTypes ]]]):
433+ seq_of_parameters (Iterable[Union[Tuple[any ], Dict[Union[str, int], any ]]]):
445434 The sequence of parameter sets to bind to the SQL statement.
446435
447436 Returns:
@@ -564,10 +553,11 @@ def _get_value(self, row: int, col: int) -> Optional[Any]:
564553
565554 if self ._connection .text_factory is bytes :
566555 return value .encode ("utf-8" )
567- if self ._connection .text_factory is str :
568- return value
569- # callable
570- return self ._connection .text_factory (value .encode ("utf-8" ))
556+ if self ._connection .text_factory is not str and callable (
557+ self ._connection .text_factory
558+ ):
559+ return self ._connection .text_factory (value .encode ("utf-8" ))
560+ return value
571561
572562 return self ._resultset .get_value (row , col )
573563
0 commit comments