DCL 3.7.4
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, Param
47 eValueIsNull, // 값이 null 이다
48 eNotSupportDataType, // 서버 혹은 드라이버에서 지원하지 않는 데이터타입이다.
49 eInvalidDataType, // 필드값을 얻거나 파라메터 값을 설정하기 위한 데이터타입이 잘못되었다.
50 eInvalidBufferSize, // 필드 혹은 아웃바인드의 값을 읽고자 하는 버퍼의 크기가 유효하지 않다.
51 // Field::getValue *_size에 필요한 버퍼의 크기를 리턴
52 eOutOfRange, // typeNumeric에서 버퍼의 데이터타입과 사이즈에 적용하는데 범위를 초과했다.
53 eBytesTruncated, // 문자열 또는 바이트 데이터가 크거나, 버퍼의 크기가 작다.
54 eInvalidData, // 수신된 데이터가 잘못되었거나, 서버에 적용하는데 실패하였다.
55 eInvalidDataSize // 데이터타입에 해당하는 데이터의 사이즈가 유효하지 않다.
56};
57
59{
60 typeUnknown = 0, // C-DataType SQL-Type
61 typeInteger, // int32_t, int64_t TINYINT, SMALLINT, INTEGER, BIGINT
62 typeUInteger, // uint32_t, uint64_t BIT, UTINYINT, USMALLINT, UINTEGER, UBIGINT
63 typeFloat, // float, double REAL, DOUBLE, FLOAT
64 typeNumeric, // INTx, UINTx, float, double, char* NUMBER, DECIMAL
65 typeDate, // SQL::Date DATE
66 typeTime, // SQL::Time TIME
67 typeTimeTz, // SQL::Time TIME WITH TIME ZONE
68 typeTimeStamp, // SQL::TimeStamp TIMESTAMP
69 typeTimeStampTz, // SQL::TimeStamp TIMESTAMP WITH TIME ZONE
70 typeInterval, // SQL::Interval
71 typeIntervalYm, // SQL::Interval INTERVAL YEAR TO SECOND
72 typeIntervalDs, // SQL::Interval INTERVAL DAY TO SECOND
73 typeText, // char* CHAR, VARCHAR,
74 typeBinary, // byte_t* BINARY, RAW
75 typeLongText, // char* LONG
76 typeLongBinary, // byte_t* LONG RAW
77 typeClob, // Clob direct accessible CLOB
78 typeBlob, // Blob direct accessible BLOB
79
80 // buffer type
81 typeInputStream, // InputStream
82 typeOutputStream // OutputStream
83};
84
85static bool getErrorMessage(
86 wchar_t* _buf, // OUT
87 size_t* _buflen, // IN OUT
88 Error _errorCode // IN
89 );
90static const wchar_t* dataTypeName(
91 DataType _dataType
92 );
93
94struct Date
95{
96 int16_t year; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
97 uint8_t month; // 1 ~ 12
98 uint8_t day; // 1 ~ 31
99};
100
101struct Time
102{
103 uint8_t hour; // 0 ~ 23
104 uint8_t min; // 0 ~ 59
105 uint8_t sec; // 0 ~ 59
106 uint32_t frac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
107 int16_t tzoff; // -720~840, GMT-12 ~ GMT+14, Time offset, Minutes
108};
109
111{
112 int16_t year; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
113 uint8_t month; // 1 ~ 12
114 uint8_t day; // 1 ~ 31
115 uint8_t hour; // 0 ~ 23
116 uint8_t min; // 0 ~ 59
117 uint8_t sec; // 0 ~ 59
118 uint32_t frac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
119 int16_t tzoff; // -720~840, GMT-12 ~ GMT+14, Time offset, Minutes
120};
121
122// INTERVAL YEAR TO MONTH : nYears ~ nMonths
123// INTERVAL DAY TO SECOND : nDays ~ nFracs
125{
126 int32_t years; // -999999999 ~ 999999999
127 int8_t months; // -11 ~ 11
128 int32_t days; // -999999999 ~ 999999999
129 int8_t hours; // -23 ~ 23
130 int8_t mins; // -59 ~ 59
131 int8_t secs; // -59 ~ 59
132 int32_t fracs; // -999999999 ~ 999999999, 1/1,000,000,000 fractional seconds
133};
134
135class Field;
136class Param;
137class Query;
138class Connection;
139
140// interface classes
141class DCLCAPI Field : public Object
142{
144public:
145 const String& name() const;
146 DataType dataType() const;
147 short precision() const;
148 short scale() const;
149 Connection* connection() const;
150
151 bool getNull(
152 size_t* _size // *_size == (size_t)-1 null
153 );
154
155 bool getDataSize(
156 size_t* _size, // count of bytes
157 bool _maxsize
158 );
159
160 bool getData(
161 void* _buf, // buffer, OUT
162 size_t* _size, // sizeof *_buf, IN OUT
163 DataType _bufType // typeof *_buf
164 );
165
166 // interfaces
167public:
168 virtual const wchar_t* serverDataTypeName() const = 0;
169
170protected:
171 Field(Query* _queryHandle);
172 virtual ~Field();
173
174 virtual bool __getDataSize(
175 size_t* _size,
176 bool _maxsize
177 ) = 0;
178
179 virtual bool __getData(
180 void* _buf,
181 size_t* _size, // IN OUT
182 DataType _bufType
183 ) = 0;
184
185protected:
187 String __name;
190 short __scale;
191};
192
193class DCLCAPI Param : public Field
194{
196public:
197 void setName(String _name);
198
199 bool setData(
200 _CONST void* _val, // data, IN
201 size_t _size, // sizeof *_val
202 DataType _valType, // typeof *_val
203 DataType _sqlType // assign to server type
204 );
205
206 // output parameter support
207 bool setOutputType(
208 DataType _sqlType
209 );
210
211 // interfaces
212 virtual void setNull() = 0;
213
214protected:
215 Param(Query* _queryHandle);
216 virtual ~Param();
217
218 virtual bool __setData(
219 _CONST void* _val, // data, IN
220 size_t _size, // sizeof *_val
221 DataType _valType, // typeof *_val
222 DataType _sqlType // assign to server type
223 ) = 0;
224
225 virtual bool __setOutputType(
226 DataType _sqlType // assign to server type
227 );
228
229 virtual bool __getDataSize(
230 size_t* _size,
231 bool _maxsize
232 );
233
234 virtual bool __getData(
235 void* _buf, // data, OUT
236 size_t* _size, // sizeof *_buf, IN OUT
237 DataType _bufType
238 );
239};
240
241class DCLCAPI Query : public Object
242{
244public:
245 bool prepare(
246 const char* _sql,
247 size_t _sqllen,
248 size_t _paramCount
249 );
250
251 bool execute();
252 bool fetch();
253 bool moreResults(bool* _moreResults);
254 bool getField(
255 size_t _index, // zero based index
256 Field** _fieldHandle // OUT
257 );
258
259 bool getParam(
260 size_t _index, // zero based index
261 Param** _paramHandle // OUT
262 );
263
264 // properties
265 bool eof() const;
266 int64_t affectedRows() const;
267 size_t fieldCount() const;
268 size_t paramCount() const;
269 wchar_t placeholder() const;
270
271 Connection* connection() const;
272 bool inState(unsigned int _state) const;
273
274 // interfaces
275protected:
276 Query(Connection* _connHandle);
277 virtual ~Query();
278
279 virtual void __destroy() = 0;
280
281 virtual bool __prepare(
282 const char* _sql,
283 size_t _sqllen,
284 size_t _paramCount
285 ) = 0;
286
287 virtual bool __execute() = 0;
288 virtual bool __fetch() = 0;
289 virtual bool __moreResults(bool* _moreResults);
290
291 virtual bool __getField(
292 size_t _index, // zero based index
293 Field** _fieldHandle // OUT
294 ) = 0;
295
296 virtual bool __getParam(
297 size_t _index, // zero based index
298 Param** _paramHandle // OUT
299 ) = 0;
300
301protected:
303 bool __eof;
304 int64_t __affectedRows; // for INSERT, UPDATE
305
308 wchar_t __placeholder; // Oracle(':') or '?'
309
310 friend class Connection;
311
312 // Object States
313protected:
314 unsigned int __states;
315
316public:
317 enum State
318 {
319 stStandBy = (unsigned int) 0x0001,
320 stPrepared = 0x0002,
321 stExecuted = 0x0004,
322 stFetched = 0x0008
323 };
324};
325
327{
329private:
330 long __refCount;
331
332public:
333 long refCount() const { return __refCount; }
334 long addRef(); // new incremented __refCount
335 long release(); // new decremented __refCount
336
337public:
338 bool open(
339 const char* _conn, // connection string, IN
340 size_t _connlen
341 );
342
343 bool close();
344 bool execute(
345 const char* _sql, // string string, IN
346 size_t _sqllen
347 );
348
349 bool startTrans();
350 bool commitTrans();
351 bool rollbackTrans();
352
353 bool getErrorMessage(
354 char* _buf, // data, OUT
355 size_t* _buflen // sizeof *_buf, IN OUT
356 );
357
358 bool getServerInfo(
359 char* _buf, // data, OUT
360 size_t* _buflen // sizeof *_buf, IN OUT
361 );
362
364 Query** _queryHandle // OUT
365 );
366
368 Query* _queryHandle // IN
369 );
370
371 // properties
372 Error errorCode() const;
373#ifdef __DCL_DEBUG
374 const wchar_t* errorFileName() const;
375 int errorLine() const;
376#endif
377 bool canTransact() const;
378 const wchar_t* serverTitle() const;
379 bool inState(unsigned int _state) const;
380
381 // interfaces
382 virtual void destroy() = 0;
383protected:
384 Connection(const wchar_t* _serverTitle);
385 virtual ~Connection();
386
387 virtual bool __open(
388 const char* _conn, // connection string
389 size_t _connlen
390 ) = 0;
391
392 virtual bool __close() = 0;
393
394 virtual bool __execute(
395 const char* _sql, // sql string
396 size_t _sqllen
397 ) = 0;
398
399 virtual bool __startTrans() = 0;
400 virtual bool __commitTrans() = 0;
401 virtual bool __rollbackTrans() = 0;
402
404 Query** _queryHandle // OUT
405 ) = 0;
406
407 virtual bool __getErrorMessage(
408 char* _buf, // OUT
409 size_t* _buflen // IN OUT
410 ) = 0;
411
412 virtual bool __getServerInfo(
413 char* _buf, // OUT
414 size_t* _buflen // IN OUT
415 ) = 0;
416
417protected:
419 const wchar_t* __serverTitle;
420
422 const wchar_t* __errorFileName;
424
425 // Object States
426 unsigned int __states;
427public:
428 enum State
429 {
430 stClosed = 0x0001,
431 stOpenned = 0x0002,
433 };
434
436 // for SQLQuery, SQLField, SQLParam, and inherited classes
437 void setErrorStatus(
438 Error _errorCode,
439 const wchar_t* _filename,
441 );
442
443 /*
444 pszConnectionString을 파싱하여 map에 저장한다.
445 pszConnectionString의 예
446 "USER NAME=aUser;PASSWORD=aPW;DATABASE NAME=aDB; SERVER NAME=aHost;"
447
448 map의 KEY는 대문자로 변환되며, KEY와 VALUE 모두 space는 trim된다.
449
450 RETUNR VALUE : map에 설정된 아이템이 개수
451 */
452 static size_t splitConnStr(
453 const char* _connstr, // connection string
454 size_t _strlen,
455 ListedByteStringToByteStringMap& _results // OUT
456 );
457};
458
460{
461 // DCL common members
462 uint32_t uSize; // structure size
463 uint32_t uDCLVersion; // DCL_CORE_VERSION
464 const wchar_t* pszBuildTimeStamp; // __BUILD_TIMESTAMP__
465 uint32_t uBuildFlag; // release(0), debug(1)
466 uint32_t uModuleType; // DCL_SQL_DRIVER_MODULE
467 const wchar_t* pszDescription; // module description
468
469 // private members
470 uint32_t uVersion; // DCL_SQL_VERSION
471 const wchar_t* pszServerTitle;
472 const wchar_t* pszFileVersion;
473 bool (*pfnInitialize)();
474 bool (*pfnCleanup)();
475 Connection* (*pfnCreateConnectionInstance)();
476};
477
478}; // class SQL
479
480//#define __SET_ERROR(_errorCode) setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
481
482#define __SET_STATE(state) __states |= state
483#define __UNSET_STATE(state) __states &= ~state
484
485#include <dcl/SQLCore.inl>
486
487__DCL_END_NAMESPACE
488
489#endif // __DCL_SQLCORE_H__
#define DCLCAPI
Definition Config.h:95
#define _CONST
Definition Config.h:325
#define _PROTECTED
Definition Config.h:327
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:227
Object()
Definition Object.cpp:183
bool commitTrans()
Definition SQLCore.cpp:758
bool __canTransact
Definition SQLCore.h:418
long refCount() const
Definition SQLCore.h:333
bool rollbackTrans()
Definition SQLCore.cpp:777
virtual bool __getErrorMessage(char *_buf, size_t *_buflen)=0
virtual bool __open(const char *_conn, size_t _connlen)=0
virtual bool __getServerInfo(char *_buf, size_t *_buflen)=0
const wchar_t * serverTitle() const
Definition SQLCore.inl:94
static size_t splitConnStr(const char *_connstr, size_t _strlen, ListedByteStringToByteStringMap &_results)
Definition SQLCore.cpp:862
virtual void destroy()=0
bool startTrans()
Definition SQLCore.cpp:739
virtual bool __startTrans()=0
virtual bool __execute(const char *_sql, size_t _sqllen)=0
const wchar_t * __serverTitle
Definition SQLCore.h:419
bool createQueryInstance(Query **_queryHandle)
Definition SQLCore.cpp:823
bool execute(const char *_sql, size_t _sqllen)
Definition SQLCore.cpp:724
_PROTECTED const wchar_t * _filename
Definition SQLCore.h:439
unsigned int __states
Definition SQLCore.h:426
Connection(const wchar_t *_serverTitle)
Definition SQLCore.cpp:665
bool canTransact() const
Definition SQLCore.inl:89
bool destroyQueryInstance(Query *_queryHandle)
Definition SQLCore.cpp:841
bool open(const char *_conn, size_t _connlen)
Definition SQLCore.cpp:686
virtual bool __commitTrans()=0
Error __errorCode
Definition SQLCore.h:421
bool getErrorMessage(char *_buf, size_t *_buflen)
Definition SQLCore.cpp:796
virtual bool __createQueryInstance(Query **_queryHandle)=0
Error errorCode() const
Definition SQLCore.inl:72
virtual bool __close()=0
virtual bool __rollbackTrans()=0
_PROTECTED const wchar_t int _line
Definition SQLCore.h:441
bool inState(unsigned int _state) const
Definition SQLCore.inl:99
const wchar_t * __errorFileName
Definition SQLCore.h:422
bool getServerInfo(char *_buf, size_t *_buflen)
Definition SQLCore.cpp:807
Query * __queryHandle
Definition SQLCore.h:186
DataType __dataType
Definition SQLCore.h:188
virtual bool __getDataSize(size_t *_size, bool _maxsize)=0
virtual const wchar_t * serverDataTypeName() const =0
Field(Query *_queryHandle)
short __precision
Definition SQLCore.h:189
virtual bool __getData(void *_buf, size_t *_size, DataType _bufType)=0
short __scale
Definition SQLCore.h:190
String __name
Definition SQLCore.h:187
virtual bool __setData(_CONST void *_val, size_t _size, DataType _valType, DataType _sqlType)=0
virtual bool __setOutputType(DataType _sqlType)
Definition SQLCore.cpp:481
Param(Query *_queryHandle)
virtual bool __getData(void *_buf, size_t *_size, DataType _bufType)
Definition SQLCore.cpp:498
virtual bool __getDataSize(size_t *_size, bool _maxsize)
Definition SQLCore.cpp:489
virtual bool __getField(size_t _index, Field **_fieldHandle)=0
unsigned int __states
Definition SQLCore.h:314
Connection * __connHandle
Definition SQLCore.h:302
virtual void __destroy()=0
friend class Connection
Definition SQLCore.h:310
Query(Connection *_connHandle)
size_t __paramCount
Definition SQLCore.h:307
virtual bool __execute()=0
wchar_t __placeholder
Definition SQLCore.h:308
virtual bool __getParam(size_t _index, Param **_paramHandle)=0
virtual bool __moreResults(bool *_moreResults)
Definition SQLCore.cpp:582
virtual bool __prepare(const char *_sql, size_t _sqllen, size_t _paramCount)=0
virtual bool __fetch()=0
bool __eof
Definition SQLCore.h:303
size_t __fieldCount
Definition SQLCore.h:306
int64_t __affectedRows
Definition SQLCore.h:304
Definition SQLCore.h:15
DataType
Definition SQLCore.h:59
@ typeBinary
Definition SQLCore.h:74
@ typeClob
Definition SQLCore.h:77
@ typeNumeric
Definition SQLCore.h:64
@ typeTime
Definition SQLCore.h:66
@ typeLongBinary
Definition SQLCore.h:76
@ typeUInteger
Definition SQLCore.h:62
@ typeUnknown
Definition SQLCore.h:60
@ typeTimeStamp
Definition SQLCore.h:68
@ typeBlob
Definition SQLCore.h:78
@ typeInputStream
Definition SQLCore.h:81
@ typeTimeStampTz
Definition SQLCore.h:69
@ typeInterval
Definition SQLCore.h:70
@ typeIntervalDs
Definition SQLCore.h:72
@ typeDate
Definition SQLCore.h:65
@ typeOutputStream
Definition SQLCore.h:82
@ typeText
Definition SQLCore.h:73
@ typeTimeTz
Definition SQLCore.h:67
@ typeFloat
Definition SQLCore.h:63
@ typeInteger
Definition SQLCore.h:61
@ typeIntervalYm
Definition SQLCore.h:71
@ typeLongText
Definition SQLCore.h:75
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:54
@ eInvalidConnectionString
Definition SQLCore.h:31
@ eNotSupportDataType
Definition SQLCore.h:48
@ eInvalidIndex
Definition SQLCore.h:44
@ eServerError
Definition SQLCore.h:21
@ eInvalidDataSize
Definition SQLCore.h:55
@ 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
@ eBytesTruncated
Definition SQLCore.h:53
@ eNoChildQuery
Definition SQLCore.h:37
const wchar_t * pszBuildTimeStamp
Definition SQLCore.h:464
bool(* pfnCleanup)()
Definition SQLCore.h:474
uint32_t uDCLVersion
Definition SQLCore.h:463
uint32_t uBuildFlag
Definition SQLCore.h:465
const wchar_t * pszFileVersion
Definition SQLCore.h:472
const wchar_t * pszDescription
Definition SQLCore.h:467
uint32_t uModuleType
Definition SQLCore.h:466
uint32_t uVersion
Definition SQLCore.h:470
bool(* pfnInitialize)()
Definition SQLCore.h:473
const wchar_t * pszServerTitle
Definition SQLCore.h:471
int16_t year
Definition SQLCore.h:96
uint8_t month
Definition SQLCore.h:97
uint8_t day
Definition SQLCore.h:98
int32_t years
Definition SQLCore.h:126
int32_t days
Definition SQLCore.h:128
int8_t hours
Definition SQLCore.h:129
int8_t mins
Definition SQLCore.h:130
int32_t fracs
Definition SQLCore.h:132
int8_t months
Definition SQLCore.h:127
int8_t secs
Definition SQLCore.h:131
uint8_t hour
Definition SQLCore.h:103
uint8_t sec
Definition SQLCore.h:105
uint32_t frac
Definition SQLCore.h:106
uint8_t min
Definition SQLCore.h:104
int16_t tzoff
Definition SQLCore.h:107
uint32_t frac
Definition SQLCore.h:118
int16_t tzoff
Definition SQLCore.h:119
uint8_t min
Definition SQLCore.h:116
uint8_t sec
Definition SQLCore.h:117
uint8_t hour
Definition SQLCore.h:115
uint8_t day
Definition SQLCore.h:114
int16_t year
Definition SQLCore.h:112
uint8_t month
Definition SQLCore.h:113