DCL 3.7.4
Loading...
Searching...
No Matches
SqConnection Class Reference

#include <SqConnection.h>

Inheritance diagram for SqConnection:
SQL::Connection Object

Public Member Functions

sqlite3 * connHandle () const
int cursor () const
int stmtNo ()
void setErrorMessage (const ByteString &_message, const wchar_t *_filename, int _line)
virtual void destroy ()
 SqConnection (const wchar_t *_serverTitle)
virtual ~SqConnection ()
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 6 of file SqConnection.h.

Constructor & Destructor Documentation

◆ SqConnection()

SqConnection::SqConnection ( const wchar_t * _serverTitle)

◆ ~SqConnection()

SqConnection::~SqConnection ( )
virtual

Definition at line 56 of file SqConnection.cpp.

57{
58 if (__conn) {
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 SqConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 161 of file SqConnection.cpp.

162{
163 if (!__conn) {
165 return false;
166 }
167
168 int rc = sqlite3_close_v2(__conn);
169 __conn = NULL;
170 if (rc != SQLITE_OK) {
171 __SET_ERROR_MSG(sqlite3_errstr(rc));
172 return false;
173 }
174 return true;
175}
#define NULL
Definition Config.h:312
#define __SET_ERROR_MSG(_message)
#define __SET_ERROR(_errorCode)
Definition SQLCore.cpp:149
@ eNotConnected
Definition SQLCore.h:33

◆ __commitTrans()

bool SqConnection::__commitTrans ( )
virtual

Implements SQL::Connection.

Definition at line 237 of file SqConnection.cpp.

238{
239 return __execute("COMMIT", (size_t)-1);
240}
virtual bool __execute(const char *_sql, size_t _sqllen)

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 247 of file SqConnection.cpp.

248{
249 __DCL_ASSERT(_queryHandleOut != NULL);
250
251 SQL::Query* newQuery = new SqQuery(this);
252 if (!newQuery) {
254 return false;
255 }
256
257 *_queryHandleOut = newQuery;
258 return true;
259}
#define __DCL_ASSERT(expr)
Definition Object.h:394
@ eOutOfMemory
Definition SQLCore.h:24

◆ __execute()

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

Implements SQL::Connection.

Definition at line 208 of file SqConnection.cpp.

209{
210 char* errmsg = NULL;
211 int rc = sqlite3_exec(__conn, _sql, NULL, NULL, &errmsg);
212 if (rc != SQLITE_OK) {
213 __SET_ERROR_MSG(errmsg);
214 return false;
215 }
216
217 switch(__GetStmtType(_sql)) {
218 case StmtTransBegin :
220 break;
221 case StmtTransEnd :
223 break;
224 case StmtOther :
225 default :
226 ;
227 }
228
229 return true;
230}
@ StmtTransEnd
@ StmtOther
@ StmtTransBegin
#define __UNSET_STATE(state)
Definition SQLCore.h:483
#define __SET_STATE(state)
Definition SQLCore.h:482

◆ __getErrorMessage()

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

Implements SQL::Connection.

Definition at line 261 of file SqConnection.cpp.

262{
263 __DCL_ASSERT(Connection::__errorCode == SQL::eServerError);
264 if (__lastErrorMessage.length() < *_buflen) {
265 *_buflen = __lastErrorMessage.length();
266 *(_buf + *_buflen) = '\0';
267 }
268 strncpy(_buf, __lastErrorMessage.data(), *_buflen);
269 return true;
270}
@ eServerError
Definition SQLCore.h:21

◆ __getServerInfo()

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

Implements SQL::Connection.

Definition at line 272 of file SqConnection.cpp.

273{
274 ByteStringBuilder sb = "SQLite ";
275 sb += sqlite3_libversion();
276#ifdef SQLITE_HAS_CODEC
277 sb += "/SQLCipher";
278#endif
279
280 if (sb.length() < *_buflen) {
281 *_buflen = sb.length();
282 *(_buf + *_buflen) = '\0';
283 }
284 strncpy(_buf, sb.data(), *_buflen);
285 return true;
286}

◆ __open()

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

Implements SQL::Connection.

Definition at line 69 of file SqConnection.cpp.

70{
71 ByteString conns(_conns, _connslen);
72 ListedByteStringToByteStringMap map;
73 Connection::splitConnStr(_conns, _connslen, map);
74
75 ByteString _DATABASE = map["DATABASE"];
76 ByteString _URI = map["URI"];
77#ifdef SQLITE_HAS_CODEC
78 ByteString _KEY = map["KEY"];
79 ByteString _REKEY = map["REKEY"];
80
81 const char* pKey = NULL;
82 int nKey = 0;
83 if (_KEY.length() > 0) {
84 pKey = _KEY.data();
85 nKey = _KEY.length();
86 }
87
88 bool hasReKey = conns.searches("REKEY", true);
89 const char* pReKey = NULL;
90 int nReKey = 0;
91 if (_REKEY.length() > 0) {
92 pReKey = _REKEY.data();
93 nReKey = _REKEY.length();
94 }
95#endif
96
97 int flags = SQLITE_OPEN_MEMORY;
98 const char* zVfs = NULL;
99 if (!(_DATABASE.isEmpty())) {
100 _URI = _DATABASE;
101 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
102 }
103 else if (!(_URI.isEmpty())) {
104 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
105 }
106 else if (!conns.isEmpty()) {
107 _URI = conns;
108 if (!_URI.isEmpty()) {
109 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
110 }
111 }
112 else {
113 flags = SQLITE_OPEN_MEMORY;
114 _URI.assign(":memory:");
115 }
116
117 if (_URI.toLowerCase().startsWith("file:")) {
118 flags |= SQLITE_OPEN_URI;
119 }
120
121#ifdef __WINNT__
122 zVfs = "win32-none";
123#else
124 zVfs = "unix-none";
125#endif
126
127 sqlite3* conn = NULL;
128 int rc = sqlite3_open_v2(_URI, &conn, flags, zVfs);
129 if (rc != SQLITE_OK) {
130 __SET_ERROR_MSG(sqlite3_errstr(rc));
131 return false;
132 }
133
134 for ( ; ; ) {
135#ifdef SQLITE_HAS_CODEC
136 rc = sqlite3_key(conn, pKey, nKey);
137 if (rc != SQLITE_OK) {
138 __SET_ERROR_MSG(sqlite3_errmsg(conn));
139 break;
140 }
141 __DCL_TRACE2_N(L"sqlite3_key [%hs][%d]\n",
142 (pKey ? pKey : "(nil)"), nKey);
143 if (hasReKey) {
144 rc = sqlite3_rekey(conn, pReKey, nReKey);
145 if (rc != SQLITE_OK) {
146 __SET_ERROR_MSG(sqlite3_errmsg(conn));
147 break;
148 }
149 }
150#endif
151 __conn = conn;
152 return true;
153 }
154
155 if (conn) {
156 sqlite3_close_v2(conn);
157 }
158 return false;
159}
#define __DCL_TRACE2_N(fmt, arg1, arg2)

◆ __rollbackTrans()

bool SqConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 242 of file SqConnection.cpp.

243{
244 return __execute("ROLLBACK", (size_t)-1);
245}

◆ __startTrans()

bool SqConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 232 of file SqConnection.cpp.

233{
234 return __execute("BEGIN", (size_t)-1);
235}

◆ connHandle()

sqlite3 * SqConnection::connHandle ( ) const
inline

Definition at line 39 of file SqConnection.h.

40{
41 return __conn;
42}

◆ cursor()

int SqConnection::cursor ( ) const

◆ destroy()

void SqConnection::destroy ( )
virtual

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

Implements SQL::Connection.

Definition at line 64 of file SqConnection.cpp.

65{
66 delete this;
67}

◆ setErrorMessage()

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

Definition at line 44 of file SqConnection.h.

48{
49 Connection::setErrorStatus(SQL::eServerError, _filename, _line);
50 __lastErrorMessage = _message;
51}
_PROTECTED const wchar_t * _filename
Definition SQLCore.h:439
_PROTECTED const wchar_t int _line
Definition SQLCore.h:441

◆ stmtNo()

int SqConnection::stmtNo ( )

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