DCL 4.0
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(_value.toString(), SQL::typeNumeric);;
145}
146
147void SQLParam::setValue(Date _value) __DCL_THROWS1(SQLException*)
148{
149 SQL::Date d;
150 int nYear, nMonth, nDay;
151
152 _value.decode(nYear, nMonth, nDay);
153
154 d.nYear = nYear;
155 d.nMonth = nMonth;
156 d.nDay = nDay;
157
158 setData(
159 (_CONST void*)&d,
160 sizeof(SQL::Date),
163 );
164}
165
166void SQLParam::setValue(Time _value) __DCL_THROWS1(SQLException*)
167{
168 SQL::Time t;
169 int nHour, nMin, nSec, nMSec;
170
171 _value.decode(nHour, nMin, nSec, nMSec);
172
173 t.nHour = nHour;
174 t.nMin = nMin;
175 t.nSec = nSec;
176 t.nFrac = nMSec * 1000000;
177
178 setData(
179 (_CONST void*)&t,
180 sizeof(SQL::Time),
183 );
184}
185
186void SQLParam::setValue(DateTime _value) __DCL_THROWS1(SQLException*)
187{
189 int nYear, nMonth, nDay, nHour, nMin, nSec, nMSec;
190 _value.date().decode(nYear, nMonth, nDay);
191 _value.time().decode(nHour, nMin, nSec, nMSec);
192
193 ts.nYear = nYear;
194 ts.nMonth = nMonth;
195 ts.nDay = nDay;
196 ts.nHour = nHour;
197 ts.nMin = nMin;
198 ts.nSec = nSec;
199 ts.nFrac = nMSec * 1000000;
200 ts.nTzMin = 0;
201
202 setData(
203 (_CONST void*)&ts,
204 sizeof(SQL::TimeStamp),
207 );
208}
209
210void SQLParam::setValue(
211 DateTime _value,
212 int16_t _tzMinute
214{
216 int nYear, nMonth, nDay, nHour, nMin, nSec, nMSec;
217 _value.date().decode(nYear, nMonth, nDay);
218 _value.time().decode(nHour, nMin, nSec, nMSec);
219
220 ts.nYear = nYear;
221 ts.nMonth = nMonth;
222 ts.nDay = nDay;
223 ts.nHour = nHour;
224 ts.nMin = nMin;
225 ts.nSec = nSec;
226 ts.nFrac = nMSec * 1000000;
227 ts.nTzMin = _tzMinute;
228
229 setData(
230 (_CONST void*)&ts,
231 sizeof(SQL::TimeStamp),
234 );
235}
236
237void SQLParam::setValue(
238 Interval _value,
239 SQL::DataType _assignType // = SQL::typeIntervalDs
241{
242 __DCL_ASSERT(_assignType == SQL::typeInterval
243 || _assignType == SQL::typeIntervalYm
244 || _assignType == SQL::typeIntervalDs);
245
246 SQL::Interval iv;
247 long nDays, nMSecs;
248 _value.decode(nDays, nMSecs);
249
250 if (_assignType == SQL::typeIntervalYm) {
251 iv.nYears = nDays / 360;
252 iv.nMonths = (int8_t)((nDays % 360) / 30);
253 iv.nDays = 0;
254 iv.nHours = 0;
255 iv.nMins = 0;
256 iv.nSecs = 0;
257 iv.nFracs = 0;
258 }
259 else {
260 iv.nYears = 0;
261 iv.nMonths = 0;
262 iv.nDays = nDays;
263 iv.nHours = (int8_t)(nMSecs / 3600000);
264 iv.nMins = (int8_t)((nMSecs % 3600000) / 60000);
265 iv.nSecs = (int8_t)((nMSecs % 60000) / 1000);
266 iv.nFracs = (nMSecs % 1000) * 1000000;
267 }
268
269 setData(
270 (_CONST void*)&iv,
271 sizeof(SQL::Interval),
272 _assignType,
273 _assignType
274 );
275}
276
277void SQLParam::setValue(
278 const String& _value,
279 SQL::DataType _assignType // = SQL::typeText
281{
282 __DCL_ASSERT(_assignType == SQL::typeNumeric
283 || _assignType == SQL::typeText
284 || _assignType == SQL::typeLongText
285 || _assignType == SQL::typeClob);
286
287 setValue(UTF8Encoder::encode(_value), _assignType);
288}
289
290void SQLParam::setValue(
291 const wchar_t* _p,
292 size_t _n,
293 SQL::DataType _assignType // = SQL::typeText
295{
296 __DCL_ASSERT(_assignType == SQL::typeNumeric
297 || _assignType == SQL::typeText
298 || _assignType == SQL::typeLongText
299 || _assignType == SQL::typeClob);
300
301 setValue(UTF8Encoder::encode(_p, _n), _assignType);
302}
303
304void SQLParam::setValue(
305 const ByteString& _value,
306 SQL::DataType _assignType // = SQL::typeBinary
308{
309 __DCL_ASSERT(_assignType == SQL::typeNumeric
310 || _assignType == SQL::typeText
311 || _assignType == SQL::typeLongText
312 || _assignType == SQL::typeClob
313 || _assignType == SQL::typeBinary
314 || _assignType == SQL::typeLongBinary
315 || _assignType == SQL::typeBlob);
316
317 // SQL::Param은 문자열을 복사하지 않을 수 있다.
318 // SQL::Param이 파괴될때까지 문자열의 참조를 보관하여 문자열이
319 // 파괴되지 않도록 한다.
320 __bytesValue = _value;
321 SQL::DataType dataType = SQL::typeText;
322 if (_assignType == SQL::typeBinary || _assignType == SQL::typeLongBinary)
323 dataType = SQL::typeBinary;
324
325 setData(
326 (_CONST void*)__bytesValue.data(),
327 __bytesValue.length(),
328 dataType,
329 _assignType
330 );
331}
332
333void SQLParam::setValue(
334 const byte_t* _p,
335 size_t _n,
336 SQL::DataType _assignType // = SQL::typeBinary
338{
339 __DCL_ASSERT(_assignType == SQL::typeBinary
340 || _assignType == SQL::typeLongBinary
341 || _assignType == SQL::typeBlob);
342
343 setData(
344 (_CONST void*)_p,
345 _n,
347 _assignType
348 );
349}
350
351void SQLParam::setValue(
352 _CONST InputStream* _input,
353 size_t _n,
354 SQL::DataType _assignType
356{
357 __DCL_ASSERT(_assignType == SQL::typeText
358 || _assignType == SQL::typeLongText
359 || _assignType == SQL::typeClob
360 || _assignType == SQL::typeBinary
361 || _assignType == SQL::typeLongBinary
362 || _assignType == SQL::typeBlob);
363
364 setData(
365 _input,
366 _n,
368 _assignType
369 );
370}
371
372void SQLParam::setDataType(
373 SQL::DataType _dataType
375{
376 __DCL_ASSERT(this != NULL);
377 __DCL_ASSERT(__handle != NULL);
378 if (!((SQL::Param*)__handle)->setDataType(_dataType))
379 {
380 throw new SQLException(this);
381 }
382}
383
384__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
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 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:76
@ typeClob
Definition SQLCore.h:79
@ typeNumeric
Definition SQLCore.h:67
@ typeTime
Definition SQLCore.h:69
@ typeLongBinary
Definition SQLCore.h:78
@ typeUInteger
Definition SQLCore.h:65
@ typeTimeStamp
Definition SQLCore.h:70
@ typeBlob
Definition SQLCore.h:80
@ typeInputStream
Definition SQLCore.h:83
@ typeTimeStampTz
Definition SQLCore.h:71
@ typeInterval
Definition SQLCore.h:72
@ typeIntervalDs
Definition SQLCore.h:74
@ typeDate
Definition SQLCore.h:68
@ typeText
Definition SQLCore.h:75
@ typeFloat
Definition SQLCore.h:66
@ typeInteger
Definition SQLCore.h:64
@ typeIntervalYm
Definition SQLCore.h:73
@ typeLongText
Definition SQLCore.h:77
virtual ~SQLParam()
Definition SQLParam.cpp:37
uint8_t nMonth
Definition SQLCore.h:97
int16_t nYear
Definition SQLCore.h:96
uint8_t nDay
Definition SQLCore.h:98
int8_t nHours
Definition SQLCore.h:128
int32_t nFracs
Definition SQLCore.h:131
int8_t nSecs
Definition SQLCore.h:130
int8_t nMins
Definition SQLCore.h:129
int32_t nYears
Definition SQLCore.h:125
int8_t nMonths
Definition SQLCore.h:126
int32_t nDays
Definition SQLCore.h:127
uint8_t nHour
Definition SQLCore.h:103
uint8_t nMin
Definition SQLCore.h:104
uint8_t nSec
Definition SQLCore.h:105
uint32_t nFrac
Definition SQLCore.h:106
int16_t nYear
Definition SQLCore.h:111
uint8_t nDay
Definition SQLCore.h:113
uint8_t nHour
Definition SQLCore.h:114
int16_t nTzMin
Definition SQLCore.h:118
uint8_t nSec
Definition SQLCore.h:116
uint8_t nMonth
Definition SQLCore.h:112
uint8_t nMin
Definition SQLCore.h:115
uint32_t nFrac
Definition SQLCore.h:117