Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit c23cfb6

Browse files
committed
little bug fix
1 parent ed7ef8c commit c23cfb6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fyCursor/core/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(
159159
self.null = NULL
160160
self.NULL = self.null
161161
self._query = None
162+
self._execution = None
162163

163164
super().__init__(__cursor)
164165
self._logger = logging.getLogger(
@@ -253,7 +254,7 @@ def execute( # type: ignore
253254
__sql: str,
254255
*__parameters: _Parameters
255256
) -> Self:
256-
self._query = __sql
257+
self._execution = __sql
257258
if __parameters:
258259
for param in __parameters: # type: ignore
259260
self._query.replace("?", param, 1) # type: ignore
@@ -269,10 +270,11 @@ def fetch(
269270
:param one - if `True` provided, the `cursor.fetchone()`
270271
function will be used
271272
"""
272-
if not self._query:
273+
if not self._query and not self._execution:
273274
raise ProgrammingError("Nothing to fetch")
274-
super().execute(self._query)
275+
super().execute(self._query or self._execution) # type: ignore
275276
super().connection.commit()
277+
self._execution = self._query = None
276278
return super().fetchone() if one else super().fetchall()
277279

278280
def one(self) -> Any:
@@ -288,8 +290,12 @@ def one(self) -> Any:
288290
return fetching
289291

290292
def commit(self) -> Self:
291-
if self._query:
293+
if self._execution:
294+
super().execute(self._execution)
295+
elif self._query:
292296
super().execute(self._query)
297+
self._execution = self._query = None
298+
293299
super().connection.commit()
294300
return self
295301

0 commit comments

Comments
 (0)