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 .
22 #include <connectivity/FValue.hxx>
23 #include <connectivity/dbconversion.hxx>
24 #include <comphelper/extract.hxx>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/sdbc/XClob.hpp>
27 #include <com/sun/star/sdbc/XBlob.hpp>
28 #include <com/sun/star/sdb/XColumn.hpp>
29 #include <com/sun/star/sdbc/XRow.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <sal/log.hxx>
32 #include <osl/diagnose.h>
34 using namespace ::dbtools
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::sdb
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::util
;
39 using namespace ::com::sun::star::io
;
41 namespace connectivity
45 bool isStorageCompatible(sal_Int32 _eType1
, sal_Int32 _eType2
)
47 bool bIsCompatible
= true;
49 if (_eType1
!= _eType2
)
51 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
55 case DataType::VARCHAR
:
56 case DataType::DECIMAL
:
57 case DataType::NUMERIC
:
58 case DataType::LONGVARCHAR
:
59 bIsCompatible
= (DataType::CHAR
== _eType2
)
60 || (DataType::VARCHAR
== _eType2
)
61 || (DataType::DECIMAL
== _eType2
)
62 || (DataType::NUMERIC
== _eType2
)
63 || (DataType::LONGVARCHAR
== _eType2
);
66 case DataType::DOUBLE
:
68 bIsCompatible
= (DataType::DOUBLE
== _eType2
)
69 || (DataType::REAL
== _eType2
);
72 case DataType::BINARY
:
73 case DataType::VARBINARY
:
74 case DataType::LONGVARBINARY
:
75 bIsCompatible
= (DataType::BINARY
== _eType2
)
76 || (DataType::VARBINARY
== _eType2
)
77 || (DataType::LONGVARBINARY
== _eType2
);
80 case DataType::INTEGER
:
81 bIsCompatible
= (DataType::SMALLINT
== _eType2
)
82 || (DataType::TINYINT
== _eType2
)
83 || (DataType::BIT
== _eType2
)
84 || (DataType::BOOLEAN
== _eType2
);
86 case DataType::SMALLINT
:
87 bIsCompatible
= (DataType::TINYINT
== _eType2
)
88 || (DataType::BIT
== _eType2
)
89 || (DataType::BOOLEAN
== _eType2
);
91 case DataType::TINYINT
:
92 bIsCompatible
= (DataType::BIT
== _eType2
)
93 || (DataType::BOOLEAN
== _eType2
);
98 case DataType::OBJECT
:
99 bIsCompatible
= (DataType::BLOB
== _eType2
)
100 || (DataType::CLOB
== _eType2
)
101 || (DataType::OBJECT
== _eType2
);
105 bIsCompatible
= false;
108 return bIsCompatible
;
111 bool isStorageComparable(sal_Int32 _eType1
, sal_Int32 _eType2
)
113 bool bIsComparable
= true;
115 if (_eType1
!= _eType2
)
117 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
121 case DataType::VARCHAR
:
122 case DataType::LONGVARCHAR
:
123 bIsComparable
= (DataType::CHAR
== _eType2
)
124 || (DataType::VARCHAR
== _eType2
)
125 || (DataType::LONGVARCHAR
== _eType2
);
128 case DataType::DECIMAL
:
129 case DataType::NUMERIC
:
130 bIsComparable
= (DataType::DECIMAL
== _eType2
)
131 || (DataType::NUMERIC
== _eType2
);
134 case DataType::DOUBLE
:
136 bIsComparable
= (DataType::DOUBLE
== _eType2
)
137 || (DataType::REAL
== _eType2
);
140 case DataType::BINARY
:
141 case DataType::VARBINARY
:
142 case DataType::LONGVARBINARY
:
143 bIsComparable
= (DataType::BINARY
== _eType2
)
144 || (DataType::VARBINARY
== _eType2
)
145 || (DataType::LONGVARBINARY
== _eType2
);
148 case DataType::INTEGER
:
149 bIsComparable
= (DataType::SMALLINT
== _eType2
)
150 || (DataType::TINYINT
== _eType2
)
151 || (DataType::BIT
== _eType2
)
152 || (DataType::BOOLEAN
== _eType2
);
154 case DataType::SMALLINT
:
155 bIsComparable
= (DataType::TINYINT
== _eType2
)
156 || (DataType::BIT
== _eType2
)
157 || (DataType::BOOLEAN
== _eType2
);
159 case DataType::TINYINT
:
160 bIsComparable
= (DataType::BIT
== _eType2
)
161 || (DataType::BOOLEAN
== _eType2
);
166 case DataType::OBJECT
:
167 bIsComparable
= (DataType::BLOB
== _eType2
)
168 || (DataType::CLOB
== _eType2
)
169 || (DataType::OBJECT
== _eType2
);
173 bIsComparable
= false;
176 return bIsComparable
;
180 void ORowSetValue::setTypeKind(sal_Int32 _eType
)
182 if ( !m_bNull
&& !isStorageCompatible(_eType
, m_eTypeKind
) )
186 case DataType::VARCHAR
:
188 case DataType::DECIMAL
:
189 case DataType::NUMERIC
:
190 case DataType::LONGVARCHAR
:
191 (*this) = getString();
193 case DataType::BIGINT
:
195 sal_Int64
nVal(getLong());
196 sal_uInt64
nuVal(getULong());
197 if (nVal
== 0 && nuVal
!= 0)
204 case DataType::FLOAT
:
205 (*this) = getFloat();
207 case DataType::DOUBLE
:
209 (*this) = getDouble();
211 case DataType::TINYINT
:
214 case DataType::SMALLINT
:
215 (*this) = getInt16();
217 case DataType::INTEGER
:
219 sal_Int32
nVal(getInt32());
220 sal_uInt32
nuVal(getUInt32());
221 if (nVal
== 0 && nuVal
!= 0)
228 case DataType::BOOLEAN
:
237 case DataType::TIMESTAMP
:
238 (*this) = getDateTime();
240 case DataType::BINARY
:
241 case DataType::VARBINARY
:
242 case DataType::LONGVARBINARY
:
243 (*this) = getSequence();
247 case DataType::OBJECT
:
248 case DataType::OTHER
:
253 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
257 m_eTypeKind
= _eType
;
261 void ORowSetValue::free() noexcept
269 case DataType::VARCHAR
:
270 case DataType::DECIMAL
:
271 case DataType::NUMERIC
:
272 case DataType::LONGVARCHAR
:
273 OSL_ENSURE(m_aValue
.m_pString
,"String pointer is null!");
274 rtl_uString_release(m_aValue
.m_pString
);
275 m_aValue
.m_pString
= nullptr;
278 delete static_cast<css::util::Date
*>(m_aValue
.m_pValue
);
279 m_aValue
.m_pValue
= nullptr;
282 delete static_cast<css::util::Time
*>(m_aValue
.m_pValue
);
283 m_aValue
.m_pValue
= nullptr;
285 case DataType::TIMESTAMP
:
286 delete static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
);
287 m_aValue
.m_pValue
= nullptr;
289 case DataType::BINARY
:
290 case DataType::VARBINARY
:
291 case DataType::LONGVARBINARY
:
292 delete static_cast<Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
293 m_aValue
.m_pValue
= nullptr;
297 case DataType::OBJECT
:
298 delete static_cast<Any
*>(m_aValue
.m_pValue
);
299 m_aValue
.m_pValue
= nullptr;
302 case DataType::TINYINT
:
303 case DataType::SMALLINT
:
304 case DataType::INTEGER
:
305 case DataType::BIGINT
:
306 case DataType::BOOLEAN
:
307 case DataType::FLOAT
:
308 case DataType::DOUBLE
:
312 if ( m_aValue
.m_pValue
)
314 delete static_cast<Any
*>(m_aValue
.m_pValue
);
315 m_aValue
.m_pValue
= nullptr;
323 ORowSetValue
& ORowSetValue::operator=(const ORowSetValue
& _rRH
)
328 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
|| (_rRH
.m_bNull
&& !m_bNull
) || m_bSigned
!= _rRH
.m_bSigned
)
331 m_bBound
= _rRH
.m_bBound
;
332 m_eTypeKind
= _rRH
.m_eTypeKind
;
333 m_bSigned
= _rRH
.m_bSigned
;
335 if(m_bNull
&& !_rRH
.m_bNull
)
337 switch(_rRH
.m_eTypeKind
)
340 case DataType::VARCHAR
:
341 case DataType::DECIMAL
:
342 case DataType::NUMERIC
:
343 case DataType::LONGVARCHAR
:
344 rtl_uString_acquire(_rRH
.m_aValue
.m_pString
);
345 m_aValue
.m_pString
= _rRH
.m_aValue
.m_pString
;
348 m_aValue
.m_pValue
= new Date(*static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
));
351 m_aValue
.m_pValue
= new Time(*static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
));
353 case DataType::TIMESTAMP
:
354 m_aValue
.m_pValue
= new DateTime(*static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
));
356 case DataType::BINARY
:
357 case DataType::VARBINARY
:
358 case DataType::LONGVARBINARY
:
359 m_aValue
.m_pValue
= new Sequence
<sal_Int8
>(*static_cast<Sequence
<sal_Int8
>*>(_rRH
.m_aValue
.m_pValue
));
362 case DataType::BOOLEAN
:
363 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
365 case DataType::TINYINT
:
366 if ( _rRH
.m_bSigned
)
367 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
369 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
371 case DataType::SMALLINT
:
372 if ( _rRH
.m_bSigned
)
373 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
375 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
377 case DataType::INTEGER
:
378 if ( _rRH
.m_bSigned
)
379 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
381 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
383 case DataType::BIGINT
:
384 if ( _rRH
.m_bSigned
)
385 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
387 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
389 case DataType::FLOAT
:
390 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
392 case DataType::DOUBLE
:
394 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
397 m_aValue
.m_pValue
= new Any(*static_cast<Any
*>(_rRH
.m_aValue
.m_pValue
));
400 else if(!_rRH
.m_bNull
)
402 switch(_rRH
.m_eTypeKind
)
405 case DataType::VARCHAR
:
406 case DataType::DECIMAL
:
407 case DataType::NUMERIC
:
408 case DataType::LONGVARCHAR
:
409 (*this) = OUString(_rRH
.m_aValue
.m_pString
);
412 (*this) = *static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
);
415 (*this) = *static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
);
417 case DataType::TIMESTAMP
:
418 (*this) = *static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
);
420 case DataType::BINARY
:
421 case DataType::VARBINARY
:
422 case DataType::LONGVARBINARY
:
423 (*this) = *static_cast<Sequence
<sal_Int8
>*>(_rRH
.m_aValue
.m_pValue
);
426 case DataType::BOOLEAN
:
427 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
429 case DataType::TINYINT
:
430 if ( _rRH
.m_bSigned
)
431 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
433 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
435 case DataType::SMALLINT
:
436 if ( _rRH
.m_bSigned
)
437 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
439 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
441 case DataType::INTEGER
:
442 if ( _rRH
.m_bSigned
)
443 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
445 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
447 case DataType::BIGINT
:
448 if ( _rRH
.m_bSigned
)
449 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
451 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
453 case DataType::FLOAT
:
454 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
456 case DataType::DOUBLE
:
458 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
461 *static_cast<Any
*>(m_aValue
.m_pValue
) = *static_cast<Any
*>(_rRH
.m_aValue
.m_pValue
);
465 m_bNull
= _rRH
.m_bNull
;
467 m_eTypeKind
= _rRH
.m_eTypeKind
;
472 ORowSetValue
& ORowSetValue::operator=(ORowSetValue
&& _rRH
) noexcept
474 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
|| !m_bNull
)
478 m_aValue
= _rRH
.m_aValue
;
479 memset(&_rRH
.m_aValue
, 0, sizeof(_rRH
.m_aValue
));
481 m_bBound
= _rRH
.m_bBound
;
482 m_eTypeKind
= _rRH
.m_eTypeKind
;
483 m_bSigned
= _rRH
.m_bSigned
;
484 m_bNull
= _rRH
.m_bNull
;
490 ORowSetValue
& ORowSetValue::operator=(const Date
& _rRH
)
492 if(m_eTypeKind
!= DataType::DATE
)
497 m_aValue
.m_pValue
= new Date(_rRH
);
498 m_eTypeKind
= DataType::DATE
;
502 *static_cast<Date
*>(m_aValue
.m_pValue
) = _rRH
;
507 ORowSetValue
& ORowSetValue::operator=(const css::util::Time
& _rRH
)
509 if(m_eTypeKind
!= DataType::TIME
)
514 m_aValue
.m_pValue
= new Time(_rRH
);
515 m_eTypeKind
= DataType::TIME
;
519 *static_cast<Time
*>(m_aValue
.m_pValue
) = _rRH
;
524 ORowSetValue
& ORowSetValue::operator=(const DateTime
& _rRH
)
526 if(m_eTypeKind
!= DataType::TIMESTAMP
)
530 m_aValue
.m_pValue
= new DateTime(_rRH
);
531 m_eTypeKind
= DataType::TIMESTAMP
;
535 *static_cast<DateTime
*>(m_aValue
.m_pValue
) = _rRH
;
541 ORowSetValue
& ORowSetValue::operator=(const OUString
& _rRH
)
543 if(m_eTypeKind
!= DataType::VARCHAR
|| m_aValue
.m_pString
!= _rRH
.pData
)
548 m_aValue
.m_pString
= _rRH
.pData
;
549 rtl_uString_acquire(m_aValue
.m_pString
);
550 m_eTypeKind
= DataType::VARCHAR
;
557 ORowSetValue
& ORowSetValue::operator=(double _rRH
)
559 if(m_eTypeKind
!= DataType::DOUBLE
)
562 m_aValue
.m_nDouble
= _rRH
;
563 m_eTypeKind
= DataType::DOUBLE
;
569 ORowSetValue
& ORowSetValue::operator=(float _rRH
)
571 if(m_eTypeKind
!= DataType::FLOAT
)
574 m_aValue
.m_nFloat
= _rRH
;
575 m_eTypeKind
= DataType::FLOAT
;
582 ORowSetValue
& ORowSetValue::operator=(sal_Int8 _rRH
)
584 if(m_eTypeKind
!= DataType::TINYINT
)
587 m_aValue
.m_nInt8
= _rRH
;
588 m_eTypeKind
= DataType::TINYINT
;
594 ORowSetValue
& ORowSetValue::operator=(sal_Int16 _rRH
)
596 if(m_eTypeKind
!= DataType::SMALLINT
)
599 m_aValue
.m_nInt16
= _rRH
;
600 m_eTypeKind
= DataType::SMALLINT
;
608 ORowSetValue
& ORowSetValue::operator=(sal_uInt16 _rRH
)
610 if(m_eTypeKind
!= DataType::SMALLINT
)
613 m_aValue
.m_uInt16
= _rRH
;
614 m_eTypeKind
= DataType::SMALLINT
;
622 ORowSetValue
& ORowSetValue::operator=(sal_Int32 _rRH
)
624 if(m_eTypeKind
!= DataType::INTEGER
)
627 m_aValue
.m_nInt32
= _rRH
;
629 m_eTypeKind
= DataType::INTEGER
;
637 ORowSetValue
& ORowSetValue::operator=(sal_uInt32 _rRH
)
639 if(m_eTypeKind
!= DataType::INTEGER
)
642 m_aValue
.m_uInt32
= _rRH
;
644 m_eTypeKind
= DataType::INTEGER
;
652 ORowSetValue
& ORowSetValue::operator=(const bool _rRH
)
654 if(m_eTypeKind
!= DataType::BIT
&& DataType::BOOLEAN
!= m_eTypeKind
)
657 m_aValue
.m_bBool
= _rRH
;
658 m_eTypeKind
= DataType::BOOLEAN
;
664 ORowSetValue
& ORowSetValue::operator=(sal_Int64 _rRH
)
666 if ( DataType::BIGINT
!= m_eTypeKind
)
669 m_aValue
.m_nInt64
= _rRH
;
670 m_eTypeKind
= DataType::BIGINT
;
677 ORowSetValue
& ORowSetValue::operator=(sal_uInt64 _rRH
)
679 if ( DataType::BIGINT
!= m_eTypeKind
)
682 m_aValue
.m_uInt64
= _rRH
;
683 m_eTypeKind
= DataType::BIGINT
;
690 ORowSetValue
& ORowSetValue::operator=(const Sequence
<sal_Int8
>& _rRH
)
692 if (!isStorageCompatible(DataType::LONGVARBINARY
,m_eTypeKind
))
697 m_aValue
.m_pValue
= new Sequence
<sal_Int8
>(_rRH
);
700 *static_cast< Sequence
< sal_Int8
>* >(m_aValue
.m_pValue
) = _rRH
;
702 m_eTypeKind
= DataType::LONGVARBINARY
;
708 ORowSetValue
& ORowSetValue::operator=(const Any
& _rAny
)
710 if (!isStorageCompatible(DataType::OBJECT
,m_eTypeKind
))
715 m_aValue
.m_pValue
= new Any(_rAny
);
718 *static_cast<Any
*>(m_aValue
.m_pValue
) = _rAny
;
720 m_eTypeKind
= DataType::OBJECT
;
727 bool ORowSetValue::operator==(const ORowSetValue
& _rRH
) const
729 if ( m_bNull
!= _rRH
.isNull() )
732 if(m_bNull
&& _rRH
.isNull())
735 if ( !isStorageComparable(m_eTypeKind
, _rRH
.m_eTypeKind
))
739 case DataType::FLOAT
:
740 case DataType::DOUBLE
:
742 return getDouble() == _rRH
.getDouble();
744 switch(_rRH
.m_eTypeKind
)
746 case DataType::FLOAT
:
747 case DataType::DOUBLE
:
749 return getDouble() == _rRH
.getDouble();
759 OSL_ENSURE(!m_bNull
,"Should not be null!");
762 case DataType::VARCHAR
:
764 case DataType::LONGVARCHAR
:
766 OUString
aVal1(m_aValue
.m_pString
);
767 OUString
aVal2(_rRH
.m_aValue
.m_pString
);
768 return aVal1
== aVal2
;
771 if ( m_bSigned
!= _rRH
.m_bSigned
)
778 case DataType::DECIMAL
:
779 case DataType::NUMERIC
:
781 OUString
aVal1(m_aValue
.m_pString
);
782 OUString
aVal2(_rRH
.m_aValue
.m_pString
);
783 bRet
= aVal1
== aVal2
;
786 case DataType::FLOAT
:
787 bRet
= m_aValue
.m_nFloat
== _rRH
.m_aValue
.m_nFloat
;
789 case DataType::DOUBLE
:
791 bRet
= m_aValue
.m_nDouble
== _rRH
.m_aValue
.m_nDouble
;
793 case DataType::TINYINT
:
794 bRet
= m_bSigned
? ( m_aValue
.m_nInt8
== _rRH
.m_aValue
.m_nInt8
) : (m_aValue
.m_uInt8
== _rRH
.m_aValue
.m_uInt8
);
796 case DataType::SMALLINT
:
797 bRet
= m_bSigned
? ( m_aValue
.m_nInt16
== _rRH
.m_aValue
.m_nInt16
) : (m_aValue
.m_uInt16
== _rRH
.m_aValue
.m_uInt16
);
799 case DataType::INTEGER
:
800 bRet
= m_bSigned
? ( m_aValue
.m_nInt32
== _rRH
.m_aValue
.m_nInt32
) : (m_aValue
.m_uInt32
== _rRH
.m_aValue
.m_uInt32
);
802 case DataType::BIGINT
:
803 bRet
= m_bSigned
? ( m_aValue
.m_nInt64
== _rRH
.m_aValue
.m_nInt64
) : (m_aValue
.m_uInt64
== _rRH
.m_aValue
.m_uInt64
);
806 case DataType::BOOLEAN
:
807 bRet
= m_aValue
.m_bBool
== _rRH
.m_aValue
.m_bBool
;
810 bRet
= *static_cast<Date
*>(m_aValue
.m_pValue
) == *static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
);
813 bRet
= *static_cast<Time
*>(m_aValue
.m_pValue
) == *static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
);
815 case DataType::TIMESTAMP
:
816 bRet
= *static_cast<DateTime
*>(m_aValue
.m_pValue
) == *static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
);
818 case DataType::BINARY
:
819 case DataType::VARBINARY
:
820 case DataType::LONGVARBINARY
:
823 case DataType::OBJECT
:
824 case DataType::OTHER
:
829 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
835 Any
ORowSetValue::makeAny() const
838 if(isBound() && !isNull())
840 switch(getTypeKind())
842 case DataType::SQLNULL
:
843 assert(rValue
== Any());
846 case DataType::VARCHAR
:
847 case DataType::DECIMAL
:
848 case DataType::NUMERIC
:
849 case DataType::LONGVARCHAR
:
850 OSL_ENSURE(m_aValue
.m_pString
,"Value is null!");
851 rValue
<<= OUString(m_aValue
.m_pString
);
853 case DataType::FLOAT
:
854 rValue
<<= m_aValue
.m_nFloat
;
856 case DataType::DOUBLE
:
858 rValue
<<= m_aValue
.m_nDouble
;
861 assert(m_aValue
.m_pValue
&& "Value is null!");
862 rValue
<<= *static_cast<Date
*>(m_aValue
.m_pValue
);
865 assert(m_aValue
.m_pValue
&& "Value is null!");
866 rValue
<<= *static_cast<Time
*>(m_aValue
.m_pValue
);
868 case DataType::TIMESTAMP
:
869 assert(m_aValue
.m_pValue
&& "Value is null!");
870 rValue
<<= *static_cast<DateTime
*>(m_aValue
.m_pValue
);
872 case DataType::BINARY
:
873 case DataType::VARBINARY
:
874 case DataType::LONGVARBINARY
:
875 assert(m_aValue
.m_pValue
&& "Value is null!");
876 rValue
<<= *static_cast<Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
880 case DataType::OBJECT
:
881 case DataType::OTHER
:
885 case DataType::BOOLEAN
:
886 rValue
<<= m_aValue
.m_bBool
;
888 case DataType::TINYINT
:
891 rValue
<<= m_aValue
.m_nInt8
;
893 // There is no TypeClass_UNSIGNED_BYTE,
894 // so silently promote it to a 16-bit integer,
895 // that is TypeClass_UNSIGNED_SHORT
896 rValue
<<= static_cast<sal_uInt16
>(m_aValue
.m_uInt8
);
898 case DataType::SMALLINT
:
901 rValue
<<= m_aValue
.m_nInt16
;
903 // TypeClass_UNSIGNED_SHORT
904 rValue
<<= m_aValue
.m_uInt16
;
906 case DataType::INTEGER
:
909 rValue
<<= m_aValue
.m_nInt32
;
911 // TypeClass_UNSIGNED_LONG
912 rValue
<<= m_aValue
.m_uInt32
;
914 case DataType::BIGINT
:
917 rValue
<<= m_aValue
.m_nInt64
;
919 // TypeClass_UNSIGNED_HYPER
920 rValue
<<= m_aValue
.m_uInt64
;
923 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
931 OUString
ORowSetValue::getString( ) const
936 switch(getTypeKind())
939 case DataType::VARCHAR
:
940 case DataType::DECIMAL
:
941 case DataType::NUMERIC
:
942 case DataType::LONGVARCHAR
:
943 aRet
= m_aValue
.m_pString
;
945 case DataType::FLOAT
:
946 aRet
= OUString::number(getFloat());
948 case DataType::DOUBLE
:
950 aRet
= OUString::number(getDouble());
953 aRet
= DBTypeConversion::toDateString(getDate());
956 aRet
= DBTypeConversion::toTimeString(getTime());
958 case DataType::TIMESTAMP
:
959 aRet
= DBTypeConversion::toDateTimeString(getDateTime());
961 case DataType::BINARY
:
962 case DataType::VARBINARY
:
963 case DataType::LONGVARBINARY
:
965 OUStringBuffer
sVal("0x");
966 for (sal_Int32 byte
: getSequence())
967 sVal
.append(byte
, 16);
968 aRet
= sVal
.makeStringAndClear();
972 aRet
= OUString::number(int(getBool()));
974 case DataType::BOOLEAN
:
975 aRet
= OUString::boolean(getBool());
977 case DataType::TINYINT
:
978 case DataType::SMALLINT
:
979 case DataType::INTEGER
:
981 aRet
= OUString::number(getInt32());
983 aRet
= OUString::number(getUInt32());
985 case DataType::BIGINT
:
987 aRet
= OUString::number(getLong());
989 aRet
= OUString::number(getULong());
993 Any
aValue( getAny() );
994 Reference
< XClob
> xClob
;
995 if ( (aValue
>>= xClob
) && xClob
.is() )
997 aRet
= xClob
->getSubString(1,static_cast<sal_Int32
>(xClob
->length()) );
1003 Any aValue
= makeAny();
1012 bool ORowSetValue::getBool() const
1017 switch(getTypeKind())
1019 case DataType::CHAR
:
1020 case DataType::VARCHAR
:
1021 case DataType::LONGVARCHAR
:
1023 const OUString
sValue(m_aValue
.m_pString
);
1024 if ( sValue
.equalsIgnoreAsciiCase("true") || (sValue
== "1") )
1029 else if ( sValue
.equalsIgnoreAsciiCase("false") || (sValue
== "0") )
1036 case DataType::DECIMAL
:
1037 case DataType::NUMERIC
:
1039 bRet
= OUString::unacquired(&m_aValue
.m_pString
).toInt32() != 0;
1041 case DataType::FLOAT
:
1042 bRet
= m_aValue
.m_nFloat
!= 0.0;
1044 case DataType::DOUBLE
:
1045 case DataType::REAL
:
1046 bRet
= m_aValue
.m_nDouble
!= 0.0;
1048 case DataType::DATE
:
1049 case DataType::TIME
:
1050 case DataType::TIMESTAMP
:
1051 case DataType::BINARY
:
1052 case DataType::VARBINARY
:
1053 case DataType::LONGVARBINARY
:
1054 OSL_FAIL("getBool() for this type is not allowed!");
1057 case DataType::BOOLEAN
:
1058 bRet
= m_aValue
.m_bBool
;
1060 case DataType::TINYINT
:
1061 bRet
= m_bSigned
? (m_aValue
.m_nInt8
!= 0) : (m_aValue
.m_uInt8
!= 0);
1063 case DataType::SMALLINT
:
1064 bRet
= m_bSigned
? (m_aValue
.m_nInt16
!= 0) : (m_aValue
.m_uInt16
!= 0);
1066 case DataType::INTEGER
:
1067 bRet
= m_bSigned
? (m_aValue
.m_nInt32
!= 0) : (m_aValue
.m_uInt32
!= 0);
1069 case DataType::BIGINT
:
1070 bRet
= m_bSigned
? (m_aValue
.m_nInt64
!= 0) : (m_aValue
.m_uInt64
!= 0);
1074 Any aValue
= makeAny();
1084 sal_Int8
ORowSetValue::getInt8() const
1089 switch(getTypeKind())
1091 case DataType::CHAR
:
1092 case DataType::VARCHAR
:
1093 case DataType::DECIMAL
:
1094 case DataType::NUMERIC
:
1095 case DataType::LONGVARCHAR
:
1096 nRet
= sal_Int8(OUString::unacquired(&m_aValue
.m_pString
).toInt32());
1098 case DataType::FLOAT
:
1099 nRet
= sal_Int8(m_aValue
.m_nFloat
);
1101 case DataType::DOUBLE
:
1102 case DataType::REAL
:
1103 nRet
= sal_Int8(m_aValue
.m_nDouble
);
1105 case DataType::DATE
:
1106 case DataType::TIME
:
1107 case DataType::TIMESTAMP
:
1108 case DataType::BINARY
:
1109 case DataType::VARBINARY
:
1110 case DataType::LONGVARBINARY
:
1111 case DataType::BLOB
:
1112 case DataType::CLOB
:
1113 OSL_FAIL("getInt8() for this type is not allowed!");
1116 case DataType::BOOLEAN
:
1117 nRet
= sal_Int8(m_aValue
.m_bBool
);
1119 case DataType::TINYINT
:
1121 nRet
= m_aValue
.m_nInt8
;
1123 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt8
);
1125 case DataType::SMALLINT
:
1127 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt16
);
1129 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt16
);
1131 case DataType::INTEGER
:
1133 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt32
);
1135 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt32
);
1137 case DataType::BIGINT
:
1139 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt64
);
1141 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt64
);
1145 Any aValue
= makeAny();
1155 sal_uInt8
ORowSetValue::getUInt8() const
1160 switch(getTypeKind())
1162 case DataType::CHAR
:
1163 case DataType::VARCHAR
:
1164 case DataType::DECIMAL
:
1165 case DataType::NUMERIC
:
1166 case DataType::LONGVARCHAR
:
1167 nRet
= sal_uInt8(OUString::unacquired(&m_aValue
.m_pString
).toInt32());
1169 case DataType::FLOAT
:
1170 nRet
= sal_uInt8(m_aValue
.m_nFloat
);
1172 case DataType::DOUBLE
:
1173 case DataType::REAL
:
1174 nRet
= sal_uInt8(m_aValue
.m_nDouble
);
1176 case DataType::DATE
:
1177 case DataType::TIME
:
1178 case DataType::TIMESTAMP
:
1179 case DataType::BINARY
:
1180 case DataType::VARBINARY
:
1181 case DataType::LONGVARBINARY
:
1182 case DataType::BLOB
:
1183 case DataType::CLOB
:
1184 OSL_FAIL("getuInt8() for this type is not allowed!");
1187 case DataType::BOOLEAN
:
1188 nRet
= int(m_aValue
.m_bBool
);
1190 case DataType::TINYINT
:
1192 nRet
= m_aValue
.m_nInt8
;
1194 nRet
= m_aValue
.m_uInt8
;
1196 case DataType::SMALLINT
:
1198 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt16
);
1200 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt16
);
1202 case DataType::INTEGER
:
1204 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt32
);
1206 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt32
);
1208 case DataType::BIGINT
:
1210 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt64
);
1212 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt64
);
1216 Any aValue
= makeAny();
1217 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1220 nRet
= static_cast<sal_uInt8
>(n
);
1230 sal_Int16
ORowSetValue::getInt16() const
1235 switch(getTypeKind())
1237 case DataType::CHAR
:
1238 case DataType::VARCHAR
:
1239 case DataType::DECIMAL
:
1240 case DataType::NUMERIC
:
1241 case DataType::LONGVARCHAR
:
1242 nRet
= sal_Int16(OUString::unacquired(&m_aValue
.m_pString
).toInt32());
1244 case DataType::FLOAT
:
1245 nRet
= sal_Int16(m_aValue
.m_nFloat
);
1247 case DataType::DOUBLE
:
1248 case DataType::REAL
:
1249 nRet
= sal_Int16(m_aValue
.m_nDouble
);
1251 case DataType::DATE
:
1252 case DataType::TIME
:
1253 case DataType::TIMESTAMP
:
1254 case DataType::BINARY
:
1255 case DataType::VARBINARY
:
1256 case DataType::LONGVARBINARY
:
1257 case DataType::BLOB
:
1258 case DataType::CLOB
:
1259 OSL_FAIL("getInt16() for this type is not allowed!");
1262 case DataType::BOOLEAN
:
1263 nRet
= sal_Int16(m_aValue
.m_bBool
);
1265 case DataType::TINYINT
:
1267 nRet
= m_aValue
.m_nInt8
;
1269 nRet
= m_aValue
.m_uInt8
;
1271 case DataType::SMALLINT
:
1273 nRet
= m_aValue
.m_nInt16
;
1275 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt16
);
1277 case DataType::INTEGER
:
1279 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt32
);
1281 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt32
);
1283 case DataType::BIGINT
:
1285 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt64
);
1287 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt64
);
1291 Any aValue
= makeAny();
1301 sal_uInt16
ORowSetValue::getUInt16() const
1303 sal_uInt16 nRet
= 0;
1306 switch(getTypeKind())
1308 case DataType::CHAR
:
1309 case DataType::VARCHAR
:
1310 case DataType::DECIMAL
:
1311 case DataType::NUMERIC
:
1312 case DataType::LONGVARCHAR
:
1313 nRet
= sal_uInt16(OUString::unacquired(&m_aValue
.m_pString
).toInt32());
1315 case DataType::FLOAT
:
1316 nRet
= sal_uInt16(m_aValue
.m_nFloat
);
1318 case DataType::DOUBLE
:
1319 case DataType::REAL
:
1320 nRet
= sal_uInt16(m_aValue
.m_nDouble
);
1322 case DataType::DATE
:
1323 case DataType::TIME
:
1324 case DataType::TIMESTAMP
:
1325 case DataType::BINARY
:
1326 case DataType::VARBINARY
:
1327 case DataType::LONGVARBINARY
:
1328 case DataType::BLOB
:
1329 case DataType::CLOB
:
1330 OSL_FAIL("getuInt16() for this type is not allowed!");
1333 case DataType::BOOLEAN
:
1334 nRet
= sal_uInt16(m_aValue
.m_bBool
);
1336 case DataType::TINYINT
:
1338 nRet
= m_aValue
.m_nInt8
;
1340 nRet
= m_aValue
.m_uInt8
;
1342 case DataType::SMALLINT
:
1344 nRet
= m_aValue
.m_nInt16
;
1346 nRet
= m_aValue
.m_uInt16
;
1348 case DataType::INTEGER
:
1350 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt32
);
1352 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt32
);
1354 case DataType::BIGINT
:
1356 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt64
);
1358 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt64
);
1362 Any aValue
= makeAny();
1372 sal_Int32
ORowSetValue::getInt32() const
1377 switch(getTypeKind())
1379 case DataType::CHAR
:
1380 case DataType::VARCHAR
:
1381 case DataType::DECIMAL
:
1382 case DataType::NUMERIC
:
1383 case DataType::LONGVARCHAR
:
1384 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toInt32();
1386 case DataType::FLOAT
:
1387 nRet
= sal_Int32(m_aValue
.m_nFloat
);
1389 case DataType::DOUBLE
:
1390 case DataType::REAL
:
1391 nRet
= sal_Int32(m_aValue
.m_nDouble
);
1393 case DataType::DATE
:
1394 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1396 case DataType::TIME
:
1397 case DataType::TIMESTAMP
:
1398 case DataType::BINARY
:
1399 case DataType::VARBINARY
:
1400 case DataType::LONGVARBINARY
:
1401 case DataType::BLOB
:
1402 case DataType::CLOB
:
1403 OSL_FAIL("getInt32() for this type is not allowed!");
1406 case DataType::BOOLEAN
:
1407 nRet
= sal_Int32(m_aValue
.m_bBool
);
1409 case DataType::TINYINT
:
1411 nRet
= m_aValue
.m_nInt8
;
1413 nRet
= m_aValue
.m_uInt8
;
1415 case DataType::SMALLINT
:
1417 nRet
= m_aValue
.m_nInt16
;
1419 nRet
= m_aValue
.m_uInt16
;
1421 case DataType::INTEGER
:
1423 nRet
= m_aValue
.m_nInt32
;
1425 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt32
);
1427 case DataType::BIGINT
:
1429 nRet
= static_cast<sal_Int32
>(m_aValue
.m_nInt64
);
1431 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt64
);
1435 Any aValue
= makeAny();
1445 sal_uInt32
ORowSetValue::getUInt32() const
1447 sal_uInt32 nRet
= 0;
1450 switch(getTypeKind())
1452 case DataType::CHAR
:
1453 case DataType::VARCHAR
:
1454 case DataType::DECIMAL
:
1455 case DataType::NUMERIC
:
1456 case DataType::LONGVARCHAR
:
1457 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toUInt32();
1459 case DataType::FLOAT
:
1460 nRet
= sal_uInt32(m_aValue
.m_nFloat
);
1462 case DataType::DOUBLE
:
1463 case DataType::REAL
:
1464 nRet
= sal_uInt32(m_aValue
.m_nDouble
);
1466 case DataType::DATE
:
1467 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1469 case DataType::TIME
:
1470 case DataType::TIMESTAMP
:
1471 case DataType::BINARY
:
1472 case DataType::VARBINARY
:
1473 case DataType::LONGVARBINARY
:
1474 case DataType::BLOB
:
1475 case DataType::CLOB
:
1476 OSL_FAIL("getuInt32() for this type is not allowed!");
1479 case DataType::BOOLEAN
:
1480 nRet
= sal_uInt32(m_aValue
.m_bBool
);
1482 case DataType::TINYINT
:
1484 nRet
= m_aValue
.m_nInt8
;
1486 nRet
= m_aValue
.m_uInt8
;
1488 case DataType::SMALLINT
:
1490 nRet
= m_aValue
.m_nInt16
;
1492 nRet
= m_aValue
.m_uInt16
;
1494 case DataType::INTEGER
:
1496 nRet
= m_aValue
.m_nInt32
;
1498 nRet
= m_aValue
.m_uInt32
;
1500 case DataType::BIGINT
:
1502 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_nInt64
);
1504 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_uInt64
);
1508 Any aValue
= makeAny();
1518 sal_Int64
ORowSetValue::getLong() const
1523 switch(getTypeKind())
1525 case DataType::CHAR
:
1526 case DataType::VARCHAR
:
1527 case DataType::DECIMAL
:
1528 case DataType::NUMERIC
:
1529 case DataType::LONGVARCHAR
:
1530 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toInt64();
1532 case DataType::FLOAT
:
1533 nRet
= sal_Int64(m_aValue
.m_nFloat
);
1535 case DataType::DOUBLE
:
1536 case DataType::REAL
:
1537 nRet
= sal_Int64(m_aValue
.m_nDouble
);
1539 case DataType::DATE
:
1540 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1542 case DataType::TIME
:
1543 case DataType::TIMESTAMP
:
1544 case DataType::BINARY
:
1545 case DataType::VARBINARY
:
1546 case DataType::LONGVARBINARY
:
1547 case DataType::BLOB
:
1548 case DataType::CLOB
:
1549 OSL_FAIL("getLong() for this type is not allowed!");
1552 case DataType::BOOLEAN
:
1553 nRet
= sal_Int64(m_aValue
.m_bBool
);
1555 case DataType::TINYINT
:
1557 nRet
= m_aValue
.m_nInt8
;
1559 nRet
= m_aValue
.m_uInt8
;
1561 case DataType::SMALLINT
:
1563 nRet
= m_aValue
.m_nInt16
;
1565 nRet
= m_aValue
.m_uInt16
;
1567 case DataType::INTEGER
:
1569 nRet
= m_aValue
.m_nInt32
;
1571 nRet
= m_aValue
.m_uInt32
;
1573 case DataType::BIGINT
:
1575 nRet
= m_aValue
.m_nInt64
;
1577 nRet
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
1581 Any aValue
= makeAny();
1591 sal_uInt64
ORowSetValue::getULong() const
1593 sal_uInt64 nRet
= 0;
1596 switch(getTypeKind())
1598 case DataType::CHAR
:
1599 case DataType::VARCHAR
:
1600 case DataType::DECIMAL
:
1601 case DataType::NUMERIC
:
1602 case DataType::LONGVARCHAR
:
1603 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toUInt64();
1605 case DataType::FLOAT
:
1606 nRet
= sal_uInt64(m_aValue
.m_nFloat
);
1608 case DataType::DOUBLE
:
1609 case DataType::REAL
:
1610 nRet
= sal_uInt64(m_aValue
.m_nDouble
);
1612 case DataType::DATE
:
1613 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1615 case DataType::TIME
:
1616 case DataType::TIMESTAMP
:
1617 case DataType::BINARY
:
1618 case DataType::VARBINARY
:
1619 case DataType::LONGVARBINARY
:
1620 case DataType::BLOB
:
1621 case DataType::CLOB
:
1622 OSL_FAIL("getULong() for this type is not allowed!");
1625 case DataType::BOOLEAN
:
1626 nRet
= sal_uInt64(m_aValue
.m_bBool
);
1628 case DataType::TINYINT
:
1630 nRet
= m_aValue
.m_nInt8
;
1632 nRet
= m_aValue
.m_uInt8
;
1634 case DataType::SMALLINT
:
1636 nRet
= m_aValue
.m_nInt16
;
1638 nRet
= m_aValue
.m_uInt16
;
1640 case DataType::INTEGER
:
1642 nRet
= m_aValue
.m_nInt32
;
1644 nRet
= m_aValue
.m_uInt32
;
1646 case DataType::BIGINT
:
1648 nRet
= m_aValue
.m_nInt64
;
1650 nRet
= m_aValue
.m_uInt64
;
1654 Any aValue
= makeAny();
1664 float ORowSetValue::getFloat() const
1669 switch(getTypeKind())
1671 case DataType::CHAR
:
1672 case DataType::VARCHAR
:
1673 case DataType::DECIMAL
:
1674 case DataType::NUMERIC
:
1675 case DataType::LONGVARCHAR
:
1676 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toFloat();
1678 case DataType::FLOAT
:
1679 nRet
= m_aValue
.m_nFloat
;
1681 case DataType::DOUBLE
:
1682 case DataType::REAL
:
1683 nRet
= static_cast<float>(m_aValue
.m_nDouble
);
1685 case DataType::DATE
:
1686 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
)));
1688 case DataType::TIME
:
1689 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
)));
1691 case DataType::TIMESTAMP
:
1692 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
)));
1694 case DataType::BINARY
:
1695 case DataType::VARBINARY
:
1696 case DataType::LONGVARBINARY
:
1697 case DataType::BLOB
:
1698 case DataType::CLOB
:
1699 OSL_FAIL("getDouble() for this type is not allowed!");
1702 case DataType::BOOLEAN
:
1703 nRet
= float(m_aValue
.m_bBool
);
1705 case DataType::TINYINT
:
1707 nRet
= m_aValue
.m_nInt8
;
1709 nRet
= m_aValue
.m_uInt8
;
1711 case DataType::SMALLINT
:
1713 nRet
= m_aValue
.m_nInt16
;
1715 nRet
= static_cast<float>(m_aValue
.m_uInt16
);
1717 case DataType::INTEGER
:
1719 nRet
= static_cast<float>(m_aValue
.m_nInt32
);
1721 nRet
= static_cast<float>(m_aValue
.m_uInt32
);
1723 case DataType::BIGINT
:
1725 nRet
= static_cast<float>(m_aValue
.m_nInt64
);
1727 nRet
= static_cast<float>(m_aValue
.m_uInt64
);
1731 Any aValue
= makeAny();
1740 double ORowSetValue::getDouble() const
1745 switch(getTypeKind())
1747 case DataType::CHAR
:
1748 case DataType::VARCHAR
:
1749 case DataType::DECIMAL
:
1750 case DataType::NUMERIC
:
1751 case DataType::LONGVARCHAR
:
1752 nRet
= OUString::unacquired(&m_aValue
.m_pString
).toDouble();
1754 case DataType::FLOAT
:
1755 nRet
= m_aValue
.m_nFloat
;
1757 case DataType::DOUBLE
:
1758 case DataType::REAL
:
1759 nRet
= m_aValue
.m_nDouble
;
1761 case DataType::DATE
:
1762 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1764 case DataType::TIME
:
1765 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
));
1767 case DataType::TIMESTAMP
:
1768 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
));
1770 case DataType::BINARY
:
1771 case DataType::VARBINARY
:
1772 case DataType::LONGVARBINARY
:
1773 case DataType::BLOB
:
1774 case DataType::CLOB
:
1775 OSL_FAIL("getDouble() for this type is not allowed!");
1778 case DataType::BOOLEAN
:
1779 nRet
= double(m_aValue
.m_bBool
);
1781 case DataType::TINYINT
:
1783 nRet
= m_aValue
.m_nInt8
;
1785 nRet
= m_aValue
.m_uInt8
;
1787 case DataType::SMALLINT
:
1789 nRet
= m_aValue
.m_nInt16
;
1791 nRet
= m_aValue
.m_uInt16
;
1793 case DataType::INTEGER
:
1795 nRet
= m_aValue
.m_nInt32
;
1797 nRet
= m_aValue
.m_uInt32
;
1799 case DataType::BIGINT
:
1801 nRet
= m_aValue
.m_nInt64
;
1803 nRet
= m_aValue
.m_uInt64
;
1807 Any aValue
= makeAny();
1816 Sequence
<sal_Int8
> ORowSetValue::getSequence() const
1818 Sequence
<sal_Int8
> aSeq
;
1823 case DataType::OBJECT
:
1824 case DataType::CLOB
:
1825 case DataType::BLOB
:
1827 Reference
<XInputStream
> xStream
;
1828 const Any aValue
= makeAny();
1829 if(aValue
.hasValue())
1831 Reference
<XBlob
> xBlob(aValue
,UNO_QUERY
);
1833 xStream
= xBlob
->getBinaryStream();
1836 Reference
<XClob
> xClob(aValue
,UNO_QUERY
);
1838 xStream
= xClob
->getCharacterStream();
1842 const sal_uInt32 nBytesToRead
= 65535;
1847 css::uno::Sequence
< sal_Int8
> aReadSeq
;
1849 nRead
= xStream
->readSomeBytes( aReadSeq
, nBytesToRead
);
1853 const sal_uInt32 nOldLength
= aSeq
.getLength();
1854 aSeq
.realloc( nOldLength
+ nRead
);
1855 memcpy( aSeq
.getArray() + nOldLength
, aReadSeq
.getConstArray(), aReadSeq
.getLength() );
1858 while( nBytesToRead
== nRead
);
1859 xStream
->closeInput();
1864 case DataType::VARCHAR
:
1865 case DataType::LONGVARCHAR
:
1867 aSeq
= Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(m_aValue
.m_pString
->buffer
),
1868 sizeof(sal_Unicode
) * m_aValue
.m_pString
->length
);
1871 case DataType::BINARY
:
1872 case DataType::VARBINARY
:
1873 case DataType::LONGVARBINARY
:
1874 aSeq
= *static_cast< Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
1878 Any aValue
= makeAny();
1888 css::util::Date
ORowSetValue::getDate() const
1890 css::util::Date aValue
;
1895 case DataType::CHAR
:
1896 case DataType::VARCHAR
:
1897 case DataType::LONGVARCHAR
:
1898 aValue
= DBTypeConversion::toDate(getString());
1900 case DataType::DECIMAL
:
1901 case DataType::NUMERIC
:
1902 case DataType::FLOAT
:
1903 case DataType::DOUBLE
:
1904 case DataType::REAL
:
1905 aValue
= DBTypeConversion::toDate(getDouble());
1908 case DataType::DATE
:
1909 aValue
= *static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
1911 case DataType::TIMESTAMP
:
1913 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1914 aValue
.Day
= pDateTime
->Day
;
1915 aValue
.Month
= pDateTime
->Month
;
1916 aValue
.Year
= pDateTime
->Year
;
1920 case DataType::BOOLEAN
:
1921 case DataType::TINYINT
:
1922 case DataType::SMALLINT
:
1923 case DataType::INTEGER
:
1924 case DataType::BIGINT
:
1925 aValue
= DBTypeConversion::toDate( double( getLong() ) );
1928 case DataType::BLOB
:
1929 case DataType::CLOB
:
1930 case DataType::OBJECT
:
1932 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1935 case DataType::BINARY
:
1936 case DataType::VARBINARY
:
1937 case DataType::LONGVARBINARY
:
1938 case DataType::TIME
:
1939 aValue
= DBTypeConversion::toDate( double(0) );
1946 css::util::Time
ORowSetValue::getTime() const
1948 css::util::Time aValue
;
1953 case DataType::CHAR
:
1954 case DataType::VARCHAR
:
1955 case DataType::LONGVARCHAR
:
1956 aValue
= DBTypeConversion::toTime(getString());
1958 case DataType::DECIMAL
:
1959 case DataType::NUMERIC
:
1960 case DataType::FLOAT
:
1961 case DataType::DOUBLE
:
1962 case DataType::REAL
:
1963 aValue
= DBTypeConversion::toTime(getDouble());
1965 case DataType::TIMESTAMP
:
1967 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1968 aValue
.NanoSeconds
= pDateTime
->NanoSeconds
;
1969 aValue
.Seconds
= pDateTime
->Seconds
;
1970 aValue
.Minutes
= pDateTime
->Minutes
;
1971 aValue
.Hours
= pDateTime
->Hours
;
1974 case DataType::TIME
:
1975 aValue
= *static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
1979 Any aAnyValue
= makeAny();
1980 aAnyValue
>>= aValue
;
1988 css::util::DateTime
ORowSetValue::getDateTime() const
1990 css::util::DateTime aValue
;
1995 case DataType::CHAR
:
1996 case DataType::VARCHAR
:
1997 case DataType::LONGVARCHAR
:
1998 aValue
= DBTypeConversion::toDateTime(getString());
2000 case DataType::DECIMAL
:
2001 case DataType::NUMERIC
:
2002 case DataType::FLOAT
:
2003 case DataType::DOUBLE
:
2004 case DataType::REAL
:
2005 aValue
= DBTypeConversion::toDateTime(getDouble());
2007 case DataType::DATE
:
2009 css::util::Date
* pDate
= static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
2010 aValue
.Day
= pDate
->Day
;
2011 aValue
.Month
= pDate
->Month
;
2012 aValue
.Year
= pDate
->Year
;
2015 case DataType::TIME
:
2017 css::util::Time
* pTime
= static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
2018 aValue
.NanoSeconds
= pTime
->NanoSeconds
;
2019 aValue
.Seconds
= pTime
->Seconds
;
2020 aValue
.Minutes
= pTime
->Minutes
;
2021 aValue
.Hours
= pTime
->Hours
;
2024 case DataType::TIMESTAMP
:
2025 aValue
= *static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
2029 Any aAnyValue
= makeAny();
2030 aAnyValue
>>= aValue
;
2038 void ORowSetValue::setSigned(bool _bMod
)
2040 if ( m_bSigned
== _bMod
)
2047 sal_Int32 nType
= m_eTypeKind
;
2050 case DataType::TINYINT
:
2052 (*this) = getInt8();
2055 m_bSigned
= !m_bSigned
;
2056 (*this) = getInt16();
2057 m_bSigned
= !m_bSigned
;
2060 case DataType::SMALLINT
:
2062 (*this) = getInt16();
2065 m_bSigned
= !m_bSigned
;
2066 (*this) = getInt32();
2067 m_bSigned
= !m_bSigned
;
2070 case DataType::INTEGER
:
2072 (*this) = getInt32();
2075 m_bSigned
= !m_bSigned
;
2076 (*this) = getLong();
2077 m_bSigned
= !m_bSigned
;
2080 case DataType::BIGINT
:
2084 auto nTmp
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
2085 m_aValue
.m_nInt64
= nTmp
;
2089 auto nTmp
= static_cast<sal_uInt64
>(m_aValue
.m_nInt64
);
2090 m_aValue
.m_uInt64
= nTmp
;
2095 m_eTypeKind
= nType
;
2101 class SAL_NO_VTABLE IValueSource
2104 virtual OUString
getString() const = 0;
2105 virtual bool getBoolean() const = 0;
2106 virtual sal_Int8
getByte() const = 0;
2107 virtual sal_Int16
getShort() const = 0;
2108 virtual sal_Int32
getInt() const = 0;
2109 virtual sal_Int64
getLong() const = 0;
2110 virtual float getFloat() const = 0;
2111 virtual double getDouble() const = 0;
2112 virtual Date
getDate() const = 0;
2113 virtual css::util::Time
getTime() const = 0;
2114 virtual DateTime
getTimestamp() const = 0;
2115 virtual Sequence
< sal_Int8
> getBytes() const = 0;
2116 virtual Reference
< XBlob
> getBlob() const = 0;
2117 virtual Reference
< XClob
> getClob() const = 0;
2118 virtual Any
getObject() const = 0;
2119 virtual bool wasNull() const = 0;
2121 virtual ~IValueSource() { }
2126 class RowValue
: public IValueSource
2129 RowValue( const Reference
< XRow
>& _xRow
, const sal_Int32 _nPos
)
2136 virtual OUString
getString() const override
{ return m_xRow
->getString( m_nPos
); };
2137 virtual bool getBoolean() const override
{ return m_xRow
->getBoolean( m_nPos
); };
2138 virtual sal_Int8
getByte() const override
{ return m_xRow
->getByte( m_nPos
); };
2139 virtual sal_Int16
getShort() const override
{ return m_xRow
->getShort( m_nPos
); }
2140 virtual sal_Int32
getInt() const override
{ return m_xRow
->getInt( m_nPos
); }
2141 virtual sal_Int64
getLong() const override
{ return m_xRow
->getLong( m_nPos
); }
2142 virtual float getFloat() const override
{ return m_xRow
->getFloat( m_nPos
); };
2143 virtual double getDouble() const override
{ return m_xRow
->getDouble( m_nPos
); };
2144 virtual Date
getDate() const override
{ return m_xRow
->getDate( m_nPos
); };
2145 virtual css::util::Time
getTime() const override
{ return m_xRow
->getTime( m_nPos
); };
2146 virtual DateTime
getTimestamp() const override
{ return m_xRow
->getTimestamp( m_nPos
); };
2147 virtual Sequence
< sal_Int8
> getBytes() const override
{ return m_xRow
->getBytes( m_nPos
); };
2148 virtual Reference
< XBlob
> getBlob() const override
{ return m_xRow
->getBlob( m_nPos
); };
2149 virtual Reference
< XClob
> getClob() const override
{ return m_xRow
->getClob( m_nPos
); };
2150 virtual Any
getObject() const override
{ return m_xRow
->getObject( m_nPos
,nullptr); };
2151 virtual bool wasNull() const override
{ return m_xRow
->wasNull( ); };
2154 const Reference
< XRow
> m_xRow
;
2155 const sal_Int32 m_nPos
;
2158 class ColumnValue
: public IValueSource
2161 explicit ColumnValue( const Reference
< XColumn
>& _rxColumn
)
2162 :m_xColumn( _rxColumn
)
2167 virtual OUString
getString() const override
{ return m_xColumn
->getString(); };
2168 virtual bool getBoolean() const override
{ return m_xColumn
->getBoolean(); };
2169 virtual sal_Int8
getByte() const override
{ return m_xColumn
->getByte(); };
2170 virtual sal_Int16
getShort() const override
{ return m_xColumn
->getShort(); }
2171 virtual sal_Int32
getInt() const override
{ return m_xColumn
->getInt(); }
2172 virtual sal_Int64
getLong() const override
{ return m_xColumn
->getLong(); }
2173 virtual float getFloat() const override
{ return m_xColumn
->getFloat(); };
2174 virtual double getDouble() const override
{ return m_xColumn
->getDouble(); };
2175 virtual Date
getDate() const override
{ return m_xColumn
->getDate(); };
2176 virtual css::util::Time
getTime() const override
{ return m_xColumn
->getTime(); };
2177 virtual DateTime
getTimestamp() const override
{ return m_xColumn
->getTimestamp(); };
2178 virtual Sequence
< sal_Int8
> getBytes() const override
{ return m_xColumn
->getBytes(); };
2179 virtual Reference
< XBlob
> getBlob() const override
{ return m_xColumn
->getBlob(); };
2180 virtual Reference
< XClob
> getClob() const override
{ return m_xColumn
->getClob(); };
2181 virtual Any
getObject() const override
{ return m_xColumn
->getObject( nullptr ); };
2182 virtual bool wasNull() const override
{ return m_xColumn
->wasNull( ); };
2185 const Reference
< XColumn
> m_xColumn
;
2192 void ORowSetValue::fill( const sal_Int32 _nType
, const Reference
< XColumn
>& _rxColumn
)
2194 detail::ColumnValue
aColumnValue( _rxColumn
);
2195 impl_fill( _nType
, true, aColumnValue
);
2199 void ORowSetValue::fill( sal_Int32 _nPos
, sal_Int32 _nType
, bool _bNullable
, const Reference
< XRow
>& _xRow
)
2201 detail::RowValue
aRowValue( _xRow
, _nPos
);
2202 impl_fill( _nType
, _bNullable
, aRowValue
);
2206 void ORowSetValue::fill(sal_Int32 _nPos
,
2208 const css::uno::Reference
< css::sdbc::XRow
>& _xRow
)
2210 fill(_nPos
,_nType
,true,_xRow
);
2214 void ORowSetValue::impl_fill( const sal_Int32 _nType
, bool _bNullable
, const detail::IValueSource
& _rValueSource
)
2218 case DataType::CHAR
:
2219 case DataType::VARCHAR
:
2220 case DataType::DECIMAL
:
2221 case DataType::NUMERIC
:
2222 case DataType::LONGVARCHAR
:
2223 (*this) = _rValueSource
.getString();
2225 case DataType::BIGINT
:
2227 (*this) = _rValueSource
.getLong();
2229 // TODO: this is rather horrible performance-wise
2230 // but fixing it needs extending the css::sdbc::XRow API
2231 // to have a getULong(), and needs updating all drivers :-|
2232 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2233 (*this) = _rValueSource
.getString().toUInt64();
2235 case DataType::FLOAT
:
2236 (*this) = _rValueSource
.getFloat();
2238 case DataType::DOUBLE
:
2239 case DataType::REAL
:
2240 (*this) = _rValueSource
.getDouble();
2242 case DataType::DATE
:
2243 (*this) = _rValueSource
.getDate();
2245 case DataType::TIME
:
2246 (*this) = _rValueSource
.getTime();
2248 case DataType::TIMESTAMP
:
2249 (*this) = _rValueSource
.getTimestamp();
2251 case DataType::BINARY
:
2252 case DataType::VARBINARY
:
2253 case DataType::LONGVARBINARY
:
2254 (*this) = _rValueSource
.getBytes();
2257 case DataType::BOOLEAN
:
2258 (*this) = _rValueSource
.getBoolean();
2260 case DataType::TINYINT
:
2262 (*this) = _rValueSource
.getByte();
2264 (*this) = _rValueSource
.getShort();
2266 case DataType::SMALLINT
:
2268 (*this) = _rValueSource
.getShort();
2270 (*this) = _rValueSource
.getInt();
2272 case DataType::INTEGER
:
2274 (*this) = _rValueSource
.getInt();
2276 (*this) = _rValueSource
.getLong();
2278 case DataType::CLOB
:
2279 (*this) = css::uno::Any(_rValueSource
.getClob());
2280 setTypeKind(DataType::CLOB
);
2282 case DataType::BLOB
:
2283 (*this) = css::uno::Any(_rValueSource
.getBlob());
2284 setTypeKind(DataType::BLOB
);
2286 case DataType::OTHER
:
2287 (*this) = _rValueSource
.getObject();
2288 setTypeKind(DataType::OTHER
);
2291 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2292 (*this) = _rValueSource
.getObject();
2295 if ( _bNullable
&& _rValueSource
.wasNull() )
2297 setTypeKind(_nType
);
2300 void ORowSetValue::fill(const Any
& _rValue
)
2302 switch (_rValue
.getValueTypeClass())
2304 case TypeClass_VOID
:
2306 case TypeClass_BOOLEAN
:
2308 bool bValue( false );
2313 case TypeClass_CHAR
:
2315 sal_Unicode
aDummy(0);
2317 (*this) = OUString(aDummy
);
2320 case TypeClass_STRING
:
2327 case TypeClass_FLOAT
:
2334 case TypeClass_DOUBLE
:
2341 case TypeClass_BYTE
:
2348 case TypeClass_SHORT
:
2350 sal_Int16
aDummy(0);
2355 case TypeClass_UNSIGNED_SHORT
:
2357 sal_uInt16
nValue(0);
2362 case TypeClass_LONG
:
2364 sal_Int32
aDummy(0);
2369 case TypeClass_UNSIGNED_LONG
:
2371 sal_uInt32
nValue(0);
2373 (*this) = static_cast<sal_Int64
>(nValue
);
2377 case TypeClass_HYPER
:
2379 sal_Int64
nValue(0);
2384 case TypeClass_UNSIGNED_HYPER
:
2386 sal_uInt64
nValue(0);
2392 case TypeClass_ENUM
:
2394 sal_Int32
enumValue( 0 );
2395 ::cppu::enum2int( enumValue
, _rValue
);
2396 (*this) = enumValue
;
2400 case TypeClass_SEQUENCE
:
2402 Sequence
<sal_Int8
> aDummy
;
2403 if ( _rValue
>>= aDummy
)
2406 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2410 case TypeClass_STRUCT
:
2412 css::util::Date aDate
;
2413 css::util::Time aTime
;
2414 css::util::DateTime aDateTime
;
2415 if ( _rValue
>>= aDate
)
2419 else if ( _rValue
>>= aTime
)
2423 else if ( _rValue
>>= aDateTime
)
2425 (*this) = aDateTime
;
2428 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2432 case TypeClass_INTERFACE
:
2434 Reference
< XClob
> xClob
;
2435 if ( _rValue
>>= xClob
)
2438 setTypeKind(DataType::CLOB
);
2442 Reference
< XBlob
> xBlob
;
2443 if ( _rValue
>>= xBlob
)
2446 setTypeKind(DataType::BLOB
);
2457 SAL_WARN( "connectivity.commontools","Unknown type");
2462 } // namespace connectivity
2464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */