forked from LadybugDB/ladybug-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepared_statement.py
More file actions
56 lines (47 loc) · 1.4 KB
/
Copy pathprepared_statement.py
File metadata and controls
56 lines (47 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from .connection import Connection
class PreparedStatement:
"""
A prepared statement is a parameterized query which can avoid planning the
same query for repeated execution.
"""
def __init__(
self,
connection: Connection,
query: str,
parameters: dict[str, Any] | None = None,
):
"""
Parameters
----------
connection : Connection
Connection to a database.
query : str
Query to prepare.
parameters : dict[str, Any]
Parameters for the query.
"""
if parameters is None:
parameters = {}
self._prepared_statement = connection._connection.prepare(query, parameters)
self._connection = connection
def is_success(self) -> bool:
"""
Check if the prepared statement is successfully prepared.
Returns
-------
bool
True if the prepared statement is successfully prepared.
"""
return self._prepared_statement.is_success()
def get_error_message(self) -> str:
"""
Get the error message if the query is not prepared successfully.
Returns
-------
str
Error message.
"""
return self._prepared_statement.get_error_message()