DCL 4.1
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() const;
62
63 size_t getDataSize(
64 bool _maxSize = false
66
67 void getData(
68 void* _pv, // buffer
69 size_t* _pn, // sizeof *_pv
70 SQL::DataType _dataType // 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(int32_t& _r) __DCL_THROWS1(SQLException*);
78 void getValue(uint32_t& _r) __DCL_THROWS1(SQLException*);
79 void getValue(int64_t& _r) __DCL_THROWS1(SQLException*);
80 void getValue(uint64_t& _r) __DCL_THROWS1(SQLException*);
81 void getValue(float& _r) __DCL_THROWS1(SQLException*);
82 void getValue(double& _r) __DCL_THROWS1(SQLException*);
83 void getValue(SQL::Date& _r) __DCL_THROWS1(SQLException*);
84 void getValue(SQL::Time& _r) __DCL_THROWS1(SQLException*);
87 void getValue(String& _r) __DCL_THROWS2(SQLException*, CharsetConvertException*);
88 void getValue(
89 ByteString& _r,
92
93 void getValue(
95 size_t _n = (size_t)-1
97
98 bool asBoolean() __DCL_THROWS1(SQLException*);
99 int asInteger() __DCL_THROWS1(SQLException*);
100 int32_t asInt32() __DCL_THROWS1(SQLException*);
101 int64_t asInt64() __DCL_THROWS1(SQLException*);
102 float asSingle() __DCL_THROWS1(SQLException*);
103 double asDouble() __DCL_THROWS1(SQLException*);
104
107 DateTime asDateTime() __DCL_THROWS1(SQLException*);
108 Interval asInterval() __DCL_THROWS1(SQLException*);
109
111 // Formatted String
112 String asStringF(
113 const wchar_t* _format = NULL
115
116protected:
119protected:
120// SQLField(SQL::Field* hField);
122 virtual ~SQLField();
123
124 friend class SQLFields;
125};
126
128{
130public:
131 void setNull();
132 void setData(
133 _CONST void* _pv, // data, IN
134 size_t _n, // sizeof *_pv
135 SQL::DataType _dataType, // typeof *_pv
136 SQL::DataType _assignType // assign to server type
138
139 // out param support
140 void setDataType(
141 SQL::DataType _dataType
143
144 // helper functions
145#if defined(_MSC_VER) && _MSC_VER <= 1200
146 void setValue(int _value) __DCL_THROWS1(SQLException*);
147 void setValue(unsigned int _value) __DCL_THROWS1(SQLException*);
148#endif
149 void setValue(int32_t _value) __DCL_THROWS1(SQLException*);
150 void setValue(uint32_t _value) __DCL_THROWS1(SQLException*);
151 void setValue(int64_t _value) __DCL_THROWS1(SQLException*);
152 void setValue(uint64_t _value) __DCL_THROWS1(SQLException*);
153 void setValue(float _value) __DCL_THROWS1(SQLException*);
154 void setValue(double _value) __DCL_THROWS1(SQLException*);
155 void setValue(
156 const Decimal& _value
158
160 void setValue(
161 Time _value,
162 int16_t _tzMinute = INT16_MIN
164 void setValue(
165 DateTime _value,
166 int16_t _tzMinute = INT16_MIN
168
169 void setValue(
170 Interval _value,
173
174 void setValue(
175 const String& _value,
176 SQL::DataType _assignType = SQL::typeText
178
179 void setValue(
180 const wchar_t* _p, size_t _n,
181 SQL::DataType _assignType = SQL::typeText
183
184 void setValue(
185 const ByteString& _value,
186 SQL::DataType _assignType = SQL::typeBinary
188
189 void setValue(
190 _CONST char* _p, size_t _n,
191 SQL::DataType _assignType = SQL::typeBinary
193
194 void setValue(
195 _CONST InputStream* _input, size_t _n = (size_t)-1,
198
199protected:
200 ByteString __bytesValue; // for String, Decimal
201
202protected:
203// SQLParam(SQL::Param* hParam);
205 virtual ~SQLParam();
206
207 friend class SQLParams;
208};
209
211{
213protected:
214 SQLField* __fields;
215 size_t __count;
216 StringToPointerMap __fieldMap;
217
218protected:
220 virtual ~SQLFields();
221
222 void clear();
223 void initialize(SQLQuery* _query);
224 friend class SQLQuery;
225
226public:
227 _CONST SQLField& at(size_t _index) const;
229 const wchar_t* _name
231
232 _CONST SQLField& operator[](size_t _index) const ;
233 size_t count() const;
234 bool isEmpty() const;
235};
236
238{
240protected:
241 SQLParam* __params;
242 size_t __count;
243 StringToPointerMap __paramMap;
244
245protected:
247 virtual ~SQLParams();
248
249 void clear();
250 void initialize(SQLQuery* _query, const StringArray _names);
251 friend class SQLQuery;
252
253public:
254 SQLParam& at(size_t _index) const;
256 const wchar_t* _name
258
259 SQLParam& operator[](size_t _index) const;
260 size_t count() const;
261 bool isEmpty() const;
262};
263
264class DCLCAPI SQLQuery : public Object
265{
267protected:
268 void initialize(SQLConnection* _conn) __DCL_THROWS1(SQLException*);
269
270public:
273 virtual ~SQLQuery();
274
276 const String& _sql
278
280
282 const String& _sql
284
287 bool eof() const;
288 int64_t affectedRows() const;
291
292 SQL::Query* handle() const;
293 SQLConnection* connection() const;
294
295protected:
296 SQL::Query* __handle;
300
301#if __DCL_DEBUG
302 String __sql;
303#endif
304};
305
307{
309protected:
310 void initialize(SQLDriver* _driver);
311
312public:
313 SQLConnection(SQLDriver* _driver);
314 SQLConnection(const String& _driverName)
316 virtual ~SQLConnection();
317
318 // Operations
319 // "USER=aUser; PASSWORD=aPW; DATABASE=aDB; SERVER=aHost"
320 void open(const String& _connString)
323 void execute(const String& _sql)
328
331
332 bool canTransact() const;
333
334 // Properties
335 SQL::Connection* handle() const;
336 SQLDriver* driver() const;
337 bool connected() const;
338 bool inTransaction() const;
339
340protected:
341 SQL::Connection* __handle;
344};
345
347{
349public:
351 const String& _connString,
352 const String& _driverName
354
355 virtual ~SQLConnectionPool();
356
357 // NULL reach __allMax
358 SQLConnection* getConnection() __DCL_THROWS1(SQLException*);
359 void release(SQLConnection* _conn);
360
361 bool setMaxCount(size_t _idleMax, size_t _allMax);
362
363 size_t count() const;
364
365 size_t idleCount() const;
366
367 void clear(unsigned _waitSeconds);
368
369protected:
372
373 PointerList __idleConns;
374 PointerArray __allConns;
375
377
378 size_t __idleMax;
379 size_t __allMax;
380};
381
382// exception support for addtional members
384{
386public:
387 enum AsErrorCode
388 {
389 // asInt32, asInt64, asSingle, ... 변환 에러
390 eInvalidCast,
391 eOutOfRange
392 };
393 String __message;
394
395protected:
396 String getServerMessage(SQL::Connection* _connHandle);
397
398public:
400 SQLException(SQLConnection* _conn, const String& _message);
401 SQLException(SQLQuery* _query);
402 SQLException(SQLQuery* _query, const String& _message);
403 SQLException(SQLField* _field);
405 SQLField* _field,
406 const wchar_t* _cast,
407 AsErrorCode errorCode
408 );
410 SQLField* _field,
411 const wchar_t* _cast,
412 Exception* _cause
413 );
414 SQLException(SQLParam* _param);
415
416 virtual String toString() const;
417};
418
419#include <dcl/SQL.inl>
420
421__DCL_END_NAMESPACE
422
423#endif // __DCL_SQL_H__
#define NULL
Definition Config.h:340
#define DCLCAPI
Definition Config.h:100
#define _CONST
Definition Config.h:353
#define __DCL_THROWS2(e1, e2)
Definition Config.h:168
#define INT16_MIN
Definition Config.h:312
#define __DCL_THROWS1(e)
Definition Config.h:167
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
buf release()
_r
Definition SQLField.cpp:261
void CharsetConvertException * setValue(UTF8Encoder::encode(_value), _assignType)
void CharsetConvertException * execute()
void CharsetConvertException *__fields clear()
Exception(Exception *_cause=NULL)
Object()
Definition Object.cpp:183
virtual String toString() const
Definition Object.cpp:187
SQLDriver * __driver
Definition SQL.h:342
bool __connected
Definition SQL.h:343
void execute(const String &_sql) __DCL_THROWS2(SQLException *
String CharsetConvertException *bool canTransact() const
SQLDriver * driver() const
Definition SQL.inl:165
SQLConnection(SQLDriver *_driver)
void rollbackTrans() __DCL_THROWS1(SQLException *)
String getServerInfo() __DCL_THROWS2(SQLException *
bool connected() const
Definition SQL.inl:170
bool inTransaction() const
SQL::Connection * handle() const
Definition SQL.inl:160
SQL::Connection * __handle
Definition SQL.h:341
void open(const String &_connString) __DCL_THROWS2(SQLException *
void commitTrans() __DCL_THROWS1(SQLException *)
void CharsetConvertException *void startTrans() __DCL_THROWS1(SQLException *)
void CharsetConvertException *void close() __DCL_THROWS1(SQLException *)
PointerList __idleConns
Definition SQL.h:373
Thread::Mutex __lock
Definition SQL.h:376
SQLDriver * __sqlDriver
Definition SQL.h:370
size_t __idleMax
Definition SQL.h:378
size_t __allMax
Definition SQL.h:379
String __connString
Definition SQL.h:371
PointerArray __allConns
Definition SQL.h:374
String getServerMessage(SQL::Connection *_connHandle)
SQLException(SQLConnection *_conn)
Definition SQL.h:48
SQL::Field * __handle
Definition SQL.h:117
friend class SQLFields
Definition SQL.h:124
SQLQuery * __query
Definition SQL.h:118
void initialize(SQLQuery *_query)
Definition SQLQuery.cpp:52
_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:79
size_t count() const
Definition SQL.inl:93
_CONST SQLField & operator[](size_t _index) const
Definition SQL.inl:86
friend class SQLQuery
Definition SQL.h:224
bool isEmpty() const
Definition SQL.inl:98
Definition SQLCore.h:15
DataType
Definition SQLCore.h:62
@ typeBinary
Definition SQLCore.h:77
@ typeLongBinary
Definition SQLCore.h:79
@ typeIntervalDs
Definition SQLCore.h:75
@ typeText
Definition SQLCore.h:76
friend class SQLParams
Definition SQL.h:207
ByteString __bytesValue
Definition SQL.h:200
size_t count() const
Definition SQL.inl:118
SQLParam & operator[](size_t _index) const
Definition SQL.inl:111
void initialize(SQLQuery *_query, const StringArray _names)
Definition SQLQuery.cpp:135
friend class SQLQuery
Definition SQL.h:251
SQLParam & at(size_t _index) const
Definition SQL.inl:104
bool isEmpty() const
Definition SQL.inl:123
SQLParam & byName(const wchar_t *_name) _CONST __DCL_THROWS1(InvalidIndexException *)
Definition SQLQuery.cpp:157
SQLQuery(SQLConnection *_conn) __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:263
SQL::Query * __handle
Definition SQL.h:296
_CONST SQLParams & params() _CONST
Definition SQL.inl:144
void prepare(const String &_sql) __DCL_THROWS2(SQLException *
_CONST SQLFields & fields() _CONST
Definition SQL.inl:139
void CharsetConvertException *void execute() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:307
SQLParams __params
Definition SQL.h:299
int64_t affectedRows() const
Definition SQL.inl:134
bool eof() const
Definition SQL.inl:129
SQLConnection * connection() const
Definition SQL.inl:154
void CharsetConvertException *void fetch() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:329
SQL::Query * handle() const
Definition SQL.inl:149
SQLFields __fields
Definition SQL.h:298
bool nextResult() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:336
SQLConnection * __connection
Definition SQL.h:297