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/CommonTools.hxx>
24 #include <connectivity/dbconversion.hxx>
25 #include <comphelper/extract.hxx>
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/sdbc/XClob.hpp>
28 #include <com/sun/star/sdbc/XBlob.hpp>
29 #include <com/sun/star/sdb/XColumn.hpp>
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <rtl/ustrbuf.hxx>
32 #include <sal/log.hxx>
33 #include <osl/diagnose.h>
35 using namespace ::dbtools
;
36 using namespace ::com::sun::star::sdbc
;
37 using namespace ::com::sun::star::sdb
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::io
;
42 namespace connectivity
46 bool isStorageCompatible(sal_Int32 _eType1
, sal_Int32 _eType2
)
48 bool bIsCompatible
= true;
50 if (_eType1
!= _eType2
)
52 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
56 case DataType::VARCHAR
:
57 case DataType::DECIMAL
:
58 case DataType::NUMERIC
:
59 case DataType::LONGVARCHAR
:
60 bIsCompatible
= (DataType::CHAR
== _eType2
)
61 || (DataType::VARCHAR
== _eType2
)
62 || (DataType::DECIMAL
== _eType2
)
63 || (DataType::NUMERIC
== _eType2
)
64 || (DataType::LONGVARCHAR
== _eType2
);
67 case DataType::DOUBLE
:
69 bIsCompatible
= (DataType::DOUBLE
== _eType2
)
70 || (DataType::REAL
== _eType2
);
73 case DataType::BINARY
:
74 case DataType::VARBINARY
:
75 case DataType::LONGVARBINARY
:
76 bIsCompatible
= (DataType::BINARY
== _eType2
)
77 || (DataType::VARBINARY
== _eType2
)
78 || (DataType::LONGVARBINARY
== _eType2
);
81 case DataType::INTEGER
:
82 bIsCompatible
= (DataType::SMALLINT
== _eType2
)
83 || (DataType::TINYINT
== _eType2
)
84 || (DataType::BIT
== _eType2
)
85 || (DataType::BOOLEAN
== _eType2
);
87 case DataType::SMALLINT
:
88 bIsCompatible
= (DataType::TINYINT
== _eType2
)
89 || (DataType::BIT
== _eType2
)
90 || (DataType::BOOLEAN
== _eType2
);
92 case DataType::TINYINT
:
93 bIsCompatible
= (DataType::BIT
== _eType2
)
94 || (DataType::BOOLEAN
== _eType2
);
99 case DataType::OBJECT
:
100 bIsCompatible
= (DataType::BLOB
== _eType2
)
101 || (DataType::CLOB
== _eType2
)
102 || (DataType::OBJECT
== _eType2
);
106 bIsCompatible
= false;
109 return bIsCompatible
;
112 bool isStorageComparable(sal_Int32 _eType1
, sal_Int32 _eType2
)
114 bool bIsComparable
= true;
116 if (_eType1
!= _eType2
)
118 SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
122 case DataType::VARCHAR
:
123 case DataType::LONGVARCHAR
:
124 bIsComparable
= (DataType::CHAR
== _eType2
)
125 || (DataType::VARCHAR
== _eType2
)
126 || (DataType::LONGVARCHAR
== _eType2
);
129 case DataType::DECIMAL
:
130 case DataType::NUMERIC
:
131 bIsComparable
= (DataType::DECIMAL
== _eType2
)
132 || (DataType::NUMERIC
== _eType2
);
135 case DataType::DOUBLE
:
137 bIsComparable
= (DataType::DOUBLE
== _eType2
)
138 || (DataType::REAL
== _eType2
);
141 case DataType::BINARY
:
142 case DataType::VARBINARY
:
143 case DataType::LONGVARBINARY
:
144 bIsComparable
= (DataType::BINARY
== _eType2
)
145 || (DataType::VARBINARY
== _eType2
)
146 || (DataType::LONGVARBINARY
== _eType2
);
149 case DataType::INTEGER
:
150 bIsComparable
= (DataType::SMALLINT
== _eType2
)
151 || (DataType::TINYINT
== _eType2
)
152 || (DataType::BIT
== _eType2
)
153 || (DataType::BOOLEAN
== _eType2
);
155 case DataType::SMALLINT
:
156 bIsComparable
= (DataType::TINYINT
== _eType2
)
157 || (DataType::BIT
== _eType2
)
158 || (DataType::BOOLEAN
== _eType2
);
160 case DataType::TINYINT
:
161 bIsComparable
= (DataType::BIT
== _eType2
)
162 || (DataType::BOOLEAN
== _eType2
);
167 case DataType::OBJECT
:
168 bIsComparable
= (DataType::BLOB
== _eType2
)
169 || (DataType::CLOB
== _eType2
)
170 || (DataType::OBJECT
== _eType2
);
174 bIsComparable
= false;
177 return bIsComparable
;
181 void ORowSetValue::setTypeKind(sal_Int32 _eType
)
183 if ( !m_bNull
&& !isStorageCompatible(_eType
, m_eTypeKind
) )
187 case DataType::VARCHAR
:
189 case DataType::DECIMAL
:
190 case DataType::NUMERIC
:
191 case DataType::LONGVARCHAR
:
192 (*this) = getString();
194 case DataType::BIGINT
:
196 sal_Int64
nVal(getLong());
197 sal_uInt64
nuVal(getULong());
198 if (nVal
== 0 && nuVal
!= 0)
205 case DataType::FLOAT
:
206 (*this) = getFloat();
208 case DataType::DOUBLE
:
210 (*this) = getDouble();
212 case DataType::TINYINT
:
215 case DataType::SMALLINT
:
216 (*this) = getInt16();
218 case DataType::INTEGER
:
220 sal_Int32
nVal(getInt32());
221 sal_uInt32
nuVal(getUInt32());
222 if (nVal
== 0 && nuVal
!= 0)
229 case DataType::BOOLEAN
:
238 case DataType::TIMESTAMP
:
239 (*this) = getDateTime();
241 case DataType::BINARY
:
242 case DataType::VARBINARY
:
243 case DataType::LONGVARBINARY
:
244 (*this) = getSequence();
248 case DataType::OBJECT
:
249 case DataType::OTHER
:
254 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
258 m_eTypeKind
= _eType
;
262 void ORowSetValue::free()
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;
324 ORowSetValue
& ORowSetValue::operator=(const ORowSetValue
& _rRH
)
329 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
|| (_rRH
.m_bNull
&& !m_bNull
) || m_bSigned
!= _rRH
.m_bSigned
)
332 m_bBound
= _rRH
.m_bBound
;
333 m_eTypeKind
= _rRH
.m_eTypeKind
;
334 m_bSigned
= _rRH
.m_bSigned
;
336 if(m_bNull
&& !_rRH
.m_bNull
)
338 switch(_rRH
.m_eTypeKind
)
341 case DataType::VARCHAR
:
342 case DataType::DECIMAL
:
343 case DataType::NUMERIC
:
344 case DataType::LONGVARCHAR
:
345 rtl_uString_acquire(_rRH
.m_aValue
.m_pString
);
346 m_aValue
.m_pString
= _rRH
.m_aValue
.m_pString
;
349 m_aValue
.m_pValue
= new Date(*static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
));
352 m_aValue
.m_pValue
= new Time(*static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
));
354 case DataType::TIMESTAMP
:
355 m_aValue
.m_pValue
= new DateTime(*static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
));
357 case DataType::BINARY
:
358 case DataType::VARBINARY
:
359 case DataType::LONGVARBINARY
:
360 m_aValue
.m_pValue
= new Sequence
<sal_Int8
>(*static_cast<Sequence
<sal_Int8
>*>(_rRH
.m_aValue
.m_pValue
));
363 case DataType::BOOLEAN
:
364 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
366 case DataType::TINYINT
:
367 if ( _rRH
.m_bSigned
)
368 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
370 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
372 case DataType::SMALLINT
:
373 if ( _rRH
.m_bSigned
)
374 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
376 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
378 case DataType::INTEGER
:
379 if ( _rRH
.m_bSigned
)
380 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
382 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
384 case DataType::BIGINT
:
385 if ( _rRH
.m_bSigned
)
386 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
388 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
390 case DataType::FLOAT
:
391 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
393 case DataType::DOUBLE
:
395 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
398 m_aValue
.m_pValue
= new Any(*static_cast<Any
*>(_rRH
.m_aValue
.m_pValue
));
401 else if(!_rRH
.m_bNull
)
403 switch(_rRH
.m_eTypeKind
)
406 case DataType::VARCHAR
:
407 case DataType::DECIMAL
:
408 case DataType::NUMERIC
:
409 case DataType::LONGVARCHAR
:
410 (*this) = OUString(_rRH
.m_aValue
.m_pString
);
413 (*this) = *static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
);
416 (*this) = *static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
);
418 case DataType::TIMESTAMP
:
419 (*this) = *static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
);
421 case DataType::BINARY
:
422 case DataType::VARBINARY
:
423 case DataType::LONGVARBINARY
:
424 (*this) = *static_cast<Sequence
<sal_Int8
>*>(_rRH
.m_aValue
.m_pValue
);
427 case DataType::BOOLEAN
:
428 m_aValue
.m_bBool
= _rRH
.m_aValue
.m_bBool
;
430 case DataType::TINYINT
:
431 if ( _rRH
.m_bSigned
)
432 m_aValue
.m_nInt8
= _rRH
.m_aValue
.m_nInt8
;
434 m_aValue
.m_uInt8
= _rRH
.m_aValue
.m_uInt8
;
436 case DataType::SMALLINT
:
437 if ( _rRH
.m_bSigned
)
438 m_aValue
.m_nInt16
= _rRH
.m_aValue
.m_nInt16
;
440 m_aValue
.m_uInt16
= _rRH
.m_aValue
.m_uInt16
;
442 case DataType::INTEGER
:
443 if ( _rRH
.m_bSigned
)
444 m_aValue
.m_nInt32
= _rRH
.m_aValue
.m_nInt32
;
446 m_aValue
.m_uInt32
= _rRH
.m_aValue
.m_uInt32
;
448 case DataType::BIGINT
:
449 if ( _rRH
.m_bSigned
)
450 m_aValue
.m_nInt64
= _rRH
.m_aValue
.m_nInt64
;
452 m_aValue
.m_uInt64
= _rRH
.m_aValue
.m_uInt64
;
454 case DataType::FLOAT
:
455 m_aValue
.m_nFloat
= _rRH
.m_aValue
.m_nFloat
;
457 case DataType::DOUBLE
:
459 m_aValue
.m_nDouble
= _rRH
.m_aValue
.m_nDouble
;
462 *static_cast<Any
*>(m_aValue
.m_pValue
) = *static_cast<Any
*>(_rRH
.m_aValue
.m_pValue
);
466 m_bNull
= _rRH
.m_bNull
;
468 m_eTypeKind
= _rRH
.m_eTypeKind
;
473 ORowSetValue
& ORowSetValue::operator=(ORowSetValue
&& _rRH
)
475 if ( m_eTypeKind
!= _rRH
.m_eTypeKind
|| !m_bNull
)
479 m_aValue
= _rRH
.m_aValue
;
480 memset(&_rRH
.m_aValue
, 0, sizeof(_rRH
.m_aValue
));
482 m_bBound
= _rRH
.m_bBound
;
483 m_eTypeKind
= _rRH
.m_eTypeKind
;
484 m_bSigned
= _rRH
.m_bSigned
;
485 m_bNull
= _rRH
.m_bNull
;
491 ORowSetValue
& ORowSetValue::operator=(const Date
& _rRH
)
493 if(m_eTypeKind
!= DataType::DATE
)
498 m_aValue
.m_pValue
= new Date(_rRH
);
499 m_eTypeKind
= DataType::DATE
;
503 *static_cast<Date
*>(m_aValue
.m_pValue
) = _rRH
;
508 ORowSetValue
& ORowSetValue::operator=(const css::util::Time
& _rRH
)
510 if(m_eTypeKind
!= DataType::TIME
)
515 m_aValue
.m_pValue
= new Time(_rRH
);
516 m_eTypeKind
= DataType::TIME
;
520 *static_cast<Time
*>(m_aValue
.m_pValue
) = _rRH
;
525 ORowSetValue
& ORowSetValue::operator=(const DateTime
& _rRH
)
527 if(m_eTypeKind
!= DataType::TIMESTAMP
)
531 m_aValue
.m_pValue
= new DateTime(_rRH
);
532 m_eTypeKind
= DataType::TIMESTAMP
;
536 *static_cast<DateTime
*>(m_aValue
.m_pValue
) = _rRH
;
542 ORowSetValue
& ORowSetValue::operator=(const OUString
& _rRH
)
544 if(m_eTypeKind
!= DataType::VARCHAR
|| m_aValue
.m_pString
!= _rRH
.pData
)
549 m_aValue
.m_pString
= _rRH
.pData
;
550 rtl_uString_acquire(m_aValue
.m_pString
);
551 m_eTypeKind
= DataType::VARCHAR
;
558 ORowSetValue
& ORowSetValue::operator=(double _rRH
)
560 if(m_eTypeKind
!= DataType::DOUBLE
)
563 m_aValue
.m_nDouble
= _rRH
;
564 m_eTypeKind
= DataType::DOUBLE
;
570 ORowSetValue
& ORowSetValue::operator=(float _rRH
)
572 if(m_eTypeKind
!= DataType::FLOAT
)
575 m_aValue
.m_nFloat
= _rRH
;
576 m_eTypeKind
= DataType::FLOAT
;
583 ORowSetValue
& ORowSetValue::operator=(sal_Int8 _rRH
)
585 if(m_eTypeKind
!= DataType::TINYINT
)
588 m_aValue
.m_nInt8
= _rRH
;
589 m_eTypeKind
= DataType::TINYINT
;
595 ORowSetValue
& ORowSetValue::operator=(sal_Int16 _rRH
)
597 if(m_eTypeKind
!= DataType::SMALLINT
)
600 m_aValue
.m_nInt16
= _rRH
;
601 m_eTypeKind
= DataType::SMALLINT
;
609 ORowSetValue
& ORowSetValue::operator=(sal_uInt16 _rRH
)
611 if(m_eTypeKind
!= DataType::SMALLINT
)
614 m_aValue
.m_uInt16
= _rRH
;
615 m_eTypeKind
= DataType::SMALLINT
;
623 ORowSetValue
& ORowSetValue::operator=(sal_Int32 _rRH
)
625 if(m_eTypeKind
!= DataType::INTEGER
)
628 m_aValue
.m_nInt32
= _rRH
;
630 m_eTypeKind
= DataType::INTEGER
;
638 ORowSetValue
& ORowSetValue::operator=(sal_uInt32 _rRH
)
640 if(m_eTypeKind
!= DataType::INTEGER
)
643 m_aValue
.m_uInt32
= _rRH
;
645 m_eTypeKind
= DataType::INTEGER
;
653 ORowSetValue
& ORowSetValue::operator=(const bool _rRH
)
655 if(m_eTypeKind
!= DataType::BIT
&& DataType::BOOLEAN
!= m_eTypeKind
)
658 m_aValue
.m_bBool
= _rRH
;
659 m_eTypeKind
= DataType::BOOLEAN
;
665 ORowSetValue
& ORowSetValue::operator=(sal_Int64 _rRH
)
667 if ( DataType::BIGINT
!= m_eTypeKind
)
670 m_aValue
.m_nInt64
= _rRH
;
671 m_eTypeKind
= DataType::BIGINT
;
678 ORowSetValue
& ORowSetValue::operator=(sal_uInt64 _rRH
)
680 if ( DataType::BIGINT
!= m_eTypeKind
)
683 m_aValue
.m_uInt64
= _rRH
;
684 m_eTypeKind
= DataType::BIGINT
;
691 ORowSetValue
& ORowSetValue::operator=(const Sequence
<sal_Int8
>& _rRH
)
693 if (!isStorageCompatible(DataType::LONGVARBINARY
,m_eTypeKind
))
698 m_aValue
.m_pValue
= new Sequence
<sal_Int8
>(_rRH
);
701 *static_cast< Sequence
< sal_Int8
>* >(m_aValue
.m_pValue
) = _rRH
;
703 m_eTypeKind
= DataType::LONGVARBINARY
;
709 ORowSetValue
& ORowSetValue::operator=(const Any
& _rAny
)
711 if (!isStorageCompatible(DataType::OBJECT
,m_eTypeKind
))
716 m_aValue
.m_pValue
= new Any(_rAny
);
719 *static_cast<Any
*>(m_aValue
.m_pValue
) = _rAny
;
721 m_eTypeKind
= DataType::OBJECT
;
728 bool ORowSetValue::operator==(const ORowSetValue
& _rRH
) const
730 if ( m_bNull
!= _rRH
.isNull() )
733 if(m_bNull
&& _rRH
.isNull())
736 if ( !isStorageComparable(m_eTypeKind
, _rRH
.m_eTypeKind
))
740 case DataType::FLOAT
:
741 case DataType::DOUBLE
:
743 return getDouble() == _rRH
.getDouble();
745 switch(_rRH
.m_eTypeKind
)
747 case DataType::FLOAT
:
748 case DataType::DOUBLE
:
750 return getDouble() == _rRH
.getDouble();
760 OSL_ENSURE(!m_bNull
,"Should not be null!");
763 case DataType::VARCHAR
:
765 case DataType::LONGVARCHAR
:
767 OUString
aVal1(m_aValue
.m_pString
);
768 OUString
aVal2(_rRH
.m_aValue
.m_pString
);
769 return aVal1
== aVal2
;
772 if ( m_bSigned
!= _rRH
.m_bSigned
)
779 case DataType::DECIMAL
:
780 case DataType::NUMERIC
:
782 OUString
aVal1(m_aValue
.m_pString
);
783 OUString
aVal2(_rRH
.m_aValue
.m_pString
);
784 bRet
= aVal1
== aVal2
;
787 case DataType::FLOAT
:
788 bRet
= m_aValue
.m_nFloat
== _rRH
.m_aValue
.m_nFloat
;
790 case DataType::DOUBLE
:
792 bRet
= m_aValue
.m_nDouble
== _rRH
.m_aValue
.m_nDouble
;
794 case DataType::TINYINT
:
795 bRet
= m_bSigned
? ( m_aValue
.m_nInt8
== _rRH
.m_aValue
.m_nInt8
) : (m_aValue
.m_uInt8
== _rRH
.m_aValue
.m_uInt8
);
797 case DataType::SMALLINT
:
798 bRet
= m_bSigned
? ( m_aValue
.m_nInt16
== _rRH
.m_aValue
.m_nInt16
) : (m_aValue
.m_uInt16
== _rRH
.m_aValue
.m_uInt16
);
800 case DataType::INTEGER
:
801 bRet
= m_bSigned
? ( m_aValue
.m_nInt32
== _rRH
.m_aValue
.m_nInt32
) : (m_aValue
.m_uInt32
== _rRH
.m_aValue
.m_uInt32
);
803 case DataType::BIGINT
:
804 bRet
= m_bSigned
? ( m_aValue
.m_nInt64
== _rRH
.m_aValue
.m_nInt64
) : (m_aValue
.m_uInt64
== _rRH
.m_aValue
.m_uInt64
);
807 case DataType::BOOLEAN
:
808 bRet
= m_aValue
.m_bBool
== _rRH
.m_aValue
.m_bBool
;
811 bRet
= *static_cast<Date
*>(m_aValue
.m_pValue
) == *static_cast<Date
*>(_rRH
.m_aValue
.m_pValue
);
814 bRet
= *static_cast<Time
*>(m_aValue
.m_pValue
) == *static_cast<Time
*>(_rRH
.m_aValue
.m_pValue
);
816 case DataType::TIMESTAMP
:
817 bRet
= *static_cast<DateTime
*>(m_aValue
.m_pValue
) == *static_cast<DateTime
*>(_rRH
.m_aValue
.m_pValue
);
819 case DataType::BINARY
:
820 case DataType::VARBINARY
:
821 case DataType::LONGVARBINARY
:
826 case DataType::OBJECT
:
827 case DataType::OTHER
:
832 SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
838 Any
ORowSetValue::makeAny() const
841 if(isBound() && !isNull())
843 switch(getTypeKind())
845 case DataType::SQLNULL
:
846 assert(rValue
== Any());
849 case DataType::VARCHAR
:
850 case DataType::DECIMAL
:
851 case DataType::NUMERIC
:
852 case DataType::LONGVARCHAR
:
853 OSL_ENSURE(m_aValue
.m_pString
,"Value is null!");
854 rValue
<<= OUString(m_aValue
.m_pString
);
856 case DataType::FLOAT
:
857 rValue
<<= m_aValue
.m_nFloat
;
859 case DataType::DOUBLE
:
861 rValue
<<= m_aValue
.m_nDouble
;
864 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
865 rValue
<<= *static_cast<Date
*>(m_aValue
.m_pValue
);
868 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
869 rValue
<<= *static_cast<Time
*>(m_aValue
.m_pValue
);
871 case DataType::TIMESTAMP
:
872 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
873 rValue
<<= *static_cast<DateTime
*>(m_aValue
.m_pValue
);
875 case DataType::BINARY
:
876 case DataType::VARBINARY
:
877 case DataType::LONGVARBINARY
:
878 OSL_ENSURE(m_aValue
.m_pValue
,"Value is null!");
879 rValue
<<= *static_cast<Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
883 case DataType::OBJECT
:
884 case DataType::OTHER
:
888 case DataType::BOOLEAN
:
889 rValue
<<= m_aValue
.m_bBool
;
891 case DataType::TINYINT
:
894 rValue
<<= m_aValue
.m_nInt8
;
896 // There is no TypeClass_UNSIGNED_BYTE,
897 // so silently promote it to a 16-bit integer,
898 // that is TypeClass_UNSIGNED_SHORT
899 rValue
<<= static_cast<sal_uInt16
>(m_aValue
.m_uInt8
);
901 case DataType::SMALLINT
:
904 rValue
<<= m_aValue
.m_nInt16
;
906 // TypeClass_UNSIGNED_SHORT
907 rValue
<<= m_aValue
.m_uInt16
;
909 case DataType::INTEGER
:
912 rValue
<<= m_aValue
.m_nInt32
;
914 // TypeClass_UNSIGNED_LONG
915 rValue
<<= m_aValue
.m_uInt32
;
917 case DataType::BIGINT
:
920 rValue
<<= m_aValue
.m_nInt64
;
922 // TypeClass_UNSIGNED_HYPER
923 rValue
<<= m_aValue
.m_uInt64
;
926 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
934 OUString
ORowSetValue::getString( ) const
939 switch(getTypeKind())
942 case DataType::VARCHAR
:
943 case DataType::DECIMAL
:
944 case DataType::NUMERIC
:
945 case DataType::LONGVARCHAR
:
946 aRet
= m_aValue
.m_pString
;
948 case DataType::FLOAT
:
949 aRet
= OUString::number(static_cast<float>(*this));
951 case DataType::DOUBLE
:
953 aRet
= OUString::number(static_cast<double>(*this));
956 aRet
= DBTypeConversion::toDateString(*this);
959 aRet
= DBTypeConversion::toTimeString(*this);
961 case DataType::TIMESTAMP
:
962 aRet
= DBTypeConversion::toDateTimeString(*this);
964 case DataType::BINARY
:
965 case DataType::VARBINARY
:
966 case DataType::LONGVARBINARY
:
968 OUStringBuffer
sVal("0x");
969 Sequence
<sal_Int8
> aSeq(getSequence());
970 const sal_Int8
* pBegin
= aSeq
.getConstArray();
971 const sal_Int8
* pEnd
= pBegin
+ aSeq
.getLength();
972 for(;pBegin
!= pEnd
;++pBegin
)
973 sVal
.append(static_cast<sal_Int32
>(*pBegin
),16);
974 aRet
= sVal
.makeStringAndClear();
978 aRet
= OUString::number(int(static_cast<bool>(*this)));
980 case DataType::BOOLEAN
:
981 aRet
= OUString::boolean(static_cast<bool>(*this));
983 case DataType::TINYINT
:
984 case DataType::SMALLINT
:
985 case DataType::INTEGER
:
987 aRet
= OUString::number(static_cast<sal_Int32
>(*this));
989 aRet
= OUString::number(static_cast<sal_uInt32
>(*this));
991 case DataType::BIGINT
:
993 aRet
= OUString::number(static_cast<sal_Int64
>(*this));
995 aRet
= OUString::number(static_cast<sal_uInt64
>(*this));
999 Any
aValue( getAny() );
1000 Reference
< XClob
> xClob
;
1001 if ( (aValue
>>= xClob
) && xClob
.is() )
1003 aRet
= xClob
->getSubString(1,static_cast<sal_Int32
>(xClob
->length()) );
1009 Any aValue
= makeAny();
1018 bool ORowSetValue::getBool() const
1023 switch(getTypeKind())
1025 case DataType::CHAR
:
1026 case DataType::VARCHAR
:
1027 case DataType::LONGVARCHAR
:
1029 const OUString
sValue(m_aValue
.m_pString
);
1030 if ( sValue
.equalsIgnoreAsciiCase("true") || (sValue
== "1") )
1035 else if ( sValue
.equalsIgnoreAsciiCase("false") || (sValue
== "0") )
1042 case DataType::DECIMAL
:
1043 case DataType::NUMERIC
:
1045 bRet
= OUString(m_aValue
.m_pString
).toInt32() != 0;
1047 case DataType::FLOAT
:
1048 bRet
= m_aValue
.m_nFloat
!= 0.0;
1050 case DataType::DOUBLE
:
1051 case DataType::REAL
:
1052 bRet
= m_aValue
.m_nDouble
!= 0.0;
1054 case DataType::DATE
:
1055 case DataType::TIME
:
1056 case DataType::TIMESTAMP
:
1057 case DataType::BINARY
:
1058 case DataType::VARBINARY
:
1059 case DataType::LONGVARBINARY
:
1060 OSL_FAIL("getBool() for this type is not allowed!");
1063 case DataType::BOOLEAN
:
1064 bRet
= m_aValue
.m_bBool
;
1066 case DataType::TINYINT
:
1067 bRet
= m_bSigned
? (m_aValue
.m_nInt8
!= 0) : (m_aValue
.m_uInt8
!= 0);
1069 case DataType::SMALLINT
:
1070 bRet
= m_bSigned
? (m_aValue
.m_nInt16
!= 0) : (m_aValue
.m_uInt16
!= 0);
1072 case DataType::INTEGER
:
1073 bRet
= m_bSigned
? (m_aValue
.m_nInt32
!= 0) : (m_aValue
.m_uInt32
!= 0);
1075 case DataType::BIGINT
:
1076 bRet
= m_bSigned
? (m_aValue
.m_nInt64
!= 0) : (m_aValue
.m_uInt64
!= 0);
1080 Any aValue
= makeAny();
1090 sal_Int8
ORowSetValue::getInt8() const
1095 switch(getTypeKind())
1097 case DataType::CHAR
:
1098 case DataType::VARCHAR
:
1099 case DataType::DECIMAL
:
1100 case DataType::NUMERIC
:
1101 case DataType::LONGVARCHAR
:
1102 nRet
= sal_Int8(OUString(m_aValue
.m_pString
).toInt32());
1104 case DataType::FLOAT
:
1105 nRet
= sal_Int8(m_aValue
.m_nFloat
);
1107 case DataType::DOUBLE
:
1108 case DataType::REAL
:
1109 nRet
= sal_Int8(m_aValue
.m_nDouble
);
1111 case DataType::DATE
:
1112 case DataType::TIME
:
1113 case DataType::TIMESTAMP
:
1114 case DataType::BINARY
:
1115 case DataType::VARBINARY
:
1116 case DataType::LONGVARBINARY
:
1117 case DataType::BLOB
:
1118 case DataType::CLOB
:
1119 OSL_FAIL("getInt8() for this type is not allowed!");
1122 case DataType::BOOLEAN
:
1123 nRet
= sal_Int8(m_aValue
.m_bBool
);
1125 case DataType::TINYINT
:
1127 nRet
= m_aValue
.m_nInt8
;
1129 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt8
);
1131 case DataType::SMALLINT
:
1133 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt16
);
1135 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt16
);
1137 case DataType::INTEGER
:
1139 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt32
);
1141 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt32
);
1143 case DataType::BIGINT
:
1145 nRet
= static_cast<sal_Int8
>(m_aValue
.m_nInt64
);
1147 nRet
= static_cast<sal_Int8
>(m_aValue
.m_uInt64
);
1151 Any aValue
= makeAny();
1161 sal_uInt8
ORowSetValue::getUInt8() const
1166 switch(getTypeKind())
1168 case DataType::CHAR
:
1169 case DataType::VARCHAR
:
1170 case DataType::DECIMAL
:
1171 case DataType::NUMERIC
:
1172 case DataType::LONGVARCHAR
:
1173 nRet
= sal_uInt8(OUString(m_aValue
.m_pString
).toInt32());
1175 case DataType::FLOAT
:
1176 nRet
= sal_uInt8(m_aValue
.m_nFloat
);
1178 case DataType::DOUBLE
:
1179 case DataType::REAL
:
1180 nRet
= sal_uInt8(m_aValue
.m_nDouble
);
1182 case DataType::DATE
:
1183 case DataType::TIME
:
1184 case DataType::TIMESTAMP
:
1185 case DataType::BINARY
:
1186 case DataType::VARBINARY
:
1187 case DataType::LONGVARBINARY
:
1188 case DataType::BLOB
:
1189 case DataType::CLOB
:
1190 OSL_FAIL("getuInt8() for this type is not allowed!");
1193 case DataType::BOOLEAN
:
1194 nRet
= int(m_aValue
.m_bBool
);
1196 case DataType::TINYINT
:
1198 nRet
= m_aValue
.m_nInt8
;
1200 nRet
= m_aValue
.m_uInt8
;
1202 case DataType::SMALLINT
:
1204 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt16
);
1206 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt16
);
1208 case DataType::INTEGER
:
1210 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt32
);
1212 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt32
);
1214 case DataType::BIGINT
:
1216 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_nInt64
);
1218 nRet
= static_cast<sal_uInt8
>(m_aValue
.m_uInt64
);
1222 Any aValue
= makeAny();
1223 // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1226 nRet
= static_cast<sal_uInt8
>(n
);
1236 sal_Int16
ORowSetValue::getInt16() const
1241 switch(getTypeKind())
1243 case DataType::CHAR
:
1244 case DataType::VARCHAR
:
1245 case DataType::DECIMAL
:
1246 case DataType::NUMERIC
:
1247 case DataType::LONGVARCHAR
:
1248 nRet
= sal_Int16(OUString(m_aValue
.m_pString
).toInt32());
1250 case DataType::FLOAT
:
1251 nRet
= sal_Int16(m_aValue
.m_nFloat
);
1253 case DataType::DOUBLE
:
1254 case DataType::REAL
:
1255 nRet
= sal_Int16(m_aValue
.m_nDouble
);
1257 case DataType::DATE
:
1258 case DataType::TIME
:
1259 case DataType::TIMESTAMP
:
1260 case DataType::BINARY
:
1261 case DataType::VARBINARY
:
1262 case DataType::LONGVARBINARY
:
1263 case DataType::BLOB
:
1264 case DataType::CLOB
:
1265 OSL_FAIL("getInt16() for this type is not allowed!");
1268 case DataType::BOOLEAN
:
1269 nRet
= sal_Int16(m_aValue
.m_bBool
);
1271 case DataType::TINYINT
:
1273 nRet
= m_aValue
.m_nInt8
;
1275 nRet
= m_aValue
.m_uInt8
;
1277 case DataType::SMALLINT
:
1279 nRet
= m_aValue
.m_nInt16
;
1281 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt16
);
1283 case DataType::INTEGER
:
1285 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt32
);
1287 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt32
);
1289 case DataType::BIGINT
:
1291 nRet
= static_cast<sal_Int16
>(m_aValue
.m_nInt64
);
1293 nRet
= static_cast<sal_Int16
>(m_aValue
.m_uInt64
);
1297 Any aValue
= makeAny();
1307 sal_uInt16
ORowSetValue::getUInt16() const
1309 sal_uInt16 nRet
= 0;
1312 switch(getTypeKind())
1314 case DataType::CHAR
:
1315 case DataType::VARCHAR
:
1316 case DataType::DECIMAL
:
1317 case DataType::NUMERIC
:
1318 case DataType::LONGVARCHAR
:
1319 nRet
= sal_uInt16(OUString(m_aValue
.m_pString
).toInt32());
1321 case DataType::FLOAT
:
1322 nRet
= sal_uInt16(m_aValue
.m_nFloat
);
1324 case DataType::DOUBLE
:
1325 case DataType::REAL
:
1326 nRet
= sal_uInt16(m_aValue
.m_nDouble
);
1328 case DataType::DATE
:
1329 case DataType::TIME
:
1330 case DataType::TIMESTAMP
:
1331 case DataType::BINARY
:
1332 case DataType::VARBINARY
:
1333 case DataType::LONGVARBINARY
:
1334 case DataType::BLOB
:
1335 case DataType::CLOB
:
1336 OSL_FAIL("getuInt16() for this type is not allowed!");
1339 case DataType::BOOLEAN
:
1340 nRet
= sal_uInt16(m_aValue
.m_bBool
);
1342 case DataType::TINYINT
:
1344 nRet
= m_aValue
.m_nInt8
;
1346 nRet
= m_aValue
.m_uInt8
;
1348 case DataType::SMALLINT
:
1350 nRet
= m_aValue
.m_nInt16
;
1352 nRet
= m_aValue
.m_uInt16
;
1354 case DataType::INTEGER
:
1356 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt32
);
1358 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt32
);
1360 case DataType::BIGINT
:
1362 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_nInt64
);
1364 nRet
= static_cast<sal_uInt16
>(m_aValue
.m_uInt64
);
1368 Any aValue
= makeAny();
1378 sal_Int32
ORowSetValue::getInt32() const
1383 switch(getTypeKind())
1385 case DataType::CHAR
:
1386 case DataType::VARCHAR
:
1387 case DataType::DECIMAL
:
1388 case DataType::NUMERIC
:
1389 case DataType::LONGVARCHAR
:
1390 nRet
= OUString(m_aValue
.m_pString
).toInt32();
1392 case DataType::FLOAT
:
1393 nRet
= sal_Int32(m_aValue
.m_nFloat
);
1395 case DataType::DOUBLE
:
1396 case DataType::REAL
:
1397 nRet
= sal_Int32(m_aValue
.m_nDouble
);
1399 case DataType::DATE
:
1400 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1402 case DataType::TIME
:
1403 case DataType::TIMESTAMP
:
1404 case DataType::BINARY
:
1405 case DataType::VARBINARY
:
1406 case DataType::LONGVARBINARY
:
1407 case DataType::BLOB
:
1408 case DataType::CLOB
:
1409 OSL_FAIL("getInt32() for this type is not allowed!");
1412 case DataType::BOOLEAN
:
1413 nRet
= sal_Int32(m_aValue
.m_bBool
);
1415 case DataType::TINYINT
:
1417 nRet
= m_aValue
.m_nInt8
;
1419 nRet
= m_aValue
.m_uInt8
;
1421 case DataType::SMALLINT
:
1423 nRet
= m_aValue
.m_nInt16
;
1425 nRet
= m_aValue
.m_uInt16
;
1427 case DataType::INTEGER
:
1429 nRet
= m_aValue
.m_nInt32
;
1431 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt32
);
1433 case DataType::BIGINT
:
1435 nRet
= static_cast<sal_Int32
>(m_aValue
.m_nInt64
);
1437 nRet
= static_cast<sal_Int32
>(m_aValue
.m_uInt64
);
1441 Any aValue
= makeAny();
1451 sal_uInt32
ORowSetValue::getUInt32() const
1453 sal_uInt32 nRet
= 0;
1456 switch(getTypeKind())
1458 case DataType::CHAR
:
1459 case DataType::VARCHAR
:
1460 case DataType::DECIMAL
:
1461 case DataType::NUMERIC
:
1462 case DataType::LONGVARCHAR
:
1463 nRet
= OUString(m_aValue
.m_pString
).toUInt32();
1465 case DataType::FLOAT
:
1466 nRet
= sal_uInt32(m_aValue
.m_nFloat
);
1468 case DataType::DOUBLE
:
1469 case DataType::REAL
:
1470 nRet
= sal_uInt32(m_aValue
.m_nDouble
);
1472 case DataType::DATE
:
1473 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1475 case DataType::TIME
:
1476 case DataType::TIMESTAMP
:
1477 case DataType::BINARY
:
1478 case DataType::VARBINARY
:
1479 case DataType::LONGVARBINARY
:
1480 case DataType::BLOB
:
1481 case DataType::CLOB
:
1482 OSL_FAIL("getuInt32() for this type is not allowed!");
1485 case DataType::BOOLEAN
:
1486 nRet
= sal_uInt32(m_aValue
.m_bBool
);
1488 case DataType::TINYINT
:
1490 nRet
= m_aValue
.m_nInt8
;
1492 nRet
= m_aValue
.m_uInt8
;
1494 case DataType::SMALLINT
:
1496 nRet
= m_aValue
.m_nInt16
;
1498 nRet
= m_aValue
.m_uInt16
;
1500 case DataType::INTEGER
:
1502 nRet
= m_aValue
.m_nInt32
;
1504 nRet
= m_aValue
.m_uInt32
;
1506 case DataType::BIGINT
:
1508 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_nInt64
);
1510 nRet
= static_cast<sal_uInt32
>(m_aValue
.m_uInt64
);
1514 Any aValue
= makeAny();
1524 sal_Int64
ORowSetValue::getLong() const
1529 switch(getTypeKind())
1531 case DataType::CHAR
:
1532 case DataType::VARCHAR
:
1533 case DataType::DECIMAL
:
1534 case DataType::NUMERIC
:
1535 case DataType::LONGVARCHAR
:
1536 nRet
= OUString(m_aValue
.m_pString
).toInt64();
1538 case DataType::FLOAT
:
1539 nRet
= sal_Int64(m_aValue
.m_nFloat
);
1541 case DataType::DOUBLE
:
1542 case DataType::REAL
:
1543 nRet
= sal_Int64(m_aValue
.m_nDouble
);
1545 case DataType::DATE
:
1546 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1548 case DataType::TIME
:
1549 case DataType::TIMESTAMP
:
1550 case DataType::BINARY
:
1551 case DataType::VARBINARY
:
1552 case DataType::LONGVARBINARY
:
1553 case DataType::BLOB
:
1554 case DataType::CLOB
:
1555 OSL_FAIL("getLong() for this type is not allowed!");
1558 case DataType::BOOLEAN
:
1559 nRet
= sal_Int64(m_aValue
.m_bBool
);
1561 case DataType::TINYINT
:
1563 nRet
= m_aValue
.m_nInt8
;
1565 nRet
= m_aValue
.m_uInt8
;
1567 case DataType::SMALLINT
:
1569 nRet
= m_aValue
.m_nInt16
;
1571 nRet
= m_aValue
.m_uInt16
;
1573 case DataType::INTEGER
:
1575 nRet
= m_aValue
.m_nInt32
;
1577 nRet
= m_aValue
.m_uInt32
;
1579 case DataType::BIGINT
:
1581 nRet
= m_aValue
.m_nInt64
;
1583 nRet
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
1587 Any aValue
= makeAny();
1597 sal_uInt64
ORowSetValue::getULong() const
1599 sal_uInt64 nRet
= 0;
1602 switch(getTypeKind())
1604 case DataType::CHAR
:
1605 case DataType::VARCHAR
:
1606 case DataType::DECIMAL
:
1607 case DataType::NUMERIC
:
1608 case DataType::LONGVARCHAR
:
1609 nRet
= OUString(m_aValue
.m_pString
).toUInt64();
1611 case DataType::FLOAT
:
1612 nRet
= sal_uInt64(m_aValue
.m_nFloat
);
1614 case DataType::DOUBLE
:
1615 case DataType::REAL
:
1616 nRet
= sal_uInt64(m_aValue
.m_nDouble
);
1618 case DataType::DATE
:
1619 nRet
= dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1621 case DataType::TIME
:
1622 case DataType::TIMESTAMP
:
1623 case DataType::BINARY
:
1624 case DataType::VARBINARY
:
1625 case DataType::LONGVARBINARY
:
1626 case DataType::BLOB
:
1627 case DataType::CLOB
:
1628 OSL_FAIL("getULong() for this type is not allowed!");
1631 case DataType::BOOLEAN
:
1632 nRet
= sal_uInt64(m_aValue
.m_bBool
);
1634 case DataType::TINYINT
:
1636 nRet
= m_aValue
.m_nInt8
;
1638 nRet
= m_aValue
.m_uInt8
;
1640 case DataType::SMALLINT
:
1642 nRet
= m_aValue
.m_nInt16
;
1644 nRet
= m_aValue
.m_uInt16
;
1646 case DataType::INTEGER
:
1648 nRet
= m_aValue
.m_nInt32
;
1650 nRet
= m_aValue
.m_uInt32
;
1652 case DataType::BIGINT
:
1654 nRet
= m_aValue
.m_nInt64
;
1656 nRet
= m_aValue
.m_uInt64
;
1660 Any aValue
= makeAny();
1670 float ORowSetValue::getFloat() const
1675 switch(getTypeKind())
1677 case DataType::CHAR
:
1678 case DataType::VARCHAR
:
1679 case DataType::DECIMAL
:
1680 case DataType::NUMERIC
:
1681 case DataType::LONGVARCHAR
:
1682 nRet
= OUString(m_aValue
.m_pString
).toFloat();
1684 case DataType::FLOAT
:
1685 nRet
= m_aValue
.m_nFloat
;
1687 case DataType::DOUBLE
:
1688 case DataType::REAL
:
1689 nRet
= static_cast<float>(m_aValue
.m_nDouble
);
1691 case DataType::DATE
:
1692 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
)));
1694 case DataType::TIME
:
1695 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
)));
1697 case DataType::TIMESTAMP
:
1698 nRet
= static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
)));
1700 case DataType::BINARY
:
1701 case DataType::VARBINARY
:
1702 case DataType::LONGVARBINARY
:
1703 case DataType::BLOB
:
1704 case DataType::CLOB
:
1705 OSL_FAIL("getDouble() for this type is not allowed!");
1708 case DataType::BOOLEAN
:
1709 nRet
= float(m_aValue
.m_bBool
);
1711 case DataType::TINYINT
:
1713 nRet
= m_aValue
.m_nInt8
;
1715 nRet
= m_aValue
.m_uInt8
;
1717 case DataType::SMALLINT
:
1719 nRet
= m_aValue
.m_nInt16
;
1721 nRet
= static_cast<float>(m_aValue
.m_uInt16
);
1723 case DataType::INTEGER
:
1725 nRet
= static_cast<float>(m_aValue
.m_nInt32
);
1727 nRet
= static_cast<float>(m_aValue
.m_uInt32
);
1729 case DataType::BIGINT
:
1731 nRet
= static_cast<float>(m_aValue
.m_nInt64
);
1733 nRet
= static_cast<float>(m_aValue
.m_uInt64
);
1737 Any aValue
= makeAny();
1746 double ORowSetValue::getDouble() const
1751 switch(getTypeKind())
1753 case DataType::CHAR
:
1754 case DataType::VARCHAR
:
1755 case DataType::DECIMAL
:
1756 case DataType::NUMERIC
:
1757 case DataType::LONGVARCHAR
:
1758 nRet
= OUString(m_aValue
.m_pString
).toDouble();
1760 case DataType::FLOAT
:
1761 nRet
= m_aValue
.m_nFloat
;
1763 case DataType::DOUBLE
:
1764 case DataType::REAL
:
1765 nRet
= m_aValue
.m_nDouble
;
1767 case DataType::DATE
:
1768 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date
*>(m_aValue
.m_pValue
));
1770 case DataType::TIME
:
1771 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time
*>(m_aValue
.m_pValue
));
1773 case DataType::TIMESTAMP
:
1774 nRet
= dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime
*>(m_aValue
.m_pValue
));
1776 case DataType::BINARY
:
1777 case DataType::VARBINARY
:
1778 case DataType::LONGVARBINARY
:
1779 case DataType::BLOB
:
1780 case DataType::CLOB
:
1781 OSL_FAIL("getDouble() for this type is not allowed!");
1784 case DataType::BOOLEAN
:
1785 nRet
= double(m_aValue
.m_bBool
);
1787 case DataType::TINYINT
:
1789 nRet
= m_aValue
.m_nInt8
;
1791 nRet
= m_aValue
.m_uInt8
;
1793 case DataType::SMALLINT
:
1795 nRet
= m_aValue
.m_nInt16
;
1797 nRet
= m_aValue
.m_uInt16
;
1799 case DataType::INTEGER
:
1801 nRet
= m_aValue
.m_nInt32
;
1803 nRet
= m_aValue
.m_uInt32
;
1805 case DataType::BIGINT
:
1807 nRet
= m_aValue
.m_nInt64
;
1809 nRet
= m_aValue
.m_uInt64
;
1813 Any aValue
= makeAny();
1822 Sequence
<sal_Int8
> ORowSetValue::getSequence() const
1824 Sequence
<sal_Int8
> aSeq
;
1829 case DataType::OBJECT
:
1830 case DataType::CLOB
:
1831 case DataType::BLOB
:
1833 Reference
<XInputStream
> xStream
;
1834 const Any aValue
= makeAny();
1835 if(aValue
.hasValue())
1837 Reference
<XBlob
> xBlob(aValue
,UNO_QUERY
);
1839 xStream
= xBlob
->getBinaryStream();
1842 Reference
<XClob
> xClob(aValue
,UNO_QUERY
);
1844 xStream
= xClob
->getCharacterStream();
1848 const sal_uInt32 nBytesToRead
= 65535;
1853 css::uno::Sequence
< sal_Int8
> aReadSeq
;
1855 nRead
= xStream
->readSomeBytes( aReadSeq
, nBytesToRead
);
1859 const sal_uInt32 nOldLength
= aSeq
.getLength();
1860 aSeq
.realloc( nOldLength
+ nRead
);
1861 memcpy( aSeq
.getArray() + nOldLength
, aReadSeq
.getConstArray(), aReadSeq
.getLength() );
1864 while( nBytesToRead
== nRead
);
1865 xStream
->closeInput();
1870 case DataType::VARCHAR
:
1871 case DataType::LONGVARCHAR
:
1873 aSeq
= Sequence
<sal_Int8
>(reinterpret_cast<const sal_Int8
*>(m_aValue
.m_pString
->buffer
),
1874 sizeof(sal_Unicode
) * m_aValue
.m_pString
->length
);
1877 case DataType::BINARY
:
1878 case DataType::VARBINARY
:
1879 case DataType::LONGVARBINARY
:
1880 aSeq
= *static_cast< Sequence
<sal_Int8
>*>(m_aValue
.m_pValue
);
1884 Any aValue
= makeAny();
1894 css::util::Date
ORowSetValue::getDate() const
1896 css::util::Date aValue
;
1901 case DataType::CHAR
:
1902 case DataType::VARCHAR
:
1903 case DataType::LONGVARCHAR
:
1904 aValue
= DBTypeConversion::toDate(getString());
1906 case DataType::DECIMAL
:
1907 case DataType::NUMERIC
:
1908 case DataType::FLOAT
:
1909 case DataType::DOUBLE
:
1910 case DataType::REAL
:
1911 aValue
= DBTypeConversion::toDate(static_cast<double>(*this));
1914 case DataType::DATE
:
1915 aValue
= *static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
1917 case DataType::TIMESTAMP
:
1919 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1920 aValue
.Day
= pDateTime
->Day
;
1921 aValue
.Month
= pDateTime
->Month
;
1922 aValue
.Year
= pDateTime
->Year
;
1926 case DataType::BOOLEAN
:
1927 case DataType::TINYINT
:
1928 case DataType::SMALLINT
:
1929 case DataType::INTEGER
:
1930 case DataType::BIGINT
:
1931 aValue
= DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1934 case DataType::BLOB
:
1935 case DataType::CLOB
:
1936 case DataType::OBJECT
:
1938 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1941 case DataType::BINARY
:
1942 case DataType::VARBINARY
:
1943 case DataType::LONGVARBINARY
:
1944 case DataType::TIME
:
1945 aValue
= DBTypeConversion::toDate( double(0) );
1952 css::util::Time
ORowSetValue::getTime() const
1954 css::util::Time aValue
;
1959 case DataType::CHAR
:
1960 case DataType::VARCHAR
:
1961 case DataType::LONGVARCHAR
:
1962 aValue
= DBTypeConversion::toTime(getString());
1964 case DataType::DECIMAL
:
1965 case DataType::NUMERIC
:
1966 aValue
= DBTypeConversion::toTime(static_cast<double>(*this));
1968 case DataType::FLOAT
:
1969 case DataType::DOUBLE
:
1970 case DataType::REAL
:
1971 aValue
= DBTypeConversion::toTime(static_cast<double>(*this));
1973 case DataType::TIMESTAMP
:
1975 css::util::DateTime
* pDateTime
= static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
1976 aValue
.NanoSeconds
= pDateTime
->NanoSeconds
;
1977 aValue
.Seconds
= pDateTime
->Seconds
;
1978 aValue
.Minutes
= pDateTime
->Minutes
;
1979 aValue
.Hours
= pDateTime
->Hours
;
1982 case DataType::TIME
:
1983 aValue
= *static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
1987 Any aAnyValue
= makeAny();
1988 aAnyValue
>>= aValue
;
1996 css::util::DateTime
ORowSetValue::getDateTime() const
1998 css::util::DateTime aValue
;
2003 case DataType::CHAR
:
2004 case DataType::VARCHAR
:
2005 case DataType::LONGVARCHAR
:
2006 aValue
= DBTypeConversion::toDateTime(getString());
2008 case DataType::DECIMAL
:
2009 case DataType::NUMERIC
:
2010 aValue
= DBTypeConversion::toDateTime(static_cast<double>(*this));
2012 case DataType::FLOAT
:
2013 case DataType::DOUBLE
:
2014 case DataType::REAL
:
2015 aValue
= DBTypeConversion::toDateTime(static_cast<double>(*this));
2017 case DataType::DATE
:
2019 css::util::Date
* pDate
= static_cast< css::util::Date
*>(m_aValue
.m_pValue
);
2020 aValue
.Day
= pDate
->Day
;
2021 aValue
.Month
= pDate
->Month
;
2022 aValue
.Year
= pDate
->Year
;
2025 case DataType::TIME
:
2027 css::util::Time
* pTime
= static_cast< css::util::Time
*>(m_aValue
.m_pValue
);
2028 aValue
.NanoSeconds
= pTime
->NanoSeconds
;
2029 aValue
.Seconds
= pTime
->Seconds
;
2030 aValue
.Minutes
= pTime
->Minutes
;
2031 aValue
.Hours
= pTime
->Hours
;
2034 case DataType::TIMESTAMP
:
2035 aValue
= *static_cast< css::util::DateTime
*>(m_aValue
.m_pValue
);
2039 Any aAnyValue
= makeAny();
2040 aAnyValue
>>= aValue
;
2048 void ORowSetValue::setSigned(bool _bMod
)
2050 if ( m_bSigned
!= _bMod
)
2055 sal_Int32 nType
= m_eTypeKind
;
2058 case DataType::TINYINT
:
2060 (*this) = getInt8();
2063 m_bSigned
= !m_bSigned
;
2064 (*this) = getInt16();
2065 m_bSigned
= !m_bSigned
;
2068 case DataType::SMALLINT
:
2070 (*this) = getInt16();
2073 m_bSigned
= !m_bSigned
;
2074 (*this) = getInt32();
2075 m_bSigned
= !m_bSigned
;
2078 case DataType::INTEGER
:
2080 (*this) = getInt32();
2083 m_bSigned
= !m_bSigned
;
2084 (*this) = getLong();
2085 m_bSigned
= !m_bSigned
;
2088 case DataType::BIGINT
:
2090 m_aValue
.m_nInt64
= static_cast<sal_Int64
>(m_aValue
.m_uInt64
);
2092 m_aValue
.m_uInt64
= static_cast<sal_uInt64
>(m_aValue
.m_nInt64
);
2095 m_eTypeKind
= nType
;
2103 class SAL_NO_VTABLE IValueSource
2106 virtual OUString
getString() const = 0;
2107 virtual bool getBoolean() const = 0;
2108 virtual sal_Int8
getByte() const = 0;
2109 virtual sal_Int16
getShort() const = 0;
2110 virtual sal_Int32
getInt() const = 0;
2111 virtual sal_Int64
getLong() const = 0;
2112 virtual float getFloat() const = 0;
2113 virtual double getDouble() const = 0;
2114 virtual Date
getDate() const = 0;
2115 virtual css::util::Time
getTime() const = 0;
2116 virtual DateTime
getTimestamp() const = 0;
2117 virtual Sequence
< sal_Int8
> getBytes() const = 0;
2118 virtual Reference
< XBlob
> getBlob() const = 0;
2119 virtual Reference
< XClob
> getClob() const = 0;
2120 virtual Any
getObject() const = 0;
2121 virtual bool wasNull() const = 0;
2123 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
;
2190 void ORowSetValue::fill( const sal_Int32 _nType
, const Reference
< XColumn
>& _rxColumn
)
2192 detail::ColumnValue
aColumnValue( _rxColumn
);
2193 impl_fill( _nType
, true, aColumnValue
);
2197 void ORowSetValue::fill( sal_Int32 _nPos
, sal_Int32 _nType
, bool _bNullable
, const Reference
< XRow
>& _xRow
)
2199 detail::RowValue
aRowValue( _xRow
, _nPos
);
2200 impl_fill( _nType
, _bNullable
, aRowValue
);
2204 void ORowSetValue::fill(sal_Int32 _nPos
,
2206 const css::uno::Reference
< css::sdbc::XRow
>& _xRow
)
2208 fill(_nPos
,_nType
,true,_xRow
);
2212 void ORowSetValue::impl_fill( const sal_Int32 _nType
, bool _bNullable
, const detail::IValueSource
& _rValueSource
)
2216 case DataType::CHAR
:
2217 case DataType::VARCHAR
:
2218 case DataType::DECIMAL
:
2219 case DataType::NUMERIC
:
2220 case DataType::LONGVARCHAR
:
2221 (*this) = _rValueSource
.getString();
2223 case DataType::BIGINT
:
2225 (*this) = _rValueSource
.getLong();
2227 // TODO: this is rather horrible performance-wise
2228 // but fixing it needs extending the css::sdbc::XRow API
2229 // to have a getULong(), and needs updating all drivers :-|
2230 // When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2231 (*this) = _rValueSource
.getString().toUInt64();
2233 case DataType::FLOAT
:
2234 (*this) = _rValueSource
.getFloat();
2236 case DataType::DOUBLE
:
2237 case DataType::REAL
:
2238 (*this) = _rValueSource
.getDouble();
2240 case DataType::DATE
:
2241 (*this) = _rValueSource
.getDate();
2243 case DataType::TIME
:
2244 (*this) = _rValueSource
.getTime();
2246 case DataType::TIMESTAMP
:
2247 (*this) = _rValueSource
.getTimestamp();
2249 case DataType::BINARY
:
2250 case DataType::VARBINARY
:
2251 case DataType::LONGVARBINARY
:
2252 (*this) = _rValueSource
.getBytes();
2255 case DataType::BOOLEAN
:
2256 (*this) = _rValueSource
.getBoolean();
2258 case DataType::TINYINT
:
2260 (*this) = _rValueSource
.getByte();
2262 (*this) = _rValueSource
.getShort();
2264 case DataType::SMALLINT
:
2266 (*this) = _rValueSource
.getShort();
2268 (*this) = _rValueSource
.getInt();
2270 case DataType::INTEGER
:
2272 (*this) = _rValueSource
.getInt();
2274 (*this) = _rValueSource
.getLong();
2276 case DataType::CLOB
:
2277 (*this) = css::uno::makeAny(_rValueSource
.getClob());
2278 setTypeKind(DataType::CLOB
);
2280 case DataType::BLOB
:
2281 (*this) = css::uno::makeAny(_rValueSource
.getBlob());
2282 setTypeKind(DataType::BLOB
);
2284 case DataType::OTHER
:
2285 (*this) = _rValueSource
.getObject();
2286 setTypeKind(DataType::OTHER
);
2289 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2290 (*this) = _rValueSource
.getObject();
2293 if ( _bNullable
&& _rValueSource
.wasNull() )
2295 setTypeKind(_nType
);
2298 void ORowSetValue::fill(const Any
& _rValue
)
2300 switch (_rValue
.getValueType().getTypeClass())
2302 case TypeClass_VOID
:
2304 case TypeClass_BOOLEAN
:
2306 bool bValue( false );
2311 case TypeClass_CHAR
:
2313 sal_Unicode
aDummy(0);
2315 (*this) = OUString(aDummy
);
2318 case TypeClass_STRING
:
2325 case TypeClass_FLOAT
:
2332 case TypeClass_DOUBLE
:
2339 case TypeClass_BYTE
:
2346 case TypeClass_SHORT
:
2348 sal_Int16
aDummy(0);
2353 case TypeClass_UNSIGNED_SHORT
:
2355 sal_uInt16
nValue(0);
2360 case TypeClass_LONG
:
2362 sal_Int32
aDummy(0);
2367 case TypeClass_UNSIGNED_LONG
:
2369 sal_uInt32
nValue(0);
2371 (*this) = static_cast<sal_Int64
>(nValue
);
2375 case TypeClass_HYPER
:
2377 sal_Int64
nValue(0);
2382 case TypeClass_UNSIGNED_HYPER
:
2384 sal_uInt64
nValue(0);
2390 case TypeClass_ENUM
:
2392 sal_Int32
enumValue( 0 );
2393 ::cppu::enum2int( enumValue
, _rValue
);
2394 (*this) = enumValue
;
2398 case TypeClass_SEQUENCE
:
2400 Sequence
<sal_Int8
> aDummy
;
2401 if ( _rValue
>>= aDummy
)
2404 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2408 case TypeClass_STRUCT
:
2410 css::util::Date aDate
;
2411 css::util::Time aTime
;
2412 css::util::DateTime aDateTime
;
2413 if ( _rValue
>>= aDate
)
2417 else if ( _rValue
>>= aTime
)
2421 else if ( _rValue
>>= aDateTime
)
2423 (*this) = aDateTime
;
2426 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2430 case TypeClass_INTERFACE
:
2432 Reference
< XClob
> xClob
;
2433 if ( _rValue
>>= xClob
)
2436 setTypeKind(DataType::CLOB
);
2440 Reference
< XBlob
> xBlob
;
2441 if ( _rValue
>>= xBlob
)
2444 setTypeKind(DataType::BLOB
);
2455 SAL_WARN( "connectivity.commontools","Unknown type");
2460 } // namespace connectivity
2462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */