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

Commit 6e72330

Browse files
committed
fix duplication bug
1 parent 54766d3 commit 6e72330

File tree

8 files changed

+69
-17
lines changed

8 files changed

+69
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Pipfile*
88
test.py
99
*.db
1010
*.pyc
11+
__main__.py

fyCursor/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
TableInsert,
1111
NULL
1212
)
13-
from .sql_types import (
13+
from .constants.sql_types import (
1414
DATATYPES,
1515
INTEGER,
1616
TEXT,
@@ -19,6 +19,7 @@
1919
BOOL,
2020
TIMESTAMP
2121
)
22+
from .constants.sql_methods import METHODS
2223

2324

2425
def connect(
@@ -83,6 +84,7 @@ class Info():
8384
"VARCHAR",
8485
"BOOL",
8586
"TIMESTAMP",
87+
"METHODS",
8688
"__title__",
8789
"__version__",
8890
"__author__",

fyCursor/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
cursor.update("myTable").add(money=5).commit()
5353
cursor.execute("INSERT INTO myTable(money) VALUES (2)").commit()
5454
55-
b = AnotherTable << {
55+
b = AnotherTable >> {
5656
"money": 2
5757
}
5858
input()
59-
a = AnotherTable >> {
59+
a = AnotherTable << {
6060
"money": 2
6161
}
6262
'''

fyCursor/constants/sql_methods.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class METHODS:
2+
UPDATE: str = "UPDATE"
3+
SET: str = "SET"
4+
WHERE: str = "WHERE"
File renamed without changes.

fyCursor/core/core.py

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def generate_name(name: str):
8282

8383
self.cursor.execute(
8484
f"INSERT INTO {self.name}({names[:-1]}) VALUES ({values[:-1]})"
85-
)
86-
self.cursor.commit()
85+
).commit()
8786

8887
return self
8988

@@ -146,14 +145,47 @@ def __init__(
146145
"""
147146
self.null = NULL
148147
self.NULL = self.null
149-
self._query = None
150-
self._execution = None
148+
# setting null constant so user will be able to easily access it
149+
150+
self._empty_query() # set query to None
151151

152152
super().__init__(__cursor)
153+
153154
self._logger = logging.getLogger(
154155
"fyCursor"
155156
) if logger is None else logger
156157

158+
def set_logger(self, logger: Any) -> Self:
159+
"""
160+
Sets a custom logger. Logger class should have following methods: \
161+
info, warning, exception
162+
163+
:param logger: - logger
164+
:returns: - self
165+
"""
166+
self._logger = logger
167+
168+
return self
169+
170+
def _empty_query(self) -> None:
171+
self._execution = self._query = None
172+
173+
def check_method(self, *methods: str) -> bool:
174+
"""
175+
Checks if provided methods are qurrently in query
176+
177+
:*methods: - str name of methods
178+
:returns: - bool
179+
"""
180+
if len(methods) > 1:
181+
return False not in [self.check_method(method)
182+
for method in methods]
183+
elif not methods:
184+
return True
185+
elif self._query is None:
186+
return False
187+
return methods[1] in self._query
188+
157189
def update(self, table: str) -> Self:
158190
"""
159191
Use this as SQL `UPDATE {table}` method
@@ -162,6 +194,7 @@ def update(self, table: str) -> Self:
162194
:returns: - self
163195
"""
164196
self._query = f"UPDATE {table}"
197+
165198
return self
166199

167200
def add(self, **kwargs: Any) -> Self:
@@ -237,16 +270,24 @@ def where(self, **kwargs: Any) -> Self:
237270
)
238271
return self
239272

240-
def execute( # type: ignore
273+
def execute(
241274
self,
242275
__sql: str,
243276
*__parameters: Any
244277
) -> Self:
245278
if __parameters:
246-
for param in __parameters: # type: ignore
247-
__sql = __sql.replace("?", str(param), 1) # type: ignore
279+
for param in __parameters:
280+
__sql = __sql.replace("?", str(param), 1)
248281
self._execution = __sql
249-
return super().execute(__sql) # type: ignore
282+
return self
283+
284+
def exec(self, __sql: Any, __parameters: Any = ()):
285+
"""
286+
Execute using super().execute
287+
288+
Use if bugs appered in fyCursor.execute
289+
"""
290+
return super().execute(__sql, __parameters)
250291

251292
def fetch(
252293
self,
@@ -260,10 +301,12 @@ def fetch(
260301
"""
261302
if not self._query and not self._execution:
262303
raise ProgrammingError("Nothing to fetch")
263-
print(self._query, self._execution)
304+
264305
super().execute(self._query or self._execution) # type: ignore
265306
super().connection.commit()
266-
self._execution = self._query = None
307+
308+
self._empty_query()
309+
267310
return super().fetchone() if one else super().fetchall()
268311

269312
def one(self) -> Any:
@@ -280,12 +323,14 @@ def one(self) -> Any:
280323

281324
def commit(self) -> Self:
282325
if self._execution:
326+
print(self._execution)
283327
super().execute(self._execution)
284328
elif self._query:
285329
super().execute(self._query)
286-
self._execution = self._query = None
287-
288330
super().connection.commit()
331+
332+
self._empty_query()
333+
289334
return self
290335

291336
def create_table(

fyCursor/core/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Optional, Any
2-
from ..sql_types import DATATYPES
2+
from ..constants.sql_types import DATATYPES
33

44

55
def _pass() -> str:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Setting up
1414
setup(
1515
name="fyCursor",
16-
version="0.1.5.4",
16+
version="0.1.6",
1717
description='Simple sqlite3 cursor',
1818
author="felixyeahh",
1919
author_email="<[email protected]>",

0 commit comments

Comments
 (0)