3939import sys
4040import threading
4141import datetime
42- # from warnings import warn
42+ from warnings import warn
4343from ctypes import memmove , memset , create_string_buffer , cast , byref , string_at , sizeof , \
4444 c_char_p , c_void_p , c_byte , c_ulong
4545from .types import Error , DatabaseError , InterfaceError , FirebirdWarning , BCD , \
@@ -104,9 +104,9 @@ def _check(self) -> None:
104104 if StateFlag .ERRORS in state :
105105 raise self .__report (DatabaseError , self .status .get_errors ())
106106 if StateFlag .WARNINGS in state : # pragma: no cover
107- raise self .__report (FirebirdWarning , self .status .get_warning ())
108- # warn(self.__report(FirebirdWarning, self.status.get_warning()).args[0] ,
109- #FirebirdWarning, 2)
107+ # raise self.__report(FirebirdWarning, self.status.get_warning())
108+ warn (self .__report (FirebirdWarning , self .status .get_warning ()),
109+ stacklevel = 2 )
110110 @property
111111 def status (self ) -> iStatus :
112112 "iStatus for interface"
@@ -868,7 +868,7 @@ class iAttachment_v3(iReferenceCounted):
868868 VERSION = 3
869869 def __init__ (self , intf ):
870870 super ().__init__ (intf )
871- self .charset : str = 'ascii'
871+ self .encoding : str = 'ascii'
872872 def get_info (self , items : bytes , buffer : bytes ) -> None :
873873 "Replaces `isc_database_info()`"
874874 self .vtable .getInfo (self , self .status , len (items ), items , len (buffer ), buffer )
@@ -930,7 +930,7 @@ def prepare(self, transaction: iTransaction, stmt: str, dialect: int,
930930 """Replaces `isc_dsql_prepare()`. Additional parameter flags makes it
931931possible to control what information will be preloaded from engine at once
932932(i.e. in single network packet for remote operation)."""
933- b_stmt : bytes = stmt .encode (self .charset )
933+ b_stmt : bytes = stmt .encode (self .encoding )
934934 result = self .vtable .prepare (self , self .status , transaction , len (b_stmt ), b_stmt ,
935935 dialect , flags )
936936 self ._check ()
@@ -941,7 +941,7 @@ def execute(self, transaction: iTransaction, stmt: str, dialect: int,
941941 """Executes any SQL statement except returning multiple rows of data.
942942Partial analogue of `isc_dsql_execute2()` - in and out XSLQDAs replaced with
943943input and output messages with appropriate buffers."""
944- b_stmt : bytes = stmt .encode (self .charset )
944+ b_stmt : bytes = stmt .encode (self .encoding )
945945 result = self .vtable .execute (self , self .status , transaction , len (b_stmt ), b_stmt ,
946946 dialect , in_metadata , in_buffer , out_metadata , out_buffer )
947947 self ._check ()
@@ -955,10 +955,10 @@ def open_cursor(self, transaction: iTransaction, stmt: str, dialect: int,
955955may be used. Parameter cursor_name specifies name of opened cursor (analogue of
956956`isc_dsql_set_cursor_name()`). Parameter cursor_flags is needed to open
957957bidirectional cursor setting it's value to Istatement::CURSOR_TYPE_SCROLLABLE."""
958- b_stmt : bytes = stmt .encode (self .charset )
958+ b_stmt : bytes = stmt .encode (self .encoding )
959959 result = self .vtable .openCursor (self , self .status , transaction , len (b_stmt ), b_stmt ,
960960 dialect , in_metadata , in_buffer , out_metadata ,
961- cursor_name .encode (self .charset ), cursor_flags )
961+ cursor_name .encode (self .encoding ), cursor_flags )
962962 self ._check ()
963963 return iResultSet (result )
964964 def que_events (self , callback : iEventCallbackImpl , events : bytes ) -> iEvents :
@@ -1011,7 +1011,7 @@ def set_statement_timeout(self, timeout: int) -> None:
10111011 def create_batch (self , transaction : iTransaction , stmt : str , dialect : int ,
10121012 in_metadata : iMessageMetadata , params : bytes ) -> iBatch :
10131013 "TODO"
1014- b_stmt : bytes = stmt .encode (self .charset )
1014+ b_stmt : bytes = stmt .encode (self .encoding )
10151015 result = self .vtable .createBatch (self , self .status , transaction , len (b_stmt ), b_stmt ,
10161016 dialect , in_metadata , len (params ), params )
10171017 self ._check ()
@@ -1146,7 +1146,7 @@ def insert_bytes(self, tag: int, value: bytes) -> None:
11461146 "Inserts a clumplet with value containing passed bytes."
11471147 self .vtable .insertBytes (self , self .status , tag , value , len (value ))
11481148 self ._check ()
1149- def insert_string (self , tag : int , value : str , encoding = 'ascii' ) -> None :
1149+ def insert_string (self , tag : int , value : str , * , encoding = 'ascii' ) -> None :
11501150 "Inserts a clumplet with value containing passed string."
11511151 self .vtable .insertString (self , self .status , tag , value .encode (encoding ))
11521152 self ._check ()
@@ -1197,11 +1197,11 @@ def get_bigint(self) -> int:
11971197 result = self .vtable .getBigInt (self , self .status )
11981198 self ._check ()
11991199 return result
1200- def get_string (self ) -> str :
1200+ def get_string (self , * , encoding = 'ascii' ) -> str :
12011201 "Returns value of current clumplet as string."
12021202 result = self .vtable .getString (self , self .status )
12031203 self ._check ()
1204- return string_at (result ).decode ()
1204+ return string_at (result ).decode (encoding )
12051205 def get_bytes (self ) -> bytes :
12061206 "Returns value of current clumplet as bytes."
12071207 buffer = self .vtable .getBytes (self , self .status )
0 commit comments