1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
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" );
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
);
64 case DataType::DOUBLE
:
66 bIsCompatible
= (DataType::DOUBLE
== _eType2
)
67 || (DataType::REAL
== _eType2
);
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
);
78 case DataType::INTEGER
:
79 bIsCompatible
= (DataType::SMALLINT
== _eType2
)
80 || (DataType::TINYINT
== _eType2
)
81 || (DataType::BIT
== _eType2
)
82 || (DataType::BOOLEAN
== _eType2
);
84 case DataType::SMALLINT
:
85 bIsCompatible
= (DataType::TINYINT
== _eType2
)
86 || (DataType::BIT
== _eType2
)
87 || (DataType::BOOLEAN
== _eType2
);
89 case DataType::TINYINT
:
90 bIsCompatible
= (DataType::BIT
== _eType2
)
91 || (DataType::BOOLEAN
== _eType2
);
96 case DataType::OBJECT
:
97 bIsCompatible
= (DataType::BLOB
== _eType2
)
98 || (DataType::CLOB
== _eType2
)
99 || (DataType::OBJECT
== _eType2
);
103 bIsCompatible
= false;
106 return bIsCompatible
;
114 #include <rtl/string.h>
118 struct AllocationType
120 const sal_Char
* pName
;
121 sal_Int32 nAllocatedUnits
;
123 AllocationType( ) : pName( NULL
), nAllocatedUnits( 0 ) { }
127 class AllocationTracer
130 typedef ::std::vector
< AllocationType
> AllocationState
;
131 static AllocationState s_aAllocated
;
132 static ::osl::Mutex s_aMutex
;
135 static void registerUnit( const sal_Char
* _pName
);
136 static void revokeUnit( const sal_Char
* _pName
);
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();
147 aLookFor
!= s_aAllocated
.end();
151 if ( 0 == rtl_str_compare( aLookFor
->pName
, _pName
) )
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 ....
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 );
188 #define TRACE_ALLOC( type )
189 #define TRACE_FREE( type )
193 void ORowSetValue::setTypeKind(sal_Int32 _eType
)
195 if ( !m_bNull
&& !isStorageCompatible(_eType
, m_eTypeKind
) )
199 case DataType::VARCHAR
:
201 case DataType::DECIMAL
:
202 case DataType::NUMERIC
:
203 case DataType::LONGVARCHAR
:
204 (*this) = getString();
206 case DataType::BIGINT
:
208 sal_Int64
nVal(getLong());
209 sal_uInt64
nuVal(getULong());
210 if (nVal
== 0 && nuVal
!= 0)
217 case DataType::FLOAT
:
218 (*this) = getFloat();
220 case DataType::DOUBLE
:
222 (*this) = getDouble();
224 case DataType::TINYINT
:
227 case DataType::SMALLINT
:
228 (*this) = getInt16();
230 case DataType::INTEGER
:
232 sal_Int32
nVal(getInt32());
233 sal_uInt32
nuVal(getUInt32());
234 if (nVal
== 0 && nuVal
!= 0)
241 case DataType::BOOLEAN
:
250 case DataType::TIMESTAMP
:
251 (*this) = getDateTime();
253 case DataType::BINARY
:
254 case DataType::VARBINARY
:
255 case DataType::LONGVARBINARY
:
256 (*this) = getSequence();
260 case DataType::OBJECT
:
261 case DataType::OTHER
:
266 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
270 m_eTypeKind
= _eType
;
274 void ORowSetValue::free()
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
;
290 delete (::com::sun::star::util::Date
*)m_aValue
.m_pValue
;
292 m_aValue
.m_pValue
= NULL
;
295 delete (::com::sun::star::util::Time
*)m_aValue
.m_pValue
;
297 m_aValue
.m_pValue
= NULL
;
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
;
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
;
313 case DataType::OBJECT
:
314 delete (Any
*)m_aValue
.m_pValue
;
316 m_aValue
.m_pValue
= NULL
;
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
:
329 if ( m_aValue
.m_pValue
)
331 delete (Any
*)m_aValue
.m_pValue
;
333 m_aValue
.m_pValue
= NULL
;
342 ORowSetValue
& ORowSetValue::operator=(const ORowSetValue
& _rRH
)
347 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
|| (_rRH
.m_bNull
&& !m_bNull
) || m_bSigned
!= _rRH
.m_bSigned
)
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
)
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
;
367 m_aValue
.m_pValue
= new Date(*(Date
*)_rRH
.m_aValue
.m_pValue
);
371 m_aValue
.m_pValue
= new Time(*(Time
*)_rRH
.m_aValue
.m_pValue
);
374 case DataType::TIMESTAMP
:
375 m_aValue
.m_pValue
= new DateTime(*(DateTime
*)_rRH
.m_aValue
.m_pValue
);
376 TRACE_ALLOC( DateTime
)
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
)
385 case DataType::BOOLEAN
:
386 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
388 case DataType::TINYINT
:
389 if ( _rRH
.m_bSigned
)
390 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
392 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
394 case DataType::SMALLINT
:
395 if ( _rRH
.m_bSigned
)
396 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
398 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
400 case DataType::INTEGER
:
401 if ( _rRH
.m_bSigned
)
402 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
404 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
406 case DataType::BIGINT
:
407 if ( _rRH
.m_bSigned
)
408 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
410 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
412 case DataType::FLOAT
:
413 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
415 case DataType::DOUBLE
:
417 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
420 m_aValue
.m_pValue
= new Any(*(Any
*)_rRH
.m_aValue
.m_pValue
);
424 else if(!_rRH
.m_bNull
)
426 switch(_rRH
.m_eTypeKind
)
429 case DataType::VARCHAR
:
430 case DataType::DECIMAL
:
431 case DataType::NUMERIC
:
432 case DataType::LONGVARCHAR
:
433 (*this) = OUString(_rRH
.m_aValue
.m_pString
);
436 (*this) = *(Date
*)_rRH
.m_aValue
.m_pValue
;
439 (*this) = *(Time
*)_rRH
.m_aValue
.m_pValue
;
441 case DataType::TIMESTAMP
:
442 (*this) = *(DateTime
*)_rRH
.m_aValue
.m_pValue
;
444 case DataType::BINARY
:
445 case DataType::VARBINARY
:
446 case DataType::LONGVARBINARY
:
447 (*this) = *(Sequence
<sal_Int8
>*)_rRH
.m_aValue
.m_pValue
;
450 case DataType::BOOLEAN
:
451 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
453 case DataType::TINYINT
:
454 if ( _rRH
.m_bSigned
)
455 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
457 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
459 case DataType::SMALLINT
:
460 if ( _rRH
.m_bSigned
)
461 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
463 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
465 case DataType::INTEGER
:
466 if ( _rRH
.m_bSigned
)
467 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
469 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
471 case DataType::BIGINT
:
472 if ( _rRH
.m_bSigned
)
473 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
475 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
477 case DataType::FLOAT
:
478 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
480 case DataType::DOUBLE
:
482 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
485 (*(Any
*)m_aValue
.m_pValue
) = (*(Any
*)_rRH
.m_aValue
.m_pValue
);
489 m_bNull
= _rRH
.m_bNull
;
491 m_eTypeKind
= _rRH
.m_eTypeKind
;
497 ORowSetValue
& ORowSetValue::operator=(const Date
& _rRH
)
499 if(m_eTypeKind
!= DataType::DATE
)
504 m_aValue
.m_pValue
= new Date(_rRH
);
506 m_eTypeKind
= DataType::DATE
;
510 *(Date
*)m_aValue
.m_pValue
= _rRH
;
515 ORowSetValue
& ORowSetValue::operator=(const Time
& _rRH
)
517 if(m_eTypeKind
!= DataType::TIME
)
522 m_aValue
.m_pValue
= new Time(_rRH
);
524 m_eTypeKind
= DataType::TIME
;
528 *(Time
*)m_aValue
.m_pValue
= _rRH
;
533 ORowSetValue
& ORowSetValue::operator=(const DateTime
& _rRH
)
535 if(m_eTypeKind
!= DataType::TIMESTAMP
)
539 m_aValue
.m_pValue
= new DateTime(_rRH
);
540 TRACE_ALLOC( DateTime
)
541 m_eTypeKind
= DataType::TIMESTAMP
;
545 *(DateTime
*)m_aValue
.m_pValue
= _rRH
;
551 ORowSetValue
& ORowSetValue::operator=(const OUString
& _rRH
)
553 if(m_eTypeKind
!= DataType::VARCHAR
|| m_aValue
.m_pString
!= _rRH
.pData
)
558 m_aValue
.m_pString
= _rRH
.pData
;
559 rtl_uString_acquire(m_aValue
.m_pString
);
560 m_eTypeKind
= DataType::VARCHAR
;
567 ORowSetValue
& ORowSetValue::operator=(const double& _rRH
)
569 if(m_eTypeKind
!= DataType::DOUBLE
)
572 m_aValue
.m_nDouble
= _rRH
;
573 m_eTypeKind
= DataType::DOUBLE
;
579 ORowSetValue
& ORowSetValue::operator=(const float& _rRH
)
581 if(m_eTypeKind
!= DataType::FLOAT
)
584 m_aValue
.m_nFloat
= _rRH
;
585 m_eTypeKind
= DataType::FLOAT
;
592 ORowSetValue
& ORowSetValue::operator=(const sal_Int8
& _rRH
)
594 if(m_eTypeKind
!= DataType::TINYINT
)
597 m_aValue
.m_nInt8
= _rRH
;
598 m_eTypeKind
= DataType::TINYINT
;
605 ORowSetValue
& ORowSetValue::operator=(const sal_uInt8
& _rRH
)
607 if(m_eTypeKind
!= DataType::TINYINT
)
610 m_aValue
.m_uInt8
= _rRH
;
611 m_eTypeKind
= DataType::TINYINT
;
618 ORowSetValue
& ORowSetValue::operator=(const sal_Int16
& _rRH
)
620 if(m_eTypeKind
!= DataType::SMALLINT
)
623 m_aValue
.m_nInt16
= _rRH
;
624 m_eTypeKind
= DataType::SMALLINT
;
632 ORowSetValue
& ORowSetValue::operator=(const sal_uInt16
& _rRH
)
634 if(m_eTypeKind
!= DataType::SMALLINT
)
637 m_aValue
.m_uInt16
= _rRH
;
638 m_eTypeKind
= DataType::SMALLINT
;
646 ORowSetValue
& ORowSetValue::operator=(const sal_Int32
& _rRH
)
648 if(m_eTypeKind
!= DataType::INTEGER
)
651 m_aValue
.m_nInt32
= _rRH
;
653 m_eTypeKind
= DataType::INTEGER
;
661 ORowSetValue
& ORowSetValue::operator=(const sal_uInt32
& _rRH
)
663 if(m_eTypeKind
!= DataType::INTEGER
)
666 m_aValue
.m_uInt32
= _rRH
;
668 m_eTypeKind
= DataType::INTEGER
;
676 ORowSetValue
& ORowSetValue::operator=(const bool _rRH
)
678 if(m_eTypeKind
!= DataType::BIT
&& DataType::BOOLEAN
!= m_eTypeKind
)
681 m_aValue
.m_bBool
= _rRH
;
682 m_eTypeKind
= DataType::BOOLEAN
;
688 ORowSetValue
& ORowSetValue::operator=(const sal_Int64
& _rRH
)
690 if ( DataType::BIGINT
!= m_eTypeKind
)
693 m_aValue
.m_nInt64
= _rRH
;
694 m_eTypeKind
= DataType::BIGINT
;
701 ORowSetValue
& ORowSetValue::operator=(const sal_uInt64
& _rRH
)
703 if ( DataType::BIGINT
!= m_eTypeKind
)
706 m_aValue
.m_uInt64
= _rRH
;
707 m_eTypeKind
= DataType::BIGINT
;
714 ORowSetValue
& ORowSetValue::operator=(const Sequence
<sal_Int8
>& _rRH
)
716 if (!isStorageCompatible(DataType::LONGVARBINARY
,m_eTypeKind
))
721 m_aValue
.m_pValue
= new Sequence
<sal_Int8
>(_rRH
);
722 TRACE_ALLOC( Sequence_sal_Int8
)
725 *static_cast< Sequence
< sal_Int8
>* >(m_aValue
.m_pValue
) = _rRH
;
727 m_eTypeKind
= DataType::LONGVARBINARY
;
733 ORowSetValue
& ORowSetValue::operator=(const Any
& _rAny
)
735 if (!isStorageCompatible(DataType::OBJECT
,m_eTypeKind
))
740 m_aValue
.m_pValue
= new Any(_rAny
);
744 *static_cast<Any
*>(m_aValue
.m_pValue
) = _rAny
;
746 m_eTypeKind
= DataType::OBJECT
;
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() )
777 if(m_bNull
&& _rRH
.isNull())
780 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
)
784 case DataType::FLOAT
:
785 case DataType::DOUBLE
:
787 return getDouble() == _rRH
.getDouble();
789 switch(_rRH
.m_eTypeKind
)
791 case DataType::FLOAT
:
792 case DataType::DOUBLE
:
794 return getDouble() == _rRH
.getDouble();
804 OSL_ENSURE(!m_bNull
,"SHould not be null!");
807 case DataType::VARCHAR
:
809 case DataType::LONGVARCHAR
:
811 OUString
aVal1(m_aValue
.m_pString
);
812 OUString
aVal2(_rRH
.m_aValue
.m_pString
);
813 return aVal1
== aVal2
;
816 if ( m_bSigned
!= _rRH
.m_bSigned
)
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
;
831 case DataType::FLOAT
:
832 bRet
= m_aValue
.m_nFloat
== _rRH
.m_aValue
.m_nFloat
;
834 case DataType::DOUBLE
:
836 bRet
= m_aValue
.m_nDouble
== _rRH
.m_aValue
.m_nDouble
;
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
);
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
);
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
);
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
);
851 case DataType::BOOLEAN
:
852 bRet
= m_aValue
.m_bBool
== _rRH
.m_aValue
.m_bBool
;
855 bRet
= *(Date
*)m_aValue
.m_pValue
== *(Date
*)_rRH
.m_aValue
.m_pValue
;
858 bRet
= *(Time
*)m_aValue
.m_pValue
== *(Time
*)_rRH
.m_aValue
.m_pValue
;
860 case DataType::TIMESTAMP
:
861 bRet
= *(DateTime
*)m_aValue
.m_pValue
== *(DateTime
*)_rRH
.m_aValue
.m_pValue
;
863 case DataType::BINARY
:
864 case DataType::VARBINARY
:
865 case DataType::LONGVARBINARY
:
870 case DataType::OBJECT
:
871 case DataType::OTHER
:
876 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
882 Any
ORowSetValue::makeAny() const
885 if(isBound() && !isNull())
887 switch(getTypeKind())
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
;
897 case DataType::FLOAT
:
898 rValue
<<= m_aValue
.m_nFloat
;
900 case DataType::DOUBLE
:
902 rValue
<<= m_aValue
.m_nDouble
;
905 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
906 rValue
<<= *(Date
*)m_aValue
.m_pValue
;
909 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
910 rValue
<<= *(Time
*)m_aValue
.m_pValue
;
912 case DataType::TIMESTAMP
:
913 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
914 rValue
<<= *(DateTime
*)m_aValue
.m_pValue
;
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
;
924 case DataType::OBJECT
:
925 case DataType::OTHER
:
929 case DataType::BOOLEAN
:
930 rValue
<<= m_aValue
.m_bBool
;
932 case DataType::TINYINT
:
935 rValue
<<= m_aValue
.m_nInt8
;
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
);
942 case DataType::SMALLINT
:
945 rValue
<<= m_aValue
.m_nInt16
;
947 // TypeClass_UNSIGNED_SHORT
948 rValue
<<= m_aValue
.m_uInt16
;
950 case DataType::INTEGER
:
953 rValue
<<= m_aValue
.m_nInt32
;
955 // TypeClass_UNSIGNED_LONG
956 rValue
<<= m_aValue
.m_uInt32
;
958 case DataType::BIGINT
:
961 rValue
<<= m_aValue
.m_nInt64
;
963 // TypeClass_UNSIGNED_HYPER
964 rValue
<<= m_aValue
.m_uInt64
;
967 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSPUPPORTED TYPE!");
975 OUString
ORowSetValue::getString( ) const
980 switch(getTypeKind())
983 case DataType::VARCHAR
:
984 case DataType::DECIMAL
:
985 case DataType::NUMERIC
:
986 case DataType::LONGVARCHAR
:
987 aRet
= m_aValue
.m_pString
;
989 case DataType::FLOAT
:
990 aRet
= OUString::number(static_cast<float>(*this));
992 case DataType::DOUBLE
:
994 aRet
= OUString::number(static_cast<double>(*this));
997 aRet
= DBTypeConversion::toDateString(*this);
1000 aRet
= DBTypeConversion::toTimeString(*this);
1002 case DataType::TIMESTAMP
:
1003 aRet
= DBTypeConversion::toDateTimeString(*this);
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();
1019 aRet
= OUString::number(int(static_cast<bool>(*this)));
1021 case DataType::BOOLEAN
:
1022 aRet
= OUString::boolean(static_cast<bool>(*this));
1024 case DataType::TINYINT
:
1025 case DataType::SMALLINT
:
1026 case DataType::INTEGER
:
1028 aRet
= OUString::number(static_cast<sal_Int32
>(*this));
1030 aRet
= OUString::number(static_cast<sal_uInt32
>(*this));
1032 case DataType::BIGINT
:
1034 aRet
= OUString::number(static_cast<sal_Int64
>(*this));
1036 aRet
= OUString::number(static_cast<sal_uInt64
>(*this));
1038 case DataType::CLOB
:
1040 Any
aValue( getAny() );
1041 Reference
< XClob
> xClob
;
1042 if ( aValue
>>= xClob
)
1046 aRet
= xClob
->getSubString(1,(sal_Int32
)xClob
->length() );
1053 Any aValue
= getAny();
1062 bool ORowSetValue::getBool() const
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") )
1079 else if ( sValue
.equalsIgnoreAsciiCase("false") || (sValue
== "0") )
1086 case DataType::DECIMAL
:
1087 case DataType::NUMERIC
:
1089 bRet
= OUString(m_aValue
.m_pString
).toInt32() != 0;
1091 case DataType::FLOAT
:
1092 bRet
= m_aValue
.m_nFloat
!= 0.0;
1094 case DataType::DOUBLE
:
1095 case DataType::REAL
:
1096 bRet
= m_aValue
.m_nDouble
!= 0.0;
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!");
1107 case DataType::BOOLEAN
:
1108 bRet
= m_aValue
.m_bBool
;
1110 case DataType::TINYINT
:
1111 bRet
= m_bSigned
? (m_aValue
.m_nInt8
!= 0) : (m_aValue
.m_uInt8
!= 0);
1113 case DataType::SMALLINT
:
1114 bRet
= m_bSigned
? (m_aValue
.m_nInt16
!= 0) : (m_aValue
.m_uInt16
!= 0);
1116 case DataType::INTEGER
:
1117 bRet
= m_bSigned
? (m_aValue
.m_nInt32
!= 0) : (m_aValue
.m_uInt32
!= 0);
1119 case DataType::BIGINT
:
1120 bRet
= m_bSigned
? (m_aValue
.m_nInt64
!= 0) : (m_aValue
.m_uInt64
!= 0);
1124 Any aValue
= getAny();
1134 sal_Int8
ORowSetValue::getInt8() const
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());
1148 case DataType::FLOAT
:
1149 nRet
= sal_Int8(m_aValue
.m_nFloat
);
1151 case DataType::DOUBLE
:
1152 case DataType::REAL
:
1153 nRet
= sal_Int8(m_aValue
.m_nDouble
);
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!");
1166 case DataType::BOOLEAN
:
1167 nRet
= sal_Int8(m_aValue
.m_bBool
);
1169 case DataType::TINYINT
:
1171 nRet
= m_aValue
.m_nInt8
;
1173 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt8
);
1175 case DataType::SMALLINT
:
1177 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt16
);
1179 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt16
);
1181 case DataType::INTEGER
:
1183 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt32
);
1185 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt32
);
1187 case DataType::BIGINT
:
1189 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt64
);
1191 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt64
);
1195 Any aValue
= getAny();
1205 sal_uInt8
ORowSetValue::getUInt8() const
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());
1219 case DataType::FLOAT
:
1220 nRet
= sal_uInt8(m_aValue
.m_nFloat
);
1222 case DataType::DOUBLE
:
1223 case DataType::REAL
:
1224 nRet
= sal_uInt8(m_aValue
.m_nDouble
);
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!");
1237 case DataType::BOOLEAN
:
1238 nRet
= m_aValue
.m_bBool
;
1240 case DataType::TINYINT
:
1242 nRet
= m_aValue
.m_nInt8
;
1244 nRet
= m_aValue
.m_uInt8
;
1246 case DataType::SMALLINT
:
1248 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt16
);
1250 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt16
);
1252 case DataType::INTEGER
:
1254 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt32
);
1256 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt32
);
1258 case DataType::BIGINT
:
1260 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt64
);
1262 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt64
);
1266 Any aValue
= getAny();
1277 sal_Int16
ORowSetValue::getInt16() const
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());
1291 case DataType::FLOAT
:
1292 nRet
= sal_Int16(m_aValue
.m_nFloat
);
1294 case DataType::DOUBLE
:
1295 case DataType::REAL
:
1296 nRet
= sal_Int16(m_aValue
.m_nDouble
);
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!");
1309 case DataType::BOOLEAN
:
1310 nRet
= sal_Int16(m_aValue
.m_bBool
);
1312 case DataType::TINYINT
:
1314 nRet
= m_aValue
.m_nInt8
;
1316 nRet
= m_aValue
.m_uInt8
;
1318 case DataType::SMALLINT
:
1320 nRet
= m_aValue
.m_nInt16
;
1322 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt16
);
1324 case DataType::INTEGER
:
1326 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt32
);
1328 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt32
);
1330 case DataType::BIGINT
:
1332 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt64
);
1334 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt64
);
1338 Any aValue
= getAny();
1348 sal_uInt16
ORowSetValue::getUInt16() const
1350 sal_uInt16 nRet
= 0;
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());
1362 case DataType::FLOAT
:
1363 nRet
= sal_uInt16(m_aValue
.m_nFloat
);
1365 case DataType::DOUBLE
:
1366 case DataType::REAL
:
1367 nRet
= sal_uInt16(m_aValue
.m_nDouble
);
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!");
1380 case DataType::BOOLEAN
:
1381 nRet
= sal_uInt16(m_aValue
.m_bBool
);
1383 case DataType::TINYINT
:
1385 nRet
= m_aValue
.m_nInt8
;
1387 nRet
= m_aValue
.m_uInt8
;
1389 case DataType::SMALLINT
:
1391 nRet
= m_aValue
.m_nInt16
;
1393 nRet
= m_aValue
.m_uInt16
;
1395 case DataType::INTEGER
:
1397 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt32
);
1399 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt32
);
1401 case DataType::BIGINT
:
1403 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt64
);
1405 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt64
);
1409 Any aValue
= getAny();
1419 sal_Int32
ORowSetValue::getInt32() const
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();
1433 case DataType::FLOAT
:
1434 nRet
= sal_Int32(m_aValue
.m_nFloat
);
1436 case DataType::DOUBLE
:
1437 case DataType::REAL
:
1438 nRet
= sal_Int32(m_aValue
.m_nDouble
);
1440 case DataType::DATE
:
1441 nRet
= dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
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!");
1453 case DataType::BOOLEAN
:
1454 nRet
= sal_Int32(m_aValue
.m_bBool
);
1456 case DataType::TINYINT
:
1458 nRet
= m_aValue
.m_nInt8
;
1460 nRet
= m_aValue
.m_uInt8
;
1462 case DataType::SMALLINT
:
1464 nRet
= m_aValue
.m_nInt16
;
1466 nRet
= m_aValue
.m_uInt16
;
1468 case DataType::INTEGER
:
1470 nRet
= m_aValue
.m_nInt32
;
1472 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt32
);
1474 case DataType::BIGINT
:
1476 nRet
= static_cast<sal_Int32
>(m_aValue
.m_nInt64
);
1478 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt64
);
1482 Any aValue
= getAny();
1492 sal_uInt32
ORowSetValue::getUInt32() const
1494 sal_uInt32 nRet
= 0;
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();
1506 case DataType::FLOAT
:
1507 nRet
= sal_uInt32(m_aValue
.m_nFloat
);
1509 case DataType::DOUBLE
:
1510 case DataType::REAL
:
1511 nRet
= sal_uInt32(m_aValue
.m_nDouble
);
1513 case DataType::DATE
:
1514 nRet
= dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
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!");
1526 case DataType::BOOLEAN
:
1527 nRet
= sal_uInt32(m_aValue
.m_bBool
);
1529 case DataType::TINYINT
:
1531 nRet
= m_aValue
.m_nInt8
;
1533 nRet
= m_aValue
.m_uInt8
;
1535 case DataType::SMALLINT
:
1537 nRet
= m_aValue
.m_nInt16
;
1539 nRet
= m_aValue
.m_uInt16
;
1541 case DataType::INTEGER
:
1543 nRet
= m_aValue
.m_nInt32
;
1545 nRet
= m_aValue
.m_uInt32
;
1547 case DataType::BIGINT
:
1549 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_nInt64
);
1551 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_uInt64
);
1555 Any aValue
= getAny();
1565 sal_Int64
ORowSetValue::getLong() const
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();
1579 case DataType::FLOAT
:
1580 nRet
= sal_Int64(m_aValue
.m_nFloat
);
1582 case DataType::DOUBLE
:
1583 case DataType::REAL
:
1584 nRet
= sal_Int64(m_aValue
.m_nDouble
);
1586 case DataType::DATE
:
1587 nRet
= dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
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!");
1599 case DataType::BOOLEAN
:
1600 nRet
= sal_Int64(m_aValue
.m_bBool
);
1602 case DataType::TINYINT
:
1604 nRet
= m_aValue
.m_nInt8
;
1606 nRet
= m_aValue
.m_uInt8
;
1608 case DataType::SMALLINT
:
1610 nRet
= m_aValue
.m_nInt16
;
1612 nRet
= m_aValue
.m_uInt16
;
1614 case DataType::INTEGER
:
1616 nRet
= m_aValue
.m_nInt32
;
1618 nRet
= m_aValue
.m_uInt32
;
1620 case DataType::BIGINT
:
1622 nRet
= m_aValue
.m_nInt64
;
1624 nRet
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
1628 Any aValue
= getAny();
1638 sal_uInt64
ORowSetValue::getULong() const
1640 sal_uInt64 nRet
= 0;
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());
1652 case DataType::FLOAT
:
1653 nRet
= sal_uInt64(m_aValue
.m_nFloat
);
1655 case DataType::DOUBLE
:
1656 case DataType::REAL
:
1657 nRet
= sal_uInt64(m_aValue
.m_nDouble
);
1659 case DataType::DATE
:
1660 nRet
= dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
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!");
1672 case DataType::BOOLEAN
:
1673 nRet
= sal_uInt64(m_aValue
.m_bBool
);
1675 case DataType::TINYINT
:
1677 nRet
= m_aValue
.m_nInt8
;
1679 nRet
= m_aValue
.m_uInt8
;
1681 case DataType::SMALLINT
:
1683 nRet
= m_aValue
.m_nInt16
;
1685 nRet
= m_aValue
.m_uInt16
;
1687 case DataType::INTEGER
:
1689 nRet
= m_aValue
.m_nInt32
;
1691 nRet
= m_aValue
.m_uInt32
;
1693 case DataType::BIGINT
:
1695 nRet
= m_aValue
.m_nInt64
;
1697 nRet
= m_aValue
.m_uInt64
;
1701 Any aValue
= getAny();
1711 float ORowSetValue::getFloat() const
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();
1725 case DataType::FLOAT
:
1726 nRet
= m_aValue
.m_nFloat
;
1728 case DataType::DOUBLE
:
1729 case DataType::REAL
:
1730 nRet
= (float)m_aValue
.m_nDouble
;
1732 case DataType::DATE
:
1733 nRet
= (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
1735 case DataType::TIME
:
1736 nRet
= (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time
*)m_aValue
.m_pValue
);
1738 case DataType::TIMESTAMP
:
1739 nRet
= (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime
*)m_aValue
.m_pValue
);
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!");
1749 case DataType::BOOLEAN
:
1750 nRet
= float(m_aValue
.m_bBool
);
1752 case DataType::TINYINT
:
1754 nRet
= m_aValue
.m_nInt8
;
1756 nRet
= m_aValue
.m_uInt8
;
1758 case DataType::SMALLINT
:
1760 nRet
= m_aValue
.m_nInt16
;
1762 nRet
= (float)m_aValue
.m_uInt16
;
1764 case DataType::INTEGER
:
1766 nRet
= (float)m_aValue
.m_nInt32
;
1768 nRet
= (float)m_aValue
.m_uInt32
;
1770 case DataType::BIGINT
:
1772 nRet
= (float)m_aValue
.m_nInt64
;
1774 nRet
= (float)m_aValue
.m_uInt64
;
1778 Any aValue
= getAny();
1787 double ORowSetValue::getDouble() const
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();
1801 case DataType::FLOAT
:
1802 nRet
= m_aValue
.m_nFloat
;
1804 case DataType::DOUBLE
:
1805 case DataType::REAL
:
1806 nRet
= m_aValue
.m_nDouble
;
1808 case DataType::DATE
:
1809 nRet
= dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date
*)m_aValue
.m_pValue
);
1811 case DataType::TIME
:
1812 nRet
= dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time
*)m_aValue
.m_pValue
);
1814 case DataType::TIMESTAMP
:
1815 nRet
= dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime
*)m_aValue
.m_pValue
);
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!");
1825 case DataType::BOOLEAN
:
1826 nRet
= double(m_aValue
.m_bBool
);
1828 case DataType::TINYINT
:
1830 nRet
= m_aValue
.m_nInt8
;
1832 nRet
= m_aValue
.m_uInt8
;
1834 case DataType::SMALLINT
:
1836 nRet
= m_aValue
.m_nInt16
;
1838 nRet
= m_aValue
.m_uInt16
;
1840 case DataType::INTEGER
:
1842 nRet
= m_aValue
.m_nInt32
;
1844 nRet
= m_aValue
.m_uInt32
;
1846 case DataType::BIGINT
:
1848 nRet
= m_aValue
.m_nInt64
;
1850 nRet
= m_aValue
.m_uInt64
;
1854 Any aValue
= getAny();
1863 Sequence
<sal_Int8
> ORowSetValue::getSequence() const
1865 Sequence
<sal_Int8
> aSeq
;
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
);
1880 xStream
= xBlob
->getBinaryStream();
1883 Reference
<XClob
> xClob(aValue
,UNO_QUERY
);
1885 xStream
= xClob
->getCharacterStream();
1889 const sal_uInt32 nBytesToRead
= 65535;
1894 ::com::sun::star::uno::Sequence
< sal_Int8
> aReadSeq
;
1896 nRead
= xStream
->readSomeBytes( aReadSeq
, nBytesToRead
);
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();
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());
1918 case DataType::BINARY
:
1919 case DataType::VARBINARY
:
1920 case DataType::LONGVARBINARY
:
1921 aSeq
= *static_cast< Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
1925 Any aValue
= getAny();
1935 ::com::sun::star::util::Date
ORowSetValue::getDate() const
1937 ::com::sun::star::util::Date aValue
;
1942 case DataType::CHAR
:
1943 case DataType::VARCHAR
:
1944 case DataType::LONGVARCHAR
:
1945 aValue
= DBTypeConversion::toDate(getString());
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);
1955 case DataType::DATE
:
1956 aValue
= *static_cast< ::com::sun::star::util::Date
*>(m_aValue
.m_pValue
);
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
;
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 ) ) );
1975 case DataType::BLOB
:
1976 case DataType::CLOB
:
1977 case DataType::OBJECT
:
1979 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1982 case DataType::BINARY
:
1983 case DataType::VARBINARY
:
1984 case DataType::LONGVARBINARY
:
1985 case DataType::TIME
:
1986 aValue
= DBTypeConversion::toDate( (double)0 );
1993 ::com::sun::star::util::Time
ORowSetValue::getTime() const
1995 ::com::sun::star::util::Time aValue
;
2000 case DataType::CHAR
:
2001 case DataType::VARCHAR
:
2002 case DataType::LONGVARCHAR
:
2003 aValue
= DBTypeConversion::toTime(getString());
2005 case DataType::DECIMAL
:
2006 case DataType::NUMERIC
:
2007 aValue
= DBTypeConversion::toTime((double)*this);
2009 case DataType::FLOAT
:
2010 case DataType::DOUBLE
:
2011 case DataType::REAL
:
2012 aValue
= DBTypeConversion::toTime((double)*this);
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
;
2023 case DataType::TIME
:
2024 aValue
= *static_cast< ::com::sun::star::util::Time
*>(m_aValue
.m_pValue
);
2028 Any aAnyValue
= getAny();
2029 aAnyValue
>>= aValue
;
2037 ::com::sun::star::util::DateTime
ORowSetValue::getDateTime() const
2039 ::com::sun::star::util::DateTime aValue
;
2044 case DataType::CHAR
:
2045 case DataType::VARCHAR
:
2046 case DataType::LONGVARCHAR
:
2047 aValue
= DBTypeConversion::toDateTime(getString());
2049 case DataType::DECIMAL
:
2050 case DataType::NUMERIC
:
2051 aValue
= DBTypeConversion::toDateTime((double)*this);
2053 case DataType::FLOAT
:
2054 case DataType::DOUBLE
:
2055 case DataType::REAL
:
2056 aValue
= DBTypeConversion::toDateTime((double)*this);
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
;
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
;
2075 case DataType::TIMESTAMP
:
2076 aValue
= *static_cast< ::com::sun::star::util::DateTime
*>(m_aValue
.m_pValue
);
2080 Any aAnyValue
= getAny();
2081 aAnyValue
>>= aValue
;
2089 void ORowSetValue::setSigned(bool _bMod
)
2091 if ( m_bSigned
!= _bMod
)
2096 sal_Int32 nType
= m_eTypeKind
;
2099 case DataType::TINYINT
:
2101 (*this) = getInt8();
2104 m_bSigned
= !m_bSigned
;
2105 (*this) = getInt16();
2106 m_bSigned
= !m_bSigned
;
2109 case DataType::SMALLINT
:
2111 (*this) = getInt16();
2114 m_bSigned
= !m_bSigned
;
2115 (*this) = getInt32();
2116 m_bSigned
= !m_bSigned
;
2119 case DataType::INTEGER
:
2121 (*this) = getInt32();
2124 m_bSigned
= !m_bSigned
;
2125 (*this) = getLong();
2126 m_bSigned
= !m_bSigned
;
2129 case DataType::BIGINT
:
2131 m_aValue
.m_nInt64
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
2133 m_aValue
.m_uInt64
= static_cast<sal_uInt64
>(m_aValue
.m_nInt64
);
2136 m_eTypeKind
= nType
;
2144 class SAL_NO_VTABLE IValueSource
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
2170 RowValue( const Reference
< XRow
>& _xRow
, const sal_Int32 _nPos
)
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( ); };
2195 const Reference
< XRow
> m_xRow
;
2196 const sal_Int32 m_nPos
;
2199 class ColumnValue
: public IValueSource
2202 ColumnValue( const Reference
< XColumn
>& _rxColumn
)
2203 :m_xColumn( _rxColumn
)
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( ); };
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
,
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;
2258 case DataType::CHAR
:
2259 case DataType::VARCHAR
:
2260 case DataType::DECIMAL
:
2261 case DataType::NUMERIC
:
2262 case DataType::LONGVARCHAR
:
2263 (*this) = _rValueSource
.getString();
2265 case DataType::BIGINT
:
2267 (*this) = _rValueSource
.getLong();
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();
2275 case DataType::FLOAT
:
2276 (*this) = _rValueSource
.getFloat();
2278 case DataType::DOUBLE
:
2279 case DataType::REAL
:
2280 (*this) = _rValueSource
.getDouble();
2282 case DataType::DATE
:
2283 (*this) = _rValueSource
.getDate();
2285 case DataType::TIME
:
2286 (*this) = _rValueSource
.getTime();
2288 case DataType::TIMESTAMP
:
2289 (*this) = _rValueSource
.getTimestamp();
2291 case DataType::BINARY
:
2292 case DataType::VARBINARY
:
2293 case DataType::LONGVARBINARY
:
2294 (*this) = _rValueSource
.getBytes();
2297 case DataType::BOOLEAN
:
2298 (*this) = _rValueSource
.getBoolean();
2300 case DataType::TINYINT
:
2302 (*this) = _rValueSource
.getByte();
2304 (*this) = _rValueSource
.getShort();
2306 case DataType::SMALLINT
:
2308 (*this) = _rValueSource
.getShort();
2310 (*this) = _rValueSource
.getInt();
2312 case DataType::INTEGER
:
2314 (*this) = _rValueSource
.getInt();
2316 (*this) = _rValueSource
.getLong();
2318 case DataType::CLOB
:
2319 (*this) = ::com::sun::star::uno::makeAny(_rValueSource
.getClob());
2320 setTypeKind(DataType::CLOB
);
2322 case DataType::BLOB
:
2323 (*this) = ::com::sun::star::uno::makeAny(_rValueSource
.getBlob());
2324 setTypeKind(DataType::BLOB
);
2326 case DataType::OTHER
:
2327 (*this) = _rValueSource
.getObject();
2328 setTypeKind(DataType::OTHER
);
2331 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2332 (*this) = _rValueSource
.getObject();
2335 if ( bReadData
&& _bNullable
&& _rValueSource
.wasNull() )
2337 setTypeKind(_nType
);
2340 void ORowSetValue::fill(const Any
& _rValue
)
2342 switch (_rValue
.getValueType().getTypeClass())
2344 case TypeClass_VOID
:
2346 case TypeClass_BOOLEAN
:
2348 bool bValue( false );
2353 case TypeClass_CHAR
:
2355 sal_Unicode
aDummy(0);
2357 (*this) = OUString(aDummy
);
2360 case TypeClass_STRING
:
2367 case TypeClass_FLOAT
:
2374 case TypeClass_DOUBLE
:
2381 case TypeClass_BYTE
:
2388 case TypeClass_SHORT
:
2390 sal_Int16
aDummy(0);
2395 case TypeClass_UNSIGNED_SHORT
:
2397 sal_uInt16
nValue(0);
2402 case TypeClass_LONG
:
2404 sal_Int32
aDummy(0);
2409 case TypeClass_UNSIGNED_LONG
:
2411 sal_uInt32
nValue(0);
2413 (*this) = static_cast<sal_Int64
>(nValue
);
2417 case TypeClass_HYPER
:
2419 sal_Int64
nValue(0);
2424 case TypeClass_UNSIGNED_HYPER
:
2426 sal_uInt64
nValue(0);
2432 case TypeClass_ENUM
:
2434 sal_Int32
enumValue( 0 );
2435 ::cppu::enum2int( enumValue
, _rValue
);
2436 (*this) = enumValue
;
2440 case TypeClass_SEQUENCE
:
2442 Sequence
<sal_Int8
> aDummy
;
2443 if ( _rValue
>>= aDummy
)
2446 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
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
)
2459 else if ( _rValue
>>= aTime
)
2463 else if ( _rValue
>>= aDateTime
)
2465 (*this) = aDateTime
;
2468 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2472 case TypeClass_INTERFACE
:
2474 Reference
< XClob
> xClob
;
2475 if ( _rValue
>>= xClob
)
2478 setTypeKind(DataType::CLOB
);
2482 Reference
< XBlob
> xBlob
;
2483 if ( _rValue
>>= xBlob
)
2486 setTypeKind(DataType::BLOB
);
2497 SAL_WARN( "connectivity.commontools","Unknown type");
2502 } // namespace connectivity
2504 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */