-
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
268 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,21 @@ | ||
#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; | ||
|
||
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,18 @@ | ||
#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) | ||
} | ||
|
||
py::str PyPreparedStatement::getErrorMessage() const { | ||
return preparedStatement->getErrorMessage(); | ||
} | ||
|
||
bool PyPreparedStatement::isSuccess() const { | ||
return preparedStatement->isSuccess(); | ||
} |
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,51 @@ | ||
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. | ||
""" | ||
|
||
def __init__(self, connection, query): | ||
""" | ||
Parameters | ||
---------- | ||
connection : Connection | ||
Connection to a database. | ||
query : str | ||
Query to prepare. | ||
""" | ||
|
||
self._prepared_statement = connection._connection.prepare(query) | ||
|
||
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() |
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.