DCL 4.0
Loading...
Searching...
No Matches
SQLCore.h
Go to the documentation of this file.
1#ifndef __DCL_SQLCORE_H__
2#define __DCL_SQLCORE_H__ 20050322
3
4#ifndef __DCL_OBJECT_H__
5#include <dcl/Object.h>
6#endif
7
8#ifndef __DCL_LISTED_HASH_MAP_H__
9#include <dcl/ListedHashMap.h>
10#endif
11
12__DCL_BEGIN_NAMESPACE
13
15{
16public:
17
19{
21 eServerError, // 서버 혹은 서버 API 호출 에러이다.
22
23 eBadAddress, // 버퍼 혹은 파라메터의 주소가 잘못되었다.
24 eOutOfMemory, // 메모리 할당이 불가능 하다.
25 eNotSupportMethod, // 서버 혹은 드라이버에서 지원하지 않는 메소드 입니다.
26
27 // Connection, Query
29
30 // Connection Errors
32 eConnected, // Connection이 이미 연결되었다.
33 eNotConnected, // 먼저 Connection::open을 호출해야 한다.
34 eInTransaction, // 이미 트랜잭션이 시작되었다.
35 eNotInTransaction, // 트랜잭션 상태가 아니다.
36 eHaveChildQuery, // 이 연결을 사용하는 Query가 있다.
37 eNoChildQuery, // 파괴하려는 Query는 다른곳에서 생성되었다.
38 eNotAvailable, // 값을 얻을 수 없다. for geServerInfo
39
40 // Query Errors
41 eNotPrepared, // 먼저 Query::prepare 를 호출해야 한다.
42 eNotExecuted, // 먼저 Query::execute 를 호출해야 한다.
43 eNotFetched, // 먼저 Query::fetch 를 호출해야 한다.
44 eInvalidIndex, // Field나 Param을 참조하는 잘못된 Index값이다.
45
46 // Field
47 eValueIsNull, // 값이 null 이다
48 eNotSupportDataType, // 서버 혹은 드라이버에서 지원하지 않는 데이터타입이다.
49 eInvalidDataType, // 필드값을 얻거나 파라메터 값을 설정하기 위한 데이터타입이 잘못되었다.
50 eInvalidBufferSize, // 필드 혹은 아웃바인드의 값을 읽고자 하는 버퍼의 크기가 유효하지 않다.
51 // Field::getValue *_pn에 필요한 버퍼의 크기를 리턴
52 eOutOfRange, // typeNumeric에서 버퍼의 데이터타입과 사이즈에 적용하는데 범위를 초과했다.
53
54 // Param
55 eInvalidData, // Param::setData, 잘못된 데이터이다.
56 // 서버API로의 데이터 변환에 실패하였다.
57 eInvalidDataSize // 데이터타입에 해당하는 데이터의 사이즈가 유효하지 않다.
58 // for SQLParam::setValue
59};
60
62{
63 typeUnknown = 0, // C-DataType SQL-Type
64 typeInteger, // int32_t, int64_t TINYINT, SMALLINT, INTEGER, BIGINT
65 typeUInteger, // uint32_t, uint64_t BIT, UTINYINT, USMALLINT, UINTEGER, UBIGINT
66 typeFloat, // float, double REAL, DOUBLE, FLOAT
67 typeNumeric, // INTx, UINTx, float, double, char* NUMBER, DECIMAL
68 typeDate, // SQL::Date DATE
69 typeTime, // SQL::Time TIME
70 typeTimeStamp, // SQL::TimeStamp TIMESTAMP
71 typeTimeStampTz, // SQL::TimeStamp TIMESTAMP WITH TIMEZONE, Oracle 9 Only
72 typeInterval, // SQL::Interval
73 typeIntervalYm, // SQL::Interval INTERVAL YEAR TO SECOND, Oracle 9 Only
74 typeIntervalDs, // SQL::Interval INTERVAL DAY TO SECOND
75 typeText, // char* CHAR, VARCHAR,
76 typeBinary, // byte_t* BINARY, RAW
77 typeLongText, // char* LONG
78 typeLongBinary, // byte_t* LONG RAW
79 typeClob, // Clob direct accessible CLOB
80 typeBlob, // Blob direct accessible BLOB
81
82 // buffer type
83 typeInputStream, // InputStream
84 typeOutputStream // OutputStream
85};
86
87static bool getErrorMessage(
88 wchar_t* _buf, // OUT
89 size_t* _buflen, // IN, OUT
90 Error _errorCode // IN
91 );
92static const wchar_t* dataTypeName(DataType _dataType);
93
94struct Date
95{
96 int16_t nYear; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
97 uint8_t nMonth; // 1 ~ 12
98 uint8_t nDay; // 1 ~ 31
99};
100
101struct Time
102{
103 uint8_t nHour; // 0 ~ 23
104 uint8_t nMin; // 0 ~ 59
105 uint8_t nSec; // 0 ~ 59
106 uint32_t nFrac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
107};
108
110{
111 int16_t nYear; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
112 uint8_t nMonth; // 1 ~ 12
113 uint8_t nDay; // 1 ~ 31
114 uint8_t nHour; // 0 ~ 23
115 uint8_t nMin; // 0 ~ 59
116 uint8_t nSec; // 0 ~ 59
117 uint32_t nFrac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
118 int16_t nTzMin; // -720~840, GMT-12 ~ GMT+14, Minutes east of UTC
119};
120
121// INTERVAL YEAR TO MONTH : nYears ~ nMonths
122// INTERVAL DAY TO SECOND : nDays ~ nFracs
124{
125 int32_t nYears; // -999999999 ~ 999999999
126 int8_t nMonths; // -11 ~ 11
127 int32_t nDays; // -999999999 ~ 999999999
128 int8_t nHours; // -23 ~ 23
129 int8_t nMins; // -59 ~ 59
130 int8_t nSecs; // -59 ~ 59
131 int32_t nFracs; // -999999999 ~ 999999999, 1/1,000,000,000 fractional seconds
132};
133
134class Field;
135class Param;
136class Query;
137class Connection;
138
139// interface classes
140class DCLCAPI Field : public Object
141{
143public:
144 const String& name() const;
145 DataType dataType() const;
146 short precision() const;
147 short scale() const;
148 Connection* connection() const;
149
150 bool getDataSize(
151 size_t* _pn, // count of bytes
152 bool _maxSize
153 );
154
155 bool getData(
156 void* _pv, // buffer, OUT
157 size_t* _pn, // sizeof *_pv, IN, OUT
158 DataType _dataType // typeof *_pv
159 );
160
161 // interfaces
162public:
163 virtual bool isNull() const = 0;
164 virtual const wchar_t* serverDataTypeName() const = 0;
165
166protected:
167 Field(Query* _queryHandle);
168 virtual ~Field();
169
170 virtual bool __getDataSize(
171 size_t* _pn,
172 bool _maxSize
173 ) = 0;
174
175 virtual bool __getData(
176 void* _pv,
177 size_t* _pn, // IN, OUT
178 DataType _dataType
179 ) = 0;
180
181protected:
183 String __name;
186 short __scale;
187};
188
189class DCLCAPI Param : public Field
190{
192public:
193 void setName(String _name);
194
195 bool setData(
196 _CONST void* _pv, // data, IN
197 size_t _n, // sizeof *_pv
198 DataType _dataType, // typeof *_pv
199 DataType _assignType // assign to server type
200 );
201
202 // out param support
203 bool setDataType(
204 DataType _dataType
205 );
206
207 // interfaces
208 virtual void setNull() = 0;
209
210protected:
211 Param(Query* _queryHandle);
212 virtual ~Param();
213
214 virtual bool __setData(
215 _CONST void* _pv,
216 size_t _n,
217 DataType _dataType,
218 DataType _assignType
219 ) = 0;
220
221 // out param support
222 virtual bool isNull() const;
223
224 virtual bool __setDataType(
225 DataType _dataType
226 );
227
228 virtual bool __getDataSize(
229 size_t* _pn,
230 bool _maxSize
231 );
232
233 virtual bool __getData(
234 void* _pv,
235 size_t* _pn, // IN, OUT
236 DataType _dataType
237 );
238};
239
240class DCLCAPI Query : public Object
241{
243public:
244 bool prepare(const char* _sql, size_t _sqllen,
245 size_t _paramCount);
246 bool execute();
247 bool fetch();
248 bool nextResult();
249 bool getField(
250 size_t _index, // zero based index
251 Field** _fieldHandleOut // OUT
252 );
253
254 bool getParam(
255 size_t _index, // zero based index
256 Param** _paramHandleOut // OUT
257 );
258
259 // properties
260 bool eof() const;
261 int64_t affectedRows() const;
262 size_t fieldCount() const;
263 size_t paramCount() const;
264 wchar_t placeholder() const;
265
266 Connection* connection() const;
267 bool inState(unsigned int _state) const;
268
269 // interfaces
270protected:
271 Query(Connection* _connHandle);
272 virtual ~Query();
273
274 virtual void __destroy() = 0;
275 virtual bool __prepare(const char* _sql, size_t _sqllen,
276 size_t _paramCount) = 0;
277 virtual bool __execute() = 0;
278 virtual bool __fetch() = 0;
279 virtual bool __nextResult();
280
281 virtual bool __getField(size_t _index, Field** _fieldHandleOut) = 0;
282 virtual bool __getParam(size_t _index, Param** _paramHandleOut) = 0;
283
284protected:
286 bool __eof;
287 int64_t __affectedRows; // for INSERT, UPDATE
288
291 wchar_t __placeholder; // Oracle(':') or '?'
292
293 friend class Connection;
294
295 // Object States
296protected:
297 unsigned int __states;
298
299public:
300 enum State
301 {
302 stStandBy = 0x0001,
303 stPrepared = 0x0002,
304 stExecuted = 0x0004,
305 stFetched = 0x0008
306 };
307};
308
310{
312private:
313 long __refCount;
314
315public:
316 long refCount() const { return __refCount; }
317 long addRef(); // new incremented __refCount
318 long release(); // new decremented __refCount
319
320public:
321 bool open(const char* _connString, size_t _connlen);
322 bool close();
323 bool execute(const char* _sql, size_t _sqllen);
324
325 bool startTrans();
326 bool commitTrans();
327 bool rollbackTrans();
328
329 bool getErrorMessage(
330 char* _pbuf,
331 size_t* _pn // IN, OUT
332 );
333
334 bool getServerInfo(
335 char* _pbuf,
336 size_t* _pn // IN, OUT
337 );
338
339 bool createQueryInstance(Query** _queryHandleOut);
340 bool destroyQueryInstance(Query* _queryHandle);
341
342 // properties
343 Error errorCode() const;
344#if __DCL_DEBUG
345 const wchar_t* errorFileName() const;
346 int errorLine() const;
347#endif
348 bool canTransact() const;
349 const wchar_t* serverTitle() const;
350 bool inState(unsigned int uState) const;
351
352 // interfaces
353 virtual void destroy() = 0;
354protected:
355 Connection(const wchar_t* _serverTitle);
356 virtual ~Connection();
357
358 virtual bool __open(const char* _connString, size_t _connlen) = 0;
359 virtual bool __close() = 0;
360 virtual bool __execute(const char* _sql, size_t _sqllen) = 0;
361
362 virtual bool __startTrans() = 0;
363 virtual bool __commitTrans() = 0;
364 virtual bool __rollbackTrans() = 0;
365
366 virtual bool __createQueryInstance(Query** _queryHandleOut) = 0;
367 virtual bool __getErrorMessage(char* _buf, size_t* _buflen) = 0;
368 virtual bool __getServerInfo(char* _buf, size_t* _buflen) = 0;
369
370protected:
372 const wchar_t* __serverTitle;
373
375 const wchar_t* __errorFileName;
377
378 // Object States
379 unsigned int __states;
380public:
381 enum State
382 {
383 stClosed = 0x0001,
384 stOpenned = 0x0002,
386 };
387
389 // for SQLQuery, SQLField, SQLParam, and inherited classes
390 void setErrorStatus(Error _errorCode, const wchar_t* _filename, int _line);
391
392 /*
393 pszConnectionString을 파싱하여 map에 저장한다.
394 pszConnectionString의 예
395 "USER NAME=aUser;PASSWORD=aPW;DATABASE NAME=aDB; SERVER NAME=aHost;"
396
397 map의 KEY는 대문자로 변환되며, KEY와 VALUE 모두 space는 trim된다.
398
399 RETUNR VALUE : map에 설정된 아이템이 개수
400 */
401 static size_t splitConnectionString(
402 const char* _connString, size_t _strlen,
403 ListedByteStringToByteStringMap& _map
404 );
405};
406
408{
409 // DCL common members
410 uint32_t uSize; // structure size
411 uint32_t uDCLVersion; // DCL_VERSION
412 const wchar_t* pszBuildTimeStamp; // __TIMESTAMP__
413 uint32_t uBuildFlag; // release(0), debug(1)
414 uint32_t uModuleType; // DCL_SQL_DRIVER_MODULE
415 const wchar_t* pszDescription; // module description
416
417 // private members
418 uint32_t uVersion; // DCL_SQL_VERSION
419 const wchar_t* pszServerTitle;
420 const wchar_t* pszFileVersion;
421 bool (*pfnInitialize)();
422 bool (*pfnCleanup)();
423 Connection* (*pfnCreateConnectionInstance)();
424};
425
426}; // class SQL
427
428//#define __SET_ERROR(_errorCode) setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
429
430#define __SET_STATE(state) __states |= state
431#define __UNSET_STATE(state) __states &= ~state
432
433#include <dcl/SQLCore.inl>
434
435__DCL_END_NAMESPACE
436
437#endif // __DCL_SQLCORE_H__
#define DCLCAPI
Definition Config.h:100
#define __PROTECTED
Definition Config.h:355
#define _CONST
Definition Config.h:353
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
buf release()
void CharsetConvertException * execute()
Object()
Definition Object.cpp:183
bool commitTrans()
Definition SQLCore.cpp:738
bool __canTransact
Definition SQLCore.h:371
virtual bool __createQueryInstance(Query **_queryHandleOut)=0
long refCount() const
Definition SQLCore.h:316
bool rollbackTrans()
Definition SQLCore.cpp:757
virtual bool __getErrorMessage(char *_buf, size_t *_buflen)=0
virtual bool __getServerInfo(char *_buf, size_t *_buflen)=0
const wchar_t * serverTitle() const
Definition SQLCore.inl:94
virtual void destroy()=0
bool startTrans()
Definition SQLCore.cpp:719
virtual bool __startTrans()=0
virtual bool __execute(const char *_sql, size_t _sqllen)=0
const wchar_t * __serverTitle
Definition SQLCore.h:372
bool open(const char *_connString, size_t _connlen)
Definition SQLCore.cpp:672
unsigned int __states
Definition SQLCore.h:379
bool getErrorMessage(char *_pbuf, size_t *_pn)
Definition SQLCore.cpp:776
bool getServerInfo(char *_pbuf, size_t *_pn)
Definition SQLCore.cpp:784
Connection(const wchar_t *_serverTitle)
Definition SQLCore.cpp:653
bool canTransact() const
Definition SQLCore.inl:89
bool inState(unsigned int uState) const
Definition SQLCore.inl:99
bool destroyQueryInstance(Query *_queryHandle)
Definition SQLCore.cpp:813
virtual bool __commitTrans()=0
bool createQueryInstance(Query **_queryHandleOut)
Definition SQLCore.cpp:797
static size_t splitConnectionString(const char *_connString, size_t _strlen, ListedByteStringToByteStringMap &_map)
Definition SQLCore.cpp:832
Error __errorCode
Definition SQLCore.h:374
__PROTECTED const wchar_t int _line
Definition SQLCore.h:390
Error errorCode() const
Definition SQLCore.inl:72
virtual bool __close()=0
virtual bool __rollbackTrans()=0
const wchar_t * __errorFileName
Definition SQLCore.h:375
virtual bool __open(const char *_connString, size_t _connlen)=0
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:390
Query * __queryHandle
Definition SQLCore.h:182
DataType __dataType
Definition SQLCore.h:184
virtual const wchar_t * serverDataTypeName() const =0
Field(Query *_queryHandle)
short __precision
Definition SQLCore.h:185
short __scale
Definition SQLCore.h:186
String __name
Definition SQLCore.h:183
virtual bool __getDataSize(size_t *_pn, bool _maxSize)=0
virtual bool __getData(void *_pv, size_t *_pn, DataType _dataType)=0
virtual bool isNull() const =0
virtual bool __getData(void *_pv, size_t *_pn, DataType _dataType)
Definition SQLCore.cpp:500
virtual bool __getDataSize(size_t *_pn, bool _maxSize)
Definition SQLCore.cpp:491
virtual bool __setData(_CONST void *_pv, size_t _n, DataType _dataType, DataType _assignType)=0
Param(Query *_queryHandle)
virtual bool isNull() const
Definition SQLCore.cpp:478
virtual bool __setDataType(DataType _dataType)
Definition SQLCore.cpp:483
unsigned int __states
Definition SQLCore.h:297
Connection * __connHandle
Definition SQLCore.h:285
virtual void __destroy()=0
virtual bool __getParam(size_t _index, Param **_paramHandleOut)=0
friend class Connection
Definition SQLCore.h:293
Query(Connection *_connHandle)
size_t __paramCount
Definition SQLCore.h:290
virtual bool __execute()=0
virtual bool __nextResult()
Definition SQLCore.cpp:579
wchar_t __placeholder
Definition SQLCore.h:291
virtual bool __prepare(const char *_sql, size_t _sqllen, size_t _paramCount)=0
virtual bool __fetch()=0
bool __eof
Definition SQLCore.h:286
virtual bool __getField(size_t _index, Field **_fieldHandleOut)=0
size_t __fieldCount
Definition SQLCore.h:289
int64_t __affectedRows
Definition SQLCore.h:287
Definition SQLCore.h:15
DataType
Definition SQLCore.h:62
@ typeBinary
Definition SQLCore.h:76
@ typeClob
Definition SQLCore.h:79
@ typeNumeric
Definition SQLCore.h:67
@ typeTime
Definition SQLCore.h:69
@ typeLongBinary
Definition SQLCore.h:78
@ typeUInteger
Definition SQLCore.h:65
@ typeUnknown
Definition SQLCore.h:63
@ typeTimeStamp
Definition SQLCore.h:70
@ typeBlob
Definition SQLCore.h:80
@ typeInputStream
Definition SQLCore.h:83
@ typeTimeStampTz
Definition SQLCore.h:71
@ typeInterval
Definition SQLCore.h:72
@ typeIntervalDs
Definition SQLCore.h:74
@ typeDate
Definition SQLCore.h:68
@ typeOutputStream
Definition SQLCore.h:84
@ typeText
Definition SQLCore.h:75
@ typeFloat
Definition SQLCore.h:66
@ typeInteger
Definition SQLCore.h:64
@ typeIntervalYm
Definition SQLCore.h:73
@ typeLongText
Definition SQLCore.h:77
Error
Definition SQLCore.h:19
@ eOutOfRange
Definition SQLCore.h:52
@ eNotSupportStatement
Definition SQLCore.h:28
@ eOutOfMemory
Definition SQLCore.h:24
@ eNotExecuted
Definition SQLCore.h:42
@ eInvalidBufferSize
Definition SQLCore.h:50
@ eInvalidData
Definition SQLCore.h:55
@ eInvalidConnectionString
Definition SQLCore.h:31
@ eNotSupportDataType
Definition SQLCore.h:48
@ eInvalidIndex
Definition SQLCore.h:44
@ eServerError
Definition SQLCore.h:21
@ eInvalidDataSize
Definition SQLCore.h:57
@ eBadAddress
Definition SQLCore.h:23
@ eInvalidDataType
Definition SQLCore.h:49
@ eNotFetched
Definition SQLCore.h:43
@ eNotConnected
Definition SQLCore.h:33
@ eConnected
Definition SQLCore.h:32
@ eNotInTransaction
Definition SQLCore.h:35
@ eNotSupportMethod
Definition SQLCore.h:25
@ eValueIsNull
Definition SQLCore.h:47
@ eInTransaction
Definition SQLCore.h:34
@ eNotAvailable
Definition SQLCore.h:38
@ eNotPrepared
Definition SQLCore.h:41
@ eHaveChildQuery
Definition SQLCore.h:36
@ eNoError
Definition SQLCore.h:20
@ eNoChildQuery
Definition SQLCore.h:37
const wchar_t * pszBuildTimeStamp
Definition SQLCore.h:412
bool(* pfnCleanup)()
Definition SQLCore.h:422
uint32_t uDCLVersion
Definition SQLCore.h:411
uint32_t uBuildFlag
Definition SQLCore.h:413
const wchar_t * pszFileVersion
Definition SQLCore.h:420
const wchar_t * pszDescription
Definition SQLCore.h:415
uint32_t uModuleType
Definition SQLCore.h:414
uint32_t uVersion
Definition SQLCore.h:418
bool(* pfnInitialize)()
Definition SQLCore.h:421
const wchar_t * pszServerTitle
Definition SQLCore.h:419
uint8_t nMonth
Definition SQLCore.h:97
int16_t nYear
Definition SQLCore.h:96
uint8_t nDay
Definition SQLCore.h:98
int8_t nHours
Definition SQLCore.h:128
int32_t nFracs
Definition SQLCore.h:131
int8_t nSecs
Definition SQLCore.h:130
int8_t nMins
Definition SQLCore.h:129
int32_t nYears
Definition SQLCore.h:125
int8_t nMonths
Definition SQLCore.h:126
int32_t nDays
Definition SQLCore.h:127
uint8_t nHour
Definition SQLCore.h:103
uint8_t nMin
Definition SQLCore.h:104
uint8_t nSec
Definition SQLCore.h:105
uint32_t nFrac
Definition SQLCore.h:106
int16_t nYear
Definition SQLCore.h:111
uint8_t nDay
Definition SQLCore.h:113
uint8_t nHour
Definition SQLCore.h:114
int16_t nTzMin
Definition SQLCore.h:118
uint8_t nSec
Definition SQLCore.h:116
uint8_t nMonth
Definition SQLCore.h:112
uint8_t nMin
Definition SQLCore.h:115
uint32_t nFrac
Definition SQLCore.h:117