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

A SQL interface; DBMS connector. More...

#include <SQLi.hpp>

Public Member Functions

 SQLi (const std::string &driver, int port)
 Construct from driver name and port. More...
 
virtual auto createStatement () -> std::shared_ptr< SQLStatement >
 Factory method for creating SQLStatement. More...
 
virtual void connect (const std::string &ip, const std::string &db, const std::string &id, const std::string &pwd)
 Connect to the DBMS
. More...
 
virtual void disconnect ()
 Disconnect from DBMS. More...
 

Protected Member Functions

virtual auto getErrorMessage (short type) const -> std::string
 Get error message. More...
 

Protected Attributes

std::string driver
 Driver; name of DBMS used for connection. More...
 
int port
 Port number of DBMS. More...
 
bool connected
 Had connected to DBMS. More...
 

Detailed Description

A SQL interface; DBMS connector.

SQLi is an abstract class managing connection (session) with a specific database and manages SQL statements are executed and results are returned within the context of a connection.

The reason why SQLStatement(s) are managed by SQLi is because of a principle of DBMS, DBMS system doesn't allow simultaneous query from a session (connection). Only a query (process0) 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 SQLStatement::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 42 of file SQLi.hpp.

Constructor & Destructor Documentation

samchon::library::SQLi::SQLi ( const std::string &  driver,
int  port 
)
inline

Construct from driver name and port.

Parameters
driverDriver name of DBMS
portPort number of DBMS

Definition at line 83 of file SQLi.hpp.

References disconnect(), driver, and port.

Here is the call graph for this function:

Member Function Documentation

virtual auto samchon::library::SQLi::createStatement ( ) -> std::shared_ptr<SQLStatement>
inlinevirtual

Factory method for creating SQLStatement.

Recommend to create SQLStatement by this method. Direct creation is not recommended as the reason of domain problem of each DBMS

Returns
A SQLStatement matched for the domain SQLi

Definition at line 106 of file SQLi.hpp.

References connect().

Here is the call graph for this function:

virtual void samchon::library::SQLi::connect ( const std::string &  ip,
const std::string &  db,
const std::string &  id,
const std::string &  pwd 
)
inlinevirtual

Connect to the DBMS
.

Parameters
ipAn IP address of the DBMS
dbA name of database to access
idYour own ID authorified from DBMS
pwdA password for the ID
Exceptions
exceptionError message from DBMS

Definition at line 122 of file SQLi.hpp.

References disconnect(), getErrorMessage(), and samchon::library::StringUtil::substitute().

Referenced by createStatement().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void samchon::library::SQLi::disconnect ( )
inlinevirtual

Disconnect from DBMS.

Definition at line 163 of file SQLi.hpp.

Referenced by connect(), and SQLi().

Here is the caller graph for this function:

virtual auto samchon::library::SQLi::getErrorMessage ( short  type) const -> std::string
inlineprotectedvirtual

Get error message.

Gets error message for throwing exception.

Definition at line 192 of file SQLi.hpp.

Referenced by connect().

Here is the caller graph for this function:

Member Data Documentation

std::string samchon::library::SQLi::driver
protected

Driver; name of DBMS used for connection.

  • MySQL: "{MySQL Server}"
  • MS-SQL: "{SQL Server}"
  • PL-SQL: "{Oracle}"

Definition at line 55 of file SQLi.hpp.

Referenced by SQLi().

int samchon::library::SQLi::port
protected

Port number of DBMS.

  • MySQL: 3306
  • MS-SQL: 1433
  • PL-SQL: 1521

Definition at line 65 of file SQLi.hpp.

Referenced by SQLi().

bool samchon::library::SQLi::connected
protected

Had connected to DBMS.

connected is a flag variable for connection to DBMS. However, it doesn't mean the real-time status. connected only stores whether a connection was succeeded or not.

Definition at line 74 of file SQLi.hpp.


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