bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / commontools / FValue.cxx
blob61f344bb92b5aab9e8c276520510da9d016d97a0
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/CommonTools.hxx>
24 #include <connectivity/dbconversion.hxx>
25 #include <comphelper/extract.hxx>
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/sdbc/XClob.hpp>
28 #include <com/sun/star/sdbc/XBlob.hpp>
29 #include <com/sun/star/sdb/XColumn.hpp>
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <rtl/ustrbuf.hxx>
32 #include <sal/log.hxx>
33 #include <osl/diagnose.h>
35 using namespace ::dbtools;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::util;
40 using namespace ::com::sun::star::io;
42 namespace connectivity
45 namespace {
46 bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
48 bool bIsCompatible = true;
50 if (_eType1 != _eType2)
52 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
53 switch (_eType1)
55 case DataType::CHAR:
56 case DataType::VARCHAR:
57 case DataType::DECIMAL:
58 case DataType::NUMERIC:
59 case DataType::LONGVARCHAR:
60 bIsCompatible = (DataType::CHAR == _eType2)
61 || (DataType::VARCHAR == _eType2)
62 || (DataType::DECIMAL == _eType2)
63 || (DataType::NUMERIC == _eType2)
64 || (DataType::LONGVARCHAR == _eType2);
65 break;
67 case DataType::DOUBLE:
68 case DataType::REAL:
69 bIsCompatible = (DataType::DOUBLE == _eType2)
70 || (DataType::REAL == _eType2);
71 break;
73 case DataType::BINARY:
74 case DataType::VARBINARY:
75 case DataType::LONGVARBINARY:
76 bIsCompatible = (DataType::BINARY == _eType2)
77 || (DataType::VARBINARY == _eType2)
78 || (DataType::LONGVARBINARY == _eType2);
79 break;
81 case DataType::INTEGER:
82 bIsCompatible = (DataType::SMALLINT == _eType2)
83 || (DataType::TINYINT == _eType2)
84 || (DataType::BIT == _eType2)
85 || (DataType::BOOLEAN == _eType2);
86 break;
87 case DataType::SMALLINT:
88 bIsCompatible = (DataType::TINYINT == _eType2)
89 || (DataType::BIT == _eType2)
90 || (DataType::BOOLEAN == _eType2);
91 break;
92 case DataType::TINYINT:
93 bIsCompatible = (DataType::BIT == _eType2)
94 || (DataType::BOOLEAN == _eType2);
95 break;
97 case DataType::BLOB:
98 case DataType::CLOB:
99 case DataType::OBJECT:
100 bIsCompatible = (DataType::BLOB == _eType2)
101 || (DataType::CLOB == _eType2)
102 || (DataType::OBJECT == _eType2);
103 break;
105 default:
106 bIsCompatible = false;
109 return bIsCompatible;
112 bool isStorageComparable(sal_Int32 _eType1, sal_Int32 _eType2)
114 bool bIsComparable = true;
116 if (_eType1 != _eType2)
118 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
119 switch (_eType1)
121 case DataType::CHAR:
122 case DataType::VARCHAR:
123 case DataType::LONGVARCHAR:
124 bIsComparable = (DataType::CHAR == _eType2)
125 || (DataType::VARCHAR == _eType2)
126 || (DataType::LONGVARCHAR == _eType2);
127 break;
129 case DataType::DECIMAL:
130 case DataType::NUMERIC:
131 bIsComparable = (DataType::DECIMAL == _eType2)
132 || (DataType::NUMERIC == _eType2);
133 break;
135 case DataType::DOUBLE:
136 case DataType::REAL:
137 bIsComparable = (DataType::DOUBLE == _eType2)
138 || (DataType::REAL == _eType2);
139 break;
141 case DataType::BINARY:
142 case DataType::VARBINARY:
143 case DataType::LONGVARBINARY:
144 bIsComparable = (DataType::BINARY == _eType2)
145 || (DataType::VARBINARY == _eType2)
146 || (DataType::LONGVARBINARY == _eType2);
147 break;
149 case DataType::INTEGER:
150 bIsComparable = (DataType::SMALLINT == _eType2)
151 || (DataType::TINYINT == _eType2)
152 || (DataType::BIT == _eType2)
153 || (DataType::BOOLEAN == _eType2);
154 break;
155 case DataType::SMALLINT:
156 bIsComparable = (DataType::TINYINT == _eType2)
157 || (DataType::BIT == _eType2)
158 || (DataType::BOOLEAN == _eType2);
159 break;
160 case DataType::TINYINT:
161 bIsComparable = (DataType::BIT == _eType2)
162 || (DataType::BOOLEAN == _eType2);
163 break;
165 case DataType::BLOB:
166 case DataType::CLOB:
167 case DataType::OBJECT:
168 bIsComparable = (DataType::BLOB == _eType2)
169 || (DataType::CLOB == _eType2)
170 || (DataType::OBJECT == _eType2);
171 break;
173 default:
174 bIsComparable = false;
177 return bIsComparable;
181 void ORowSetValue::setTypeKind(sal_Int32 _eType)
183 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
185 switch(_eType)
187 case DataType::VARCHAR:
188 case DataType::CHAR:
189 case DataType::DECIMAL:
190 case DataType::NUMERIC:
191 case DataType::LONGVARCHAR:
192 (*this) = getString();
193 break;
194 case DataType::BIGINT:
196 sal_Int64 nVal(getLong());
197 sal_uInt64 nuVal(getULong());
198 if (nVal == 0 && nuVal != 0)
199 (*this) = nuVal;
200 else
201 (*this) = nVal;
202 break;
205 case DataType::FLOAT:
206 (*this) = getFloat();
207 break;
208 case DataType::DOUBLE:
209 case DataType::REAL:
210 (*this) = getDouble();
211 break;
212 case DataType::TINYINT:
213 (*this) = getInt8();
214 break;
215 case DataType::SMALLINT:
216 (*this) = getInt16();
217 break;
218 case DataType::INTEGER:
220 sal_Int32 nVal(getInt32());
221 sal_uInt32 nuVal(getUInt32());
222 if (nVal == 0 && nuVal != 0)
223 (*this) = nuVal;
224 else
225 (*this) = nVal;
226 break;
228 case DataType::BIT:
229 case DataType::BOOLEAN:
230 (*this) = getBool();
231 break;
232 case DataType::DATE:
233 (*this) = getDate();
234 break;
235 case DataType::TIME:
236 (*this) = getTime();
237 break;
238 case DataType::TIMESTAMP:
239 (*this) = getDateTime();
240 break;
241 case DataType::BINARY:
242 case DataType::VARBINARY:
243 case DataType::LONGVARBINARY:
244 (*this) = getSequence();
245 break;
246 case DataType::BLOB:
247 case DataType::CLOB:
248 case DataType::OBJECT:
249 case DataType::OTHER:
250 (*this) = makeAny();
251 break;
252 default:
253 (*this) = makeAny();
254 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
258 m_eTypeKind = _eType;
262 void ORowSetValue::free()
264 if(!m_bNull)
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;
324 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
326 if(&_rRH == this)
327 return *this;
329 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
330 free();
332 m_bBound = _rRH.m_bBound;
333 m_eTypeKind = _rRH.m_eTypeKind;
334 m_bSigned = _rRH.m_bSigned;
336 if(m_bNull && !_rRH.m_bNull)
338 switch(_rRH.m_eTypeKind)
340 case DataType::CHAR:
341 case DataType::VARCHAR:
342 case DataType::DECIMAL:
343 case DataType::NUMERIC:
344 case DataType::LONGVARCHAR:
345 rtl_uString_acquire(_rRH.m_aValue.m_pString);
346 m_aValue.m_pString = _rRH.m_aValue.m_pString;
347 break;
348 case DataType::DATE:
349 m_aValue.m_pValue = new Date(*static_cast<Date*>(_rRH.m_aValue.m_pValue));
350 break;
351 case DataType::TIME:
352 m_aValue.m_pValue = new Time(*static_cast<Time*>(_rRH.m_aValue.m_pValue));
353 break;
354 case DataType::TIMESTAMP:
355 m_aValue.m_pValue = new DateTime(*static_cast<DateTime*>(_rRH.m_aValue.m_pValue));
356 break;
357 case DataType::BINARY:
358 case DataType::VARBINARY:
359 case DataType::LONGVARBINARY:
360 m_aValue.m_pValue = new Sequence<sal_Int8>(*static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue));
361 break;
362 case DataType::BIT:
363 case DataType::BOOLEAN:
364 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
365 break;
366 case DataType::TINYINT:
367 if ( _rRH.m_bSigned )
368 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
369 else
370 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
371 break;
372 case DataType::SMALLINT:
373 if ( _rRH.m_bSigned )
374 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
375 else
376 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
377 break;
378 case DataType::INTEGER:
379 if ( _rRH.m_bSigned )
380 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
381 else
382 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
383 break;
384 case DataType::BIGINT:
385 if ( _rRH.m_bSigned )
386 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
387 else
388 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
389 break;
390 case DataType::FLOAT:
391 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
392 break;
393 case DataType::DOUBLE:
394 case DataType::REAL:
395 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
396 break;
397 default:
398 m_aValue.m_pValue = new Any(*static_cast<Any*>(_rRH.m_aValue.m_pValue));
401 else if(!_rRH.m_bNull)
403 switch(_rRH.m_eTypeKind)
405 case DataType::CHAR:
406 case DataType::VARCHAR:
407 case DataType::DECIMAL:
408 case DataType::NUMERIC:
409 case DataType::LONGVARCHAR:
410 (*this) = OUString(_rRH.m_aValue.m_pString);
411 break;
412 case DataType::DATE:
413 (*this) = *static_cast<Date*>(_rRH.m_aValue.m_pValue);
414 break;
415 case DataType::TIME:
416 (*this) = *static_cast<Time*>(_rRH.m_aValue.m_pValue);
417 break;
418 case DataType::TIMESTAMP:
419 (*this) = *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
420 break;
421 case DataType::BINARY:
422 case DataType::VARBINARY:
423 case DataType::LONGVARBINARY:
424 (*this) = *static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue);
425 break;
426 case DataType::BIT:
427 case DataType::BOOLEAN:
428 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
429 break;
430 case DataType::TINYINT:
431 if ( _rRH.m_bSigned )
432 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
433 else
434 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
435 break;
436 case DataType::SMALLINT:
437 if ( _rRH.m_bSigned )
438 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
439 else
440 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
441 break;
442 case DataType::INTEGER:
443 if ( _rRH.m_bSigned )
444 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
445 else
446 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
447 break;
448 case DataType::BIGINT:
449 if ( _rRH.m_bSigned )
450 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
451 else
452 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
453 break;
454 case DataType::FLOAT:
455 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
456 break;
457 case DataType::DOUBLE:
458 case DataType::REAL:
459 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
460 break;
461 default:
462 *static_cast<Any*>(m_aValue.m_pValue) = *static_cast<Any*>(_rRH.m_aValue.m_pValue);
466 m_bNull = _rRH.m_bNull;
467 // OJ: BUGID: 96277
468 m_eTypeKind = _rRH.m_eTypeKind;
470 return *this;
473 ORowSetValue& ORowSetValue::operator=(ORowSetValue&& _rRH)
475 if ( m_eTypeKind != _rRH.m_eTypeKind || !m_bNull)
476 free();
477 if(!_rRH.m_bNull)
479 m_aValue = _rRH.m_aValue;
480 memset(&_rRH.m_aValue, 0, sizeof(_rRH.m_aValue));
482 m_bBound = _rRH.m_bBound;
483 m_eTypeKind = _rRH.m_eTypeKind;
484 m_bSigned = _rRH.m_bSigned;
485 m_bNull = _rRH.m_bNull;
486 _rRH.m_bNull = true;
487 return *this;
491 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
493 if(m_eTypeKind != DataType::DATE)
494 free();
496 if(m_bNull)
498 m_aValue.m_pValue = new Date(_rRH);
499 m_eTypeKind = DataType::DATE;
500 m_bNull = false;
502 else
503 *static_cast<Date*>(m_aValue.m_pValue) = _rRH;
505 return *this;
508 ORowSetValue& ORowSetValue::operator=(const css::util::Time& _rRH)
510 if(m_eTypeKind != DataType::TIME)
511 free();
513 if(m_bNull)
515 m_aValue.m_pValue = new Time(_rRH);
516 m_eTypeKind = DataType::TIME;
517 m_bNull = false;
519 else
520 *static_cast<Time*>(m_aValue.m_pValue) = _rRH;
522 return *this;
525 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
527 if(m_eTypeKind != DataType::TIMESTAMP)
528 free();
529 if(m_bNull)
531 m_aValue.m_pValue = new DateTime(_rRH);
532 m_eTypeKind = DataType::TIMESTAMP;
533 m_bNull = false;
535 else
536 *static_cast<DateTime*>(m_aValue.m_pValue) = _rRH;
538 return *this;
542 ORowSetValue& ORowSetValue::operator=(const OUString& _rRH)
544 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
546 free();
547 m_bNull = false;
549 m_aValue.m_pString = _rRH.pData;
550 rtl_uString_acquire(m_aValue.m_pString);
551 m_eTypeKind = DataType::VARCHAR;
554 return *this;
558 ORowSetValue& ORowSetValue::operator=(double _rRH)
560 if(m_eTypeKind != DataType::DOUBLE)
561 free();
563 m_aValue.m_nDouble = _rRH;
564 m_eTypeKind = DataType::DOUBLE;
565 m_bNull = false;
567 return *this;
570 ORowSetValue& ORowSetValue::operator=(float _rRH)
572 if(m_eTypeKind != DataType::FLOAT)
573 free();
575 m_aValue.m_nFloat = _rRH;
576 m_eTypeKind = DataType::FLOAT;
577 m_bNull = false;
579 return *this;
583 ORowSetValue& ORowSetValue::operator=(sal_Int8 _rRH)
585 if(m_eTypeKind != DataType::TINYINT )
586 free();
588 m_aValue.m_nInt8 = _rRH;
589 m_eTypeKind = DataType::TINYINT;
590 m_bNull = false;
591 m_bSigned = true;
592 return *this;
595 ORowSetValue& ORowSetValue::operator=(sal_Int16 _rRH)
597 if(m_eTypeKind != DataType::SMALLINT )
598 free();
600 m_aValue.m_nInt16 = _rRH;
601 m_eTypeKind = DataType::SMALLINT;
602 m_bNull = false;
603 m_bSigned = true;
605 return *this;
609 ORowSetValue& ORowSetValue::operator=(sal_uInt16 _rRH)
611 if(m_eTypeKind != DataType::SMALLINT )
612 free();
614 m_aValue.m_uInt16 = _rRH;
615 m_eTypeKind = DataType::SMALLINT;
616 m_bNull = false;
617 m_bSigned = false;
619 return *this;
623 ORowSetValue& ORowSetValue::operator=(sal_Int32 _rRH)
625 if(m_eTypeKind != DataType::INTEGER )
626 free();
628 m_aValue.m_nInt32 = _rRH;
630 m_eTypeKind = DataType::INTEGER;
631 m_bNull = false;
632 m_bSigned = true;
634 return *this;
638 ORowSetValue& ORowSetValue::operator=(sal_uInt32 _rRH)
640 if(m_eTypeKind != DataType::INTEGER )
641 free();
643 m_aValue.m_uInt32 = _rRH;
645 m_eTypeKind = DataType::INTEGER;
646 m_bNull = false;
647 m_bSigned = false;
649 return *this;
653 ORowSetValue& ORowSetValue::operator=(const bool _rRH)
655 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
656 free();
658 m_aValue.m_bBool = _rRH;
659 m_eTypeKind = DataType::BOOLEAN;
660 m_bNull = false;
662 return *this;
665 ORowSetValue& ORowSetValue::operator=(sal_Int64 _rRH)
667 if ( DataType::BIGINT != m_eTypeKind)
668 free();
670 m_aValue.m_nInt64 = _rRH;
671 m_eTypeKind = DataType::BIGINT;
672 m_bNull = false;
673 m_bSigned = true;
675 return *this;
678 ORowSetValue& ORowSetValue::operator=(sal_uInt64 _rRH)
680 if ( DataType::BIGINT != m_eTypeKind)
681 free();
683 m_aValue.m_uInt64 = _rRH;
684 m_eTypeKind = DataType::BIGINT;
685 m_bNull = false;
686 m_bSigned = false;
688 return *this;
691 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
693 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
694 free();
696 if (m_bNull)
698 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
700 else
701 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
703 m_eTypeKind = DataType::LONGVARBINARY;
704 m_bNull = false;
706 return *this;
709 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
711 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
712 free();
714 if ( m_bNull )
716 m_aValue.m_pValue = new Any(_rAny);
718 else
719 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
721 m_eTypeKind = DataType::OBJECT;
722 m_bNull = false;
724 return *this;
728 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
730 if ( m_bNull != _rRH.isNull() )
731 return false;
733 if(m_bNull && _rRH.isNull())
734 return true;
736 if ( !isStorageComparable(m_eTypeKind, _rRH.m_eTypeKind ))
738 switch(m_eTypeKind)
740 case DataType::FLOAT:
741 case DataType::DOUBLE:
742 case DataType::REAL:
743 return getDouble() == _rRH.getDouble();
744 default:
745 switch(_rRH.m_eTypeKind)
747 case DataType::FLOAT:
748 case DataType::DOUBLE:
749 case DataType::REAL:
750 return getDouble() == _rRH.getDouble();
751 default:
752 break;
754 break;
756 return false;
759 bool bRet = false;
760 OSL_ENSURE(!m_bNull,"Should not be null!");
761 switch(m_eTypeKind)
763 case DataType::VARCHAR:
764 case DataType::CHAR:
765 case DataType::LONGVARCHAR:
767 OUString aVal1(m_aValue.m_pString);
768 OUString aVal2(_rRH.m_aValue.m_pString);
769 return aVal1 == aVal2;
771 default:
772 if ( m_bSigned != _rRH.m_bSigned )
773 return false;
774 break;
777 switch(m_eTypeKind)
779 case DataType::DECIMAL:
780 case DataType::NUMERIC:
782 OUString aVal1(m_aValue.m_pString);
783 OUString aVal2(_rRH.m_aValue.m_pString);
784 bRet = aVal1 == aVal2;
786 break;
787 case DataType::FLOAT:
788 bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
789 break;
790 case DataType::DOUBLE:
791 case DataType::REAL:
792 bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
793 break;
794 case DataType::TINYINT:
795 bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
796 break;
797 case DataType::SMALLINT:
798 bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_uInt16 == _rRH.m_aValue.m_uInt16);
799 break;
800 case DataType::INTEGER:
801 bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (m_aValue.m_uInt32 == _rRH.m_aValue.m_uInt32);
802 break;
803 case DataType::BIGINT:
804 bRet = m_bSigned ? ( m_aValue.m_nInt64 == _rRH.m_aValue.m_nInt64 ) : (m_aValue.m_uInt64 == _rRH.m_aValue.m_uInt64);
805 break;
806 case DataType::BIT:
807 case DataType::BOOLEAN:
808 bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
809 break;
810 case DataType::DATE:
811 bRet = *static_cast<Date*>(m_aValue.m_pValue) == *static_cast<Date*>(_rRH.m_aValue.m_pValue);
812 break;
813 case DataType::TIME:
814 bRet = *static_cast<Time*>(m_aValue.m_pValue) == *static_cast<Time*>(_rRH.m_aValue.m_pValue);
815 break;
816 case DataType::TIMESTAMP:
817 bRet = *static_cast<DateTime*>(m_aValue.m_pValue) == *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
818 break;
819 case DataType::BINARY:
820 case DataType::VARBINARY:
821 case DataType::LONGVARBINARY:
822 bRet = false;
823 break;
824 case DataType::BLOB:
825 case DataType::CLOB:
826 case DataType::OBJECT:
827 case DataType::OTHER:
828 bRet = false;
829 break;
830 default:
831 bRet = false;
832 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
833 break;
835 return bRet;
838 Any ORowSetValue::makeAny() const
840 Any rValue;
841 if(isBound() && !isNull())
843 switch(getTypeKind())
845 case DataType::SQLNULL:
846 assert(rValue == Any());
847 break;
848 case DataType::CHAR:
849 case DataType::VARCHAR:
850 case DataType::DECIMAL:
851 case DataType::NUMERIC:
852 case DataType::LONGVARCHAR:
853 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
854 rValue <<= OUString(m_aValue.m_pString);
855 break;
856 case DataType::FLOAT:
857 rValue <<= m_aValue.m_nFloat;
858 break;
859 case DataType::DOUBLE:
860 case DataType::REAL:
861 rValue <<= m_aValue.m_nDouble;
862 break;
863 case DataType::DATE:
864 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
865 rValue <<= *static_cast<Date*>(m_aValue.m_pValue);
866 break;
867 case DataType::TIME:
868 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
869 rValue <<= *static_cast<Time*>(m_aValue.m_pValue);
870 break;
871 case DataType::TIMESTAMP:
872 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
873 rValue <<= *static_cast<DateTime*>(m_aValue.m_pValue);
874 break;
875 case DataType::BINARY:
876 case DataType::VARBINARY:
877 case DataType::LONGVARBINARY:
878 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
879 rValue <<= *static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
880 break;
881 case DataType::BLOB:
882 case DataType::CLOB:
883 case DataType::OBJECT:
884 case DataType::OTHER:
885 rValue = getAny();
886 break;
887 case DataType::BIT:
888 case DataType::BOOLEAN:
889 rValue <<= m_aValue.m_bBool;
890 break;
891 case DataType::TINYINT:
892 if ( m_bSigned )
893 // TypeClass_BYTE
894 rValue <<= m_aValue.m_nInt8;
895 else
896 // There is no TypeClass_UNSIGNED_BYTE,
897 // so silently promote it to a 16-bit integer,
898 // that is TypeClass_UNSIGNED_SHORT
899 rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
900 break;
901 case DataType::SMALLINT:
902 if ( m_bSigned )
903 // TypeClass_SHORT
904 rValue <<= m_aValue.m_nInt16;
905 else
906 // TypeClass_UNSIGNED_SHORT
907 rValue <<= m_aValue.m_uInt16;
908 break;
909 case DataType::INTEGER:
910 if ( m_bSigned )
911 // TypeClass_LONG
912 rValue <<= m_aValue.m_nInt32;
913 else
914 // TypeClass_UNSIGNED_LONG
915 rValue <<= m_aValue.m_uInt32;
916 break;
917 case DataType::BIGINT:
918 if ( m_bSigned )
919 // TypeClass_HYPER
920 rValue <<= m_aValue.m_nInt64;
921 else
922 // TypeClass_UNSIGNED_HYPER
923 rValue <<= m_aValue.m_uInt64;
924 break;
925 default:
926 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
927 rValue = getAny();
928 break;
931 return rValue;
934 OUString ORowSetValue::getString( ) const
936 OUString aRet;
937 if(!m_bNull)
939 switch(getTypeKind())
941 case DataType::CHAR:
942 case DataType::VARCHAR:
943 case DataType::DECIMAL:
944 case DataType::NUMERIC:
945 case DataType::LONGVARCHAR:
946 aRet = m_aValue.m_pString;
947 break;
948 case DataType::FLOAT:
949 aRet = OUString::number(static_cast<float>(*this));
950 break;
951 case DataType::DOUBLE:
952 case DataType::REAL:
953 aRet = OUString::number(static_cast<double>(*this));
954 break;
955 case DataType::DATE:
956 aRet = DBTypeConversion::toDateString(*this);
957 break;
958 case DataType::TIME:
959 aRet = DBTypeConversion::toTimeString(*this);
960 break;
961 case DataType::TIMESTAMP:
962 aRet = DBTypeConversion::toDateTimeString(*this);
963 break;
964 case DataType::BINARY:
965 case DataType::VARBINARY:
966 case DataType::LONGVARBINARY:
968 OUStringBuffer sVal("0x");
969 Sequence<sal_Int8> aSeq(getSequence());
970 const sal_Int8* pBegin = aSeq.getConstArray();
971 const sal_Int8* pEnd = pBegin + aSeq.getLength();
972 for(;pBegin != pEnd;++pBegin)
973 sVal.append(static_cast<sal_Int32>(*pBegin),16);
974 aRet = sVal.makeStringAndClear();
976 break;
977 case DataType::BIT:
978 aRet = OUString::number(int(static_cast<bool>(*this)));
979 break;
980 case DataType::BOOLEAN:
981 aRet = OUString::boolean(static_cast<bool>(*this));
982 break;
983 case DataType::TINYINT:
984 case DataType::SMALLINT:
985 case DataType::INTEGER:
986 if ( m_bSigned )
987 aRet = OUString::number(static_cast<sal_Int32>(*this));
988 else
989 aRet = OUString::number(static_cast<sal_uInt32>(*this));
990 break;
991 case DataType::BIGINT:
992 if ( m_bSigned )
993 aRet = OUString::number(static_cast<sal_Int64>(*this));
994 else
995 aRet = OUString::number(static_cast<sal_uInt64>(*this));
996 break;
997 case DataType::CLOB:
999 Any aValue( getAny() );
1000 Reference< XClob > xClob;
1001 if ( (aValue >>= xClob) && xClob.is() )
1003 aRet = xClob->getSubString(1,static_cast<sal_Int32>(xClob->length()) );
1006 break;
1007 default:
1009 Any aValue = makeAny();
1010 aValue >>= aRet;
1011 break;
1015 return aRet;
1018 bool ORowSetValue::getBool() const
1020 bool bRet = false;
1021 if(!m_bNull)
1023 switch(getTypeKind())
1025 case DataType::CHAR:
1026 case DataType::VARCHAR:
1027 case DataType::LONGVARCHAR:
1029 const OUString sValue(m_aValue.m_pString);
1030 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1032 bRet = true;
1033 break;
1035 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1037 bRet = false;
1038 break;
1041 [[fallthrough]];
1042 case DataType::DECIMAL:
1043 case DataType::NUMERIC:
1045 bRet = OUString(m_aValue.m_pString).toInt32() != 0;
1046 break;
1047 case DataType::FLOAT:
1048 bRet = m_aValue.m_nFloat != 0.0;
1049 break;
1050 case DataType::DOUBLE:
1051 case DataType::REAL:
1052 bRet = m_aValue.m_nDouble != 0.0;
1053 break;
1054 case DataType::DATE:
1055 case DataType::TIME:
1056 case DataType::TIMESTAMP:
1057 case DataType::BINARY:
1058 case DataType::VARBINARY:
1059 case DataType::LONGVARBINARY:
1060 OSL_FAIL("getBool() for this type is not allowed!");
1061 break;
1062 case DataType::BIT:
1063 case DataType::BOOLEAN:
1064 bRet = m_aValue.m_bBool;
1065 break;
1066 case DataType::TINYINT:
1067 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_uInt8 != 0);
1068 break;
1069 case DataType::SMALLINT:
1070 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_uInt16 != 0);
1071 break;
1072 case DataType::INTEGER:
1073 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1074 break;
1075 case DataType::BIGINT:
1076 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1077 break;
1078 default:
1080 Any aValue = makeAny();
1081 aValue >>= bRet;
1082 break;
1086 return bRet;
1090 sal_Int8 ORowSetValue::getInt8() const
1092 sal_Int8 nRet = 0;
1093 if(!m_bNull)
1095 switch(getTypeKind())
1097 case DataType::CHAR:
1098 case DataType::VARCHAR:
1099 case DataType::DECIMAL:
1100 case DataType::NUMERIC:
1101 case DataType::LONGVARCHAR:
1102 nRet = sal_Int8(OUString(m_aValue.m_pString).toInt32());
1103 break;
1104 case DataType::FLOAT:
1105 nRet = sal_Int8(m_aValue.m_nFloat);
1106 break;
1107 case DataType::DOUBLE:
1108 case DataType::REAL:
1109 nRet = sal_Int8(m_aValue.m_nDouble);
1110 break;
1111 case DataType::DATE:
1112 case DataType::TIME:
1113 case DataType::TIMESTAMP:
1114 case DataType::BINARY:
1115 case DataType::VARBINARY:
1116 case DataType::LONGVARBINARY:
1117 case DataType::BLOB:
1118 case DataType::CLOB:
1119 OSL_FAIL("getInt8() for this type is not allowed!");
1120 break;
1121 case DataType::BIT:
1122 case DataType::BOOLEAN:
1123 nRet = sal_Int8(m_aValue.m_bBool);
1124 break;
1125 case DataType::TINYINT:
1126 if ( m_bSigned )
1127 nRet = m_aValue.m_nInt8;
1128 else
1129 nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1130 break;
1131 case DataType::SMALLINT:
1132 if ( m_bSigned )
1133 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1134 else
1135 nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1136 break;
1137 case DataType::INTEGER:
1138 if ( m_bSigned )
1139 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1140 else
1141 nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1142 break;
1143 case DataType::BIGINT:
1144 if ( m_bSigned )
1145 nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1146 else
1147 nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1148 break;
1149 default:
1151 Any aValue = makeAny();
1152 aValue >>= nRet;
1153 break;
1157 return nRet;
1161 sal_uInt8 ORowSetValue::getUInt8() const
1163 sal_uInt8 nRet = 0;
1164 if(!m_bNull)
1166 switch(getTypeKind())
1168 case DataType::CHAR:
1169 case DataType::VARCHAR:
1170 case DataType::DECIMAL:
1171 case DataType::NUMERIC:
1172 case DataType::LONGVARCHAR:
1173 nRet = sal_uInt8(OUString(m_aValue.m_pString).toInt32());
1174 break;
1175 case DataType::FLOAT:
1176 nRet = sal_uInt8(m_aValue.m_nFloat);
1177 break;
1178 case DataType::DOUBLE:
1179 case DataType::REAL:
1180 nRet = sal_uInt8(m_aValue.m_nDouble);
1181 break;
1182 case DataType::DATE:
1183 case DataType::TIME:
1184 case DataType::TIMESTAMP:
1185 case DataType::BINARY:
1186 case DataType::VARBINARY:
1187 case DataType::LONGVARBINARY:
1188 case DataType::BLOB:
1189 case DataType::CLOB:
1190 OSL_FAIL("getuInt8() for this type is not allowed!");
1191 break;
1192 case DataType::BIT:
1193 case DataType::BOOLEAN:
1194 nRet = int(m_aValue.m_bBool);
1195 break;
1196 case DataType::TINYINT:
1197 if ( m_bSigned )
1198 nRet = m_aValue.m_nInt8;
1199 else
1200 nRet = m_aValue.m_uInt8;
1201 break;
1202 case DataType::SMALLINT:
1203 if ( m_bSigned )
1204 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1205 else
1206 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1207 break;
1208 case DataType::INTEGER:
1209 if ( m_bSigned )
1210 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1211 else
1212 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1213 break;
1214 case DataType::BIGINT:
1215 if ( m_bSigned )
1216 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1217 else
1218 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1219 break;
1220 default:
1222 Any aValue = makeAny();
1223 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1224 sal_uInt16 n;
1225 if (aValue >>= n) {
1226 nRet = static_cast<sal_uInt8>(n);
1228 break;
1232 return nRet;
1236 sal_Int16 ORowSetValue::getInt16() const
1238 sal_Int16 nRet = 0;
1239 if(!m_bNull)
1241 switch(getTypeKind())
1243 case DataType::CHAR:
1244 case DataType::VARCHAR:
1245 case DataType::DECIMAL:
1246 case DataType::NUMERIC:
1247 case DataType::LONGVARCHAR:
1248 nRet = sal_Int16(OUString(m_aValue.m_pString).toInt32());
1249 break;
1250 case DataType::FLOAT:
1251 nRet = sal_Int16(m_aValue.m_nFloat);
1252 break;
1253 case DataType::DOUBLE:
1254 case DataType::REAL:
1255 nRet = sal_Int16(m_aValue.m_nDouble);
1256 break;
1257 case DataType::DATE:
1258 case DataType::TIME:
1259 case DataType::TIMESTAMP:
1260 case DataType::BINARY:
1261 case DataType::VARBINARY:
1262 case DataType::LONGVARBINARY:
1263 case DataType::BLOB:
1264 case DataType::CLOB:
1265 OSL_FAIL("getInt16() for this type is not allowed!");
1266 break;
1267 case DataType::BIT:
1268 case DataType::BOOLEAN:
1269 nRet = sal_Int16(m_aValue.m_bBool);
1270 break;
1271 case DataType::TINYINT:
1272 if ( m_bSigned )
1273 nRet = m_aValue.m_nInt8;
1274 else
1275 nRet = m_aValue.m_uInt8;
1276 break;
1277 case DataType::SMALLINT:
1278 if ( m_bSigned )
1279 nRet = m_aValue.m_nInt16;
1280 else
1281 nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1282 break;
1283 case DataType::INTEGER:
1284 if ( m_bSigned )
1285 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1286 else
1287 nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1288 break;
1289 case DataType::BIGINT:
1290 if ( m_bSigned )
1291 nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1292 else
1293 nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1294 break;
1295 default:
1297 Any aValue = makeAny();
1298 aValue >>= nRet;
1299 break;
1303 return nRet;
1307 sal_uInt16 ORowSetValue::getUInt16() const
1309 sal_uInt16 nRet = 0;
1310 if(!m_bNull)
1312 switch(getTypeKind())
1314 case DataType::CHAR:
1315 case DataType::VARCHAR:
1316 case DataType::DECIMAL:
1317 case DataType::NUMERIC:
1318 case DataType::LONGVARCHAR:
1319 nRet = sal_uInt16(OUString(m_aValue.m_pString).toInt32());
1320 break;
1321 case DataType::FLOAT:
1322 nRet = sal_uInt16(m_aValue.m_nFloat);
1323 break;
1324 case DataType::DOUBLE:
1325 case DataType::REAL:
1326 nRet = sal_uInt16(m_aValue.m_nDouble);
1327 break;
1328 case DataType::DATE:
1329 case DataType::TIME:
1330 case DataType::TIMESTAMP:
1331 case DataType::BINARY:
1332 case DataType::VARBINARY:
1333 case DataType::LONGVARBINARY:
1334 case DataType::BLOB:
1335 case DataType::CLOB:
1336 OSL_FAIL("getuInt16() for this type is not allowed!");
1337 break;
1338 case DataType::BIT:
1339 case DataType::BOOLEAN:
1340 nRet = sal_uInt16(m_aValue.m_bBool);
1341 break;
1342 case DataType::TINYINT:
1343 if ( m_bSigned )
1344 nRet = m_aValue.m_nInt8;
1345 else
1346 nRet = m_aValue.m_uInt8;
1347 break;
1348 case DataType::SMALLINT:
1349 if ( m_bSigned )
1350 nRet = m_aValue.m_nInt16;
1351 else
1352 nRet = m_aValue.m_uInt16;
1353 break;
1354 case DataType::INTEGER:
1355 if ( m_bSigned )
1356 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1357 else
1358 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1359 break;
1360 case DataType::BIGINT:
1361 if ( m_bSigned )
1362 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1363 else
1364 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1365 break;
1366 default:
1368 Any aValue = makeAny();
1369 aValue >>= nRet;
1370 break;
1374 return nRet;
1378 sal_Int32 ORowSetValue::getInt32() const
1380 sal_Int32 nRet = 0;
1381 if(!m_bNull)
1383 switch(getTypeKind())
1385 case DataType::CHAR:
1386 case DataType::VARCHAR:
1387 case DataType::DECIMAL:
1388 case DataType::NUMERIC:
1389 case DataType::LONGVARCHAR:
1390 nRet = OUString(m_aValue.m_pString).toInt32();
1391 break;
1392 case DataType::FLOAT:
1393 nRet = sal_Int32(m_aValue.m_nFloat);
1394 break;
1395 case DataType::DOUBLE:
1396 case DataType::REAL:
1397 nRet = sal_Int32(m_aValue.m_nDouble);
1398 break;
1399 case DataType::DATE:
1400 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1401 break;
1402 case DataType::TIME:
1403 case DataType::TIMESTAMP:
1404 case DataType::BINARY:
1405 case DataType::VARBINARY:
1406 case DataType::LONGVARBINARY:
1407 case DataType::BLOB:
1408 case DataType::CLOB:
1409 OSL_FAIL("getInt32() for this type is not allowed!");
1410 break;
1411 case DataType::BIT:
1412 case DataType::BOOLEAN:
1413 nRet = sal_Int32(m_aValue.m_bBool);
1414 break;
1415 case DataType::TINYINT:
1416 if ( m_bSigned )
1417 nRet = m_aValue.m_nInt8;
1418 else
1419 nRet = m_aValue.m_uInt8;
1420 break;
1421 case DataType::SMALLINT:
1422 if ( m_bSigned )
1423 nRet = m_aValue.m_nInt16;
1424 else
1425 nRet = m_aValue.m_uInt16;
1426 break;
1427 case DataType::INTEGER:
1428 if ( m_bSigned )
1429 nRet = m_aValue.m_nInt32;
1430 else
1431 nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1432 break;
1433 case DataType::BIGINT:
1434 if ( m_bSigned )
1435 nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1436 else
1437 nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1438 break;
1439 default:
1441 Any aValue = makeAny();
1442 aValue >>= nRet;
1443 break;
1447 return nRet;
1451 sal_uInt32 ORowSetValue::getUInt32() const
1453 sal_uInt32 nRet = 0;
1454 if(!m_bNull)
1456 switch(getTypeKind())
1458 case DataType::CHAR:
1459 case DataType::VARCHAR:
1460 case DataType::DECIMAL:
1461 case DataType::NUMERIC:
1462 case DataType::LONGVARCHAR:
1463 nRet = OUString(m_aValue.m_pString).toUInt32();
1464 break;
1465 case DataType::FLOAT:
1466 nRet = sal_uInt32(m_aValue.m_nFloat);
1467 break;
1468 case DataType::DOUBLE:
1469 case DataType::REAL:
1470 nRet = sal_uInt32(m_aValue.m_nDouble);
1471 break;
1472 case DataType::DATE:
1473 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1474 break;
1475 case DataType::TIME:
1476 case DataType::TIMESTAMP:
1477 case DataType::BINARY:
1478 case DataType::VARBINARY:
1479 case DataType::LONGVARBINARY:
1480 case DataType::BLOB:
1481 case DataType::CLOB:
1482 OSL_FAIL("getuInt32() for this type is not allowed!");
1483 break;
1484 case DataType::BIT:
1485 case DataType::BOOLEAN:
1486 nRet = sal_uInt32(m_aValue.m_bBool);
1487 break;
1488 case DataType::TINYINT:
1489 if ( m_bSigned )
1490 nRet = m_aValue.m_nInt8;
1491 else
1492 nRet = m_aValue.m_uInt8;
1493 break;
1494 case DataType::SMALLINT:
1495 if ( m_bSigned )
1496 nRet = m_aValue.m_nInt16;
1497 else
1498 nRet = m_aValue.m_uInt16;
1499 break;
1500 case DataType::INTEGER:
1501 if ( m_bSigned )
1502 nRet = m_aValue.m_nInt32;
1503 else
1504 nRet = m_aValue.m_uInt32;
1505 break;
1506 case DataType::BIGINT:
1507 if ( m_bSigned )
1508 nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1509 else
1510 nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1511 break;
1512 default:
1514 Any aValue = makeAny();
1515 aValue >>= nRet;
1516 break;
1520 return nRet;
1524 sal_Int64 ORowSetValue::getLong() const
1526 sal_Int64 nRet = 0;
1527 if(!m_bNull)
1529 switch(getTypeKind())
1531 case DataType::CHAR:
1532 case DataType::VARCHAR:
1533 case DataType::DECIMAL:
1534 case DataType::NUMERIC:
1535 case DataType::LONGVARCHAR:
1536 nRet = OUString(m_aValue.m_pString).toInt64();
1537 break;
1538 case DataType::FLOAT:
1539 nRet = sal_Int64(m_aValue.m_nFloat);
1540 break;
1541 case DataType::DOUBLE:
1542 case DataType::REAL:
1543 nRet = sal_Int64(m_aValue.m_nDouble);
1544 break;
1545 case DataType::DATE:
1546 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1547 break;
1548 case DataType::TIME:
1549 case DataType::TIMESTAMP:
1550 case DataType::BINARY:
1551 case DataType::VARBINARY:
1552 case DataType::LONGVARBINARY:
1553 case DataType::BLOB:
1554 case DataType::CLOB:
1555 OSL_FAIL("getLong() for this type is not allowed!");
1556 break;
1557 case DataType::BIT:
1558 case DataType::BOOLEAN:
1559 nRet = sal_Int64(m_aValue.m_bBool);
1560 break;
1561 case DataType::TINYINT:
1562 if ( m_bSigned )
1563 nRet = m_aValue.m_nInt8;
1564 else
1565 nRet = m_aValue.m_uInt8;
1566 break;
1567 case DataType::SMALLINT:
1568 if ( m_bSigned )
1569 nRet = m_aValue.m_nInt16;
1570 else
1571 nRet = m_aValue.m_uInt16;
1572 break;
1573 case DataType::INTEGER:
1574 if ( m_bSigned )
1575 nRet = m_aValue.m_nInt32;
1576 else
1577 nRet = m_aValue.m_uInt32;
1578 break;
1579 case DataType::BIGINT:
1580 if ( m_bSigned )
1581 nRet = m_aValue.m_nInt64;
1582 else
1583 nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1584 break;
1585 default:
1587 Any aValue = makeAny();
1588 aValue >>= nRet;
1589 break;
1593 return nRet;
1597 sal_uInt64 ORowSetValue::getULong() const
1599 sal_uInt64 nRet = 0;
1600 if(!m_bNull)
1602 switch(getTypeKind())
1604 case DataType::CHAR:
1605 case DataType::VARCHAR:
1606 case DataType::DECIMAL:
1607 case DataType::NUMERIC:
1608 case DataType::LONGVARCHAR:
1609 nRet = OUString(m_aValue.m_pString).toUInt64();
1610 break;
1611 case DataType::FLOAT:
1612 nRet = sal_uInt64(m_aValue.m_nFloat);
1613 break;
1614 case DataType::DOUBLE:
1615 case DataType::REAL:
1616 nRet = sal_uInt64(m_aValue.m_nDouble);
1617 break;
1618 case DataType::DATE:
1619 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1620 break;
1621 case DataType::TIME:
1622 case DataType::TIMESTAMP:
1623 case DataType::BINARY:
1624 case DataType::VARBINARY:
1625 case DataType::LONGVARBINARY:
1626 case DataType::BLOB:
1627 case DataType::CLOB:
1628 OSL_FAIL("getULong() for this type is not allowed!");
1629 break;
1630 case DataType::BIT:
1631 case DataType::BOOLEAN:
1632 nRet = sal_uInt64(m_aValue.m_bBool);
1633 break;
1634 case DataType::TINYINT:
1635 if ( m_bSigned )
1636 nRet = m_aValue.m_nInt8;
1637 else
1638 nRet = m_aValue.m_uInt8;
1639 break;
1640 case DataType::SMALLINT:
1641 if ( m_bSigned )
1642 nRet = m_aValue.m_nInt16;
1643 else
1644 nRet = m_aValue.m_uInt16;
1645 break;
1646 case DataType::INTEGER:
1647 if ( m_bSigned )
1648 nRet = m_aValue.m_nInt32;
1649 else
1650 nRet = m_aValue.m_uInt32;
1651 break;
1652 case DataType::BIGINT:
1653 if ( m_bSigned )
1654 nRet = m_aValue.m_nInt64;
1655 else
1656 nRet = m_aValue.m_uInt64;
1657 break;
1658 default:
1660 Any aValue = makeAny();
1661 aValue >>= nRet;
1662 break;
1666 return nRet;
1670 float ORowSetValue::getFloat() const
1672 float nRet = 0;
1673 if(!m_bNull)
1675 switch(getTypeKind())
1677 case DataType::CHAR:
1678 case DataType::VARCHAR:
1679 case DataType::DECIMAL:
1680 case DataType::NUMERIC:
1681 case DataType::LONGVARCHAR:
1682 nRet = OUString(m_aValue.m_pString).toFloat();
1683 break;
1684 case DataType::FLOAT:
1685 nRet = m_aValue.m_nFloat;
1686 break;
1687 case DataType::DOUBLE:
1688 case DataType::REAL:
1689 nRet = static_cast<float>(m_aValue.m_nDouble);
1690 break;
1691 case DataType::DATE:
1692 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue)));
1693 break;
1694 case DataType::TIME:
1695 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue)));
1696 break;
1697 case DataType::TIMESTAMP:
1698 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue)));
1699 break;
1700 case DataType::BINARY:
1701 case DataType::VARBINARY:
1702 case DataType::LONGVARBINARY:
1703 case DataType::BLOB:
1704 case DataType::CLOB:
1705 OSL_FAIL("getDouble() for this type is not allowed!");
1706 break;
1707 case DataType::BIT:
1708 case DataType::BOOLEAN:
1709 nRet = float(m_aValue.m_bBool);
1710 break;
1711 case DataType::TINYINT:
1712 if ( m_bSigned )
1713 nRet = m_aValue.m_nInt8;
1714 else
1715 nRet = m_aValue.m_uInt8;
1716 break;
1717 case DataType::SMALLINT:
1718 if ( m_bSigned )
1719 nRet = m_aValue.m_nInt16;
1720 else
1721 nRet = static_cast<float>(m_aValue.m_uInt16);
1722 break;
1723 case DataType::INTEGER:
1724 if ( m_bSigned )
1725 nRet = static_cast<float>(m_aValue.m_nInt32);
1726 else
1727 nRet = static_cast<float>(m_aValue.m_uInt32);
1728 break;
1729 case DataType::BIGINT:
1730 if ( m_bSigned )
1731 nRet = static_cast<float>(m_aValue.m_nInt64);
1732 else
1733 nRet = static_cast<float>(m_aValue.m_uInt64);
1734 break;
1735 default:
1737 Any aValue = makeAny();
1738 aValue >>= nRet;
1739 break;
1743 return nRet;
1746 double ORowSetValue::getDouble() const
1748 double nRet = 0;
1749 if(!m_bNull)
1751 switch(getTypeKind())
1753 case DataType::CHAR:
1754 case DataType::VARCHAR:
1755 case DataType::DECIMAL:
1756 case DataType::NUMERIC:
1757 case DataType::LONGVARCHAR:
1758 nRet = OUString(m_aValue.m_pString).toDouble();
1759 break;
1760 case DataType::FLOAT:
1761 nRet = m_aValue.m_nFloat;
1762 break;
1763 case DataType::DOUBLE:
1764 case DataType::REAL:
1765 nRet = m_aValue.m_nDouble;
1766 break;
1767 case DataType::DATE:
1768 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1769 break;
1770 case DataType::TIME:
1771 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1772 break;
1773 case DataType::TIMESTAMP:
1774 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1775 break;
1776 case DataType::BINARY:
1777 case DataType::VARBINARY:
1778 case DataType::LONGVARBINARY:
1779 case DataType::BLOB:
1780 case DataType::CLOB:
1781 OSL_FAIL("getDouble() for this type is not allowed!");
1782 break;
1783 case DataType::BIT:
1784 case DataType::BOOLEAN:
1785 nRet = double(m_aValue.m_bBool);
1786 break;
1787 case DataType::TINYINT:
1788 if ( m_bSigned )
1789 nRet = m_aValue.m_nInt8;
1790 else
1791 nRet = m_aValue.m_uInt8;
1792 break;
1793 case DataType::SMALLINT:
1794 if ( m_bSigned )
1795 nRet = m_aValue.m_nInt16;
1796 else
1797 nRet = m_aValue.m_uInt16;
1798 break;
1799 case DataType::INTEGER:
1800 if ( m_bSigned )
1801 nRet = m_aValue.m_nInt32;
1802 else
1803 nRet = m_aValue.m_uInt32;
1804 break;
1805 case DataType::BIGINT:
1806 if ( m_bSigned )
1807 nRet = m_aValue.m_nInt64;
1808 else
1809 nRet = m_aValue.m_uInt64;
1810 break;
1811 default:
1813 Any aValue = makeAny();
1814 aValue >>= nRet;
1815 break;
1819 return nRet;
1822 Sequence<sal_Int8> ORowSetValue::getSequence() const
1824 Sequence<sal_Int8> aSeq;
1825 if (!m_bNull)
1827 switch(m_eTypeKind)
1829 case DataType::OBJECT:
1830 case DataType::CLOB:
1831 case DataType::BLOB:
1833 Reference<XInputStream> xStream;
1834 const Any aValue = makeAny();
1835 if(aValue.hasValue())
1837 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1838 if ( xBlob.is() )
1839 xStream = xBlob->getBinaryStream();
1840 else
1842 Reference<XClob> xClob(aValue,UNO_QUERY);
1843 if ( xClob.is() )
1844 xStream = xClob->getCharacterStream();
1846 if(xStream.is())
1848 const sal_uInt32 nBytesToRead = 65535;
1849 sal_uInt32 nRead;
1853 css::uno::Sequence< sal_Int8 > aReadSeq;
1855 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1857 if( nRead )
1859 const sal_uInt32 nOldLength = aSeq.getLength();
1860 aSeq.realloc( nOldLength + nRead );
1861 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1864 while( nBytesToRead == nRead );
1865 xStream->closeInput();
1869 break;
1870 case DataType::VARCHAR:
1871 case DataType::LONGVARCHAR:
1873 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(m_aValue.m_pString->buffer),
1874 sizeof(sal_Unicode) * m_aValue.m_pString->length);
1876 break;
1877 case DataType::BINARY:
1878 case DataType::VARBINARY:
1879 case DataType::LONGVARBINARY:
1880 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1881 break;
1882 default:
1884 Any aValue = makeAny();
1885 aValue >>= aSeq;
1886 break;
1890 return aSeq;
1894 css::util::Date ORowSetValue::getDate() const
1896 css::util::Date aValue;
1897 if(!m_bNull)
1899 switch(m_eTypeKind)
1901 case DataType::CHAR:
1902 case DataType::VARCHAR:
1903 case DataType::LONGVARCHAR:
1904 aValue = DBTypeConversion::toDate(getString());
1905 break;
1906 case DataType::DECIMAL:
1907 case DataType::NUMERIC:
1908 case DataType::FLOAT:
1909 case DataType::DOUBLE:
1910 case DataType::REAL:
1911 aValue = DBTypeConversion::toDate(static_cast<double>(*this));
1912 break;
1914 case DataType::DATE:
1915 aValue = *static_cast< css::util::Date*>(m_aValue.m_pValue);
1916 break;
1917 case DataType::TIMESTAMP:
1919 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1920 aValue.Day = pDateTime->Day;
1921 aValue.Month = pDateTime->Month;
1922 aValue.Year = pDateTime->Year;
1924 break;
1925 case DataType::BIT:
1926 case DataType::BOOLEAN:
1927 case DataType::TINYINT:
1928 case DataType::SMALLINT:
1929 case DataType::INTEGER:
1930 case DataType::BIGINT:
1931 aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1932 break;
1934 case DataType::BLOB:
1935 case DataType::CLOB:
1936 case DataType::OBJECT:
1937 default:
1938 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1939 [[fallthrough]];
1941 case DataType::BINARY:
1942 case DataType::VARBINARY:
1943 case DataType::LONGVARBINARY:
1944 case DataType::TIME:
1945 aValue = DBTypeConversion::toDate( double(0) );
1946 break;
1949 return aValue;
1952 css::util::Time ORowSetValue::getTime() const
1954 css::util::Time aValue;
1955 if(!m_bNull)
1957 switch(m_eTypeKind)
1959 case DataType::CHAR:
1960 case DataType::VARCHAR:
1961 case DataType::LONGVARCHAR:
1962 aValue = DBTypeConversion::toTime(getString());
1963 break;
1964 case DataType::DECIMAL:
1965 case DataType::NUMERIC:
1966 aValue = DBTypeConversion::toTime(static_cast<double>(*this));
1967 break;
1968 case DataType::FLOAT:
1969 case DataType::DOUBLE:
1970 case DataType::REAL:
1971 aValue = DBTypeConversion::toTime(static_cast<double>(*this));
1972 break;
1973 case DataType::TIMESTAMP:
1975 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1976 aValue.NanoSeconds = pDateTime->NanoSeconds;
1977 aValue.Seconds = pDateTime->Seconds;
1978 aValue.Minutes = pDateTime->Minutes;
1979 aValue.Hours = pDateTime->Hours;
1981 break;
1982 case DataType::TIME:
1983 aValue = *static_cast< css::util::Time*>(m_aValue.m_pValue);
1984 break;
1985 default:
1987 Any aAnyValue = makeAny();
1988 aAnyValue >>= aValue;
1989 break;
1993 return aValue;
1996 css::util::DateTime ORowSetValue::getDateTime() const
1998 css::util::DateTime aValue;
1999 if(!m_bNull)
2001 switch(m_eTypeKind)
2003 case DataType::CHAR:
2004 case DataType::VARCHAR:
2005 case DataType::LONGVARCHAR:
2006 aValue = DBTypeConversion::toDateTime(getString());
2007 break;
2008 case DataType::DECIMAL:
2009 case DataType::NUMERIC:
2010 aValue = DBTypeConversion::toDateTime(static_cast<double>(*this));
2011 break;
2012 case DataType::FLOAT:
2013 case DataType::DOUBLE:
2014 case DataType::REAL:
2015 aValue = DBTypeConversion::toDateTime(static_cast<double>(*this));
2016 break;
2017 case DataType::DATE:
2019 css::util::Date* pDate = static_cast< css::util::Date*>(m_aValue.m_pValue);
2020 aValue.Day = pDate->Day;
2021 aValue.Month = pDate->Month;
2022 aValue.Year = pDate->Year;
2024 break;
2025 case DataType::TIME:
2027 css::util::Time* pTime = static_cast< css::util::Time*>(m_aValue.m_pValue);
2028 aValue.NanoSeconds = pTime->NanoSeconds;
2029 aValue.Seconds = pTime->Seconds;
2030 aValue.Minutes = pTime->Minutes;
2031 aValue.Hours = pTime->Hours;
2033 break;
2034 case DataType::TIMESTAMP:
2035 aValue = *static_cast< css::util::DateTime*>(m_aValue.m_pValue);
2036 break;
2037 default:
2039 Any aAnyValue = makeAny();
2040 aAnyValue >>= aValue;
2041 break;
2045 return aValue;
2048 void ORowSetValue::setSigned(bool _bMod)
2050 if ( m_bSigned != _bMod )
2052 m_bSigned = _bMod;
2053 if ( !m_bNull )
2055 sal_Int32 nType = m_eTypeKind;
2056 switch(m_eTypeKind)
2058 case DataType::TINYINT:
2059 if ( m_bSigned )
2060 (*this) = getInt8();
2061 else
2063 m_bSigned = !m_bSigned;
2064 (*this) = getInt16();
2065 m_bSigned = !m_bSigned;
2067 break;
2068 case DataType::SMALLINT:
2069 if ( m_bSigned )
2070 (*this) = getInt16();
2071 else
2073 m_bSigned = !m_bSigned;
2074 (*this) = getInt32();
2075 m_bSigned = !m_bSigned;
2077 break;
2078 case DataType::INTEGER:
2079 if ( m_bSigned )
2080 (*this) = getInt32();
2081 else
2083 m_bSigned = !m_bSigned;
2084 (*this) = getLong();
2085 m_bSigned = !m_bSigned;
2087 break;
2088 case DataType::BIGINT:
2089 if ( m_bSigned )
2090 m_aValue.m_nInt64 = static_cast<sal_Int64>(m_aValue.m_uInt64);
2091 else
2092 m_aValue.m_uInt64 = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2093 break;
2095 m_eTypeKind = nType;
2101 namespace detail
2103 class SAL_NO_VTABLE IValueSource
2105 public:
2106 virtual OUString getString() const = 0;
2107 virtual bool getBoolean() const = 0;
2108 virtual sal_Int8 getByte() const = 0;
2109 virtual sal_Int16 getShort() const = 0;
2110 virtual sal_Int32 getInt() const = 0;
2111 virtual sal_Int64 getLong() const = 0;
2112 virtual float getFloat() const = 0;
2113 virtual double getDouble() const = 0;
2114 virtual Date getDate() const = 0;
2115 virtual css::util::Time getTime() const = 0;
2116 virtual DateTime getTimestamp() const = 0;
2117 virtual Sequence< sal_Int8 > getBytes() const = 0;
2118 virtual Reference< XBlob > getBlob() const = 0;
2119 virtual Reference< XClob > getClob() const = 0;
2120 virtual Any getObject() const = 0;
2121 virtual bool wasNull() const = 0;
2123 virtual ~IValueSource() { }
2126 class RowValue : public IValueSource
2128 public:
2129 RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2130 :m_xRow( _xRow )
2131 ,m_nPos( _nPos )
2135 // IValueSource
2136 virtual OUString getString() const override { return m_xRow->getString( m_nPos ); };
2137 virtual bool getBoolean() const override { return m_xRow->getBoolean( m_nPos ); };
2138 virtual sal_Int8 getByte() const override { return m_xRow->getByte( m_nPos ); };
2139 virtual sal_Int16 getShort() const override { return m_xRow->getShort( m_nPos ); }
2140 virtual sal_Int32 getInt() const override { return m_xRow->getInt( m_nPos ); }
2141 virtual sal_Int64 getLong() const override { return m_xRow->getLong( m_nPos ); }
2142 virtual float getFloat() const override { return m_xRow->getFloat( m_nPos ); };
2143 virtual double getDouble() const override { return m_xRow->getDouble( m_nPos ); };
2144 virtual Date getDate() const override { return m_xRow->getDate( m_nPos ); };
2145 virtual css::util::Time getTime() const override { return m_xRow->getTime( m_nPos ); };
2146 virtual DateTime getTimestamp() const override { return m_xRow->getTimestamp( m_nPos ); };
2147 virtual Sequence< sal_Int8 > getBytes() const override { return m_xRow->getBytes( m_nPos ); };
2148 virtual Reference< XBlob > getBlob() const override { return m_xRow->getBlob( m_nPos ); };
2149 virtual Reference< XClob > getClob() const override { return m_xRow->getClob( m_nPos ); };
2150 virtual Any getObject() const override { return m_xRow->getObject( m_nPos ,nullptr); };
2151 virtual bool wasNull() const override { return m_xRow->wasNull( ); };
2153 private:
2154 const Reference< XRow > m_xRow;
2155 const sal_Int32 m_nPos;
2158 class ColumnValue : public IValueSource
2160 public:
2161 explicit ColumnValue( const Reference< XColumn >& _rxColumn )
2162 :m_xColumn( _rxColumn )
2166 // IValueSource
2167 virtual OUString getString() const override { return m_xColumn->getString(); };
2168 virtual bool getBoolean() const override { return m_xColumn->getBoolean(); };
2169 virtual sal_Int8 getByte() const override { return m_xColumn->getByte(); };
2170 virtual sal_Int16 getShort() const override { return m_xColumn->getShort(); }
2171 virtual sal_Int32 getInt() const override { return m_xColumn->getInt(); }
2172 virtual sal_Int64 getLong() const override { return m_xColumn->getLong(); }
2173 virtual float getFloat() const override { return m_xColumn->getFloat(); };
2174 virtual double getDouble() const override { return m_xColumn->getDouble(); };
2175 virtual Date getDate() const override { return m_xColumn->getDate(); };
2176 virtual css::util::Time getTime() const override { return m_xColumn->getTime(); };
2177 virtual DateTime getTimestamp() const override { return m_xColumn->getTimestamp(); };
2178 virtual Sequence< sal_Int8 > getBytes() const override { return m_xColumn->getBytes(); };
2179 virtual Reference< XBlob > getBlob() const override { return m_xColumn->getBlob(); };
2180 virtual Reference< XClob > getClob() const override { return m_xColumn->getClob(); };
2181 virtual Any getObject() const override { return m_xColumn->getObject( nullptr ); };
2182 virtual bool wasNull() const override { return m_xColumn->wasNull( ); };
2184 private:
2185 const Reference< XColumn > m_xColumn;
2190 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2192 detail::ColumnValue aColumnValue( _rxColumn );
2193 impl_fill( _nType, true, aColumnValue );
2197 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2199 detail::RowValue aRowValue( _xRow, _nPos );
2200 impl_fill( _nType, _bNullable, aRowValue );
2204 void ORowSetValue::fill(sal_Int32 _nPos,
2205 sal_Int32 _nType,
2206 const css::uno::Reference< css::sdbc::XRow>& _xRow)
2208 fill(_nPos,_nType,true,_xRow);
2212 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2214 switch(_nType)
2216 case DataType::CHAR:
2217 case DataType::VARCHAR:
2218 case DataType::DECIMAL:
2219 case DataType::NUMERIC:
2220 case DataType::LONGVARCHAR:
2221 (*this) = _rValueSource.getString();
2222 break;
2223 case DataType::BIGINT:
2224 if ( isSigned() )
2225 (*this) = _rValueSource.getLong();
2226 else
2227 // TODO: this is rather horrible performance-wise
2228 // but fixing it needs extending the css::sdbc::XRow API
2229 // to have a getULong(), and needs updating all drivers :-|
2230 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2231 (*this) = _rValueSource.getString().toUInt64();
2232 break;
2233 case DataType::FLOAT:
2234 (*this) = _rValueSource.getFloat();
2235 break;
2236 case DataType::DOUBLE:
2237 case DataType::REAL:
2238 (*this) = _rValueSource.getDouble();
2239 break;
2240 case DataType::DATE:
2241 (*this) = _rValueSource.getDate();
2242 break;
2243 case DataType::TIME:
2244 (*this) = _rValueSource.getTime();
2245 break;
2246 case DataType::TIMESTAMP:
2247 (*this) = _rValueSource.getTimestamp();
2248 break;
2249 case DataType::BINARY:
2250 case DataType::VARBINARY:
2251 case DataType::LONGVARBINARY:
2252 (*this) = _rValueSource.getBytes();
2253 break;
2254 case DataType::BIT:
2255 case DataType::BOOLEAN:
2256 (*this) = _rValueSource.getBoolean();
2257 break;
2258 case DataType::TINYINT:
2259 if ( isSigned() )
2260 (*this) = _rValueSource.getByte();
2261 else
2262 (*this) = _rValueSource.getShort();
2263 break;
2264 case DataType::SMALLINT:
2265 if ( isSigned() )
2266 (*this) = _rValueSource.getShort();
2267 else
2268 (*this) = _rValueSource.getInt();
2269 break;
2270 case DataType::INTEGER:
2271 if ( isSigned() )
2272 (*this) = _rValueSource.getInt();
2273 else
2274 (*this) = _rValueSource.getLong();
2275 break;
2276 case DataType::CLOB:
2277 (*this) = css::uno::makeAny(_rValueSource.getClob());
2278 setTypeKind(DataType::CLOB);
2279 break;
2280 case DataType::BLOB:
2281 (*this) = css::uno::makeAny(_rValueSource.getBlob());
2282 setTypeKind(DataType::BLOB);
2283 break;
2284 case DataType::OTHER:
2285 (*this) = _rValueSource.getObject();
2286 setTypeKind(DataType::OTHER);
2287 break;
2288 default:
2289 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2290 (*this) = _rValueSource.getObject();
2291 break;
2293 if ( _bNullable && _rValueSource.wasNull() )
2294 setNull();
2295 setTypeKind(_nType);
2298 void ORowSetValue::fill(const Any& _rValue)
2300 switch (_rValue.getValueType().getTypeClass())
2302 case TypeClass_VOID:
2303 setNull(); break;
2304 case TypeClass_BOOLEAN:
2306 bool bValue( false );
2307 _rValue >>= bValue;
2308 (*this) = bValue;
2309 break;
2311 case TypeClass_CHAR:
2313 sal_Unicode aDummy(0);
2314 _rValue >>= aDummy;
2315 (*this) = OUString(aDummy);
2316 break;
2318 case TypeClass_STRING:
2320 OUString sDummy;
2321 _rValue >>= sDummy;
2322 (*this) = sDummy;
2323 break;
2325 case TypeClass_FLOAT:
2327 float aDummy(0.0);
2328 _rValue >>= aDummy;
2329 (*this) = aDummy;
2330 break;
2332 case TypeClass_DOUBLE:
2334 double aDummy(0.0);
2335 _rValue >>= aDummy;
2336 (*this) = aDummy;
2337 break;
2339 case TypeClass_BYTE:
2341 sal_Int8 aDummy(0);
2342 _rValue >>= aDummy;
2343 (*this) = aDummy;
2344 break;
2346 case TypeClass_SHORT:
2348 sal_Int16 aDummy(0);
2349 _rValue >>= aDummy;
2350 (*this) = aDummy;
2351 break;
2353 case TypeClass_UNSIGNED_SHORT:
2355 sal_uInt16 nValue(0);
2356 _rValue >>= nValue;
2357 (*this) = nValue;
2358 break;
2360 case TypeClass_LONG:
2362 sal_Int32 aDummy(0);
2363 _rValue >>= aDummy;
2364 (*this) = aDummy;
2365 break;
2367 case TypeClass_UNSIGNED_LONG:
2369 sal_uInt32 nValue(0);
2370 _rValue >>= nValue;
2371 (*this) = static_cast<sal_Int64>(nValue);
2372 setSigned(false);
2373 break;
2375 case TypeClass_HYPER:
2377 sal_Int64 nValue(0);
2378 _rValue >>= nValue;
2379 (*this) = nValue;
2380 break;
2382 case TypeClass_UNSIGNED_HYPER:
2384 sal_uInt64 nValue(0);
2385 _rValue >>= nValue;
2386 (*this) = nValue;
2387 setSigned(false);
2388 break;
2390 case TypeClass_ENUM:
2392 sal_Int32 enumValue( 0 );
2393 ::cppu::enum2int( enumValue, _rValue );
2394 (*this) = enumValue;
2396 break;
2398 case TypeClass_SEQUENCE:
2400 Sequence<sal_Int8> aDummy;
2401 if ( _rValue >>= aDummy )
2402 (*this) = aDummy;
2403 else
2404 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2405 break;
2408 case TypeClass_STRUCT:
2410 css::util::Date aDate;
2411 css::util::Time aTime;
2412 css::util::DateTime aDateTime;
2413 if ( _rValue >>= aDate )
2415 (*this) = aDate;
2417 else if ( _rValue >>= aTime )
2419 (*this) = aTime;
2421 else if ( _rValue >>= aDateTime )
2423 (*this) = aDateTime;
2425 else
2426 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2428 break;
2430 case TypeClass_INTERFACE:
2432 Reference< XClob > xClob;
2433 if ( _rValue >>= xClob )
2435 (*this) = _rValue;
2436 setTypeKind(DataType::CLOB);
2438 else
2440 Reference< XBlob > xBlob;
2441 if ( _rValue >>= xBlob )
2443 (*this) = _rValue;
2444 setTypeKind(DataType::BLOB);
2446 else
2448 (*this) = _rValue;
2452 break;
2454 default:
2455 SAL_WARN( "connectivity.commontools","Unknown type");
2456 break;
2460 } // namespace connectivity
2462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */