DCL 3.7.4
Loading...
Searching...
No Matches
SQL.h
Go to the documentation of this file.
1#ifndef __DCL_SQL_H__
2#define __DCL_SQL_H__ 20050322
3
4#ifndef __DCL_OBJECT_H__
5#include <dcl/Object.h>
6#endif
7
8#include <dcl/SQLCore.h>
9#include <dcl/SQLDriver.h>
10
11#ifndef __DCL_NUMERIC_H__
12#include <dcl/Numeric.h>
13#endif
14#ifndef __DCL_DATE_TIME_H__
15#include <dcl/DateTime.h>
16#endif
17#ifndef __DCL_INPUT_STREAM_H__
18#include <dcl/InputStream.h>
19#endif
20#ifndef __DCL_OUTPUT_STREAM_H__
21#include <dcl/OutputStream.h>
22#endif
23
24#ifndef __DCL_THREAD_H__
25#include <dcl/Thread.h>
26#endif
27#ifndef __DCL_ARRAY_H__
28#include <dcl/Array.h>
29#endif
30#ifndef __DCL_LIST_H__
31#include <dcl/List.h>
32#endif
33#ifndef __DCL_HASH_MAP_H__
34#include <dcl/HashMap.h>
35#endif
36
37__DCL_BEGIN_NAMESPACE
38
39class SQLField;
40class SQLFields;
41class SQLParam;
42class SQLParams;
43class SQLQuery;
44class SQLConnection;
46
47class DCLCAPI SQLField : public Object
48{
50public:
51 SQL::Field* handle() const;
52 const String& name() const ;
53
54 SQL::DataType dataType() const;
55 const wchar_t* dataTypeName() const;
56 const wchar_t* serverDataTypeName() const;
57
58 short precision() const;
59 short scale() const;
60
61 bool isNull() __DCL_THROWS1(SQLException*);
62
63 size_t getDataSize(
64 bool _maxsize = false
66
67 void getData(
68 void* _buf, // buffer
69 size_t* _size, // sizeof *_buf
70 SQL::DataType _bufType // buffer data type
72
73 // helper functions
74 size_t dataSize() __DCL_THROWS1(SQLException*);
75 size_t dataSizeMax() __DCL_THROWS1(SQLException*);
76
77 void getValue(int8_t& _val) __DCL_THROWS1(SQLException*);
78 void getValue(uint8_t& _val) __DCL_THROWS1(SQLException*);
79 void getValue(int16_t& _val) __DCL_THROWS1(SQLException*);
80 void getValue(uint16_t& _val) __DCL_THROWS1(SQLException*);
81 void getValue(int32_t& _val) __DCL_THROWS1(SQLException*);
82 void getValue(uint32_t& _val) __DCL_THROWS1(SQLException*);
83 void getValue(int64_t& _val) __DCL_THROWS1(SQLException*);
84 void getValue(uint64_t& _val) __DCL_THROWS1(SQLException*);
85 void getValue(float& _val) __DCL_THROWS1(SQLException*);
86 void getValue(double& _val) __DCL_THROWS1(SQLException*);
87 void getValue(SQL::Date& _val) __DCL_THROWS1(SQLException*);
88 void getValue(SQL::Time& _val) __DCL_THROWS1(SQLException*);
89 void getValue(SQL::TimeStamp& _val) __DCL_THROWS1(SQLException*);
90 void getValue(SQL::Interval& _val) __DCL_THROWS1(SQLException*);
91 void getValue(String& _val) __DCL_THROWS1(SQLException*);
92
93 void getValue(
94 ByteString& _val,
97
98 void getValue(
99 OutputStream& _output,
100 size_t _size = (size_t)-1
102
103 bool asBoolean() __DCL_THROWS1(SQLException*);
104 int asInteger() __DCL_THROWS1(SQLException*);
105 int32_t asInt32() __DCL_THROWS1(SQLException*);
106 int64_t asInt64() __DCL_THROWS1(SQLException*);
107 float asSingle() __DCL_THROWS1(SQLException*);
108 double asDouble() __DCL_THROWS1(SQLException*);
109
112 DateTime asDateTime() __DCL_THROWS1(SQLException*);
113 Interval asInterval() __DCL_THROWS1(SQLException*);
114
115 String asString() __DCL_THROWS1(SQLException*);
116 // Formatted String
117 String asStringF(
118 const wchar_t* _format = NULL
120
121protected:
124protected:
125// SQLField(SQL::Field* hField);
127 virtual ~SQLField();
128
129 friend class SQLFields;
130};
131
133{
135public:
136 void setNull();
137
138 void setData(
139 _CONST void* _val, // data, IN
140 size_t _size, // sizeof *_val
141 SQL::DataType _valType, // typeof *_val
142 SQL::DataType _sqlType // assign to server type
144
145 // output parameter support
146 void setOutputType(
147 SQL::DataType _sqlType
149
150 // helper functions
151 void setValue(int8_t _val) __DCL_THROWS1(SQLException*);
152 void setValue(uint8_t _val) __DCL_THROWS1(SQLException*);
153 void setValue(int16_t _val) __DCL_THROWS1(SQLException*);
154 void setValue(uint16_t _val) __DCL_THROWS1(SQLException*);
155 void setValue(int32_t _val) __DCL_THROWS1(SQLException*);
156 void setValue(uint32_t _val) __DCL_THROWS1(SQLException*);
157 void setValue(int64_t _val) __DCL_THROWS1(SQLException*);
158 void setValue(uint64_t _val) __DCL_THROWS1(SQLException*);
159 void setValue(float _val) __DCL_THROWS1(SQLException*);
160 void setValue(double _val) __DCL_THROWS1(SQLException*);
161
162 void setValue(
163 const Decimal& _val
165
166 void setValue(Date _val) __DCL_THROWS1(SQLException*);
167
168 void setValue(
169 Time _val,
170 int16_t _tzMinute = INT16_MIN
172
173 void setValue(
174 DateTime _val,
175 int16_t _tzMinute = INT16_MIN
177
178 void setValue(
179 Interval _val,
182
183 void setValue(
184 const String& _val,
187
188 void setValue(
189 const wchar_t* _val, size_t _size, // count of chars
192
193 void setValue(
194 const ByteString& _val,
197
198 void setValue(
199 const char* _val, size_t _size, // count of bytes
202
203 void setValue(
204 _CONST InputStream& _input, size_t _size = (size_t)-1,
207
208protected:
209 ByteString __bytesValue; // for String, Decimal
210
211protected:
212// SQLParam(SQL::Param* hParam);
214 virtual ~SQLParam();
215
216 friend class SQLParams;
217};
218
220{
222protected:
223 SQLField* __fields;
224 size_t __count;
225 StringToPointerMap __fieldMap;
226
227protected:
229 virtual ~SQLFields();
230
231 void clear();
232 void initialize(SQLQuery* _query);
233 friend class SQLQuery;
234
235public:
236 _CONST SQLField& at(size_t _index) const;
237
239 const wchar_t* _name
241
242 _CONST SQLField& operator[](size_t _index) const ;
243 size_t count() const;
244 bool isEmpty() const;
245};
246
248{
250protected:
251 SQLParam* __params;
252 size_t __count;
253 StringToPointerMap __paramMap;
254
255protected:
257 virtual ~SQLParams();
258
259 void clear();
260 void initialize(SQLQuery* _query, const StringArray _names);
261 friend class SQLQuery;
262
263public:
264 SQLParam& at(size_t _index) const;
265
267 const wchar_t* _name
269
270 SQLParam& operator[](size_t _index) const;
271 size_t count() const;
272 bool isEmpty() const;
273};
274
275class DCLCAPI SQLQuery : public Object
276{
278protected:
279 void initialize(SQLConnection* _conn) __DCL_THROWS1(SQLException*);
280
281public:
284 virtual ~SQLQuery();
285
286 void prepare(const String& _sql) __DCL_THROWS1(SQLException*);
288 void execute(const String& _sql) __DCL_THROWS1(SQLException*);
289
292 bool eof() const;
293 int64_t affectedRows() const;
296
297 SQL::Query* handle() const;
298 SQLConnection* connection() const;
299
300protected:
305
306#ifdef __DCL_DEBUG
307 String __sql;
308#endif
309};
310
312{
314protected:
315 void initialize(SQLDriver* _driver);
316
317public:
318 SQLConnection(SQLDriver* _driver);
319 SQLConnection(const String& _driverName)
321 virtual ~SQLConnection();
322
323 // Operations
324 // "USER=aUser; PASSWORD=aPW; DATABASE=aDB; SERVER=aHost"
325 void open(const String& _connstr) __DCL_THROWS1(SQLException*);
327 void execute(const String& _sql) __DCL_THROWS1(SQLException*);
331
333
334 bool canTransact() const;
335
336 // Properties
337 SQL::Connection* handle() const;
338 SQLDriver* driver() const;
339 bool connected() const;
340 bool inTransaction() const;
341
342protected:
346};
347
349{
351public:
353 const String& _connString,
354 const String& _driverName
356
357 virtual ~SQLConnectionPool();
358
359 // NULL reach __allMax
360 SQLConnection* getConnection() __DCL_THROWS1(SQLException*);
361 void release(SQLConnection* _conn);
362
363 bool setMaxCount(size_t _idleMax, size_t _allMax);
364
365 size_t count() const;
366
367 size_t idleCount() const;
368
369 void clear(unsigned _waitSeconds);
370
371protected:
374
375 PointerList __idleConns;
376 PointerArray __allConns;
377
379
380 size_t __idleMax;
381 size_t __allMax;
382};
383
384// exception support for addtional members
386{
388public:
389 enum AsErrorCode
390 {
391 // asInt32, asInt64, asSingle, ... 변환 에러
392 eInvalidCast,
393 eOutOfRange
394 };
395 String __message;
396
397protected:
398 String getServerMessage(SQL::Connection* _connHandle);
399
400public:
401 SQLException(SQLConnection* _conn, Exception* _cause);
402 SQLException(SQLConnection* _conn, const String& _message);
403 SQLException(SQLQuery* _query, Exception* _cause);
404 SQLException(SQLQuery* _query, const String& _message);
405 SQLException(SQLField* _field, Exception* _cause);
406
408 SQLField* _field,
409 const wchar_t* _cast,
410 AsErrorCode errorCode
411 );
412
414 SQLField* _field,
415 const wchar_t* _cast,
416 Exception* _cause
417 );
418
419 virtual String toString() const;
420};
421
422#include <dcl/SQL.inl>
423
424__DCL_END_NAMESPACE
425
426#endif // __DCL_SQL_H__
#define NULL
Definition Config.h:312
#define DCLCAPI
Definition Config.h:95
#define _CONST
Definition Config.h:325
#define INT16_MIN
Definition Config.h:284
#define __DCL_THROWS1(e)
Definition Config.h:152
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:227
Exception(Exception *_cause=NULL)
Object()
Definition Object.cpp:183
virtual String toString() const
Definition Object.cpp:187
SQLDriver * __driver
Definition SQL.h:344
bool __connected
Definition SQL.h:345
void open(const String &_connstr) __DCL_THROWS1(SQLException *)
String getServerInfo() __DCL_THROWS1(SQLException *)
bool canTransact() const
SQLDriver * driver() const
Definition SQL.inl:127
SQLConnection(SQLDriver *_driver)
void rollbackTrans() __DCL_THROWS1(SQLException *)
bool connected() const
Definition SQL.inl:132
bool inTransaction() const
SQL::Connection * handle() const
Definition SQL.inl:122
SQL::Connection * __handle
Definition SQL.h:343
void execute(const String &_sql) __DCL_THROWS1(SQLException *)
void commitTrans() __DCL_THROWS1(SQLException *)
void startTrans() __DCL_THROWS1(SQLException *)
void close() __DCL_THROWS1(SQLException *)
PointerList __idleConns
Definition SQL.h:375
Thread::Mutex __lock
Definition SQL.h:378
SQLDriver * __sqlDriver
Definition SQL.h:372
size_t __idleMax
Definition SQL.h:380
size_t __allMax
Definition SQL.h:381
String __connString
Definition SQL.h:373
PointerArray __allConns
Definition SQL.h:376
String getServerMessage(SQL::Connection *_connHandle)
SQLException(SQLConnection *_conn, Exception *_cause)
Definition SQL.h:48
SQL::Field * __handle
Definition SQL.h:122
friend class SQLFields
Definition SQL.h:129
SQLQuery * __query
Definition SQL.h:123
void initialize(SQLQuery *_query)
Definition SQLQuery.cpp:53
_CONST SQLField & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
Definition SQLQuery.cpp:77
_CONST SQLField & at(size_t _index) const
Definition SQL.inl:41
size_t count() const
Definition SQL.inl:55
_CONST SQLField & operator[](size_t _index) const
Definition SQL.inl:48
void clear()
Definition SQLQuery.cpp:42
friend class SQLQuery
Definition SQL.h:233
bool isEmpty() const
Definition SQL.inl:60
DataType
Definition SQLCore.h:59
@ typeBinary
Definition SQLCore.h:74
@ typeLongBinary
Definition SQLCore.h:76
@ typeIntervalDs
Definition SQLCore.h:72
@ typeText
Definition SQLCore.h:73
friend class SQLParams
Definition SQL.h:216
ByteString __bytesValue
Definition SQL.h:209
size_t count() const
Definition SQL.inl:80
SQLParam & operator[](size_t _index) const
Definition SQL.inl:73
void initialize(SQLQuery *_query, const StringArray _names)
Definition SQLQuery.cpp:135
friend class SQLQuery
Definition SQL.h:261
SQLParam & at(size_t _index) const
Definition SQL.inl:66
void clear()
Definition SQLQuery.cpp:124
bool isEmpty() const
Definition SQL.inl:85
SQLParam & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
Definition SQLQuery.cpp:157
void prepare(const String &_sql) __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:282
SQLQuery(SQLConnection *_conn) __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:267
SQL::Query * __handle
Definition SQL.h:301
_CONST SQLParams & params() _CONST
Definition SQL.inl:106
_CONST SQLFields & fields() _CONST
Definition SQL.inl:101
void execute() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:316
SQLParams __params
Definition SQL.h:304
int64_t affectedRows() const
Definition SQL.inl:96
bool eof() const
Definition SQL.inl:91
SQLConnection * connection() const
Definition SQL.inl:116
void fetch() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:336
SQL::Query * handle() const
Definition SQL.inl:111
SQLFields __fields
Definition SQL.h:303
bool moreResults() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:343
SQLConnection * __connection
Definition SQL.h:302