DCL 4.1
Loading...
Searching...
No Matches
SQLParam.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2#if __DCL_WINDOWS
3#include <windows.h>
4#endif
5// 2005.01.26
6
7#include <dcl/Object.h>
8
9#if __DCL_HAVE_ALLOC_DEBUG
10#undef __DCL_ALLOC_LEVEL
11#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
12#endif
13
14#include <dcl/Charset.h>
15#include <dcl/SQL.h>
16
17#if __DCL_DEBUG
18#undef __THIS_FILE__
19static const char_t __THIS_FILE__[] = __T("dcl/SQLParam.cpp");
20#endif
21
22__DCL_BEGIN_NAMESPACE
23
26
27/*
28SQLParam::SQLParam(SQL::Param* hParam)
29{
30 __handle = hParam;
31}
32*/
34{
35}
36
41
42void SQLParam::setNull()
43{
44 __DCL_ASSERT(this != NULL);
46#ifdef __DCL_NO_RTTI
48#else
49 __DCL_ASSERT(dynamic_cast<SQL::Param*>(__handle) != NULL);
50#endif
51
52 ((SQL::Param*)__handle)->setNull();
53}
54
55void SQLParam::setData(
56 _CONST void* _pv, // data, IN
57 size_t _n, // sizeof *_pv
58 SQL::DataType _dataType, // typeof *_pv
59 SQL::DataType _assignType // assign to server type
61{
62 __DCL_ASSERT(this != NULL);
63 __DCL_ASSERT(__handle != NULL);
64#ifdef __DCL_NO_RTTI
65 __DCL_ASSERT(__handle->isKindOf(CLASSINFO(SQL::Param)));
66#else
67 __DCL_ASSERT(dynamic_cast<SQL::Param*>(__handle) != NULL);
68#endif
69
70 __DCL_ASSERT(_pv != NULL);
71// __DCL_ASSERT(_n > 0); 문자열일 경우 _n는 0일 수 있다.
72
73 if (!((SQL::Param*)__handle)->setData(_pv, _n, _dataType, _assignType)) {
74 throw new SQLException(this);
75 }
76}
77
79
80void SQLParam::setValue(int32_t _value) __DCL_THROWS1(SQLException*)
81{
82 setData(
83 (_CONST void*)&_value,
84 sizeof(int32_t),
87 );
88}
89
90void SQLParam::setValue(uint32_t _value) __DCL_THROWS1(SQLException*)
91{
92 setData(
93 (_CONST void*)&_value,
94 sizeof(uint32_t),
97 );
98}
99
100void SQLParam::setValue(int64_t _value) __DCL_THROWS1(SQLException*)
101{
102 setData(
103 (_CONST void*)&_value,
104 sizeof(int64_t),
107 );
108}
109
110void SQLParam::setValue(uint64_t _value) __DCL_THROWS1(SQLException*)
111{
112 setData(
113 (_CONST void*)&_value,
114 sizeof(uint64_t),
117 );
118}
119
120void SQLParam::setValue(float _value) __DCL_THROWS1(SQLException*)
121{
122 setData(
123 (_CONST void*)&_value,
124 sizeof(float),
127 );
128}
129
130void SQLParam::setValue(double _value) __DCL_THROWS1(SQLException*)
131{
132 setData(
133 (_CONST void*)&_value,
134 sizeof(double),
137 );
138}
139
140void SQLParam::setValue(
141 const Decimal& _value
143{
144 setValue(
145 _value.toString(),
147 );
148}
149
150void SQLParam::setValue(Date _value) __DCL_THROWS1(SQLException*)
151{
152 SQL::Date d;
153 int nYear, nMonth, nDay;
154
155 _value.decode(nYear, nMonth, nDay);
156
157 d.year = nYear;
158 d.month = nMonth;
159 d.day = nDay;
160
161 setData(
162 (_CONST void*)&d,
163 sizeof(SQL::Date),
166 );
167}
168
169void SQLParam::setValue(
170 Time _value,
171 int16_t _tzMinute // = INT16_MIN
173{
174 SQL::Time t;
175 int nHour, nMin, nSec, nMSec;
176
177 _value.decode(nHour, nMin, nSec, nMSec);
178
179 t.hour = nHour;
180 t.min = nMin;
181 t.sec = nSec;
182 t.frac = nMSec * 1000000;
183 t.tzoff = _tzMinute;
184
185 setData(
186 (_CONST void*) & t,
187 sizeof(SQL::Time),
190 );
191}
192
193void SQLParam::setValue(
194 DateTime _value,
195 int16_t _tzMinute // = INT16_MIN
197{
199 int nYear, nMonth, nDay, nHour, nMin, nSec, nMSec;
200 _value.date().decode(nYear, nMonth, nDay);
201 _value.time().decode(nHour, nMin, nSec, nMSec);
202
203 ts.year = nYear;
204 ts.month = nMonth;
205 ts.day = nDay;
206 ts.hour = nHour;
207 ts.min = nMin;
208 ts.sec = nSec;
209 ts.frac = nMSec * 1000000;
210 ts.tzoff = _tzMinute;
211
212 setData(
213 (_CONST void*)&ts,
214 sizeof(SQL::TimeStamp),
217 );
218}
219
220void SQLParam::setValue(
221 Interval _value,
222 SQL::DataType _assignType // = SQL::typeIntervalDs
224{
225 __DCL_ASSERT(_assignType == SQL::typeInterval
226 || _assignType == SQL::typeIntervalYm
227 || _assignType == SQL::typeIntervalDs);
228
229 SQL::Interval iv;
230 long nDays, nMSecs;
231 _value.decode(nDays, nMSecs);
232
233 if (_assignType == SQL::typeIntervalYm) {
234 iv.years = nDays / 360;
235 iv.months = (int8_t)((nDays % 360) / 30);
236 iv.days = 0;
237 iv.hours = 0;
238 iv.mins = 0;
239 iv.secs = 0;
240 iv.fracs = 0;
241 }
242 else {
243 iv.years = 0;
244 iv.months = 0;
245 iv.days = nDays;
246 iv.hours = (int8_t)(nMSecs / 3600000);
247 iv.mins = (int8_t)((nMSecs % 3600000) / 60000);
248 iv.secs = (int8_t)((nMSecs % 60000) / 1000);
249 iv.fracs = (nMSecs % 1000) * 1000000;
250 }
251
252 setData(
253 (_CONST void*)&iv,
254 sizeof(SQL::Interval),
256 _assignType
257 );
258}
259
260void SQLParam::setValue(
261 const String& _value,
262 SQL::DataType _assignType // = SQL::typeText
264{
265 __DCL_ASSERT(_assignType == SQL::typeNumeric
266 || _assignType == SQL::typeText
267 || _assignType == SQL::typeLongText
268 || _assignType == SQL::typeClob);
269
270 setValue(UTF8Encoder::encode(_value), _assignType);
271}
272
273void SQLParam::setValue(
274 const wchar_t* _p,
275 size_t _n,
276 SQL::DataType _assignType // = SQL::typeText
278{
279 __DCL_ASSERT(_assignType == SQL::typeNumeric
280 || _assignType == SQL::typeText
281 || _assignType == SQL::typeLongText
282 || _assignType == SQL::typeClob);
283
284 setValue(UTF8Encoder::encode(_p, _n), _assignType);
285}
286
287void SQLParam::setValue(
288 const ByteString& _value,
289 SQL::DataType _assignType // = SQL::typeBinary
291{
292 __DCL_ASSERT(_assignType == SQL::typeNumeric
293 || _assignType == SQL::typeText
294 || _assignType == SQL::typeLongText
295 || _assignType == SQL::typeClob
296 || _assignType == SQL::typeBinary
297 || _assignType == SQL::typeLongBinary
298 || _assignType == SQL::typeBlob);
299
300 // SQL::Param은 문자열을 복사하지 않을 수 있다.
301 // SQL::Param이 파괴될때까지 문자열의 참조를 보관하여 문자열이
302 // 파괴되지 않도록 한다.
303 __bytesValue = _value;
304
305 setData(
306 (_CONST void*)__bytesValue.data(),
307 __bytesValue.length(),
308 (_assignType == SQL::typeBinary
309 || _assignType == SQL::typeLongBinary
310 || _assignType == SQL::typeBlob
312 _assignType
313 );
314}
315
316void SQLParam::setValue(
317 _CONST char* _p,
318 size_t _n,
319 SQL::DataType _assignType // = SQL::typeBinary
321{
322 __DCL_ASSERT(_assignType == SQL::typeText
323 || _assignType == SQL::typeLongText
324 || _assignType == SQL::typeClob
325 || _assignType == SQL::typeBinary
326 || _assignType == SQL::typeLongBinary
327 || _assignType == SQL::typeBlob);
328
329 setData(
330 (_CONST void*)_p,
331 _n,
332 (_assignType == SQL::typeBinary
333 || _assignType == SQL::typeLongBinary
334 || _assignType == SQL::typeBlob
336 _assignType
337 );
338}
339
340void SQLParam::setValue(
341 _CONST InputStream* _input,
342 size_t _n,
343 SQL::DataType _assignType
345{
346 __DCL_ASSERT(_assignType == SQL::typeText
347 || _assignType == SQL::typeLongText
348 || _assignType == SQL::typeClob
349 || _assignType == SQL::typeBinary
350 || _assignType == SQL::typeLongBinary
351 || _assignType == SQL::typeBlob);
352
353 setData(
354 _input,
355 _n,
357 _assignType
358 );
359}
360
361void SQLParam::setDataType(
362 SQL::DataType _dataType
364{
365 __DCL_ASSERT(this != NULL);
366 __DCL_ASSERT(__handle != NULL);
367 if (!((SQL::Param*)__handle)->setDataType(_dataType))
368 {
369 throw new SQLException(this);
370 }
371}
372
373__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
#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 CLASSINFO(class_name)
Definition Object.h:209
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:228
#define __T(str)
Definition Object.h:44
void CharsetConvertException * setValue(UTF8Encoder::encode(_value), _assignType)
Definition SQL.h:48
SQL::Field * __handle
Definition SQL.h:117
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
@ 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
@ 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
virtual ~SQLParam()
Definition SQLParam.cpp:37
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