LibreOffice Module connectivity (master) 1
FValue.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <string.h>
25#include <com/sun/star/io/XInputStream.hpp>
26#include <com/sun/star/sdbc/XClob.hpp>
27#include <com/sun/star/sdbc/XBlob.hpp>
28#include <com/sun/star/sdb/XColumn.hpp>
29#include <com/sun/star/sdbc/XRow.hpp>
30#include <rtl/ustrbuf.hxx>
31#include <sal/log.hxx>
32#include <osl/diagnose.h>
33
34using namespace ::dbtools;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::sdb;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::util;
39using namespace ::com::sun::star::io;
40
41namespace connectivity
42{
43
44namespace {
45 bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
46 {
47 bool bIsCompatible = true;
48
49 if (_eType1 != _eType2)
50 {
51 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
52 switch (_eType1)
53 {
54 case DataType::CHAR:
55 case DataType::VARCHAR:
56 case DataType::DECIMAL:
57 case DataType::NUMERIC:
58 case DataType::LONGVARCHAR:
59 bIsCompatible = (DataType::CHAR == _eType2)
60 || (DataType::VARCHAR == _eType2)
61 || (DataType::DECIMAL == _eType2)
62 || (DataType::NUMERIC == _eType2)
63 || (DataType::LONGVARCHAR == _eType2);
64 break;
65
66 case DataType::DOUBLE:
67 case DataType::REAL:
68 bIsCompatible = (DataType::DOUBLE == _eType2)
69 || (DataType::REAL == _eType2);
70 break;
71
72 case DataType::BINARY:
73 case DataType::VARBINARY:
74 case DataType::LONGVARBINARY:
75 bIsCompatible = (DataType::BINARY == _eType2)
76 || (DataType::VARBINARY == _eType2)
77 || (DataType::LONGVARBINARY == _eType2);
78 break;
79
80 case DataType::INTEGER:
81 bIsCompatible = (DataType::SMALLINT == _eType2)
82 || (DataType::TINYINT == _eType2)
83 || (DataType::BIT == _eType2)
84 || (DataType::BOOLEAN == _eType2);
85 break;
86 case DataType::SMALLINT:
87 bIsCompatible = (DataType::TINYINT == _eType2)
88 || (DataType::BIT == _eType2)
89 || (DataType::BOOLEAN == _eType2);
90 break;
91 case DataType::TINYINT:
92 bIsCompatible = (DataType::BIT == _eType2)
93 || (DataType::BOOLEAN == _eType2);
94 break;
95
96 case DataType::BLOB:
97 case DataType::CLOB:
98 case DataType::OBJECT:
99 bIsCompatible = (DataType::BLOB == _eType2)
100 || (DataType::CLOB == _eType2)
101 || (DataType::OBJECT == _eType2);
102 break;
103
104 default:
105 bIsCompatible = false;
106 }
107 }
108 return bIsCompatible;
109 }
110
111 bool isStorageComparable(sal_Int32 _eType1, sal_Int32 _eType2)
112 {
113 bool bIsComparable = true;
114
115 if (_eType1 != _eType2)
116 {
117 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
118 switch (_eType1)
119 {
120 case DataType::CHAR:
121 case DataType::VARCHAR:
122 case DataType::LONGVARCHAR:
123 bIsComparable = (DataType::CHAR == _eType2)
124 || (DataType::VARCHAR == _eType2)
125 || (DataType::LONGVARCHAR == _eType2);
126 break;
127
128 case DataType::DECIMAL:
129 case DataType::NUMERIC:
130 bIsComparable = (DataType::DECIMAL == _eType2)
131 || (DataType::NUMERIC == _eType2);
132 break;
133
134 case DataType::DOUBLE:
135 case DataType::REAL:
136 bIsComparable = (DataType::DOUBLE == _eType2)
137 || (DataType::REAL == _eType2);
138 break;
139
140 case DataType::BINARY:
141 case DataType::VARBINARY:
142 case DataType::LONGVARBINARY:
143 bIsComparable = (DataType::BINARY == _eType2)
144 || (DataType::VARBINARY == _eType2)
145 || (DataType::LONGVARBINARY == _eType2);
146 break;
147
148 case DataType::INTEGER:
149 bIsComparable = (DataType::SMALLINT == _eType2)
150 || (DataType::TINYINT == _eType2)
151 || (DataType::BIT == _eType2)
152 || (DataType::BOOLEAN == _eType2);
153 break;
154 case DataType::SMALLINT:
155 bIsComparable = (DataType::TINYINT == _eType2)
156 || (DataType::BIT == _eType2)
157 || (DataType::BOOLEAN == _eType2);
158 break;
159 case DataType::TINYINT:
160 bIsComparable = (DataType::BIT == _eType2)
161 || (DataType::BOOLEAN == _eType2);
162 break;
163
164 case DataType::BLOB:
165 case DataType::CLOB:
166 case DataType::OBJECT:
167 bIsComparable = (DataType::BLOB == _eType2)
168 || (DataType::CLOB == _eType2)
169 || (DataType::OBJECT == _eType2);
170 break;
171
172 default:
173 bIsComparable = false;
174 }
175 }
176 return bIsComparable;
177 }
178}
179
180void ORowSetValue::setTypeKind(sal_Int32 _eType)
181{
182 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
183 {
184 switch(_eType)
185 {
186 case DataType::VARCHAR:
187 case DataType::CHAR:
188 case DataType::DECIMAL:
189 case DataType::NUMERIC:
190 case DataType::LONGVARCHAR:
191 (*this) = getString();
192 break;
193 case DataType::BIGINT:
194 {
195 sal_Int64 nVal(getLong());
196 sal_uInt64 nuVal(getULong());
197 if (nVal == 0 && nuVal != 0)
198 (*this) = nuVal;
199 else
200 (*this) = nVal;
201 break;
202 }
203
204 case DataType::FLOAT:
205 (*this) = getFloat();
206 break;
207 case DataType::DOUBLE:
208 case DataType::REAL:
209 (*this) = getDouble();
210 break;
211 case DataType::TINYINT:
212 (*this) = getInt8();
213 break;
214 case DataType::SMALLINT:
215 (*this) = getInt16();
216 break;
217 case DataType::INTEGER:
218 {
219 sal_Int32 nVal(getInt32());
220 sal_uInt32 nuVal(getUInt32());
221 if (nVal == 0 && nuVal != 0)
222 (*this) = nuVal;
223 else
224 (*this) = nVal;
225 break;
226 }
227 case DataType::BIT:
228 case DataType::BOOLEAN:
229 (*this) = getBool();
230 break;
231 case DataType::DATE:
232 (*this) = getDate();
233 break;
234 case DataType::TIME:
235 (*this) = getTime();
236 break;
237 case DataType::TIMESTAMP:
238 (*this) = getDateTime();
239 break;
240 case DataType::BINARY:
241 case DataType::VARBINARY:
242 case DataType::LONGVARBINARY:
243 (*this) = getSequence();
244 break;
245 case DataType::BLOB:
246 case DataType::CLOB:
247 case DataType::OBJECT:
248 case DataType::OTHER:
249 (*this) = makeAny();
250 break;
251 default:
252 (*this) = makeAny();
253 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
254 }
255 }
256
257 m_eTypeKind = _eType;
258}
259
260
261void ORowSetValue::free() noexcept
262{
263 if(m_bNull)
264 return;
265
266 switch(m_eTypeKind)
267 {
268 case DataType::CHAR:
269 case DataType::VARCHAR:
270 case DataType::DECIMAL:
271 case DataType::NUMERIC:
272 case DataType::LONGVARCHAR:
273 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
274 rtl_uString_release(m_aValue.m_pString);
275 m_aValue.m_pString = nullptr;
276 break;
277 case DataType::DATE:
278 delete static_cast<css::util::Date*>(m_aValue.m_pValue);
279 m_aValue.m_pValue = nullptr;
280 break;
281 case DataType::TIME:
282 delete static_cast<css::util::Time*>(m_aValue.m_pValue);
283 m_aValue.m_pValue = nullptr;
284 break;
285 case DataType::TIMESTAMP:
286 delete static_cast<css::util::DateTime*>(m_aValue.m_pValue);
287 m_aValue.m_pValue = nullptr;
288 break;
289 case DataType::BINARY:
290 case DataType::VARBINARY:
291 case DataType::LONGVARBINARY:
292 delete static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
293 m_aValue.m_pValue = nullptr;
294 break;
295 case DataType::BLOB:
296 case DataType::CLOB:
297 case DataType::OBJECT:
298 delete static_cast<Any*>(m_aValue.m_pValue);
299 m_aValue.m_pValue = nullptr;
300 break;
301 case DataType::BIT:
302 case DataType::TINYINT:
303 case DataType::SMALLINT:
304 case DataType::INTEGER:
305 case DataType::BIGINT:
306 case DataType::BOOLEAN:
307 case DataType::FLOAT:
308 case DataType::DOUBLE:
309 case DataType::REAL:
310 break;
311 default:
312 if ( m_aValue.m_pValue )
313 {
314 delete static_cast<Any*>(m_aValue.m_pValue);
315 m_aValue.m_pValue = nullptr;
316 }
317 break;
318
319 }
320 m_bNull = true;
321}
322
324{
325 if(&_rRH == this)
326 return *this;
327
328 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
329 free();
330
331 m_bBound = _rRH.m_bBound;
333 m_bSigned = _rRH.m_bSigned;
334
335 if(m_bNull && !_rRH.m_bNull)
336 {
337 switch(_rRH.m_eTypeKind)
338 {
339 case DataType::CHAR:
340 case DataType::VARCHAR:
341 case DataType::DECIMAL:
342 case DataType::NUMERIC:
343 case DataType::LONGVARCHAR:
344 rtl_uString_acquire(_rRH.m_aValue.m_pString);
345 m_aValue.m_pString = _rRH.m_aValue.m_pString;
346 break;
347 case DataType::DATE:
348 m_aValue.m_pValue = new Date(*static_cast<Date*>(_rRH.m_aValue.m_pValue));
349 break;
350 case DataType::TIME:
351 m_aValue.m_pValue = new Time(*static_cast<Time*>(_rRH.m_aValue.m_pValue));
352 break;
353 case DataType::TIMESTAMP:
354 m_aValue.m_pValue = new DateTime(*static_cast<DateTime*>(_rRH.m_aValue.m_pValue));
355 break;
356 case DataType::BINARY:
357 case DataType::VARBINARY:
358 case DataType::LONGVARBINARY:
359 m_aValue.m_pValue = new Sequence<sal_Int8>(*static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue));
360 break;
361 case DataType::BIT:
362 case DataType::BOOLEAN:
363 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
364 break;
365 case DataType::TINYINT:
366 if ( _rRH.m_bSigned )
367 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
368 else
369 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
370 break;
371 case DataType::SMALLINT:
372 if ( _rRH.m_bSigned )
373 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
374 else
375 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
376 break;
377 case DataType::INTEGER:
378 if ( _rRH.m_bSigned )
379 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
380 else
381 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
382 break;
383 case DataType::BIGINT:
384 if ( _rRH.m_bSigned )
385 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
386 else
387 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
388 break;
389 case DataType::FLOAT:
390 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
391 break;
392 case DataType::DOUBLE:
393 case DataType::REAL:
394 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
395 break;
396 default:
397 m_aValue.m_pValue = new Any(*static_cast<Any*>(_rRH.m_aValue.m_pValue));
398 }
399 }
400 else if(!_rRH.m_bNull)
401 {
402 switch(_rRH.m_eTypeKind)
403 {
404 case DataType::CHAR:
405 case DataType::VARCHAR:
406 case DataType::DECIMAL:
407 case DataType::NUMERIC:
408 case DataType::LONGVARCHAR:
409 (*this) = OUString(_rRH.m_aValue.m_pString);
410 break;
411 case DataType::DATE:
412 (*this) = *static_cast<Date*>(_rRH.m_aValue.m_pValue);
413 break;
414 case DataType::TIME:
415 (*this) = *static_cast<Time*>(_rRH.m_aValue.m_pValue);
416 break;
417 case DataType::TIMESTAMP:
418 (*this) = *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
419 break;
420 case DataType::BINARY:
421 case DataType::VARBINARY:
422 case DataType::LONGVARBINARY:
423 (*this) = *static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue);
424 break;
425 case DataType::BIT:
426 case DataType::BOOLEAN:
427 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
428 break;
429 case DataType::TINYINT:
430 if ( _rRH.m_bSigned )
431 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
432 else
433 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
434 break;
435 case DataType::SMALLINT:
436 if ( _rRH.m_bSigned )
437 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
438 else
439 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
440 break;
441 case DataType::INTEGER:
442 if ( _rRH.m_bSigned )
443 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
444 else
445 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
446 break;
447 case DataType::BIGINT:
448 if ( _rRH.m_bSigned )
449 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
450 else
451 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
452 break;
453 case DataType::FLOAT:
454 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
455 break;
456 case DataType::DOUBLE:
457 case DataType::REAL:
458 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
459 break;
460 default:
461 *static_cast<Any*>(m_aValue.m_pValue) = *static_cast<Any*>(_rRH.m_aValue.m_pValue);
462 }
463 }
464
465 m_bNull = _rRH.m_bNull;
466 // OJ: BUGID: 96277
468
469 return *this;
470}
471
473{
474 if ( m_eTypeKind != _rRH.m_eTypeKind || !m_bNull)
475 free();
476 if(!_rRH.m_bNull)
477 {
478 m_aValue = _rRH.m_aValue;
479 memset(&_rRH.m_aValue, 0, sizeof(_rRH.m_aValue));
480 }
481 m_bBound = _rRH.m_bBound;
482 m_eTypeKind = _rRH.m_eTypeKind;
483 m_bSigned = _rRH.m_bSigned;
484 m_bNull = _rRH.m_bNull;
485 _rRH.m_bNull = true;
486 return *this;
487}
488
489
491{
492 if(m_eTypeKind != DataType::DATE)
493 free();
494
495 if(m_bNull)
496 {
497 m_aValue.m_pValue = new Date(_rRH);
498 m_eTypeKind = DataType::DATE;
499 m_bNull = false;
500 }
501 else
502 *static_cast<Date*>(m_aValue.m_pValue) = _rRH;
503
504 return *this;
505}
506
507ORowSetValue& ORowSetValue::operator=(const css::util::Time& _rRH)
508{
509 if(m_eTypeKind != DataType::TIME)
510 free();
511
512 if(m_bNull)
513 {
514 m_aValue.m_pValue = new Time(_rRH);
515 m_eTypeKind = DataType::TIME;
516 m_bNull = false;
517 }
518 else
519 *static_cast<Time*>(m_aValue.m_pValue) = _rRH;
520
521 return *this;
522}
523
525{
526 if(m_eTypeKind != DataType::TIMESTAMP)
527 free();
528 if(m_bNull)
529 {
530 m_aValue.m_pValue = new DateTime(_rRH);
531 m_eTypeKind = DataType::TIMESTAMP;
532 m_bNull = false;
533 }
534 else
535 *static_cast<DateTime*>(m_aValue.m_pValue) = _rRH;
536
537 return *this;
538}
539
540
542{
543 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
544 {
545 free();
546 m_bNull = false;
547
548 m_aValue.m_pString = _rRH.pData;
549 rtl_uString_acquire(m_aValue.m_pString);
550 m_eTypeKind = DataType::VARCHAR;
551 }
552
553 return *this;
554}
555
556
558{
559 if(m_eTypeKind != DataType::DOUBLE)
560 free();
561
562 m_aValue.m_nDouble = _rRH;
563 m_eTypeKind = DataType::DOUBLE;
564 m_bNull = false;
565
566 return *this;
567}
568
570{
571 if(m_eTypeKind != DataType::FLOAT)
572 free();
573
574 m_aValue.m_nFloat = _rRH;
575 m_eTypeKind = DataType::FLOAT;
576 m_bNull = false;
577
578 return *this;
579}
580
581
583{
584 if(m_eTypeKind != DataType::TINYINT )
585 free();
586
587 m_aValue.m_nInt8 = _rRH;
588 m_eTypeKind = DataType::TINYINT;
589 m_bNull = false;
590 m_bSigned = true;
591 return *this;
592}
593
595{
596 if(m_eTypeKind != DataType::SMALLINT )
597 free();
598
599 m_aValue.m_nInt16 = _rRH;
600 m_eTypeKind = DataType::SMALLINT;
601 m_bNull = false;
602 m_bSigned = true;
603
604 return *this;
605}
606
607
609{
610 if(m_eTypeKind != DataType::SMALLINT )
611 free();
612
613 m_aValue.m_uInt16 = _rRH;
614 m_eTypeKind = DataType::SMALLINT;
615 m_bNull = false;
616 m_bSigned = false;
617
618 return *this;
619}
620
621
623{
624 if(m_eTypeKind != DataType::INTEGER )
625 free();
626
627 m_aValue.m_nInt32 = _rRH;
628
629 m_eTypeKind = DataType::INTEGER;
630 m_bNull = false;
631 m_bSigned = true;
632
633 return *this;
634}
635
636
638{
639 if(m_eTypeKind != DataType::INTEGER )
640 free();
641
642 m_aValue.m_uInt32 = _rRH;
643
644 m_eTypeKind = DataType::INTEGER;
645 m_bNull = false;
646 m_bSigned = false;
647
648 return *this;
649}
650
651
653{
654 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
655 free();
656
657 m_aValue.m_bBool = _rRH;
658 m_eTypeKind = DataType::BOOLEAN;
659 m_bNull = false;
660
661 return *this;
662}
663
665{
666 if ( DataType::BIGINT != m_eTypeKind)
667 free();
668
669 m_aValue.m_nInt64 = _rRH;
670 m_eTypeKind = DataType::BIGINT;
671 m_bNull = false;
672 m_bSigned = true;
673
674 return *this;
675}
676
678{
679 if ( DataType::BIGINT != m_eTypeKind)
680 free();
681
682 m_aValue.m_uInt64 = _rRH;
683 m_eTypeKind = DataType::BIGINT;
684 m_bNull = false;
685 m_bSigned = false;
686
687 return *this;
688}
689
690ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
691{
692 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
693 free();
694
695 if (m_bNull)
696 {
697 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
698 }
699 else
700 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
701
702 m_eTypeKind = DataType::LONGVARBINARY;
703 m_bNull = false;
704
705 return *this;
706}
707
708ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
709{
710 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
711 free();
712
713 if ( m_bNull )
714 {
715 m_aValue.m_pValue = new Any(_rAny);
716 }
717 else
718 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
719
720 m_eTypeKind = DataType::OBJECT;
721 m_bNull = false;
722
723 return *this;
724}
725
726
728{
729 if ( m_bNull != _rRH.isNull() )
730 return false;
731
732 if(m_bNull && _rRH.isNull())
733 return true;
734
735 if ( !isStorageComparable(m_eTypeKind, _rRH.m_eTypeKind ))
736 {
737 switch(m_eTypeKind)
738 {
739 case DataType::FLOAT:
740 case DataType::DOUBLE:
741 case DataType::REAL:
742 return getDouble() == _rRH.getDouble();
743 default:
744 switch(_rRH.m_eTypeKind)
745 {
746 case DataType::FLOAT:
747 case DataType::DOUBLE:
748 case DataType::REAL:
749 return getDouble() == _rRH.getDouble();
750 default:
751 break;
752 }
753 break;
754 }
755 return false;
756 }
757
758 bool bRet = false;
759 OSL_ENSURE(!m_bNull,"Should not be null!");
760 switch(m_eTypeKind)
761 {
762 case DataType::VARCHAR:
763 case DataType::CHAR:
764 case DataType::LONGVARCHAR:
765 {
766 OUString aVal1(m_aValue.m_pString);
767 OUString aVal2(_rRH.m_aValue.m_pString);
768 return aVal1 == aVal2;
769 }
770 default:
771 if ( m_bSigned != _rRH.m_bSigned )
772 return false;
773 break;
774 }
775
776 switch(m_eTypeKind)
777 {
778 case DataType::DECIMAL:
779 case DataType::NUMERIC:
780 {
781 OUString aVal1(m_aValue.m_pString);
782 OUString aVal2(_rRH.m_aValue.m_pString);
783 bRet = aVal1 == aVal2;
784 }
785 break;
786 case DataType::FLOAT:
787 bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
788 break;
789 case DataType::DOUBLE:
790 case DataType::REAL:
791 bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
792 break;
793 case DataType::TINYINT:
794 bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
795 break;
796 case DataType::SMALLINT:
797 bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_uInt16 == _rRH.m_aValue.m_uInt16);
798 break;
799 case DataType::INTEGER:
800 bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (m_aValue.m_uInt32 == _rRH.m_aValue.m_uInt32);
801 break;
802 case DataType::BIGINT:
803 bRet = m_bSigned ? ( m_aValue.m_nInt64 == _rRH.m_aValue.m_nInt64 ) : (m_aValue.m_uInt64 == _rRH.m_aValue.m_uInt64);
804 break;
805 case DataType::BIT:
806 case DataType::BOOLEAN:
807 bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
808 break;
809 case DataType::DATE:
810 bRet = *static_cast<Date*>(m_aValue.m_pValue) == *static_cast<Date*>(_rRH.m_aValue.m_pValue);
811 break;
812 case DataType::TIME:
813 bRet = *static_cast<Time*>(m_aValue.m_pValue) == *static_cast<Time*>(_rRH.m_aValue.m_pValue);
814 break;
815 case DataType::TIMESTAMP:
816 bRet = *static_cast<DateTime*>(m_aValue.m_pValue) == *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
817 break;
818 case DataType::BINARY:
819 case DataType::VARBINARY:
820 case DataType::LONGVARBINARY:
821 bRet = false;
822 break;
823 case DataType::BLOB:
824 case DataType::CLOB:
825 case DataType::OBJECT:
826 case DataType::OTHER:
827 bRet = false;
828 break;
829 default:
830 bRet = false;
831 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
832 break;
833 }
834 return bRet;
835}
836
838{
839 Any rValue;
840 if(isBound() && !isNull())
841 {
842 switch(getTypeKind())
843 {
844 case DataType::SQLNULL:
845 assert(rValue == Any());
846 break;
847 case DataType::CHAR:
848 case DataType::VARCHAR:
849 case DataType::DECIMAL:
850 case DataType::NUMERIC:
851 case DataType::LONGVARCHAR:
852 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
853 rValue <<= OUString(m_aValue.m_pString);
854 break;
855 case DataType::FLOAT:
856 rValue <<= m_aValue.m_nFloat;
857 break;
858 case DataType::DOUBLE:
859 case DataType::REAL:
860 rValue <<= m_aValue.m_nDouble;
861 break;
862 case DataType::DATE:
863 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
864 rValue <<= *static_cast<Date*>(m_aValue.m_pValue);
865 break;
866 case DataType::TIME:
867 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
868 rValue <<= *static_cast<Time*>(m_aValue.m_pValue);
869 break;
870 case DataType::TIMESTAMP:
871 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
872 rValue <<= *static_cast<DateTime*>(m_aValue.m_pValue);
873 break;
874 case DataType::BINARY:
875 case DataType::VARBINARY:
876 case DataType::LONGVARBINARY:
877 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
878 rValue <<= *static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
879 break;
880 case DataType::BLOB:
881 case DataType::CLOB:
882 case DataType::OBJECT:
883 case DataType::OTHER:
884 rValue = getAny();
885 break;
886 case DataType::BIT:
887 case DataType::BOOLEAN:
888 rValue <<= m_aValue.m_bBool;
889 break;
890 case DataType::TINYINT:
891 if ( m_bSigned )
892 // TypeClass_BYTE
893 rValue <<= m_aValue.m_nInt8;
894 else
895 // There is no TypeClass_UNSIGNED_BYTE,
896 // so silently promote it to a 16-bit integer,
897 // that is TypeClass_UNSIGNED_SHORT
898 rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
899 break;
900 case DataType::SMALLINT:
901 if ( m_bSigned )
902 // TypeClass_SHORT
903 rValue <<= m_aValue.m_nInt16;
904 else
905 // TypeClass_UNSIGNED_SHORT
906 rValue <<= m_aValue.m_uInt16;
907 break;
908 case DataType::INTEGER:
909 if ( m_bSigned )
910 // TypeClass_LONG
911 rValue <<= m_aValue.m_nInt32;
912 else
913 // TypeClass_UNSIGNED_LONG
914 rValue <<= m_aValue.m_uInt32;
915 break;
916 case DataType::BIGINT:
917 if ( m_bSigned )
918 // TypeClass_HYPER
919 rValue <<= m_aValue.m_nInt64;
920 else
921 // TypeClass_UNSIGNED_HYPER
922 rValue <<= m_aValue.m_uInt64;
923 break;
924 default:
925 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
926 rValue = getAny();
927 break;
928 }
929 }
930 return rValue;
931}
932
933OUString ORowSetValue::getString( ) const
934{
935 OUString aRet;
936 if(!m_bNull)
937 {
938 switch(getTypeKind())
939 {
940 case DataType::CHAR:
941 case DataType::VARCHAR:
942 case DataType::DECIMAL:
943 case DataType::NUMERIC:
944 case DataType::LONGVARCHAR:
945 aRet = m_aValue.m_pString;
946 break;
947 case DataType::FLOAT:
948 aRet = OUString::number(getFloat());
949 break;
950 case DataType::DOUBLE:
951 case DataType::REAL:
952 aRet = OUString::number(getDouble());
953 break;
954 case DataType::DATE:
956 break;
957 case DataType::TIME:
959 break;
960 case DataType::TIMESTAMP:
962 break;
963 case DataType::BINARY:
964 case DataType::VARBINARY:
965 case DataType::LONGVARBINARY:
966 {
967 OUStringBuffer sVal("0x");
968 Sequence<sal_Int8> aSeq(getSequence());
969 const sal_Int8* pBegin = aSeq.getConstArray();
970 const sal_Int8* pEnd = pBegin + aSeq.getLength();
971 for(;pBegin != pEnd;++pBegin)
972 sVal.append(static_cast<sal_Int32>(*pBegin),16);
973 aRet = sVal.makeStringAndClear();
974 }
975 break;
976 case DataType::BIT:
977 aRet = OUString::number(int(getBool()));
978 break;
979 case DataType::BOOLEAN:
980 aRet = OUString::boolean(getBool());
981 break;
982 case DataType::TINYINT:
983 case DataType::SMALLINT:
984 case DataType::INTEGER:
985 if ( m_bSigned )
986 aRet = OUString::number(getInt32());
987 else
988 aRet = OUString::number(getUInt32());
989 break;
990 case DataType::BIGINT:
991 if ( m_bSigned )
992 aRet = OUString::number(getLong());
993 else
994 aRet = OUString::number(getULong());
995 break;
996 case DataType::CLOB:
997 {
998 Any aValue( getAny() );
999 Reference< XClob > xClob;
1000 if ( (aValue >>= xClob) && xClob.is() )
1001 {
1002 aRet = xClob->getSubString(1,static_cast<sal_Int32>(xClob->length()) );
1003 }
1004 }
1005 break;
1006 default:
1007 {
1008 Any aValue = makeAny();
1009 aValue >>= aRet;
1010 break;
1011 }
1012 }
1013 }
1014 return aRet;
1015}
1016
1018{
1019 bool bRet = false;
1020 if(!m_bNull)
1021 {
1022 switch(getTypeKind())
1023 {
1024 case DataType::CHAR:
1025 case DataType::VARCHAR:
1026 case DataType::LONGVARCHAR:
1027 {
1028 const OUString sValue(m_aValue.m_pString);
1029 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1030 {
1031 bRet = true;
1032 break;
1033 }
1034 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1035 {
1036 bRet = false;
1037 break;
1038 }
1039 }
1040 [[fallthrough]];
1041 case DataType::DECIMAL:
1042 case DataType::NUMERIC:
1043
1044 bRet = OUString::unacquired(&m_aValue.m_pString).toInt32() != 0;
1045 break;
1046 case DataType::FLOAT:
1047 bRet = m_aValue.m_nFloat != 0.0;
1048 break;
1049 case DataType::DOUBLE:
1050 case DataType::REAL:
1051 bRet = m_aValue.m_nDouble != 0.0;
1052 break;
1053 case DataType::DATE:
1054 case DataType::TIME:
1055 case DataType::TIMESTAMP:
1056 case DataType::BINARY:
1057 case DataType::VARBINARY:
1058 case DataType::LONGVARBINARY:
1059 OSL_FAIL("getBool() for this type is not allowed!");
1060 break;
1061 case DataType::BIT:
1062 case DataType::BOOLEAN:
1063 bRet = m_aValue.m_bBool;
1064 break;
1065 case DataType::TINYINT:
1066 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_uInt8 != 0);
1067 break;
1068 case DataType::SMALLINT:
1069 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_uInt16 != 0);
1070 break;
1071 case DataType::INTEGER:
1072 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1073 break;
1074 case DataType::BIGINT:
1075 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1076 break;
1077 default:
1078 {
1079 Any aValue = makeAny();
1080 aValue >>= bRet;
1081 break;
1082 }
1083 }
1084 }
1085 return bRet;
1086}
1087
1088
1090{
1091 sal_Int8 nRet = 0;
1092 if(!m_bNull)
1093 {
1094 switch(getTypeKind())
1095 {
1096 case DataType::CHAR:
1097 case DataType::VARCHAR:
1098 case DataType::DECIMAL:
1099 case DataType::NUMERIC:
1100 case DataType::LONGVARCHAR:
1101 nRet = sal_Int8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1102 break;
1103 case DataType::FLOAT:
1104 nRet = sal_Int8(m_aValue.m_nFloat);
1105 break;
1106 case DataType::DOUBLE:
1107 case DataType::REAL:
1108 nRet = sal_Int8(m_aValue.m_nDouble);
1109 break;
1110 case DataType::DATE:
1111 case DataType::TIME:
1112 case DataType::TIMESTAMP:
1113 case DataType::BINARY:
1114 case DataType::VARBINARY:
1115 case DataType::LONGVARBINARY:
1116 case DataType::BLOB:
1117 case DataType::CLOB:
1118 OSL_FAIL("getInt8() for this type is not allowed!");
1119 break;
1120 case DataType::BIT:
1121 case DataType::BOOLEAN:
1122 nRet = sal_Int8(m_aValue.m_bBool);
1123 break;
1124 case DataType::TINYINT:
1125 if ( m_bSigned )
1126 nRet = m_aValue.m_nInt8;
1127 else
1128 nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1129 break;
1130 case DataType::SMALLINT:
1131 if ( m_bSigned )
1132 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1133 else
1134 nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1135 break;
1136 case DataType::INTEGER:
1137 if ( m_bSigned )
1138 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1139 else
1140 nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1141 break;
1142 case DataType::BIGINT:
1143 if ( m_bSigned )
1144 nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1145 else
1146 nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1147 break;
1148 default:
1149 {
1150 Any aValue = makeAny();
1151 aValue >>= nRet;
1152 break;
1153 }
1154 }
1155 }
1156 return nRet;
1157}
1158
1159
1161{
1162 sal_uInt8 nRet = 0;
1163 if(!m_bNull)
1164 {
1165 switch(getTypeKind())
1166 {
1167 case DataType::CHAR:
1168 case DataType::VARCHAR:
1169 case DataType::DECIMAL:
1170 case DataType::NUMERIC:
1171 case DataType::LONGVARCHAR:
1172 nRet = sal_uInt8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1173 break;
1174 case DataType::FLOAT:
1175 nRet = sal_uInt8(m_aValue.m_nFloat);
1176 break;
1177 case DataType::DOUBLE:
1178 case DataType::REAL:
1179 nRet = sal_uInt8(m_aValue.m_nDouble);
1180 break;
1181 case DataType::DATE:
1182 case DataType::TIME:
1183 case DataType::TIMESTAMP:
1184 case DataType::BINARY:
1185 case DataType::VARBINARY:
1186 case DataType::LONGVARBINARY:
1187 case DataType::BLOB:
1188 case DataType::CLOB:
1189 OSL_FAIL("getuInt8() for this type is not allowed!");
1190 break;
1191 case DataType::BIT:
1192 case DataType::BOOLEAN:
1193 nRet = int(m_aValue.m_bBool);
1194 break;
1195 case DataType::TINYINT:
1196 if ( m_bSigned )
1197 nRet = m_aValue.m_nInt8;
1198 else
1199 nRet = m_aValue.m_uInt8;
1200 break;
1201 case DataType::SMALLINT:
1202 if ( m_bSigned )
1203 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1204 else
1205 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1206 break;
1207 case DataType::INTEGER:
1208 if ( m_bSigned )
1209 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1210 else
1211 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1212 break;
1213 case DataType::BIGINT:
1214 if ( m_bSigned )
1215 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1216 else
1217 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1218 break;
1219 default:
1220 {
1221 Any aValue = makeAny();
1222 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1223 sal_uInt16 n;
1224 if (aValue >>= n) {
1225 nRet = static_cast<sal_uInt8>(n);
1226 }
1227 break;
1228 }
1229 }
1230 }
1231 return nRet;
1232}
1233
1234
1235sal_Int16 ORowSetValue::getInt16() const
1236{
1237 sal_Int16 nRet = 0;
1238 if(!m_bNull)
1239 {
1240 switch(getTypeKind())
1241 {
1242 case DataType::CHAR:
1243 case DataType::VARCHAR:
1244 case DataType::DECIMAL:
1245 case DataType::NUMERIC:
1246 case DataType::LONGVARCHAR:
1247 nRet = sal_Int16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1248 break;
1249 case DataType::FLOAT:
1250 nRet = sal_Int16(m_aValue.m_nFloat);
1251 break;
1252 case DataType::DOUBLE:
1253 case DataType::REAL:
1254 nRet = sal_Int16(m_aValue.m_nDouble);
1255 break;
1256 case DataType::DATE:
1257 case DataType::TIME:
1258 case DataType::TIMESTAMP:
1259 case DataType::BINARY:
1260 case DataType::VARBINARY:
1261 case DataType::LONGVARBINARY:
1262 case DataType::BLOB:
1263 case DataType::CLOB:
1264 OSL_FAIL("getInt16() for this type is not allowed!");
1265 break;
1266 case DataType::BIT:
1267 case DataType::BOOLEAN:
1268 nRet = sal_Int16(m_aValue.m_bBool);
1269 break;
1270 case DataType::TINYINT:
1271 if ( m_bSigned )
1272 nRet = m_aValue.m_nInt8;
1273 else
1274 nRet = m_aValue.m_uInt8;
1275 break;
1276 case DataType::SMALLINT:
1277 if ( m_bSigned )
1278 nRet = m_aValue.m_nInt16;
1279 else
1280 nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1281 break;
1282 case DataType::INTEGER:
1283 if ( m_bSigned )
1284 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1285 else
1286 nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1287 break;
1288 case DataType::BIGINT:
1289 if ( m_bSigned )
1290 nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1291 else
1292 nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1293 break;
1294 default:
1295 {
1296 Any aValue = makeAny();
1297 aValue >>= nRet;
1298 break;
1299 }
1300 }
1301 }
1302 return nRet;
1303}
1304
1305
1306sal_uInt16 ORowSetValue::getUInt16() const
1307{
1308 sal_uInt16 nRet = 0;
1309 if(!m_bNull)
1310 {
1311 switch(getTypeKind())
1312 {
1313 case DataType::CHAR:
1314 case DataType::VARCHAR:
1315 case DataType::DECIMAL:
1316 case DataType::NUMERIC:
1317 case DataType::LONGVARCHAR:
1318 nRet = sal_uInt16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1319 break;
1320 case DataType::FLOAT:
1321 nRet = sal_uInt16(m_aValue.m_nFloat);
1322 break;
1323 case DataType::DOUBLE:
1324 case DataType::REAL:
1325 nRet = sal_uInt16(m_aValue.m_nDouble);
1326 break;
1327 case DataType::DATE:
1328 case DataType::TIME:
1329 case DataType::TIMESTAMP:
1330 case DataType::BINARY:
1331 case DataType::VARBINARY:
1332 case DataType::LONGVARBINARY:
1333 case DataType::BLOB:
1334 case DataType::CLOB:
1335 OSL_FAIL("getuInt16() for this type is not allowed!");
1336 break;
1337 case DataType::BIT:
1338 case DataType::BOOLEAN:
1339 nRet = sal_uInt16(m_aValue.m_bBool);
1340 break;
1341 case DataType::TINYINT:
1342 if ( m_bSigned )
1343 nRet = m_aValue.m_nInt8;
1344 else
1345 nRet = m_aValue.m_uInt8;
1346 break;
1347 case DataType::SMALLINT:
1348 if ( m_bSigned )
1349 nRet = m_aValue.m_nInt16;
1350 else
1351 nRet = m_aValue.m_uInt16;
1352 break;
1353 case DataType::INTEGER:
1354 if ( m_bSigned )
1355 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1356 else
1357 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1358 break;
1359 case DataType::BIGINT:
1360 if ( m_bSigned )
1361 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1362 else
1363 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1364 break;
1365 default:
1366 {
1367 Any aValue = makeAny();
1368 aValue >>= nRet;
1369 break;
1370 }
1371 }
1372 }
1373 return nRet;
1374}
1375
1376
1377sal_Int32 ORowSetValue::getInt32() const
1378{
1379 sal_Int32 nRet = 0;
1380 if(!m_bNull)
1381 {
1382 switch(getTypeKind())
1383 {
1384 case DataType::CHAR:
1385 case DataType::VARCHAR:
1386 case DataType::DECIMAL:
1387 case DataType::NUMERIC:
1388 case DataType::LONGVARCHAR:
1389 nRet = OUString::unacquired(&m_aValue.m_pString).toInt32();
1390 break;
1391 case DataType::FLOAT:
1392 nRet = sal_Int32(m_aValue.m_nFloat);
1393 break;
1394 case DataType::DOUBLE:
1395 case DataType::REAL:
1396 nRet = sal_Int32(m_aValue.m_nDouble);
1397 break;
1398 case DataType::DATE:
1399 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1400 break;
1401 case DataType::TIME:
1402 case DataType::TIMESTAMP:
1403 case DataType::BINARY:
1404 case DataType::VARBINARY:
1405 case DataType::LONGVARBINARY:
1406 case DataType::BLOB:
1407 case DataType::CLOB:
1408 OSL_FAIL("getInt32() for this type is not allowed!");
1409 break;
1410 case DataType::BIT:
1411 case DataType::BOOLEAN:
1412 nRet = sal_Int32(m_aValue.m_bBool);
1413 break;
1414 case DataType::TINYINT:
1415 if ( m_bSigned )
1416 nRet = m_aValue.m_nInt8;
1417 else
1418 nRet = m_aValue.m_uInt8;
1419 break;
1420 case DataType::SMALLINT:
1421 if ( m_bSigned )
1422 nRet = m_aValue.m_nInt16;
1423 else
1424 nRet = m_aValue.m_uInt16;
1425 break;
1426 case DataType::INTEGER:
1427 if ( m_bSigned )
1428 nRet = m_aValue.m_nInt32;
1429 else
1430 nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1431 break;
1432 case DataType::BIGINT:
1433 if ( m_bSigned )
1434 nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1435 else
1436 nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1437 break;
1438 default:
1439 {
1440 Any aValue = makeAny();
1441 aValue >>= nRet;
1442 break;
1443 }
1444 }
1445 }
1446 return nRet;
1447}
1448
1449
1450sal_uInt32 ORowSetValue::getUInt32() const
1451{
1452 sal_uInt32 nRet = 0;
1453 if(!m_bNull)
1454 {
1455 switch(getTypeKind())
1456 {
1457 case DataType::CHAR:
1458 case DataType::VARCHAR:
1459 case DataType::DECIMAL:
1460 case DataType::NUMERIC:
1461 case DataType::LONGVARCHAR:
1462 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt32();
1463 break;
1464 case DataType::FLOAT:
1465 nRet = sal_uInt32(m_aValue.m_nFloat);
1466 break;
1467 case DataType::DOUBLE:
1468 case DataType::REAL:
1469 nRet = sal_uInt32(m_aValue.m_nDouble);
1470 break;
1471 case DataType::DATE:
1472 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1473 break;
1474 case DataType::TIME:
1475 case DataType::TIMESTAMP:
1476 case DataType::BINARY:
1477 case DataType::VARBINARY:
1478 case DataType::LONGVARBINARY:
1479 case DataType::BLOB:
1480 case DataType::CLOB:
1481 OSL_FAIL("getuInt32() for this type is not allowed!");
1482 break;
1483 case DataType::BIT:
1484 case DataType::BOOLEAN:
1485 nRet = sal_uInt32(m_aValue.m_bBool);
1486 break;
1487 case DataType::TINYINT:
1488 if ( m_bSigned )
1489 nRet = m_aValue.m_nInt8;
1490 else
1491 nRet = m_aValue.m_uInt8;
1492 break;
1493 case DataType::SMALLINT:
1494 if ( m_bSigned )
1495 nRet = m_aValue.m_nInt16;
1496 else
1497 nRet = m_aValue.m_uInt16;
1498 break;
1499 case DataType::INTEGER:
1500 if ( m_bSigned )
1501 nRet = m_aValue.m_nInt32;
1502 else
1503 nRet = m_aValue.m_uInt32;
1504 break;
1505 case DataType::BIGINT:
1506 if ( m_bSigned )
1507 nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1508 else
1509 nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1510 break;
1511 default:
1512 {
1513 Any aValue = makeAny();
1514 aValue >>= nRet;
1515 break;
1516 }
1517 }
1518 }
1519 return nRet;
1520}
1521
1522
1523sal_Int64 ORowSetValue::getLong() const
1524{
1525 sal_Int64 nRet = 0;
1526 if(!m_bNull)
1527 {
1528 switch(getTypeKind())
1529 {
1530 case DataType::CHAR:
1531 case DataType::VARCHAR:
1532 case DataType::DECIMAL:
1533 case DataType::NUMERIC:
1534 case DataType::LONGVARCHAR:
1535 nRet = OUString::unacquired(&m_aValue.m_pString).toInt64();
1536 break;
1537 case DataType::FLOAT:
1538 nRet = sal_Int64(m_aValue.m_nFloat);
1539 break;
1540 case DataType::DOUBLE:
1541 case DataType::REAL:
1542 nRet = sal_Int64(m_aValue.m_nDouble);
1543 break;
1544 case DataType::DATE:
1545 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1546 break;
1547 case DataType::TIME:
1548 case DataType::TIMESTAMP:
1549 case DataType::BINARY:
1550 case DataType::VARBINARY:
1551 case DataType::LONGVARBINARY:
1552 case DataType::BLOB:
1553 case DataType::CLOB:
1554 OSL_FAIL("getLong() for this type is not allowed!");
1555 break;
1556 case DataType::BIT:
1557 case DataType::BOOLEAN:
1558 nRet = sal_Int64(m_aValue.m_bBool);
1559 break;
1560 case DataType::TINYINT:
1561 if ( m_bSigned )
1562 nRet = m_aValue.m_nInt8;
1563 else
1564 nRet = m_aValue.m_uInt8;
1565 break;
1566 case DataType::SMALLINT:
1567 if ( m_bSigned )
1568 nRet = m_aValue.m_nInt16;
1569 else
1570 nRet = m_aValue.m_uInt16;
1571 break;
1572 case DataType::INTEGER:
1573 if ( m_bSigned )
1574 nRet = m_aValue.m_nInt32;
1575 else
1576 nRet = m_aValue.m_uInt32;
1577 break;
1578 case DataType::BIGINT:
1579 if ( m_bSigned )
1580 nRet = m_aValue.m_nInt64;
1581 else
1582 nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1583 break;
1584 default:
1585 {
1586 Any aValue = makeAny();
1587 aValue >>= nRet;
1588 break;
1589 }
1590 }
1591 }
1592 return nRet;
1593}
1594
1595
1596sal_uInt64 ORowSetValue::getULong() const
1597{
1598 sal_uInt64 nRet = 0;
1599 if(!m_bNull)
1600 {
1601 switch(getTypeKind())
1602 {
1603 case DataType::CHAR:
1604 case DataType::VARCHAR:
1605 case DataType::DECIMAL:
1606 case DataType::NUMERIC:
1607 case DataType::LONGVARCHAR:
1608 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt64();
1609 break;
1610 case DataType::FLOAT:
1611 nRet = sal_uInt64(m_aValue.m_nFloat);
1612 break;
1613 case DataType::DOUBLE:
1614 case DataType::REAL:
1615 nRet = sal_uInt64(m_aValue.m_nDouble);
1616 break;
1617 case DataType::DATE:
1618 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1619 break;
1620 case DataType::TIME:
1621 case DataType::TIMESTAMP:
1622 case DataType::BINARY:
1623 case DataType::VARBINARY:
1624 case DataType::LONGVARBINARY:
1625 case DataType::BLOB:
1626 case DataType::CLOB:
1627 OSL_FAIL("getULong() for this type is not allowed!");
1628 break;
1629 case DataType::BIT:
1630 case DataType::BOOLEAN:
1631 nRet = sal_uInt64(m_aValue.m_bBool);
1632 break;
1633 case DataType::TINYINT:
1634 if ( m_bSigned )
1635 nRet = m_aValue.m_nInt8;
1636 else
1637 nRet = m_aValue.m_uInt8;
1638 break;
1639 case DataType::SMALLINT:
1640 if ( m_bSigned )
1641 nRet = m_aValue.m_nInt16;
1642 else
1643 nRet = m_aValue.m_uInt16;
1644 break;
1645 case DataType::INTEGER:
1646 if ( m_bSigned )
1647 nRet = m_aValue.m_nInt32;
1648 else
1649 nRet = m_aValue.m_uInt32;
1650 break;
1651 case DataType::BIGINT:
1652 if ( m_bSigned )
1653 nRet = m_aValue.m_nInt64;
1654 else
1655 nRet = m_aValue.m_uInt64;
1656 break;
1657 default:
1658 {
1659 Any aValue = makeAny();
1660 aValue >>= nRet;
1661 break;
1662 }
1663 }
1664 }
1665 return nRet;
1666}
1667
1668
1670{
1671 float nRet = 0;
1672 if(!m_bNull)
1673 {
1674 switch(getTypeKind())
1675 {
1676 case DataType::CHAR:
1677 case DataType::VARCHAR:
1678 case DataType::DECIMAL:
1679 case DataType::NUMERIC:
1680 case DataType::LONGVARCHAR:
1681 nRet = OUString::unacquired(&m_aValue.m_pString).toFloat();
1682 break;
1683 case DataType::FLOAT:
1684 nRet = m_aValue.m_nFloat;
1685 break;
1686 case DataType::DOUBLE:
1687 case DataType::REAL:
1688 nRet = static_cast<float>(m_aValue.m_nDouble);
1689 break;
1690 case DataType::DATE:
1691 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue)));
1692 break;
1693 case DataType::TIME:
1694 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue)));
1695 break;
1696 case DataType::TIMESTAMP:
1697 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue)));
1698 break;
1699 case DataType::BINARY:
1700 case DataType::VARBINARY:
1701 case DataType::LONGVARBINARY:
1702 case DataType::BLOB:
1703 case DataType::CLOB:
1704 OSL_FAIL("getDouble() for this type is not allowed!");
1705 break;
1706 case DataType::BIT:
1707 case DataType::BOOLEAN:
1708 nRet = float(m_aValue.m_bBool);
1709 break;
1710 case DataType::TINYINT:
1711 if ( m_bSigned )
1712 nRet = m_aValue.m_nInt8;
1713 else
1714 nRet = m_aValue.m_uInt8;
1715 break;
1716 case DataType::SMALLINT:
1717 if ( m_bSigned )
1718 nRet = m_aValue.m_nInt16;
1719 else
1720 nRet = static_cast<float>(m_aValue.m_uInt16);
1721 break;
1722 case DataType::INTEGER:
1723 if ( m_bSigned )
1724 nRet = static_cast<float>(m_aValue.m_nInt32);
1725 else
1726 nRet = static_cast<float>(m_aValue.m_uInt32);
1727 break;
1728 case DataType::BIGINT:
1729 if ( m_bSigned )
1730 nRet = static_cast<float>(m_aValue.m_nInt64);
1731 else
1732 nRet = static_cast<float>(m_aValue.m_uInt64);
1733 break;
1734 default:
1735 {
1736 Any aValue = makeAny();
1737 aValue >>= nRet;
1738 break;
1739 }
1740 }
1741 }
1742 return nRet;
1743}
1744
1746{
1747 double nRet = 0;
1748 if(!m_bNull)
1749 {
1750 switch(getTypeKind())
1751 {
1752 case DataType::CHAR:
1753 case DataType::VARCHAR:
1754 case DataType::DECIMAL:
1755 case DataType::NUMERIC:
1756 case DataType::LONGVARCHAR:
1757 nRet = OUString::unacquired(&m_aValue.m_pString).toDouble();
1758 break;
1759 case DataType::FLOAT:
1760 nRet = m_aValue.m_nFloat;
1761 break;
1762 case DataType::DOUBLE:
1763 case DataType::REAL:
1764 nRet = m_aValue.m_nDouble;
1765 break;
1766 case DataType::DATE:
1767 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1768 break;
1769 case DataType::TIME:
1770 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1771 break;
1772 case DataType::TIMESTAMP:
1773 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1774 break;
1775 case DataType::BINARY:
1776 case DataType::VARBINARY:
1777 case DataType::LONGVARBINARY:
1778 case DataType::BLOB:
1779 case DataType::CLOB:
1780 OSL_FAIL("getDouble() for this type is not allowed!");
1781 break;
1782 case DataType::BIT:
1783 case DataType::BOOLEAN:
1784 nRet = double(m_aValue.m_bBool);
1785 break;
1786 case DataType::TINYINT:
1787 if ( m_bSigned )
1788 nRet = m_aValue.m_nInt8;
1789 else
1790 nRet = m_aValue.m_uInt8;
1791 break;
1792 case DataType::SMALLINT:
1793 if ( m_bSigned )
1794 nRet = m_aValue.m_nInt16;
1795 else
1796 nRet = m_aValue.m_uInt16;
1797 break;
1798 case DataType::INTEGER:
1799 if ( m_bSigned )
1800 nRet = m_aValue.m_nInt32;
1801 else
1802 nRet = m_aValue.m_uInt32;
1803 break;
1804 case DataType::BIGINT:
1805 if ( m_bSigned )
1806 nRet = m_aValue.m_nInt64;
1807 else
1808 nRet = m_aValue.m_uInt64;
1809 break;
1810 default:
1811 {
1812 Any aValue = makeAny();
1813 aValue >>= nRet;
1814 break;
1815 }
1816 }
1817 }
1818 return nRet;
1819}
1820
1821Sequence<sal_Int8> ORowSetValue::getSequence() const
1822{
1823 Sequence<sal_Int8> aSeq;
1824 if (!m_bNull)
1825 {
1826 switch(m_eTypeKind)
1827 {
1828 case DataType::OBJECT:
1829 case DataType::CLOB:
1830 case DataType::BLOB:
1831 {
1832 Reference<XInputStream> xStream;
1833 const Any aValue = makeAny();
1834 if(aValue.hasValue())
1835 {
1836 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1837 if ( xBlob.is() )
1838 xStream = xBlob->getBinaryStream();
1839 else
1840 {
1841 Reference<XClob> xClob(aValue,UNO_QUERY);
1842 if ( xClob.is() )
1843 xStream = xClob->getCharacterStream();
1844 }
1845 if(xStream.is())
1846 {
1847 const sal_uInt32 nBytesToRead = 65535;
1848 sal_uInt32 nRead;
1849
1850 do
1851 {
1852 css::uno::Sequence< sal_Int8 > aReadSeq;
1853
1854 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1855
1856 if( nRead )
1857 {
1858 const sal_uInt32 nOldLength = aSeq.getLength();
1859 aSeq.realloc( nOldLength + nRead );
1860 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1861 }
1862 }
1863 while( nBytesToRead == nRead );
1864 xStream->closeInput();
1865 }
1866 }
1867 }
1868 break;
1869 case DataType::VARCHAR:
1870 case DataType::LONGVARCHAR:
1871 {
1872 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(m_aValue.m_pString->buffer),
1873 sizeof(sal_Unicode) * m_aValue.m_pString->length);
1874 }
1875 break;
1876 case DataType::BINARY:
1877 case DataType::VARBINARY:
1878 case DataType::LONGVARBINARY:
1879 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1880 break;
1881 default:
1882 {
1883 Any aValue = makeAny();
1884 aValue >>= aSeq;
1885 break;
1886 }
1887 }
1888 }
1889 return aSeq;
1890
1891}
1892
1893css::util::Date ORowSetValue::getDate() const
1894{
1895 css::util::Date aValue;
1896 if(!m_bNull)
1897 {
1898 switch(m_eTypeKind)
1899 {
1900 case DataType::CHAR:
1901 case DataType::VARCHAR:
1902 case DataType::LONGVARCHAR:
1904 break;
1905 case DataType::DECIMAL:
1906 case DataType::NUMERIC:
1907 case DataType::FLOAT:
1908 case DataType::DOUBLE:
1909 case DataType::REAL:
1911 break;
1912
1913 case DataType::DATE:
1914 aValue = *static_cast< css::util::Date*>(m_aValue.m_pValue);
1915 break;
1916 case DataType::TIMESTAMP:
1917 {
1918 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1919 aValue.Day = pDateTime->Day;
1920 aValue.Month = pDateTime->Month;
1921 aValue.Year = pDateTime->Year;
1922 }
1923 break;
1924 case DataType::BIT:
1925 case DataType::BOOLEAN:
1926 case DataType::TINYINT:
1927 case DataType::SMALLINT:
1928 case DataType::INTEGER:
1929 case DataType::BIGINT:
1930 aValue = DBTypeConversion::toDate( double( getLong() ) );
1931 break;
1932
1933 case DataType::BLOB:
1934 case DataType::CLOB:
1935 case DataType::OBJECT:
1936 default:
1937 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1938 [[fallthrough]];
1939
1940 case DataType::BINARY:
1941 case DataType::VARBINARY:
1942 case DataType::LONGVARBINARY:
1943 case DataType::TIME:
1944 aValue = DBTypeConversion::toDate( double(0) );
1945 break;
1946 }
1947 }
1948 return aValue;
1949}
1950
1951css::util::Time ORowSetValue::getTime() const
1952{
1953 css::util::Time aValue;
1954 if(!m_bNull)
1955 {
1956 switch(m_eTypeKind)
1957 {
1958 case DataType::CHAR:
1959 case DataType::VARCHAR:
1960 case DataType::LONGVARCHAR:
1962 break;
1963 case DataType::DECIMAL:
1964 case DataType::NUMERIC:
1966 break;
1967 case DataType::FLOAT:
1968 case DataType::DOUBLE:
1969 case DataType::REAL:
1971 break;
1972 case DataType::TIMESTAMP:
1973 {
1974 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1975 aValue.NanoSeconds = pDateTime->NanoSeconds;
1976 aValue.Seconds = pDateTime->Seconds;
1977 aValue.Minutes = pDateTime->Minutes;
1978 aValue.Hours = pDateTime->Hours;
1979 }
1980 break;
1981 case DataType::TIME:
1982 aValue = *static_cast< css::util::Time*>(m_aValue.m_pValue);
1983 break;
1984 default:
1985 {
1986 Any aAnyValue = makeAny();
1987 aAnyValue >>= aValue;
1988 break;
1989 }
1990 }
1991 }
1992 return aValue;
1993}
1994
1995css::util::DateTime ORowSetValue::getDateTime() const
1996{
1997 css::util::DateTime aValue;
1998 if(!m_bNull)
1999 {
2000 switch(m_eTypeKind)
2001 {
2002 case DataType::CHAR:
2003 case DataType::VARCHAR:
2004 case DataType::LONGVARCHAR:
2006 break;
2007 case DataType::DECIMAL:
2008 case DataType::NUMERIC:
2010 break;
2011 case DataType::FLOAT:
2012 case DataType::DOUBLE:
2013 case DataType::REAL:
2015 break;
2016 case DataType::DATE:
2017 {
2018 css::util::Date* pDate = static_cast< css::util::Date*>(m_aValue.m_pValue);
2019 aValue.Day = pDate->Day;
2020 aValue.Month = pDate->Month;
2021 aValue.Year = pDate->Year;
2022 }
2023 break;
2024 case DataType::TIME:
2025 {
2026 css::util::Time* pTime = static_cast< css::util::Time*>(m_aValue.m_pValue);
2027 aValue.NanoSeconds = pTime->NanoSeconds;
2028 aValue.Seconds = pTime->Seconds;
2029 aValue.Minutes = pTime->Minutes;
2030 aValue.Hours = pTime->Hours;
2031 }
2032 break;
2033 case DataType::TIMESTAMP:
2034 aValue = *static_cast< css::util::DateTime*>(m_aValue.m_pValue);
2035 break;
2036 default:
2037 {
2038 Any aAnyValue = makeAny();
2039 aAnyValue >>= aValue;
2040 break;
2041 }
2042 }
2043 }
2044 return aValue;
2045}
2046
2048{
2049 if ( m_bSigned == _bMod )
2050 return;
2051
2052 m_bSigned = _bMod;
2053 if ( m_bNull )
2054 return;
2055
2056 sal_Int32 nType = m_eTypeKind;
2057 switch(m_eTypeKind)
2058 {
2059 case DataType::TINYINT:
2060 if ( m_bSigned )
2061 (*this) = getInt8();
2062 else
2063 {
2065 (*this) = getInt16();
2067 }
2068 break;
2069 case DataType::SMALLINT:
2070 if ( m_bSigned )
2071 (*this) = getInt16();
2072 else
2073 {
2075 (*this) = getInt32();
2077 }
2078 break;
2079 case DataType::INTEGER:
2080 if ( m_bSigned )
2081 (*this) = getInt32();
2082 else
2083 {
2085 (*this) = getLong();
2087 }
2088 break;
2089 case DataType::BIGINT:
2090 {
2091 if ( m_bSigned )
2092 {
2093 auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64);
2094 m_aValue.m_nInt64 = nTmp;
2095 }
2096 else
2097 {
2098 auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2099 m_aValue.m_uInt64 = nTmp;
2100 }
2101 break;
2102 }
2103 }
2105}
2106
2107
2108namespace detail
2109{
2111 {
2112 public:
2113 virtual OUString getString() const = 0;
2114 virtual bool getBoolean() const = 0;
2115 virtual sal_Int8 getByte() const = 0;
2116 virtual sal_Int16 getShort() const = 0;
2117 virtual sal_Int32 getInt() const = 0;
2118 virtual sal_Int64 getLong() const = 0;
2119 virtual float getFloat() const = 0;
2120 virtual double getDouble() const = 0;
2121 virtual Date getDate() const = 0;
2122 virtual css::util::Time getTime() const = 0;
2123 virtual DateTime getTimestamp() const = 0;
2124 virtual Sequence< sal_Int8 > getBytes() const = 0;
2125 virtual Reference< XBlob > getBlob() const = 0;
2126 virtual Reference< XClob > getClob() const = 0;
2127 virtual Any getObject() const = 0;
2128 virtual bool wasNull() const = 0;
2129
2130 virtual ~IValueSource() { }
2131 };
2132
2133 namespace {
2134
2135 class RowValue : public IValueSource
2136 {
2137 public:
2138 RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2139 :m_xRow( _xRow )
2140 ,m_nPos( _nPos )
2141 {
2142 }
2143
2144 // IValueSource
2145 virtual OUString getString() const override { return m_xRow->getString( m_nPos ); };
2146 virtual bool getBoolean() const override { return m_xRow->getBoolean( m_nPos ); };
2147 virtual sal_Int8 getByte() const override { return m_xRow->getByte( m_nPos ); };
2148 virtual sal_Int16 getShort() const override { return m_xRow->getShort( m_nPos ); }
2149 virtual sal_Int32 getInt() const override { return m_xRow->getInt( m_nPos ); }
2150 virtual sal_Int64 getLong() const override { return m_xRow->getLong( m_nPos ); }
2151 virtual float getFloat() const override { return m_xRow->getFloat( m_nPos ); };
2152 virtual double getDouble() const override { return m_xRow->getDouble( m_nPos ); };
2153 virtual Date getDate() const override { return m_xRow->getDate( m_nPos ); };
2154 virtual css::util::Time getTime() const override { return m_xRow->getTime( m_nPos ); };
2155 virtual DateTime getTimestamp() const override { return m_xRow->getTimestamp( m_nPos ); };
2156 virtual Sequence< sal_Int8 > getBytes() const override { return m_xRow->getBytes( m_nPos ); };
2157 virtual Reference< XBlob > getBlob() const override { return m_xRow->getBlob( m_nPos ); };
2158 virtual Reference< XClob > getClob() const override { return m_xRow->getClob( m_nPos ); };
2159 virtual Any getObject() const override { return m_xRow->getObject( m_nPos ,nullptr); };
2160 virtual bool wasNull() const override { return m_xRow->wasNull( ); };
2161
2162 private:
2163 const Reference< XRow > m_xRow;
2164 const sal_Int32 m_nPos;
2165 };
2166
2167 class ColumnValue : public IValueSource
2168 {
2169 public:
2170 explicit ColumnValue( const Reference< XColumn >& _rxColumn )
2171 :m_xColumn( _rxColumn )
2172 {
2173 }
2174
2175 // IValueSource
2176 virtual OUString getString() const override { return m_xColumn->getString(); };
2177 virtual bool getBoolean() const override { return m_xColumn->getBoolean(); };
2178 virtual sal_Int8 getByte() const override { return m_xColumn->getByte(); };
2179 virtual sal_Int16 getShort() const override { return m_xColumn->getShort(); }
2180 virtual sal_Int32 getInt() const override { return m_xColumn->getInt(); }
2181 virtual sal_Int64 getLong() const override { return m_xColumn->getLong(); }
2182 virtual float getFloat() const override { return m_xColumn->getFloat(); };
2183 virtual double getDouble() const override { return m_xColumn->getDouble(); };
2184 virtual Date getDate() const override { return m_xColumn->getDate(); };
2185 virtual css::util::Time getTime() const override { return m_xColumn->getTime(); };
2186 virtual DateTime getTimestamp() const override { return m_xColumn->getTimestamp(); };
2187 virtual Sequence< sal_Int8 > getBytes() const override { return m_xColumn->getBytes(); };
2188 virtual Reference< XBlob > getBlob() const override { return m_xColumn->getBlob(); };
2189 virtual Reference< XClob > getClob() const override { return m_xColumn->getClob(); };
2190 virtual Any getObject() const override { return m_xColumn->getObject( nullptr ); };
2191 virtual bool wasNull() const override { return m_xColumn->wasNull( ); };
2192
2193 private:
2194 const Reference< XColumn > m_xColumn;
2195 };
2196
2197 }
2198}
2199
2200
2201void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2202{
2203 detail::ColumnValue aColumnValue( _rxColumn );
2204 impl_fill( _nType, true, aColumnValue );
2205}
2206
2207
2208void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2209{
2210 detail::RowValue aRowValue( _xRow, _nPos );
2211 impl_fill( _nType, _bNullable, aRowValue );
2212}
2213
2214
2215void ORowSetValue::fill(sal_Int32 _nPos,
2216 sal_Int32 _nType,
2217 const css::uno::Reference< css::sdbc::XRow>& _xRow)
2218{
2219 fill(_nPos,_nType,true,_xRow);
2220}
2221
2222
2223void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2224{
2225 switch(_nType)
2226 {
2227 case DataType::CHAR:
2228 case DataType::VARCHAR:
2229 case DataType::DECIMAL:
2230 case DataType::NUMERIC:
2231 case DataType::LONGVARCHAR:
2232 (*this) = _rValueSource.getString();
2233 break;
2234 case DataType::BIGINT:
2235 if ( isSigned() )
2236 (*this) = _rValueSource.getLong();
2237 else
2238 // TODO: this is rather horrible performance-wise
2239 // but fixing it needs extending the css::sdbc::XRow API
2240 // to have a getULong(), and needs updating all drivers :-|
2241 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2242 (*this) = _rValueSource.getString().toUInt64();
2243 break;
2244 case DataType::FLOAT:
2245 (*this) = _rValueSource.getFloat();
2246 break;
2247 case DataType::DOUBLE:
2248 case DataType::REAL:
2249 (*this) = _rValueSource.getDouble();
2250 break;
2251 case DataType::DATE:
2252 (*this) = _rValueSource.getDate();
2253 break;
2254 case DataType::TIME:
2255 (*this) = _rValueSource.getTime();
2256 break;
2257 case DataType::TIMESTAMP:
2258 (*this) = _rValueSource.getTimestamp();
2259 break;
2260 case DataType::BINARY:
2261 case DataType::VARBINARY:
2262 case DataType::LONGVARBINARY:
2263 (*this) = _rValueSource.getBytes();
2264 break;
2265 case DataType::BIT:
2266 case DataType::BOOLEAN:
2267 (*this) = _rValueSource.getBoolean();
2268 break;
2269 case DataType::TINYINT:
2270 if ( isSigned() )
2271 (*this) = _rValueSource.getByte();
2272 else
2273 (*this) = _rValueSource.getShort();
2274 break;
2275 case DataType::SMALLINT:
2276 if ( isSigned() )
2277 (*this) = _rValueSource.getShort();
2278 else
2279 (*this) = _rValueSource.getInt();
2280 break;
2281 case DataType::INTEGER:
2282 if ( isSigned() )
2283 (*this) = _rValueSource.getInt();
2284 else
2285 (*this) = _rValueSource.getLong();
2286 break;
2287 case DataType::CLOB:
2288 (*this) = css::uno::Any(_rValueSource.getClob());
2289 setTypeKind(DataType::CLOB);
2290 break;
2291 case DataType::BLOB:
2292 (*this) = css::uno::Any(_rValueSource.getBlob());
2293 setTypeKind(DataType::BLOB);
2294 break;
2295 case DataType::OTHER:
2296 (*this) = _rValueSource.getObject();
2297 setTypeKind(DataType::OTHER);
2298 break;
2299 default:
2300 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2301 (*this) = _rValueSource.getObject();
2302 break;
2303 }
2304 if ( _bNullable && _rValueSource.wasNull() )
2305 setNull();
2306 setTypeKind(_nType);
2307}
2308
2309void ORowSetValue::fill(const Any& _rValue)
2310{
2311 switch (_rValue.getValueType().getTypeClass())
2312 {
2313 case TypeClass_VOID:
2314 setNull(); break;
2315 case TypeClass_BOOLEAN:
2316 {
2317 bool bValue( false );
2318 _rValue >>= bValue;
2319 (*this) = bValue;
2320 break;
2321 }
2322 case TypeClass_CHAR:
2323 {
2324 sal_Unicode aDummy(0);
2325 _rValue >>= aDummy;
2326 (*this) = OUString(aDummy);
2327 break;
2328 }
2329 case TypeClass_STRING:
2330 {
2331 OUString sDummy;
2332 _rValue >>= sDummy;
2333 (*this) = sDummy;
2334 break;
2335 }
2336 case TypeClass_FLOAT:
2337 {
2338 float aDummy(0.0);
2339 _rValue >>= aDummy;
2340 (*this) = aDummy;
2341 break;
2342 }
2343 case TypeClass_DOUBLE:
2344 {
2345 double aDummy(0.0);
2346 _rValue >>= aDummy;
2347 (*this) = aDummy;
2348 break;
2349 }
2350 case TypeClass_BYTE:
2351 {
2352 sal_Int8 aDummy(0);
2353 _rValue >>= aDummy;
2354 (*this) = aDummy;
2355 break;
2356 }
2357 case TypeClass_SHORT:
2358 {
2359 sal_Int16 aDummy(0);
2360 _rValue >>= aDummy;
2361 (*this) = aDummy;
2362 break;
2363 }
2364 case TypeClass_UNSIGNED_SHORT:
2365 {
2366 sal_uInt16 nValue(0);
2367 _rValue >>= nValue;
2368 (*this) = nValue;
2369 break;
2370 }
2371 case TypeClass_LONG:
2372 {
2373 sal_Int32 aDummy(0);
2374 _rValue >>= aDummy;
2375 (*this) = aDummy;
2376 break;
2377 }
2378 case TypeClass_UNSIGNED_LONG:
2379 {
2380 sal_uInt32 nValue(0);
2381 _rValue >>= nValue;
2382 (*this) = static_cast<sal_Int64>(nValue);
2383 setSigned(false);
2384 break;
2385 }
2386 case TypeClass_HYPER:
2387 {
2388 sal_Int64 nValue(0);
2389 _rValue >>= nValue;
2390 (*this) = nValue;
2391 break;
2392 }
2393 case TypeClass_UNSIGNED_HYPER:
2394 {
2395 sal_uInt64 nValue(0);
2396 _rValue >>= nValue;
2397 (*this) = nValue;
2398 setSigned(false);
2399 break;
2400 }
2401 case TypeClass_ENUM:
2402 {
2403 sal_Int32 enumValue( 0 );
2404 ::cppu::enum2int( enumValue, _rValue );
2405 (*this) = enumValue;
2406 }
2407 break;
2408
2409 case TypeClass_SEQUENCE:
2410 {
2411 Sequence<sal_Int8> aDummy;
2412 if ( _rValue >>= aDummy )
2413 (*this) = aDummy;
2414 else
2415 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2416 break;
2417 }
2418
2419 case TypeClass_STRUCT:
2420 {
2421 css::util::Date aDate;
2422 css::util::Time aTime;
2423 css::util::DateTime aDateTime;
2424 if ( _rValue >>= aDate )
2425 {
2426 (*this) = aDate;
2427 }
2428 else if ( _rValue >>= aTime )
2429 {
2430 (*this) = aTime;
2431 }
2432 else if ( _rValue >>= aDateTime )
2433 {
2434 (*this) = aDateTime;
2435 }
2436 else
2437 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2438
2439 break;
2440 }
2441 case TypeClass_INTERFACE:
2442 {
2443 Reference< XClob > xClob;
2444 if ( _rValue >>= xClob )
2445 {
2446 (*this) = _rValue;
2447 setTypeKind(DataType::CLOB);
2448 }
2449 else
2450 {
2451 Reference< XBlob > xBlob;
2452 if ( _rValue >>= xBlob )
2453 {
2454 (*this) = _rValue;
2455 setTypeKind(DataType::BLOB);
2456 }
2457 else
2458 {
2459 (*this) = _rValue;
2460 }
2461 }
2462 }
2463 break;
2464
2465 default:
2466 SAL_WARN( "connectivity.commontools","Unknown type");
2467 break;
2468 }
2469}
2470
2471} // namespace connectivity
2472
2473/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Reference< XRow > m_xRow
Definition: FValue.cxx:2160
const sal_Int32 m_nPos
Definition: FValue.cxx:2164
const Reference< XColumn > m_xColumn
Definition: FValue.cxx:2191
Reference< XInputStream > xStream
sal_uInt16 getUInt16() const
Definition: FValue.cxx:1306
css::util::Time getTime() const
Definition: FValue.cxx:1951
rtl_uString * m_pString
Definition: FValue.hxx:67
sal_uInt64 getULong() const
Definition: FValue.cxx:1596
sal_Int32 getInt32() const
Definition: FValue.cxx:1377
sal_uInt8 getUInt8() const
Definition: FValue.cxx:1160
OUString getString() const
Definition: FValue.cxx:933
void impl_fill(const sal_Int32 _nType, bool _bNullable, const detail::IValueSource &_rValueSource)
Definition: FValue.cxx:2223
css::uno::Any makeAny() const
Definition: FValue.cxx:837
ORowSetValue & operator=(const ORowSetValue &_rRH)
Definition: FValue.cxx:323
bool operator==(const ORowSetValue &_rRH) const
Definition: FValue.cxx:727
sal_Int32 getTypeKind() const
Definition: FValue.hxx:340
void free() noexcept
Definition: FValue.cxx:261
sal_Int8 getInt8() const
Definition: FValue.cxx:1089
float getFloat() const
Definition: FValue.cxx:1669
sal_Int16 getInt16() const
Definition: FValue.cxx:1235
void setTypeKind(sal_Int32 _eType)
Definition: FValue.cxx:180
css::util::Date getDate() const
Definition: FValue.cxx:1893
css::util::DateTime getDateTime() const
Definition: FValue.cxx:1995
void fill(sal_Int32 _nPos, sal_Int32 _nType, const css::uno::Reference< css::sdbc::XRow > &_xRow)
fetches a single value out of the row
Definition: FValue.cxx:2215
void setSigned(bool _bSig)
Definition: FValue.cxx:2047
sal_Int64 getLong() const
Definition: FValue.cxx:1523
double getDouble() const
Definition: FValue.cxx:1745
const css::uno::Any & getAny() const
Definition: FValue.hxx:366
union connectivity::ORowSetValue::@1 m_aValue
sal_uInt32 getUInt32() const
Definition: FValue.cxx:1450
css::uno::Sequence< sal_Int8 > getSequence() const
Definition: FValue.cxx:1821
virtual Date getDate() const =0
virtual bool wasNull() const =0
virtual OUString getString() const =0
virtual Any getObject() const =0
virtual sal_Int32 getInt() const =0
virtual css::util::Time getTime() const =0
virtual double getDouble() const =0
virtual Sequence< sal_Int8 > getBytes() const =0
virtual Reference< XBlob > getBlob() const =0
virtual sal_Int8 getByte() const =0
virtual Reference< XClob > getClob() const =0
virtual sal_Int16 getShort() const =0
virtual bool getBoolean() const =0
virtual float getFloat() const =0
virtual DateTime getTimestamp() const =0
virtual sal_Int64 getLong() const =0
sal_Int16 nValue
sal_Int64 n
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
double getDouble(const Any &_rAny)
float getFloat(const Any &_rAny)
OUString getString(const Any &_rAny)
OOO_DLLPUBLIC_DBTOOLS OUString toTimeString(const css::util::Time &rTime)
OOO_DLLPUBLIC_DBTOOLS OUString toDateString(const css::util::Date &rDate)
OOO_DLLPUBLIC_DBTOOLS double toDouble(const css::util::Date &rVal, const css::util::Date &_rNullDate=getStandardDate())
OOO_DLLPUBLIC_DBTOOLS css::util::Date toDate(double dVal, const css::util::Date &_rNullDate=getStandardDate())
OOO_DLLPUBLIC_DBTOOLS OUString toDateTimeString(const css::util::DateTime &_rDateTime)
OOO_DLLPUBLIC_DBTOOLS sal_Int32 toDays(const css::util::Date &_rVal, const css::util::Date &_rNullDate=getStandardDate())
OOO_DLLPUBLIC_DBTOOLS css::util::Time toTime(double dVal, short nDigits=9)
OOO_DLLPUBLIC_DBTOOLS css::util::DateTime toDateTime(double dVal, const css::util::Date &_rNullDate=getStandardDate())
QPRO_FUNC_TYPE nType
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
unsigned char sal_uInt8
#define SAL_NO_VTABLE
sal_uInt16 sal_Unicode
signed char sal_Int8
sal_Int32 _nPos