5656from pathlib import Path
5757from queue import PriorityQueue
5858from ctypes import memset , memmove , create_string_buffer , byref , string_at , addressof , pointer
59- from firebird .base .types import Sentinel , UNLIMITED , ByteOrder
60- from firebird .base .logging import LoggingIdMixin , UNDEFINED
59+ from firebird .base .types import Sentinel , UNLIMITED , ByteOrder , UNDEFINED
6160from firebird .base .buffer import MemoryBuffer , BufferFactory , BytesBufferFactory , \
6261 CTypesBufferFactory , safe_ord
6362from . import fbapi as a
@@ -1612,7 +1611,7 @@ def statement_timeout(self) -> int:
16121611 def set_statement_timeout (self , value : int ) -> None :
16131612 self ._con ()._att .set_statement_timeout (value )
16141613
1615- class Connection ( LoggingIdMixin ) :
1614+ class Connection :
16161615 """Connection to the database.
16171616
16181617 Note:
@@ -2077,14 +2076,14 @@ def __make_connection(create: bool, dsn: str, utf8filename: bool, dpb: bytes,
20772076 hook (con )
20782077 return con
20792078
2080- def connect (database : str , * , user : str = None , password : str = None , role : str = None ,
2079+ def connect (database : str | Path , * , user : str = None , password : str = None , role : str = None ,
20812080 no_gc : bool = None , no_db_triggers : bool = None , dbkey_scope : DBKeyScope = None ,
20822081 crypt_callback : iCryptKeyCallbackImpl = None , charset : str = None ,
20832082 auth_plugin_list : str = None , session_time_zone : str = None ) -> Connection :
20842083 """Establishes a connection to the database.
20852084
20862085 Arguments:
2087- database: DSN or Database configuration name.
2086+ database: DSN or Database configuration name. Could be also a Path object.
20882087 user: User name.
20892088 password: User password.
20902089 role: User role.
@@ -2114,17 +2113,25 @@ def connect(database: str, *, user: str=None, password: str=None, role: str=None
21142113
21152114 Any value returned by hook is ignored.
21162115 """
2116+ if isinstance (database , Path ):
2117+ database = str (database )
21172118 db_config = driver_config .get_database (database )
21182119 if db_config is None :
21192120 db_config = driver_config .db_defaults
2120- else :
2121- database = db_config . database . value
2122- if db_config . server . value is None :
2121+ # we'll assume that 'database' is 'dsn'
2122+ dsn = database
2123+ database = None
21232124 srv_config = driver_config .server_defaults
2125+ srv_config .host .clear ()
21242126 else :
2125- srv_config = driver_config .get_server (db_config .server .value )
2126- if srv_config is None :
2127- raise ValueError (f"Configuration for server '{ db_config .server .value } ' not found" )
2127+ database = db_config .database .value
2128+ dsn = db_config .dsn .value
2129+ if db_config .server .value is None :
2130+ srv_config = driver_config .server_defaults
2131+ else :
2132+ srv_config = driver_config .get_server (db_config .server .value )
2133+ if srv_config is None :
2134+ raise ValueError (f"Configuration for server '{ db_config .server .value } ' not found" )
21282135 if user is None :
21292136 user = db_config .user .value
21302137 if user is None :
@@ -2143,7 +2150,7 @@ def connect(database: str, *, user: str=None, password: str=None, role: str=None
21432150 auth_plugin_list = db_config .auth_plugin_list .value
21442151 if session_time_zone is None :
21452152 session_time_zone = db_config .session_time_zone .value
2146- dsn = _connect_helper (db_config . dsn . value , srv_config .host .value , srv_config .port .value ,
2153+ dsn = _connect_helper (dsn , srv_config .host .value , srv_config .port .value ,
21472154 database , db_config .protocol .value )
21482155 dpb = DPB (user = user , password = password , role = role , trusted_auth = db_config .trusted_auth .value ,
21492156 sql_dialect = db_config .sql_dialect .value , timeout = db_config .timeout .value ,
@@ -2159,7 +2166,7 @@ def connect(database: str, *, user: str=None, password: str=None, role: str=None
21592166 return __make_connection (False , dsn , db_config .utf8filename .value , dpb .get_buffer (),
21602167 db_config .sql_dialect .value , charset , crypt_callback )
21612168
2162- def create_database (database : str , * , user : str = None , password : str = None , role : str = None ,
2169+ def create_database (database : str | Path , * , user : str = None , password : str = None , role : str = None ,
21632170 no_gc : bool = None , no_db_triggers : bool = None , dbkey_scope : DBKeyScope = None ,
21642171 crypt_callback : iCryptKeyCallbackImpl = None , charset : str = None ,
21652172 overwrite : bool = False , auth_plugin_list = None ,
@@ -2188,17 +2195,19 @@ def create_database(database: str, *, user: str=None, password: str=None, role:
21882195
21892196 Any value returned by hook is ignored.
21902197 """
2198+ if isinstance (database , Path ):
2199+ database = str (database )
21912200 db_config = driver_config .get_database (database )
21922201 if db_config is None :
21932202 db_config = driver_config .db_defaults
2194- db_config .database .value = database
2195- if db_config .server .value is None :
2196- srv_config = driver_config .server_defaults
2197- else :
2198- srv_config = driver_config .get_server (db_config .server .value )
2199- if srv_config is None :
2200- raise ValueError (f"Configuration for server '{ db_config .server .value } ' not found" )
2203+ # we'll assume that 'database' is 'dsn'
2204+ dsn = database
2205+ database = None
2206+ srv_config = driver_config .server_defaults
2207+ srv_config .host .clear ()
22012208 else :
2209+ database = db_config .database .value
2210+ dsn = db_config .dsn .value
22022211 if db_config .server .value is None :
22032212 srv_config = driver_config .server_defaults
22042213 else :
@@ -2223,8 +2232,8 @@ def create_database(database: str, *, user: str=None, password: str=None, role:
22232232 auth_plugin_list = db_config .auth_plugin_list .value
22242233 if session_time_zone is None :
22252234 session_time_zone = db_config .session_time_zone .value
2226- dsn = _connect_helper (db_config . dsn . value , srv_config .host .value , srv_config .port .value ,
2227- db_config . database . value , db_config .protocol .value )
2235+ dsn = _connect_helper (dsn , srv_config .host .value , srv_config .port .value ,
2236+ database , db_config .protocol .value )
22282237 dpb = DPB (user = user , password = password , role = role , trusted_auth = db_config .trusted_auth .value ,
22292238 sql_dialect = db_config .db_sql_dialect .value , timeout = db_config .timeout .value ,
22302239 charset = charset , cache_size = db_config .cache_size .value ,
@@ -2368,7 +2377,7 @@ def snapshot_number(self) -> int:
23682377 """
23692378 return self .get_info (TraInfoCode .SNAPSHOT_NUMBER )
23702379
2371- class TransactionManager ( LoggingIdMixin ) :
2380+ class TransactionManager :
23722381 """Transaction manager.
23732382
23742383 Note:
@@ -2757,7 +2766,7 @@ def __init__(self, charset: str, stmt: Statement):
27572766 StmtInfoCode .EXEC_PATH_BLR_TEXT : self .response .read_sized_string ,
27582767 })
27592768
2760- class Statement ( LoggingIdMixin ) :
2769+ class Statement :
27612770 """Prepared SQL statement.
27622771
27632772 Note:
@@ -2890,7 +2899,7 @@ def _timeout(self, value: int) -> None:
28902899 return self ._istmt .set_timeout (value )
28912900 raise NotSupportedError (f"Statement timeout not supported by engine version { self ._connection ()._engine_version ()} " )
28922901
2893- class BlobReader (io .IOBase , LoggingIdMixin ):
2902+ class BlobReader (io .IOBase ):
28942903 """Handler for large BLOB values returned by server.
28952904
28962905 The BlobReader is a “file-like” class, so it acts much like an open file instance.
@@ -3112,7 +3121,7 @@ def blob_type(self) -> BlobType:
31123121 result = self ._blob .get_info2 (BlobInfoCode .TYPE )
31133122 return BlobType (result )
31143123
3115- class Cursor ( LoggingIdMixin ) :
3124+ class Cursor :
31163125 """Represents a database cursor, which is used to execute SQL statement and
31173126 manage the context of a fetch operation.
31183127
@@ -5383,7 +5392,7 @@ def store():
53835392 store ()
53845393 return result
53855394
5386- class Server ( LoggingIdMixin ) :
5395+ class Server :
53875396 """Represents connection to Firebird Service Manager.
53885397
53895398 Note:
0 commit comments