Samchon Framework for CPP  1.0.0
samchon::library::SQLStatement Class Reference

A sql statement. More...

#include <SQLStatement.hpp>

Collaboration diagram for samchon::library::SQLStatement:

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

SQLisqli
 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...
 

Detailed Description

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.

Class Diagram
Note

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.

Library - SQL Driver

Author
Jeongho Nam http://samchon.org

Definition at line 46 of file SQLStatement.hpp.

Constructor & Destructor Documentation

samchon::library::SQLStatement::SQLStatement ( SQLi sqli)
inlineprotected

Protected Constructor.

SQLStatement's constructor have to created by SQLi::createStatement().

Note

Don't create SQLStatement by yourself.

SQLStatement has to be created by SQLi::createStatement().

Parameters
sqliParent SQLi who created the SQLStatement

Definition at line 98 of file SQLStatement.hpp.

References free(), and sqli.

Here is the call graph for this function:

Member Function Documentation

void samchon::library::SQLStatement::free ( )
inline

Free the sql statement.

Definition at line 124 of file SQLStatement.hpp.

Referenced by SQLStatement().

Here is the caller graph for this function:

void samchon::library::SQLStatement::refresh ( )
inline

Refresh the sql statement.

Definition at line 140 of file SQLStatement.hpp.

Referenced by prepare().

Here is the caller graph for this function:

template<typename T , typename... _Args>
void samchon::library::SQLStatement::prepare ( const std::string &  sql,
const T &  val,
const _Args &...  args 
)
inline

Prepare a sql statement.

Prepare a sql statement with parameters to bind for execution

Warning
Be careful for destructions of binded parameters
Parameters
sqlA sql-statement to prepare
...args The parameters to bind

Definition at line 168 of file SQLStatement.hpp.

References bindParameter(), and refresh().

Here is the call graph for this function:

void samchon::library::SQLStatement::execute ( )
inline

Execute the prepared sql statement.

Exceptions
exceptionError message from DBMS

Definition at line 212 of file SQLStatement.hpp.

Referenced by executeDirectly().

Here is the caller graph for this function:

void samchon::library::SQLStatement::executeDirectly ( const std::string &  sql)
inline

Execute sql-statement direclty.

Executes the given sql-statement without preparing or binding any parameter

Warning
  • Cannot use if prepare statement has already defined. Use execute instead.
  • Not recommended when the case of dynamic sql and the sql-statement is not for procedure but for direct access to table. Use prepare and execute instead.
Parameters
sqlsql-statement you want to execute
Exceptions
exceptionError message from DBMS
exceptionMethod prepare is already called

Definition at line 239 of file SQLStatement.hpp.

References execute().

Here is the call graph for this function:

auto samchon::library::SQLStatement::fetch ( ) const -> bool
inline

Fetch a record.

Returns

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().

Here is the call graph for this function:

auto samchon::library::SQLStatement::next ( ) const -> bool
inline

Move cursor to the next sql-statement.

Returns
Whether succeded to move cursor to the next statement.

Definition at line 279 of file SQLStatement.hpp.

Referenced by fetch().

Here is the caller graph for this function:

auto samchon::library::SQLStatement::size ( ) const -> size_t
inline

Get size of columns.

Returns the number of columns in a result set.

Warning
Not size of rows.

Definition at line 293 of file SQLStatement.hpp.

Referenced by at().

Here is the caller graph for this function:

template<typename T >
auto samchon::library::SQLStatement::at ( size_t  index) const -> T
inline

Get column's data by its index.

Returns column's data from fetched-record by specified column index

Parameters
indexIndex number of a column wants to get
Returns
Data stored in the record at the position of specifield column

Definition at line 308 of file SQLStatement.hpp.

References size().

Here is the call graph for this function:

template<typename T , typename... _Args>
void samchon::library::SQLStatement::bindParameter ( const T &  val,
const _Args &...  args 
)
inlineprivate

Get a column data by its name.

Returns column's data from fetchched-recrod by specified column name

Parameters
nameName of a column wants to get
Returns
Data stored in the record at the position of specifield column Result sets to XML

Converts the records of current sql-statement to XML.

Recommends to override for each DBMS's domain XML rule.

Returns
XML representing records of the statement

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

SQLi* samchon::library::SQLStatement::sqli
protected

SQLi who created the SQLStatement.

Definition at line 63 of file SQLStatement.hpp.

Referenced by SQLStatement().

void* samchon::library::SQLStatement::hstmt
protected

Handler of sql statement (OBDC)

Definition at line 68 of file SQLStatement.hpp.

size_t samchon::library::SQLStatement::bindParameterCount
protected

Count of binded parameters
.

Definition at line 76 of file SQLStatement.hpp.

HashMap<size_t, SQL_SIZE_T> samchon::library::SQLStatement::bindParameterBASizeMap
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.


The documentation for this class was generated from the following file: