DCL 4.1
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 typeTimeTz, // SQL::Time TIME WITH TIME ZONE
71 typeTimeStamp, // SQL::TimeStamp TIMESTAMP
72 typeTimeStampTz, // SQL::TimeStamp TIMESTAMP WITH TIME ZONE
73 typeInterval, // SQL::Interval
74 typeIntervalYm, // SQL::Interval INTERVAL YEAR TO SECOND
75 typeIntervalDs, // SQL::Interval INTERVAL DAY TO SECOND
76 typeText, // char* CHAR, VARCHAR,
77 typeBinary, // byte_t* BINARY, RAW
78 typeLongText, // char* LONG
79 typeLongBinary, // byte_t* LONG RAW
80 typeClob, // Clob direct accessible CLOB
81 typeBlob, // Blob direct accessible BLOB
82
83 // buffer type
84 typeInputStream, // InputStream
85 typeOutputStream // OutputStream
86};
87
88static bool getErrorMessage(
89 wchar_t* _buf, // OUT
90 size_t* _buflen, // IN, OUT
91 Error _errorCode // IN
92 );
93static const wchar_t* dataTypeName(DataType _dataType);
94
95struct Date
96{
97 int16_t year; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
98 uint8_t month; // 1 ~ 12
99 uint8_t day; // 1 ~ 31
100};
101
102struct Time
103{
104 uint8_t hour; // 0 ~ 23
105 uint8_t min; // 0 ~ 59
106 uint8_t sec; // 0 ~ 59
107 uint32_t frac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
108 int16_t tzoff; // -720~840, GMT-12 ~ GMT+14, Time offset, Minutes
109};
110
112{
113 int16_t year; // 1 ~ 9999, -4712 ~ 9999, DBMS dependent
114 uint8_t month; // 1 ~ 12
115 uint8_t day; // 1 ~ 31
116 uint8_t hour; // 0 ~ 23
117 uint8_t min; // 0 ~ 59
118 uint8_t sec; // 0 ~ 59
119 uint32_t frac; // 0 ~ 999999999, 1/1,000,000,000 fractional seconds
120 int16_t tzoff; // -720~840, GMT-12 ~ GMT+14, Time offset, Minutes
121};
122
123// INTERVAL YEAR TO MONTH : nYears ~ nMonths
124// INTERVAL DAY TO SECOND : nDays ~ nFracs
126{
127 int32_t years; // -999999999 ~ 999999999
128 int8_t months; // -11 ~ 11
129 int32_t days; // -999999999 ~ 999999999
130 int8_t hours; // -23 ~ 23
131 int8_t mins; // -59 ~ 59
132 int8_t secs; // -59 ~ 59
133 int32_t fracs; // -999999999 ~ 999999999, 1/1,000,000,000 fractional seconds
134};
135
136class Field;
137class Param;
138class Query;
139class Connection;
140
141// interface classes
142class DCLCAPI Field : public Object
143{
145public:
146 const String& name() const;
147 DataType dataType() const;
148 short precision() const;
149 short scale() const;
150 Connection* connection() const;
151
152 bool getDataSize(
153 size_t* _pn, // count of bytes
154 bool _maxSize
155 );
156
157 bool getData(
158 void* _pv, // buffer, OUT
159 size_t* _pn, // sizeof *_pv, IN, OUT
160 DataType _dataType // typeof *_pv
161 );
162
163 // interfaces
164public:
165 virtual bool isNull() const = 0;
166 virtual const wchar_t* serverDataTypeName() const = 0;
167
168protected:
169 Field(Query* _queryHandle);
170 virtual ~Field();
171
172 virtual bool __getDataSize(
173 size_t* _pn,
174 bool _maxSize
175 ) = 0;
176
177 virtual bool __getData(
178 void* _pv,
179 size_t* _pn, // IN, OUT
180 DataType _dataType
181 ) = 0;
182
183protected:
185 String __name;
188 short __scale;
189};
190
191class DCLCAPI Param : public Field
192{
194public:
195 void setName(String _name);
196
197 bool setData(
198 _CONST void* _pv, // data, IN
199 size_t _n, // sizeof *_pv
200 DataType _dataType, // typeof *_pv
201 DataType _assignType // assign to server type
202 );
203
204 // out param support
205 bool setDataType(
206 DataType _dataType
207 );
208
209 // interfaces
210 virtual void setNull() = 0;
211
212protected:
213 Param(Query* _queryHandle);
214 virtual ~Param();
215
216 virtual bool __setData(
217 _CONST void* _pv,
218 size_t _n,
219 DataType _dataType,
220 DataType _assignType
221 ) = 0;
222
223 // out param support
224 virtual bool isNull() const;
225
226 virtual bool __setDataType(
227 DataType _dataType
228 );
229
230 virtual bool __getDataSize(
231 size_t* _pn,
232 bool _maxSize
233 );
234
235 virtual bool __getData(
236 void* _pv,
237 size_t* _pn, // IN, OUT
238 DataType _dataType
239 );
240};
241
242class DCLCAPI Query : public Object
243{
245public:
246 bool prepare(const char* _sql, size_t _sqllen,
247 size_t _paramCount);
248 bool execute();
249 bool fetch();
250 bool nextResult();
251 bool getField(
252 size_t _index, // zero based index
253 Field** _fieldHandleOut // OUT
254 );
255
256 bool getParam(
257 size_t _index, // zero based index
258 Param** _paramHandleOut // OUT
259 );
260
261 // properties
262 bool eof() const;
263 int64_t affectedRows() const;
264 size_t fieldCount() const;
265 size_t paramCount() const;
266 wchar_t placeholder() const;
267
268 Connection* connection() const;
269 bool inState(unsigned int _state) const;
270
271 // interfaces
272protected:
273 Query(Connection* _connHandle);
274 virtual ~Query();
275
276 virtual void __destroy() = 0;
277 virtual bool __prepare(const char* _sql, size_t _sqllen,
278 size_t _paramCount) = 0;
279 virtual bool __execute() = 0;
280 virtual bool __fetch() = 0;
281 virtual bool __nextResult();
282
283 virtual bool __getField(size_t _index, Field** _fieldHandleOut) = 0;
284 virtual bool __getParam(size_t _index, Param** _paramHandleOut) = 0;
285
286protected:
288 bool __eof;
289 int64_t __affectedRows; // for INSERT, UPDATE
290
293 wchar_t __placeholder; // Oracle(':') or '?'
294
295 friend class Connection;
296
297 // Object States
298protected:
299 unsigned int __states;
300
301public:
302 enum State
303 {
304 stStandBy = 0x0001,
305 stPrepared = 0x0002,
306 stExecuted = 0x0004,
307 stFetched = 0x0008
308 };
309};
310
312{
314private:
315 long __refCount;
316
317public:
318 long refCount() const { return __refCount; }
319 long addRef(); // new incremented __refCount
320 long release(); // new decremented __refCount
321
322public:
323 bool open(const char* _connString, size_t _connlen);
324 bool close();
325 bool execute(const char* _sql, size_t _sqllen);
326
327 bool startTrans();
328 bool commitTrans();
329 bool rollbackTrans();
330
331 bool getErrorMessage(
332 char* _pbuf,
333 size_t* _pn // IN, OUT
334 );
335
336 bool getServerInfo(
337 char* _pbuf,
338 size_t* _pn // IN, OUT
339 );
340
341 bool createQueryInstance(Query** _queryHandleOut);
342 bool destroyQueryInstance(Query* _queryHandle);
343
344 // properties
345 Error errorCode() const;
346#if __DCL_DEBUG
347 const wchar_t* errorFileName() const;
348 int errorLine() const;
349#endif
350 bool canTransact() const;
351 const wchar_t* serverTitle() const;
352 bool inState(unsigned int uState) const;
353
354 // interfaces
355 virtual void destroy() = 0;
356protected:
357 Connection(const wchar_t* _serverTitle);
358 virtual ~Connection();
359
360 virtual bool __open(const char* _connString, size_t _connlen) = 0;
361 virtual bool __close() = 0;
362 virtual bool __execute(const char* _sql, size_t _sqllen) = 0;
363
364 virtual bool __startTrans() = 0;
365 virtual bool __commitTrans() = 0;
366 virtual bool __rollbackTrans() = 0;
367
368 virtual bool __createQueryInstance(Query** _queryHandleOut) = 0;
369 virtual bool __getErrorMessage(char* _buf, size_t* _buflen) = 0;
370 virtual bool __getServerInfo(char* _buf, size_t* _buflen) = 0;
371
372protected:
374 const wchar_t* __serverTitle;
375
377 const wchar_t* __errorFileName;
379
380 // Object States
381 unsigned int __states;
382public:
383 enum State
384 {
385 stClosed = 0x0001,
386 stOpenned = 0x0002,
388 };
389
391 // for SQLQuery, SQLField, SQLParam, and inherited classes
392 void setErrorStatus(Error _errorCode, const wchar_t* _filename, int _line);
393
394 /*
395 pszConnectionString을 파싱하여 map에 저장한다.
396 pszConnectionString의 예
397 "USER NAME=aUser;PASSWORD=aPW;DATABASE NAME=aDB; SERVER NAME=aHost;"
398
399 map의 KEY는 대문자로 변환되며, KEY와 VALUE 모두 space는 trim된다.
400
401 RETUNR VALUE : map에 설정된 아이템이 개수
402 */
403 static size_t splitConnectionString(
404 const char* _connString, size_t _strlen,
405 ListedByteStringToByteStringMap& _map
406 );
407};
408
410{
411 // DCL common members
412 uint32_t uSize; // structure size
413 uint32_t uDCLVersion; // DCL_VERSION
414 const wchar_t* pszBuildTimeStamp; // __TIMESTAMP__
415 uint32_t uBuildFlag; // release(0), debug(1)
416 uint32_t uModuleType; // DCL_SQL_DRIVER_MODULE
417 const wchar_t* pszDescription; // module description
418
419 // private members
420 uint32_t uVersion; // DCL_SQL_VERSION
421 const wchar_t* pszServerTitle;
422 const wchar_t* pszFileVersion;
423 bool (*pfnInitialize)();
424 bool (*pfnCleanup)();
425 Connection* (*pfnCreateConnectionInstance)();
426};
427
428}; // class SQL
429
430//#define __SET_ERROR(_errorCode) setErrorStatus(_errorCode, __THIS_FILE__, __LINE__)
431
432#define __SET_STATE(state) __states |= state
433#define __UNSET_STATE(state) __states &= ~state
434
435#include <dcl/SQLCore.inl>
436
437__DCL_END_NAMESPACE
438
439#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:739
bool __canTransact
Definition SQLCore.h:373
virtual bool __createQueryInstance(Query **_queryHandleOut)=0
long refCount() const
Definition SQLCore.h:318
bool rollbackTrans()
Definition SQLCore.cpp:758
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:720
virtual bool __startTrans()=0
virtual bool __execute(const char *_sql, size_t _sqllen)=0
const wchar_t * __serverTitle
Definition SQLCore.h:374
bool open(const char *_connString, size_t _connlen)
Definition SQLCore.cpp:667
unsigned int __states
Definition SQLCore.h:381
bool getErrorMessage(char *_pbuf, size_t *_pn)
Definition SQLCore.cpp:777
bool getServerInfo(char *_pbuf, size_t *_pn)
Definition SQLCore.cpp:788
Connection(const wchar_t *_serverTitle)
Definition SQLCore.cpp:646
bool canTransact() const
Definition SQLCore.inl:89
bool inState(unsigned int uState) const
Definition SQLCore.inl:99
bool destroyQueryInstance(Query *_queryHandle)
Definition SQLCore.cpp:822
virtual bool __commitTrans()=0
bool createQueryInstance(Query **_queryHandleOut)
Definition SQLCore.cpp:804
static size_t splitConnectionString(const char *_connString, size_t _strlen, ListedByteStringToByteStringMap &_map)
Definition SQLCore.cpp:843
Error __errorCode
Definition SQLCore.h:376
__PROTECTED const wchar_t int _line
Definition SQLCore.h:392
Error errorCode() const
Definition SQLCore.inl:72
virtual bool __close()=0
virtual bool __rollbackTrans()=0
const wchar_t * __errorFileName
Definition SQLCore.h:377
virtual bool __open(const char *_connString, size_t _connlen)=0
__PROTECTED const wchar_t * _filename
Definition SQLCore.h:392
Query * __queryHandle
Definition SQLCore.h:184
DataType __dataType
Definition SQLCore.h:186
virtual const wchar_t * serverDataTypeName() const =0
Field(Query *_queryHandle)
short __precision
Definition SQLCore.h:187
short __scale
Definition SQLCore.h:188
String __name
Definition SQLCore.h:185
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:479
virtual bool __getDataSize(size_t *_pn, bool _maxSize)
Definition SQLCore.cpp:470
virtual bool __setData(_CONST void *_pv, size_t _n, DataType _dataType, DataType _assignType)=0
Param(Query *_queryHandle)
virtual bool isNull() const
Definition SQLCore.cpp:457
virtual bool __setDataType(DataType _dataType)
Definition SQLCore.cpp:462
unsigned int __states
Definition SQLCore.h:299
Connection * __connHandle
Definition SQLCore.h:287
virtual void __destroy()=0
virtual bool __getParam(size_t _index, Param **_paramHandleOut)=0
friend class Connection
Definition SQLCore.h:295
Query(Connection *_connHandle)
size_t __paramCount
Definition SQLCore.h:292
virtual bool __execute()=0
virtual bool __nextResult()
Definition SQLCore.cpp:563
wchar_t __placeholder
Definition SQLCore.h:293
virtual bool __prepare(const char *_sql, size_t _sqllen, size_t _paramCount)=0
virtual bool __fetch()=0
bool __eof
Definition SQLCore.h:288
virtual bool __getField(size_t _index, Field **_fieldHandleOut)=0
size_t __fieldCount
Definition SQLCore.h:291
int64_t __affectedRows
Definition SQLCore.h:289
Definition SQLCore.h:15
DataType
Definition SQLCore.h:62
@ typeBinary
Definition SQLCore.h:77
@ typeClob
Definition SQLCore.h:80
@ typeNumeric
Definition SQLCore.h:67
@ typeTime
Definition SQLCore.h:69
@ typeLongBinary
Definition SQLCore.h:79
@ typeUInteger
Definition SQLCore.h:65
@ typeUnknown
Definition SQLCore.h:63
@ typeTimeStamp
Definition SQLCore.h:71
@ typeBlob
Definition SQLCore.h:81
@ typeInputStream
Definition SQLCore.h:84
@ typeTimeStampTz
Definition SQLCore.h:72
@ typeInterval
Definition SQLCore.h:73
@ typeIntervalDs
Definition SQLCore.h:75
@ typeDate
Definition SQLCore.h:68
@ typeOutputStream
Definition SQLCore.h:85
@ typeText
Definition SQLCore.h:76
@ typeTimeTz
Definition SQLCore.h:70
@ typeFloat
Definition SQLCore.h:66
@ typeInteger
Definition SQLCore.h:64
@ typeIntervalYm
Definition SQLCore.h:74
@ typeLongText
Definition SQLCore.h:78
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:414
bool(* pfnCleanup)()
Definition SQLCore.h:424
uint32_t uDCLVersion
Definition SQLCore.h:413
uint32_t uBuildFlag
Definition SQLCore.h:415
const wchar_t * pszFileVersion
Definition SQLCore.h:422
const wchar_t * pszDescription
Definition SQLCore.h:417
uint32_t uModuleType
Definition SQLCore.h:416
uint32_t uVersion
Definition SQLCore.h:420
bool(* pfnInitialize)()
Definition SQLCore.h:423
const wchar_t * pszServerTitle
Definition SQLCore.h:421
int16_t year
Definition SQLCore.h:97
uint8_t month
Definition SQLCore.h:98
uint8_t day
Definition SQLCore.h:99
int32_t years
Definition SQLCore.h:127
int32_t days
Definition SQLCore.h:129
int8_t hours
Definition SQLCore.h:130
int8_t mins
Definition SQLCore.h:131
int32_t fracs
Definition SQLCore.h:133
int8_t months
Definition SQLCore.h:128
int8_t secs
Definition SQLCore.h:132
uint8_t hour
Definition SQLCore.h:104
uint8_t sec
Definition SQLCore.h:106
uint32_t frac
Definition SQLCore.h:107
uint8_t min
Definition SQLCore.h:105
int16_t tzoff
Definition SQLCore.h:108
uint32_t frac
Definition SQLCore.h:119
int16_t tzoff
Definition SQLCore.h:120
uint8_t min
Definition SQLCore.h:117
uint8_t sec
Definition SQLCore.h:118
uint8_t hour
Definition SQLCore.h:116
uint8_t day
Definition SQLCore.h:115
int16_t year
Definition SQLCore.h:113
uint8_t month
Definition SQLCore.h:114