DCL 4.0
Loading...
Searching...
No Matches
MyConnection Class Reference

#include <MyConnection.h>

Inheritance diagram for MyConnection:
SQL::Connection Object

Public Member Functions

MYSQL * connHandle () const
bool storeResult () const
void setErrorStatus (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorStatus (const ByteString &_message, const wchar_t *_filename, int _line)
 MyConnection (const wchar_t *_serverTitle)
virtual void destroy ()
virtual ~MyConnection ()
virtual bool __open (const char *_pszConnString, size_t _n)
virtual bool __close ()
virtual bool __execute (const char *pszSQL, size_t _n)
virtual bool __startTrans ()
virtual bool __commitTrans ()
virtual bool __rollbackTrans ()
virtual bool __createQueryInstance (SQL::Query **_ppQuery)
virtual bool __getErrorMessage (char *_buffer, size_t *_size)
virtual bool __getServerInfo (char *_buffer, size_t *_size)
Public Member Functions inherited from SQL::Connection
long refCount () const
long addRef ()
long release ()
bool open (const char *_connString, size_t _connlen)
bool close ()
bool execute (const char *_sql, size_t _sqllen)
bool startTrans ()
bool commitTrans ()
bool rollbackTrans ()
bool getErrorMessage (char *_pbuf, size_t *_pn)
bool getServerInfo (char *_pbuf, size_t *_pn)
bool createQueryInstance (Query **_queryHandleOut)
bool destroyQueryInstance (Query *_queryHandle)
Error errorCode () const
bool canTransact () const
const wchar_t * serverTitle () const
bool inState (unsigned int uState) const
Public Member Functions inherited from Object
virtual String toString () const
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Additional Inherited Members

Public Types inherited from SQL::Connection
enum  State { stClosed = 0x0001 , stOpenned = 0x0002 , stInTransaction = 0x0004 }
Static Public Member Functions inherited from SQL::Connection
static size_t splitConnectionString (const char *_connString, size_t _strlen, ListedByteStringToByteStringMap &_map)
Public Attributes inherited from SQL::Connection
__PROTECTED : void setErrorStatus(Error _errorCode
__PROTECTED const wchar_t * _filename
__PROTECTED const wchar_t int _line
Protected Member Functions inherited from SQL::Connection
 Connection (const wchar_t *_serverTitle)
virtual ~Connection ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()
Protected Attributes inherited from SQL::Connection
bool __canTransact
const wchar_t * __serverTitle
Error __errorCode
const wchar_t * __errorFileName
int __errorLine
unsigned int __states

Detailed Description

Definition at line 18 of file MyConnection.h.

Constructor & Destructor Documentation

◆ MyConnection()

MyConnection::MyConnection ( const wchar_t * _serverTitle)

◆ ~MyConnection()

MyConnection::~MyConnection ( )
virtual

Definition at line 51 of file MyConnection.cpp.

52{
53 if (__mysql) {
54 __DCL_TRACE0_N(L"Warning!! The connection was not closed\n");
55 close();
56 }
57}
#define __DCL_TRACE0_N(fmt)
Definition IFXField.cpp:37

Member Function Documentation

◆ __close()

bool MyConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 148 of file MyConnection.cpp.

149{
150 if (!__mysql) {
152 return false;
153 }
154
155 mysql_close(__mysql);
156 __mysql = NULL;
157
158 return true;
159}
#define NULL
Definition Config.h:340
#define __SET_ERROR(_error)
@ eNotConnected
Definition SQLCore.h:33

◆ __commitTrans()

bool MyConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 220 of file MyConnection.cpp.

221{
222 if (mysql_commit(connHandle())) {
223 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
224 mysql_errno(connHandle()),
225 mysql_error(connHandle())));
226 }
227
228 return true;
229}
#define __SET_ERROR_MSG(_msg)
MYSQL * connHandle() const

◆ __createQueryInstance()

bool MyConnection::__createQueryInstance ( SQL::Query ** _ppQuery)
virtual

Implements SQL::Connection.

Definition at line 242 of file MyConnection.cpp.

243{
244 __DCL_ASSERT(_ppQuery != NULL);
245
246 MyQuery* pNewQuery = new MyQuery(this);
247 if (!pNewQuery) {
249 return false;
250 }
251
252 *_ppQuery = pNewQuery;
253 return true;
254}
#define __DCL_ASSERT(expr)
Definition Object.h:371
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

bool MyConnection::__execute ( const char * pszSQL,
size_t _n )
virtual

Implements SQL::Connection.

Definition at line 192 of file MyConnection.cpp.

193{
194 if (mysql_real_query(connHandle(), _sql, (unsigned long) _n)) {
195 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
196 mysql_errno(connHandle()),
197 mysql_error(connHandle())));
198 }
199
200 switch (__GetStmtType(_sql)) {
201 case StmtTransBegin:
203 break;
204 case StmtTransEnd:
206 break;
207 case StmtOther:
208 default:
209 ;
210 }
211
212 return true;
213}
@ StmtTransEnd
@ StmtOther
@ StmtTransBegin
#define __UNSET_STATE(state)
Definition SQLCore.h:431
#define __SET_STATE(state)
Definition SQLCore.h:430

◆ __getErrorMessage()

bool MyConnection::__getErrorMessage ( char * _buffer,
size_t * _size )
virtual

Implements SQL::Connection.

Definition at line 256 of file MyConnection.cpp.

257{
258 if (__lastErrorMessage.length() < *_size)
259 *_size = __lastErrorMessage.length();
260
261 strncpy(_buffer, __lastErrorMessage.data(), *_size);
262
263 return true;
264}

◆ __getServerInfo()

bool MyConnection::__getServerInfo ( char * _buffer,
size_t * _size )
virtual

Implements SQL::Connection.

Definition at line 266 of file MyConnection.cpp.

267{
268 const char* psz = mysql_get_server_info(connHandle());
269 if (!psz)
270 return false;
271
272 size_t nLength = strlen(psz);
273
274 if (nLength < *_size)
275 *_size = nLength;
276
277 strncpy(_buffer, psz, *_size);
278
279 return true;
280}

◆ __open()

bool MyConnection::__open ( const char * _pszConnString,
size_t _n )
virtual

Implements SQL::Connection.

Definition at line 82 of file MyConnection.cpp.

83{
84 if ((__mysql = mysql_init(NULL)) == NULL) {
86 return false;
87 }
88
89 ListedByteStringToByteStringMap map;
90 Connection::splitConnectionString(_pszConnString, _n, map);
91
92 ByteString strAppName = map["APPLICATION"];
93
94 if (!strAppName.isEmpty()) {
95 mysql_options(connHandle(), MYSQL_READ_DEFAULT_GROUP, strAppName.data());
96 }
97
98 ByteString strUser = map["USER"];
99 ByteString strPassword = map["PASSWORD"];
100 ByteString strHost = map["SERVER"];
101 ByteString strDb = map["DATABASE"];
102 ByteString strPort = map["PORT"];
103 ByteString strUnixSocket = map["UNIX_SOCKET"];
104 __storeResult = map.find("STORE_RESULT") != map.end();
105
106 unsigned int port = 0;
107 if (!strPort.isEmpty()) {
108 char* endptr;
109 unsigned long n = strtoul(strPort.data(), &endptr, 10);
110 if (n == ULONG_MAX) {
111 __SET_ERROR_MSG("연결 문자열이 잘못되었습니다. PORT=" + strPort);
112 return false;
113 }
114 port = (unsigned int) n;
115 }
116
117 if (mysql_real_connect(
118 connHandle(),
119 strHost.isEmpty()? NULL : strHost.data(),
120 strUser.isEmpty()? NULL : strUser.data(),
121 strPassword.isEmpty()? NULL : strPassword.data(),
122 strDb.isEmpty() ? NULL : strDb.data(),
123 port,
124 strUnixSocket.isEmpty() ? NULL : strUnixSocket.data(),
125 0
126 ) == NULL) {
128 return false;
129 }
130
131 if (mysql_set_character_set(connHandle(), "utf8")) {
132 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
133 mysql_errno(connHandle()),
134 mysql_error(connHandle())));
135 return false;
136 }
137
138 if (mysql_autocommit(connHandle(), 0)) {
139 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
140 mysql_errno(connHandle()),
141 mysql_error(connHandle())));
142 return false;
143 }
144
145 return true;
146}
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
@ eServerError
Definition SQLCore.h:21

◆ __rollbackTrans()

bool MyConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 231 of file MyConnection.cpp.

232{
233 if (mysql_rollback(connHandle())) {
234 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
235 mysql_errno(connHandle()),
236 mysql_error(connHandle())));
237 }
238
239 return true;
240}

◆ __startTrans()

bool MyConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 215 of file MyConnection.cpp.

216{
217 return __execute("START TRANSACTION", 17);
218}
virtual bool __execute(const char *pszSQL, size_t _n)

◆ connHandle()

MYSQL * MyConnection::connHandle ( ) const
inline

Definition at line 50 of file MyConnection.h.

51{
52 return __mysql;
53}

◆ destroy()

void MyConnection::destroy ( )
virtual

파생클래스에서 new 연산자를 override했거나, 추가적인 행위가 필요하다면 이것도 override하라

Implements SQL::Connection.

Definition at line 59 of file MyConnection.cpp.

60{
61 delete this;
62}

◆ setErrorStatus() [1/2]

void MyConnection::setErrorStatus ( const ByteString & _message,
const wchar_t * _filename,
int _line )
inline

Definition at line 74 of file MyConnection.h.

79{
80 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
81 __lastErrorMessage = _message;
82}
__PROTECTED const wchar_t int _line
Definition SQLCore.h:390
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:390

◆ setErrorStatus() [2/2]

void MyConnection::setErrorStatus ( SQL::Error _error,
const wchar_t * _filename,
int _line )
inline

Definition at line 60 of file MyConnection.h.

65{
66 Connection::setErrorStatus(_error, _filename, _line);
67
68 if (_error == SQL::eServerError)
69 __lastErrorMessage = mysql_error(connHandle());
70 else
71 __lastErrorMessage.clear();
72}

◆ storeResult()

bool MyConnection::storeResult ( ) const
inline

Definition at line 55 of file MyConnection.h.

56{
57 return __storeResult;
58}

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