DCL 3.7.6
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 60 of file SqConnection.cpp.

61{
62 if (__conn) {
63 __DCL_TRACE0_N(L"Warning!! The connection was not closed\n");
64 close();
65 }
66}
#define __DCL_TRACE0_N(fmt)

Member Function Documentation

◆ __close()

bool SqConnection::__close ( )
virtual

Implements SQL::Connection.

Definition at line 165 of file SqConnection.cpp.

166{
167 if (!__conn) {
169 return false;
170 }
171
172 int rc = sqlite3_close_v2(__conn);
173 __conn = NULL;
174 if (rc != SQLITE_OK) {
175 __SET_ERROR_MSG(sqlite3_errstr(rc));
176 return false;
177 }
178 return true;
179}
#define NULL
Definition Config.h:316
#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 241 of file SqConnection.cpp.

242{
243 return __execute("COMMIT", (size_t)-1);
244}
virtual bool __execute(const char *_sql, size_t _sqllen)

◆ __createQueryInstance()

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

Implements SQL::Connection.

Definition at line 251 of file SqConnection.cpp.

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

◆ __execute()

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

Implements SQL::Connection.

Definition at line 212 of file SqConnection.cpp.

213{
214 char* errmsg = NULL;
215 int rc = sqlite3_exec(__conn, _sql, NULL, NULL, &errmsg);
216 if (rc != SQLITE_OK) {
217 __SET_ERROR_MSG(errmsg);
218 return false;
219 }
220
221 switch(__GetStmtType(_sql)) {
222 case StmtTransBegin :
224 break;
225 case StmtTransEnd :
227 break;
228 case StmtOther :
229 default :
230 ;
231 }
232
233 return true;
234}
@ 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 265 of file SqConnection.cpp.

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

◆ __getServerInfo()

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

Implements SQL::Connection.

Definition at line 276 of file SqConnection.cpp.

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

◆ __open()

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

Implements SQL::Connection.

Definition at line 73 of file SqConnection.cpp.

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

◆ __rollbackTrans()

bool SqConnection::__rollbackTrans ( )
virtual

Implements SQL::Connection.

Definition at line 246 of file SqConnection.cpp.

247{
248 return __execute("ROLLBACK", (size_t)-1);
249}

◆ __startTrans()

bool SqConnection::__startTrans ( )
virtual

Implements SQL::Connection.

Definition at line 236 of file SqConnection.cpp.

237{
238 return __execute("BEGIN", (size_t)-1);
239}

◆ 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 68 of file SqConnection.cpp.

69{
70 delete this;
71}

◆ 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: