Samchon Framework for CPP
1.0.0
|
A sql statement. More...
#include <SQLStatement.hpp>
Public Member Functions | |
void | free () |
Free the sql statement. More... | |
void | refresh () |
Refresh the sql statement. More... | |
template<typename T , typename... _Args> | |
void | prepare (const std::string &sql, const T &val, const _Args &...args) |
Prepare a sql statement. More... | |
void | execute () |
Execute the prepared sql statement. More... | |
void | executeDirectly (const std::string &sql) |
Execute sql-statement direclty. More... | |
auto | fetch () const -> bool |
Fetch a record. More... | |
auto | next () const -> bool |
Move cursor to the next sql-statement. More... | |
auto | size () const -> size_t |
Get size of columns. More... | |
template<typename T > | |
auto | at (size_t index) const -> T |
Get column's data by its index. More... | |
Protected Member Functions | |
SQLStatement (SQLi *sqli) | |
Protected Constructor. More... | |
Protected Attributes | |
SQLi * | sqli |
SQLi who created the SQLStatement. More... | |
void * | hstmt |
Handler of sql statement (OBDC) More... | |
size_t | bindParameterCount |
Count of binded parameters . More... | |
HashMap< size_t, SQL_SIZE_T > | bindParameterBASizeMap |
A map for binary size. More... | |
Private Member Functions | |
template<typename T , typename... _Args> | |
void | bindParameter (const T &val, const _Args &...args) |
Get a column data by its name. More... | |
A sql statement.
A SQLStatement instance is used to executing a SQL statement and returning the results it produces against a SQL database that is opened through a SQLi instance.
Through the SQLi, it's the reason why a principle of DBMS, DBMS system doesn't allow simultaneous query from a session (connection). Only a query (process) is allowed at a time. If you try to simultaneous query from a SQLi, ODBC throws error. To avoid the error, an execute of query from SQLStatement will lock a mutex of SQLi to ensure exclusiveness.
To ensure the exclusiveness, you've to make SQLStatement from SQLi. Do not make SQLStatement by yourself. call SQLi::createSQLStatement() instead. Even you make a derived class from SQLStatement, don't make its constructor to have public accessor.
Becuase execution of a sql statement causes lock on mutex in SQLi, you've to destruct the SQLStatement or call free() method(). If you don't, the mutex will not be unlocked, thus you can't do anything by the SQLi.
Definition at line 46 of file SQLStatement.hpp.
|
inlineprotected |
Protected Constructor.
SQLStatement's constructor have to created by SQLi::createStatement().
Don't create SQLStatement by yourself.
SQLStatement has to be created by SQLi::createStatement().
sqli | Parent SQLi who created the SQLStatement |
Definition at line 98 of file SQLStatement.hpp.
|
inline |
Free the sql statement.
Definition at line 124 of file SQLStatement.hpp.
Referenced by SQLStatement().
|
inline |
Refresh the sql statement.
Definition at line 140 of file SQLStatement.hpp.
Referenced by prepare().
|
inline |
Prepare a sql statement.
Prepare a sql statement with parameters to bind for execution
sql | A sql-statement to prepare |
... | args The parameters to bind |
Definition at line 168 of file SQLStatement.hpp.
References bindParameter(), and refresh().
|
inline |
Execute the prepared sql statement.
exception | Error message from DBMS |
Definition at line 212 of file SQLStatement.hpp.
Referenced by executeDirectly().
|
inline |
Execute sql-statement direclty.
Executes the given sql-statement without preparing or binding any parameter
sql | sql-statement you want to execute |
exception | Error message from DBMS |
exception | Method prepare is already called |
Definition at line 239 of file SQLStatement.hpp.
References execute().
|
inline |
Fetch a record.
Whether succeded to fetch a record.
False means there's not any record or previous record was the last.
Definition at line 260 of file SQLStatement.hpp.
References next().
|
inline |
Move cursor to the next sql-statement.
Definition at line 279 of file SQLStatement.hpp.
Referenced by fetch().
|
inline |
Get size of columns.
Returns the number of columns in a result set.
Definition at line 293 of file SQLStatement.hpp.
Referenced by at().
|
inline |
Get column's data by its index.
Returns column's data from fetched-record by specified column index
index | Index number of a column wants to get |
Definition at line 308 of file SQLStatement.hpp.
References size().
|
inlineprivate |
Get a column data by its name.
Returns column's data from fetchched-recrod by specified column name
name | Name of a column wants to get |
Converts the records of current sql-statement to XML.
Recommends to override for each DBMS's domain XML rule.
Definition at line 396 of file SQLStatement.hpp.
References samchon::HashMap< Key, T, Hash, Pred, Alloc >::get(), and samchon::HashMap< Key, T, Hash, Pred, Alloc >::set().
Referenced by prepare().
|
protected |
SQLi who created the SQLStatement.
Definition at line 63 of file SQLStatement.hpp.
Referenced by SQLStatement().
|
protected |
Handler of sql statement (OBDC)
Definition at line 68 of file SQLStatement.hpp.
|
protected |
Count of binded parameters
.
Definition at line 76 of file SQLStatement.hpp.
|
protected |
A map for binary size.
When calls ByteArray::size(), the returned size_t value can't be kept until
Definition at line 84 of file SQLStatement.hpp.