Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / commontools / FValue.cxx
blobe7bb80306cd314bb5b7fd796c01cdb3250109c81
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 <stdio.h>
23 #include "connectivity/FValue.hxx"
24 #include "connectivity/CommonTools.hxx"
25 #include <connectivity/dbconversion.hxx>
26 #include <comphelper/extract.hxx>
27 #include <com/sun/star/io/XInputStream.hpp>
28 #include <rtl/ustrbuf.hxx>
29 #include <boost/type_traits.hpp>
30 #include <boost/static_assert.hpp>
32 using namespace ::dbtools;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::sdb;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::util;
37 using namespace ::com::sun::star::io;
39 namespace connectivity
42 namespace {
43 static bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
45 bool bIsCompatible = true;
47 if (_eType1 != _eType2)
49 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
50 switch (_eType1)
52 case DataType::CHAR:
53 case DataType::VARCHAR:
54 case DataType::DECIMAL:
55 case DataType::NUMERIC:
56 case DataType::LONGVARCHAR:
57 bIsCompatible = (DataType::CHAR == _eType2)
58 || (DataType::VARCHAR == _eType2)
59 || (DataType::DECIMAL == _eType2)
60 || (DataType::NUMERIC == _eType2)
61 || (DataType::LONGVARCHAR == _eType2);
62 break;
64 case DataType::DOUBLE:
65 case DataType::REAL:
66 bIsCompatible = (DataType::DOUBLE == _eType2)
67 || (DataType::REAL == _eType2);
68 break;
70 case DataType::BINARY:
71 case DataType::VARBINARY:
72 case DataType::LONGVARBINARY:
73 bIsCompatible = (DataType::BINARY == _eType2)
74 || (DataType::VARBINARY == _eType2)
75 || (DataType::LONGVARBINARY == _eType2);
76 break;
78 case DataType::INTEGER:
79 bIsCompatible = (DataType::SMALLINT == _eType2)
80 || (DataType::TINYINT == _eType2)
81 || (DataType::BIT == _eType2)
82 || (DataType::BOOLEAN == _eType2);
83 break;
84 case DataType::SMALLINT:
85 bIsCompatible = (DataType::TINYINT == _eType2)
86 || (DataType::BIT == _eType2)
87 || (DataType::BOOLEAN == _eType2);
88 break;
89 case DataType::TINYINT:
90 bIsCompatible = (DataType::BIT == _eType2)
91 || (DataType::BOOLEAN == _eType2);
92 break;
94 case DataType::BLOB:
95 case DataType::CLOB:
96 case DataType::OBJECT:
97 bIsCompatible = (DataType::BLOB == _eType2)
98 || (DataType::CLOB == _eType2)
99 || (DataType::OBJECT == _eType2);
100 break;
102 default:
103 bIsCompatible = false;
106 return bIsCompatible;
111 #ifdef DBG_UTIL
113 #include <vector>
114 #include <rtl/string.h>
116 namespace tracing
118 struct AllocationType
120 const sal_Char* pName;
121 sal_Int32 nAllocatedUnits;
123 AllocationType( ) : pName( NULL ), nAllocatedUnits( 0 ) { }
127 class AllocationTracer
129 public:
130 typedef ::std::vector< AllocationType > AllocationState;
131 static AllocationState s_aAllocated;
132 static ::osl::Mutex s_aMutex;
134 public:
135 static void registerUnit( const sal_Char* _pName );
136 static void revokeUnit( const sal_Char* _pName );
138 private:
139 static AllocationState::iterator getLocation( const sal_Char* _pName );
143 AllocationTracer::AllocationState::iterator AllocationTracer::getLocation( const sal_Char* _pName )
145 AllocationState::iterator aLookFor = s_aAllocated.begin();
146 for ( ;
147 aLookFor != s_aAllocated.end();
148 ++aLookFor
151 if ( 0 == rtl_str_compare( aLookFor->pName, _pName ) )
152 // found
153 return aLookFor;
155 // not found
156 s_aAllocated.push_back( AllocationType() );
157 aLookFor = s_aAllocated.end(); --aLookFor;
158 aLookFor->pName = _pName; // note that this assumes that _pName is a constant string ....
159 return aLookFor;
163 AllocationTracer::AllocationState AllocationTracer::s_aAllocated;
164 ::osl::Mutex AllocationTracer::s_aMutex;
167 void AllocationTracer::registerUnit( const sal_Char* _pName )
169 ::osl::MutexGuard aGuard( s_aMutex );
171 AllocationState::iterator aPos = getLocation( _pName );
172 ++aPos->nAllocatedUnits;
176 void AllocationTracer::revokeUnit( const sal_Char* _pName )
178 ::osl::MutexGuard aGuard( s_aMutex );
180 AllocationState::iterator aPos = getLocation( _pName );
181 --aPos->nAllocatedUnits;
184 #define TRACE_ALLOC( type ) tracing::AllocationTracer::registerUnit( #type );
185 #define TRACE_FREE( type ) tracing::AllocationTracer::revokeUnit( #type );
187 #else
188 #define TRACE_ALLOC( type )
189 #define TRACE_FREE( type )
190 #endif
193 void ORowSetValue::setTypeKind(sal_Int32 _eType)
195 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
197 switch(_eType)
199 case DataType::VARCHAR:
200 case DataType::CHAR:
201 case DataType::DECIMAL:
202 case DataType::NUMERIC:
203 case DataType::LONGVARCHAR:
204 (*this) = getString();
205 break;
206 case DataType::BIGINT:
208 sal_Int64 nVal(getLong());
209 sal_uInt64 nuVal(getULong());
210 if (nVal == 0 && nuVal != 0)
211 (*this) = nuVal;
212 else
213 (*this) = nVal;
214 break;
217 case DataType::FLOAT:
218 (*this) = getFloat();
219 break;
220 case DataType::DOUBLE:
221 case DataType::REAL:
222 (*this) = getDouble();
223 break;
224 case DataType::TINYINT:
225 (*this) = getInt8();
226 break;
227 case DataType::SMALLINT:
228 (*this) = getInt16();
229 break;
230 case DataType::INTEGER:
232 sal_Int32 nVal(getInt32());
233 sal_uInt32 nuVal(getUInt32());
234 if (nVal == 0 && nuVal != 0)
235 (*this) = nuVal;
236 else
237 (*this) = nVal;
238 break;
240 case DataType::BIT:
241 case DataType::BOOLEAN:
242 (*this) = getBool();
243 break;
244 case DataType::DATE:
245 (*this) = getDate();
246 break;
247 case DataType::TIME:
248 (*this) = getTime();
249 break;
250 case DataType::TIMESTAMP:
251 (*this) = getDateTime();
252 break;
253 case DataType::BINARY:
254 case DataType::VARBINARY:
255 case DataType::LONGVARBINARY:
256 (*this) = getSequence();
257 break;
258 case DataType::BLOB:
259 case DataType::CLOB:
260 case DataType::OBJECT:
261 case DataType::OTHER:
262 (*this) = makeAny();
263 break;
264 default:
265 (*this) = makeAny();
266 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
270 m_eTypeKind = _eType;
274 void ORowSetValue::free()
276 if(!m_bNull)
278 switch(m_eTypeKind)
280 case DataType::CHAR:
281 case DataType::VARCHAR:
282 case DataType::DECIMAL:
283 case DataType::NUMERIC:
284 case DataType::LONGVARCHAR:
285 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
286 rtl_uString_release(m_aValue.m_pString);
287 m_aValue.m_pString = NULL;
288 break;
289 case DataType::DATE:
290 delete (::com::sun::star::util::Date*)m_aValue.m_pValue;
291 TRACE_FREE( Date )
292 m_aValue.m_pValue = NULL;
293 break;
294 case DataType::TIME:
295 delete (::com::sun::star::util::Time*)m_aValue.m_pValue;
296 TRACE_FREE( Time )
297 m_aValue.m_pValue = NULL;
298 break;
299 case DataType::TIMESTAMP:
300 delete (::com::sun::star::util::DateTime*)m_aValue.m_pValue;
301 TRACE_FREE( DateTime )
302 m_aValue.m_pValue = NULL;
303 break;
304 case DataType::BINARY:
305 case DataType::VARBINARY:
306 case DataType::LONGVARBINARY:
307 delete (Sequence<sal_Int8>*)m_aValue.m_pValue;
308 TRACE_FREE( Sequence_sal_Int8 )
309 m_aValue.m_pValue = NULL;
310 break;
311 case DataType::BLOB:
312 case DataType::CLOB:
313 case DataType::OBJECT:
314 delete (Any*)m_aValue.m_pValue;
315 TRACE_FREE( Any )
316 m_aValue.m_pValue = NULL;
317 break;
318 case DataType::BIT:
319 case DataType::TINYINT:
320 case DataType::SMALLINT:
321 case DataType::INTEGER:
322 case DataType::BIGINT:
323 case DataType::BOOLEAN:
324 case DataType::FLOAT:
325 case DataType::DOUBLE:
326 case DataType::REAL:
327 break;
328 default:
329 if ( m_aValue.m_pValue )
331 delete (Any*)m_aValue.m_pValue;
332 TRACE_FREE( Any )
333 m_aValue.m_pValue = NULL;
335 break;
338 m_bNull = true;
342 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
344 if(&_rRH == this)
345 return *this;
347 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
348 free();
350 m_bBound = _rRH.m_bBound;
351 m_eTypeKind = _rRH.m_eTypeKind;
352 m_bSigned = _rRH.m_bSigned;
354 if(m_bNull && !_rRH.m_bNull)
356 switch(_rRH.m_eTypeKind)
358 case DataType::CHAR:
359 case DataType::VARCHAR:
360 case DataType::DECIMAL:
361 case DataType::NUMERIC:
362 case DataType::LONGVARCHAR:
363 rtl_uString_acquire(_rRH.m_aValue.m_pString);
364 m_aValue.m_pString = _rRH.m_aValue.m_pString;
365 break;
366 case DataType::DATE:
367 m_aValue.m_pValue = new Date(*(Date*)_rRH.m_aValue.m_pValue);
368 TRACE_ALLOC( Date )
369 break;
370 case DataType::TIME:
371 m_aValue.m_pValue = new Time(*(Time*)_rRH.m_aValue.m_pValue);
372 TRACE_ALLOC( Time )
373 break;
374 case DataType::TIMESTAMP:
375 m_aValue.m_pValue = new DateTime(*(DateTime*)_rRH.m_aValue.m_pValue);
376 TRACE_ALLOC( DateTime )
377 break;
378 case DataType::BINARY:
379 case DataType::VARBINARY:
380 case DataType::LONGVARBINARY:
381 m_aValue.m_pValue = new Sequence<sal_Int8>(*(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue);
382 TRACE_ALLOC( Sequence_sal_Int8 )
383 break;
384 case DataType::BIT:
385 case DataType::BOOLEAN:
386 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
387 break;
388 case DataType::TINYINT:
389 if ( _rRH.m_bSigned )
390 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
391 else
392 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
393 break;
394 case DataType::SMALLINT:
395 if ( _rRH.m_bSigned )
396 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
397 else
398 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
399 break;
400 case DataType::INTEGER:
401 if ( _rRH.m_bSigned )
402 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
403 else
404 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
405 break;
406 case DataType::BIGINT:
407 if ( _rRH.m_bSigned )
408 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
409 else
410 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
411 break;
412 case DataType::FLOAT:
413 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
414 break;
415 case DataType::DOUBLE:
416 case DataType::REAL:
417 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
418 break;
419 default:
420 m_aValue.m_pValue = new Any(*(Any*)_rRH.m_aValue.m_pValue);
421 TRACE_ALLOC( Any )
424 else if(!_rRH.m_bNull)
426 switch(_rRH.m_eTypeKind)
428 case DataType::CHAR:
429 case DataType::VARCHAR:
430 case DataType::DECIMAL:
431 case DataType::NUMERIC:
432 case DataType::LONGVARCHAR:
433 (*this) = OUString(_rRH.m_aValue.m_pString);
434 break;
435 case DataType::DATE:
436 (*this) = *(Date*)_rRH.m_aValue.m_pValue;
437 break;
438 case DataType::TIME:
439 (*this) = *(Time*)_rRH.m_aValue.m_pValue;
440 break;
441 case DataType::TIMESTAMP:
442 (*this) = *(DateTime*)_rRH.m_aValue.m_pValue;
443 break;
444 case DataType::BINARY:
445 case DataType::VARBINARY:
446 case DataType::LONGVARBINARY:
447 (*this) = *(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue;
448 break;
449 case DataType::BIT:
450 case DataType::BOOLEAN:
451 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
452 break;
453 case DataType::TINYINT:
454 if ( _rRH.m_bSigned )
455 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
456 else
457 m_aValue.m_uInt8 = _rRH.m_aValue.m_uInt8;
458 break;
459 case DataType::SMALLINT:
460 if ( _rRH.m_bSigned )
461 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
462 else
463 m_aValue.m_uInt16 = _rRH.m_aValue.m_uInt16;
464 break;
465 case DataType::INTEGER:
466 if ( _rRH.m_bSigned )
467 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
468 else
469 m_aValue.m_uInt32 = _rRH.m_aValue.m_uInt32;
470 break;
471 case DataType::BIGINT:
472 if ( _rRH.m_bSigned )
473 m_aValue.m_nInt64 = _rRH.m_aValue.m_nInt64;
474 else
475 m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
476 break;
477 case DataType::FLOAT:
478 m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
479 break;
480 case DataType::DOUBLE:
481 case DataType::REAL:
482 m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
483 break;
484 default:
485 (*(Any*)m_aValue.m_pValue) = (*(Any*)_rRH.m_aValue.m_pValue);
489 m_bNull = _rRH.m_bNull;
490 // OJ: BUGID: 96277
491 m_eTypeKind = _rRH.m_eTypeKind;
493 return *this;
497 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
499 if(m_eTypeKind != DataType::DATE)
500 free();
502 if(m_bNull)
504 m_aValue.m_pValue = new Date(_rRH);
505 TRACE_ALLOC( Date )
506 m_eTypeKind = DataType::DATE;
507 m_bNull = false;
509 else
510 *(Date*)m_aValue.m_pValue = _rRH;
512 return *this;
515 ORowSetValue& ORowSetValue::operator=(const Time& _rRH)
517 if(m_eTypeKind != DataType::TIME)
518 free();
520 if(m_bNull)
522 m_aValue.m_pValue = new Time(_rRH);
523 TRACE_ALLOC( Time )
524 m_eTypeKind = DataType::TIME;
525 m_bNull = false;
527 else
528 *(Time*)m_aValue.m_pValue = _rRH;
530 return *this;
533 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
535 if(m_eTypeKind != DataType::TIMESTAMP)
536 free();
537 if(m_bNull)
539 m_aValue.m_pValue = new DateTime(_rRH);
540 TRACE_ALLOC( DateTime )
541 m_eTypeKind = DataType::TIMESTAMP;
542 m_bNull = false;
544 else
545 *(DateTime*)m_aValue.m_pValue = _rRH;
547 return *this;
551 ORowSetValue& ORowSetValue::operator=(const OUString& _rRH)
553 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
555 free();
556 m_bNull = false;
558 m_aValue.m_pString = _rRH.pData;
559 rtl_uString_acquire(m_aValue.m_pString);
560 m_eTypeKind = DataType::VARCHAR;
563 return *this;
567 ORowSetValue& ORowSetValue::operator=(const double& _rRH)
569 if(m_eTypeKind != DataType::DOUBLE)
570 free();
572 m_aValue.m_nDouble = _rRH;
573 m_eTypeKind = DataType::DOUBLE;
574 m_bNull = false;
576 return *this;
579 ORowSetValue& ORowSetValue::operator=(const float& _rRH)
581 if(m_eTypeKind != DataType::FLOAT)
582 free();
584 m_aValue.m_nFloat = _rRH;
585 m_eTypeKind = DataType::FLOAT;
586 m_bNull = false;
588 return *this;
592 ORowSetValue& ORowSetValue::operator=(const sal_Int8& _rRH)
594 if(m_eTypeKind != DataType::TINYINT )
595 free();
597 m_aValue.m_nInt8 = _rRH;
598 m_eTypeKind = DataType::TINYINT;
599 m_bNull = false;
600 m_bSigned = true;
601 return *this;
605 ORowSetValue& ORowSetValue::operator=(const sal_uInt8& _rRH)
607 if(m_eTypeKind != DataType::TINYINT )
608 free();
610 m_aValue.m_uInt8 = _rRH;
611 m_eTypeKind = DataType::TINYINT;
612 m_bNull = false;
613 m_bSigned = false;
614 return *this;
618 ORowSetValue& ORowSetValue::operator=(const sal_Int16& _rRH)
620 if(m_eTypeKind != DataType::SMALLINT )
621 free();
623 m_aValue.m_nInt16 = _rRH;
624 m_eTypeKind = DataType::SMALLINT;
625 m_bNull = false;
626 m_bSigned = true;
628 return *this;
632 ORowSetValue& ORowSetValue::operator=(const sal_uInt16& _rRH)
634 if(m_eTypeKind != DataType::SMALLINT )
635 free();
637 m_aValue.m_uInt16 = _rRH;
638 m_eTypeKind = DataType::SMALLINT;
639 m_bNull = false;
640 m_bSigned = false;
642 return *this;
646 ORowSetValue& ORowSetValue::operator=(const sal_Int32& _rRH)
648 if(m_eTypeKind != DataType::INTEGER )
649 free();
651 m_aValue.m_nInt32 = _rRH;
653 m_eTypeKind = DataType::INTEGER;
654 m_bNull = false;
655 m_bSigned = true;
657 return *this;
661 ORowSetValue& ORowSetValue::operator=(const sal_uInt32& _rRH)
663 if(m_eTypeKind != DataType::INTEGER )
664 free();
666 m_aValue.m_uInt32 = _rRH;
668 m_eTypeKind = DataType::INTEGER;
669 m_bNull = false;
670 m_bSigned = false;
672 return *this;
676 ORowSetValue& ORowSetValue::operator=(const bool _rRH)
678 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
679 free();
681 m_aValue.m_bBool = _rRH;
682 m_eTypeKind = DataType::BOOLEAN;
683 m_bNull = false;
685 return *this;
688 ORowSetValue& ORowSetValue::operator=(const sal_Int64& _rRH)
690 if ( DataType::BIGINT != m_eTypeKind)
691 free();
693 m_aValue.m_nInt64 = _rRH;
694 m_eTypeKind = DataType::BIGINT;
695 m_bNull = false;
696 m_bSigned = true;
698 return *this;
701 ORowSetValue& ORowSetValue::operator=(const sal_uInt64& _rRH)
703 if ( DataType::BIGINT != m_eTypeKind)
704 free();
706 m_aValue.m_uInt64 = _rRH;
707 m_eTypeKind = DataType::BIGINT;
708 m_bNull = false;
709 m_bSigned = false;
711 return *this;
714 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
716 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
717 free();
719 if (m_bNull)
721 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
722 TRACE_ALLOC( Sequence_sal_Int8 )
724 else
725 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
727 m_eTypeKind = DataType::LONGVARBINARY;
728 m_bNull = false;
730 return *this;
733 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
735 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
736 free();
738 if ( m_bNull )
740 m_aValue.m_pValue = new Any(_rAny);
741 TRACE_ALLOC( Any )
743 else
744 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
746 m_eTypeKind = DataType::OBJECT;
747 m_bNull = false;
749 return *this;
753 bool operator==(const Date& _rLH,const Date& _rRH)
755 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year;
759 bool operator==(const Time& _rLH,const Time& _rRH)
761 return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds;
765 bool operator==(const DateTime& _rLH,const DateTime& _rRH)
767 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year &&
768 _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds;
772 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
774 if ( m_bNull != _rRH.isNull() )
775 return false;
777 if(m_bNull && _rRH.isNull())
778 return true;
780 if ( m_eTypeKind != _rRH.m_eTypeKind )
782 switch(m_eTypeKind)
784 case DataType::FLOAT:
785 case DataType::DOUBLE:
786 case DataType::REAL:
787 return getDouble() == _rRH.getDouble();
788 default:
789 switch(_rRH.m_eTypeKind)
791 case DataType::FLOAT:
792 case DataType::DOUBLE:
793 case DataType::REAL:
794 return getDouble() == _rRH.getDouble();
795 default:
796 break;
798 break;
800 return false;
803 bool bRet = false;
804 OSL_ENSURE(!m_bNull,"SHould not be null!");
805 switch(m_eTypeKind)
807 case DataType::VARCHAR:
808 case DataType::CHAR:
809 case DataType::LONGVARCHAR:
811 OUString aVal1(m_aValue.m_pString);
812 OUString aVal2(_rRH.m_aValue.m_pString);
813 return aVal1 == aVal2;
815 default:
816 if ( m_bSigned != _rRH.m_bSigned )
817 return false;
818 break;
821 switch(m_eTypeKind)
823 case DataType::DECIMAL:
824 case DataType::NUMERIC:
826 OUString aVal1(m_aValue.m_pString);
827 OUString aVal2(_rRH.m_aValue.m_pString);
828 bRet = aVal1 == aVal2;
830 break;
831 case DataType::FLOAT:
832 bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
833 break;
834 case DataType::DOUBLE:
835 case DataType::REAL:
836 bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
837 break;
838 case DataType::TINYINT:
839 bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
840 break;
841 case DataType::SMALLINT:
842 bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_uInt16 == _rRH.m_aValue.m_uInt16);
843 break;
844 case DataType::INTEGER:
845 bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (m_aValue.m_uInt32 == _rRH.m_aValue.m_uInt32);
846 break;
847 case DataType::BIGINT:
848 bRet = m_bSigned ? ( m_aValue.m_nInt64 == _rRH.m_aValue.m_nInt64 ) : (m_aValue.m_uInt64 == _rRH.m_aValue.m_uInt64);
849 break;
850 case DataType::BIT:
851 case DataType::BOOLEAN:
852 bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
853 break;
854 case DataType::DATE:
855 bRet = *(Date*)m_aValue.m_pValue == *(Date*)_rRH.m_aValue.m_pValue;
856 break;
857 case DataType::TIME:
858 bRet = *(Time*)m_aValue.m_pValue == *(Time*)_rRH.m_aValue.m_pValue;
859 break;
860 case DataType::TIMESTAMP:
861 bRet = *(DateTime*)m_aValue.m_pValue == *(DateTime*)_rRH.m_aValue.m_pValue;
862 break;
863 case DataType::BINARY:
864 case DataType::VARBINARY:
865 case DataType::LONGVARBINARY:
866 bRet = false;
867 break;
868 case DataType::BLOB:
869 case DataType::CLOB:
870 case DataType::OBJECT:
871 case DataType::OTHER:
872 bRet = false;
873 break;
874 default:
875 bRet = false;
876 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
877 break;
879 return bRet;
882 Any ORowSetValue::makeAny() const
884 Any rValue;
885 if(isBound() && !isNull())
887 switch(getTypeKind())
889 case DataType::CHAR:
890 case DataType::VARCHAR:
891 case DataType::DECIMAL:
892 case DataType::NUMERIC:
893 case DataType::LONGVARCHAR:
894 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
895 rValue <<= (OUString)m_aValue.m_pString;
896 break;
897 case DataType::FLOAT:
898 rValue <<= m_aValue.m_nFloat;
899 break;
900 case DataType::DOUBLE:
901 case DataType::REAL:
902 rValue <<= m_aValue.m_nDouble;
903 break;
904 case DataType::DATE:
905 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
906 rValue <<= *(Date*)m_aValue.m_pValue;
907 break;
908 case DataType::TIME:
909 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
910 rValue <<= *(Time*)m_aValue.m_pValue;
911 break;
912 case DataType::TIMESTAMP:
913 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
914 rValue <<= *(DateTime*)m_aValue.m_pValue;
915 break;
916 case DataType::BINARY:
917 case DataType::VARBINARY:
918 case DataType::LONGVARBINARY:
919 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
920 rValue <<= *(Sequence<sal_Int8>*)m_aValue.m_pValue;
921 break;
922 case DataType::BLOB:
923 case DataType::CLOB:
924 case DataType::OBJECT:
925 case DataType::OTHER:
926 rValue = getAny();
927 break;
928 case DataType::BIT:
929 case DataType::BOOLEAN:
930 rValue <<= m_aValue.m_bBool;
931 break;
932 case DataType::TINYINT:
933 if ( m_bSigned )
934 // TypeClass_BYTE
935 rValue <<= m_aValue.m_nInt8;
936 else
937 // There is no TypeClass_UNSIGNED_BYTE,
938 // so silently promote it to a 16-bit integer,
939 // that is TypeClass_UNSIGNED_SHORT
940 rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
941 break;
942 case DataType::SMALLINT:
943 if ( m_bSigned )
944 // TypeClass_SHORT
945 rValue <<= m_aValue.m_nInt16;
946 else
947 // TypeClass_UNSIGNED_SHORT
948 rValue <<= m_aValue.m_uInt16;
949 break;
950 case DataType::INTEGER:
951 if ( m_bSigned )
952 // TypeClass_LONG
953 rValue <<= m_aValue.m_nInt32;
954 else
955 // TypeClass_UNSIGNED_LONG
956 rValue <<= m_aValue.m_uInt32;
957 break;
958 case DataType::BIGINT:
959 if ( m_bSigned )
960 // TypeClass_HYPER
961 rValue <<= m_aValue.m_nInt64;
962 else
963 // TypeClass_UNSIGNED_HYPER
964 rValue <<= m_aValue.m_uInt64;
965 break;
966 default:
967 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSPUPPORTED TYPE!");
968 rValue = getAny();
969 break;
972 return rValue;
975 OUString ORowSetValue::getString( ) const
977 OUString aRet;
978 if(!m_bNull)
980 switch(getTypeKind())
982 case DataType::CHAR:
983 case DataType::VARCHAR:
984 case DataType::DECIMAL:
985 case DataType::NUMERIC:
986 case DataType::LONGVARCHAR:
987 aRet = m_aValue.m_pString;
988 break;
989 case DataType::FLOAT:
990 aRet = OUString::number(static_cast<float>(*this));
991 break;
992 case DataType::DOUBLE:
993 case DataType::REAL:
994 aRet = OUString::number(static_cast<double>(*this));
995 break;
996 case DataType::DATE:
997 aRet = DBTypeConversion::toDateString(*this);
998 break;
999 case DataType::TIME:
1000 aRet = DBTypeConversion::toTimeString(*this);
1001 break;
1002 case DataType::TIMESTAMP:
1003 aRet = DBTypeConversion::toDateTimeString(*this);
1004 break;
1005 case DataType::BINARY:
1006 case DataType::VARBINARY:
1007 case DataType::LONGVARBINARY:
1009 OUStringBuffer sVal("0x");
1010 Sequence<sal_Int8> aSeq(getSequence());
1011 const sal_Int8* pBegin = aSeq.getConstArray();
1012 const sal_Int8* pEnd = pBegin + aSeq.getLength();
1013 for(;pBegin != pEnd;++pBegin)
1014 sVal.append((sal_Int32)*pBegin,16);
1015 aRet = sVal.makeStringAndClear();
1017 break;
1018 case DataType::BIT:
1019 aRet = OUString::number(int(static_cast<bool>(*this)));
1020 break;
1021 case DataType::BOOLEAN:
1022 aRet = OUString::boolean(static_cast<bool>(*this));
1023 break;
1024 case DataType::TINYINT:
1025 case DataType::SMALLINT:
1026 case DataType::INTEGER:
1027 if ( m_bSigned )
1028 aRet = OUString::number(static_cast<sal_Int32>(*this));
1029 else
1030 aRet = OUString::number(static_cast<sal_uInt32>(*this));
1031 break;
1032 case DataType::BIGINT:
1033 if ( m_bSigned )
1034 aRet = OUString::number(static_cast<sal_Int64>(*this));
1035 else
1036 aRet = OUString::number(static_cast<sal_uInt64>(*this));
1037 break;
1038 case DataType::CLOB:
1040 Any aValue( getAny() );
1041 Reference< XClob > xClob;
1042 if ( aValue >>= xClob )
1044 if ( xClob.is() )
1046 aRet = xClob->getSubString(1,(sal_Int32)xClob->length() );
1050 break;
1051 default:
1053 Any aValue = getAny();
1054 aValue >>= aRet;
1055 break;
1059 return aRet;
1062 bool ORowSetValue::getBool() const
1064 bool bRet = false;
1065 if(!m_bNull)
1067 switch(getTypeKind())
1069 case DataType::CHAR:
1070 case DataType::VARCHAR:
1071 case DataType::LONGVARCHAR:
1073 const OUString sValue(m_aValue.m_pString);
1074 if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1076 bRet = true;
1077 break;
1079 else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1081 bRet = false;
1082 break;
1085 // run through
1086 case DataType::DECIMAL:
1087 case DataType::NUMERIC:
1089 bRet = OUString(m_aValue.m_pString).toInt32() != 0;
1090 break;
1091 case DataType::FLOAT:
1092 bRet = m_aValue.m_nFloat != 0.0;
1093 break;
1094 case DataType::DOUBLE:
1095 case DataType::REAL:
1096 bRet = m_aValue.m_nDouble != 0.0;
1097 break;
1098 case DataType::DATE:
1099 case DataType::TIME:
1100 case DataType::TIMESTAMP:
1101 case DataType::BINARY:
1102 case DataType::VARBINARY:
1103 case DataType::LONGVARBINARY:
1104 OSL_FAIL("getBool() for this type is not allowed!");
1105 break;
1106 case DataType::BIT:
1107 case DataType::BOOLEAN:
1108 bRet = m_aValue.m_bBool;
1109 break;
1110 case DataType::TINYINT:
1111 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_uInt8 != 0);
1112 break;
1113 case DataType::SMALLINT:
1114 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_uInt16 != 0);
1115 break;
1116 case DataType::INTEGER:
1117 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1118 break;
1119 case DataType::BIGINT:
1120 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1121 break;
1122 default:
1124 Any aValue = getAny();
1125 aValue >>= bRet;
1126 break;
1130 return bRet;
1134 sal_Int8 ORowSetValue::getInt8() const
1136 sal_Int8 nRet = 0;
1137 if(!m_bNull)
1139 switch(getTypeKind())
1141 case DataType::CHAR:
1142 case DataType::VARCHAR:
1143 case DataType::DECIMAL:
1144 case DataType::NUMERIC:
1145 case DataType::LONGVARCHAR:
1146 nRet = sal_Int8(OUString(m_aValue.m_pString).toInt32());
1147 break;
1148 case DataType::FLOAT:
1149 nRet = sal_Int8(m_aValue.m_nFloat);
1150 break;
1151 case DataType::DOUBLE:
1152 case DataType::REAL:
1153 nRet = sal_Int8(m_aValue.m_nDouble);
1154 break;
1155 case DataType::DATE:
1156 case DataType::TIME:
1157 case DataType::TIMESTAMP:
1158 case DataType::BINARY:
1159 case DataType::VARBINARY:
1160 case DataType::LONGVARBINARY:
1161 case DataType::BLOB:
1162 case DataType::CLOB:
1163 OSL_FAIL("getInt8() for this type is not allowed!");
1164 break;
1165 case DataType::BIT:
1166 case DataType::BOOLEAN:
1167 nRet = sal_Int8(m_aValue.m_bBool);
1168 break;
1169 case DataType::TINYINT:
1170 if ( m_bSigned )
1171 nRet = m_aValue.m_nInt8;
1172 else
1173 nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1174 break;
1175 case DataType::SMALLINT:
1176 if ( m_bSigned )
1177 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1178 else
1179 nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1180 break;
1181 case DataType::INTEGER:
1182 if ( m_bSigned )
1183 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1184 else
1185 nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1186 break;
1187 case DataType::BIGINT:
1188 if ( m_bSigned )
1189 nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1190 else
1191 nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1192 break;
1193 default:
1195 Any aValue = getAny();
1196 aValue >>= nRet;
1197 break;
1201 return nRet;
1205 sal_uInt8 ORowSetValue::getUInt8() const
1207 sal_uInt8 nRet = 0;
1208 if(!m_bNull)
1210 switch(getTypeKind())
1212 case DataType::CHAR:
1213 case DataType::VARCHAR:
1214 case DataType::DECIMAL:
1215 case DataType::NUMERIC:
1216 case DataType::LONGVARCHAR:
1217 nRet = sal_uInt8(OUString(m_aValue.m_pString).toInt32());
1218 break;
1219 case DataType::FLOAT:
1220 nRet = sal_uInt8(m_aValue.m_nFloat);
1221 break;
1222 case DataType::DOUBLE:
1223 case DataType::REAL:
1224 nRet = sal_uInt8(m_aValue.m_nDouble);
1225 break;
1226 case DataType::DATE:
1227 case DataType::TIME:
1228 case DataType::TIMESTAMP:
1229 case DataType::BINARY:
1230 case DataType::VARBINARY:
1231 case DataType::LONGVARBINARY:
1232 case DataType::BLOB:
1233 case DataType::CLOB:
1234 OSL_FAIL("getuInt8() for this type is not allowed!");
1235 break;
1236 case DataType::BIT:
1237 case DataType::BOOLEAN:
1238 nRet = m_aValue.m_bBool;
1239 break;
1240 case DataType::TINYINT:
1241 if ( m_bSigned )
1242 nRet = m_aValue.m_nInt8;
1243 else
1244 nRet = m_aValue.m_uInt8;
1245 break;
1246 case DataType::SMALLINT:
1247 if ( m_bSigned )
1248 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1249 else
1250 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1251 break;
1252 case DataType::INTEGER:
1253 if ( m_bSigned )
1254 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1255 else
1256 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1257 break;
1258 case DataType::BIGINT:
1259 if ( m_bSigned )
1260 nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1261 else
1262 nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1263 break;
1264 default:
1266 Any aValue = getAny();
1267 aValue >>= nRet;
1268 break;
1272 return nRet;
1277 sal_Int16 ORowSetValue::getInt16() const
1279 sal_Int16 nRet = 0;
1280 if(!m_bNull)
1282 switch(getTypeKind())
1284 case DataType::CHAR:
1285 case DataType::VARCHAR:
1286 case DataType::DECIMAL:
1287 case DataType::NUMERIC:
1288 case DataType::LONGVARCHAR:
1289 nRet = sal_Int16(OUString(m_aValue.m_pString).toInt32());
1290 break;
1291 case DataType::FLOAT:
1292 nRet = sal_Int16(m_aValue.m_nFloat);
1293 break;
1294 case DataType::DOUBLE:
1295 case DataType::REAL:
1296 nRet = sal_Int16(m_aValue.m_nDouble);
1297 break;
1298 case DataType::DATE:
1299 case DataType::TIME:
1300 case DataType::TIMESTAMP:
1301 case DataType::BINARY:
1302 case DataType::VARBINARY:
1303 case DataType::LONGVARBINARY:
1304 case DataType::BLOB:
1305 case DataType::CLOB:
1306 OSL_FAIL("getInt16() for this type is not allowed!");
1307 break;
1308 case DataType::BIT:
1309 case DataType::BOOLEAN:
1310 nRet = sal_Int16(m_aValue.m_bBool);
1311 break;
1312 case DataType::TINYINT:
1313 if ( m_bSigned )
1314 nRet = m_aValue.m_nInt8;
1315 else
1316 nRet = m_aValue.m_uInt8;
1317 break;
1318 case DataType::SMALLINT:
1319 if ( m_bSigned )
1320 nRet = m_aValue.m_nInt16;
1321 else
1322 nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1323 break;
1324 case DataType::INTEGER:
1325 if ( m_bSigned )
1326 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1327 else
1328 nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1329 break;
1330 case DataType::BIGINT:
1331 if ( m_bSigned )
1332 nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1333 else
1334 nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1335 break;
1336 default:
1338 Any aValue = getAny();
1339 aValue >>= nRet;
1340 break;
1344 return nRet;
1348 sal_uInt16 ORowSetValue::getUInt16() const
1350 sal_uInt16 nRet = 0;
1351 if(!m_bNull)
1353 switch(getTypeKind())
1355 case DataType::CHAR:
1356 case DataType::VARCHAR:
1357 case DataType::DECIMAL:
1358 case DataType::NUMERIC:
1359 case DataType::LONGVARCHAR:
1360 nRet = sal_uInt16(OUString(m_aValue.m_pString).toInt32());
1361 break;
1362 case DataType::FLOAT:
1363 nRet = sal_uInt16(m_aValue.m_nFloat);
1364 break;
1365 case DataType::DOUBLE:
1366 case DataType::REAL:
1367 nRet = sal_uInt16(m_aValue.m_nDouble);
1368 break;
1369 case DataType::DATE:
1370 case DataType::TIME:
1371 case DataType::TIMESTAMP:
1372 case DataType::BINARY:
1373 case DataType::VARBINARY:
1374 case DataType::LONGVARBINARY:
1375 case DataType::BLOB:
1376 case DataType::CLOB:
1377 OSL_FAIL("getuInt16() for this type is not allowed!");
1378 break;
1379 case DataType::BIT:
1380 case DataType::BOOLEAN:
1381 nRet = sal_uInt16(m_aValue.m_bBool);
1382 break;
1383 case DataType::TINYINT:
1384 if ( m_bSigned )
1385 nRet = m_aValue.m_nInt8;
1386 else
1387 nRet = m_aValue.m_uInt8;
1388 break;
1389 case DataType::SMALLINT:
1390 if ( m_bSigned )
1391 nRet = m_aValue.m_nInt16;
1392 else
1393 nRet = m_aValue.m_uInt16;
1394 break;
1395 case DataType::INTEGER:
1396 if ( m_bSigned )
1397 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1398 else
1399 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1400 break;
1401 case DataType::BIGINT:
1402 if ( m_bSigned )
1403 nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1404 else
1405 nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1406 break;
1407 default:
1409 Any aValue = getAny();
1410 aValue >>= nRet;
1411 break;
1415 return nRet;
1419 sal_Int32 ORowSetValue::getInt32() const
1421 sal_Int32 nRet = 0;
1422 if(!m_bNull)
1424 switch(getTypeKind())
1426 case DataType::CHAR:
1427 case DataType::VARCHAR:
1428 case DataType::DECIMAL:
1429 case DataType::NUMERIC:
1430 case DataType::LONGVARCHAR:
1431 nRet = OUString(m_aValue.m_pString).toInt32();
1432 break;
1433 case DataType::FLOAT:
1434 nRet = sal_Int32(m_aValue.m_nFloat);
1435 break;
1436 case DataType::DOUBLE:
1437 case DataType::REAL:
1438 nRet = sal_Int32(m_aValue.m_nDouble);
1439 break;
1440 case DataType::DATE:
1441 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1442 break;
1443 case DataType::TIME:
1444 case DataType::TIMESTAMP:
1445 case DataType::BINARY:
1446 case DataType::VARBINARY:
1447 case DataType::LONGVARBINARY:
1448 case DataType::BLOB:
1449 case DataType::CLOB:
1450 OSL_FAIL("getInt32() for this type is not allowed!");
1451 break;
1452 case DataType::BIT:
1453 case DataType::BOOLEAN:
1454 nRet = sal_Int32(m_aValue.m_bBool);
1455 break;
1456 case DataType::TINYINT:
1457 if ( m_bSigned )
1458 nRet = m_aValue.m_nInt8;
1459 else
1460 nRet = m_aValue.m_uInt8;
1461 break;
1462 case DataType::SMALLINT:
1463 if ( m_bSigned )
1464 nRet = m_aValue.m_nInt16;
1465 else
1466 nRet = m_aValue.m_uInt16;
1467 break;
1468 case DataType::INTEGER:
1469 if ( m_bSigned )
1470 nRet = m_aValue.m_nInt32;
1471 else
1472 nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1473 break;
1474 case DataType::BIGINT:
1475 if ( m_bSigned )
1476 nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1477 else
1478 nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1479 break;
1480 default:
1482 Any aValue = getAny();
1483 aValue >>= nRet;
1484 break;
1488 return nRet;
1492 sal_uInt32 ORowSetValue::getUInt32() const
1494 sal_uInt32 nRet = 0;
1495 if(!m_bNull)
1497 switch(getTypeKind())
1499 case DataType::CHAR:
1500 case DataType::VARCHAR:
1501 case DataType::DECIMAL:
1502 case DataType::NUMERIC:
1503 case DataType::LONGVARCHAR:
1504 nRet = OUString(m_aValue.m_pString).toUInt32();
1505 break;
1506 case DataType::FLOAT:
1507 nRet = sal_uInt32(m_aValue.m_nFloat);
1508 break;
1509 case DataType::DOUBLE:
1510 case DataType::REAL:
1511 nRet = sal_uInt32(m_aValue.m_nDouble);
1512 break;
1513 case DataType::DATE:
1514 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1515 break;
1516 case DataType::TIME:
1517 case DataType::TIMESTAMP:
1518 case DataType::BINARY:
1519 case DataType::VARBINARY:
1520 case DataType::LONGVARBINARY:
1521 case DataType::BLOB:
1522 case DataType::CLOB:
1523 OSL_FAIL("getuInt32() for this type is not allowed!");
1524 break;
1525 case DataType::BIT:
1526 case DataType::BOOLEAN:
1527 nRet = sal_uInt32(m_aValue.m_bBool);
1528 break;
1529 case DataType::TINYINT:
1530 if ( m_bSigned )
1531 nRet = m_aValue.m_nInt8;
1532 else
1533 nRet = m_aValue.m_uInt8;
1534 break;
1535 case DataType::SMALLINT:
1536 if ( m_bSigned )
1537 nRet = m_aValue.m_nInt16;
1538 else
1539 nRet = m_aValue.m_uInt16;
1540 break;
1541 case DataType::INTEGER:
1542 if ( m_bSigned )
1543 nRet = m_aValue.m_nInt32;
1544 else
1545 nRet = m_aValue.m_uInt32;
1546 break;
1547 case DataType::BIGINT:
1548 if ( m_bSigned )
1549 nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1550 else
1551 nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1552 break;
1553 default:
1555 Any aValue = getAny();
1556 aValue >>= nRet;
1557 break;
1561 return nRet;
1565 sal_Int64 ORowSetValue::getLong() const
1567 sal_Int64 nRet = 0;
1568 if(!m_bNull)
1570 switch(getTypeKind())
1572 case DataType::CHAR:
1573 case DataType::VARCHAR:
1574 case DataType::DECIMAL:
1575 case DataType::NUMERIC:
1576 case DataType::LONGVARCHAR:
1577 nRet = OUString(m_aValue.m_pString).toInt64();
1578 break;
1579 case DataType::FLOAT:
1580 nRet = sal_Int64(m_aValue.m_nFloat);
1581 break;
1582 case DataType::DOUBLE:
1583 case DataType::REAL:
1584 nRet = sal_Int64(m_aValue.m_nDouble);
1585 break;
1586 case DataType::DATE:
1587 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1588 break;
1589 case DataType::TIME:
1590 case DataType::TIMESTAMP:
1591 case DataType::BINARY:
1592 case DataType::VARBINARY:
1593 case DataType::LONGVARBINARY:
1594 case DataType::BLOB:
1595 case DataType::CLOB:
1596 OSL_FAIL("getLong() for this type is not allowed!");
1597 break;
1598 case DataType::BIT:
1599 case DataType::BOOLEAN:
1600 nRet = sal_Int64(m_aValue.m_bBool);
1601 break;
1602 case DataType::TINYINT:
1603 if ( m_bSigned )
1604 nRet = m_aValue.m_nInt8;
1605 else
1606 nRet = m_aValue.m_uInt8;
1607 break;
1608 case DataType::SMALLINT:
1609 if ( m_bSigned )
1610 nRet = m_aValue.m_nInt16;
1611 else
1612 nRet = m_aValue.m_uInt16;
1613 break;
1614 case DataType::INTEGER:
1615 if ( m_bSigned )
1616 nRet = m_aValue.m_nInt32;
1617 else
1618 nRet = m_aValue.m_uInt32;
1619 break;
1620 case DataType::BIGINT:
1621 if ( m_bSigned )
1622 nRet = m_aValue.m_nInt64;
1623 else
1624 nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1625 break;
1626 default:
1628 Any aValue = getAny();
1629 aValue >>= nRet;
1630 break;
1634 return nRet;
1638 sal_uInt64 ORowSetValue::getULong() const
1640 sal_uInt64 nRet = 0;
1641 if(!m_bNull)
1643 switch(getTypeKind())
1645 case DataType::CHAR:
1646 case DataType::VARCHAR:
1647 case DataType::DECIMAL:
1648 case DataType::NUMERIC:
1649 case DataType::LONGVARCHAR:
1650 nRet = static_cast<sal_uInt64>(OUString(m_aValue.m_pString).toUInt64());
1651 break;
1652 case DataType::FLOAT:
1653 nRet = sal_uInt64(m_aValue.m_nFloat);
1654 break;
1655 case DataType::DOUBLE:
1656 case DataType::REAL:
1657 nRet = sal_uInt64(m_aValue.m_nDouble);
1658 break;
1659 case DataType::DATE:
1660 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1661 break;
1662 case DataType::TIME:
1663 case DataType::TIMESTAMP:
1664 case DataType::BINARY:
1665 case DataType::VARBINARY:
1666 case DataType::LONGVARBINARY:
1667 case DataType::BLOB:
1668 case DataType::CLOB:
1669 OSL_FAIL("getULong() for this type is not allowed!");
1670 break;
1671 case DataType::BIT:
1672 case DataType::BOOLEAN:
1673 nRet = sal_uInt64(m_aValue.m_bBool);
1674 break;
1675 case DataType::TINYINT:
1676 if ( m_bSigned )
1677 nRet = m_aValue.m_nInt8;
1678 else
1679 nRet = m_aValue.m_uInt8;
1680 break;
1681 case DataType::SMALLINT:
1682 if ( m_bSigned )
1683 nRet = m_aValue.m_nInt16;
1684 else
1685 nRet = m_aValue.m_uInt16;
1686 break;
1687 case DataType::INTEGER:
1688 if ( m_bSigned )
1689 nRet = m_aValue.m_nInt32;
1690 else
1691 nRet = m_aValue.m_uInt32;
1692 break;
1693 case DataType::BIGINT:
1694 if ( m_bSigned )
1695 nRet = m_aValue.m_nInt64;
1696 else
1697 nRet = m_aValue.m_uInt64;
1698 break;
1699 default:
1701 Any aValue = getAny();
1702 aValue >>= nRet;
1703 break;
1707 return nRet;
1711 float ORowSetValue::getFloat() const
1713 float nRet = 0;
1714 if(!m_bNull)
1716 switch(getTypeKind())
1718 case DataType::CHAR:
1719 case DataType::VARCHAR:
1720 case DataType::DECIMAL:
1721 case DataType::NUMERIC:
1722 case DataType::LONGVARCHAR:
1723 nRet = OUString(m_aValue.m_pString).toFloat();
1724 break;
1725 case DataType::FLOAT:
1726 nRet = m_aValue.m_nFloat;
1727 break;
1728 case DataType::DOUBLE:
1729 case DataType::REAL:
1730 nRet = (float)m_aValue.m_nDouble;
1731 break;
1732 case DataType::DATE:
1733 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1734 break;
1735 case DataType::TIME:
1736 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1737 break;
1738 case DataType::TIMESTAMP:
1739 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1740 break;
1741 case DataType::BINARY:
1742 case DataType::VARBINARY:
1743 case DataType::LONGVARBINARY:
1744 case DataType::BLOB:
1745 case DataType::CLOB:
1746 OSL_FAIL("getDouble() for this type is not allowed!");
1747 break;
1748 case DataType::BIT:
1749 case DataType::BOOLEAN:
1750 nRet = float(m_aValue.m_bBool);
1751 break;
1752 case DataType::TINYINT:
1753 if ( m_bSigned )
1754 nRet = m_aValue.m_nInt8;
1755 else
1756 nRet = m_aValue.m_uInt8;
1757 break;
1758 case DataType::SMALLINT:
1759 if ( m_bSigned )
1760 nRet = m_aValue.m_nInt16;
1761 else
1762 nRet = (float)m_aValue.m_uInt16;
1763 break;
1764 case DataType::INTEGER:
1765 if ( m_bSigned )
1766 nRet = (float)m_aValue.m_nInt32;
1767 else
1768 nRet = (float)m_aValue.m_uInt32;
1769 break;
1770 case DataType::BIGINT:
1771 if ( m_bSigned )
1772 nRet = (float)m_aValue.m_nInt64;
1773 else
1774 nRet = (float)m_aValue.m_uInt64;
1775 break;
1776 default:
1778 Any aValue = getAny();
1779 aValue >>= nRet;
1780 break;
1784 return nRet;
1787 double ORowSetValue::getDouble() const
1789 double nRet = 0;
1790 if(!m_bNull)
1792 switch(getTypeKind())
1794 case DataType::CHAR:
1795 case DataType::VARCHAR:
1796 case DataType::DECIMAL:
1797 case DataType::NUMERIC:
1798 case DataType::LONGVARCHAR:
1799 nRet = OUString(m_aValue.m_pString).toDouble();
1800 break;
1801 case DataType::FLOAT:
1802 nRet = m_aValue.m_nFloat;
1803 break;
1804 case DataType::DOUBLE:
1805 case DataType::REAL:
1806 nRet = m_aValue.m_nDouble;
1807 break;
1808 case DataType::DATE:
1809 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1810 break;
1811 case DataType::TIME:
1812 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1813 break;
1814 case DataType::TIMESTAMP:
1815 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1816 break;
1817 case DataType::BINARY:
1818 case DataType::VARBINARY:
1819 case DataType::LONGVARBINARY:
1820 case DataType::BLOB:
1821 case DataType::CLOB:
1822 OSL_FAIL("getDouble() for this type is not allowed!");
1823 break;
1824 case DataType::BIT:
1825 case DataType::BOOLEAN:
1826 nRet = double(m_aValue.m_bBool);
1827 break;
1828 case DataType::TINYINT:
1829 if ( m_bSigned )
1830 nRet = m_aValue.m_nInt8;
1831 else
1832 nRet = m_aValue.m_uInt8;
1833 break;
1834 case DataType::SMALLINT:
1835 if ( m_bSigned )
1836 nRet = m_aValue.m_nInt16;
1837 else
1838 nRet = m_aValue.m_uInt16;
1839 break;
1840 case DataType::INTEGER:
1841 if ( m_bSigned )
1842 nRet = m_aValue.m_nInt32;
1843 else
1844 nRet = m_aValue.m_uInt32;
1845 break;
1846 case DataType::BIGINT:
1847 if ( m_bSigned )
1848 nRet = m_aValue.m_nInt64;
1849 else
1850 nRet = m_aValue.m_uInt64;
1851 break;
1852 default:
1854 Any aValue = getAny();
1855 aValue >>= nRet;
1856 break;
1860 return nRet;
1863 Sequence<sal_Int8> ORowSetValue::getSequence() const
1865 Sequence<sal_Int8> aSeq;
1866 if (!m_bNull)
1868 switch(m_eTypeKind)
1870 case DataType::OBJECT:
1871 case DataType::CLOB:
1872 case DataType::BLOB:
1874 Reference<XInputStream> xStream;
1875 const Any aValue = makeAny();
1876 if(aValue.hasValue())
1878 Reference<XBlob> xBlob(aValue,UNO_QUERY);
1879 if ( xBlob.is() )
1880 xStream = xBlob->getBinaryStream();
1881 else
1883 Reference<XClob> xClob(aValue,UNO_QUERY);
1884 if ( xClob.is() )
1885 xStream = xClob->getCharacterStream();
1887 if(xStream.is())
1889 const sal_uInt32 nBytesToRead = 65535;
1890 sal_uInt32 nRead;
1894 ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
1896 nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1898 if( nRead )
1900 const sal_uInt32 nOldLength = aSeq.getLength();
1901 aSeq.realloc( nOldLength + nRead );
1902 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1905 while( nBytesToRead == nRead );
1906 xStream->closeInput();
1910 break;
1911 case DataType::VARCHAR:
1912 case DataType::LONGVARCHAR:
1914 OUString sVal(m_aValue.m_pString);
1915 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sVal.getStr()),sizeof(sal_Unicode)*sVal.getLength());
1917 break;
1918 case DataType::BINARY:
1919 case DataType::VARBINARY:
1920 case DataType::LONGVARBINARY:
1921 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1922 break;
1923 default:
1925 Any aValue = getAny();
1926 aValue >>= aSeq;
1927 break;
1931 return aSeq;
1935 ::com::sun::star::util::Date ORowSetValue::getDate() const
1937 ::com::sun::star::util::Date aValue;
1938 if(!m_bNull)
1940 switch(m_eTypeKind)
1942 case DataType::CHAR:
1943 case DataType::VARCHAR:
1944 case DataType::LONGVARCHAR:
1945 aValue = DBTypeConversion::toDate(getString());
1946 break;
1947 case DataType::DECIMAL:
1948 case DataType::NUMERIC:
1949 case DataType::FLOAT:
1950 case DataType::DOUBLE:
1951 case DataType::REAL:
1952 aValue = DBTypeConversion::toDate((double)*this);
1953 break;
1955 case DataType::DATE:
1956 aValue = *static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1957 break;
1958 case DataType::TIMESTAMP:
1960 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1961 aValue.Day = pDateTime->Day;
1962 aValue.Month = pDateTime->Month;
1963 aValue.Year = pDateTime->Year;
1965 break;
1966 case DataType::BIT:
1967 case DataType::BOOLEAN:
1968 case DataType::TINYINT:
1969 case DataType::SMALLINT:
1970 case DataType::INTEGER:
1971 case DataType::BIGINT:
1972 aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1973 break;
1975 case DataType::BLOB:
1976 case DataType::CLOB:
1977 case DataType::OBJECT:
1978 default:
1979 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1980 // NO break!
1982 case DataType::BINARY:
1983 case DataType::VARBINARY:
1984 case DataType::LONGVARBINARY:
1985 case DataType::TIME:
1986 aValue = DBTypeConversion::toDate( (double)0 );
1987 break;
1990 return aValue;
1993 ::com::sun::star::util::Time ORowSetValue::getTime() const
1995 ::com::sun::star::util::Time aValue;
1996 if(!m_bNull)
1998 switch(m_eTypeKind)
2000 case DataType::CHAR:
2001 case DataType::VARCHAR:
2002 case DataType::LONGVARCHAR:
2003 aValue = DBTypeConversion::toTime(getString());
2004 break;
2005 case DataType::DECIMAL:
2006 case DataType::NUMERIC:
2007 aValue = DBTypeConversion::toTime((double)*this);
2008 break;
2009 case DataType::FLOAT:
2010 case DataType::DOUBLE:
2011 case DataType::REAL:
2012 aValue = DBTypeConversion::toTime((double)*this);
2013 break;
2014 case DataType::TIMESTAMP:
2016 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
2017 aValue.NanoSeconds = pDateTime->NanoSeconds;
2018 aValue.Seconds = pDateTime->Seconds;
2019 aValue.Minutes = pDateTime->Minutes;
2020 aValue.Hours = pDateTime->Hours;
2022 break;
2023 case DataType::TIME:
2024 aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
2025 break;
2026 default:
2028 Any aAnyValue = getAny();
2029 aAnyValue >>= aValue;
2030 break;
2034 return aValue;
2037 ::com::sun::star::util::DateTime ORowSetValue::getDateTime() const
2039 ::com::sun::star::util::DateTime aValue;
2040 if(!m_bNull)
2042 switch(m_eTypeKind)
2044 case DataType::CHAR:
2045 case DataType::VARCHAR:
2046 case DataType::LONGVARCHAR:
2047 aValue = DBTypeConversion::toDateTime(getString());
2048 break;
2049 case DataType::DECIMAL:
2050 case DataType::NUMERIC:
2051 aValue = DBTypeConversion::toDateTime((double)*this);
2052 break;
2053 case DataType::FLOAT:
2054 case DataType::DOUBLE:
2055 case DataType::REAL:
2056 aValue = DBTypeConversion::toDateTime((double)*this);
2057 break;
2058 case DataType::DATE:
2060 ::com::sun::star::util::Date* pDate = static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
2061 aValue.Day = pDate->Day;
2062 aValue.Month = pDate->Month;
2063 aValue.Year = pDate->Year;
2065 break;
2066 case DataType::TIME:
2068 ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
2069 aValue.NanoSeconds = pTime->NanoSeconds;
2070 aValue.Seconds = pTime->Seconds;
2071 aValue.Minutes = pTime->Minutes;
2072 aValue.Hours = pTime->Hours;
2074 break;
2075 case DataType::TIMESTAMP:
2076 aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
2077 break;
2078 default:
2080 Any aAnyValue = getAny();
2081 aAnyValue >>= aValue;
2082 break;
2086 return aValue;
2089 void ORowSetValue::setSigned(bool _bMod)
2091 if ( m_bSigned != _bMod )
2093 m_bSigned = _bMod;
2094 if ( !m_bNull )
2096 sal_Int32 nType = m_eTypeKind;
2097 switch(m_eTypeKind)
2099 case DataType::TINYINT:
2100 if ( m_bSigned )
2101 (*this) = getInt8();
2102 else
2104 m_bSigned = !m_bSigned;
2105 (*this) = getInt16();
2106 m_bSigned = !m_bSigned;
2108 break;
2109 case DataType::SMALLINT:
2110 if ( m_bSigned )
2111 (*this) = getInt16();
2112 else
2114 m_bSigned = !m_bSigned;
2115 (*this) = getInt32();
2116 m_bSigned = !m_bSigned;
2118 break;
2119 case DataType::INTEGER:
2120 if ( m_bSigned )
2121 (*this) = getInt32();
2122 else
2124 m_bSigned = !m_bSigned;
2125 (*this) = getLong();
2126 m_bSigned = !m_bSigned;
2128 break;
2129 case DataType::BIGINT:
2130 if ( m_bSigned )
2131 m_aValue.m_nInt64 = static_cast<sal_Int64>(m_aValue.m_uInt64);
2132 else
2133 m_aValue.m_uInt64 = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2134 break;
2136 m_eTypeKind = nType;
2142 namespace detail
2144 class SAL_NO_VTABLE IValueSource
2146 public:
2147 virtual OUString getString() const = 0;
2148 virtual bool getBoolean() const = 0;
2149 virtual sal_Int8 getByte() const = 0;
2150 virtual sal_Int16 getShort() const = 0;
2151 virtual sal_Int32 getInt() const = 0;
2152 virtual sal_Int64 getLong() const = 0;
2153 virtual float getFloat() const = 0;
2154 virtual double getDouble() const = 0;
2155 virtual Date getDate() const = 0;
2156 virtual Time getTime() const = 0;
2157 virtual DateTime getTimestamp() const = 0;
2158 virtual Sequence< sal_Int8 > getBytes() const = 0;
2159 virtual Reference< XBlob > getBlob() const = 0;
2160 virtual Reference< XClob > getClob() const = 0;
2161 virtual Any getObject() const = 0;
2162 virtual bool wasNull() const = 0;
2164 virtual ~IValueSource() { }
2167 class RowValue : public IValueSource
2169 public:
2170 RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2171 :m_xRow( _xRow )
2172 ,m_nPos( _nPos )
2176 // IValueSource
2177 virtual OUString getString() const SAL_OVERRIDE { return m_xRow->getString( m_nPos ); };
2178 virtual bool getBoolean() const SAL_OVERRIDE { return m_xRow->getBoolean( m_nPos ); };
2179 virtual sal_Int8 getByte() const SAL_OVERRIDE { return m_xRow->getByte( m_nPos ); };
2180 virtual sal_Int16 getShort() const SAL_OVERRIDE { return m_xRow->getShort( m_nPos ); }
2181 virtual sal_Int32 getInt() const SAL_OVERRIDE { return m_xRow->getInt( m_nPos ); }
2182 virtual sal_Int64 getLong() const SAL_OVERRIDE { return m_xRow->getLong( m_nPos ); }
2183 virtual float getFloat() const SAL_OVERRIDE { return m_xRow->getFloat( m_nPos ); };
2184 virtual double getDouble() const SAL_OVERRIDE { return m_xRow->getDouble( m_nPos ); };
2185 virtual Date getDate() const SAL_OVERRIDE { return m_xRow->getDate( m_nPos ); };
2186 virtual Time getTime() const SAL_OVERRIDE { return m_xRow->getTime( m_nPos ); };
2187 virtual DateTime getTimestamp() const SAL_OVERRIDE { return m_xRow->getTimestamp( m_nPos ); };
2188 virtual Sequence< sal_Int8 > getBytes() const SAL_OVERRIDE { return m_xRow->getBytes( m_nPos ); };
2189 virtual Reference< XBlob > getBlob() const SAL_OVERRIDE { return m_xRow->getBlob( m_nPos ); };
2190 virtual Reference< XClob > getClob() const SAL_OVERRIDE { return m_xRow->getClob( m_nPos ); };
2191 virtual Any getObject() const SAL_OVERRIDE { return m_xRow->getObject( m_nPos ,NULL); };
2192 virtual bool wasNull() const SAL_OVERRIDE { return m_xRow->wasNull( ); };
2194 private:
2195 const Reference< XRow > m_xRow;
2196 const sal_Int32 m_nPos;
2199 class ColumnValue : public IValueSource
2201 public:
2202 ColumnValue( const Reference< XColumn >& _rxColumn )
2203 :m_xColumn( _rxColumn )
2207 // IValueSource
2208 virtual OUString getString() const SAL_OVERRIDE { return m_xColumn->getString(); };
2209 virtual bool getBoolean() const SAL_OVERRIDE { return m_xColumn->getBoolean(); };
2210 virtual sal_Int8 getByte() const SAL_OVERRIDE { return m_xColumn->getByte(); };
2211 virtual sal_Int16 getShort() const SAL_OVERRIDE { return m_xColumn->getShort(); }
2212 virtual sal_Int32 getInt() const SAL_OVERRIDE { return m_xColumn->getInt(); }
2213 virtual sal_Int64 getLong() const SAL_OVERRIDE { return m_xColumn->getLong(); }
2214 virtual float getFloat() const SAL_OVERRIDE { return m_xColumn->getFloat(); };
2215 virtual double getDouble() const SAL_OVERRIDE { return m_xColumn->getDouble(); };
2216 virtual Date getDate() const SAL_OVERRIDE { return m_xColumn->getDate(); };
2217 virtual Time getTime() const SAL_OVERRIDE { return m_xColumn->getTime(); };
2218 virtual DateTime getTimestamp() const SAL_OVERRIDE { return m_xColumn->getTimestamp(); };
2219 virtual Sequence< sal_Int8 > getBytes() const SAL_OVERRIDE { return m_xColumn->getBytes(); };
2220 virtual Reference< XBlob > getBlob() const SAL_OVERRIDE { return m_xColumn->getBlob(); };
2221 virtual Reference< XClob > getClob() const SAL_OVERRIDE { return m_xColumn->getClob(); };
2222 virtual Any getObject() const SAL_OVERRIDE { return m_xColumn->getObject( NULL ); };
2223 virtual bool wasNull() const SAL_OVERRIDE { return m_xColumn->wasNull( ); };
2225 private:
2226 const Reference< XColumn > m_xColumn;
2231 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2233 detail::ColumnValue aColumnValue( _rxColumn );
2234 impl_fill( _nType, true, aColumnValue );
2238 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const Reference< XRow>& _xRow )
2240 detail::RowValue aRowValue( _xRow, _nPos );
2241 impl_fill( _nType, _bNullable, aRowValue );
2245 void ORowSetValue::fill(sal_Int32 _nPos,
2246 sal_Int32 _nType,
2247 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
2249 fill(_nPos,_nType,true,_xRow);
2253 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2255 bool bReadData = true;
2256 switch(_nType)
2258 case DataType::CHAR:
2259 case DataType::VARCHAR:
2260 case DataType::DECIMAL:
2261 case DataType::NUMERIC:
2262 case DataType::LONGVARCHAR:
2263 (*this) = _rValueSource.getString();
2264 break;
2265 case DataType::BIGINT:
2266 if ( isSigned() )
2267 (*this) = _rValueSource.getLong();
2268 else
2269 // TODO: this is rather horrible performance-wise
2270 // but fixing it needs extending the ::com::sun::star::sdbc::XRow API
2271 // to have a getULong(), and needs updating all drivers :-|
2272 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2273 (*this) = _rValueSource.getString().toUInt64();
2274 break;
2275 case DataType::FLOAT:
2276 (*this) = _rValueSource.getFloat();
2277 break;
2278 case DataType::DOUBLE:
2279 case DataType::REAL:
2280 (*this) = _rValueSource.getDouble();
2281 break;
2282 case DataType::DATE:
2283 (*this) = _rValueSource.getDate();
2284 break;
2285 case DataType::TIME:
2286 (*this) = _rValueSource.getTime();
2287 break;
2288 case DataType::TIMESTAMP:
2289 (*this) = _rValueSource.getTimestamp();
2290 break;
2291 case DataType::BINARY:
2292 case DataType::VARBINARY:
2293 case DataType::LONGVARBINARY:
2294 (*this) = _rValueSource.getBytes();
2295 break;
2296 case DataType::BIT:
2297 case DataType::BOOLEAN:
2298 (*this) = _rValueSource.getBoolean();
2299 break;
2300 case DataType::TINYINT:
2301 if ( isSigned() )
2302 (*this) = _rValueSource.getByte();
2303 else
2304 (*this) = _rValueSource.getShort();
2305 break;
2306 case DataType::SMALLINT:
2307 if ( isSigned() )
2308 (*this) = _rValueSource.getShort();
2309 else
2310 (*this) = _rValueSource.getInt();
2311 break;
2312 case DataType::INTEGER:
2313 if ( isSigned() )
2314 (*this) = _rValueSource.getInt();
2315 else
2316 (*this) = _rValueSource.getLong();
2317 break;
2318 case DataType::CLOB:
2319 (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob());
2320 setTypeKind(DataType::CLOB);
2321 break;
2322 case DataType::BLOB:
2323 (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob());
2324 setTypeKind(DataType::BLOB);
2325 break;
2326 case DataType::OTHER:
2327 (*this) = _rValueSource.getObject();
2328 setTypeKind(DataType::OTHER);
2329 break;
2330 default:
2331 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2332 (*this) = _rValueSource.getObject();
2333 break;
2335 if ( bReadData && _bNullable && _rValueSource.wasNull() )
2336 setNull();
2337 setTypeKind(_nType);
2340 void ORowSetValue::fill(const Any& _rValue)
2342 switch (_rValue.getValueType().getTypeClass())
2344 case TypeClass_VOID:
2345 setNull(); break;
2346 case TypeClass_BOOLEAN:
2348 bool bValue( false );
2349 _rValue >>= bValue;
2350 (*this) = bValue;
2351 break;
2353 case TypeClass_CHAR:
2355 sal_Unicode aDummy(0);
2356 _rValue >>= aDummy;
2357 (*this) = OUString(aDummy);
2358 break;
2360 case TypeClass_STRING:
2362 OUString sDummy;
2363 _rValue >>= sDummy;
2364 (*this) = sDummy;
2365 break;
2367 case TypeClass_FLOAT:
2369 float aDummy(0.0);
2370 _rValue >>= aDummy;
2371 (*this) = aDummy;
2372 break;
2374 case TypeClass_DOUBLE:
2376 double aDummy(0.0);
2377 _rValue >>= aDummy;
2378 (*this) = aDummy;
2379 break;
2381 case TypeClass_BYTE:
2383 sal_Int8 aDummy(0);
2384 _rValue >>= aDummy;
2385 (*this) = aDummy;
2386 break;
2388 case TypeClass_SHORT:
2390 sal_Int16 aDummy(0);
2391 _rValue >>= aDummy;
2392 (*this) = aDummy;
2393 break;
2395 case TypeClass_UNSIGNED_SHORT:
2397 sal_uInt16 nValue(0);
2398 _rValue >>= nValue;
2399 (*this) = nValue;
2400 break;
2402 case TypeClass_LONG:
2404 sal_Int32 aDummy(0);
2405 _rValue >>= aDummy;
2406 (*this) = aDummy;
2407 break;
2409 case TypeClass_UNSIGNED_LONG:
2411 sal_uInt32 nValue(0);
2412 _rValue >>= nValue;
2413 (*this) = static_cast<sal_Int64>(nValue);
2414 setSigned(false);
2415 break;
2417 case TypeClass_HYPER:
2419 sal_Int64 nValue(0);
2420 _rValue >>= nValue;
2421 (*this) = nValue;
2422 break;
2424 case TypeClass_UNSIGNED_HYPER:
2426 sal_uInt64 nValue(0);
2427 _rValue >>= nValue;
2428 (*this) = nValue;
2429 setSigned(false);
2430 break;
2432 case TypeClass_ENUM:
2434 sal_Int32 enumValue( 0 );
2435 ::cppu::enum2int( enumValue, _rValue );
2436 (*this) = enumValue;
2438 break;
2440 case TypeClass_SEQUENCE:
2442 Sequence<sal_Int8> aDummy;
2443 if ( _rValue >>= aDummy )
2444 (*this) = aDummy;
2445 else
2446 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2447 break;
2450 case TypeClass_STRUCT:
2452 ::com::sun::star::util::Date aDate;
2453 ::com::sun::star::util::Time aTime;
2454 ::com::sun::star::util::DateTime aDateTime;
2455 if ( _rValue >>= aDate )
2457 (*this) = aDate;
2459 else if ( _rValue >>= aTime )
2461 (*this) = aTime;
2463 else if ( _rValue >>= aDateTime )
2465 (*this) = aDateTime;
2467 else
2468 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2470 break;
2472 case TypeClass_INTERFACE:
2474 Reference< XClob > xClob;
2475 if ( _rValue >>= xClob )
2477 (*this) = _rValue;
2478 setTypeKind(DataType::CLOB);
2480 else
2482 Reference< XBlob > xBlob;
2483 if ( _rValue >>= xBlob )
2485 (*this) = _rValue;
2486 setTypeKind(DataType::BLOB);
2488 else
2490 (*this) = _rValue;
2494 break;
2496 default:
2497 SAL_WARN( "connectivity.commontools","Unknown type");
2498 break;
2502 } // namespace connectivity
2504 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */