DCL 3.7.4
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 setErrorHandle (SQL::Error _error, const wchar_t *_filename, int _line)
void setErrorMessage (const ByteString &_message, const wchar_t *_filename, int _line)
 MyConnection (const wchar_t *_serverTitle)
virtual void destroy ()
virtual ~MyConnection ()
virtual bool __open (const char *_conns, size_t _connslen)
virtual bool __close ()
virtual bool __execute (const char *_sql, size_t _sqllen)
virtual bool __startTrans ()
virtual bool __commitTrans ()
virtual bool __rollbackTrans ()
virtual bool __createQueryInstance (SQL::Query **_queryHandleOut)
virtual bool __getErrorMessage (char *_buf, size_t *_buflen)
virtual bool __getServerInfo (char *_buf, size_t *_buflen)
Public Member Functions inherited from SQL::Connection
long refCount () const
long addRef ()
long release ()
bool open (const char *_conn, size_t _connlen)
bool close ()
bool execute (const char *_sql, size_t _sqllen)
bool startTrans ()
bool commitTrans ()
bool rollbackTrans ()
bool getErrorMessage (char *_buf, size_t *_buflen)
bool getServerInfo (char *_buf, size_t *_buflen)
bool createQueryInstance (Query **_queryHandle)
bool destroyQueryInstance (Query *_queryHandle)
Error errorCode () const
bool canTransact () const
const wchar_t * serverTitle () const
bool inState (unsigned int _state) 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 splitConnStr (const char *_connstr, size_t _strlen, ListedByteStringToByteStringMap &_results)
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 8 of file MyConnection.h.

Constructor & Destructor Documentation

◆ MyConnection()

MyConnection::MyConnection ( const wchar_t * _serverTitle)

◆ ~MyConnection()

MyConnection::~MyConnection ( )
virtual

Definition at line 56 of file MyConnection.cpp.

57{
58 if (__mysql) {
59 __DCL_TRACE0_N(L"Warning!! The connection was not closed\n");
60 close();
61 }
62}
#define __DCL_TRACE0_N(fmt)

Member Function Documentation

◆ __close()

bool MyConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 154 of file MyConnection.cpp.

155{
156 if (!__mysql) {
158 return false;
159 }
160
161 mysql_close(__mysql);
162 __mysql = NULL;
163
164 return true;
165}
#define NULL
Definition Config.h:312
#define __SET_ERROR_HANDLE(_SQLCODE)
@ eNotConnected
Definition SQLCore.h:33

◆ __commitTrans()

bool MyConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 227 of file MyConnection.cpp.

228{
229 if (mysql_commit(connHandle())) {
230 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
231 mysql_errno(connHandle()),
232 mysql_error(connHandle()))
233 );
234 }
235
236 return true;
237}
#define __SET_ERROR_MSG(_message)
MYSQL * connHandle() const

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 251 of file MyConnection.cpp.

252{
253 __DCL_ASSERT(_queryHandleOut != NULL);
254
255 MyQuery* pNewQuery = new MyQuery(this);
256 if (!pNewQuery) {
258 return false;
259 }
260
261 *_queryHandleOut = pNewQuery;
262 return true;
263}
#define __DCL_ASSERT(expr)
Definition Object.h:394
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

bool MyConnection::__execute ( const char * _sql,
size_t _sqllen )
virtual

Implements SQL::Connection.

Definition at line 198 of file MyConnection.cpp.

199{
200 if (mysql_real_query(connHandle(), _sql, (unsigned long) _sqllen)) {
201 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
202 mysql_errno(connHandle()),
203 mysql_error(connHandle()))
204 );
205 }
206
207 switch (__GetStmtType(_sql)) {
208 case StmtTransBegin:
210 break;
211 case StmtTransEnd:
213 break;
214 case StmtOther:
215 default:
216 ;
217 }
218
219 return true;
220}
@ StmtTransEnd
@ StmtOther
@ StmtTransBegin
#define __UNSET_STATE(state)
Definition SQLCore.h:483
#define __SET_STATE(state)
Definition SQLCore.h:482

◆ __getErrorMessage()

bool MyConnection::__getErrorMessage ( char * _buf,
size_t * _buflen )
virtual

Implements SQL::Connection.

Definition at line 265 of file MyConnection.cpp.

266{
267 if (__lastErrorMessage.length() < *_buflen) {
268 *_buflen = __lastErrorMessage.length();
269 *(_buf + *_buflen) = '\0';
270 }
271 strncpy(_buf, __lastErrorMessage.data(), *_buflen);
272 return true;
273}

◆ __getServerInfo()

bool MyConnection::__getServerInfo ( char * _buf,
size_t * _buflen )
virtual

Implements SQL::Connection.

Definition at line 275 of file MyConnection.cpp.

276{
277 const char* psz = mysql_get_server_info(connHandle());
278 if (!psz) {
279 return false;
280 }
281
282 size_t length = strlen(psz);
283 if (length < *_buflen) {
284 *_buflen = length;
285 *(_buf + *_buflen) = '\0';
286 }
287 strncpy(_buf, psz, *_buflen);
288 return true;
289}

◆ __open()

bool MyConnection::__open ( const char * _conns,
size_t _connslen )
virtual

Implements SQL::Connection.

Definition at line 87 of file MyConnection.cpp.

88{
89 if (__mysql == NULL && (__mysql = mysql_init(NULL)) == NULL) {
91 return false;
92 }
93
94 ListedByteStringToByteStringMap map;
95 Connection::splitConnStr(_conns, _connslen, map);
96
97 ByteString _APPLICATION = map["APPLICATION"];
98 if (!_APPLICATION.isEmpty()) {
99 mysql_options(connHandle(), MYSQL_READ_DEFAULT_GROUP, _APPLICATION.data());
100 }
101
102 ByteString _USER = map["USER"];
103 ByteString _PASSWORD = map["PASSWORD"];
104 ByteString _SERVER = map["SERVER"];
105 ByteString _DATABASE = map["DATABASE"];
106 ByteString _PORT = map["PORT"];
107 ByteString _UNIX_SOCKET = map["UNIX_SOCKET"];
108 __storeResult = map.find("STORE_RESULT") != map.end();
109
110 unsigned int port = 0;
111 if (!_PORT.isEmpty()) {
112 char* endptr;
113 unsigned long n = strtoul(_PORT.data(), &endptr, 10);
114 if (n == ULONG_MAX) {
115 __SET_ERROR_MSG("연결 문자열이 잘못되었습니다. PORT=" + _PORT);
116 return false;
117 }
118 port = (unsigned int) n;
119 }
120
121 if (mysql_real_connect(
122 connHandle(),
123 _SERVER.isEmpty()? NULL : _SERVER.data(),
124 _USER.isEmpty()? NULL : _USER.data(),
125 _PASSWORD.isEmpty()? NULL : _PASSWORD.data(),
126 _DATABASE.isEmpty() ? NULL : _DATABASE.data(),
127 port,
128 _UNIX_SOCKET.isEmpty() ? NULL : _UNIX_SOCKET.data(),
129 0
130 ) == NULL) {
132 return false;
133 }
134
135 if (mysql_set_character_set(connHandle(), "utf8")) {
136 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
137 mysql_errno(connHandle()),
138 mysql_error(connHandle()))
139 );
140 return false;
141 }
142
143 if (mysql_autocommit(connHandle(), 0)) {
144 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
145 mysql_errno(connHandle()),
146 mysql_error(connHandle()))
147 );
148 return false;
149 }
150
151 return true;
152}
@ eServerError
Definition SQLCore.h:21

◆ __rollbackTrans()

bool MyConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 239 of file MyConnection.cpp.

240{
241 if (mysql_rollback(connHandle())) {
242 __SET_ERROR_MSG(ByteString::format("(%u) %hs",
243 mysql_errno(connHandle()),
244 mysql_error(connHandle()))
245 );
246 }
247
248 return true;
249}

◆ __startTrans()

bool MyConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 222 of file MyConnection.cpp.

223{
224 return __execute("START TRANSACTION", 17);
225}
virtual bool __execute(const char *_sql, size_t _sqllen)

◆ connHandle()

MYSQL * MyConnection::connHandle ( ) const
inline

Definition at line 47 of file MyConnection.h.

48{
49 return __mysql;
50}

◆ destroy()

void MyConnection::destroy ( )
virtual

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

Implements SQL::Connection.

Definition at line 64 of file MyConnection.cpp.

65{
66 delete this;
67}

◆ setErrorHandle()

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

Definition at line 57 of file MyConnection.h.

62{
63 Connection::setErrorStatus(_error, _filename, _line);
64
65 if (_error == SQL::eServerError)
66 __lastErrorMessage = mysql_error(connHandle());
67 else
68 __lastErrorMessage.clear();
69}
_PROTECTED const wchar_t * _filename
Definition SQLCore.h:439
_PROTECTED const wchar_t int _line
Definition SQLCore.h:441

◆ setErrorMessage()

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

Definition at line 71 of file MyConnection.h.

76{
77 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
78
79 __lastErrorMessage = _message;
80}

◆ storeResult()

bool MyConnection::storeResult ( ) const
inline

Definition at line 52 of file MyConnection.h.

53{
54 return __storeResult;
55}

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