3434from . import __name__ as MODULE_NAME
3535from . import errors
3636from . import connection as connection_module
37- from .defaults import defaults
3837from .fetch_info import FetchInfo
3938from .var import Var
4039from .base_impl import DbType , DB_TYPE_OBJECT
4140from .dbobject import DbObjectType
4241
4342
4443class BaseCursor :
44+ _impl = None
45+
4546 def __init__ (
4647 self ,
4748 connection : "connection_module.Connection" ,
4849 scrollable : bool = False ,
4950 ) -> None :
50- self ._impl = None
5151 self .connection = connection
52- self .statement = None
53- self ._set_input_sizes = False
54- self ._impl = connection ._impl .create_cursor_impl ()
55- self ._impl .scrollable = scrollable
56- self ._impl .arraysize = defaults .arraysize
57- self ._impl .prefetchrows = defaults .prefetchrows
58- self ._fetch_infos = None
52+ self ._impl = connection ._impl .create_cursor_impl (scrollable )
5953
6054 def __del__ (self ):
6155 if self ._impl is not None :
@@ -124,58 +118,16 @@ def _prepare(
124118 """
125119 Internal method used for preparing a statement for execution.
126120 """
127- self ._impl .fetch_vars = None
128- if not self ._set_input_sizes :
129- self ._impl .bind_vars = None
130- self ._impl .bind_vars_by_name = None
131- self ._impl .bind_style = None
132121 self ._impl .prepare (statement , tag , cache_statement )
133- self .statement = statement
134- self ._impl .rowfactory = None
135- self ._fetch_infos = None
136122
137123 def _prepare_for_execute (self , statement , parameters , keyword_parameters ):
138124 """
139125 Internal method for preparing a statement for execution.
140126 """
141-
142- # verify parameters
143- if statement is None and self .statement is None :
144- errors ._raise_err (errors .ERR_NO_STATEMENT )
145- if keyword_parameters :
146- if parameters :
147- errors ._raise_err (errors .ERR_ARGS_AND_KEYWORD_ARGS )
148- parameters = keyword_parameters
149- elif parameters is not None and not isinstance (
150- parameters , (list , tuple , dict )
151- ):
152- errors ._raise_err (errors .ERR_WRONG_EXECUTE_PARAMETERS_TYPE )
153127 self ._verify_open ()
154- impl = self ._impl
155- bind_vars = impl .bind_vars
156- bind_style = impl .bind_style
157- prepare_needed = statement and statement != self .statement
158- if (
159- not (prepare_needed and not self ._set_input_sizes )
160- and bind_vars is not None
161- and parameters is not None
162- ):
163- if (
164- bind_style is dict
165- and not isinstance (parameters , dict )
166- or bind_style is not dict
167- and isinstance (parameters , dict )
168- ):
169- errors ._raise_err (errors .ERR_MIXED_POSITIONAL_AND_NAMED_BINDS )
170-
171- # prepare statement, if necessary
172- if prepare_needed :
173- self ._prepare (statement )
174-
175- # perform bind and execute
176- self ._set_input_sizes = False
177- if parameters is not None :
178- impl .bind_one (self , parameters )
128+ self ._impl ._prepare_for_execute (
129+ self , statement , parameters , keyword_parameters
130+ )
179131
180132 def _verify_fetch (self ) -> None :
181133 """
@@ -265,7 +217,7 @@ def bindnames(self) -> list:
265217 that a statement must have been prepared first.
266218 """
267219 self ._verify_open ()
268- if self .statement is None :
220+ if self ._impl . statement is None :
269221 errors ._raise_err (errors .ERR_NO_STATEMENT_PREPARED )
270222 return self ._impl .get_bind_names ()
271223
@@ -300,11 +252,10 @@ def description(self) -> tuple:
300252 cursor has not had an operation invoked via the execute() method yet.
301253 """
302254 self ._verify_open ()
303- if self ._fetch_infos is None and self . _impl .is_query (self ):
304- self . _fetch_infos = [
255+ if self ._impl .is_query (self ):
256+ return [
305257 FetchInfo ._from_impl (i ) for i in self ._impl .fetch_info_impls
306258 ]
307- return self ._fetch_infos
308259
309260 @property
310261 def fetchvars (self ) -> list :
@@ -314,7 +265,7 @@ def fetchvars(self) -> list:
314265 attribute. In particular, elements should not be removed or replaced.
315266 """
316267 self ._verify_open ()
317- return self ._impl .fetch_vars
268+ return self ._impl .get_fetch_vars ()
318269
319270 def getarraydmlrowcounts (self ) -> list :
320271 """
@@ -491,9 +442,7 @@ def setinputsizes(self, *args: Any, **kwargs: Any) -> Union[list, dict]:
491442 errors ._raise_err (errors .ERR_ARGS_AND_KEYWORD_ARGS )
492443 elif args or kwargs :
493444 self ._verify_open ()
494- self ._impl .setinputsizes (self .connection , args , kwargs )
495- self ._set_input_sizes = True
496- return self ._impl .get_bind_vars ()
445+ return self ._impl .setinputsizes (self .connection , args , kwargs )
497446 return []
498447
499448 def setoutputsize (self , size : int , column : int = 0 ) -> None :
@@ -503,6 +452,14 @@ def setoutputsize(self, size: int, column: int = 0) -> None:
503452 """
504453 pass
505454
455+ @property
456+ def statement (self ) -> Union [str , None ]:
457+ """
458+ Returns the statement associated with the cursor, if one is present.
459+ """
460+ if self ._impl is not None :
461+ return self ._impl .statement
462+
506463 def var (
507464 self ,
508465 typ : Union [DbType , DbObjectType , type ],
@@ -741,7 +698,6 @@ def execute(
741698 """
742699 self ._prepare_for_execute (statement , parameters , keyword_parameters )
743700 impl = self ._impl
744- impl .warning = None
745701 impl .execute (self )
746702 if impl .fetch_vars is not None :
747703 return self
@@ -789,18 +745,18 @@ def executemany(
789745 bound as numbers or dates will raise a TypeError exception.
790746 """
791747 # verify parameters
792- if statement is None and self .statement is None :
748+ if statement is None and self ._impl . statement is None :
793749 errors ._raise_err (errors .ERR_NO_STATEMENT )
794750 if not isinstance (parameters , (list , int )):
795751 errors ._raise_err (errors .ERR_WRONG_EXECUTEMANY_PARAMETERS_TYPE )
796752
797753 # prepare statement, if necessary
798754 self ._verify_open ()
799- if statement and statement != self .statement :
755+ if statement and statement != self ._impl . statement :
800756 self ._prepare (statement )
801757
802758 # perform bind and execute
803- self ._set_input_sizes = False
759+ self ._impl . set_input_sizes = False
804760 if isinstance (parameters , int ):
805761 num_execs = parameters
806762 else :
@@ -1010,7 +966,6 @@ async def execute(
1010966 TypeError exception.
1011967 """
1012968 self ._prepare_for_execute (statement , parameters , keyword_parameters )
1013- self ._impl .warning = None
1014969 await self ._impl .execute (self )
1015970
1016971 async def executemany (
@@ -1056,18 +1011,18 @@ async def executemany(
10561011 bound as numbers or dates will raise a TypeError exception.
10571012 """
10581013 # verify parameters
1059- if statement is None and self .statement is None :
1014+ if statement is None and self ._impl . statement is None :
10601015 errors ._raise_err (errors .ERR_NO_STATEMENT )
10611016 if not isinstance (parameters , (list , int )):
10621017 errors ._raise_err (errors .ERR_WRONG_EXECUTEMANY_PARAMETERS_TYPE )
10631018
10641019 # prepare statement, if necessary
10651020 self ._verify_open ()
1066- if statement and statement != self .statement :
1021+ if statement and statement != self ._impl . statement :
10671022 self ._prepare (statement )
10681023
10691024 # perform bind and execute
1070- self ._set_input_sizes = False
1025+ self ._impl . set_input_sizes = False
10711026 if isinstance (parameters , int ):
10721027 num_execs = parameters
10731028 else :
0 commit comments