nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / commontools / FValue.cxx
blob2f1cabbd452036dd52a2f5d224521c91a11ac511
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <string.h>
22 #include <connectivity/FValue.hxx>
23 #include <connectivity/dbconversion.hxx>
24 #include <comphelper/extract.hxx>
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>
34 using namespace ::dbtools;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::sdb;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::io;
41 namespace connectivity
44 namespace {
45 bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
47 bool bIsCompatible = true;
49 if (_eType1 != _eType2)
51 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
52 switch (_eType1)
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;
66 case DataType::DOUBLE:
67 case DataType::REAL:
68 bIsCompatible = (DataType::DOUBLE == _eType2)
69 || (DataType::REAL == _eType2);
70 break;
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;
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;
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;
104 default:
105 bIsCompatible = false;
108 return bIsCompatible;
111 bool isStorageComparable(sal_Int32 _eType1, sal_Int32 _eType2)
113 bool bIsComparable = true;
115 if (_eType1 != _eType2)
117 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
118 switch (_eType1)
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;
128 case DataType::DECIMAL:
129 case DataType::NUMERIC:
130 bIsComparable = (DataType::DECIMAL == _eType2)
131 || (DataType::NUMERIC == _eType2);
132 break;
134 case DataType::DOUBLE:
135 case DataType::REAL:
136 bIsComparable = (DataType::DOUBLE == _eType2)
137 || (DataType::REAL == _eType2);
138 break;
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;
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;
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;
172 default:
173 bIsComparable = false;
176 return bIsComparable;
180 void ORowSetValue::setTypeKind(sal_Int32 _eType)
182 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
184 switch(_eType)
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:
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;
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:
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;
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!");
257 m_eTypeKind = _eType;
261 void ORowSetValue::free() noexcept
263 if(m_bNull)
264 return;
266 switch(m_eTypeKind)
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 )
314 delete static_cast<Any*>(m_aValue.m_pValue);
315 m_aValue.m_pValue = nullptr;
317 break;
320 m_bNull = true;
323 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
325 if(&_rRH == this)
326 return *this;
328 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
329 free();
331 m_bBound = _rRH.m_bBound;
332 m_eTypeKind = _rRH.m_eTypeKind;
333 m_bSigned = _rRH.m_bSigned;
335 if(m_bNull && !_rRH.m_bNull)
337 switch(_rRH.m_eTypeKind)
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));
400 else if(!_rRH.m_bNull)
402 switch(_rRH.m_eTypeKind)
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);
465 m_bNull = _rRH.m_bNull;
466 // OJ: BUGID: 96277
467 m_eTypeKind = _rRH.m_eTypeKind;
469 return *this;
472 ORowSetValue& ORowSetValue::operator=(ORowSetValue&& _rRH) noexcept
474 if ( m_eTypeKind != _rRH.m_eTypeKind || !m_bNull)
475 free();
476 if(!_rRH.m_bNull)
478 m_aValue = _rRH.m_aValue;
479 memset(&_rRH.m_aValue, 0, sizeof(_rRH.m_aValue));
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;
490 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
492 if(m_eTypeKind != DataType::DATE)
493 free();
495 if(m_bNull)
497 m_aValue.m_pValue = new Date(_rRH);
498 m_eTypeKind = DataType::DATE;
499 m_bNull = false;
501 else
502 *static_cast<Date*>(m_aValue.m_pValue) = _rRH;
504 return *this;
507 ORowSetValue& ORowSetValue::operator=(const css::util::Time& _rRH)
509 if(m_eTypeKind != DataType::TIME)
510 free();
512 if(m_bNull)
514 m_aValue.m_pValue = new Time(_rRH);
515 m_eTypeKind = DataType::TIME;
516 m_bNull = false;
518 else
519 *static_cast<Time*>(m_aValue.m_pValue) = _rRH;
521 return *this;
524 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
526 if(m_eTypeKind != DataType::TIMESTAMP)
527 free();
528 if(m_bNull)
530 m_aValue.m_pValue = new DateTime(_rRH);
531 m_eTypeKind = DataType::TIMESTAMP;
532 m_bNull = false;
534 else
535 *static_cast<DateTime*>(m_aValue.m_pValue) = _rRH;
537 return *this;
541 ORowSetValue& ORowSetValue::operator=(const OUString& _rRH)
543 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
545 free();
546 m_bNull = false;
548 m_aValue.m_pString = _rRH.pData;
549 rtl_uString_acquire(m_aValue.m_pString);
550 m_eTypeKind = DataType::VARCHAR;
553 return *this;
557 ORowSetValue& ORowSetValue::operator=(double _rRH)
559 if(m_eTypeKind != DataType::DOUBLE)
560 free();
562 m_aValue.m_nDouble = _rRH;
563 m_eTypeKind = DataType::DOUBLE;
564 m_bNull = false;
566 return *this;
569 ORowSetValue& ORowSetValue::operator=(float _rRH)
571 if(m_eTypeKind != DataType::FLOAT)
572 free();
574 m_aValue.m_nFloat = _rRH;
575 m_eTypeKind = DataType::FLOAT;
576 m_bNull = false;
578 return *this;
582 ORowSetValue& ORowSetValue::operator=(sal_Int8 _rRH)
584 if(m_eTypeKind != DataType::TINYINT )
585 free();
587 m_aValue.m_nInt8 = _rRH;
588 m_eTypeKind = DataType::TINYINT;
589 m_bNull = false;
590 m_bSigned = true;
591 return *this;
594 ORowSetValue& ORowSetValue::operator=(sal_Int16 _rRH)
596 if(m_eTypeKind != DataType::SMALLINT )
597 free();
599 m_aValue.m_nInt16 = _rRH;
600 m_eTypeKind = DataType::SMALLINT;
601 m_bNull = false;
602 m_bSigned = true;
604 return *this;
608 ORowSetValue& ORowSetValue::operator=(sal_uInt16 _rRH)
610 if(m_eTypeKind != DataType::SMALLINT )
611 free();
613 m_aValue.m_uInt16 = _rRH;
614 m_eTypeKind = DataType::SMALLINT;
615 m_bNull = false;
616 m_bSigned = false;
618 return *this;
622 ORowSetValue& ORowSetValue::operator=(sal_Int32 _rRH)
624 if(m_eTypeKind != DataType::INTEGER )
625 free();
627 m_aValue.m_nInt32 = _rRH;
629 m_eTypeKind = DataType::INTEGER;
630 m_bNull = false;
631 m_bSigned = true;
633 return *this;
637 ORowSetValue& ORowSetValue::operator=(sal_uInt32 _rRH)
639 if(m_eTypeKind != DataType::INTEGER )
640 free();
642 m_aValue.m_uInt32 = _rRH;
644 m_eTypeKind = DataType::INTEGER;
645 m_bNull = false;
646 m_bSigned = false;
648 return *this;
652 ORowSetValue& ORowSetValue::operator=(const bool _rRH)
654 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
655 free();
657 m_aValue.m_bBool = _rRH;
658 m_eTypeKind = DataType::BOOLEAN;
659 m_bNull = false;
661 return *this;
664 ORowSetValue& ORowSetValue::operator=(sal_Int64 _rRH)
666 if ( DataType::BIGINT != m_eTypeKind)
667 free();
669 m_aValue.m_nInt64 = _rRH;
670 m_eTypeKind = DataType::BIGINT;
671 m_bNull = false;
672 m_bSigned = true;
674 return *this;
677 ORowSetValue& ORowSetValue::operator=(sal_uInt64 _rRH)
679 if ( DataType::BIGINT != m_eTypeKind)
680 free();
682 m_aValue.m_uInt64 = _rRH;
683 m_eTypeKind = DataType::BIGINT;
684 m_bNull = false;
685 m_bSigned = false;
687 return *this;
690 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
692 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
693 free();
695 if (m_bNull)
697 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
699 else
700 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
702 m_eTypeKind = DataType::LONGVARBINARY;
703 m_bNull = false;
705 return *this;
708 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
710 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
711 free();
713 if ( m_bNull )
715 m_aValue.m_pValue = new Any(_rAny);
717 else
718 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
720 m_eTypeKind = DataType::OBJECT;
721 m_bNull = false;
723 return *this;
727 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
729 if ( m_bNull != _rRH.isNull() )
730 return false;
732 if(m_bNull && _rRH.isNull())
733 return true;
735 if ( !isStorageComparable(m_eTypeKind, _rRH.m_eTypeKind ))
737 switch(m_eTypeKind)
739 case DataType::FLOAT:
740 case DataType::DOUBLE:
741 case DataType::REAL:
742 return getDouble() == _rRH.getDouble();
743 default:
744 switch(_rRH.m_eTypeKind)
746 case DataType::FLOAT:
747 case DataType::DOUBLE:
748 case DataType::REAL:
749 return getDouble() == _rRH.getDouble();
750 default:
751 break;
753 break;
755 return false;
758 bool bRet = false;
759 OSL_ENSURE(!m_bNull,"Should not be null!");
760 switch(m_eTypeKind)
762 case DataType::VARCHAR:
763 case DataType::CHAR:
764 case DataType::LONGVARCHAR:
766 OUString aVal1(m_aValue.m_pString);
767 OUString aVal2(_rRH.m_aValue.m_pString);
768 return aVal1 == aVal2;
770 default:
771 if ( m_bSigned != _rRH.m_bSigned )
772 return false;
773 break;
776 switch(m_eTypeKind)
778 case DataType::DECIMAL:
779 case DataType::NUMERIC:
781 OUString aVal1(m_aValue.m_pString);
782 OUString aVal2(_rRH.m_aValue.m_pString);
783 bRet = aVal1 == aVal2;
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;
834 return bRet;
837 Any ORowSetValue::makeAny() const
839 Any rValue;
840 if(isBound() && !isNull())
842 switch(getTypeKind())
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;
930 return rValue;
933 OUString ORowSetValue::getString( ) const
935 OUString aRet;
936 if(!m_bNull)
938 switch(getTypeKind())
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(static_cast<float>(*this));
949 break;
950 case DataType::DOUBLE:
951 case DataType::REAL:
952 aRet = OUString::number(static_cast<double>(*this));
953 break;
954 case DataType::DATE:
955 aRet = DBTypeConversion::toDateString(*this);
956 break;
957 case DataType::TIME:
958 aRet = DBTypeConversion::toTimeString(*this);
959 break;
960 case DataType::TIMESTAMP:
961 aRet = DBTypeConversion::toDateTimeString(*this);
962 break;
963 case DataType::BINARY:
964 case DataType::VARBINARY:
965 case DataType::LONGVARBINARY:
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();
975 break;
976 case DataType::BIT:
977 aRet = OUString::number(int(static_cast<bool>(*this)));
978 break;
979 case DataType::BOOLEAN:
980 aRet = OUString::boolean(static_cast<bool>(*this));
981 break;
982 case DataType::TINYINT:
983 case DataType::SMALLINT:
984 case DataType::INTEGER:
985 if ( m_bSigned )
986 aRet = OUString::number(static_cast<sal_Int32>(*this));
987 else
988 aRet = OUString::number(static_cast<sal_uInt32>(*this));
989 break;
990 case DataType::BIGINT:
991 if ( m_bSigned )
992 aRet = OUString::number(static_cast<sal_Int64>(*this));
993 else
994 aRet = OUString::number(static_cast<sal_uInt64>(*this));
995 break;
996 case DataType::CLOB:
998 Any aValue( getAny() );
999 Reference< XClob > xClob;
1000 if ( (aValue >>= xClob) && xClob.is() )
1002 aRet = xClob->getSubString(1,static_cast<sal_Int32>(xClob->length()) );
1005 break;
1006 default:
1008 Any aValue = makeAny();
1009 aValue >>= aRet;
1010 break;
1014 return aRet;
1017 bool ORowSetValue::getBool() const
1019 bool bRet = false;
1020 if(!m_bNull)
1022 switch(getTypeKind())
1024 case DataType::CHAR:
1025 case DataType::VARCHAR:
1026 case DataType::LONGVARCHAR:
1028 const OUString sValue(m_aValue.m_pString);
1029 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1031 bRet = true;
1032 break;
1034 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1036 bRet = false;
1037 break;
1040 [[fallthrough]];
1041 case DataType::DECIMAL:
1042 case DataType::NUMERIC:
1044 bRet = OUString(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:
1079 Any aValue = makeAny();
1080 aValue >>= bRet;
1081 break;
1085 return bRet;
1089 sal_Int8 ORowSetValue::getInt8() const
1091 sal_Int8 nRet = 0;
1092 if(!m_bNull)
1094 switch(getTypeKind())
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(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:
1150 Any aValue = makeAny();
1151 aValue >>= nRet;
1152 break;
1156 return nRet;
1160 sal_uInt8 ORowSetValue::getUInt8() const
1162 sal_uInt8 nRet = 0;
1163 if(!m_bNull)
1165 switch(getTypeKind())
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(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:
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);
1227 break;
1231 return nRet;
1235 sal_Int16 ORowSetValue::getInt16() const
1237 sal_Int16 nRet = 0;
1238 if(!m_bNull)
1240 switch(getTypeKind())
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(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:
1296 Any aValue = makeAny();
1297 aValue >>= nRet;
1298 break;
1302 return nRet;
1306 sal_uInt16 ORowSetValue::getUInt16() const
1308 sal_uInt16 nRet = 0;
1309 if(!m_bNull)
1311 switch(getTypeKind())
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(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:
1367 Any aValue = makeAny();
1368 aValue >>= nRet;
1369 break;
1373 return nRet;
1377 sal_Int32 ORowSetValue::getInt32() const
1379 sal_Int32 nRet = 0;
1380 if(!m_bNull)
1382 switch(getTypeKind())
1384 case DataType::CHAR:
1385 case DataType::VARCHAR:
1386 case DataType::DECIMAL:
1387 case DataType::NUMERIC:
1388 case DataType::LONGVARCHAR:
1389 nRet = OUString(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:
1440 Any aValue = makeAny();
1441 aValue >>= nRet;
1442 break;
1446 return nRet;
1450 sal_uInt32 ORowSetValue::getUInt32() const
1452 sal_uInt32 nRet = 0;
1453 if(!m_bNull)
1455 switch(getTypeKind())
1457 case DataType::CHAR:
1458 case DataType::VARCHAR:
1459 case DataType::DECIMAL:
1460 case DataType::NUMERIC:
1461 case DataType::LONGVARCHAR:
1462 nRet = OUString(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:
1513 Any aValue = makeAny();
1514 aValue >>= nRet;
1515 break;
1519 return nRet;
1523 sal_Int64 ORowSetValue::getLong() const
1525 sal_Int64 nRet = 0;
1526 if(!m_bNull)
1528 switch(getTypeKind())
1530 case DataType::CHAR:
1531 case DataType::VARCHAR:
1532 case DataType::DECIMAL:
1533 case DataType::NUMERIC:
1534 case DataType::LONGVARCHAR:
1535 nRet = OUString(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:
1586 Any aValue = makeAny();
1587 aValue >>= nRet;
1588 break;
1592 return nRet;
1596 sal_uInt64 ORowSetValue::getULong() const
1598 sal_uInt64 nRet = 0;
1599 if(!m_bNull)
1601 switch(getTypeKind())
1603 case DataType::CHAR:
1604 case DataType::VARCHAR:
1605 case DataType::DECIMAL:
1606 case DataType::NUMERIC:
1607 case DataType::LONGVARCHAR:
1608 nRet = OUString(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:
1659 Any aValue = makeAny();
1660 aValue >>= nRet;
1661 break;
1665 return nRet;
1669 float ORowSetValue::getFloat() const
1671 float nRet = 0;
1672 if(!m_bNull)
1674 switch(getTypeKind())
1676 case DataType::CHAR:
1677 case DataType::VARCHAR:
1678 case DataType::DECIMAL:
1679 case DataType::NUMERIC:
1680 case DataType::LONGVARCHAR:
1681 nRet = OUString(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:
1736 Any aValue = makeAny();
1737 aValue >>= nRet;
1738 break;
1742 return nRet;
1745 double ORowSetValue::getDouble() const
1747 double nRet = 0;
1748 if(!m_bNull)
1750 switch(getTypeKind())
1752 case DataType::CHAR:
1753 case DataType::VARCHAR:
1754 case DataType::DECIMAL:
1755 case DataType::NUMERIC:
1756 case DataType::LONGVARCHAR:
1757 nRet = OUString(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:
1812 Any aValue = makeAny();
1813 aValue >>= nRet;
1814 break;
1818 return nRet;
1821 Sequence<sal_Int8> ORowSetValue::getSequence() const
1823 Sequence<sal_Int8> aSeq;
1824 if (!m_bNull)
1826 switch(m_eTypeKind)
1828 case DataType::OBJECT:
1829 case DataType::CLOB:
1830 case DataType::BLOB:
1832 Reference<XInputStream> xStream;
1833 const Any aValue = makeAny();
1834 if(aValue.hasValue())
1836 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1837 if ( xBlob.is() )
1838 xStream = xBlob->getBinaryStream();
1839 else
1841 Reference<XClob> xClob(aValue,UNO_QUERY);
1842 if ( xClob.is() )
1843 xStream = xClob->getCharacterStream();
1845 if(xStream.is())
1847 const sal_uInt32 nBytesToRead = 65535;
1848 sal_uInt32 nRead;
1852 css::uno::Sequence< sal_Int8 > aReadSeq;
1854 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1856 if( nRead )
1858 const sal_uInt32 nOldLength = aSeq.getLength();
1859 aSeq.realloc( nOldLength + nRead );
1860 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1863 while( nBytesToRead == nRead );
1864 xStream->closeInput();
1868 break;
1869 case DataType::VARCHAR:
1870 case DataType::LONGVARCHAR:
1872 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(m_aValue.m_pString->buffer),
1873 sizeof(sal_Unicode) * m_aValue.m_pString->length);
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:
1883 Any aValue = makeAny();
1884 aValue >>= aSeq;
1885 break;
1889 return aSeq;
1893 css::util::Date ORowSetValue::getDate() const
1895 css::util::Date aValue;
1896 if(!m_bNull)
1898 switch(m_eTypeKind)
1900 case DataType::CHAR:
1901 case DataType::VARCHAR:
1902 case DataType::LONGVARCHAR:
1903 aValue = DBTypeConversion::toDate(getString());
1904 break;
1905 case DataType::DECIMAL:
1906 case DataType::NUMERIC:
1907 case DataType::FLOAT:
1908 case DataType::DOUBLE:
1909 case DataType::REAL:
1910 aValue = DBTypeConversion::toDate(static_cast<double>(*this));
1911 break;
1913 case DataType::DATE:
1914 aValue = *static_cast< css::util::Date*>(m_aValue.m_pValue);
1915 break;
1916 case DataType::TIMESTAMP:
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;
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( sal_Int64( *this ) ) );
1931 break;
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]];
1940 case DataType::BINARY:
1941 case DataType::VARBINARY:
1942 case DataType::LONGVARBINARY:
1943 case DataType::TIME:
1944 aValue = DBTypeConversion::toDate( double(0) );
1945 break;
1948 return aValue;
1951 css::util::Time ORowSetValue::getTime() const
1953 css::util::Time aValue;
1954 if(!m_bNull)
1956 switch(m_eTypeKind)
1958 case DataType::CHAR:
1959 case DataType::VARCHAR:
1960 case DataType::LONGVARCHAR:
1961 aValue = DBTypeConversion::toTime(getString());
1962 break;
1963 case DataType::DECIMAL:
1964 case DataType::NUMERIC:
1965 aValue = DBTypeConversion::toTime(static_cast<double>(*this));
1966 break;
1967 case DataType::FLOAT:
1968 case DataType::DOUBLE:
1969 case DataType::REAL:
1970 aValue = DBTypeConversion::toTime(static_cast<double>(*this));
1971 break;
1972 case DataType::TIMESTAMP:
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;
1980 break;
1981 case DataType::TIME:
1982 aValue = *static_cast< css::util::Time*>(m_aValue.m_pValue);
1983 break;
1984 default:
1986 Any aAnyValue = makeAny();
1987 aAnyValue >>= aValue;
1988 break;
1992 return aValue;
1995 css::util::DateTime ORowSetValue::getDateTime() const
1997 css::util::DateTime aValue;
1998 if(!m_bNull)
2000 switch(m_eTypeKind)
2002 case DataType::CHAR:
2003 case DataType::VARCHAR:
2004 case DataType::LONGVARCHAR:
2005 aValue = DBTypeConversion::toDateTime(getString());
2006 break;
2007 case DataType::DECIMAL:
2008 case DataType::NUMERIC:
2009 aValue = DBTypeConversion::toDateTime(static_cast<double>(*this));
2010 break;
2011 case DataType::FLOAT:
2012 case DataType::DOUBLE:
2013 case DataType::REAL:
2014 aValue = DBTypeConversion::toDateTime(static_cast<double>(*this));
2015 break;
2016 case DataType::DATE:
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;
2023 break;
2024 case DataType::TIME:
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;
2032 break;
2033 case DataType::TIMESTAMP:
2034 aValue = *static_cast< css::util::DateTime*>(m_aValue.m_pValue);
2035 break;
2036 default:
2038 Any aAnyValue = makeAny();
2039 aAnyValue >>= aValue;
2040 break;
2044 return aValue;
2047 void ORowSetValue::setSigned(bool _bMod)
2049 if ( m_bSigned == _bMod )
2050 return;
2052 m_bSigned = _bMod;
2053 if ( m_bNull )
2054 return;
2056 sal_Int32 nType = m_eTypeKind;
2057 switch(m_eTypeKind)
2059 case DataType::TINYINT:
2060 if ( m_bSigned )
2061 (*this) = getInt8();
2062 else
2064 m_bSigned = !m_bSigned;
2065 (*this) = getInt16();
2066 m_bSigned = !m_bSigned;
2068 break;
2069 case DataType::SMALLINT:
2070 if ( m_bSigned )
2071 (*this) = getInt16();
2072 else
2074 m_bSigned = !m_bSigned;
2075 (*this) = getInt32();
2076 m_bSigned = !m_bSigned;
2078 break;
2079 case DataType::INTEGER:
2080 if ( m_bSigned )
2081 (*this) = getInt32();
2082 else
2084 m_bSigned = !m_bSigned;
2085 (*this) = getLong();
2086 m_bSigned = !m_bSigned;
2088 break;
2089 case DataType::BIGINT:
2091 if ( m_bSigned )
2093 auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64);
2094 m_aValue.m_nInt64 = nTmp;
2096 else
2098 auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2099 m_aValue.m_uInt64 = nTmp;
2101 break;
2104 m_eTypeKind = nType;
2108 namespace detail
2110 class SAL_NO_VTABLE IValueSource
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;
2130 virtual ~IValueSource() { }
2133 namespace {
2135 class RowValue : public IValueSource
2137 public:
2138 RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2139 :m_xRow( _xRow )
2140 ,m_nPos( _nPos )
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( ); };
2162 private:
2163 const Reference< XRow > m_xRow;
2164 const sal_Int32 m_nPos;
2167 class ColumnValue : public IValueSource
2169 public:
2170 explicit ColumnValue( const Reference< XColumn >& _rxColumn )
2171 :m_xColumn( _rxColumn )
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( ); };
2193 private:
2194 const Reference< XColumn > m_xColumn;
2201 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2203 detail::ColumnValue aColumnValue( _rxColumn );
2204 impl_fill( _nType, true, aColumnValue );
2208 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2210 detail::RowValue aRowValue( _xRow, _nPos );
2211 impl_fill( _nType, _bNullable, aRowValue );
2215 void ORowSetValue::fill(sal_Int32 _nPos,
2216 sal_Int32 _nType,
2217 const css::uno::Reference< css::sdbc::XRow>& _xRow)
2219 fill(_nPos,_nType,true,_xRow);
2223 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2225 switch(_nType)
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::makeAny(_rValueSource.getClob());
2289 setTypeKind(DataType::CLOB);
2290 break;
2291 case DataType::BLOB:
2292 (*this) = css::uno::makeAny(_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;
2304 if ( _bNullable && _rValueSource.wasNull() )
2305 setNull();
2306 setTypeKind(_nType);
2309 void ORowSetValue::fill(const Any& _rValue)
2311 switch (_rValue.getValueType().getTypeClass())
2313 case TypeClass_VOID:
2314 setNull(); break;
2315 case TypeClass_BOOLEAN:
2317 bool bValue( false );
2318 _rValue >>= bValue;
2319 (*this) = bValue;
2320 break;
2322 case TypeClass_CHAR:
2324 sal_Unicode aDummy(0);
2325 _rValue >>= aDummy;
2326 (*this) = OUString(aDummy);
2327 break;
2329 case TypeClass_STRING:
2331 OUString sDummy;
2332 _rValue >>= sDummy;
2333 (*this) = sDummy;
2334 break;
2336 case TypeClass_FLOAT:
2338 float aDummy(0.0);
2339 _rValue >>= aDummy;
2340 (*this) = aDummy;
2341 break;
2343 case TypeClass_DOUBLE:
2345 double aDummy(0.0);
2346 _rValue >>= aDummy;
2347 (*this) = aDummy;
2348 break;
2350 case TypeClass_BYTE:
2352 sal_Int8 aDummy(0);
2353 _rValue >>= aDummy;
2354 (*this) = aDummy;
2355 break;
2357 case TypeClass_SHORT:
2359 sal_Int16 aDummy(0);
2360 _rValue >>= aDummy;
2361 (*this) = aDummy;
2362 break;
2364 case TypeClass_UNSIGNED_SHORT:
2366 sal_uInt16 nValue(0);
2367 _rValue >>= nValue;
2368 (*this) = nValue;
2369 break;
2371 case TypeClass_LONG:
2373 sal_Int32 aDummy(0);
2374 _rValue >>= aDummy;
2375 (*this) = aDummy;
2376 break;
2378 case TypeClass_UNSIGNED_LONG:
2380 sal_uInt32 nValue(0);
2381 _rValue >>= nValue;
2382 (*this) = static_cast<sal_Int64>(nValue);
2383 setSigned(false);
2384 break;
2386 case TypeClass_HYPER:
2388 sal_Int64 nValue(0);
2389 _rValue >>= nValue;
2390 (*this) = nValue;
2391 break;
2393 case TypeClass_UNSIGNED_HYPER:
2395 sal_uInt64 nValue(0);
2396 _rValue >>= nValue;
2397 (*this) = nValue;
2398 setSigned(false);
2399 break;
2401 case TypeClass_ENUM:
2403 sal_Int32 enumValue( 0 );
2404 ::cppu::enum2int( enumValue, _rValue );
2405 (*this) = enumValue;
2407 break;
2409 case TypeClass_SEQUENCE:
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;
2419 case TypeClass_STRUCT:
2421 css::util::Date aDate;
2422 css::util::Time aTime;
2423 css::util::DateTime aDateTime;
2424 if ( _rValue >>= aDate )
2426 (*this) = aDate;
2428 else if ( _rValue >>= aTime )
2430 (*this) = aTime;
2432 else if ( _rValue >>= aDateTime )
2434 (*this) = aDateTime;
2436 else
2437 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2439 break;
2441 case TypeClass_INTERFACE:
2443 Reference< XClob > xClob;
2444 if ( _rValue >>= xClob )
2446 (*this) = _rValue;
2447 setTypeKind(DataType::CLOB);
2449 else
2451 Reference< XBlob > xBlob;
2452 if ( _rValue >>= xBlob )
2454 (*this) = _rValue;
2455 setTypeKind(DataType::BLOB);
2457 else
2459 (*this) = _rValue;
2463 break;
2465 default:
2466 SAL_WARN( "connectivity.commontools","Unknown type");
2467 break;
2471 } // namespace connectivity
2473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */