bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / commontools / FValue.cxx
blob0cad2141e5c91a2fb3d3930f0a18a3965c928788
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 <rtl/ustrbuf.hxx>
28 #include <boost/type_traits.hpp>
30 using namespace ::dbtools;
31 using namespace ::com::sun::star::sdbc;
32 using namespace ::com::sun::star::sdb;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::io;
37 namespace connectivity
40 namespace {
41 static bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
43 bool bIsCompatible = true;
45 if (_eType1 != _eType2)
47 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
48 switch (_eType1)
50 case DataType::CHAR:
51 case DataType::VARCHAR:
52 case DataType::DECIMAL:
53 case DataType::NUMERIC:
54 case DataType::LONGVARCHAR:
55 bIsCompatible = (DataType::CHAR == _eType2)
56 || (DataType::VARCHAR == _eType2)
57 || (DataType::DECIMAL == _eType2)
58 || (DataType::NUMERIC == _eType2)
59 || (DataType::LONGVARCHAR == _eType2);
60 break;
62 case DataType::DOUBLE:
63 case DataType::REAL:
64 bIsCompatible = (DataType::DOUBLE == _eType2)
65 || (DataType::REAL == _eType2);
66 break;
68 case DataType::BINARY:
69 case DataType::VARBINARY:
70 case DataType::LONGVARBINARY:
71 bIsCompatible = (DataType::BINARY == _eType2)
72 || (DataType::VARBINARY == _eType2)
73 || (DataType::LONGVARBINARY == _eType2);
74 break;
76 case DataType::INTEGER:
77 bIsCompatible = (DataType::SMALLINT == _eType2)
78 || (DataType::TINYINT == _eType2)
79 || (DataType::BIT == _eType2)
80 || (DataType::BOOLEAN == _eType2);
81 break;
82 case DataType::SMALLINT:
83 bIsCompatible = (DataType::TINYINT == _eType2)
84 || (DataType::BIT == _eType2)
85 || (DataType::BOOLEAN == _eType2);
86 break;
87 case DataType::TINYINT:
88 bIsCompatible = (DataType::BIT == _eType2)
89 || (DataType::BOOLEAN == _eType2);
90 break;
92 case DataType::BLOB:
93 case DataType::CLOB:
94 case DataType::OBJECT:
95 bIsCompatible = (DataType::BLOB == _eType2)
96 || (DataType::CLOB == _eType2)
97 || (DataType::OBJECT == _eType2);
98 break;
100 default:
101 bIsCompatible = false;
104 return bIsCompatible;
107 static bool isStorageComparable(sal_Int32 _eType1, sal_Int32 _eType2)
109 bool bIsComparable = true;
111 if (_eType1 != _eType2)
113 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
114 switch (_eType1)
116 case DataType::CHAR:
117 case DataType::VARCHAR:
118 case DataType::LONGVARCHAR:
119 bIsComparable = (DataType::CHAR == _eType2)
120 || (DataType::VARCHAR == _eType2)
121 || (DataType::LONGVARCHAR == _eType2);
122 break;
124 case DataType::DECIMAL:
125 case DataType::NUMERIC:
126 bIsComparable = (DataType::DECIMAL == _eType2)
127 || (DataType::NUMERIC == _eType2);
128 break;
130 case DataType::DOUBLE:
131 case DataType::REAL:
132 bIsComparable = (DataType::DOUBLE == _eType2)
133 || (DataType::REAL == _eType2);
134 break;
136 case DataType::BINARY:
137 case DataType::VARBINARY:
138 case DataType::LONGVARBINARY:
139 bIsComparable = (DataType::BINARY == _eType2)
140 || (DataType::VARBINARY == _eType2)
141 || (DataType::LONGVARBINARY == _eType2);
142 break;
144 case DataType::INTEGER:
145 bIsComparable = (DataType::SMALLINT == _eType2)
146 || (DataType::TINYINT == _eType2)
147 || (DataType::BIT == _eType2)
148 || (DataType::BOOLEAN == _eType2);
149 break;
150 case DataType::SMALLINT:
151 bIsComparable = (DataType::TINYINT == _eType2)
152 || (DataType::BIT == _eType2)
153 || (DataType::BOOLEAN == _eType2);
154 break;
155 case DataType::TINYINT:
156 bIsComparable = (DataType::BIT == _eType2)
157 || (DataType::BOOLEAN == _eType2);
158 break;
160 case DataType::BLOB:
161 case DataType::CLOB:
162 case DataType::OBJECT:
163 bIsComparable = (DataType::BLOB == _eType2)
164 || (DataType::CLOB == _eType2)
165 || (DataType::OBJECT == _eType2);
166 break;
168 default:
169 bIsComparable = false;
172 return bIsComparable;
177 #ifdef DBG_UTIL
179 #include <vector>
180 #include <rtl/string.h>
182 namespace tracing
184 struct AllocationType
186 const sal_Char* pName;
187 sal_Int32 nAllocatedUnits;
189 AllocationType( ) : pName( NULL ), nAllocatedUnits( 0 ) { }
193 class AllocationTracer
195 public:
196 typedef ::std::vector< AllocationType > AllocationState;
197 static AllocationState s_aAllocated;
198 static ::osl::Mutex s_aMutex;
200 public:
201 static void registerUnit( const sal_Char* _pName );
202 static void revokeUnit( const sal_Char* _pName );
204 private:
205 static AllocationState::iterator getLocation( const sal_Char* _pName );
209 AllocationTracer::AllocationState::iterator AllocationTracer::getLocation( const sal_Char* _pName )
211 AllocationState::iterator aLookFor = s_aAllocated.begin();
212 for ( ;
213 aLookFor != s_aAllocated.end();
214 ++aLookFor
217 if ( 0 == rtl_str_compare( aLookFor->pName, _pName ) )
218 // found
219 return aLookFor;
221 // not found
222 s_aAllocated.push_back( AllocationType() );
223 aLookFor = s_aAllocated.end(); --aLookFor;
224 aLookFor->pName = _pName; // note that this assumes that _pName is a constant string ....
225 return aLookFor;
229 AllocationTracer::AllocationState AllocationTracer::s_aAllocated;
230 ::osl::Mutex AllocationTracer::s_aMutex;
233 void AllocationTracer::registerUnit( const sal_Char* _pName )
235 ::osl::MutexGuard aGuard( s_aMutex );
237 AllocationState::iterator aPos = getLocation( _pName );
238 ++aPos->nAllocatedUnits;
242 void AllocationTracer::revokeUnit( const sal_Char* _pName )
244 ::osl::MutexGuard aGuard( s_aMutex );
246 AllocationState::iterator aPos = getLocation( _pName );
247 --aPos->nAllocatedUnits;
250 #define TRACE_ALLOC( type ) tracing::AllocationTracer::registerUnit( #type );
251 #define TRACE_FREE( type ) tracing::AllocationTracer::revokeUnit( #type );
253 #else
254 #define TRACE_ALLOC( type )
255 #define TRACE_FREE( type )
256 #endif
259 void ORowSetValue::setTypeKind(sal_Int32 _eType)
261 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
263 switch(_eType)
265 case DataType::VARCHAR:
266 case DataType::CHAR:
267 case DataType::DECIMAL:
268 case DataType::NUMERIC:
269 case DataType::LONGVARCHAR:
270 (*this) = getString();
271 break;
272 case DataType::BIGINT:
274 sal_Int64 nVal(getLong());
275 sal_uInt64 nuVal(getULong());
276 if (nVal == 0 && nuVal != 0)
277 (*this) = nuVal;
278 else
279 (*this) = nVal;
280 break;
283 case DataType::FLOAT:
284 (*this) = getFloat();
285 break;
286 case DataType::DOUBLE:
287 case DataType::REAL:
288 (*this) = getDouble();
289 break;
290 case DataType::TINYINT:
291 (*this) = getInt8();
292 break;
293 case DataType::SMALLINT:
294 (*this) = getInt16();
295 break;
296 case DataType::INTEGER:
298 sal_Int32 nVal(getInt32());
299 sal_uInt32 nuVal(getUInt32());
300 if (nVal == 0 && nuVal != 0)
301 (*this) = nuVal;
302 else
303 (*this) = nVal;
304 break;
306 case DataType::BIT:
307 case DataType::BOOLEAN:
308 (*this) = getBool();
309 break;
310 case DataType::DATE:
311 (*this) = getDate();
312 break;
313 case DataType::TIME:
314 (*this) = getTime();
315 break;
316 case DataType::TIMESTAMP:
317 (*this) = getDateTime();
318 break;
319 case DataType::BINARY:
320 case DataType::VARBINARY:
321 case DataType::LONGVARBINARY:
322 (*this) = getSequence();
323 break;
324 case DataType::BLOB:
325 case DataType::CLOB:
326 case DataType::OBJECT:
327 case DataType::OTHER:
328 (*this) = makeAny();
329 break;
330 default:
331 (*this) = makeAny();
332 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
336 m_eTypeKind = _eType;
340 void ORowSetValue::free()
342 if(!m_bNull)
344 switch(m_eTypeKind)
346 case DataType::CHAR:
347 case DataType::VARCHAR:
348 case DataType::DECIMAL:
349 case DataType::NUMERIC:
350 case DataType::LONGVARCHAR:
351 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
352 rtl_uString_release(m_aValue.m_pString);
353 m_aValue.m_pString = NULL;
354 break;
355 case DataType::DATE:
356 delete static_cast<css::util::Date*>(m_aValue.m_pValue);
357 TRACE_FREE( Date )
358 m_aValue.m_pValue = NULL;
359 break;
360 case DataType::TIME:
361 delete static_cast<css::util::Time*>(m_aValue.m_pValue);
362 TRACE_FREE( tools::Time )
363 m_aValue.m_pValue = NULL;
364 break;
365 case DataType::TIMESTAMP:
366 delete static_cast<css::util::DateTime*>(m_aValue.m_pValue);
367 TRACE_FREE( DateTime )
368 m_aValue.m_pValue = NULL;
369 break;
370 case DataType::BINARY:
371 case DataType::VARBINARY:
372 case DataType::LONGVARBINARY:
373 delete static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
374 TRACE_FREE( Sequence_sal_Int8 )
375 m_aValue.m_pValue = NULL;
376 break;
377 case DataType::BLOB:
378 case DataType::CLOB:
379 case DataType::OBJECT:
380 delete static_cast<Any*>(m_aValue.m_pValue);
381 TRACE_FREE( Any )
382 m_aValue.m_pValue = NULL;
383 break;
384 case DataType::BIT:
385 case DataType::TINYINT:
386 case DataType::SMALLINT:
387 case DataType::INTEGER:
388 case DataType::BIGINT:
389 case DataType::BOOLEAN:
390 case DataType::FLOAT:
391 case DataType::DOUBLE:
392 case DataType::REAL:
393 break;
394 default:
395 if ( m_aValue.m_pValue )
397 delete static_cast<Any*>(m_aValue.m_pValue);
398 TRACE_FREE( Any )
399 m_aValue.m_pValue = NULL;
401 break;
404 m_bNull = true;
408 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
410 if(&_rRH == this)
411 return *this;
413 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
414 free();
416 m_bBound = _rRH.m_bBound;
417 m_eTypeKind = _rRH.m_eTypeKind;
418 m_bSigned = _rRH.m_bSigned;
420 if(m_bNull && !_rRH.m_bNull)
422 switch(_rRH.m_eTypeKind)
424 case DataType::CHAR:
425 case DataType::VARCHAR:
426 case DataType::DECIMAL:
427 case DataType::NUMERIC:
428 case DataType::LONGVARCHAR:
429 rtl_uString_acquire(_rRH.m_aValue.m_pString);
430 m_aValue.m_pString = _rRH.m_aValue.m_pString;
431 break;
432 case DataType::DATE:
433 m_aValue.m_pValue = new Date(*static_cast<Date*>(_rRH.m_aValue.m_pValue));
434 TRACE_ALLOC( Date )
435 break;
436 case DataType::TIME:
437 m_aValue.m_pValue = new Time(*static_cast<Time*>(_rRH.m_aValue.m_pValue));
438 TRACE_ALLOC( tools::Time )
439 break;
440 case DataType::TIMESTAMP:
441 m_aValue.m_pValue = new DateTime(*static_cast<DateTime*>(_rRH.m_aValue.m_pValue));
442 TRACE_ALLOC( DateTime )
443 break;
444 case DataType::BINARY:
445 case DataType::VARBINARY:
446 case DataType::LONGVARBINARY:
447 m_aValue.m_pValue = new Sequence<sal_Int8>(*static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue));
448 TRACE_ALLOC( Sequence_sal_Int8 )
449 break;
450 case DataType::BIT:
451 case DataType::BOOLEAN:
452 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
453 break;
454 case DataType::TINYINT:
455 if ( _rRH.m_bSigned )
456 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
457 else
458 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
459 break;
460 case DataType::SMALLINT:
461 if ( _rRH.m_bSigned )
462 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
463 else
464 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
465 break;
466 case DataType::INTEGER:
467 if ( _rRH.m_bSigned )
468 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
469 else
470 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
471 break;
472 case DataType::BIGINT:
473 if ( _rRH.m_bSigned )
474 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
475 else
476 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
477 break;
478 case DataType::FLOAT:
479 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
480 break;
481 case DataType::DOUBLE:
482 case DataType::REAL:
483 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
484 break;
485 default:
486 m_aValue.m_pValue = new Any(*static_cast<Any*>(_rRH.m_aValue.m_pValue));
487 TRACE_ALLOC( Any )
490 else if(!_rRH.m_bNull)
492 switch(_rRH.m_eTypeKind)
494 case DataType::CHAR:
495 case DataType::VARCHAR:
496 case DataType::DECIMAL:
497 case DataType::NUMERIC:
498 case DataType::LONGVARCHAR:
499 (*this) = OUString(_rRH.m_aValue.m_pString);
500 break;
501 case DataType::DATE:
502 (*this) = *static_cast<Date*>(_rRH.m_aValue.m_pValue);
503 break;
504 case DataType::TIME:
505 (*this) = *static_cast<Time*>(_rRH.m_aValue.m_pValue);
506 break;
507 case DataType::TIMESTAMP:
508 (*this) = *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
509 break;
510 case DataType::BINARY:
511 case DataType::VARBINARY:
512 case DataType::LONGVARBINARY:
513 (*this) = *static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue);
514 break;
515 case DataType::BIT:
516 case DataType::BOOLEAN:
517 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
518 break;
519 case DataType::TINYINT:
520 if ( _rRH.m_bSigned )
521 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
522 else
523 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
524 break;
525 case DataType::SMALLINT:
526 if ( _rRH.m_bSigned )
527 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
528 else
529 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
530 break;
531 case DataType::INTEGER:
532 if ( _rRH.m_bSigned )
533 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
534 else
535 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
536 break;
537 case DataType::BIGINT:
538 if ( _rRH.m_bSigned )
539 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
540 else
541 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
542 break;
543 case DataType::FLOAT:
544 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
545 break;
546 case DataType::DOUBLE:
547 case DataType::REAL:
548 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
549 break;
550 default:
551 *static_cast<Any*>(m_aValue.m_pValue) = *static_cast<Any*>(_rRH.m_aValue.m_pValue);
555 m_bNull = _rRH.m_bNull;
556 // OJ: BUGID: 96277
557 m_eTypeKind = _rRH.m_eTypeKind;
559 return *this;
563 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
565 if(m_eTypeKind != DataType::DATE)
566 free();
568 if(m_bNull)
570 m_aValue.m_pValue = new Date(_rRH);
571 TRACE_ALLOC( Date )
572 m_eTypeKind = DataType::DATE;
573 m_bNull = false;
575 else
576 *static_cast<Date*>(m_aValue.m_pValue) = _rRH;
578 return *this;
581 ORowSetValue& ORowSetValue::operator=(const css::util::Time& _rRH)
583 if(m_eTypeKind != DataType::TIME)
584 free();
586 if(m_bNull)
588 m_aValue.m_pValue = new Time(_rRH);
589 TRACE_ALLOC( tools::Time )
590 m_eTypeKind = DataType::TIME;
591 m_bNull = false;
593 else
594 *static_cast<Time*>(m_aValue.m_pValue) = _rRH;
596 return *this;
599 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
601 if(m_eTypeKind != DataType::TIMESTAMP)
602 free();
603 if(m_bNull)
605 m_aValue.m_pValue = new DateTime(_rRH);
606 TRACE_ALLOC( DateTime )
607 m_eTypeKind = DataType::TIMESTAMP;
608 m_bNull = false;
610 else
611 *static_cast<DateTime*>(m_aValue.m_pValue) = _rRH;
613 return *this;
617 ORowSetValue& ORowSetValue::operator=(const OUString& _rRH)
619 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
621 free();
622 m_bNull = false;
624 m_aValue.m_pString = _rRH.pData;
625 rtl_uString_acquire(m_aValue.m_pString);
626 m_eTypeKind = DataType::VARCHAR;
629 return *this;
633 ORowSetValue& ORowSetValue::operator=(const double& _rRH)
635 if(m_eTypeKind != DataType::DOUBLE)
636 free();
638 m_aValue.m_nDouble = _rRH;
639 m_eTypeKind = DataType::DOUBLE;
640 m_bNull = false;
642 return *this;
645 ORowSetValue& ORowSetValue::operator=(const float& _rRH)
647 if(m_eTypeKind != DataType::FLOAT)
648 free();
650 m_aValue.m_nFloat = _rRH;
651 m_eTypeKind = DataType::FLOAT;
652 m_bNull = false;
654 return *this;
658 ORowSetValue& ORowSetValue::operator=(const sal_Int8& _rRH)
660 if(m_eTypeKind != DataType::TINYINT )
661 free();
663 m_aValue.m_nInt8 = _rRH;
664 m_eTypeKind = DataType::TINYINT;
665 m_bNull = false;
666 m_bSigned = true;
667 return *this;
671 ORowSetValue& ORowSetValue::operator=(const sal_uInt8& _rRH)
673 if(m_eTypeKind != DataType::TINYINT )
674 free();
676 m_aValue.m_uInt8 = _rRH;
677 m_eTypeKind = DataType::TINYINT;
678 m_bNull = false;
679 m_bSigned = false;
680 return *this;
684 ORowSetValue& ORowSetValue::operator=(const sal_Int16& _rRH)
686 if(m_eTypeKind != DataType::SMALLINT )
687 free();
689 m_aValue.m_nInt16 = _rRH;
690 m_eTypeKind = DataType::SMALLINT;
691 m_bNull = false;
692 m_bSigned = true;
694 return *this;
698 ORowSetValue& ORowSetValue::operator=(const sal_uInt16& _rRH)
700 if(m_eTypeKind != DataType::SMALLINT )
701 free();
703 m_aValue.m_uInt16 = _rRH;
704 m_eTypeKind = DataType::SMALLINT;
705 m_bNull = false;
706 m_bSigned = false;
708 return *this;
712 ORowSetValue& ORowSetValue::operator=(const sal_Int32& _rRH)
714 if(m_eTypeKind != DataType::INTEGER )
715 free();
717 m_aValue.m_nInt32 = _rRH;
719 m_eTypeKind = DataType::INTEGER;
720 m_bNull = false;
721 m_bSigned = true;
723 return *this;
727 ORowSetValue& ORowSetValue::operator=(const sal_uInt32& _rRH)
729 if(m_eTypeKind != DataType::INTEGER )
730 free();
732 m_aValue.m_uInt32 = _rRH;
734 m_eTypeKind = DataType::INTEGER;
735 m_bNull = false;
736 m_bSigned = false;
738 return *this;
742 ORowSetValue& ORowSetValue::operator=(const bool _rRH)
744 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
745 free();
747 m_aValue.m_bBool = _rRH;
748 m_eTypeKind = DataType::BOOLEAN;
749 m_bNull = false;
751 return *this;
754 ORowSetValue& ORowSetValue::operator=(const sal_Int64& _rRH)
756 if ( DataType::BIGINT != m_eTypeKind)
757 free();
759 m_aValue.m_nInt64 = _rRH;
760 m_eTypeKind = DataType::BIGINT;
761 m_bNull = false;
762 m_bSigned = true;
764 return *this;
767 ORowSetValue& ORowSetValue::operator=(const sal_uInt64& _rRH)
769 if ( DataType::BIGINT != m_eTypeKind)
770 free();
772 m_aValue.m_uInt64 = _rRH;
773 m_eTypeKind = DataType::BIGINT;
774 m_bNull = false;
775 m_bSigned = false;
777 return *this;
780 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
782 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
783 free();
785 if (m_bNull)
787 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
788 TRACE_ALLOC( Sequence_sal_Int8 )
790 else
791 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
793 m_eTypeKind = DataType::LONGVARBINARY;
794 m_bNull = false;
796 return *this;
799 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
801 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
802 free();
804 if ( m_bNull )
806 m_aValue.m_pValue = new Any(_rAny);
807 TRACE_ALLOC( Any )
809 else
810 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
812 m_eTypeKind = DataType::OBJECT;
813 m_bNull = false;
815 return *this;
819 bool operator==(const Date& _rLH, const Date& _rRH)
821 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year;
825 bool operator==(const css::util::Time& _rLH, const css::util::Time& _rRH)
827 return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds;
831 bool operator==(const DateTime& _rLH, const DateTime& _rRH)
833 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year &&
834 _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds;
838 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
840 if ( m_bNull != _rRH.isNull() )
841 return false;
843 if(m_bNull && _rRH.isNull())
844 return true;
846 if ( !isStorageComparable(m_eTypeKind, _rRH.m_eTypeKind ))
848 switch(m_eTypeKind)
850 case DataType::FLOAT:
851 case DataType::DOUBLE:
852 case DataType::REAL:
853 return getDouble() == _rRH.getDouble();
854 default:
855 switch(_rRH.m_eTypeKind)
857 case DataType::FLOAT:
858 case DataType::DOUBLE:
859 case DataType::REAL:
860 return getDouble() == _rRH.getDouble();
861 default:
862 break;
864 break;
866 return false;
869 bool bRet = false;
870 OSL_ENSURE(!m_bNull,"SHould not be null!");
871 switch(m_eTypeKind)
873 case DataType::VARCHAR:
874 case DataType::CHAR:
875 case DataType::LONGVARCHAR:
877 OUString aVal1(m_aValue.m_pString);
878 OUString aVal2(_rRH.m_aValue.m_pString);
879 return aVal1 == aVal2;
881 default:
882 if ( m_bSigned != _rRH.m_bSigned )
883 return false;
884 break;
887 switch(m_eTypeKind)
889 case DataType::DECIMAL:
890 case DataType::NUMERIC:
892 OUString aVal1(m_aValue.m_pString);
893 OUString aVal2(_rRH.m_aValue.m_pString);
894 bRet = aVal1 == aVal2;
896 break;
897 case DataType::FLOAT:
898 bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
899 break;
900 case DataType::DOUBLE:
901 case DataType::REAL:
902 bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
903 break;
904 case DataType::TINYINT:
905 bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
906 break;
907 case DataType::SMALLINT:
908 bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_uInt16 == _rRH.m_aValue.m_uInt16);
909 break;
910 case DataType::INTEGER:
911 bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (m_aValue.m_uInt32 == _rRH.m_aValue.m_uInt32);
912 break;
913 case DataType::BIGINT:
914 bRet = m_bSigned ? ( m_aValue.m_nInt64 == _rRH.m_aValue.m_nInt64 ) : (m_aValue.m_uInt64 == _rRH.m_aValue.m_uInt64);
915 break;
916 case DataType::BIT:
917 case DataType::BOOLEAN:
918 bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
919 break;
920 case DataType::DATE:
921 bRet = *static_cast<Date*>(m_aValue.m_pValue) == *static_cast<Date*>(_rRH.m_aValue.m_pValue);
922 break;
923 case DataType::TIME:
924 bRet = *static_cast<Time*>(m_aValue.m_pValue) == *static_cast<Time*>(_rRH.m_aValue.m_pValue);
925 break;
926 case DataType::TIMESTAMP:
927 bRet = *static_cast<DateTime*>(m_aValue.m_pValue) == *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
928 break;
929 case DataType::BINARY:
930 case DataType::VARBINARY:
931 case DataType::LONGVARBINARY:
932 bRet = false;
933 break;
934 case DataType::BLOB:
935 case DataType::CLOB:
936 case DataType::OBJECT:
937 case DataType::OTHER:
938 bRet = false;
939 break;
940 default:
941 bRet = false;
942 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
943 break;
945 return bRet;
948 Any ORowSetValue::makeAny() const
950 Any rValue;
951 if(isBound() && !isNull())
953 switch(getTypeKind())
955 case DataType::SQLNULL:
956 assert(rValue == Any());
957 break;
958 case DataType::CHAR:
959 case DataType::VARCHAR:
960 case DataType::DECIMAL:
961 case DataType::NUMERIC:
962 case DataType::LONGVARCHAR:
963 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
964 rValue <<= OUString(m_aValue.m_pString);
965 break;
966 case DataType::FLOAT:
967 rValue <<= m_aValue.m_nFloat;
968 break;
969 case DataType::DOUBLE:
970 case DataType::REAL:
971 rValue <<= m_aValue.m_nDouble;
972 break;
973 case DataType::DATE:
974 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
975 rValue <<= *static_cast<Date*>(m_aValue.m_pValue);
976 break;
977 case DataType::TIME:
978 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
979 rValue <<= *static_cast<Time*>(m_aValue.m_pValue);
980 break;
981 case DataType::TIMESTAMP:
982 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
983 rValue <<= *static_cast<DateTime*>(m_aValue.m_pValue);
984 break;
985 case DataType::BINARY:
986 case DataType::VARBINARY:
987 case DataType::LONGVARBINARY:
988 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
989 rValue <<= *static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
990 break;
991 case DataType::BLOB:
992 case DataType::CLOB:
993 case DataType::OBJECT:
994 case DataType::OTHER:
995 rValue = getAny();
996 break;
997 case DataType::BIT:
998 case DataType::BOOLEAN:
999 rValue <<= m_aValue.m_bBool;
1000 break;
1001 case DataType::TINYINT:
1002 if ( m_bSigned )
1003 // TypeClass_BYTE
1004 rValue <<= m_aValue.m_nInt8;
1005 else
1006 // There is no TypeClass_UNSIGNED_BYTE,
1007 // so silently promote it to a 16-bit integer,
1008 // that is TypeClass_UNSIGNED_SHORT
1009 rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
1010 break;
1011 case DataType::SMALLINT:
1012 if ( m_bSigned )
1013 // TypeClass_SHORT
1014 rValue <<= m_aValue.m_nInt16;
1015 else
1016 // TypeClass_UNSIGNED_SHORT
1017 rValue <<= m_aValue.m_uInt16;
1018 break;
1019 case DataType::INTEGER:
1020 if ( m_bSigned )
1021 // TypeClass_LONG
1022 rValue <<= m_aValue.m_nInt32;
1023 else
1024 // TypeClass_UNSIGNED_LONG
1025 rValue <<= m_aValue.m_uInt32;
1026 break;
1027 case DataType::BIGINT:
1028 if ( m_bSigned )
1029 // TypeClass_HYPER
1030 rValue <<= m_aValue.m_nInt64;
1031 else
1032 // TypeClass_UNSIGNED_HYPER
1033 rValue <<= m_aValue.m_uInt64;
1034 break;
1035 default:
1036 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
1037 rValue = getAny();
1038 break;
1041 return rValue;
1044 OUString ORowSetValue::getString( ) const
1046 OUString aRet;
1047 if(!m_bNull)
1049 switch(getTypeKind())
1051 case DataType::CHAR:
1052 case DataType::VARCHAR:
1053 case DataType::DECIMAL:
1054 case DataType::NUMERIC:
1055 case DataType::LONGVARCHAR:
1056 aRet = m_aValue.m_pString;
1057 break;
1058 case DataType::FLOAT:
1059 aRet = OUString::number(static_cast<float>(*this));
1060 break;
1061 case DataType::DOUBLE:
1062 case DataType::REAL:
1063 aRet = OUString::number(static_cast<double>(*this));
1064 break;
1065 case DataType::DATE:
1066 aRet = DBTypeConversion::toDateString(*this);
1067 break;
1068 case DataType::TIME:
1069 aRet = DBTypeConversion::toTimeString(*this);
1070 break;
1071 case DataType::TIMESTAMP:
1072 aRet = DBTypeConversion::toDateTimeString(*this);
1073 break;
1074 case DataType::BINARY:
1075 case DataType::VARBINARY:
1076 case DataType::LONGVARBINARY:
1078 OUStringBuffer sVal("0x");
1079 Sequence<sal_Int8> aSeq(getSequence());
1080 const sal_Int8* pBegin = aSeq.getConstArray();
1081 const sal_Int8* pEnd = pBegin + aSeq.getLength();
1082 for(;pBegin != pEnd;++pBegin)
1083 sVal.append((sal_Int32)*pBegin,16);
1084 aRet = sVal.makeStringAndClear();
1086 break;
1087 case DataType::BIT:
1088 aRet = OUString::number(int(static_cast<bool>(*this)));
1089 break;
1090 case DataType::BOOLEAN:
1091 aRet = OUString::boolean(static_cast<bool>(*this));
1092 break;
1093 case DataType::TINYINT:
1094 case DataType::SMALLINT:
1095 case DataType::INTEGER:
1096 if ( m_bSigned )
1097 aRet = OUString::number(static_cast<sal_Int32>(*this));
1098 else
1099 aRet = OUString::number(static_cast<sal_uInt32>(*this));
1100 break;
1101 case DataType::BIGINT:
1102 if ( m_bSigned )
1103 aRet = OUString::number(static_cast<sal_Int64>(*this));
1104 else
1105 aRet = OUString::number(static_cast<sal_uInt64>(*this));
1106 break;
1107 case DataType::CLOB:
1109 Any aValue( getAny() );
1110 Reference< XClob > xClob;
1111 if ( aValue >>= xClob )
1113 if ( xClob.is() )
1115 aRet = xClob->getSubString(1,(sal_Int32)xClob->length() );
1119 break;
1120 default:
1122 Any aValue = makeAny();
1123 aValue >>= aRet;
1124 break;
1128 return aRet;
1131 bool ORowSetValue::getBool() const
1133 bool bRet = false;
1134 if(!m_bNull)
1136 switch(getTypeKind())
1138 case DataType::CHAR:
1139 case DataType::VARCHAR:
1140 case DataType::LONGVARCHAR:
1142 const OUString sValue(m_aValue.m_pString);
1143 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1145 bRet = true;
1146 break;
1148 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1150 bRet = false;
1151 break;
1154 // run through
1155 case DataType::DECIMAL:
1156 case DataType::NUMERIC:
1158 bRet = OUString(m_aValue.m_pString).toInt32() != 0;
1159 break;
1160 case DataType::FLOAT:
1161 bRet = m_aValue.m_nFloat != 0.0;
1162 break;
1163 case DataType::DOUBLE:
1164 case DataType::REAL:
1165 bRet = m_aValue.m_nDouble != 0.0;
1166 break;
1167 case DataType::DATE:
1168 case DataType::TIME:
1169 case DataType::TIMESTAMP:
1170 case DataType::BINARY:
1171 case DataType::VARBINARY:
1172 case DataType::LONGVARBINARY:
1173 OSL_FAIL("getBool() for this type is not allowed!");
1174 break;
1175 case DataType::BIT:
1176 case DataType::BOOLEAN:
1177 bRet = m_aValue.m_bBool;
1178 break;
1179 case DataType::TINYINT:
1180 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_uInt8 != 0);
1181 break;
1182 case DataType::SMALLINT:
1183 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_uInt16 != 0);
1184 break;
1185 case DataType::INTEGER:
1186 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1187 break;
1188 case DataType::BIGINT:
1189 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1190 break;
1191 default:
1193 Any aValue = makeAny();
1194 aValue >>= bRet;
1195 break;
1199 return bRet;
1203 sal_Int8 ORowSetValue::getInt8() const
1205 sal_Int8 nRet = 0;
1206 if(!m_bNull)
1208 switch(getTypeKind())
1210 case DataType::CHAR:
1211 case DataType::VARCHAR:
1212 case DataType::DECIMAL:
1213 case DataType::NUMERIC:
1214 case DataType::LONGVARCHAR:
1215 nRet = sal_Int8(OUString(m_aValue.m_pString).toInt32());
1216 break;
1217 case DataType::FLOAT:
1218 nRet = sal_Int8(m_aValue.m_nFloat);
1219 break;
1220 case DataType::DOUBLE:
1221 case DataType::REAL:
1222 nRet = sal_Int8(m_aValue.m_nDouble);
1223 break;
1224 case DataType::DATE:
1225 case DataType::TIME:
1226 case DataType::TIMESTAMP:
1227 case DataType::BINARY:
1228 case DataType::VARBINARY:
1229 case DataType::LONGVARBINARY:
1230 case DataType::BLOB:
1231 case DataType::CLOB:
1232 OSL_FAIL("getInt8() for this type is not allowed!");
1233 break;
1234 case DataType::BIT:
1235 case DataType::BOOLEAN:
1236 nRet = sal_Int8(m_aValue.m_bBool);
1237 break;
1238 case DataType::TINYINT:
1239 if ( m_bSigned )
1240 nRet = m_aValue.m_nInt8;
1241 else
1242 nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1243 break;
1244 case DataType::SMALLINT:
1245 if ( m_bSigned )
1246 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1247 else
1248 nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1249 break;
1250 case DataType::INTEGER:
1251 if ( m_bSigned )
1252 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1253 else
1254 nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1255 break;
1256 case DataType::BIGINT:
1257 if ( m_bSigned )
1258 nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1259 else
1260 nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1261 break;
1262 default:
1264 Any aValue = makeAny();
1265 aValue >>= nRet;
1266 break;
1270 return nRet;
1274 sal_uInt8 ORowSetValue::getUInt8() const
1276 sal_uInt8 nRet = 0;
1277 if(!m_bNull)
1279 switch(getTypeKind())
1281 case DataType::CHAR:
1282 case DataType::VARCHAR:
1283 case DataType::DECIMAL:
1284 case DataType::NUMERIC:
1285 case DataType::LONGVARCHAR:
1286 nRet = sal_uInt8(OUString(m_aValue.m_pString).toInt32());
1287 break;
1288 case DataType::FLOAT:
1289 nRet = sal_uInt8(m_aValue.m_nFloat);
1290 break;
1291 case DataType::DOUBLE:
1292 case DataType::REAL:
1293 nRet = sal_uInt8(m_aValue.m_nDouble);
1294 break;
1295 case DataType::DATE:
1296 case DataType::TIME:
1297 case DataType::TIMESTAMP:
1298 case DataType::BINARY:
1299 case DataType::VARBINARY:
1300 case DataType::LONGVARBINARY:
1301 case DataType::BLOB:
1302 case DataType::CLOB:
1303 OSL_FAIL("getuInt8() for this type is not allowed!");
1304 break;
1305 case DataType::BIT:
1306 case DataType::BOOLEAN:
1307 nRet = int(m_aValue.m_bBool);
1308 break;
1309 case DataType::TINYINT:
1310 if ( m_bSigned )
1311 nRet = m_aValue.m_nInt8;
1312 else
1313 nRet = m_aValue.m_uInt8;
1314 break;
1315 case DataType::SMALLINT:
1316 if ( m_bSigned )
1317 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1318 else
1319 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1320 break;
1321 case DataType::INTEGER:
1322 if ( m_bSigned )
1323 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1324 else
1325 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1326 break;
1327 case DataType::BIGINT:
1328 if ( m_bSigned )
1329 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1330 else
1331 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1332 break;
1333 default:
1335 Any aValue = makeAny();
1336 aValue >>= nRet;
1337 break;
1341 return nRet;
1346 sal_Int16 ORowSetValue::getInt16() const
1348 sal_Int16 nRet = 0;
1349 if(!m_bNull)
1351 switch(getTypeKind())
1353 case DataType::CHAR:
1354 case DataType::VARCHAR:
1355 case DataType::DECIMAL:
1356 case DataType::NUMERIC:
1357 case DataType::LONGVARCHAR:
1358 nRet = sal_Int16(OUString(m_aValue.m_pString).toInt32());
1359 break;
1360 case DataType::FLOAT:
1361 nRet = sal_Int16(m_aValue.m_nFloat);
1362 break;
1363 case DataType::DOUBLE:
1364 case DataType::REAL:
1365 nRet = sal_Int16(m_aValue.m_nDouble);
1366 break;
1367 case DataType::DATE:
1368 case DataType::TIME:
1369 case DataType::TIMESTAMP:
1370 case DataType::BINARY:
1371 case DataType::VARBINARY:
1372 case DataType::LONGVARBINARY:
1373 case DataType::BLOB:
1374 case DataType::CLOB:
1375 OSL_FAIL("getInt16() for this type is not allowed!");
1376 break;
1377 case DataType::BIT:
1378 case DataType::BOOLEAN:
1379 nRet = sal_Int16(m_aValue.m_bBool);
1380 break;
1381 case DataType::TINYINT:
1382 if ( m_bSigned )
1383 nRet = m_aValue.m_nInt8;
1384 else
1385 nRet = m_aValue.m_uInt8;
1386 break;
1387 case DataType::SMALLINT:
1388 if ( m_bSigned )
1389 nRet = m_aValue.m_nInt16;
1390 else
1391 nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1392 break;
1393 case DataType::INTEGER:
1394 if ( m_bSigned )
1395 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1396 else
1397 nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1398 break;
1399 case DataType::BIGINT:
1400 if ( m_bSigned )
1401 nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1402 else
1403 nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1404 break;
1405 default:
1407 Any aValue = makeAny();
1408 aValue >>= nRet;
1409 break;
1413 return nRet;
1417 sal_uInt16 ORowSetValue::getUInt16() const
1419 sal_uInt16 nRet = 0;
1420 if(!m_bNull)
1422 switch(getTypeKind())
1424 case DataType::CHAR:
1425 case DataType::VARCHAR:
1426 case DataType::DECIMAL:
1427 case DataType::NUMERIC:
1428 case DataType::LONGVARCHAR:
1429 nRet = sal_uInt16(OUString(m_aValue.m_pString).toInt32());
1430 break;
1431 case DataType::FLOAT:
1432 nRet = sal_uInt16(m_aValue.m_nFloat);
1433 break;
1434 case DataType::DOUBLE:
1435 case DataType::REAL:
1436 nRet = sal_uInt16(m_aValue.m_nDouble);
1437 break;
1438 case DataType::DATE:
1439 case DataType::TIME:
1440 case DataType::TIMESTAMP:
1441 case DataType::BINARY:
1442 case DataType::VARBINARY:
1443 case DataType::LONGVARBINARY:
1444 case DataType::BLOB:
1445 case DataType::CLOB:
1446 OSL_FAIL("getuInt16() for this type is not allowed!");
1447 break;
1448 case DataType::BIT:
1449 case DataType::BOOLEAN:
1450 nRet = sal_uInt16(m_aValue.m_bBool);
1451 break;
1452 case DataType::TINYINT:
1453 if ( m_bSigned )
1454 nRet = m_aValue.m_nInt8;
1455 else
1456 nRet = m_aValue.m_uInt8;
1457 break;
1458 case DataType::SMALLINT:
1459 if ( m_bSigned )
1460 nRet = m_aValue.m_nInt16;
1461 else
1462 nRet = m_aValue.m_uInt16;
1463 break;
1464 case DataType::INTEGER:
1465 if ( m_bSigned )
1466 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1467 else
1468 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1469 break;
1470 case DataType::BIGINT:
1471 if ( m_bSigned )
1472 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1473 else
1474 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1475 break;
1476 default:
1478 Any aValue = makeAny();
1479 aValue >>= nRet;
1480 break;
1484 return nRet;
1488 sal_Int32 ORowSetValue::getInt32() const
1490 sal_Int32 nRet = 0;
1491 if(!m_bNull)
1493 switch(getTypeKind())
1495 case DataType::CHAR:
1496 case DataType::VARCHAR:
1497 case DataType::DECIMAL:
1498 case DataType::NUMERIC:
1499 case DataType::LONGVARCHAR:
1500 nRet = OUString(m_aValue.m_pString).toInt32();
1501 break;
1502 case DataType::FLOAT:
1503 nRet = sal_Int32(m_aValue.m_nFloat);
1504 break;
1505 case DataType::DOUBLE:
1506 case DataType::REAL:
1507 nRet = sal_Int32(m_aValue.m_nDouble);
1508 break;
1509 case DataType::DATE:
1510 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1511 break;
1512 case DataType::TIME:
1513 case DataType::TIMESTAMP:
1514 case DataType::BINARY:
1515 case DataType::VARBINARY:
1516 case DataType::LONGVARBINARY:
1517 case DataType::BLOB:
1518 case DataType::CLOB:
1519 OSL_FAIL("getInt32() for this type is not allowed!");
1520 break;
1521 case DataType::BIT:
1522 case DataType::BOOLEAN:
1523 nRet = sal_Int32(m_aValue.m_bBool);
1524 break;
1525 case DataType::TINYINT:
1526 if ( m_bSigned )
1527 nRet = m_aValue.m_nInt8;
1528 else
1529 nRet = m_aValue.m_uInt8;
1530 break;
1531 case DataType::SMALLINT:
1532 if ( m_bSigned )
1533 nRet = m_aValue.m_nInt16;
1534 else
1535 nRet = m_aValue.m_uInt16;
1536 break;
1537 case DataType::INTEGER:
1538 if ( m_bSigned )
1539 nRet = m_aValue.m_nInt32;
1540 else
1541 nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1542 break;
1543 case DataType::BIGINT:
1544 if ( m_bSigned )
1545 nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1546 else
1547 nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1548 break;
1549 default:
1551 Any aValue = makeAny();
1552 aValue >>= nRet;
1553 break;
1557 return nRet;
1561 sal_uInt32 ORowSetValue::getUInt32() const
1563 sal_uInt32 nRet = 0;
1564 if(!m_bNull)
1566 switch(getTypeKind())
1568 case DataType::CHAR:
1569 case DataType::VARCHAR:
1570 case DataType::DECIMAL:
1571 case DataType::NUMERIC:
1572 case DataType::LONGVARCHAR:
1573 nRet = OUString(m_aValue.m_pString).toUInt32();
1574 break;
1575 case DataType::FLOAT:
1576 nRet = sal_uInt32(m_aValue.m_nFloat);
1577 break;
1578 case DataType::DOUBLE:
1579 case DataType::REAL:
1580 nRet = sal_uInt32(m_aValue.m_nDouble);
1581 break;
1582 case DataType::DATE:
1583 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1584 break;
1585 case DataType::TIME:
1586 case DataType::TIMESTAMP:
1587 case DataType::BINARY:
1588 case DataType::VARBINARY:
1589 case DataType::LONGVARBINARY:
1590 case DataType::BLOB:
1591 case DataType::CLOB:
1592 OSL_FAIL("getuInt32() for this type is not allowed!");
1593 break;
1594 case DataType::BIT:
1595 case DataType::BOOLEAN:
1596 nRet = sal_uInt32(m_aValue.m_bBool);
1597 break;
1598 case DataType::TINYINT:
1599 if ( m_bSigned )
1600 nRet = m_aValue.m_nInt8;
1601 else
1602 nRet = m_aValue.m_uInt8;
1603 break;
1604 case DataType::SMALLINT:
1605 if ( m_bSigned )
1606 nRet = m_aValue.m_nInt16;
1607 else
1608 nRet = m_aValue.m_uInt16;
1609 break;
1610 case DataType::INTEGER:
1611 if ( m_bSigned )
1612 nRet = m_aValue.m_nInt32;
1613 else
1614 nRet = m_aValue.m_uInt32;
1615 break;
1616 case DataType::BIGINT:
1617 if ( m_bSigned )
1618 nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1619 else
1620 nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1621 break;
1622 default:
1624 Any aValue = makeAny();
1625 aValue >>= nRet;
1626 break;
1630 return nRet;
1634 sal_Int64 ORowSetValue::getLong() const
1636 sal_Int64 nRet = 0;
1637 if(!m_bNull)
1639 switch(getTypeKind())
1641 case DataType::CHAR:
1642 case DataType::VARCHAR:
1643 case DataType::DECIMAL:
1644 case DataType::NUMERIC:
1645 case DataType::LONGVARCHAR:
1646 nRet = OUString(m_aValue.m_pString).toInt64();
1647 break;
1648 case DataType::FLOAT:
1649 nRet = sal_Int64(m_aValue.m_nFloat);
1650 break;
1651 case DataType::DOUBLE:
1652 case DataType::REAL:
1653 nRet = sal_Int64(m_aValue.m_nDouble);
1654 break;
1655 case DataType::DATE:
1656 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1657 break;
1658 case DataType::TIME:
1659 case DataType::TIMESTAMP:
1660 case DataType::BINARY:
1661 case DataType::VARBINARY:
1662 case DataType::LONGVARBINARY:
1663 case DataType::BLOB:
1664 case DataType::CLOB:
1665 OSL_FAIL("getLong() for this type is not allowed!");
1666 break;
1667 case DataType::BIT:
1668 case DataType::BOOLEAN:
1669 nRet = sal_Int64(m_aValue.m_bBool);
1670 break;
1671 case DataType::TINYINT:
1672 if ( m_bSigned )
1673 nRet = m_aValue.m_nInt8;
1674 else
1675 nRet = m_aValue.m_uInt8;
1676 break;
1677 case DataType::SMALLINT:
1678 if ( m_bSigned )
1679 nRet = m_aValue.m_nInt16;
1680 else
1681 nRet = m_aValue.m_uInt16;
1682 break;
1683 case DataType::INTEGER:
1684 if ( m_bSigned )
1685 nRet = m_aValue.m_nInt32;
1686 else
1687 nRet = m_aValue.m_uInt32;
1688 break;
1689 case DataType::BIGINT:
1690 if ( m_bSigned )
1691 nRet = m_aValue.m_nInt64;
1692 else
1693 nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1694 break;
1695 default:
1697 Any aValue = makeAny();
1698 aValue >>= nRet;
1699 break;
1703 return nRet;
1707 sal_uInt64 ORowSetValue::getULong() const
1709 sal_uInt64 nRet = 0;
1710 if(!m_bNull)
1712 switch(getTypeKind())
1714 case DataType::CHAR:
1715 case DataType::VARCHAR:
1716 case DataType::DECIMAL:
1717 case DataType::NUMERIC:
1718 case DataType::LONGVARCHAR:
1719 nRet = static_cast<sal_uInt64>(OUString(m_aValue.m_pString).toUInt64());
1720 break;
1721 case DataType::FLOAT:
1722 nRet = sal_uInt64(m_aValue.m_nFloat);
1723 break;
1724 case DataType::DOUBLE:
1725 case DataType::REAL:
1726 nRet = sal_uInt64(m_aValue.m_nDouble);
1727 break;
1728 case DataType::DATE:
1729 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1730 break;
1731 case DataType::TIME:
1732 case DataType::TIMESTAMP:
1733 case DataType::BINARY:
1734 case DataType::VARBINARY:
1735 case DataType::LONGVARBINARY:
1736 case DataType::BLOB:
1737 case DataType::CLOB:
1738 OSL_FAIL("getULong() for this type is not allowed!");
1739 break;
1740 case DataType::BIT:
1741 case DataType::BOOLEAN:
1742 nRet = sal_uInt64(m_aValue.m_bBool);
1743 break;
1744 case DataType::TINYINT:
1745 if ( m_bSigned )
1746 nRet = m_aValue.m_nInt8;
1747 else
1748 nRet = m_aValue.m_uInt8;
1749 break;
1750 case DataType::SMALLINT:
1751 if ( m_bSigned )
1752 nRet = m_aValue.m_nInt16;
1753 else
1754 nRet = m_aValue.m_uInt16;
1755 break;
1756 case DataType::INTEGER:
1757 if ( m_bSigned )
1758 nRet = m_aValue.m_nInt32;
1759 else
1760 nRet = m_aValue.m_uInt32;
1761 break;
1762 case DataType::BIGINT:
1763 if ( m_bSigned )
1764 nRet = m_aValue.m_nInt64;
1765 else
1766 nRet = m_aValue.m_uInt64;
1767 break;
1768 default:
1770 Any aValue = makeAny();
1771 aValue >>= nRet;
1772 break;
1776 return nRet;
1780 float ORowSetValue::getFloat() const
1782 float nRet = 0;
1783 if(!m_bNull)
1785 switch(getTypeKind())
1787 case DataType::CHAR:
1788 case DataType::VARCHAR:
1789 case DataType::DECIMAL:
1790 case DataType::NUMERIC:
1791 case DataType::LONGVARCHAR:
1792 nRet = OUString(m_aValue.m_pString).toFloat();
1793 break;
1794 case DataType::FLOAT:
1795 nRet = m_aValue.m_nFloat;
1796 break;
1797 case DataType::DOUBLE:
1798 case DataType::REAL:
1799 nRet = (float)m_aValue.m_nDouble;
1800 break;
1801 case DataType::DATE:
1802 nRet = (float)dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1803 break;
1804 case DataType::TIME:
1805 nRet = (float)dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1806 break;
1807 case DataType::TIMESTAMP:
1808 nRet = (float)dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1809 break;
1810 case DataType::BINARY:
1811 case DataType::VARBINARY:
1812 case DataType::LONGVARBINARY:
1813 case DataType::BLOB:
1814 case DataType::CLOB:
1815 OSL_FAIL("getDouble() for this type is not allowed!");
1816 break;
1817 case DataType::BIT:
1818 case DataType::BOOLEAN:
1819 nRet = float(m_aValue.m_bBool);
1820 break;
1821 case DataType::TINYINT:
1822 if ( m_bSigned )
1823 nRet = m_aValue.m_nInt8;
1824 else
1825 nRet = m_aValue.m_uInt8;
1826 break;
1827 case DataType::SMALLINT:
1828 if ( m_bSigned )
1829 nRet = m_aValue.m_nInt16;
1830 else
1831 nRet = (float)m_aValue.m_uInt16;
1832 break;
1833 case DataType::INTEGER:
1834 if ( m_bSigned )
1835 nRet = (float)m_aValue.m_nInt32;
1836 else
1837 nRet = (float)m_aValue.m_uInt32;
1838 break;
1839 case DataType::BIGINT:
1840 if ( m_bSigned )
1841 nRet = (float)m_aValue.m_nInt64;
1842 else
1843 nRet = (float)m_aValue.m_uInt64;
1844 break;
1845 default:
1847 Any aValue = makeAny();
1848 aValue >>= nRet;
1849 break;
1853 return nRet;
1856 double ORowSetValue::getDouble() const
1858 double nRet = 0;
1859 if(!m_bNull)
1861 switch(getTypeKind())
1863 case DataType::CHAR:
1864 case DataType::VARCHAR:
1865 case DataType::DECIMAL:
1866 case DataType::NUMERIC:
1867 case DataType::LONGVARCHAR:
1868 nRet = OUString(m_aValue.m_pString).toDouble();
1869 break;
1870 case DataType::FLOAT:
1871 nRet = m_aValue.m_nFloat;
1872 break;
1873 case DataType::DOUBLE:
1874 case DataType::REAL:
1875 nRet = m_aValue.m_nDouble;
1876 break;
1877 case DataType::DATE:
1878 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1879 break;
1880 case DataType::TIME:
1881 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1882 break;
1883 case DataType::TIMESTAMP:
1884 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1885 break;
1886 case DataType::BINARY:
1887 case DataType::VARBINARY:
1888 case DataType::LONGVARBINARY:
1889 case DataType::BLOB:
1890 case DataType::CLOB:
1891 OSL_FAIL("getDouble() for this type is not allowed!");
1892 break;
1893 case DataType::BIT:
1894 case DataType::BOOLEAN:
1895 nRet = double(m_aValue.m_bBool);
1896 break;
1897 case DataType::TINYINT:
1898 if ( m_bSigned )
1899 nRet = m_aValue.m_nInt8;
1900 else
1901 nRet = m_aValue.m_uInt8;
1902 break;
1903 case DataType::SMALLINT:
1904 if ( m_bSigned )
1905 nRet = m_aValue.m_nInt16;
1906 else
1907 nRet = m_aValue.m_uInt16;
1908 break;
1909 case DataType::INTEGER:
1910 if ( m_bSigned )
1911 nRet = m_aValue.m_nInt32;
1912 else
1913 nRet = m_aValue.m_uInt32;
1914 break;
1915 case DataType::BIGINT:
1916 if ( m_bSigned )
1917 nRet = m_aValue.m_nInt64;
1918 else
1919 nRet = m_aValue.m_uInt64;
1920 break;
1921 default:
1923 Any aValue = makeAny();
1924 aValue >>= nRet;
1925 break;
1929 return nRet;
1932 Sequence<sal_Int8> ORowSetValue::getSequence() const
1934 Sequence<sal_Int8> aSeq;
1935 if (!m_bNull)
1937 switch(m_eTypeKind)
1939 case DataType::OBJECT:
1940 case DataType::CLOB:
1941 case DataType::BLOB:
1943 Reference<XInputStream> xStream;
1944 const Any aValue = makeAny();
1945 if(aValue.hasValue())
1947 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1948 if ( xBlob.is() )
1949 xStream = xBlob->getBinaryStream();
1950 else
1952 Reference<XClob> xClob(aValue,UNO_QUERY);
1953 if ( xClob.is() )
1954 xStream = xClob->getCharacterStream();
1956 if(xStream.is())
1958 const sal_uInt32 nBytesToRead = 65535;
1959 sal_uInt32 nRead;
1963 ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
1965 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1967 if( nRead )
1969 const sal_uInt32 nOldLength = aSeq.getLength();
1970 aSeq.realloc( nOldLength + nRead );
1971 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1974 while( nBytesToRead == nRead );
1975 xStream->closeInput();
1979 break;
1980 case DataType::VARCHAR:
1981 case DataType::LONGVARCHAR:
1983 OUString sVal(m_aValue.m_pString);
1984 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sVal.getStr()),sizeof(sal_Unicode)*sVal.getLength());
1986 break;
1987 case DataType::BINARY:
1988 case DataType::VARBINARY:
1989 case DataType::LONGVARBINARY:
1990 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1991 break;
1992 default:
1994 Any aValue = makeAny();
1995 aValue >>= aSeq;
1996 break;
2000 return aSeq;
2004 ::com::sun::star::util::Date ORowSetValue::getDate() const
2006 ::com::sun::star::util::Date aValue;
2007 if(!m_bNull)
2009 switch(m_eTypeKind)
2011 case DataType::CHAR:
2012 case DataType::VARCHAR:
2013 case DataType::LONGVARCHAR:
2014 aValue = DBTypeConversion::toDate(getString());
2015 break;
2016 case DataType::DECIMAL:
2017 case DataType::NUMERIC:
2018 case DataType::FLOAT:
2019 case DataType::DOUBLE:
2020 case DataType::REAL:
2021 aValue = DBTypeConversion::toDate((double)*this);
2022 break;
2024 case DataType::DATE:
2025 aValue = *static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
2026 break;
2027 case DataType::TIMESTAMP:
2029 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
2030 aValue.Day = pDateTime->Day;
2031 aValue.Month = pDateTime->Month;
2032 aValue.Year = pDateTime->Year;
2034 break;
2035 case DataType::BIT:
2036 case DataType::BOOLEAN:
2037 case DataType::TINYINT:
2038 case DataType::SMALLINT:
2039 case DataType::INTEGER:
2040 case DataType::BIGINT:
2041 aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
2042 break;
2044 case DataType::BLOB:
2045 case DataType::CLOB:
2046 case DataType::OBJECT:
2047 default:
2048 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
2049 // NO break!
2051 case DataType::BINARY:
2052 case DataType::VARBINARY:
2053 case DataType::LONGVARBINARY:
2054 case DataType::TIME:
2055 aValue = DBTypeConversion::toDate( (double)0 );
2056 break;
2059 return aValue;
2062 ::com::sun::star::util::Time ORowSetValue::getTime() const
2064 ::com::sun::star::util::Time aValue;
2065 if(!m_bNull)
2067 switch(m_eTypeKind)
2069 case DataType::CHAR:
2070 case DataType::VARCHAR:
2071 case DataType::LONGVARCHAR:
2072 aValue = DBTypeConversion::toTime(getString());
2073 break;
2074 case DataType::DECIMAL:
2075 case DataType::NUMERIC:
2076 aValue = DBTypeConversion::toTime((double)*this);
2077 break;
2078 case DataType::FLOAT:
2079 case DataType::DOUBLE:
2080 case DataType::REAL:
2081 aValue = DBTypeConversion::toTime((double)*this);
2082 break;
2083 case DataType::TIMESTAMP:
2085 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
2086 aValue.NanoSeconds = pDateTime->NanoSeconds;
2087 aValue.Seconds = pDateTime->Seconds;
2088 aValue.Minutes = pDateTime->Minutes;
2089 aValue.Hours = pDateTime->Hours;
2091 break;
2092 case DataType::TIME:
2093 aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
2094 break;
2095 default:
2097 Any aAnyValue = makeAny();
2098 aAnyValue >>= aValue;
2099 break;
2103 return aValue;
2106 ::com::sun::star::util::DateTime ORowSetValue::getDateTime() const
2108 ::com::sun::star::util::DateTime aValue;
2109 if(!m_bNull)
2111 switch(m_eTypeKind)
2113 case DataType::CHAR:
2114 case DataType::VARCHAR:
2115 case DataType::LONGVARCHAR:
2116 aValue = DBTypeConversion::toDateTime(getString());
2117 break;
2118 case DataType::DECIMAL:
2119 case DataType::NUMERIC:
2120 aValue = DBTypeConversion::toDateTime((double)*this);
2121 break;
2122 case DataType::FLOAT:
2123 case DataType::DOUBLE:
2124 case DataType::REAL:
2125 aValue = DBTypeConversion::toDateTime((double)*this);
2126 break;
2127 case DataType::DATE:
2129 ::com::sun::star::util::Date* pDate = static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
2130 aValue.Day = pDate->Day;
2131 aValue.Month = pDate->Month;
2132 aValue.Year = pDate->Year;
2134 break;
2135 case DataType::TIME:
2137 ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
2138 aValue.NanoSeconds = pTime->NanoSeconds;
2139 aValue.Seconds = pTime->Seconds;
2140 aValue.Minutes = pTime->Minutes;
2141 aValue.Hours = pTime->Hours;
2143 break;
2144 case DataType::TIMESTAMP:
2145 aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
2146 break;
2147 default:
2149 Any aAnyValue = makeAny();
2150 aAnyValue >>= aValue;
2151 break;
2155 return aValue;
2158 void ORowSetValue::setSigned(bool _bMod)
2160 if ( m_bSigned != _bMod )
2162 m_bSigned = _bMod;
2163 if ( !m_bNull )
2165 sal_Int32 nType = m_eTypeKind;
2166 switch(m_eTypeKind)
2168 case DataType::TINYINT:
2169 if ( m_bSigned )
2170 (*this) = getInt8();
2171 else
2173 m_bSigned = !m_bSigned;
2174 (*this) = getInt16();
2175 m_bSigned = !m_bSigned;
2177 break;
2178 case DataType::SMALLINT:
2179 if ( m_bSigned )
2180 (*this) = getInt16();
2181 else
2183 m_bSigned = !m_bSigned;
2184 (*this) = getInt32();
2185 m_bSigned = !m_bSigned;
2187 break;
2188 case DataType::INTEGER:
2189 if ( m_bSigned )
2190 (*this) = getInt32();
2191 else
2193 m_bSigned = !m_bSigned;
2194 (*this) = getLong();
2195 m_bSigned = !m_bSigned;
2197 break;
2198 case DataType::BIGINT:
2199 if ( m_bSigned )
2200 m_aValue.m_nInt64 = static_cast<sal_Int64>(m_aValue.m_uInt64);
2201 else
2202 m_aValue.m_uInt64 = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2203 break;
2205 m_eTypeKind = nType;
2211 namespace detail
2213 class SAL_NO_VTABLE IValueSource
2215 public:
2216 virtual OUString getString() const = 0;
2217 virtual bool getBoolean() const = 0;
2218 virtual sal_Int8 getByte() const = 0;
2219 virtual sal_Int16 getShort() const = 0;
2220 virtual sal_Int32 getInt() const = 0;
2221 virtual sal_Int64 getLong() const = 0;
2222 virtual float getFloat() const = 0;
2223 virtual double getDouble() const = 0;
2224 virtual Date getDate() const = 0;
2225 virtual css::util::Time getTime() const = 0;
2226 virtual DateTime getTimestamp() const = 0;
2227 virtual Sequence< sal_Int8 > getBytes() const = 0;
2228 virtual Reference< XBlob > getBlob() const = 0;
2229 virtual Reference< XClob > getClob() const = 0;
2230 virtual Any getObject() const = 0;
2231 virtual bool wasNull() const = 0;
2233 virtual ~IValueSource() { }
2236 class RowValue : public IValueSource
2238 public:
2239 RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2240 :m_xRow( _xRow )
2241 ,m_nPos( _nPos )
2245 // IValueSource
2246 virtual OUString getString() const SAL_OVERRIDE { return m_xRow->getString( m_nPos ); };
2247 virtual bool getBoolean() const SAL_OVERRIDE { return m_xRow->getBoolean( m_nPos ); };
2248 virtual sal_Int8 getByte() const SAL_OVERRIDE { return m_xRow->getByte( m_nPos ); };
2249 virtual sal_Int16 getShort() const SAL_OVERRIDE { return m_xRow->getShort( m_nPos ); }
2250 virtual sal_Int32 getInt() const SAL_OVERRIDE { return m_xRow->getInt( m_nPos ); }
2251 virtual sal_Int64 getLong() const SAL_OVERRIDE { return m_xRow->getLong( m_nPos ); }
2252 virtual float getFloat() const SAL_OVERRIDE { return m_xRow->getFloat( m_nPos ); };
2253 virtual double getDouble() const SAL_OVERRIDE { return m_xRow->getDouble( m_nPos ); };
2254 virtual Date getDate() const SAL_OVERRIDE { return m_xRow->getDate( m_nPos ); };
2255 virtual css::util::Time getTime() const SAL_OVERRIDE { return m_xRow->getTime( m_nPos ); };
2256 virtual DateTime getTimestamp() const SAL_OVERRIDE { return m_xRow->getTimestamp( m_nPos ); };
2257 virtual Sequence< sal_Int8 > getBytes() const SAL_OVERRIDE { return m_xRow->getBytes( m_nPos ); };
2258 virtual Reference< XBlob > getBlob() const SAL_OVERRIDE { return m_xRow->getBlob( m_nPos ); };
2259 virtual Reference< XClob > getClob() const SAL_OVERRIDE { return m_xRow->getClob( m_nPos ); };
2260 virtual Any getObject() const SAL_OVERRIDE { return m_xRow->getObject( m_nPos ,NULL); };
2261 virtual bool wasNull() const SAL_OVERRIDE { return m_xRow->wasNull( ); };
2263 private:
2264 const Reference< XRow > m_xRow;
2265 const sal_Int32 m_nPos;
2268 class ColumnValue : public IValueSource
2270 public:
2271 ColumnValue( const Reference< XColumn >& _rxColumn )
2272 :m_xColumn( _rxColumn )
2276 // IValueSource
2277 virtual OUString getString() const SAL_OVERRIDE { return m_xColumn->getString(); };
2278 virtual bool getBoolean() const SAL_OVERRIDE { return m_xColumn->getBoolean(); };
2279 virtual sal_Int8 getByte() const SAL_OVERRIDE { return m_xColumn->getByte(); };
2280 virtual sal_Int16 getShort() const SAL_OVERRIDE { return m_xColumn->getShort(); }
2281 virtual sal_Int32 getInt() const SAL_OVERRIDE { return m_xColumn->getInt(); }
2282 virtual sal_Int64 getLong() const SAL_OVERRIDE { return m_xColumn->getLong(); }
2283 virtual float getFloat() const SAL_OVERRIDE { return m_xColumn->getFloat(); };
2284 virtual double getDouble() const SAL_OVERRIDE { return m_xColumn->getDouble(); };
2285 virtual Date getDate() const SAL_OVERRIDE { return m_xColumn->getDate(); };
2286 virtual css::util::Time getTime() const SAL_OVERRIDE { return m_xColumn->getTime(); };
2287 virtual DateTime getTimestamp() const SAL_OVERRIDE { return m_xColumn->getTimestamp(); };
2288 virtual Sequence< sal_Int8 > getBytes() const SAL_OVERRIDE { return m_xColumn->getBytes(); };
2289 virtual Reference< XBlob > getBlob() const SAL_OVERRIDE { return m_xColumn->getBlob(); };
2290 virtual Reference< XClob > getClob() const SAL_OVERRIDE { return m_xColumn->getClob(); };
2291 virtual Any getObject() const SAL_OVERRIDE { return m_xColumn->getObject( NULL ); };
2292 virtual bool wasNull() const SAL_OVERRIDE { return m_xColumn->wasNull( ); };
2294 private:
2295 const Reference< XColumn > m_xColumn;
2300 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2302 detail::ColumnValue aColumnValue( _rxColumn );
2303 impl_fill( _nType, true, aColumnValue );
2307 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2309 detail::RowValue aRowValue( _xRow, _nPos );
2310 impl_fill( _nType, _bNullable, aRowValue );
2314 void ORowSetValue::fill(sal_Int32 _nPos,
2315 sal_Int32 _nType,
2316 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
2318 fill(_nPos,_nType,true,_xRow);
2322 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2324 bool bReadData = true;
2325 switch(_nType)
2327 case DataType::CHAR:
2328 case DataType::VARCHAR:
2329 case DataType::DECIMAL:
2330 case DataType::NUMERIC:
2331 case DataType::LONGVARCHAR:
2332 (*this) = _rValueSource.getString();
2333 break;
2334 case DataType::BIGINT:
2335 if ( isSigned() )
2336 (*this) = _rValueSource.getLong();
2337 else
2338 // TODO: this is rather horrible performance-wise
2339 // but fixing it needs extending the ::com::sun::star::sdbc::XRow API
2340 // to have a getULong(), and needs updating all drivers :-|
2341 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2342 (*this) = _rValueSource.getString().toUInt64();
2343 break;
2344 case DataType::FLOAT:
2345 (*this) = _rValueSource.getFloat();
2346 break;
2347 case DataType::DOUBLE:
2348 case DataType::REAL:
2349 (*this) = _rValueSource.getDouble();
2350 break;
2351 case DataType::DATE:
2352 (*this) = _rValueSource.getDate();
2353 break;
2354 case DataType::TIME:
2355 (*this) = _rValueSource.getTime();
2356 break;
2357 case DataType::TIMESTAMP:
2358 (*this) = _rValueSource.getTimestamp();
2359 break;
2360 case DataType::BINARY:
2361 case DataType::VARBINARY:
2362 case DataType::LONGVARBINARY:
2363 (*this) = _rValueSource.getBytes();
2364 break;
2365 case DataType::BIT:
2366 case DataType::BOOLEAN:
2367 (*this) = _rValueSource.getBoolean();
2368 break;
2369 case DataType::TINYINT:
2370 if ( isSigned() )
2371 (*this) = _rValueSource.getByte();
2372 else
2373 (*this) = _rValueSource.getShort();
2374 break;
2375 case DataType::SMALLINT:
2376 if ( isSigned() )
2377 (*this) = _rValueSource.getShort();
2378 else
2379 (*this) = _rValueSource.getInt();
2380 break;
2381 case DataType::INTEGER:
2382 if ( isSigned() )
2383 (*this) = _rValueSource.getInt();
2384 else
2385 (*this) = _rValueSource.getLong();
2386 break;
2387 case DataType::CLOB:
2388 (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob());
2389 setTypeKind(DataType::CLOB);
2390 break;
2391 case DataType::BLOB:
2392 (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob());
2393 setTypeKind(DataType::BLOB);
2394 break;
2395 case DataType::OTHER:
2396 (*this) = _rValueSource.getObject();
2397 setTypeKind(DataType::OTHER);
2398 break;
2399 default:
2400 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2401 (*this) = _rValueSource.getObject();
2402 break;
2404 if ( bReadData && _bNullable && _rValueSource.wasNull() )
2405 setNull();
2406 setTypeKind(_nType);
2409 void ORowSetValue::fill(const Any& _rValue)
2411 switch (_rValue.getValueType().getTypeClass())
2413 case TypeClass_VOID:
2414 setNull(); break;
2415 case TypeClass_BOOLEAN:
2417 bool bValue( false );
2418 _rValue >>= bValue;
2419 (*this) = bValue;
2420 break;
2422 case TypeClass_CHAR:
2424 sal_Unicode aDummy(0);
2425 _rValue >>= aDummy;
2426 (*this) = OUString(aDummy);
2427 break;
2429 case TypeClass_STRING:
2431 OUString sDummy;
2432 _rValue >>= sDummy;
2433 (*this) = sDummy;
2434 break;
2436 case TypeClass_FLOAT:
2438 float aDummy(0.0);
2439 _rValue >>= aDummy;
2440 (*this) = aDummy;
2441 break;
2443 case TypeClass_DOUBLE:
2445 double aDummy(0.0);
2446 _rValue >>= aDummy;
2447 (*this) = aDummy;
2448 break;
2450 case TypeClass_BYTE:
2452 sal_Int8 aDummy(0);
2453 _rValue >>= aDummy;
2454 (*this) = aDummy;
2455 break;
2457 case TypeClass_SHORT:
2459 sal_Int16 aDummy(0);
2460 _rValue >>= aDummy;
2461 (*this) = aDummy;
2462 break;
2464 case TypeClass_UNSIGNED_SHORT:
2466 sal_uInt16 nValue(0);
2467 _rValue >>= nValue;
2468 (*this) = nValue;
2469 break;
2471 case TypeClass_LONG:
2473 sal_Int32 aDummy(0);
2474 _rValue >>= aDummy;
2475 (*this) = aDummy;
2476 break;
2478 case TypeClass_UNSIGNED_LONG:
2480 sal_uInt32 nValue(0);
2481 _rValue >>= nValue;
2482 (*this) = static_cast<sal_Int64>(nValue);
2483 setSigned(false);
2484 break;
2486 case TypeClass_HYPER:
2488 sal_Int64 nValue(0);
2489 _rValue >>= nValue;
2490 (*this) = nValue;
2491 break;
2493 case TypeClass_UNSIGNED_HYPER:
2495 sal_uInt64 nValue(0);
2496 _rValue >>= nValue;
2497 (*this) = nValue;
2498 setSigned(false);
2499 break;
2501 case TypeClass_ENUM:
2503 sal_Int32 enumValue( 0 );
2504 ::cppu::enum2int( enumValue, _rValue );
2505 (*this) = enumValue;
2507 break;
2509 case TypeClass_SEQUENCE:
2511 Sequence<sal_Int8> aDummy;
2512 if ( _rValue >>= aDummy )
2513 (*this) = aDummy;
2514 else
2515 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2516 break;
2519 case TypeClass_STRUCT:
2521 ::com::sun::star::util::Date aDate;
2522 ::com::sun::star::util::Time aTime;
2523 ::com::sun::star::util::DateTime aDateTime;
2524 if ( _rValue >>= aDate )
2526 (*this) = aDate;
2528 else if ( _rValue >>= aTime )
2530 (*this) = aTime;
2532 else if ( _rValue >>= aDateTime )
2534 (*this) = aDateTime;
2536 else
2537 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2539 break;
2541 case TypeClass_INTERFACE:
2543 Reference< XClob > xClob;
2544 if ( _rValue >>= xClob )
2546 (*this) = _rValue;
2547 setTypeKind(DataType::CLOB);
2549 else
2551 Reference< XBlob > xBlob;
2552 if ( _rValue >>= xBlob )
2554 (*this) = _rValue;
2555 setTypeKind(DataType::BLOB);
2557 else
2559 (*this) = _rValue;
2563 break;
2565 default:
2566 SAL_WARN( "connectivity.commontools","Unknown type");
2567 break;
2571 } // namespace connectivity
2573 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */