DCL 3.7.4
Loading...
Searching...
No Matches
SQLParam.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <windows.h>
5#endif
6// 2005.01.26
7
8#include <dcl/Object.h>
9
10#if __DCL_HAVE_ALLOC_DEBUG
11#undef __DCL_ALLOC_LEVEL
12#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
13#endif
14
15#include <dcl/Charset.h>
16#include <dcl/SQL.h>
17
18#if __DCL_HAVE_THIS_FILE__
19#undef __THIS_FILE__
20static const char_t __THIS_FILE__[] = __T("dcl/SQLParam.cpp");
21#endif
22
23__DCL_BEGIN_NAMESPACE
24
31
35
36void SQLParam::setNull()
37{
39#ifdef __DCL_NO_RTTI
41#else
42 __DCL_ASSERT(dynamic_cast<SQL::Param*>(__handle) != NULL);
43#endif
44
45 ((SQL::Param*)__handle)->setNull();
46}
47
48void SQLParam::setData(
49 _CONST void* _val, // data, IN
50 size_t _size, // sizeof *_val
51 SQL::DataType _valType, // typeof *_val
52 SQL::DataType _sqlType // assign to server type
54{
55 __DCL_ASSERT(__handle != NULL);
56#ifdef __DCL_NO_RTTI
57 __DCL_ASSERT(__handle->isKindOf(CLASSINFO(SQL::Param)));
58#else
59 __DCL_ASSERT(dynamic_cast<SQL::Param*>(__handle) != NULL);
60#endif
61
62 __DCL_ASSERT(_val != NULL);
63// __DCL_ASSERT(_size > 0); 문자열일 경우 _size는 0일 수 있다.
64
65 if (!((SQL::Param*)__handle)->setData(_val, _size, _valType, _sqlType)) {
66 throw new SQLException(this, NULL);
67 }
68}
69
70void SQLParam::setOutputType(
71 SQL::DataType _sqlType
73{
74 __DCL_ASSERT(__handle != NULL);
75 if (!((SQL::Param*)__handle)->setOutputType(_sqlType)) {
76 throw new SQLException(this, NULL);
77 }
78}
79
81void SQLParam::setValue(int8_t _val) __DCL_THROWS1(SQLException*)
82{
83 setData(
84 (_CONST void*) & _val,
85 sizeof(int8_t),
88 );
89}
90
91void SQLParam::setValue(uint8_t _val) __DCL_THROWS1(SQLException*)
92{
93 setData(
94 (_CONST void*) & _val,
95 sizeof(uint8_t),
98 );
99}
100
101void SQLParam::setValue(int16_t _val) __DCL_THROWS1(SQLException*)
102{
103 setData(
104 (_CONST void*) & _val,
105 sizeof(int16_t),
108 );
109}
110
111void SQLParam::setValue(uint16_t _val) __DCL_THROWS1(SQLException*)
112{
113 setData(
114 (_CONST void*) & _val,
115 sizeof(uint16_t),
118 );
119}
120
121void SQLParam::setValue(int32_t _val) __DCL_THROWS1(SQLException*)
122{
123 setData(
124 (_CONST void*)&_val,
125 sizeof(int32_t),
128 );
129}
130
131void SQLParam::setValue(uint32_t _val) __DCL_THROWS1(SQLException*)
132{
133 setData(
134 (_CONST void*)&_val,
135 sizeof(uint32_t),
138 );
139}
140
141void SQLParam::setValue(int64_t _val) __DCL_THROWS1(SQLException*)
142{
143 setData(
144 (_CONST void*)&_val,
145 sizeof(int64_t),
148 );
149}
150
151void SQLParam::setValue(uint64_t _val) __DCL_THROWS1(SQLException*)
152{
153 setData(
154 (_CONST void*)&_val,
155 sizeof(uint64_t),
158 );
159}
160
161void SQLParam::setValue(float _val) __DCL_THROWS1(SQLException*)
162{
163 setData(
164 (_CONST void*)&_val,
165 sizeof(float),
168 );
169}
170
171void SQLParam::setValue(double _val) __DCL_THROWS1(SQLException*)
172{
173 setData(
174 (_CONST void*)&_val,
175 sizeof(double),
178 );
179}
180
181void SQLParam::setValue(const Decimal& _val) __DCL_THROWS1(SQLException*)
182{
183 setValue(
184 _val.toString(),
186 );
187}
188
189void SQLParam::setValue(Date _val) __DCL_THROWS1(SQLException*)
190{
191 SQL::Date d;
192 int nYear, nMonth, nDay;
193
194 _val.decode(nYear, nMonth, nDay);
195
196 d.year = nYear;
197 d.month = nMonth;
198 d.day = nDay;
199
200 setData(
201 (_CONST void*)&d,
202 sizeof(SQL::Date),
205 );
206}
207
208void SQLParam::setValue(
209 Time _val,
210 int16_t _tzMinute // = INT16_MIN
212{
213 SQL::Time t;
214 int nHour, nMin, nSec, nMSec;
215
216 _val.decode(nHour, nMin, nSec, nMSec);
217
218 t.hour = nHour;
219 t.min = nMin;
220 t.sec = nSec;
221 t.frac = nMSec * 1000000;
222 t.tzoff = _tzMinute;
223
224 setData(
225 (_CONST void*) & t,
226 sizeof(SQL::Time),
229 );
230}
231
232void SQLParam::setValue(
233 DateTime _val,
234 int16_t _tzMinute // = INT16_MIN
236{
238 int nYear, nMonth, nDay, nHour, nMin, nSec, nMSec;
239 _val.date().decode(nYear, nMonth, nDay);
240 _val.time().decode(nHour, nMin, nSec, nMSec);
241
242 ts.year = nYear;
243 ts.month = nMonth;
244 ts.day = nDay;
245 ts.hour = nHour;
246 ts.min = nMin;
247 ts.sec = nSec;
248 ts.frac = nMSec * 1000000;
249 ts.tzoff = _tzMinute;
250
251 setData(
252 (_CONST void*)&ts,
253 sizeof(SQL::TimeStamp),
256 );
257}
258
259void SQLParam::setValue(
260 Interval _val,
261 SQL::DataType _sqlType // = SQL::typeIntervalDs
263{
265 || _sqlType == SQL::typeIntervalDs);
266
267 SQL::Interval iv;
268 long nDays, nMSecs;
269 _val.decode(nDays, nMSecs);
270
271 if (_sqlType == SQL::typeIntervalYm) {
272 iv.years = nDays / 360;
273 iv.months = (int8_t)((nDays % 360) / 30);
274 iv.days = 0;
275 iv.hours = 0;
276 iv.mins = 0;
277 iv.secs = 0;
278 iv.fracs = 0;
279 }
280 else {
281 iv.years = 0;
282 iv.months = 0;
283 iv.days = nDays;
284 iv.hours = (int8_t)(nMSecs / 3600000);
285 iv.mins = (int8_t)((nMSecs % 3600000) / 60000);
286 iv.secs = (int8_t)((nMSecs % 60000) / 1000);
287 iv.fracs = (nMSecs % 1000) * 1000000;
288 }
289
290 setData(
291 (_CONST void*)&iv,
292 sizeof(SQL::Interval),
294 _sqlType
295 );
296}
297
298void SQLParam::setValue(
299 const String& _val,
300 SQL::DataType _sqlType // = SQL::typeText
302{
303 setValue(_val.data(), _val.length());
304}
305
306void SQLParam::setValue(
307 const wchar_t* _val,
308 size_t _size,
309 SQL::DataType _sqlType // = SQL::typeText
311{
313 || _sqlType == SQL::typeText
314 || _sqlType == SQL::typeLongText
315 || _sqlType == SQL::typeClob
316 );
317
318 ByteString val;
319 try {
320 val = UTF8Encoder::encode(_val, _size);
321 }
322 catch (CharsetConvertException* _cause) {
323 throw new SQLException(this, _cause);
324 }
325 setValue(val, _sqlType);
326}
327
328void SQLParam::setValue(
329 const ByteString& _val,
330 SQL::DataType _sqlType // = SQL::typeBinary
332{
334 || _sqlType == SQL::typeText
335 || _sqlType == SQL::typeLongText
336 || _sqlType == SQL::typeClob
337 || _sqlType == SQL::typeBinary
338 || _sqlType == SQL::typeLongBinary
339 || _sqlType == SQL::typeBlob
340 );
341
342 // SQL::Param은 문자열을 복사하지 않을 수 있다.
343 // SQL::Param이 파괴될때까지 문자열의 참조를 보관하여 문자열이
344 // 파괴되지 않도록 한다.
345 __bytesValue = _val;
346
347 setData(
348 (_CONST void*)__bytesValue.data(),
349 __bytesValue.length(),
350 (_sqlType == SQL::typeBinary
351 || _sqlType == SQL::typeLongBinary
352 || _sqlType == SQL::typeBlob
354 _sqlType
355 );
356}
357
358void SQLParam::setValue(
359 const char* _val,
360 size_t _size,
361 SQL::DataType _sqlType // = SQL::typeBinary
363{
364 __DCL_ASSERT(_sqlType == SQL::typeText
365 || _sqlType == SQL::typeLongText
366 || _sqlType == SQL::typeClob
367 || _sqlType == SQL::typeBinary
368 || _sqlType == SQL::typeLongBinary
369 || _sqlType == SQL::typeBlob
370 );
371
372 setData(
373 (_CONST void*)_val,
374 _size,
375 (_sqlType == SQL::typeBinary
376 || _sqlType == SQL::typeLongBinary
377 || _sqlType == SQL::typeBlob
379 _sqlType
380 );
381}
382
383void SQLParam::setValue(
384 _CONST InputStream& _input,
385 size_t _size, // = (size_t)-1,
386 SQL::DataType _sqlType // = SQL::typeLongBinary
388{
389 __DCL_ASSERT(_sqlType == SQL::typeText
390 || _sqlType == SQL::typeLongText
391 || _sqlType == SQL::typeClob
392 || _sqlType == SQL::typeBinary
393 || _sqlType == SQL::typeLongBinary
394 || _sqlType == SQL::typeBlob
395 );
396
397 setData(
398 &_input,
399 _size,
401 _sqlType
402 );
403}
404
405__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
wchar_t char_t
Definition Config.h:247
#define _CONST
Definition Config.h:325
#define INT16_MIN
Definition Config.h:284
#define __DCL_THROWS1(e)
Definition Config.h:152
#define CLASSINFO(class_name)
Definition Object.h:226
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:245
#define __T(str)
Definition Object.h:60
Definition SQL.h:48
SQL::Field * __handle
Definition SQL.h:122
DataType
Definition SQLCore.h:59
@ typeBinary
Definition SQLCore.h:74
@ typeClob
Definition SQLCore.h:77
@ typeNumeric
Definition SQLCore.h:64
@ typeTime
Definition SQLCore.h:66
@ typeLongBinary
Definition SQLCore.h:76
@ typeUInteger
Definition SQLCore.h:62
@ typeTimeStamp
Definition SQLCore.h:68
@ typeBlob
Definition SQLCore.h:78
@ typeInputStream
Definition SQLCore.h:81
@ typeTimeStampTz
Definition SQLCore.h:69
@ typeInterval
Definition SQLCore.h:70
@ typeIntervalDs
Definition SQLCore.h:72
@ typeDate
Definition SQLCore.h:65
@ typeText
Definition SQLCore.h:73
@ typeTimeTz
Definition SQLCore.h:67
@ typeFloat
Definition SQLCore.h:63
@ typeInteger
Definition SQLCore.h:61
@ typeIntervalYm
Definition SQLCore.h:71
@ typeLongText
Definition SQLCore.h:75
virtual ~SQLParam()
Definition SQLParam.cpp:32
int16_t year
Definition SQLCore.h:96
uint8_t month
Definition SQLCore.h:97
uint8_t day
Definition SQLCore.h:98
int32_t years
Definition SQLCore.h:126
int32_t days
Definition SQLCore.h:128
int8_t hours
Definition SQLCore.h:129
int8_t mins
Definition SQLCore.h:130
int32_t fracs
Definition SQLCore.h:132
int8_t months
Definition SQLCore.h:127
int8_t secs
Definition SQLCore.h:131
uint8_t hour
Definition SQLCore.h:103
uint8_t sec
Definition SQLCore.h:105
uint32_t frac
Definition SQLCore.h:106
uint8_t min
Definition SQLCore.h:104
int16_t tzoff
Definition SQLCore.h:107
uint32_t frac
Definition SQLCore.h:118
int16_t tzoff
Definition SQLCore.h:119
uint8_t min
Definition SQLCore.h:116
uint8_t sec
Definition SQLCore.h:117
uint8_t hour
Definition SQLCore.h:115
uint8_t day
Definition SQLCore.h:114
int16_t year
Definition SQLCore.h:112
uint8_t month
Definition SQLCore.h:113