|
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 &) |
| 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... | |
| template<typename T > | |
| auto | get (const std::string &) const -> T |
| Get a column data by its name. More... | |
| virtual auto | toXML () const -> std::shared_ptr< XML > |
| Result sets to XML. 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... | |
| Map< size_t, SQL_SIZE_T > | bindParameterBASizeMap |
| A map for binary size. 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 SQLStatement::free() method(). If you don't, the mutex will not be unlocked, thus you can't do anything by the SQLi.
Definition at line 44 of file SQLStatement.hpp.
|
protected |
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 22 of file SQLStatement.cpp.
References samchon::library::SQLi::hdbc.
| void SQLStatement::free | ( | ) |
Free the sql statement.
Definition at line 41 of file SQLStatement.cpp.
References samchon::library::SQLi::stmt, and samchon::library::SQLi::stmtMutex.
| void SQLStatement::refresh | ( | ) |
Refresh the sql statement.
Definition at line 53 of file SQLStatement.cpp.
References samchon::library::SQLi::stmt, and samchon::library::SQLi::stmtMutex.
|
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 126 of file SQLStatement.hpp.
| void SQLStatement::execute | ( | ) |
Execute the prepared sql statement.
| exception | Error message from DBMS |
Definition at line 83 of file SQLStatement.cpp.
| void SQLStatement::executeDirectly | ( | const std::string & | sql | ) |
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 89 of file SQLStatement.cpp.
| auto SQLStatement::fetch | ( | ) | const -> bool |
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 109 of file SQLStatement.cpp.
| auto SQLStatement::next | ( | ) | const -> bool |
Move cursor to the next sql-statement.
Definition at line 105 of file SQLStatement.cpp.
| auto SQLStatement::size | ( | ) | const -> size_t |
Get size of columns.
Returns the number of columns in a result set.
Definition at line 123 of file SQLStatement.cpp.
|
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 220 of file SQLStatement.hpp.
|
inline |
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 |
Definition at line 247 of file SQLStatement.hpp.
|
virtual |
Result sets to XML.
Converts the records of current sql-statement to XML.
Recommends to override for each DBMS's domain XML rule.
Reimplemented in samchon::library::TSQLStatement.
Definition at line 134 of file SQLStatement.cpp.
|
protected |
SQLi who created the SQLStatement.
Definition at line 61 of file SQLStatement.hpp.
|
protected |
Handler of sql statement (OBDC)
Definition at line 66 of file SQLStatement.hpp.
|
protected |
Count of binded parameters
.
Definition at line 74 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 82 of file SQLStatement.hpp.