39
39
import sys
40
40
import threading
41
41
import datetime
42
- # from warnings import warn
42
+ from warnings import warn
43
43
from ctypes import memmove , memset , create_string_buffer , cast , byref , string_at , sizeof , \
44
44
c_char_p , c_void_p , c_byte , c_ulong
45
45
from .types import Error , DatabaseError , InterfaceError , FirebirdWarning , BCD , \
@@ -104,9 +104,9 @@ def _check(self) -> None:
104
104
if StateFlag .ERRORS in state :
105
105
raise self .__report (DatabaseError , self .status .get_errors ())
106
106
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 )
110
110
@property
111
111
def status (self ) -> iStatus :
112
112
"iStatus for interface"
@@ -868,7 +868,7 @@ class iAttachment_v3(iReferenceCounted):
868
868
VERSION = 3
869
869
def __init__ (self , intf ):
870
870
super ().__init__ (intf )
871
- self .charset : str = 'ascii'
871
+ self .encoding : str = 'ascii'
872
872
def get_info (self , items : bytes , buffer : bytes ) -> None :
873
873
"Replaces `isc_database_info()`"
874
874
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,
930
930
"""Replaces `isc_dsql_prepare()`. Additional parameter flags makes it
931
931
possible to control what information will be preloaded from engine at once
932
932
(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 )
934
934
result = self .vtable .prepare (self , self .status , transaction , len (b_stmt ), b_stmt ,
935
935
dialect , flags )
936
936
self ._check ()
@@ -941,7 +941,7 @@ def execute(self, transaction: iTransaction, stmt: str, dialect: int,
941
941
"""Executes any SQL statement except returning multiple rows of data.
942
942
Partial analogue of `isc_dsql_execute2()` - in and out XSLQDAs replaced with
943
943
input and output messages with appropriate buffers."""
944
- b_stmt : bytes = stmt .encode (self .charset )
944
+ b_stmt : bytes = stmt .encode (self .encoding )
945
945
result = self .vtable .execute (self , self .status , transaction , len (b_stmt ), b_stmt ,
946
946
dialect , in_metadata , in_buffer , out_metadata , out_buffer )
947
947
self ._check ()
@@ -955,10 +955,10 @@ def open_cursor(self, transaction: iTransaction, stmt: str, dialect: int,
955
955
may be used. Parameter cursor_name specifies name of opened cursor (analogue of
956
956
`isc_dsql_set_cursor_name()`). Parameter cursor_flags is needed to open
957
957
bidirectional 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 )
959
959
result = self .vtable .openCursor (self , self .status , transaction , len (b_stmt ), b_stmt ,
960
960
dialect , in_metadata , in_buffer , out_metadata ,
961
- cursor_name .encode (self .charset ), cursor_flags )
961
+ cursor_name .encode (self .encoding ), cursor_flags )
962
962
self ._check ()
963
963
return iResultSet (result )
964
964
def que_events (self , callback : iEventCallbackImpl , events : bytes ) -> iEvents :
@@ -1011,7 +1011,7 @@ def set_statement_timeout(self, timeout: int) -> None:
1011
1011
def create_batch (self , transaction : iTransaction , stmt : str , dialect : int ,
1012
1012
in_metadata : iMessageMetadata , params : bytes ) -> iBatch :
1013
1013
"TODO"
1014
- b_stmt : bytes = stmt .encode (self .charset )
1014
+ b_stmt : bytes = stmt .encode (self .encoding )
1015
1015
result = self .vtable .createBatch (self , self .status , transaction , len (b_stmt ), b_stmt ,
1016
1016
dialect , in_metadata , len (params ), params )
1017
1017
self ._check ()
@@ -1146,7 +1146,7 @@ def insert_bytes(self, tag: int, value: bytes) -> None:
1146
1146
"Inserts a clumplet with value containing passed bytes."
1147
1147
self .vtable .insertBytes (self , self .status , tag , value , len (value ))
1148
1148
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 :
1150
1150
"Inserts a clumplet with value containing passed string."
1151
1151
self .vtable .insertString (self , self .status , tag , value .encode (encoding ))
1152
1152
self ._check ()
@@ -1197,11 +1197,11 @@ def get_bigint(self) -> int:
1197
1197
result = self .vtable .getBigInt (self , self .status )
1198
1198
self ._check ()
1199
1199
return result
1200
- def get_string (self ) -> str :
1200
+ def get_string (self , * , encoding = 'ascii' ) -> str :
1201
1201
"Returns value of current clumplet as string."
1202
1202
result = self .vtable .getString (self , self .status )
1203
1203
self ._check ()
1204
- return string_at (result ).decode ()
1204
+ return string_at (result ).decode (encoding )
1205
1205
def get_bytes (self ) -> bytes :
1206
1206
"Returns value of current clumplet as bytes."
1207
1207
buffer = self .vtable .getBytes (self , self .status )
0 commit comments