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
:
825 case DataType::OBJECT
:
826 case DataType::OTHER
:
831 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
837 Any
ORowSetValue::makeAny() const
840 if(isBound() && !isNull())
842 switch(getTypeKind())
844 case DataType::SQLNULL
:
845 assert(rValue
== Any());
848 case DataType::VARCHAR
:
849 case DataType::DECIMAL
:
850 case DataType::NUMERIC
:
851 case DataType::LONGVARCHAR
:
852 OSL_ENSURE(m_aValue
.m_pString
,"Value is null!");
853 rValue
<<= OUString(m_aValue
.m_pString
);
855 case DataType::FLOAT
:
856 rValue
<<= m_aValue
.m_nFloat
;
858 case DataType::DOUBLE
:
860 rValue
<<= m_aValue
.m_nDouble
;
863 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
864 rValue
<<= *static_cast<Date
*>(m_aValue
.m_pValue
);
867 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
868 rValue
<<= *static_cast<Time
*>(m_aValue
.m_pValue
);
870 case DataType::TIMESTAMP
:
871 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
872 rValue
<<= *static_cast<DateTime
*>(m_aValue
.m_pValue
);
874 case DataType::BINARY
:
875 case DataType::VARBINARY
:
876 case DataType::LONGVARBINARY
:
877 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
878 rValue
<<= *static_cast<Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
882 case DataType::OBJECT
:
883 case DataType::OTHER
:
887 case DataType::BOOLEAN
:
888 rValue
<<= m_aValue
.m_bBool
;
890 case DataType::TINYINT
:
893 rValue
<<= m_aValue
.m_nInt8
;
895 // There is no TypeClass_UNSIGNED_BYTE,
896 // so silently promote it to a 16-bit integer,
897 // that is TypeClass_UNSIGNED_SHORT
898 rValue
<<= static_cast<sal_uInt16
>(m_aValue
.m_uInt8
);
900 case DataType::SMALLINT
:
903 rValue
<<= m_aValue
.m_nInt16
;
905 // TypeClass_UNSIGNED_SHORT
906 rValue
<<= m_aValue
.m_uInt16
;
908 case DataType::INTEGER
:
911 rValue
<<= m_aValue
.m_nInt32
;
913 // TypeClass_UNSIGNED_LONG
914 rValue
<<= m_aValue
.m_uInt32
;
916 case DataType::BIGINT
:
919 rValue
<<= m_aValue
.m_nInt64
;
921 // TypeClass_UNSIGNED_HYPER
922 rValue
<<= m_aValue
.m_uInt64
;
925 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
933 OUString
ORowSetValue::getString( ) const
938 switch(getTypeKind())
941 case DataType::VARCHAR
:
942 case DataType::DECIMAL
:
943 case DataType::NUMERIC
:
944 case DataType::LONGVARCHAR
:
945 aRet
= m_aValue
.m_pString
;
947 case DataType::FLOAT
:
948 aRet
= OUString::number(static_cast<float>(*this));
950 case DataType::DOUBLE
:
952 aRet
= OUString::number(static_cast<double>(*this));
955 aRet
= DBTypeConversion::toDateString(*this);
958 aRet
= DBTypeConversion::toTimeString(*this);
960 case DataType::TIMESTAMP
:
961 aRet
= DBTypeConversion::toDateTimeString(*this);
963 case DataType::BINARY
:
964 case DataType::VARBINARY
:
965 case DataType::LONGVARBINARY
:
967 OUStringBuffer
sVal("0x");
968 Sequence
<sal_Int8
> aSeq(getSequence());
969 const sal_Int8
* pBegin
= aSeq
.getConstArray();
970 const sal_Int8
* pEnd
= pBegin
+ aSeq
.getLength();
971 for(;pBegin
!= pEnd
;++pBegin
)
972 sVal
.append(static_cast<sal_Int32
>(*pBegin
),16);
973 aRet
= sVal
.makeStringAndClear();
977 aRet
= OUString::number(int(static_cast<bool>(*this)));
979 case DataType::BOOLEAN
:
980 aRet
= OUString::boolean(static_cast<bool>(*this));
982 case DataType::TINYINT
:
983 case DataType::SMALLINT
:
984 case DataType::INTEGER
:
986 aRet
= OUString::number(static_cast<sal_Int32
>(*this));
988 aRet
= OUString::number(static_cast<sal_uInt32
>(*this));
990 case DataType::BIGINT
:
992 aRet
= OUString::number(static_cast<sal_Int64
>(*this));
994 aRet
= OUString::number(static_cast<sal_uInt64
>(*this));
998 Any
aValue( getAny() );
999 Reference
< XClob
> xClob
;
1000 if ( (aValue
>>= xClob
) && xClob
.is() )
1002 aRet
= xClob
->getSubString(1,static_cast<sal_Int32
>(xClob
->length()) );
1008 Any aValue
= makeAny();
1017 bool ORowSetValue::getBool() const
1022 switch(getTypeKind())
1024 case DataType::CHAR
:
1025 case DataType::VARCHAR
:
1026 case DataType::LONGVARCHAR
:
1028 const OUString
sValue(m_aValue
.m_pString
);
1029 if ( sValue
.equalsIgnoreAsciiCase("true") || (sValue
== "1") )
1034 else if ( sValue
.equalsIgnoreAsciiCase("false") || (sValue
== "0") )
1041 case DataType::DECIMAL
:
1042 case DataType::NUMERIC
:
1044 bRet
= OUString(m_aValue
.m_pString
).toInt32() != 0;
1046 case DataType::FLOAT
:
1047 bRet
= m_aValue
.m_nFloat
!= 0.0;
1049 case DataType::DOUBLE
:
1050 case DataType::REAL
:
1051 bRet
= m_aValue
.m_nDouble
!= 0.0;
1053 case DataType::DATE
:
1054 case DataType::TIME
:
1055 case DataType::TIMESTAMP
:
1056 case DataType::BINARY
:
1057 case DataType::VARBINARY
:
1058 case DataType::LONGVARBINARY
:
1059 OSL_FAIL("getBool() for this type is not allowed!");
1062 case DataType::BOOLEAN
:
1063 bRet
= m_aValue
.m_bBool
;
1065 case DataType::TINYINT
:
1066 bRet
= m_bSigned
? (m_aValue
.m_nInt8
!= 0) : (m_aValue
.m_uInt8
!= 0);
1068 case DataType::SMALLINT
:
1069 bRet
= m_bSigned
? (m_aValue
.m_nInt16
!= 0) : (m_aValue
.m_uInt16
!= 0);
1071 case DataType::INTEGER
:
1072 bRet
= m_bSigned
? (m_aValue
.m_nInt32
!= 0) : (m_aValue
.m_uInt32
!= 0);
1074 case DataType::BIGINT
:
1075 bRet
= m_bSigned
? (m_aValue
.m_nInt64
!= 0) : (m_aValue
.m_uInt64
!= 0);
1079 Any aValue
= makeAny();
1089 sal_Int8
ORowSetValue::getInt8() const
1094 switch(getTypeKind())
1096 case DataType::CHAR
:
1097 case DataType::VARCHAR
:
1098 case DataType::DECIMAL
:
1099 case DataType::NUMERIC
:
1100 case DataType::LONGVARCHAR
:
1101 nRet
= sal_Int8(OUString(m_aValue
.m_pString
).toInt32());
1103 case DataType::FLOAT
:
1104 nRet
= sal_Int8(m_aValue
.m_nFloat
);
1106 case DataType::DOUBLE
:
1107 case DataType::REAL
:
1108 nRet
= sal_Int8(m_aValue
.m_nDouble
);
1110 case DataType::DATE
:
1111 case DataType::TIME
:
1112 case DataType::TIMESTAMP
:
1113 case DataType::BINARY
:
1114 case DataType::VARBINARY
:
1115 case DataType::LONGVARBINARY
:
1116 case DataType::BLOB
:
1117 case DataType::CLOB
:
1118 OSL_FAIL("getInt8() for this type is not allowed!");
1121 case DataType::BOOLEAN
:
1122 nRet
= sal_Int8(m_aValue
.m_bBool
);
1124 case DataType::TINYINT
:
1126 nRet
= m_aValue
.m_nInt8
;
1128 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt8
);
1130 case DataType::SMALLINT
:
1132 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt16
);
1134 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt16
);
1136 case DataType::INTEGER
:
1138 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt32
);
1140 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt32
);
1142 case DataType::BIGINT
:
1144 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt64
);
1146 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt64
);
1150 Any aValue
= makeAny();
1160 sal_uInt8
ORowSetValue::getUInt8() const
1165 switch(getTypeKind())
1167 case DataType::CHAR
:
1168 case DataType::VARCHAR
:
1169 case DataType::DECIMAL
:
1170 case DataType::NUMERIC
:
1171 case DataType::LONGVARCHAR
:
1172 nRet
= sal_uInt8(OUString(m_aValue
.m_pString
).toInt32());
1174 case DataType::FLOAT
:
1175 nRet
= sal_uInt8(m_aValue
.m_nFloat
);
1177 case DataType::DOUBLE
:
1178 case DataType::REAL
:
1179 nRet
= sal_uInt8(m_aValue
.m_nDouble
);
1181 case DataType::DATE
:
1182 case DataType::TIME
:
1183 case DataType::TIMESTAMP
:
1184 case DataType::BINARY
:
1185 case DataType::VARBINARY
:
1186 case DataType::LONGVARBINARY
:
1187 case DataType::BLOB
:
1188 case DataType::CLOB
:
1189 OSL_FAIL("getuInt8() for this type is not allowed!");
1192 case DataType::BOOLEAN
:
1193 nRet
= int(m_aValue
.m_bBool
);
1195 case DataType::TINYINT
:
1197 nRet
= m_aValue
.m_nInt8
;
1199 nRet
= m_aValue
.m_uInt8
;
1201 case DataType::SMALLINT
:
1203 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt16
);
1205 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt16
);
1207 case DataType::INTEGER
:
1209 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt32
);
1211 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt32
);
1213 case DataType::BIGINT
:
1215 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt64
);
1217 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt64
);
1221 Any aValue
= makeAny();
1222 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1225 nRet
= static_cast<sal_uInt8
>(n
);
1235 sal_Int16
ORowSetValue::getInt16() const
1240 switch(getTypeKind())
1242 case DataType::CHAR
:
1243 case DataType::VARCHAR
:
1244 case DataType::DECIMAL
:
1245 case DataType::NUMERIC
:
1246 case DataType::LONGVARCHAR
:
1247 nRet
= sal_Int16(OUString(m_aValue
.m_pString
).toInt32());
1249 case DataType::FLOAT
:
1250 nRet
= sal_Int16(m_aValue
.m_nFloat
);
1252 case DataType::DOUBLE
:
1253 case DataType::REAL
:
1254 nRet
= sal_Int16(m_aValue
.m_nDouble
);
1256 case DataType::DATE
:
1257 case DataType::TIME
:
1258 case DataType::TIMESTAMP
:
1259 case DataType::BINARY
:
1260 case DataType::VARBINARY
:
1261 case DataType::LONGVARBINARY
:
1262 case DataType::BLOB
:
1263 case DataType::CLOB
:
1264 OSL_FAIL("getInt16() for this type is not allowed!");
1267 case DataType::BOOLEAN
:
1268 nRet
= sal_Int16(m_aValue
.m_bBool
);
1270 case DataType::TINYINT
:
1272 nRet
= m_aValue
.m_nInt8
;
1274 nRet
= m_aValue
.m_uInt8
;
1276 case DataType::SMALLINT
:
1278 nRet
= m_aValue
.m_nInt16
;
1280 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt16
);
1282 case DataType::INTEGER
:
1284 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt32
);
1286 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt32
);
1288 case DataType::BIGINT
:
1290 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt64
);
1292 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt64
);
1296 Any aValue
= makeAny();
1306 sal_uInt16
ORowSetValue::getUInt16() const
1308 sal_uInt16 nRet
= 0;
1311 switch(getTypeKind())
1313 case DataType::CHAR
:
1314 case DataType::VARCHAR
:
1315 case DataType::DECIMAL
:
1316 case DataType::NUMERIC
:
1317 case DataType::LONGVARCHAR
:
1318 nRet
= sal_uInt16(OUString(m_aValue
.m_pString
).toInt32());
1320 case DataType::FLOAT
:
1321 nRet
= sal_uInt16(m_aValue
.m_nFloat
);
1323 case DataType::DOUBLE
:
1324 case DataType::REAL
:
1325 nRet
= sal_uInt16(m_aValue
.m_nDouble
);
1327 case DataType::DATE
:
1328 case DataType::TIME
:
1329 case DataType::TIMESTAMP
:
1330 case DataType::BINARY
:
1331 case DataType::VARBINARY
:
1332 case DataType::LONGVARBINARY
:
1333 case DataType::BLOB
:
1334 case DataType::CLOB
:
1335 OSL_FAIL("getuInt16() for this type is not allowed!");
1338 case DataType::BOOLEAN
:
1339 nRet
= sal_uInt16(m_aValue
.m_bBool
);
1341 case DataType::TINYINT
:
1343 nRet
= m_aValue
.m_nInt8
;
1345 nRet
= m_aValue
.m_uInt8
;
1347 case DataType::SMALLINT
:
1349 nRet
= m_aValue
.m_nInt16
;
1351 nRet
= m_aValue
.m_uInt16
;
1353 case DataType::INTEGER
:
1355 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt32
);
1357 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt32
);
1359 case DataType::BIGINT
:
1361 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt64
);
1363 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt64
);
1367 Any aValue
= makeAny();
1377 sal_Int32
ORowSetValue::getInt32() const
1382 switch(getTypeKind())
1384 case DataType::CHAR
:
1385 case DataType::VARCHAR
:
1386 case DataType::DECIMAL
:
1387 case DataType::NUMERIC
:
1388 case DataType::LONGVARCHAR
:
1389 nRet
= OUString(m_aValue
.m_pString
).toInt32();
1391 case DataType::FLOAT
:
1392 nRet
= sal_Int32(m_aValue
.m_nFloat
);
1394 case DataType::DOUBLE
:
1395 case DataType::REAL
:
1396 nRet
= sal_Int32(m_aValue
.m_nDouble
);
1398 case DataType::DATE
:
1399 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1401 case DataType::TIME
:
1402 case DataType::TIMESTAMP
:
1403 case DataType::BINARY
:
1404 case DataType::VARBINARY
:
1405 case DataType::LONGVARBINARY
:
1406 case DataType::BLOB
:
1407 case DataType::CLOB
:
1408 OSL_FAIL("getInt32() for this type is not allowed!");
1411 case DataType::BOOLEAN
:
1412 nRet
= sal_Int32(m_aValue
.m_bBool
);
1414 case DataType::TINYINT
:
1416 nRet
= m_aValue
.m_nInt8
;
1418 nRet
= m_aValue
.m_uInt8
;
1420 case DataType::SMALLINT
:
1422 nRet
= m_aValue
.m_nInt16
;
1424 nRet
= m_aValue
.m_uInt16
;
1426 case DataType::INTEGER
:
1428 nRet
= m_aValue
.m_nInt32
;
1430 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt32
);
1432 case DataType::BIGINT
:
1434 nRet
= static_cast<sal_Int32
>(m_aValue
.m_nInt64
);
1436 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt64
);
1440 Any aValue
= makeAny();
1450 sal_uInt32
ORowSetValue::getUInt32() const
1452 sal_uInt32 nRet
= 0;
1455 switch(getTypeKind())
1457 case DataType::CHAR
:
1458 case DataType::VARCHAR
:
1459 case DataType::DECIMAL
:
1460 case DataType::NUMERIC
:
1461 case DataType::LONGVARCHAR
:
1462 nRet
= OUString(m_aValue
.m_pString
).toUInt32();
1464 case DataType::FLOAT
:
1465 nRet
= sal_uInt32(m_aValue
.m_nFloat
);
1467 case DataType::DOUBLE
:
1468 case DataType::REAL
:
1469 nRet
= sal_uInt32(m_aValue
.m_nDouble
);
1471 case DataType::DATE
:
1472 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1474 case DataType::TIME
:
1475 case DataType::TIMESTAMP
:
1476 case DataType::BINARY
:
1477 case DataType::VARBINARY
:
1478 case DataType::LONGVARBINARY
:
1479 case DataType::BLOB
:
1480 case DataType::CLOB
:
1481 OSL_FAIL("getuInt32() for this type is not allowed!");
1484 case DataType::BOOLEAN
:
1485 nRet
= sal_uInt32(m_aValue
.m_bBool
);
1487 case DataType::TINYINT
:
1489 nRet
= m_aValue
.m_nInt8
;
1491 nRet
= m_aValue
.m_uInt8
;
1493 case DataType::SMALLINT
:
1495 nRet
= m_aValue
.m_nInt16
;
1497 nRet
= m_aValue
.m_uInt16
;
1499 case DataType::INTEGER
:
1501 nRet
= m_aValue
.m_nInt32
;
1503 nRet
= m_aValue
.m_uInt32
;
1505 case DataType::BIGINT
:
1507 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_nInt64
);
1509 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_uInt64
);
1513 Any aValue
= makeAny();
1523 sal_Int64
ORowSetValue::getLong() const
1528 switch(getTypeKind())
1530 case DataType::CHAR
:
1531 case DataType::VARCHAR
:
1532 case DataType::DECIMAL
:
1533 case DataType::NUMERIC
:
1534 case DataType::LONGVARCHAR
:
1535 nRet
= OUString(m_aValue
.m_pString
).toInt64();
1537 case DataType::FLOAT
:
1538 nRet
= sal_Int64(m_aValue
.m_nFloat
);
1540 case DataType::DOUBLE
:
1541 case DataType::REAL
:
1542 nRet
= sal_Int64(m_aValue
.m_nDouble
);
1544 case DataType::DATE
:
1545 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1547 case DataType::TIME
:
1548 case DataType::TIMESTAMP
:
1549 case DataType::BINARY
:
1550 case DataType::VARBINARY
:
1551 case DataType::LONGVARBINARY
:
1552 case DataType::BLOB
:
1553 case DataType::CLOB
:
1554 OSL_FAIL("getLong() for this type is not allowed!");
1557 case DataType::BOOLEAN
:
1558 nRet
= sal_Int64(m_aValue
.m_bBool
);
1560 case DataType::TINYINT
:
1562 nRet
= m_aValue
.m_nInt8
;
1564 nRet
= m_aValue
.m_uInt8
;
1566 case DataType::SMALLINT
:
1568 nRet
= m_aValue
.m_nInt16
;
1570 nRet
= m_aValue
.m_uInt16
;
1572 case DataType::INTEGER
:
1574 nRet
= m_aValue
.m_nInt32
;
1576 nRet
= m_aValue
.m_uInt32
;
1578 case DataType::BIGINT
:
1580 nRet
= m_aValue
.m_nInt64
;
1582 nRet
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
1586 Any aValue
= makeAny();
1596 sal_uInt64
ORowSetValue::getULong() const
1598 sal_uInt64 nRet
= 0;
1601 switch(getTypeKind())
1603 case DataType::CHAR
:
1604 case DataType::VARCHAR
:
1605 case DataType::DECIMAL
:
1606 case DataType::NUMERIC
:
1607 case DataType::LONGVARCHAR
:
1608 nRet
= OUString(m_aValue
.m_pString
).toUInt64();
1610 case DataType::FLOAT
:
1611 nRet
= sal_uInt64(m_aValue
.m_nFloat
);
1613 case DataType::DOUBLE
:
1614 case DataType::REAL
:
1615 nRet
= sal_uInt64(m_aValue
.m_nDouble
);
1617 case DataType::DATE
:
1618 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1620 case DataType::TIME
:
1621 case DataType::TIMESTAMP
:
1622 case DataType::BINARY
:
1623 case DataType::VARBINARY
:
1624 case DataType::LONGVARBINARY
:
1625 case DataType::BLOB
:
1626 case DataType::CLOB
:
1627 OSL_FAIL("getULong() for this type is not allowed!");
1630 case DataType::BOOLEAN
:
1631 nRet
= sal_uInt64(m_aValue
.m_bBool
);
1633 case DataType::TINYINT
:
1635 nRet
= m_aValue
.m_nInt8
;
1637 nRet
= m_aValue
.m_uInt8
;
1639 case DataType::SMALLINT
:
1641 nRet
= m_aValue
.m_nInt16
;
1643 nRet
= m_aValue
.m_uInt16
;
1645 case DataType::INTEGER
:
1647 nRet
= m_aValue
.m_nInt32
;
1649 nRet
= m_aValue
.m_uInt32
;
1651 case DataType::BIGINT
:
1653 nRet
= m_aValue
.m_nInt64
;
1655 nRet
= m_aValue
.m_uInt64
;
1659 Any aValue
= makeAny();
1669 float ORowSetValue::getFloat() const
1674 switch(getTypeKind())
1676 case DataType::CHAR
:
1677 case DataType::VARCHAR
:
1678 case DataType::DECIMAL
:
1679 case DataType::NUMERIC
:
1680 case DataType::LONGVARCHAR
:
1681 nRet
= OUString(m_aValue
.m_pString
).toFloat();
1683 case DataType::FLOAT
:
1684 nRet
= m_aValue
.m_nFloat
;
1686 case DataType::DOUBLE
:
1687 case DataType::REAL
:
1688 nRet
= static_cast<float>(m_aValue
.m_nDouble
);
1690 case DataType::DATE
:
1691 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
)));
1693 case DataType::TIME
:
1694 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
)));
1696 case DataType::TIMESTAMP
:
1697 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
)));
1699 case DataType::BINARY
:
1700 case DataType::VARBINARY
:
1701 case DataType::LONGVARBINARY
:
1702 case DataType::BLOB
:
1703 case DataType::CLOB
:
1704 OSL_FAIL("getDouble() for this type is not allowed!");
1707 case DataType::BOOLEAN
:
1708 nRet
= float(m_aValue
.m_bBool
);
1710 case DataType::TINYINT
:
1712 nRet
= m_aValue
.m_nInt8
;
1714 nRet
= m_aValue
.m_uInt8
;
1716 case DataType::SMALLINT
:
1718 nRet
= m_aValue
.m_nInt16
;
1720 nRet
= static_cast<float>(m_aValue
.m_uInt16
);
1722 case DataType::INTEGER
:
1724 nRet
= static_cast<float>(m_aValue
.m_nInt32
);
1726 nRet
= static_cast<float>(m_aValue
.m_uInt32
);
1728 case DataType::BIGINT
:
1730 nRet
= static_cast<float>(m_aValue
.m_nInt64
);
1732 nRet
= static_cast<float>(m_aValue
.m_uInt64
);
1736 Any aValue
= makeAny();
1745 double ORowSetValue::getDouble() const
1750 switch(getTypeKind())
1752 case DataType::CHAR
:
1753 case DataType::VARCHAR
:
1754 case DataType::DECIMAL
:
1755 case DataType::NUMERIC
:
1756 case DataType::LONGVARCHAR
:
1757 nRet
= OUString(m_aValue
.m_pString
).toDouble();
1759 case DataType::FLOAT
:
1760 nRet
= m_aValue
.m_nFloat
;
1762 case DataType::DOUBLE
:
1763 case DataType::REAL
:
1764 nRet
= m_aValue
.m_nDouble
;
1766 case DataType::DATE
:
1767 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1769 case DataType::TIME
:
1770 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
));
1772 case DataType::TIMESTAMP
:
1773 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
));
1775 case DataType::BINARY
:
1776 case DataType::VARBINARY
:
1777 case DataType::LONGVARBINARY
:
1778 case DataType::BLOB
:
1779 case DataType::CLOB
:
1780 OSL_FAIL("getDouble() for this type is not allowed!");
1783 case DataType::BOOLEAN
:
1784 nRet
= double(m_aValue
.m_bBool
);
1786 case DataType::TINYINT
:
1788 nRet
= m_aValue
.m_nInt8
;
1790 nRet
= m_aValue
.m_uInt8
;
1792 case DataType::SMALLINT
:
1794 nRet
= m_aValue
.m_nInt16
;
1796 nRet
= m_aValue
.m_uInt16
;
1798 case DataType::INTEGER
:
1800 nRet
= m_aValue
.m_nInt32
;
1802 nRet
= m_aValue
.m_uInt32
;
1804 case DataType::BIGINT
:
1806 nRet
= m_aValue
.m_nInt64
;
1808 nRet
= m_aValue
.m_uInt64
;
1812 Any aValue
= makeAny();
1821 Sequence
<sal_Int8
> ORowSetValue::getSequence() const
1823 Sequence
<sal_Int8
> aSeq
;
1828 case DataType::OBJECT
:
1829 case DataType::CLOB
:
1830 case DataType::BLOB
:
1832 Reference
<XInputStream
> xStream
;
1833 const Any aValue
= makeAny();
1834 if(aValue
.hasValue())
1836 Reference
<XBlob
> xBlob(aValue
,UNO_QUERY
);
1838 xStream
= xBlob
->getBinaryStream();
1841 Reference
<XClob
> xClob(aValue
,UNO_QUERY
);
1843 xStream
= xClob
->getCharacterStream();
1847 const sal_uInt32 nBytesToRead
= 65535;
1852 css::uno::Sequence
< sal_Int8
> aReadSeq
;
1854 nRead
= xStream
->readSomeBytes( aReadSeq
, nBytesToRead
);
1858 const sal_uInt32 nOldLength
= aSeq
.getLength();
1859 aSeq
.realloc( nOldLength
+ nRead
);
1860 memcpy( aSeq
.getArray() + nOldLength
, aReadSeq
.getConstArray(), aReadSeq
.getLength() );
1863 while( nBytesToRead
== nRead
);
1864 xStream
->closeInput();
1869 case DataType::VARCHAR
:
1870 case DataType::LONGVARCHAR
:
1872 aSeq
= Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(m_aValue
.m_pString
->buffer
),
1873 sizeof(sal_Unicode
) * m_aValue
.m_pString
->length
);
1876 case DataType::BINARY
:
1877 case DataType::VARBINARY
:
1878 case DataType::LONGVARBINARY
:
1879 aSeq
= *static_cast< Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
1883 Any aValue
= makeAny();
1893 css::util::Date
ORowSetValue::getDate() const
1895 css::util::Date aValue
;
1900 case DataType::CHAR
:
1901 case DataType::VARCHAR
:
1902 case DataType::LONGVARCHAR
:
1903 aValue
= DBTypeConversion::toDate(getString());
1905 case DataType::DECIMAL
:
1906 case DataType::NUMERIC
:
1907 case DataType::FLOAT
:
1908 case DataType::DOUBLE
:
1909 case DataType::REAL
:
1910 aValue
= DBTypeConversion::toDate(static_cast<double>(*this));
1913 case DataType::DATE
:
1914 aValue
= *static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
1916 case DataType::TIMESTAMP
:
1918 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1919 aValue
.Day
= pDateTime
->Day
;
1920 aValue
.Month
= pDateTime
->Month
;
1921 aValue
.Year
= pDateTime
->Year
;
1925 case DataType::BOOLEAN
:
1926 case DataType::TINYINT
:
1927 case DataType::SMALLINT
:
1928 case DataType::INTEGER
:
1929 case DataType::BIGINT
:
1930 aValue
= DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1933 case DataType::BLOB
:
1934 case DataType::CLOB
:
1935 case DataType::OBJECT
:
1937 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1940 case DataType::BINARY
:
1941 case DataType::VARBINARY
:
1942 case DataType::LONGVARBINARY
:
1943 case DataType::TIME
:
1944 aValue
= DBTypeConversion::toDate( double(0) );
1951 css::util::Time
ORowSetValue::getTime() const
1953 css::util::Time aValue
;
1958 case DataType::CHAR
:
1959 case DataType::VARCHAR
:
1960 case DataType::LONGVARCHAR
:
1961 aValue
= DBTypeConversion::toTime(getString());
1963 case DataType::DECIMAL
:
1964 case DataType::NUMERIC
:
1965 aValue
= DBTypeConversion::toTime(static_cast<double>(*this));
1967 case DataType::FLOAT
:
1968 case DataType::DOUBLE
:
1969 case DataType::REAL
:
1970 aValue
= DBTypeConversion::toTime(static_cast<double>(*this));
1972 case DataType::TIMESTAMP
:
1974 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1975 aValue
.NanoSeconds
= pDateTime
->NanoSeconds
;
1976 aValue
.Seconds
= pDateTime
->Seconds
;
1977 aValue
.Minutes
= pDateTime
->Minutes
;
1978 aValue
.Hours
= pDateTime
->Hours
;
1981 case DataType::TIME
:
1982 aValue
= *static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
1986 Any aAnyValue
= makeAny();
1987 aAnyValue
>>= aValue
;
1995 css::util::DateTime
ORowSetValue::getDateTime() const
1997 css::util::DateTime aValue
;
2002 case DataType::CHAR
:
2003 case DataType::VARCHAR
:
2004 case DataType::LONGVARCHAR
:
2005 aValue
= DBTypeConversion::toDateTime(getString());
2007 case DataType::DECIMAL
:
2008 case DataType::NUMERIC
:
2009 aValue
= DBTypeConversion::toDateTime(static_cast<double>(*this));
2011 case DataType::FLOAT
:
2012 case DataType::DOUBLE
:
2013 case DataType::REAL
:
2014 aValue
= DBTypeConversion::toDateTime(static_cast<double>(*this));
2016 case DataType::DATE
:
2018 css::util::Date
* pDate
= static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
2019 aValue
.Day
= pDate
->Day
;
2020 aValue
.Month
= pDate
->Month
;
2021 aValue
.Year
= pDate
->Year
;
2024 case DataType::TIME
:
2026 css::util::Time
* pTime
= static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
2027 aValue
.NanoSeconds
= pTime
->NanoSeconds
;
2028 aValue
.Seconds
= pTime
->Seconds
;
2029 aValue
.Minutes
= pTime
->Minutes
;
2030 aValue
.Hours
= pTime
->Hours
;
2033 case DataType::TIMESTAMP
:
2034 aValue
= *static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
2038 Any aAnyValue
= makeAny();
2039 aAnyValue
>>= aValue
;
2047 void ORowSetValue::setSigned(bool _bMod
)
2049 if ( m_bSigned
== _bMod
)
2056 sal_Int32 nType
= m_eTypeKind
;
2059 case DataType::TINYINT
:
2061 (*this) = getInt8();
2064 m_bSigned
= !m_bSigned
;
2065 (*this) = getInt16();
2066 m_bSigned
= !m_bSigned
;
2069 case DataType::SMALLINT
:
2071 (*this) = getInt16();
2074 m_bSigned
= !m_bSigned
;
2075 (*this) = getInt32();
2076 m_bSigned
= !m_bSigned
;
2079 case DataType::INTEGER
:
2081 (*this) = getInt32();
2084 m_bSigned
= !m_bSigned
;
2085 (*this) = getLong();
2086 m_bSigned
= !m_bSigned
;
2089 case DataType::BIGINT
:
2093 auto nTmp
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
2094 m_aValue
.m_nInt64
= nTmp
;
2098 auto nTmp
= static_cast<sal_uInt64
>(m_aValue
.m_nInt64
);
2099 m_aValue
.m_uInt64
= nTmp
;
2104 m_eTypeKind
= nType
;
2110 class SAL_NO_VTABLE IValueSource
2113 virtual OUString
getString() const = 0;
2114 virtual bool getBoolean() const = 0;
2115 virtual sal_Int8
getByte() const = 0;
2116 virtual sal_Int16
getShort() const = 0;
2117 virtual sal_Int32
getInt() const = 0;
2118 virtual sal_Int64
getLong() const = 0;
2119 virtual float getFloat() const = 0;
2120 virtual double getDouble() const = 0;
2121 virtual Date
getDate() const = 0;
2122 virtual css::util::Time
getTime() const = 0;
2123 virtual DateTime
getTimestamp() const = 0;
2124 virtual Sequence
< sal_Int8
> getBytes() const = 0;
2125 virtual Reference
< XBlob
> getBlob() const = 0;
2126 virtual Reference
< XClob
> getClob() const = 0;
2127 virtual Any
getObject() const = 0;
2128 virtual bool wasNull() const = 0;
2130 virtual ~IValueSource() { }
2135 class RowValue
: public IValueSource
2138 RowValue( const Reference
< XRow
>& _xRow
, const sal_Int32 _nPos
)
2145 virtual OUString
getString() const override
{ return m_xRow
->getString( m_nPos
); };
2146 virtual bool getBoolean() const override
{ return m_xRow
->getBoolean( m_nPos
); };
2147 virtual sal_Int8
getByte() const override
{ return m_xRow
->getByte( m_nPos
); };
2148 virtual sal_Int16
getShort() const override
{ return m_xRow
->getShort( m_nPos
); }
2149 virtual sal_Int32
getInt() const override
{ return m_xRow
->getInt( m_nPos
); }
2150 virtual sal_Int64
getLong() const override
{ return m_xRow
->getLong( m_nPos
); }
2151 virtual float getFloat() const override
{ return m_xRow
->getFloat( m_nPos
); };
2152 virtual double getDouble() const override
{ return m_xRow
->getDouble( m_nPos
); };
2153 virtual Date
getDate() const override
{ return m_xRow
->getDate( m_nPos
); };
2154 virtual css::util::Time
getTime() const override
{ return m_xRow
->getTime( m_nPos
); };
2155 virtual DateTime
getTimestamp() const override
{ return m_xRow
->getTimestamp( m_nPos
); };
2156 virtual Sequence
< sal_Int8
> getBytes() const override
{ return m_xRow
->getBytes( m_nPos
); };
2157 virtual Reference
< XBlob
> getBlob() const override
{ return m_xRow
->getBlob( m_nPos
); };
2158 virtual Reference
< XClob
> getClob() const override
{ return m_xRow
->getClob( m_nPos
); };
2159 virtual Any
getObject() const override
{ return m_xRow
->getObject( m_nPos
,nullptr); };
2160 virtual bool wasNull() const override
{ return m_xRow
->wasNull( ); };
2163 const Reference
< XRow
> m_xRow
;
2164 const sal_Int32 m_nPos
;
2167 class ColumnValue
: public IValueSource
2170 explicit ColumnValue( const Reference
< XColumn
>& _rxColumn
)
2171 :m_xColumn( _rxColumn
)
2176 virtual OUString
getString() const override
{ return m_xColumn
->getString(); };
2177 virtual bool getBoolean() const override
{ return m_xColumn
->getBoolean(); };
2178 virtual sal_Int8
getByte() const override
{ return m_xColumn
->getByte(); };
2179 virtual sal_Int16
getShort() const override
{ return m_xColumn
->getShort(); }
2180 virtual sal_Int32
getInt() const override
{ return m_xColumn
->getInt(); }
2181 virtual sal_Int64
getLong() const override
{ return m_xColumn
->getLong(); }
2182 virtual float getFloat() const override
{ return m_xColumn
->getFloat(); };
2183 virtual double getDouble() const override
{ return m_xColumn
->getDouble(); };
2184 virtual Date
getDate() const override
{ return m_xColumn
->getDate(); };
2185 virtual css::util::Time
getTime() const override
{ return m_xColumn
->getTime(); };
2186 virtual DateTime
getTimestamp() const override
{ return m_xColumn
->getTimestamp(); };
2187 virtual Sequence
< sal_Int8
> getBytes() const override
{ return m_xColumn
->getBytes(); };
2188 virtual Reference
< XBlob
> getBlob() const override
{ return m_xColumn
->getBlob(); };
2189 virtual Reference
< XClob
> getClob() const override
{ return m_xColumn
->getClob(); };
2190 virtual Any
getObject() const override
{ return m_xColumn
->getObject( nullptr ); };
2191 virtual bool wasNull() const override
{ return m_xColumn
->wasNull( ); };
2194 const Reference
< XColumn
> m_xColumn
;
2201 void ORowSetValue::fill( const sal_Int32 _nType
, const Reference
< XColumn
>& _rxColumn
)
2203 detail::ColumnValue
aColumnValue( _rxColumn
);
2204 impl_fill( _nType
, true, aColumnValue
);
2208 void ORowSetValue::fill( sal_Int32 _nPos
, sal_Int32 _nType
, bool _bNullable
, const Reference
< XRow
>& _xRow
)
2210 detail::RowValue
aRowValue( _xRow
, _nPos
);
2211 impl_fill( _nType
, _bNullable
, aRowValue
);
2215 void ORowSetValue::fill(sal_Int32 _nPos
,
2217 const css::uno::Reference
< css::sdbc::XRow
>& _xRow
)
2219 fill(_nPos
,_nType
,true,_xRow
);
2223 void ORowSetValue::impl_fill( const sal_Int32 _nType
, bool _bNullable
, const detail::IValueSource
& _rValueSource
)
2227 case DataType::CHAR
:
2228 case DataType::VARCHAR
:
2229 case DataType::DECIMAL
:
2230 case DataType::NUMERIC
:
2231 case DataType::LONGVARCHAR
:
2232 (*this) = _rValueSource
.getString();
2234 case DataType::BIGINT
:
2236 (*this) = _rValueSource
.getLong();
2238 // TODO: this is rather horrible performance-wise
2239 // but fixing it needs extending the css::sdbc::XRow API
2240 // to have a getULong(), and needs updating all drivers :-|
2241 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2242 (*this) = _rValueSource
.getString().toUInt64();
2244 case DataType::FLOAT
:
2245 (*this) = _rValueSource
.getFloat();
2247 case DataType::DOUBLE
:
2248 case DataType::REAL
:
2249 (*this) = _rValueSource
.getDouble();
2251 case DataType::DATE
:
2252 (*this) = _rValueSource
.getDate();
2254 case DataType::TIME
:
2255 (*this) = _rValueSource
.getTime();
2257 case DataType::TIMESTAMP
:
2258 (*this) = _rValueSource
.getTimestamp();
2260 case DataType::BINARY
:
2261 case DataType::VARBINARY
:
2262 case DataType::LONGVARBINARY
:
2263 (*this) = _rValueSource
.getBytes();
2266 case DataType::BOOLEAN
:
2267 (*this) = _rValueSource
.getBoolean();
2269 case DataType::TINYINT
:
2271 (*this) = _rValueSource
.getByte();
2273 (*this) = _rValueSource
.getShort();
2275 case DataType::SMALLINT
:
2277 (*this) = _rValueSource
.getShort();
2279 (*this) = _rValueSource
.getInt();
2281 case DataType::INTEGER
:
2283 (*this) = _rValueSource
.getInt();
2285 (*this) = _rValueSource
.getLong();
2287 case DataType::CLOB
:
2288 (*this) = css::uno::makeAny(_rValueSource
.getClob());
2289 setTypeKind(DataType::CLOB
);
2291 case DataType::BLOB
:
2292 (*this) = css::uno::makeAny(_rValueSource
.getBlob());
2293 setTypeKind(DataType::BLOB
);
2295 case DataType::OTHER
:
2296 (*this) = _rValueSource
.getObject();
2297 setTypeKind(DataType::OTHER
);
2300 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2301 (*this) = _rValueSource
.getObject();
2304 if ( _bNullable
&& _rValueSource
.wasNull() )
2306 setTypeKind(_nType
);
2309 void ORowSetValue::fill(const Any
& _rValue
)
2311 switch (_rValue
.getValueType().getTypeClass())
2313 case TypeClass_VOID
:
2315 case TypeClass_BOOLEAN
:
2317 bool bValue( false );
2322 case TypeClass_CHAR
:
2324 sal_Unicode
aDummy(0);
2326 (*this) = OUString(aDummy
);
2329 case TypeClass_STRING
:
2336 case TypeClass_FLOAT
:
2343 case TypeClass_DOUBLE
:
2350 case TypeClass_BYTE
:
2357 case TypeClass_SHORT
:
2359 sal_Int16
aDummy(0);
2364 case TypeClass_UNSIGNED_SHORT
:
2366 sal_uInt16
nValue(0);
2371 case TypeClass_LONG
:
2373 sal_Int32
aDummy(0);
2378 case TypeClass_UNSIGNED_LONG
:
2380 sal_uInt32
nValue(0);
2382 (*this) = static_cast<sal_Int64
>(nValue
);
2386 case TypeClass_HYPER
:
2388 sal_Int64
nValue(0);
2393 case TypeClass_UNSIGNED_HYPER
:
2395 sal_uInt64
nValue(0);
2401 case TypeClass_ENUM
:
2403 sal_Int32
enumValue( 0 );
2404 ::cppu::enum2int( enumValue
, _rValue
);
2405 (*this) = enumValue
;
2409 case TypeClass_SEQUENCE
:
2411 Sequence
<sal_Int8
> aDummy
;
2412 if ( _rValue
>>= aDummy
)
2415 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2419 case TypeClass_STRUCT
:
2421 css::util::Date aDate
;
2422 css::util::Time aTime
;
2423 css::util::DateTime aDateTime
;
2424 if ( _rValue
>>= aDate
)
2428 else if ( _rValue
>>= aTime
)
2432 else if ( _rValue
>>= aDateTime
)
2434 (*this) = aDateTime
;
2437 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2441 case TypeClass_INTERFACE
:
2443 Reference
< XClob
> xClob
;
2444 if ( _rValue
>>= xClob
)
2447 setTypeKind(DataType::CLOB
);
2451 Reference
< XBlob
> xBlob
;
2452 if ( _rValue
>>= xBlob
)
2455 setTypeKind(DataType::BLOB
);
2466 SAL_WARN( "connectivity.commontools","Unknown type");
2471 } // namespace connectivity
2473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */