|
lintel 0.2.0
|
#include <PreparedStatement.h>
Classes | |
| struct | Definition |
Public Member Functions | |
| PreparedStatement (const Connection &connection, const Definition &definition) | |
| ~PreparedStatement () noexcept | |
| std::shared_ptr< Result > | execute (const std::vector< std::string > ¶ms) |
| void | close () |
Static Public Member Functions | |
| static constexpr int32_t | initNParams (std::string_view tempStatement) |
| static std::string | initStatement (const std::string &tempStatement) |
format of prepared statement example: insert into table (..,..) values(?,?);
=> ? will be replace automatically with $1 and $2 => algorithm will automatically count the number of parameters
| lintel::postgresql::PreparedStatement::PreparedStatement | ( | const Connection & | connection, |
| const Definition & | definition | ||
| ) |
Prepares a statement on the given connection.
| connection | the PostgreSQL connection |
| definition | the statement name and SQL template |
|
noexcept |
Destroys the object and deallocates the server-side prepared statement.
A pooled connection is reused, so a prepared statement that survived the release would still be visible to the next lease (and a name collision would make the next prepare fail). The destructor deallocates it, and because destructors must not throw it swallows the failure of a connection that is already gone - the pool's health check drops such a connection anyway.
The statement stays named rather than unnamed (PQprepare with ""): the parameterized query path (Statement::execute(query, builder)) uses PQexecParams, which also targets the unnamed statement, so an unnamed prepared statement would be clobbered between its prepare and execute. Deallocating in the destructor is the deterministic equivalent for reuse.
| void lintel::postgresql::PreparedStatement::close | ( | ) |
Closes the prepared statement.
| std::shared_ptr< Result > lintel::postgresql::PreparedStatement::execute | ( | const std::vector< std::string > & | params | ) |
Executes the prepared statement with the given parameters.
| params | the parameter values as strings |
|
inlinestaticconstexpr |
Counts the number of '?' placeholders in a statement template.
| tempStatement | the statement template |
|
static |
Converts '?' placeholders to PostgreSQL's $1, $2, ... format.
| tempStatement | the statement template with '?' placeholders |