34
34
# ______________________________________
35
35
# pylint: disable=C0302, W0212, R0902, R0912,R0913, R0914, R0915, R0904
36
36
37
- """firebird-driver - Main driver code (connection, transaction, cursor etc.)
37
+ """firebird-driver - Main driver code
38
+
39
+ This module implements the core components of the firebird-driver, including the DB-API 2.0
40
+ compliant Connection, Cursor, and Transaction objects, as well as helper classes for managing
41
+ events, BLOBs, parameter buffers, and accessing database/server information.
38
42
"""
39
43
40
44
from __future__ import annotations
@@ -296,7 +300,7 @@ def temp_database(*args, **kwargs) -> Connection:
296
300
297
301
# Managers for Parameter buffers
298
302
class TPB : # pylint: disable=R0902
299
- """Transaction Parameter Buffer .
303
+ """Helper class to build and parse Transaction Parameter Buffers (TPB) used when starting transactions .
300
304
"""
301
305
def __init__ (self , * , access_mode : TraAccessMode = TraAccessMode .WRITE ,
302
306
isolation : Isolation = Isolation .SNAPSHOT ,
@@ -412,7 +416,7 @@ def reserve_table(self, name: str, share_mode: TableShareMode, access_mode: Tabl
412
416
self ._table_reservation .append ((name , share_mode , access_mode ))
413
417
414
418
class DPB :
415
- """Database Parameter Buffer .
419
+ """Helper class to build and parse Database Parameter Buffers (DPB) used when connecting databases .
416
420
"""
417
421
def __init__ (self , * , user : str = None , password : str = None , role : str = None ,
418
422
trusted_auth : bool = False , sql_dialect : int = 3 , timeout : int = None ,
@@ -684,7 +688,8 @@ def get_buffer(self, *, for_create: bool = False) -> bytes:
684
688
return result
685
689
686
690
class SPB_ATTACH :
687
- """Service Parameter Buffer.
691
+ """Helper class to build and parse Service Parameter Buffers (SPB) used when connecting
692
+ to service manager.
688
693
"""
689
694
def __init__ (self , * , user : str = None , password : str = None , trusted_auth : bool = False ,
690
695
config : str = None , auth_plugin_list : str = None , expected_db : str = None ,
@@ -1106,6 +1111,9 @@ def get_engine_version(self, con: Connection | Server) -> float:
1106
1111
class DatabaseInfoProvider3 (InfoProvider ):
1107
1112
"""Provides access to information about attached database [Firebird 3+].
1108
1113
1114
+ Information can be accessed either via specific properties (preferred) or the lower-level
1115
+ `get_info()` method.
1116
+
1109
1117
Important:
1110
1118
Do NOT create instances of this class directly! Use `Connection.info` property to
1111
1119
access the instance already bound to attached database.
@@ -1316,6 +1324,13 @@ def get_info(self, info_code: DbInfoCode, page_number: int=None) -> Any:
1316
1324
1317
1325
Returns:
1318
1326
The data type of returned value depends on information required.
1327
+
1328
+ Note:
1329
+ Info codes that return stable values are cached on first call, so subsequent calls do not
1330
+ access the server. These codes are: `CREATION_DATE`, `DB_CLASS`, `DB_PROVIDER`,
1331
+ `DB_SQL_DIALECT`, `ODS_MINOR_VERSION`, `ODS_VERSION`, `PAGE_SIZE`, `VERSION`,
1332
+ `FIREBIRD_VERSION`, `IMPLEMENTATION_OLD`, `IMPLEMENTATION`, `DB_ID`, `BASE_LEVEL`,
1333
+ and `ATTACHMENT_ID`.
1319
1334
"""
1320
1335
if info_code in self ._cache :
1321
1336
return self ._cache [info_code ]
@@ -1589,6 +1604,9 @@ def engine_version(self) -> float:
1589
1604
class DatabaseInfoProvider (DatabaseInfoProvider3 ):
1590
1605
"""Provides access to information about attached database [Firebird 4+].
1591
1606
1607
+ Information can be accessed either via specific properties (preferred) or the lower-level
1608
+ `get_info()` method.
1609
+
1592
1610
Important:
1593
1611
Do NOT create instances of this class directly! Use `Connection.info` property to
1594
1612
access the instance already bound to attached database.
@@ -1754,6 +1772,7 @@ def _prepare(self, sql: str, tra: TransactionManager) -> Statement:
1754
1772
tra .commit ()
1755
1773
return result
1756
1774
def _determine_field_precision (self , meta : ItemMetadata ) -> int :
1775
+ # This internal method involve database queries using _tra_qry.
1757
1776
if (not meta .relation ) or (not meta .field ):
1758
1777
# Either or both field name and relation name are not provided,
1759
1778
# so we cannot determine field precision. It's normal situation
@@ -1796,6 +1815,7 @@ def _determine_field_precision(self, meta: ItemMetadata) -> int:
1796
1815
# We ran out of options
1797
1816
return 0
1798
1817
def _get_array_sqlsubtype (self , relation : bytes , column : bytes ) -> int | None :
1818
+ # This internal method involve database query using _tra_qry.
1799
1819
subtype = self .__sqlsubtype_cache .get ((relation , column ))
1800
1820
if subtype is not None :
1801
1821
return subtype
@@ -1820,6 +1840,9 @@ def drop_database(self) -> None:
1820
1840
Closes all event collectors, transaction managers (with rollback) and statements
1821
1841
associated with this connection before attempt to drop the database.
1822
1842
1843
+ Important:
1844
+ The connection object becomes unusable after this call.
1845
+
1823
1846
Hooks:
1824
1847
Event `.ConnectionHook.DROPPED`: Executed after database is sucessfuly dropped.
1825
1848
Hook must have signature::
@@ -2021,7 +2044,7 @@ def transactions(self) -> list[TransactionManager]:
2021
2044
return result
2022
2045
@property
2023
2046
def schema (self ) -> 'firebird.lib.schema.Schema' :
2024
- """Access to database schema. Requires firebird.lib package.
2047
+ """Access to database schema. Requires ` firebird.lib` package.
2025
2048
"""
2026
2049
if self .__schema is None :
2027
2050
import firebird .lib .schema # pylint: disable=C0415
@@ -2031,7 +2054,7 @@ def schema(self) -> 'firebird.lib.schema.Schema':
2031
2054
return self .__schema
2032
2055
@property
2033
2056
def monitor (self ) -> 'firebird.lib.monitor.Monitor' :
2034
- """Access to database monitoring tables. Requires firebird.lib package.
2057
+ """Access to database monitoring tables. Requires ` firebird.lib` package.
2035
2058
"""
2036
2059
if self .__monitor is None :
2037
2060
import firebird .lib .monitor # pylint: disable=C0415
@@ -2283,6 +2306,9 @@ def create_database(database: str | Path, *, user: str=None, password: str=None,
2283
2306
class TransactionInfoProvider3 (InfoProvider ):
2284
2307
"""Provides access to information about transaction [Firebird 3+].
2285
2308
2309
+ Information can be accessed either via specific properties (preferred) or the lower-level
2310
+ `get_info()` method.
2311
+
2286
2312
Important:
2287
2313
Do NOT create instances of this class directly! Use `TransactionManager.info`
2288
2314
property to access the instance already bound to transaction context.
@@ -2392,6 +2418,9 @@ def snapshot_number(self) -> int:
2392
2418
class TransactionInfoProvider (TransactionInfoProvider3 ):
2393
2419
"""Provides access to information about transaction [Firebird 4+].
2394
2420
2421
+ Information can be accessed either via specific properties (preferred) or the lower-level
2422
+ `get_info()` method.
2423
+
2395
2424
Important:
2396
2425
Do NOT create instances of this class directly! Use `TransactionManager.info`
2397
2426
property to access the instance already bound to transaction context.
@@ -2467,6 +2496,8 @@ def _get_handle(self) -> a.FB_API_HANDLE:
2467
2496
def close (self ) -> None :
2468
2497
"""Close the transaction manager and release all associated resources.
2469
2498
2499
+ Implicitly ends the current active transaction according to default_action (if active).
2500
+
2470
2501
Important:
2471
2502
Closed instance SHALL NOT be used anymore.
2472
2503
"""
@@ -3015,7 +3046,8 @@ def read(self, size: int=-1) -> str | bytes:
3015
3046
Like `file.read()`.
3016
3047
3017
3048
Note:
3018
- Performs automatic conversion to `str` for TEXT BLOBs.
3049
+ Performs automatic conversion to `str` for TEXT BLOBs (subtype 1) based on the
3050
+ connection's encoding.
3019
3051
"""
3020
3052
assert self ._blob is not None
3021
3053
if size >= 0 :
@@ -3195,6 +3227,7 @@ def __init__(self, connection: Connection, transaction: TransactionManager): # p
3195
3227
#: Names of columns that should be returned as `BlobReader`.
3196
3228
self .stream_blobs : list [str ] = []
3197
3229
#: BLOBs greater than threshold are returned as `BlobReader` instead in materialized form.
3230
+ #: Defaults to the value from `driver_config`.
3198
3231
self .stream_blob_threshold = driver_config .stream_blob_threshold .value
3199
3232
def __enter__ (self ) -> Cursor :
3200
3233
return self
@@ -3930,7 +3963,7 @@ def executemany(self, operation: str | Statement,
3930
3963
Note:
3931
3964
This function simply calls `.execute` in a loop, feeding it with
3932
3965
parameters from `seq_of_parameters`. Because `.execute` reuses the statement,
3933
- calling `executemany` is equally efective as direct use of prepared `Statement`
3966
+ calling `executemany` is equally effective as direct use of prepared `Statement`
3934
3967
and calling `execute` in a loop directly in application.
3935
3968
"""
3936
3969
for parameters in seq_of_parameters :
@@ -4075,7 +4108,7 @@ def to_dict(self, row: tuple, into: dict=None) -> dict:
4075
4108
4076
4109
Arguments:
4077
4110
row: Row data returned by fetch_* method.
4078
- into: Dictionary that shouold be updated with row data.
4111
+ into: Dictionary that should be updated with row data.
4079
4112
"""
4080
4113
assert len (self ._stmt ._names ) == len (row ), "Length of data must match number of fields"
4081
4114
if into is None :
@@ -4216,6 +4249,9 @@ def name(self) -> str:
4216
4249
class ServerInfoProvider (InfoProvider ):
4217
4250
"""Provides access to information about attached server.
4218
4251
4252
+ Information can be accessed either via specific properties (preferred) or the lower-level
4253
+ `get_info()` method.
4254
+
4219
4255
Important:
4220
4256
Do NOT create instances of this class directly! Use `Server.info` property to access
4221
4257
the instance already bound to connectected server.
@@ -5458,7 +5494,7 @@ def __init__(self, svc: iService, spb: bytes, host: str, encoding: str,
5458
5494
self .host : str = host
5459
5495
#: Service output mode (line or eof)
5460
5496
self .mode : SrvInfoCode = SrvInfoCode .TO_EOF
5461
- #: Response buffer used to comunicate with service
5497
+ #: Response buffer used to communicate with service
5462
5498
self .response : CBuffer = CBuffer (USHRT_MAX )
5463
5499
self ._eof : bool = False
5464
5500
self .__line_buffer : list [str ] = []
0 commit comments