tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / connectivity / source / commontools / FValue.cxx
blobcd47492326c94ac45a6cc7400aaea197f026c6df
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 case DataType::BLOB:
822 case DataType::CLOB:
823 case DataType::OBJECT:
824 case DataType::OTHER:
825 bRet = false;
826 break;
827 default:
828 bRet = false;
829 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
830 break;
832 return bRet;
835 Any ORowSetValue::makeAny() const
837 Any rValue;
838 if(isBound() && !isNull())
840 switch(getTypeKind())
842 case DataType::SQLNULL:
843 assert(rValue == Any());
844 break;
845 case DataType::CHAR:
846 case DataType::VARCHAR:
847 case DataType::DECIMAL:
848 case DataType::NUMERIC:
849 case DataType::LONGVARCHAR:
850 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
851 rValue <<= OUString(m_aValue.m_pString);
852 break;
853 case DataType::FLOAT:
854 rValue <<= m_aValue.m_nFloat;
855 break;
856 case DataType::DOUBLE:
857 case DataType::REAL:
858 rValue <<= m_aValue.m_nDouble;
859 break;
860 case DataType::DATE:
861 assert(m_aValue.m_pValue && "Value is null!");
862 rValue <<= *static_cast<Date*>(m_aValue.m_pValue);
863 break;
864 case DataType::TIME:
865 assert(m_aValue.m_pValue && "Value is null!");
866 rValue <<= *static_cast<Time*>(m_aValue.m_pValue);
867 break;
868 case DataType::TIMESTAMP:
869 assert(m_aValue.m_pValue && "Value is null!");
870 rValue <<= *static_cast<DateTime*>(m_aValue.m_pValue);
871 break;
872 case DataType::BINARY:
873 case DataType::VARBINARY:
874 case DataType::LONGVARBINARY:
875 assert(m_aValue.m_pValue && "Value is null!");
876 rValue <<= *static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
877 break;
878 case DataType::BLOB:
879 case DataType::CLOB:
880 case DataType::OBJECT:
881 case DataType::OTHER:
882 rValue = getAny();
883 break;
884 case DataType::BIT:
885 case DataType::BOOLEAN:
886 rValue <<= m_aValue.m_bBool;
887 break;
888 case DataType::TINYINT:
889 if ( m_bSigned )
890 // TypeClass_BYTE
891 rValue <<= m_aValue.m_nInt8;
892 else
893 // There is no TypeClass_UNSIGNED_BYTE,
894 // so silently promote it to a 16-bit integer,
895 // that is TypeClass_UNSIGNED_SHORT
896 rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
897 break;
898 case DataType::SMALLINT:
899 if ( m_bSigned )
900 // TypeClass_SHORT
901 rValue <<= m_aValue.m_nInt16;
902 else
903 // TypeClass_UNSIGNED_SHORT
904 rValue <<= m_aValue.m_uInt16;
905 break;
906 case DataType::INTEGER:
907 if ( m_bSigned )
908 // TypeClass_LONG
909 rValue <<= m_aValue.m_nInt32;
910 else
911 // TypeClass_UNSIGNED_LONG
912 rValue <<= m_aValue.m_uInt32;
913 break;
914 case DataType::BIGINT:
915 if ( m_bSigned )
916 // TypeClass_HYPER
917 rValue <<= m_aValue.m_nInt64;
918 else
919 // TypeClass_UNSIGNED_HYPER
920 rValue <<= m_aValue.m_uInt64;
921 break;
922 default:
923 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
924 rValue = getAny();
925 break;
928 return rValue;
931 OUString ORowSetValue::getString( ) const
933 OUString aRet;
934 if(!m_bNull)
936 switch(getTypeKind())
938 case DataType::CHAR:
939 case DataType::VARCHAR:
940 case DataType::DECIMAL:
941 case DataType::NUMERIC:
942 case DataType::LONGVARCHAR:
943 aRet = m_aValue.m_pString;
944 break;
945 case DataType::FLOAT:
946 aRet = OUString::number(getFloat());
947 break;
948 case DataType::DOUBLE:
949 case DataType::REAL:
950 aRet = OUString::number(getDouble());
951 break;
952 case DataType::DATE:
953 aRet = DBTypeConversion::toDateString(getDate());
954 break;
955 case DataType::TIME:
956 aRet = DBTypeConversion::toTimeString(getTime());
957 break;
958 case DataType::TIMESTAMP:
959 aRet = DBTypeConversion::toDateTimeString(getDateTime());
960 break;
961 case DataType::BINARY:
962 case DataType::VARBINARY:
963 case DataType::LONGVARBINARY:
965 OUStringBuffer sVal("0x");
966 for (sal_Int32 byte : getSequence())
967 sVal.append(byte, 16);
968 aRet = sVal.makeStringAndClear();
970 break;
971 case DataType::BIT:
972 aRet = OUString::number(int(getBool()));
973 break;
974 case DataType::BOOLEAN:
975 aRet = OUString::boolean(getBool());
976 break;
977 case DataType::TINYINT:
978 case DataType::SMALLINT:
979 case DataType::INTEGER:
980 if ( m_bSigned )
981 aRet = OUString::number(getInt32());
982 else
983 aRet = OUString::number(getUInt32());
984 break;
985 case DataType::BIGINT:
986 if ( m_bSigned )
987 aRet = OUString::number(getLong());
988 else
989 aRet = OUString::number(getULong());
990 break;
991 case DataType::CLOB:
993 Any aValue( getAny() );
994 Reference< XClob > xClob;
995 if ( (aValue >>= xClob) && xClob.is() )
997 aRet = xClob->getSubString(1,static_cast<sal_Int32>(xClob->length()) );
1000 break;
1001 default:
1003 Any aValue = makeAny();
1004 aValue >>= aRet;
1005 break;
1009 return aRet;
1012 bool ORowSetValue::getBool() const
1014 bool bRet = false;
1015 if(!m_bNull)
1017 switch(getTypeKind())
1019 case DataType::CHAR:
1020 case DataType::VARCHAR:
1021 case DataType::LONGVARCHAR:
1023 const OUString sValue(m_aValue.m_pString);
1024 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1026 bRet = true;
1027 break;
1029 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1031 bRet = false;
1032 break;
1035 [[fallthrough]];
1036 case DataType::DECIMAL:
1037 case DataType::NUMERIC:
1039 bRet = OUString::unacquired(&m_aValue.m_pString).toInt32() != 0;
1040 break;
1041 case DataType::FLOAT:
1042 bRet = m_aValue.m_nFloat != 0.0;
1043 break;
1044 case DataType::DOUBLE:
1045 case DataType::REAL:
1046 bRet = m_aValue.m_nDouble != 0.0;
1047 break;
1048 case DataType::DATE:
1049 case DataType::TIME:
1050 case DataType::TIMESTAMP:
1051 case DataType::BINARY:
1052 case DataType::VARBINARY:
1053 case DataType::LONGVARBINARY:
1054 OSL_FAIL("getBool() for this type is not allowed!");
1055 break;
1056 case DataType::BIT:
1057 case DataType::BOOLEAN:
1058 bRet = m_aValue.m_bBool;
1059 break;
1060 case DataType::TINYINT:
1061 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_uInt8 != 0);
1062 break;
1063 case DataType::SMALLINT:
1064 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_uInt16 != 0);
1065 break;
1066 case DataType::INTEGER:
1067 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1068 break;
1069 case DataType::BIGINT:
1070 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1071 break;
1072 default:
1074 Any aValue = makeAny();
1075 aValue >>= bRet;
1076 break;
1080 return bRet;
1084 sal_Int8 ORowSetValue::getInt8() const
1086 sal_Int8 nRet = 0;
1087 if(!m_bNull)
1089 switch(getTypeKind())
1091 case DataType::CHAR:
1092 case DataType::VARCHAR:
1093 case DataType::DECIMAL:
1094 case DataType::NUMERIC:
1095 case DataType::LONGVARCHAR:
1096 nRet = sal_Int8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1097 break;
1098 case DataType::FLOAT:
1099 nRet = sal_Int8(m_aValue.m_nFloat);
1100 break;
1101 case DataType::DOUBLE:
1102 case DataType::REAL:
1103 nRet = sal_Int8(m_aValue.m_nDouble);
1104 break;
1105 case DataType::DATE:
1106 case DataType::TIME:
1107 case DataType::TIMESTAMP:
1108 case DataType::BINARY:
1109 case DataType::VARBINARY:
1110 case DataType::LONGVARBINARY:
1111 case DataType::BLOB:
1112 case DataType::CLOB:
1113 OSL_FAIL("getInt8() for this type is not allowed!");
1114 break;
1115 case DataType::BIT:
1116 case DataType::BOOLEAN:
1117 nRet = sal_Int8(m_aValue.m_bBool);
1118 break;
1119 case DataType::TINYINT:
1120 if ( m_bSigned )
1121 nRet = m_aValue.m_nInt8;
1122 else
1123 nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1124 break;
1125 case DataType::SMALLINT:
1126 if ( m_bSigned )
1127 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1128 else
1129 nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1130 break;
1131 case DataType::INTEGER:
1132 if ( m_bSigned )
1133 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1134 else
1135 nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1136 break;
1137 case DataType::BIGINT:
1138 if ( m_bSigned )
1139 nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1140 else
1141 nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1142 break;
1143 default:
1145 Any aValue = makeAny();
1146 aValue >>= nRet;
1147 break;
1151 return nRet;
1155 sal_uInt8 ORowSetValue::getUInt8() const
1157 sal_uInt8 nRet = 0;
1158 if(!m_bNull)
1160 switch(getTypeKind())
1162 case DataType::CHAR:
1163 case DataType::VARCHAR:
1164 case DataType::DECIMAL:
1165 case DataType::NUMERIC:
1166 case DataType::LONGVARCHAR:
1167 nRet = sal_uInt8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1168 break;
1169 case DataType::FLOAT:
1170 nRet = sal_uInt8(m_aValue.m_nFloat);
1171 break;
1172 case DataType::DOUBLE:
1173 case DataType::REAL:
1174 nRet = sal_uInt8(m_aValue.m_nDouble);
1175 break;
1176 case DataType::DATE:
1177 case DataType::TIME:
1178 case DataType::TIMESTAMP:
1179 case DataType::BINARY:
1180 case DataType::VARBINARY:
1181 case DataType::LONGVARBINARY:
1182 case DataType::BLOB:
1183 case DataType::CLOB:
1184 OSL_FAIL("getuInt8() for this type is not allowed!");
1185 break;
1186 case DataType::BIT:
1187 case DataType::BOOLEAN:
1188 nRet = int(m_aValue.m_bBool);
1189 break;
1190 case DataType::TINYINT:
1191 if ( m_bSigned )
1192 nRet = m_aValue.m_nInt8;
1193 else
1194 nRet = m_aValue.m_uInt8;
1195 break;
1196 case DataType::SMALLINT:
1197 if ( m_bSigned )
1198 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1199 else
1200 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1201 break;
1202 case DataType::INTEGER:
1203 if ( m_bSigned )
1204 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1205 else
1206 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1207 break;
1208 case DataType::BIGINT:
1209 if ( m_bSigned )
1210 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1211 else
1212 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1213 break;
1214 default:
1216 Any aValue = makeAny();
1217 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1218 sal_uInt16 n;
1219 if (aValue >>= n) {
1220 nRet = static_cast<sal_uInt8>(n);
1222 break;
1226 return nRet;
1230 sal_Int16 ORowSetValue::getInt16() const
1232 sal_Int16 nRet = 0;
1233 if(!m_bNull)
1235 switch(getTypeKind())
1237 case DataType::CHAR:
1238 case DataType::VARCHAR:
1239 case DataType::DECIMAL:
1240 case DataType::NUMERIC:
1241 case DataType::LONGVARCHAR:
1242 nRet = sal_Int16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1243 break;
1244 case DataType::FLOAT:
1245 nRet = sal_Int16(m_aValue.m_nFloat);
1246 break;
1247 case DataType::DOUBLE:
1248 case DataType::REAL:
1249 nRet = sal_Int16(m_aValue.m_nDouble);
1250 break;
1251 case DataType::DATE:
1252 case DataType::TIME:
1253 case DataType::TIMESTAMP:
1254 case DataType::BINARY:
1255 case DataType::VARBINARY:
1256 case DataType::LONGVARBINARY:
1257 case DataType::BLOB:
1258 case DataType::CLOB:
1259 OSL_FAIL("getInt16() for this type is not allowed!");
1260 break;
1261 case DataType::BIT:
1262 case DataType::BOOLEAN:
1263 nRet = sal_Int16(m_aValue.m_bBool);
1264 break;
1265 case DataType::TINYINT:
1266 if ( m_bSigned )
1267 nRet = m_aValue.m_nInt8;
1268 else
1269 nRet = m_aValue.m_uInt8;
1270 break;
1271 case DataType::SMALLINT:
1272 if ( m_bSigned )
1273 nRet = m_aValue.m_nInt16;
1274 else
1275 nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1276 break;
1277 case DataType::INTEGER:
1278 if ( m_bSigned )
1279 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1280 else
1281 nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1282 break;
1283 case DataType::BIGINT:
1284 if ( m_bSigned )
1285 nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1286 else
1287 nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1288 break;
1289 default:
1291 Any aValue = makeAny();
1292 aValue >>= nRet;
1293 break;
1297 return nRet;
1301 sal_uInt16 ORowSetValue::getUInt16() const
1303 sal_uInt16 nRet = 0;
1304 if(!m_bNull)
1306 switch(getTypeKind())
1308 case DataType::CHAR:
1309 case DataType::VARCHAR:
1310 case DataType::DECIMAL:
1311 case DataType::NUMERIC:
1312 case DataType::LONGVARCHAR:
1313 nRet = sal_uInt16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1314 break;
1315 case DataType::FLOAT:
1316 nRet = sal_uInt16(m_aValue.m_nFloat);
1317 break;
1318 case DataType::DOUBLE:
1319 case DataType::REAL:
1320 nRet = sal_uInt16(m_aValue.m_nDouble);
1321 break;
1322 case DataType::DATE:
1323 case DataType::TIME:
1324 case DataType::TIMESTAMP:
1325 case DataType::BINARY:
1326 case DataType::VARBINARY:
1327 case DataType::LONGVARBINARY:
1328 case DataType::BLOB:
1329 case DataType::CLOB:
1330 OSL_FAIL("getuInt16() for this type is not allowed!");
1331 break;
1332 case DataType::BIT:
1333 case DataType::BOOLEAN:
1334 nRet = sal_uInt16(m_aValue.m_bBool);
1335 break;
1336 case DataType::TINYINT:
1337 if ( m_bSigned )
1338 nRet = m_aValue.m_nInt8;
1339 else
1340 nRet = m_aValue.m_uInt8;
1341 break;
1342 case DataType::SMALLINT:
1343 if ( m_bSigned )
1344 nRet = m_aValue.m_nInt16;
1345 else
1346 nRet = m_aValue.m_uInt16;
1347 break;
1348 case DataType::INTEGER:
1349 if ( m_bSigned )
1350 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1351 else
1352 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1353 break;
1354 case DataType::BIGINT:
1355 if ( m_bSigned )
1356 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1357 else
1358 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1359 break;
1360 default:
1362 Any aValue = makeAny();
1363 aValue >>= nRet;
1364 break;
1368 return nRet;
1372 sal_Int32 ORowSetValue::getInt32() const
1374 sal_Int32 nRet = 0;
1375 if(!m_bNull)
1377 switch(getTypeKind())
1379 case DataType::CHAR:
1380 case DataType::VARCHAR:
1381 case DataType::DECIMAL:
1382 case DataType::NUMERIC:
1383 case DataType::LONGVARCHAR:
1384 nRet = OUString::unacquired(&m_aValue.m_pString).toInt32();
1385 break;
1386 case DataType::FLOAT:
1387 nRet = sal_Int32(m_aValue.m_nFloat);
1388 break;
1389 case DataType::DOUBLE:
1390 case DataType::REAL:
1391 nRet = sal_Int32(m_aValue.m_nDouble);
1392 break;
1393 case DataType::DATE:
1394 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1395 break;
1396 case DataType::TIME:
1397 case DataType::TIMESTAMP:
1398 case DataType::BINARY:
1399 case DataType::VARBINARY:
1400 case DataType::LONGVARBINARY:
1401 case DataType::BLOB:
1402 case DataType::CLOB:
1403 OSL_FAIL("getInt32() for this type is not allowed!");
1404 break;
1405 case DataType::BIT:
1406 case DataType::BOOLEAN:
1407 nRet = sal_Int32(m_aValue.m_bBool);
1408 break;
1409 case DataType::TINYINT:
1410 if ( m_bSigned )
1411 nRet = m_aValue.m_nInt8;
1412 else
1413 nRet = m_aValue.m_uInt8;
1414 break;
1415 case DataType::SMALLINT:
1416 if ( m_bSigned )
1417 nRet = m_aValue.m_nInt16;
1418 else
1419 nRet = m_aValue.m_uInt16;
1420 break;
1421 case DataType::INTEGER:
1422 if ( m_bSigned )
1423 nRet = m_aValue.m_nInt32;
1424 else
1425 nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1426 break;
1427 case DataType::BIGINT:
1428 if ( m_bSigned )
1429 nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1430 else
1431 nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1432 break;
1433 default:
1435 Any aValue = makeAny();
1436 aValue >>= nRet;
1437 break;
1441 return nRet;
1445 sal_uInt32 ORowSetValue::getUInt32() const
1447 sal_uInt32 nRet = 0;
1448 if(!m_bNull)
1450 switch(getTypeKind())
1452 case DataType::CHAR:
1453 case DataType::VARCHAR:
1454 case DataType::DECIMAL:
1455 case DataType::NUMERIC:
1456 case DataType::LONGVARCHAR:
1457 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt32();
1458 break;
1459 case DataType::FLOAT:
1460 nRet = sal_uInt32(m_aValue.m_nFloat);
1461 break;
1462 case DataType::DOUBLE:
1463 case DataType::REAL:
1464 nRet = sal_uInt32(m_aValue.m_nDouble);
1465 break;
1466 case DataType::DATE:
1467 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1468 break;
1469 case DataType::TIME:
1470 case DataType::TIMESTAMP:
1471 case DataType::BINARY:
1472 case DataType::VARBINARY:
1473 case DataType::LONGVARBINARY:
1474 case DataType::BLOB:
1475 case DataType::CLOB:
1476 OSL_FAIL("getuInt32() for this type is not allowed!");
1477 break;
1478 case DataType::BIT:
1479 case DataType::BOOLEAN:
1480 nRet = sal_uInt32(m_aValue.m_bBool);
1481 break;
1482 case DataType::TINYINT:
1483 if ( m_bSigned )
1484 nRet = m_aValue.m_nInt8;
1485 else
1486 nRet = m_aValue.m_uInt8;
1487 break;
1488 case DataType::SMALLINT:
1489 if ( m_bSigned )
1490 nRet = m_aValue.m_nInt16;
1491 else
1492 nRet = m_aValue.m_uInt16;
1493 break;
1494 case DataType::INTEGER:
1495 if ( m_bSigned )
1496 nRet = m_aValue.m_nInt32;
1497 else
1498 nRet = m_aValue.m_uInt32;
1499 break;
1500 case DataType::BIGINT:
1501 if ( m_bSigned )
1502 nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1503 else
1504 nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1505 break;
1506 default:
1508 Any aValue = makeAny();
1509 aValue >>= nRet;
1510 break;
1514 return nRet;
1518 sal_Int64 ORowSetValue::getLong() const
1520 sal_Int64 nRet = 0;
1521 if(!m_bNull)
1523 switch(getTypeKind())
1525 case DataType::CHAR:
1526 case DataType::VARCHAR:
1527 case DataType::DECIMAL:
1528 case DataType::NUMERIC:
1529 case DataType::LONGVARCHAR:
1530 nRet = OUString::unacquired(&m_aValue.m_pString).toInt64();
1531 break;
1532 case DataType::FLOAT:
1533 nRet = sal_Int64(m_aValue.m_nFloat);
1534 break;
1535 case DataType::DOUBLE:
1536 case DataType::REAL:
1537 nRet = sal_Int64(m_aValue.m_nDouble);
1538 break;
1539 case DataType::DATE:
1540 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1541 break;
1542 case DataType::TIME:
1543 case DataType::TIMESTAMP:
1544 case DataType::BINARY:
1545 case DataType::VARBINARY:
1546 case DataType::LONGVARBINARY:
1547 case DataType::BLOB:
1548 case DataType::CLOB:
1549 OSL_FAIL("getLong() for this type is not allowed!");
1550 break;
1551 case DataType::BIT:
1552 case DataType::BOOLEAN:
1553 nRet = sal_Int64(m_aValue.m_bBool);
1554 break;
1555 case DataType::TINYINT:
1556 if ( m_bSigned )
1557 nRet = m_aValue.m_nInt8;
1558 else
1559 nRet = m_aValue.m_uInt8;
1560 break;
1561 case DataType::SMALLINT:
1562 if ( m_bSigned )
1563 nRet = m_aValue.m_nInt16;
1564 else
1565 nRet = m_aValue.m_uInt16;
1566 break;
1567 case DataType::INTEGER:
1568 if ( m_bSigned )
1569 nRet = m_aValue.m_nInt32;
1570 else
1571 nRet = m_aValue.m_uInt32;
1572 break;
1573 case DataType::BIGINT:
1574 if ( m_bSigned )
1575 nRet = m_aValue.m_nInt64;
1576 else
1577 nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1578 break;
1579 default:
1581 Any aValue = makeAny();
1582 aValue >>= nRet;
1583 break;
1587 return nRet;
1591 sal_uInt64 ORowSetValue::getULong() const
1593 sal_uInt64 nRet = 0;
1594 if(!m_bNull)
1596 switch(getTypeKind())
1598 case DataType::CHAR:
1599 case DataType::VARCHAR:
1600 case DataType::DECIMAL:
1601 case DataType::NUMERIC:
1602 case DataType::LONGVARCHAR:
1603 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt64();
1604 break;
1605 case DataType::FLOAT:
1606 nRet = sal_uInt64(m_aValue.m_nFloat);
1607 break;
1608 case DataType::DOUBLE:
1609 case DataType::REAL:
1610 nRet = sal_uInt64(m_aValue.m_nDouble);
1611 break;
1612 case DataType::DATE:
1613 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1614 break;
1615 case DataType::TIME:
1616 case DataType::TIMESTAMP:
1617 case DataType::BINARY:
1618 case DataType::VARBINARY:
1619 case DataType::LONGVARBINARY:
1620 case DataType::BLOB:
1621 case DataType::CLOB:
1622 OSL_FAIL("getULong() for this type is not allowed!");
1623 break;
1624 case DataType::BIT:
1625 case DataType::BOOLEAN:
1626 nRet = sal_uInt64(m_aValue.m_bBool);
1627 break;
1628 case DataType::TINYINT:
1629 if ( m_bSigned )
1630 nRet = m_aValue.m_nInt8;
1631 else
1632 nRet = m_aValue.m_uInt8;
1633 break;
1634 case DataType::SMALLINT:
1635 if ( m_bSigned )
1636 nRet = m_aValue.m_nInt16;
1637 else
1638 nRet = m_aValue.m_uInt16;
1639 break;
1640 case DataType::INTEGER:
1641 if ( m_bSigned )
1642 nRet = m_aValue.m_nInt32;
1643 else
1644 nRet = m_aValue.m_uInt32;
1645 break;
1646 case DataType::BIGINT:
1647 if ( m_bSigned )
1648 nRet = m_aValue.m_nInt64;
1649 else
1650 nRet = m_aValue.m_uInt64;
1651 break;
1652 default:
1654 Any aValue = makeAny();
1655 aValue >>= nRet;
1656 break;
1660 return nRet;
1664 float ORowSetValue::getFloat() const
1666 float nRet = 0;
1667 if(!m_bNull)
1669 switch(getTypeKind())
1671 case DataType::CHAR:
1672 case DataType::VARCHAR:
1673 case DataType::DECIMAL:
1674 case DataType::NUMERIC:
1675 case DataType::LONGVARCHAR:
1676 nRet = OUString::unacquired(&m_aValue.m_pString).toFloat();
1677 break;
1678 case DataType::FLOAT:
1679 nRet = m_aValue.m_nFloat;
1680 break;
1681 case DataType::DOUBLE:
1682 case DataType::REAL:
1683 nRet = static_cast<float>(m_aValue.m_nDouble);
1684 break;
1685 case DataType::DATE:
1686 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue)));
1687 break;
1688 case DataType::TIME:
1689 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue)));
1690 break;
1691 case DataType::TIMESTAMP:
1692 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue)));
1693 break;
1694 case DataType::BINARY:
1695 case DataType::VARBINARY:
1696 case DataType::LONGVARBINARY:
1697 case DataType::BLOB:
1698 case DataType::CLOB:
1699 OSL_FAIL("getDouble() for this type is not allowed!");
1700 break;
1701 case DataType::BIT:
1702 case DataType::BOOLEAN:
1703 nRet = float(m_aValue.m_bBool);
1704 break;
1705 case DataType::TINYINT:
1706 if ( m_bSigned )
1707 nRet = m_aValue.m_nInt8;
1708 else
1709 nRet = m_aValue.m_uInt8;
1710 break;
1711 case DataType::SMALLINT:
1712 if ( m_bSigned )
1713 nRet = m_aValue.m_nInt16;
1714 else
1715 nRet = static_cast<float>(m_aValue.m_uInt16);
1716 break;
1717 case DataType::INTEGER:
1718 if ( m_bSigned )
1719 nRet = static_cast<float>(m_aValue.m_nInt32);
1720 else
1721 nRet = static_cast<float>(m_aValue.m_uInt32);
1722 break;
1723 case DataType::BIGINT:
1724 if ( m_bSigned )
1725 nRet = static_cast<float>(m_aValue.m_nInt64);
1726 else
1727 nRet = static_cast<float>(m_aValue.m_uInt64);
1728 break;
1729 default:
1731 Any aValue = makeAny();
1732 aValue >>= nRet;
1733 break;
1737 return nRet;
1740 double ORowSetValue::getDouble() const
1742 double nRet = 0;
1743 if(!m_bNull)
1745 switch(getTypeKind())
1747 case DataType::CHAR:
1748 case DataType::VARCHAR:
1749 case DataType::DECIMAL:
1750 case DataType::NUMERIC:
1751 case DataType::LONGVARCHAR:
1752 nRet = OUString::unacquired(&m_aValue.m_pString).toDouble();
1753 break;
1754 case DataType::FLOAT:
1755 nRet = m_aValue.m_nFloat;
1756 break;
1757 case DataType::DOUBLE:
1758 case DataType::REAL:
1759 nRet = m_aValue.m_nDouble;
1760 break;
1761 case DataType::DATE:
1762 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1763 break;
1764 case DataType::TIME:
1765 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1766 break;
1767 case DataType::TIMESTAMP:
1768 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1769 break;
1770 case DataType::BINARY:
1771 case DataType::VARBINARY:
1772 case DataType::LONGVARBINARY:
1773 case DataType::BLOB:
1774 case DataType::CLOB:
1775 OSL_FAIL("getDouble() for this type is not allowed!");
1776 break;
1777 case DataType::BIT:
1778 case DataType::BOOLEAN:
1779 nRet = double(m_aValue.m_bBool);
1780 break;
1781 case DataType::TINYINT:
1782 if ( m_bSigned )
1783 nRet = m_aValue.m_nInt8;
1784 else
1785 nRet = m_aValue.m_uInt8;
1786 break;
1787 case DataType::SMALLINT:
1788 if ( m_bSigned )
1789 nRet = m_aValue.m_nInt16;
1790 else
1791 nRet = m_aValue.m_uInt16;
1792 break;
1793 case DataType::INTEGER:
1794 if ( m_bSigned )
1795 nRet = m_aValue.m_nInt32;
1796 else
1797 nRet = m_aValue.m_uInt32;
1798 break;
1799 case DataType::BIGINT:
1800 if ( m_bSigned )
1801 nRet = m_aValue.m_nInt64;
1802 else
1803 nRet = m_aValue.m_uInt64;
1804 break;
1805 default:
1807 Any aValue = makeAny();
1808 aValue >>= nRet;
1809 break;
1813 return nRet;
1816 Sequence<sal_Int8> ORowSetValue::getSequence() const
1818 Sequence<sal_Int8> aSeq;
1819 if (!m_bNull)
1821 switch(m_eTypeKind)
1823 case DataType::OBJECT:
1824 case DataType::CLOB:
1825 case DataType::BLOB:
1827 Reference<XInputStream> xStream;
1828 const Any aValue = makeAny();
1829 if(aValue.hasValue())
1831 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1832 if ( xBlob.is() )
1833 xStream = xBlob->getBinaryStream();
1834 else
1836 Reference<XClob> xClob(aValue,UNO_QUERY);
1837 if ( xClob.is() )
1838 xStream = xClob->getCharacterStream();
1840 if(xStream.is())
1842 const sal_uInt32 nBytesToRead = 65535;
1843 sal_uInt32 nRead;
1847 css::uno::Sequence< sal_Int8 > aReadSeq;
1849 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1851 if( nRead )
1853 const sal_uInt32 nOldLength = aSeq.getLength();
1854 aSeq.realloc( nOldLength + nRead );
1855 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1858 while( nBytesToRead == nRead );
1859 xStream->closeInput();
1863 break;
1864 case DataType::VARCHAR:
1865 case DataType::LONGVARCHAR:
1867 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(m_aValue.m_pString->buffer),
1868 sizeof(sal_Unicode) * m_aValue.m_pString->length);
1870 break;
1871 case DataType::BINARY:
1872 case DataType::VARBINARY:
1873 case DataType::LONGVARBINARY:
1874 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1875 break;
1876 default:
1878 Any aValue = makeAny();
1879 aValue >>= aSeq;
1880 break;
1884 return aSeq;
1888 css::util::Date ORowSetValue::getDate() const
1890 css::util::Date aValue;
1891 if(!m_bNull)
1893 switch(m_eTypeKind)
1895 case DataType::CHAR:
1896 case DataType::VARCHAR:
1897 case DataType::LONGVARCHAR:
1898 aValue = DBTypeConversion::toDate(getString());
1899 break;
1900 case DataType::DECIMAL:
1901 case DataType::NUMERIC:
1902 case DataType::FLOAT:
1903 case DataType::DOUBLE:
1904 case DataType::REAL:
1905 aValue = DBTypeConversion::toDate(getDouble());
1906 break;
1908 case DataType::DATE:
1909 aValue = *static_cast< css::util::Date*>(m_aValue.m_pValue);
1910 break;
1911 case DataType::TIMESTAMP:
1913 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1914 aValue.Day = pDateTime->Day;
1915 aValue.Month = pDateTime->Month;
1916 aValue.Year = pDateTime->Year;
1918 break;
1919 case DataType::BIT:
1920 case DataType::BOOLEAN:
1921 case DataType::TINYINT:
1922 case DataType::SMALLINT:
1923 case DataType::INTEGER:
1924 case DataType::BIGINT:
1925 aValue = DBTypeConversion::toDate( double( getLong() ) );
1926 break;
1928 case DataType::BLOB:
1929 case DataType::CLOB:
1930 case DataType::OBJECT:
1931 default:
1932 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1933 [[fallthrough]];
1935 case DataType::BINARY:
1936 case DataType::VARBINARY:
1937 case DataType::LONGVARBINARY:
1938 case DataType::TIME:
1939 aValue = DBTypeConversion::toDate( double(0) );
1940 break;
1943 return aValue;
1946 css::util::Time ORowSetValue::getTime() const
1948 css::util::Time aValue;
1949 if(!m_bNull)
1951 switch(m_eTypeKind)
1953 case DataType::CHAR:
1954 case DataType::VARCHAR:
1955 case DataType::LONGVARCHAR:
1956 aValue = DBTypeConversion::toTime(getString());
1957 break;
1958 case DataType::DECIMAL:
1959 case DataType::NUMERIC:
1960 case DataType::FLOAT:
1961 case DataType::DOUBLE:
1962 case DataType::REAL:
1963 aValue = DBTypeConversion::toTime(getDouble());
1964 break;
1965 case DataType::TIMESTAMP:
1967 css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1968 aValue.NanoSeconds = pDateTime->NanoSeconds;
1969 aValue.Seconds = pDateTime->Seconds;
1970 aValue.Minutes = pDateTime->Minutes;
1971 aValue.Hours = pDateTime->Hours;
1973 break;
1974 case DataType::TIME:
1975 aValue = *static_cast< css::util::Time*>(m_aValue.m_pValue);
1976 break;
1977 default:
1979 Any aAnyValue = makeAny();
1980 aAnyValue >>= aValue;
1981 break;
1985 return aValue;
1988 css::util::DateTime ORowSetValue::getDateTime() const
1990 css::util::DateTime aValue;
1991 if(!m_bNull)
1993 switch(m_eTypeKind)
1995 case DataType::CHAR:
1996 case DataType::VARCHAR:
1997 case DataType::LONGVARCHAR:
1998 aValue = DBTypeConversion::toDateTime(getString());
1999 break;
2000 case DataType::DECIMAL:
2001 case DataType::NUMERIC:
2002 case DataType::FLOAT:
2003 case DataType::DOUBLE:
2004 case DataType::REAL:
2005 aValue = DBTypeConversion::toDateTime(getDouble());
2006 break;
2007 case DataType::DATE:
2009 css::util::Date* pDate = static_cast< css::util::Date*>(m_aValue.m_pValue);
2010 aValue.Day = pDate->Day;
2011 aValue.Month = pDate->Month;
2012 aValue.Year = pDate->Year;
2014 break;
2015 case DataType::TIME:
2017 css::util::Time* pTime = static_cast< css::util::Time*>(m_aValue.m_pValue);
2018 aValue.NanoSeconds = pTime->NanoSeconds;
2019 aValue.Seconds = pTime->Seconds;
2020 aValue.Minutes = pTime->Minutes;
2021 aValue.Hours = pTime->Hours;
2023 break;
2024 case DataType::TIMESTAMP:
2025 aValue = *static_cast< css::util::DateTime*>(m_aValue.m_pValue);
2026 break;
2027 default:
2029 Any aAnyValue = makeAny();
2030 aAnyValue >>= aValue;
2031 break;
2035 return aValue;
2038 void ORowSetValue::setSigned(bool _bMod)
2040 if ( m_bSigned == _bMod )
2041 return;
2043 m_bSigned = _bMod;
2044 if ( m_bNull )
2045 return;
2047 sal_Int32 nType = m_eTypeKind;
2048 switch(m_eTypeKind)
2050 case DataType::TINYINT:
2051 if ( m_bSigned )
2052 (*this) = getInt8();
2053 else
2055 m_bSigned = !m_bSigned;
2056 (*this) = getInt16();
2057 m_bSigned = !m_bSigned;
2059 break;
2060 case DataType::SMALLINT:
2061 if ( m_bSigned )
2062 (*this) = getInt16();
2063 else
2065 m_bSigned = !m_bSigned;
2066 (*this) = getInt32();
2067 m_bSigned = !m_bSigned;
2069 break;
2070 case DataType::INTEGER:
2071 if ( m_bSigned )
2072 (*this) = getInt32();
2073 else
2075 m_bSigned = !m_bSigned;
2076 (*this) = getLong();
2077 m_bSigned = !m_bSigned;
2079 break;
2080 case DataType::BIGINT:
2082 if ( m_bSigned )
2084 auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64);
2085 m_aValue.m_nInt64 = nTmp;
2087 else
2089 auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2090 m_aValue.m_uInt64 = nTmp;
2092 break;
2095 m_eTypeKind = nType;
2099 namespace detail
2101 class SAL_NO_VTABLE IValueSource
2103 public:
2104 virtual OUString getString() const = 0;
2105 virtual bool getBoolean() const = 0;
2106 virtual sal_Int8 getByte() const = 0;
2107 virtual sal_Int16 getShort() const = 0;
2108 virtual sal_Int32 getInt() const = 0;
2109 virtual sal_Int64 getLong() const = 0;
2110 virtual float getFloat() const = 0;
2111 virtual double getDouble() const = 0;
2112 virtual Date getDate() const = 0;
2113 virtual css::util::Time getTime() const = 0;
2114 virtual DateTime getTimestamp() const = 0;
2115 virtual Sequence< sal_Int8 > getBytes() const = 0;
2116 virtual Reference< XBlob > getBlob() const = 0;
2117 virtual Reference< XClob > getClob() const = 0;
2118 virtual Any getObject() const = 0;
2119 virtual bool wasNull() const = 0;
2121 virtual ~IValueSource() { }
2124 namespace {
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;
2192 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2194 detail::ColumnValue aColumnValue( _rxColumn );
2195 impl_fill( _nType, true, aColumnValue );
2199 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2201 detail::RowValue aRowValue( _xRow, _nPos );
2202 impl_fill( _nType, _bNullable, aRowValue );
2206 void ORowSetValue::fill(sal_Int32 _nPos,
2207 sal_Int32 _nType,
2208 const css::uno::Reference< css::sdbc::XRow>& _xRow)
2210 fill(_nPos,_nType,true,_xRow);
2214 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2216 switch(_nType)
2218 case DataType::CHAR:
2219 case DataType::VARCHAR:
2220 case DataType::DECIMAL:
2221 case DataType::NUMERIC:
2222 case DataType::LONGVARCHAR:
2223 (*this) = _rValueSource.getString();
2224 break;
2225 case DataType::BIGINT:
2226 if ( isSigned() )
2227 (*this) = _rValueSource.getLong();
2228 else
2229 // TODO: this is rather horrible performance-wise
2230 // but fixing it needs extending the css::sdbc::XRow API
2231 // to have a getULong(), and needs updating all drivers :-|
2232 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2233 (*this) = _rValueSource.getString().toUInt64();
2234 break;
2235 case DataType::FLOAT:
2236 (*this) = _rValueSource.getFloat();
2237 break;
2238 case DataType::DOUBLE:
2239 case DataType::REAL:
2240 (*this) = _rValueSource.getDouble();
2241 break;
2242 case DataType::DATE:
2243 (*this) = _rValueSource.getDate();
2244 break;
2245 case DataType::TIME:
2246 (*this) = _rValueSource.getTime();
2247 break;
2248 case DataType::TIMESTAMP:
2249 (*this) = _rValueSource.getTimestamp();
2250 break;
2251 case DataType::BINARY:
2252 case DataType::VARBINARY:
2253 case DataType::LONGVARBINARY:
2254 (*this) = _rValueSource.getBytes();
2255 break;
2256 case DataType::BIT:
2257 case DataType::BOOLEAN:
2258 (*this) = _rValueSource.getBoolean();
2259 break;
2260 case DataType::TINYINT:
2261 if ( isSigned() )
2262 (*this) = _rValueSource.getByte();
2263 else
2264 (*this) = _rValueSource.getShort();
2265 break;
2266 case DataType::SMALLINT:
2267 if ( isSigned() )
2268 (*this) = _rValueSource.getShort();
2269 else
2270 (*this) = _rValueSource.getInt();
2271 break;
2272 case DataType::INTEGER:
2273 if ( isSigned() )
2274 (*this) = _rValueSource.getInt();
2275 else
2276 (*this) = _rValueSource.getLong();
2277 break;
2278 case DataType::CLOB:
2279 (*this) = css::uno::Any(_rValueSource.getClob());
2280 setTypeKind(DataType::CLOB);
2281 break;
2282 case DataType::BLOB:
2283 (*this) = css::uno::Any(_rValueSource.getBlob());
2284 setTypeKind(DataType::BLOB);
2285 break;
2286 case DataType::OTHER:
2287 (*this) = _rValueSource.getObject();
2288 setTypeKind(DataType::OTHER);
2289 break;
2290 default:
2291 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2292 (*this) = _rValueSource.getObject();
2293 break;
2295 if ( _bNullable && _rValueSource.wasNull() )
2296 setNull();
2297 setTypeKind(_nType);
2300 void ORowSetValue::fill(const Any& _rValue)
2302 switch (_rValue.getValueTypeClass())
2304 case TypeClass_VOID:
2305 setNull(); break;
2306 case TypeClass_BOOLEAN:
2308 bool bValue( false );
2309 _rValue >>= bValue;
2310 (*this) = bValue;
2311 break;
2313 case TypeClass_CHAR:
2315 sal_Unicode aDummy(0);
2316 _rValue >>= aDummy;
2317 (*this) = OUString(aDummy);
2318 break;
2320 case TypeClass_STRING:
2322 OUString sDummy;
2323 _rValue >>= sDummy;
2324 (*this) = sDummy;
2325 break;
2327 case TypeClass_FLOAT:
2329 float aDummy(0.0);
2330 _rValue >>= aDummy;
2331 (*this) = aDummy;
2332 break;
2334 case TypeClass_DOUBLE:
2336 double aDummy(0.0);
2337 _rValue >>= aDummy;
2338 (*this) = aDummy;
2339 break;
2341 case TypeClass_BYTE:
2343 sal_Int8 aDummy(0);
2344 _rValue >>= aDummy;
2345 (*this) = aDummy;
2346 break;
2348 case TypeClass_SHORT:
2350 sal_Int16 aDummy(0);
2351 _rValue >>= aDummy;
2352 (*this) = aDummy;
2353 break;
2355 case TypeClass_UNSIGNED_SHORT:
2357 sal_uInt16 nValue(0);
2358 _rValue >>= nValue;
2359 (*this) = nValue;
2360 break;
2362 case TypeClass_LONG:
2364 sal_Int32 aDummy(0);
2365 _rValue >>= aDummy;
2366 (*this) = aDummy;
2367 break;
2369 case TypeClass_UNSIGNED_LONG:
2371 sal_uInt32 nValue(0);
2372 _rValue >>= nValue;
2373 (*this) = static_cast<sal_Int64>(nValue);
2374 setSigned(false);
2375 break;
2377 case TypeClass_HYPER:
2379 sal_Int64 nValue(0);
2380 _rValue >>= nValue;
2381 (*this) = nValue;
2382 break;
2384 case TypeClass_UNSIGNED_HYPER:
2386 sal_uInt64 nValue(0);
2387 _rValue >>= nValue;
2388 (*this) = nValue;
2389 setSigned(false);
2390 break;
2392 case TypeClass_ENUM:
2394 sal_Int32 enumValue( 0 );
2395 ::cppu::enum2int( enumValue, _rValue );
2396 (*this) = enumValue;
2398 break;
2400 case TypeClass_SEQUENCE:
2402 Sequence<sal_Int8> aDummy;
2403 if ( _rValue >>= aDummy )
2404 (*this) = aDummy;
2405 else
2406 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2407 break;
2410 case TypeClass_STRUCT:
2412 css::util::Date aDate;
2413 css::util::Time aTime;
2414 css::util::DateTime aDateTime;
2415 if ( _rValue >>= aDate )
2417 (*this) = aDate;
2419 else if ( _rValue >>= aTime )
2421 (*this) = aTime;
2423 else if ( _rValue >>= aDateTime )
2425 (*this) = aDateTime;
2427 else
2428 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2430 break;
2432 case TypeClass_INTERFACE:
2434 Reference< XClob > xClob;
2435 if ( _rValue >>= xClob )
2437 (*this) = _rValue;
2438 setTypeKind(DataType::CLOB);
2440 else
2442 Reference< XBlob > xBlob;
2443 if ( _rValue >>= xBlob )
2445 (*this) = _rValue;
2446 setTypeKind(DataType::BLOB);
2448 else
2450 (*this) = _rValue;
2454 break;
2456 default:
2457 SAL_WARN( "connectivity.commontools","Unknown type");
2458 break;
2462 } // namespace connectivity
2464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */