Skip to content

Commit 5d26bb4

Browse files
committed
fix: correctly implement SQL parameter replacement as pyformat paramstyle
1 parent 4e26ebb commit 5d26bb4

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

wherobots/__init__.py

Whitespace-only changes.

wherobots/db/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
2020
PROTOCOL_VERSION: Version = Version("1.0.0")
2121

22+
PARAM_STYLE = "pyformat"
23+
2224

2325
class ExecutionState(LowercaseStrEnum):
2426
IDLE = auto()

wherobots/db/cursor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ def execute(self, operation: str, parameters: Dict[str, Any] = None) -> None:
8080
self.__rowcount = -1
8181
self.__description = None
8282

83-
sql = (
84-
operation.replace("{", "{{").replace("}", "}}").format(**(parameters or {}))
83+
self.__current_execution_id = self.__exec_fn(
84+
operation % (parameters or {}), self.__on_execution_result
8585
)
86-
self.__current_execution_id = self.__exec_fn(sql, self.__on_execution_result)
8786

8887
def executemany(
8988
self, operation: str, seq_of_parameters: List[Dict[str, Any]]

wherobots/db/driver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import platform
1212
import requests
1313
import tenacity
14-
from typing import Union, Dict
14+
from typing import Final, Union, Dict
1515
import urllib.parse
1616
import websockets.sync.client
1717
import certifi
@@ -25,6 +25,7 @@
2525
DEFAULT_SESSION_TYPE,
2626
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
2727
MAX_MESSAGE_SIZE,
28+
PARAM_STYLE,
2829
PROTOCOL_VERSION,
2930
AppStatus,
3031
DataCompression,
@@ -41,7 +42,7 @@
4142

4243
apilevel = "2.0"
4344
threadsafety = 1
44-
paramstyle = "pyformat"
45+
paramstyle: Final[str] = PARAM_STYLE
4546

4647

4748
def gen_user_agent_header():

0 commit comments

Comments
 (0)