-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python API binding for prepared statement
- Loading branch information
Showing
11 changed files
with
294 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "main/kuzu.h" | ||
#include "main/prepared_statement.h" | ||
#include "pybind_include.h" | ||
|
||
using namespace kuzu::main; | ||
|
||
class PyPreparedStatement { | ||
friend class PyConnection; | ||
|
||
public: | ||
static void initialize(py::handle& m); | ||
|
||
py::str getErrorMessage() const; | ||
|
||
bool isSuccess() const; | ||
|
||
bool isReadOnly() const; | ||
|
||
private: | ||
std::unique_ptr<PreparedStatement> preparedStatement; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "include/py_prepared_statement.h" | ||
|
||
#include "binder/binder.h" | ||
#include "planner/logical_plan/logical_plan.h" | ||
|
||
void PyPreparedStatement::initialize(py::handle& m) { | ||
py::class_<PyPreparedStatement>(m, "PreparedStatement") | ||
.def("get_error_message", &PyPreparedStatement::getErrorMessage) | ||
.def("is_success", &PyPreparedStatement::isSuccess) | ||
.def("is_read_only", &PyPreparedStatement::isReadOnly); | ||
} | ||
|
||
py::str PyPreparedStatement::getErrorMessage() const { | ||
return preparedStatement->getErrorMessage(); | ||
} | ||
|
||
bool PyPreparedStatement::isSuccess() const { | ||
return preparedStatement->isSuccess(); | ||
} | ||
|
||
bool PyPreparedStatement::isReadOnly() const { | ||
return preparedStatement->isReadOnly(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class PreparedStatement: | ||
""" | ||
A prepared statement is a parameterized query which can avoid planning the | ||
same query for repeated execution. | ||
Methods | ||
------- | ||
is_success() | ||
Check if the prepared statement is successfully prepared. | ||
get_error_message() | ||
Get the error message if the query is not prepared successfully. | ||
is_read_only() | ||
Check if the prepared statement is read-only. | ||
""" | ||
|
||
def __init__(self, connection, query): | ||
""" | ||
Parameters | ||
---------- | ||
connection : Connection | ||
Connection to a database. | ||
query : str | ||
Query to prepare. | ||
""" | ||
|
||
self._prepared_statement = connection._connection.prepare(query) | ||
# Keep a reference to the connection to prevent make sure the connection | ||
# is not garbage collected before the prepared statement. | ||
self.connection = connection | ||
|
||
def is_success(self): | ||
""" | ||
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): | ||
""" | ||
Get the error message if the query is not prepared successfully. | ||
Returns | ||
------- | ||
str | ||
Error message. | ||
""" | ||
|
||
return self._prepared_statement.get_error_message() | ||
|
||
def is_read_only(self): | ||
""" | ||
Check if the prepared statement is read-only. | ||
Returns | ||
------- | ||
bool | ||
True if the prepared statement is read-only. | ||
""" | ||
|
||
return self._prepared_statement.is_read_only() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.