DCL 4.0
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
162 void setValue(
163 DateTime _value,
164 int16_t _tzMinute
166
167 void setValue(
168 Interval _value,
171
172 void setValue(
173 const String& _value,
174 SQL::DataType _assignType = SQL::typeText
176
177 void setValue(
178 const wchar_t* _p, size_t _n,
179 SQL::DataType _assignType = SQL::typeText
181
182 void setValue(
183 const ByteString& _value,
184 SQL::DataType _assignType = SQL::typeBinary
186
187 void setValue(
188 const byte_t* _p, size_t _n,
189 SQL::DataType _assignType = SQL::typeBinary
191
192 void setValue(
193 _CONST InputStream* _input, size_t _n = (size_t)-1,
196
197protected:
198 ByteString __bytesValue; // for String, Decimal
199
200protected:
201// SQLParam(SQL::Param* hParam);
203 virtual ~SQLParam();
204
205 friend class SQLParams;
206};
207
209{
211protected:
212 SQLField* __fields;
213 size_t __count;
214 StringToPointerMap __fieldMap;
215
216protected:
218 virtual ~SQLFields();
219
220 void clear();
221 void initialize(SQLQuery* _query);
222 friend class SQLQuery;
223
224public:
225 _CONST SQLField& at(size_t _index) const;
227 const wchar_t* _name
229
230 _CONST SQLField& operator[](size_t _index) const ;
231 size_t count() const;
232 bool isEmpty() const;
233};
234
236{
238protected:
239 SQLParam* __params;
240 size_t __count;
241 StringToPointerMap __paramMap;
242
243protected:
245 virtual ~SQLParams();
246
247 void clear();
248 void initialize(SQLQuery* _query, const StringArray _names);
249 friend class SQLQuery;
250
251public:
252 SQLParam& at(size_t _index) const;
254 const wchar_t* _name
256
257 SQLParam& operator[](size_t _index) const;
258 size_t count() const;
259 bool isEmpty() const;
260};
261
262class DCLCAPI SQLQuery : public Object
263{
265protected:
266 void initialize(SQLConnection* _conn) __DCL_THROWS1(SQLException*);
267
268public:
271 virtual ~SQLQuery();
272
274 const String& _sql
276
278
280 const String& _sql
282
285 bool eof() const;
286 int64_t affectedRows() const;
289
290 SQL::Query* handle() const;
291 SQLConnection* connection() const;
292
293protected:
294 SQL::Query* __handle;
298
299#if __DCL_DEBUG
300 String __sql;
301#endif
302};
303
305{
307protected:
308 void initialize(SQLDriver* _driver);
309
310public:
311 SQLConnection(SQLDriver* _driver);
312 SQLConnection(const String& _driverName)
314 virtual ~SQLConnection();
315
316 // Operations
317 // "USER=aUser; PASSWORD=aPW; DATABASE=aDB; SERVER=aHost"
318 void open(const String& _connString)
321 void execute(const String& _sql)
326
329
330 bool canTransact() const;
331
332 // Properties
333 SQL::Connection* handle() const;
334 SQLDriver* driver() const;
335 bool connected() const;
336 bool inTransaction() const;
337
338protected:
339 SQL::Connection* __handle;
342};
343
345{
347public:
349 const String& _connString,
350 const String& _driverName
352
353 virtual ~SQLConnectionPool();
354
355 // NULL reach __allMax
356 SQLConnection* getConnection() __DCL_THROWS1(SQLException*);
357 void release(SQLConnection* _conn);
358
359 bool setMaxCount(size_t _idleMax, size_t _allMax);
360
361 size_t count() const;
362
363 size_t idleCount() const;
364
365 void clear(unsigned _waitSeconds);
366
367protected:
370
371 PointerList __idleConns;
372 PointerArray __allConns;
373
375
376 size_t __idleMax;
377 size_t __allMax;
378};
379
380// exception support for addtional members
382{
384public:
385 enum AsErrorCode
386 {
387 // asInt32, asInt64, asSingle, ... 변환 에러
388 eInvalidCast,
389 eOutOfRange
390 };
391 String __message;
392
393protected:
394 String getServerMessage(SQL::Connection* _connHandle);
395
396public:
398 SQLException(SQLConnection* _conn, const String& _message);
399 SQLException(SQLQuery* _query);
400 SQLException(SQLQuery* _query, const String& _message);
401 SQLException(SQLField* _field);
403 SQLField* _field,
404 const wchar_t* _cast,
405 AsErrorCode errorCode
406 );
408 SQLField* _field,
409 const wchar_t* _cast,
410 Exception* _cause
411 );
412 SQLException(SQLParam* _param);
413
414 virtual String toString() const;
415};
416
417#include <dcl/SQL.inl>
418
419__DCL_END_NAMESPACE
420
421#endif // __DCL_SQL_H__
#define NULL
Definition Config.h:340
#define DCLCAPI
Definition Config.h:100
unsigned char byte_t
Definition Config.h:274
#define _CONST
Definition Config.h:353
#define __DCL_THROWS2(e1, e2)
Definition Config.h:168
#define __DCL_THROWS1(e)
Definition Config.h:167
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:210
buf release()
_r
Definition SQLField.cpp:260
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:340
bool __connected
Definition SQL.h:341
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:339
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:371
Thread::Mutex __lock
Definition SQL.h:374
SQLDriver * __sqlDriver
Definition SQL.h:368
size_t __idleMax
Definition SQL.h:376
size_t __allMax
Definition SQL.h:377
String __connString
Definition SQL.h:369
PointerArray __allConns
Definition SQL.h:372
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:222
bool isEmpty() const
Definition SQL.inl:98
Definition SQLCore.h:15
DataType
Definition SQLCore.h:62
@ typeBinary
Definition SQLCore.h:76
@ typeLongBinary
Definition SQLCore.h:78
@ typeIntervalDs
Definition SQLCore.h:74
@ typeText
Definition SQLCore.h:75
friend class SQLParams
Definition SQL.h:205
ByteString __bytesValue
Definition SQL.h:198
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:249
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:294
_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:297
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:296
bool nextResult() __DCL_THROWS1(SQLException *)
Definition SQLQuery.cpp:336
SQLConnection * __connection
Definition SQL.h:295