update dev300-m58
[ooovba.git] / connectivity / source / commontools / FValue.cxx
blob37e91d22c890d233ab26860b3a8687d6809c5965
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FValue.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include <stdio.h>
35 #include "connectivity/FValue.hxx"
36 #include "connectivity/CommonTools.hxx"
37 #include <connectivity/dbconversion.hxx>
38 #include <cppuhelper/extract.hxx>
39 #include <com/sun/star/io/XInputStream.hpp>
40 #include <rtl/ustrbuf.hxx>
41 #include <rtl/logfile.hxx>
43 using namespace connectivity;
44 using namespace dbtools;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::util;
48 using namespace ::com::sun::star::io;
50 namespace {
51 static sal_Bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
53 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::isStorageCompatible" );
54 sal_Bool bIsCompatible = sal_True;
56 if (_eType1 != _eType2)
58 RTL_LOGFILE_CONTEXT_TRACE( aLogger, "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
59 switch (_eType1)
61 case DataType::CHAR:
62 case DataType::VARCHAR:
63 case DataType::DECIMAL:
64 case DataType::NUMERIC:
65 case DataType::LONGVARCHAR:
66 bIsCompatible = (DataType::CHAR == _eType2)
67 || (DataType::VARCHAR == _eType2)
68 || (DataType::DECIMAL == _eType2)
69 || (DataType::NUMERIC == _eType2)
70 || (DataType::LONGVARCHAR == _eType2);
71 break;
73 case DataType::DOUBLE:
74 case DataType::REAL:
75 bIsCompatible = (DataType::DOUBLE == _eType2)
76 || (DataType::REAL == _eType2);
77 break;
79 case DataType::BINARY:
80 case DataType::VARBINARY:
81 case DataType::LONGVARBINARY:
82 bIsCompatible = (DataType::BINARY == _eType2)
83 || (DataType::VARBINARY == _eType2)
84 || (DataType::LONGVARBINARY == _eType2);
85 break;
87 case DataType::INTEGER:
88 bIsCompatible = (DataType::SMALLINT == _eType2)
89 || (DataType::TINYINT == _eType2)
90 || (DataType::BIT == _eType2)
91 || (DataType::BOOLEAN == _eType2);
92 break;
93 case DataType::SMALLINT:
94 bIsCompatible = (DataType::TINYINT == _eType2)
95 || (DataType::BIT == _eType2)
96 || (DataType::BOOLEAN == _eType2);
97 break;
98 case DataType::TINYINT:
99 bIsCompatible = (DataType::BIT == _eType2)
100 || (DataType::BOOLEAN == _eType2);
101 break;
103 case DataType::BLOB:
104 case DataType::CLOB:
105 case DataType::OBJECT:
106 bIsCompatible = (DataType::BLOB == _eType2)
107 || (DataType::CLOB == _eType2)
108 || (DataType::OBJECT == _eType2);
109 break;
111 default:
112 bIsCompatible = sal_False;
115 return bIsCompatible;
119 // -----------------------------------------------------------------------------
120 #ifdef DBG_UTIL
122 #include <vector>
123 #include <rtl/string.h>
125 namespace tracing
127 struct AllocationType
129 const sal_Char* pName;
130 sal_Int32 nAllocatedUnits;
132 AllocationType( ) : pName( NULL ), nAllocatedUnits( 0 ) { }
135 // =============================================================================
136 class AllocationTracer
138 public:
139 typedef ::std::vector< AllocationType > AllocationState;
140 static AllocationState s_aAllocated;
141 static ::osl::Mutex s_aMutex;
143 public:
144 static void registerUnit( const sal_Char* _pName );
145 static void revokeUnit( const sal_Char* _pName );
147 private:
148 static AllocationState::iterator getLocation( const sal_Char* _pName );
151 // =============================================================================
152 AllocationTracer::AllocationState::iterator AllocationTracer::getLocation( const sal_Char* _pName )
154 AllocationState::iterator aLookFor = s_aAllocated.begin();
155 for ( ;
156 aLookFor != s_aAllocated.end();
157 ++aLookFor
160 if ( 0 == rtl_str_compare( aLookFor->pName, _pName ) )
161 // found
162 return aLookFor;
164 // not found
165 s_aAllocated.push_back( AllocationType() );
166 aLookFor = s_aAllocated.end(); --aLookFor;
167 aLookFor->pName = _pName; // note that this assumes that _pName is a constant string ....
168 return aLookFor;
171 // =============================================================================
172 AllocationTracer::AllocationState AllocationTracer::s_aAllocated;
173 ::osl::Mutex AllocationTracer::s_aMutex;
175 // =============================================================================
176 void AllocationTracer::registerUnit( const sal_Char* _pName )
178 ::osl::MutexGuard aGuard( s_aMutex );
180 AllocationState::iterator aPos = getLocation( _pName );
181 ++aPos->nAllocatedUnits;
184 // =============================================================================
185 void AllocationTracer::revokeUnit( const sal_Char* _pName )
187 ::osl::MutexGuard aGuard( s_aMutex );
189 AllocationState::iterator aPos = getLocation( _pName );
190 --aPos->nAllocatedUnits;
193 #define TRACE_ALLOC( type ) tracing::AllocationTracer::registerUnit( #type );
194 #define TRACE_FREE( type ) tracing::AllocationTracer::revokeUnit( #type );
196 #else
197 #define TRACE_ALLOC( type )
198 #define TRACE_FREE( type )
199 #endif
201 // -----------------------------------------------------------------------------
202 void ORowSetValue::setTypeKind(sal_Int32 _eType)
204 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setTypeKind" );
205 if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
207 switch(_eType)
209 case DataType::VARCHAR:
210 case DataType::CHAR:
211 case DataType::DECIMAL:
212 case DataType::NUMERIC:
213 case DataType::LONGVARCHAR:
214 (*this) = getString();
215 break;
216 case DataType::BIGINT:
217 (*this) = getLong();
218 break;
220 case DataType::FLOAT:
221 (*this) = getFloat();
222 break;
223 case DataType::DOUBLE:
224 case DataType::REAL:
225 (*this) = getDouble();
226 break;
227 case DataType::TINYINT:
228 (*this) = getInt8();
229 break;
230 case DataType::SMALLINT:
231 (*this) = getInt16();
232 break;
233 case DataType::INTEGER:
234 (*this) = getInt32();
235 break;
236 case DataType::BIT:
237 case DataType::BOOLEAN:
238 (*this) = getBool();
239 break;
240 case DataType::DATE:
241 (*this) = getDate();
242 break;
243 case DataType::TIME:
244 (*this) = getTime();
245 break;
246 case DataType::TIMESTAMP:
247 (*this) = getDateTime();
248 break;
249 case DataType::BINARY:
250 case DataType::VARBINARY:
251 case DataType::LONGVARBINARY:
252 (*this) = getSequence();
253 break;
254 case DataType::BLOB:
255 case DataType::CLOB:
256 case DataType::OBJECT:
257 (*this) = getAny();
258 break;
259 default:
260 OSL_ENSURE(0,"ORowSetValue:operator==(): UNSPUPPORTED TYPE!");
264 m_eTypeKind = _eType;
267 // -----------------------------------------------------------------------------
268 void ORowSetValue::free()
270 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::free" );
271 if(!m_bNull)
273 switch(m_eTypeKind)
275 case DataType::CHAR:
276 case DataType::VARCHAR:
277 case DataType::DECIMAL:
278 case DataType::NUMERIC:
279 case DataType::LONGVARCHAR:
280 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
281 rtl_uString_release(m_aValue.m_pString);
282 m_aValue.m_pString = NULL;
283 break;
284 case DataType::INTEGER:
285 if ( !m_bSigned )
287 delete (sal_Int64*)m_aValue.m_pValue;
288 TRACE_FREE( sal_Int64 )
289 m_aValue.m_pValue = NULL;
291 break;
292 case DataType::BIGINT:
293 if ( m_bSigned )
295 delete (sal_Int64*)m_aValue.m_pValue;
296 TRACE_FREE( sal_Int64 )
297 m_aValue.m_pValue = NULL;
299 else
301 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
302 rtl_uString_release(m_aValue.m_pString);
303 m_aValue.m_pString = NULL;
305 break;
306 case DataType::FLOAT:
307 delete (float*)m_aValue.m_pValue;
308 TRACE_FREE( float )
309 m_aValue.m_pValue = NULL;
310 break;
311 case DataType::DOUBLE:
312 case DataType::REAL:
313 delete (double*)m_aValue.m_pValue;
314 TRACE_FREE( double )
315 m_aValue.m_pValue = NULL;
316 break;
317 case DataType::DATE:
318 delete (::com::sun::star::util::Date*)m_aValue.m_pValue;
319 TRACE_FREE( Date )
320 m_aValue.m_pValue = NULL;
321 break;
322 case DataType::TIME:
323 delete (::com::sun::star::util::Time*)m_aValue.m_pValue;
324 TRACE_FREE( Time )
325 m_aValue.m_pValue = NULL;
326 break;
327 case DataType::TIMESTAMP:
328 delete (::com::sun::star::util::DateTime*)m_aValue.m_pValue;
329 TRACE_FREE( DateTime )
330 m_aValue.m_pValue = NULL;
331 break;
332 case DataType::BINARY:
333 case DataType::VARBINARY:
334 case DataType::LONGVARBINARY:
335 delete (Sequence<sal_Int8>*)m_aValue.m_pValue;
336 TRACE_FREE( Sequence_sal_Int8 )
337 m_aValue.m_pValue = NULL;
338 break;
339 case DataType::BLOB:
340 case DataType::CLOB:
341 case DataType::OBJECT:
342 delete (Any*)m_aValue.m_pValue;
343 TRACE_FREE( Any )
344 m_aValue.m_pValue = NULL;
345 break;
348 m_bNull = sal_True;
351 // -----------------------------------------------------------------------------
352 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
354 if(&_rRH == this)
355 return *this;
357 if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
358 free();
360 m_bBound = _rRH.m_bBound;
361 m_eTypeKind = _rRH.m_eTypeKind;
362 m_bSigned = _rRH.m_bSigned;
364 if(m_bNull && !_rRH.m_bNull)
366 switch(_rRH.m_eTypeKind)
368 case DataType::CHAR:
369 case DataType::VARCHAR:
370 case DataType::DECIMAL:
371 case DataType::NUMERIC:
372 case DataType::LONGVARCHAR:
373 rtl_uString_acquire(_rRH.m_aValue.m_pString);
374 m_aValue.m_pString = _rRH.m_aValue.m_pString;
375 break;
376 case DataType::BIGINT:
377 if ( _rRH.m_bSigned )
379 m_aValue.m_pValue = new sal_Int64(*(sal_Int64*)_rRH.m_aValue.m_pValue);
380 TRACE_ALLOC( sal_Int64 )
382 else
384 rtl_uString_acquire(_rRH.m_aValue.m_pString);
385 m_aValue.m_pString = _rRH.m_aValue.m_pString;
387 break;
388 case DataType::FLOAT:
389 m_aValue.m_pValue = new float(*(float*)_rRH.m_aValue.m_pValue);
390 TRACE_ALLOC( float )
391 break;
392 case DataType::DOUBLE:
393 case DataType::REAL:
394 m_aValue.m_pValue = new double(*(double*)_rRH.m_aValue.m_pValue);
395 TRACE_ALLOC( double )
396 break;
397 case DataType::DATE:
398 m_aValue.m_pValue = new Date(*(Date*)_rRH.m_aValue.m_pValue);
399 TRACE_ALLOC( Date )
400 break;
401 case DataType::TIME:
402 m_aValue.m_pValue = new Time(*(Time*)_rRH.m_aValue.m_pValue);
403 TRACE_ALLOC( Time )
404 break;
405 case DataType::TIMESTAMP:
406 m_aValue.m_pValue = new DateTime(*(DateTime*)_rRH.m_aValue.m_pValue);
407 TRACE_ALLOC( DateTime )
408 break;
409 case DataType::BINARY:
410 case DataType::VARBINARY:
411 case DataType::LONGVARBINARY:
412 m_aValue.m_pValue = new Sequence<sal_Int8>(*(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue);
413 TRACE_ALLOC( Sequence_sal_Int8 )
414 break;
415 case DataType::BIT:
416 case DataType::BOOLEAN:
417 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
418 break;
419 case DataType::TINYINT:
420 if ( _rRH.m_bSigned )
421 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
422 else
423 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
424 break;
425 case DataType::SMALLINT:
426 if ( _rRH.m_bSigned )
427 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
428 else
429 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
430 break;
431 case DataType::INTEGER:
432 if ( _rRH.m_bSigned )
433 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
434 else
436 m_aValue.m_pValue = new sal_Int64(*(sal_Int64*)_rRH.m_aValue.m_pValue);
437 TRACE_ALLOC( sal_Int64 )
439 break;
440 default:
441 m_aValue.m_pValue = new Any(*(Any*)_rRH.m_aValue.m_pValue);
442 TRACE_ALLOC( Any )
445 else if(!_rRH.m_bNull)
447 switch(_rRH.m_eTypeKind)
449 case DataType::CHAR:
450 case DataType::VARCHAR:
451 case DataType::DECIMAL:
452 case DataType::NUMERIC:
453 case DataType::LONGVARCHAR:
454 (*this) = ::rtl::OUString(_rRH.m_aValue.m_pString);
455 break;
456 case DataType::BIGINT:
457 if ( _rRH.m_bSigned )
458 (*this) = *(sal_Int64*)_rRH.m_aValue.m_pValue;
459 else
460 (*this) = ::rtl::OUString(_rRH.m_aValue.m_pString);
461 break;
462 case DataType::FLOAT:
463 (*this) = *(float*)_rRH.m_aValue.m_pValue;
464 break;
465 case DataType::DOUBLE:
466 case DataType::REAL:
467 (*this) = *(double*)_rRH.m_aValue.m_pValue;
468 break;
469 case DataType::DATE:
470 (*this) = *(Date*)_rRH.m_aValue.m_pValue;
471 break;
472 case DataType::TIME:
473 (*this) = *(Time*)_rRH.m_aValue.m_pValue;
474 break;
475 case DataType::TIMESTAMP:
476 (*this) = *(DateTime*)_rRH.m_aValue.m_pValue;
477 break;
478 case DataType::BINARY:
479 case DataType::VARBINARY:
480 case DataType::LONGVARBINARY:
481 (*this) = *(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue;
482 break;
483 case DataType::BIT:
484 case DataType::BOOLEAN:
485 m_aValue.m_bBool = _rRH.m_aValue.m_bBool;
486 break;
487 case DataType::TINYINT:
488 if ( _rRH.m_bSigned )
489 m_aValue.m_nInt8 = _rRH.m_aValue.m_nInt8;
490 else
491 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
492 break;
493 case DataType::SMALLINT:
494 if ( _rRH.m_bSigned )
495 m_aValue.m_nInt16 = _rRH.m_aValue.m_nInt16;
496 else
497 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
498 break;
499 case DataType::INTEGER:
500 if ( _rRH.m_bSigned )
501 m_aValue.m_nInt32 = _rRH.m_aValue.m_nInt32;
502 else
503 *static_cast<sal_Int64*>(m_aValue.m_pValue) = *(sal_Int64*)_rRH.m_aValue.m_pValue;
504 break;
505 default:
506 (*(Any*)m_aValue.m_pValue) = (*(Any*)_rRH.m_aValue.m_pValue);
510 m_bNull = _rRH.m_bNull;
511 // OJ: BUGID: 96277
512 m_eTypeKind = _rRH.m_eTypeKind;
514 return *this;
516 // -------------------------------------------------------------------------
518 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
520 if(m_eTypeKind != DataType::DATE)
521 free();
523 if(m_bNull)
525 m_aValue.m_pValue = new Date(_rRH);
526 TRACE_ALLOC( Date )
527 m_eTypeKind = DataType::DATE;
528 m_bNull = sal_False;
530 else
531 *(Date*)m_aValue.m_pValue = _rRH;
533 return *this;
535 // -------------------------------------------------------------------------
536 ORowSetValue& ORowSetValue::operator=(const Time& _rRH)
538 if(m_eTypeKind != DataType::TIME)
539 free();
541 if(m_bNull)
543 m_aValue.m_pValue = new Time(_rRH);
544 TRACE_ALLOC( Time )
545 m_eTypeKind = DataType::TIME;
546 m_bNull = sal_False;
548 else
549 *(Time*)m_aValue.m_pValue = _rRH;
551 return *this;
553 // -------------------------------------------------------------------------
554 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
556 if(m_eTypeKind != DataType::TIMESTAMP)
557 free();
558 if(m_bNull)
560 m_aValue.m_pValue = new DateTime(_rRH);
561 TRACE_ALLOC( DateTime )
562 m_eTypeKind = DataType::TIMESTAMP;
563 m_bNull = sal_False;
565 else
566 *(DateTime*)m_aValue.m_pValue = _rRH;
568 return *this;
570 // -------------------------------------------------------------------------
572 ORowSetValue& ORowSetValue::operator=(const ::rtl::OUString& _rRH)
574 if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
576 free();
577 m_bNull = sal_False;
579 m_aValue.m_pString = _rRH.pData;
580 rtl_uString_acquire(m_aValue.m_pString);
581 m_eTypeKind = DataType::VARCHAR;
584 return *this;
586 // -------------------------------------------------------------------------
588 ORowSetValue& ORowSetValue::operator=(const double& _rRH)
590 if( !isStorageCompatible(m_eTypeKind,DataType::DOUBLE) )
591 free();
593 if(m_bNull)
595 m_aValue.m_pValue = new double(_rRH);
596 TRACE_ALLOC( double )
597 m_eTypeKind = DataType::DOUBLE;
598 m_bNull = sal_False;
600 else
601 *(double*)m_aValue.m_pValue = _rRH;
603 return *this;
605 // -----------------------------------------------------------------------------
606 ORowSetValue& ORowSetValue::operator=(const float& _rRH)
608 if(m_eTypeKind != DataType::FLOAT)
609 free();
611 if(m_bNull)
613 m_aValue.m_pValue = new float(_rRH);
614 TRACE_ALLOC( float )
615 m_eTypeKind = DataType::FLOAT;
616 m_bNull = sal_False;
618 else
619 *(float*)m_aValue.m_pValue = _rRH;
621 return *this;
623 // -------------------------------------------------------------------------
625 ORowSetValue& ORowSetValue::operator=(const sal_Int8& _rRH)
627 if(m_eTypeKind != DataType::TINYINT )
628 free();
630 m_aValue.m_nInt8 = _rRH;
631 m_eTypeKind = DataType::TINYINT;
632 m_bNull = sal_False;
633 return *this;
635 // -------------------------------------------------------------------------
637 ORowSetValue& ORowSetValue::operator=(const sal_Int16& _rRH)
639 if(m_eTypeKind != DataType::SMALLINT )
640 free();
642 m_aValue.m_nInt16 = _rRH;
643 m_eTypeKind = DataType::SMALLINT;
644 m_bNull = sal_False;
646 return *this;
648 // -------------------------------------------------------------------------
650 ORowSetValue& ORowSetValue::operator=(const sal_Int32& _rRH)
652 if(m_eTypeKind != DataType::INTEGER )
653 free();
655 if ( m_bSigned )
656 m_aValue.m_nInt32 = _rRH;
657 else
659 if ( m_bNull )
661 m_aValue.m_pValue = new sal_Int64(_rRH);
662 TRACE_ALLOC( sal_Int64 )
664 else
665 *static_cast<sal_Int64*>(m_aValue.m_pValue) = static_cast<sal_Int64>(_rRH);
668 m_eTypeKind = DataType::INTEGER;
669 m_bNull = sal_False;
671 return *this;
673 // -------------------------------------------------------------------------
675 ORowSetValue& ORowSetValue::operator=(const sal_Bool _rRH)
677 if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
678 free();
680 m_aValue.m_bBool = _rRH;
681 m_eTypeKind = DataType::BIT;
682 m_bNull = sal_False;
684 return *this;
686 // -------------------------------------------------------------------------
687 ORowSetValue& ORowSetValue::operator=(const sal_Int64& _rRH)
689 if ( DataType::BIGINT != m_eTypeKind || !m_bSigned )
690 free();
692 if ( m_bSigned )
694 if(m_bNull)
696 m_aValue.m_pValue = new sal_Int64(_rRH);
697 TRACE_ALLOC( sal_Int64 )
699 else
700 *static_cast<sal_Int64*>(m_aValue.m_pValue) = _rRH;
702 else
704 ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rRH);
705 m_aValue.m_pString = aVal.pData;
706 rtl_uString_acquire(m_aValue.m_pString);
709 m_eTypeKind = DataType::BIGINT;
710 m_bNull = sal_False;
712 return *this;
714 // -------------------------------------------------------------------------
715 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
717 if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
718 free();
720 if (m_bNull)
722 m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
723 TRACE_ALLOC( Sequence_sal_Int8 )
725 else
726 *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
728 m_eTypeKind = DataType::LONGVARBINARY;
729 m_bNull = sal_False;
731 return *this;
733 // -------------------------------------------------------------------------
734 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
736 if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
737 free();
739 if ( m_bNull )
741 m_aValue.m_pValue = new Any(_rAny);
742 TRACE_ALLOC( Any )
744 else
745 *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
747 m_eTypeKind = DataType::OBJECT;
748 m_bNull = sal_False;
750 return *this;
752 // -------------------------------------------------------------------------
754 sal_Bool operator==(const Date& _rLH,const Date& _rRH)
756 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year;
758 // -------------------------------------------------------------------------
760 sal_Bool operator==(const Time& _rLH,const Time& _rRH)
762 return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds;
764 // -------------------------------------------------------------------------
766 sal_Bool operator==(const DateTime& _rLH,const DateTime& _rRH)
768 return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year &&
769 _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds;
771 // -------------------------------------------------------------------------
773 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
775 if(m_eTypeKind != _rRH.m_eTypeKind)
776 return false;
777 if ( m_bSigned != _rRH.m_bSigned )
778 return false;
779 if(m_bNull != _rRH.isNull())
780 return false;
781 if(m_bNull && _rRH.isNull())
782 return true;
784 bool bRet = false;
785 OSL_ENSURE(!m_bNull,"SHould not be null!");
786 switch(m_eTypeKind)
788 case DataType::VARCHAR:
789 case DataType::CHAR:
790 case DataType::DECIMAL:
791 case DataType::NUMERIC:
792 case DataType::LONGVARCHAR:
794 ::rtl::OUString aVal1(m_aValue.m_pString);
795 ::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
796 bRet = aVal1 == aVal2;
797 break;
800 case DataType::FLOAT:
801 bRet = *(float*)m_aValue.m_pValue == *(float*)_rRH.m_aValue.m_pValue;
802 break;
803 case DataType::DOUBLE:
804 case DataType::REAL:
805 bRet = *(double*)m_aValue.m_pValue == *(double*)_rRH.m_aValue.m_pValue;
806 break;
807 case DataType::TINYINT:
808 bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16);
809 break;
810 case DataType::SMALLINT:
811 bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32);
812 break;
813 case DataType::INTEGER:
814 bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (*(sal_Int64*)m_aValue.m_pValue == *(sal_Int64*)_rRH.m_aValue.m_pValue);
815 break;
816 case DataType::BIGINT:
817 if ( m_bSigned )
818 bRet = *(sal_Int64*)m_aValue.m_pValue == *(sal_Int64*)_rRH.m_aValue.m_pValue;
819 else
821 ::rtl::OUString aVal1(m_aValue.m_pString);
822 ::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
823 bRet = aVal1 == aVal2;
825 break;
826 case DataType::BIT:
827 case DataType::BOOLEAN:
828 bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
829 break;
830 case DataType::DATE:
831 bRet = *(Date*)m_aValue.m_pValue == *(Date*)_rRH.m_aValue.m_pValue;
832 break;
833 case DataType::TIME:
834 bRet = *(Time*)m_aValue.m_pValue == *(Time*)_rRH.m_aValue.m_pValue;
835 break;
836 case DataType::TIMESTAMP:
837 bRet = *(DateTime*)m_aValue.m_pValue == *(DateTime*)_rRH.m_aValue.m_pValue;
838 break;
839 case DataType::BINARY:
840 case DataType::VARBINARY:
841 case DataType::LONGVARBINARY:
842 bRet = false;
843 break;
844 case DataType::BLOB:
845 case DataType::CLOB:
846 case DataType::OBJECT:
847 bRet = false;
848 break;
849 default:
850 OSL_ENSURE(0,"ORowSetValue::operator==(): UNSPUPPORTED TYPE!");
852 return bRet;
854 // -------------------------------------------------------------------------
855 Any ORowSetValue::makeAny() const
857 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::makeAny" );
858 Any rValue;
859 if(isBound() && !isNull())
861 switch(getTypeKind())
863 case DataType::CHAR:
864 case DataType::VARCHAR:
865 case DataType::DECIMAL:
866 case DataType::NUMERIC:
867 case DataType::LONGVARCHAR:
868 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
869 rValue <<= (::rtl::OUString)m_aValue.m_pString;
870 break;
871 case DataType::BIGINT:
872 if ( m_bSigned )
874 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
875 rValue <<= *(sal_Int64*)m_aValue.m_pValue;
877 else
879 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
880 rValue <<= (::rtl::OUString)m_aValue.m_pString;
882 break;
883 case DataType::FLOAT:
884 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
885 rValue <<= *(float*)m_aValue.m_pValue;
886 break;
887 case DataType::DOUBLE:
888 case DataType::REAL:
889 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
890 rValue <<= *(double*)m_aValue.m_pValue;
891 break;
892 case DataType::DATE:
893 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
894 rValue <<= *(Date*)m_aValue.m_pValue;
895 break;
896 case DataType::TIME:
897 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
898 rValue <<= *(Time*)m_aValue.m_pValue;
899 break;
900 case DataType::TIMESTAMP:
901 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
902 rValue <<= *(DateTime*)m_aValue.m_pValue;
903 break;
904 case DataType::BINARY:
905 case DataType::VARBINARY:
906 case DataType::LONGVARBINARY:
907 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
908 rValue <<= *(Sequence<sal_Int8>*)m_aValue.m_pValue;
909 break;
910 case DataType::BLOB:
911 case DataType::CLOB:
912 case DataType::OBJECT:
913 rValue = getAny();
914 break;
915 case DataType::BIT:
916 case DataType::BOOLEAN:
917 rValue.setValue( &m_aValue.m_bBool, ::getCppuBooleanType() );
918 break;
919 case DataType::TINYINT:
920 if ( m_bSigned )
921 rValue <<= m_aValue.m_nInt8;
922 else
923 rValue <<= m_aValue.m_nInt16;
924 break;
925 case DataType::SMALLINT:
926 if ( m_bSigned )
927 rValue <<= m_aValue.m_nInt16;
928 else
929 rValue <<= m_aValue.m_nInt32;
930 break;
931 case DataType::INTEGER:
932 if ( m_bSigned )
933 rValue <<= m_aValue.m_nInt32;
934 else
936 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
937 rValue <<= *(sal_Int64*)m_aValue.m_pValue;
939 break;
940 default:
941 OSL_ENSURE(0,"ORowSetValue::makeAny(): UNSPUPPORTED TYPE!");
944 return rValue;
946 // -------------------------------------------------------------------------
947 ::rtl::OUString ORowSetValue::getString( ) const
949 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getString" );
950 ::rtl::OUString aRet;
951 if(!m_bNull)
953 switch(getTypeKind())
955 case DataType::CHAR:
956 case DataType::VARCHAR:
957 case DataType::DECIMAL:
958 case DataType::NUMERIC:
959 case DataType::LONGVARCHAR:
960 aRet = m_aValue.m_pString;
961 break;
962 case DataType::BIGINT:
963 if ( m_bSigned )
964 aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
965 else
966 aRet = m_aValue.m_pString;
967 break;
968 case DataType::FLOAT:
969 aRet = ::rtl::OUString::valueOf((float)*this);
970 break;
971 case DataType::DOUBLE:
972 case DataType::REAL:
973 aRet = ::rtl::OUString::valueOf((double)*this);
974 break;
975 case DataType::DATE:
976 aRet = connectivity::toDateString(*this);
977 break;
978 case DataType::TIME:
979 aRet = connectivity::toTimeString(*this);
980 break;
981 case DataType::TIMESTAMP:
982 aRet = connectivity::toDateTimeString(*this);
983 break;
984 case DataType::BINARY:
985 case DataType::VARBINARY:
986 case DataType::LONGVARBINARY:
988 ::rtl::OUStringBuffer sVal = ::rtl::OUString::createFromAscii("0x");
989 Sequence<sal_Int8> aSeq(getSequence());
990 const sal_Int8* pBegin = aSeq.getConstArray();
991 const sal_Int8* pEnd = pBegin + aSeq.getLength();
992 for(;pBegin != pEnd;++pBegin)
993 sVal.append((sal_Int32)*pBegin,16);
994 aRet = sVal.makeStringAndClear();
996 break;
997 case DataType::BIT:
998 case DataType::BOOLEAN:
999 aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Bool)*this);
1000 break;
1001 case DataType::TINYINT:
1002 if ( m_bSigned )
1003 aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int8)*this);
1004 else
1005 aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1006 break;
1007 case DataType::SMALLINT:
1008 if ( m_bSigned )
1009 aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1010 else
1011 aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1012 break;
1013 case DataType::INTEGER:
1014 if ( m_bSigned )
1015 aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1016 else
1017 aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
1018 break;
1021 return aRet;
1023 // -------------------------------------------------------------------------
1024 sal_Bool ORowSetValue::getBool() const
1026 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getBool" );
1027 sal_Bool bRet = sal_False;
1028 if(!m_bNull)
1030 switch(getTypeKind())
1032 case DataType::CHAR:
1033 case DataType::VARCHAR:
1034 case DataType::LONGVARCHAR:
1036 const ::rtl::OUString sValue(m_aValue.m_pString);
1037 const static ::rtl::OUString s_sTrue(RTL_CONSTASCII_USTRINGPARAM("true"));
1038 const static ::rtl::OUString s_sFalse(RTL_CONSTASCII_USTRINGPARAM("false"));
1039 if ( sValue.equalsIgnoreAsciiCase(s_sTrue) )
1041 bRet = sal_True;
1042 break;
1044 else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) )
1046 bRet = sal_False;
1047 break;
1050 // run through
1051 case DataType::DECIMAL:
1052 case DataType::NUMERIC:
1054 bRet = ::rtl::OUString(m_aValue.m_pString).toInt32() != 0;
1055 break;
1056 case DataType::BIGINT:
1057 if ( m_bSigned )
1058 bRet = *(sal_Int64*)m_aValue.m_pValue != 0;
1059 else
1060 bRet = ::rtl::OUString(m_aValue.m_pString).toInt64() != 0;
1061 break;
1062 case DataType::FLOAT:
1063 bRet = *(float*)m_aValue.m_pValue != 0.0;
1064 break;
1065 case DataType::DOUBLE:
1066 case DataType::REAL:
1067 bRet = *(double*)m_aValue.m_pValue != 0.0;
1068 break;
1069 case DataType::DATE:
1070 case DataType::TIME:
1071 case DataType::TIMESTAMP:
1072 case DataType::BINARY:
1073 case DataType::VARBINARY:
1074 case DataType::LONGVARBINARY:
1075 OSL_ASSERT(!"getBool() for this type is not allowed!");
1076 break;
1077 case DataType::BIT:
1078 case DataType::BOOLEAN:
1079 bRet = m_aValue.m_bBool;
1080 break;
1081 case DataType::TINYINT:
1082 bRet = m_bSigned ? (m_aValue.m_nInt8 != 0) : (m_aValue.m_nInt16 != 0);
1083 break;
1084 case DataType::SMALLINT:
1085 bRet = m_bSigned ? (m_aValue.m_nInt16 != 0) : (m_aValue.m_nInt32 != 0);
1086 break;
1087 case DataType::INTEGER:
1088 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0));
1089 break;
1092 return bRet;
1094 // -------------------------------------------------------------------------
1095 sal_Int8 ORowSetValue::getInt8() const
1097 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt8" );
1100 sal_Int8 nRet = 0;
1101 if(!m_bNull)
1103 switch(getTypeKind())
1105 case DataType::CHAR:
1106 case DataType::VARCHAR:
1107 case DataType::DECIMAL:
1108 case DataType::NUMERIC:
1109 case DataType::LONGVARCHAR:
1110 nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1111 break;
1112 case DataType::BIGINT:
1113 if ( m_bSigned )
1114 nRet = sal_Int8(*(sal_Int64*)m_aValue.m_pValue);
1115 else
1116 nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1117 break;
1118 case DataType::FLOAT:
1119 nRet = sal_Int8(*(float*)m_aValue.m_pValue);
1120 break;
1121 case DataType::DOUBLE:
1122 case DataType::REAL:
1123 nRet = sal_Int8(*(double*)m_aValue.m_pValue);
1124 break;
1125 case DataType::DATE:
1126 case DataType::TIME:
1127 case DataType::TIMESTAMP:
1128 case DataType::BINARY:
1129 case DataType::VARBINARY:
1130 case DataType::LONGVARBINARY:
1131 OSL_ASSERT(!"getInt8() for this type is not allowed!");
1132 break;
1133 case DataType::BIT:
1134 case DataType::BOOLEAN:
1135 nRet = m_aValue.m_bBool;
1136 break;
1137 case DataType::TINYINT:
1138 if ( m_bSigned )
1139 nRet = m_aValue.m_nInt8;
1140 else
1141 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1142 break;
1143 case DataType::SMALLINT:
1144 if ( m_bSigned )
1145 nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1146 else
1147 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1148 break;
1149 case DataType::INTEGER:
1150 if ( m_bSigned )
1151 nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1152 else
1153 nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1154 break;
1157 return nRet;
1159 // -------------------------------------------------------------------------
1160 sal_Int16 ORowSetValue::getInt16() const
1162 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt16" );
1165 sal_Int16 nRet = 0;
1166 if(!m_bNull)
1168 switch(getTypeKind())
1170 case DataType::CHAR:
1171 case DataType::VARCHAR:
1172 case DataType::DECIMAL:
1173 case DataType::NUMERIC:
1174 case DataType::LONGVARCHAR:
1175 nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1176 break;
1177 case DataType::BIGINT:
1178 if ( m_bSigned )
1179 nRet = sal_Int16(*(sal_Int64*)m_aValue.m_pValue);
1180 else
1181 nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1182 break;
1183 case DataType::FLOAT:
1184 nRet = sal_Int16(*(float*)m_aValue.m_pValue);
1185 break;
1186 case DataType::DOUBLE:
1187 case DataType::REAL:
1188 nRet = sal_Int16(*(double*)m_aValue.m_pValue);
1189 break;
1190 case DataType::DATE:
1191 case DataType::TIME:
1192 case DataType::TIMESTAMP:
1193 case DataType::BINARY:
1194 case DataType::VARBINARY:
1195 case DataType::LONGVARBINARY:
1196 OSL_ASSERT(!"getInt16() for this type is not allowed!");
1197 break;
1198 case DataType::BIT:
1199 case DataType::BOOLEAN:
1200 nRet = m_aValue.m_bBool;
1201 break;
1202 case DataType::TINYINT:
1203 if ( m_bSigned )
1204 nRet = m_aValue.m_nInt8;
1205 else
1206 nRet = m_aValue.m_nInt16;
1207 break;
1208 case DataType::SMALLINT:
1209 if ( m_bSigned )
1210 nRet = m_aValue.m_nInt16;
1211 else
1212 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1213 break;
1214 case DataType::INTEGER:
1215 if ( m_bSigned )
1216 nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1217 else
1218 nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1219 break;
1222 return nRet;
1224 // -------------------------------------------------------------------------
1225 sal_Int32 ORowSetValue::getInt32() const
1227 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt32" );
1228 sal_Int32 nRet = 0;
1229 if(!m_bNull)
1231 switch(getTypeKind())
1233 case DataType::CHAR:
1234 case DataType::VARCHAR:
1235 case DataType::DECIMAL:
1236 case DataType::NUMERIC:
1237 case DataType::LONGVARCHAR:
1238 nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1239 break;
1240 case DataType::BIGINT:
1241 if ( m_bSigned )
1242 nRet = sal_Int32(*(sal_Int64*)m_aValue.m_pValue);
1243 else
1244 nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1245 break;
1246 case DataType::FLOAT:
1247 nRet = sal_Int32(*(float*)m_aValue.m_pValue);
1248 break;
1249 case DataType::DOUBLE:
1250 case DataType::REAL:
1251 nRet = sal_Int32(*(double*)m_aValue.m_pValue);
1252 break;
1253 case DataType::DATE:
1254 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1255 break;
1256 case DataType::TIME:
1257 case DataType::TIMESTAMP:
1258 case DataType::BINARY:
1259 case DataType::VARBINARY:
1260 case DataType::LONGVARBINARY:
1261 OSL_ASSERT(!"getInt32() for this type is not allowed!");
1262 break;
1263 case DataType::BIT:
1264 case DataType::BOOLEAN:
1265 nRet = m_aValue.m_bBool;
1266 break;
1267 case DataType::TINYINT:
1268 if ( m_bSigned )
1269 nRet = m_aValue.m_nInt8;
1270 else
1271 nRet = m_aValue.m_nInt16;
1272 break;
1273 case DataType::SMALLINT:
1274 if ( m_bSigned )
1275 nRet = m_aValue.m_nInt16;
1276 else
1277 nRet = m_aValue.m_nInt32;
1278 break;
1279 case DataType::INTEGER:
1280 if ( m_bSigned )
1281 nRet = m_aValue.m_nInt32;
1282 else
1283 nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1284 break;
1287 return nRet;
1289 // -------------------------------------------------------------------------
1290 sal_Int64 ORowSetValue::getLong() const
1292 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getLong" );
1293 sal_Int64 nRet = 0;
1294 if(!m_bNull)
1296 switch(getTypeKind())
1298 case DataType::CHAR:
1299 case DataType::VARCHAR:
1300 case DataType::DECIMAL:
1301 case DataType::NUMERIC:
1302 case DataType::LONGVARCHAR:
1303 nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1304 break;
1305 case DataType::BIGINT:
1306 if ( m_bSigned )
1307 nRet = *(sal_Int64*)m_aValue.m_pValue;
1308 else
1309 nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1310 break;
1311 case DataType::FLOAT:
1312 nRet = sal_Int64(*(float*)m_aValue.m_pValue);
1313 break;
1314 case DataType::DOUBLE:
1315 case DataType::REAL:
1316 nRet = sal_Int64(*(double*)m_aValue.m_pValue);
1317 break;
1318 case DataType::DATE:
1319 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1320 break;
1321 case DataType::TIME:
1322 case DataType::TIMESTAMP:
1323 case DataType::BINARY:
1324 case DataType::VARBINARY:
1325 case DataType::LONGVARBINARY:
1326 OSL_ASSERT(!"getInt32() for this type is not allowed!");
1327 break;
1328 case DataType::BIT:
1329 case DataType::BOOLEAN:
1330 nRet = m_aValue.m_bBool;
1331 break;
1332 case DataType::TINYINT:
1333 if ( m_bSigned )
1334 nRet = m_aValue.m_nInt8;
1335 else
1336 nRet = m_aValue.m_nInt16;
1337 break;
1338 case DataType::SMALLINT:
1339 if ( m_bSigned )
1340 nRet = m_aValue.m_nInt16;
1341 else
1342 nRet = m_aValue.m_nInt32;
1343 break;
1344 case DataType::INTEGER:
1345 if ( m_bSigned )
1346 nRet = m_aValue.m_nInt32;
1347 else
1348 nRet = *(sal_Int64*)m_aValue.m_pValue;
1349 break;
1352 return nRet;
1354 // -------------------------------------------------------------------------
1355 float ORowSetValue::getFloat() const
1357 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getFloat" );
1358 float nRet = 0;
1359 if(!m_bNull)
1361 switch(getTypeKind())
1363 case DataType::CHAR:
1364 case DataType::VARCHAR:
1365 case DataType::DECIMAL:
1366 case DataType::NUMERIC:
1367 case DataType::LONGVARCHAR:
1368 nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1369 break;
1370 case DataType::BIGINT:
1371 if ( m_bSigned )
1372 nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1373 else
1374 nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1375 break;
1376 case DataType::FLOAT:
1377 nRet = *(float*)m_aValue.m_pValue;
1378 break;
1379 case DataType::DOUBLE:
1380 case DataType::REAL:
1381 nRet = (float)*(double*)m_aValue.m_pValue;
1382 break;
1383 case DataType::DATE:
1384 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1385 break;
1386 case DataType::TIME:
1387 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1388 break;
1389 case DataType::TIMESTAMP:
1390 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1391 break;
1392 case DataType::BINARY:
1393 case DataType::VARBINARY:
1394 case DataType::LONGVARBINARY:
1395 OSL_ASSERT(!"getDouble() for this type is not allowed!");
1396 break;
1397 case DataType::BIT:
1398 case DataType::BOOLEAN:
1399 nRet = m_aValue.m_bBool;
1400 break;
1401 case DataType::TINYINT:
1402 if ( m_bSigned )
1403 nRet = m_aValue.m_nInt8;
1404 else
1405 nRet = m_aValue.m_nInt16;
1406 break;
1407 case DataType::SMALLINT:
1408 if ( m_bSigned )
1409 nRet = m_aValue.m_nInt16;
1410 else
1411 nRet = (float)m_aValue.m_nInt32;
1412 break;
1413 case DataType::INTEGER:
1414 if ( m_bSigned )
1415 nRet = (float)m_aValue.m_nInt32;
1416 else
1417 nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1418 break;
1421 return nRet;
1423 // -------------------------------------------------------------------------
1424 double ORowSetValue::getDouble() const
1426 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDouble" );
1429 double nRet = 0;
1430 if(!m_bNull)
1432 switch(getTypeKind())
1434 case DataType::CHAR:
1435 case DataType::VARCHAR:
1436 case DataType::DECIMAL:
1437 case DataType::NUMERIC:
1438 case DataType::LONGVARCHAR:
1439 nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1440 break;
1441 case DataType::BIGINT:
1442 if ( m_bSigned )
1443 nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1444 else
1445 nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1446 break;
1447 case DataType::FLOAT:
1448 nRet = *(float*)m_aValue.m_pValue;
1449 break;
1450 case DataType::DOUBLE:
1451 case DataType::REAL:
1452 nRet = *(double*)m_aValue.m_pValue;
1453 break;
1454 case DataType::DATE:
1455 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1456 break;
1457 case DataType::TIME:
1458 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1459 break;
1460 case DataType::TIMESTAMP:
1461 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1462 break;
1463 case DataType::BINARY:
1464 case DataType::VARBINARY:
1465 case DataType::LONGVARBINARY:
1466 OSL_ASSERT(!"getDouble() for this type is not allowed!");
1467 break;
1468 case DataType::BIT:
1469 case DataType::BOOLEAN:
1470 nRet = m_aValue.m_bBool;
1471 break;
1472 case DataType::TINYINT:
1473 if ( m_bSigned )
1474 nRet = m_aValue.m_nInt8;
1475 else
1476 nRet = m_aValue.m_nInt16;
1477 break;
1478 case DataType::SMALLINT:
1479 if ( m_bSigned )
1480 nRet = m_aValue.m_nInt16;
1481 else
1482 nRet = m_aValue.m_nInt32;
1483 break;
1484 case DataType::INTEGER:
1485 if ( m_bSigned )
1486 nRet = m_aValue.m_nInt32;
1487 else
1488 nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1489 break;
1492 return nRet;
1494 // -------------------------------------------------------------------------
1495 void ORowSetValue::setFromDouble(const double& _rVal,sal_Int32 _nDatatype)
1497 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setFromDouble" );
1498 free();
1500 m_bNull = sal_False;
1501 switch(_nDatatype)
1503 case DataType::CHAR:
1504 case DataType::VARCHAR:
1505 case DataType::DECIMAL:
1506 case DataType::NUMERIC:
1507 case DataType::LONGVARCHAR:
1509 ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1510 m_aValue.m_pString = aVal.pData;
1511 rtl_uString_acquire(m_aValue.m_pString);
1513 break;
1514 case DataType::BIGINT:
1515 if ( m_bSigned )
1517 m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1518 TRACE_ALLOC( sal_Int64 )
1520 else
1522 ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1523 m_aValue.m_pString = aVal.pData;
1524 rtl_uString_acquire(m_aValue.m_pString);
1526 break;
1527 case DataType::FLOAT:
1528 m_aValue.m_pValue = new float((float)_rVal);
1529 TRACE_ALLOC( float )
1530 break;
1531 case DataType::DOUBLE:
1532 case DataType::REAL:
1533 m_aValue.m_pValue = new double(_rVal);
1534 TRACE_ALLOC( double )
1535 break;
1536 case DataType::DATE:
1537 m_aValue.m_pValue = new Date(dbtools::DBTypeConversion::toDate(_rVal));
1538 TRACE_ALLOC( Date )
1539 break;
1540 case DataType::TIME:
1541 m_aValue.m_pValue = new Time(dbtools::DBTypeConversion::toTime(_rVal));
1542 TRACE_ALLOC( Time )
1543 break;
1544 case DataType::TIMESTAMP:
1545 m_aValue.m_pValue = new DateTime(dbtools::DBTypeConversion::toDateTime(_rVal));
1546 TRACE_ALLOC( DateTime )
1547 break;
1548 case DataType::BINARY:
1549 case DataType::VARBINARY:
1550 case DataType::LONGVARBINARY:
1551 OSL_ASSERT(!"setFromDouble() for this type is not allowed!");
1552 break;
1553 case DataType::BIT:
1554 case DataType::BOOLEAN:
1555 m_aValue.m_bBool = _rVal != 0.0;
1556 break;
1557 case DataType::TINYINT:
1558 if ( m_bSigned )
1559 m_aValue.m_nInt8 = sal_Int8(_rVal);
1560 else
1561 m_aValue.m_nInt16 = sal_Int16(_rVal);
1562 break;
1563 case DataType::SMALLINT:
1564 if ( m_bSigned )
1565 m_aValue.m_nInt16 = sal_Int16(_rVal);
1566 else
1567 m_aValue.m_nInt32 = sal_Int32(_rVal);
1568 break;
1569 case DataType::INTEGER:
1570 if ( m_bSigned )
1571 m_aValue.m_nInt32 = sal_Int32(_rVal);
1572 else
1574 m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1575 TRACE_ALLOC( sal_Int64 )
1577 break;
1579 m_eTypeKind = _nDatatype;
1581 // -----------------------------------------------------------------------------
1582 Sequence<sal_Int8> ORowSetValue::getSequence() const
1584 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getSequence" );
1585 Sequence<sal_Int8> aSeq;
1586 if (!m_bNull)
1588 switch(m_eTypeKind)
1590 case DataType::OBJECT:
1591 case DataType::CLOB:
1592 case DataType::BLOB:
1594 Reference<XInputStream> xStream;
1595 Any aValue = getAny();
1596 if(aValue.hasValue())
1598 aValue >>= xStream;
1599 if(xStream.is())
1600 xStream->readBytes(aSeq,xStream->available());
1603 break;
1604 case DataType::VARCHAR:
1605 case DataType::LONGVARCHAR:
1607 ::rtl::OUString sVal(m_aValue.m_pString);
1608 aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sVal.getStr()),sizeof(sal_Unicode)*sVal.getLength());
1610 break;
1611 case DataType::BINARY:
1612 case DataType::VARBINARY:
1613 case DataType::LONGVARBINARY:
1614 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1615 break;
1616 default:
1620 return aSeq;
1623 // -----------------------------------------------------------------------------
1624 ::com::sun::star::util::Date ORowSetValue::getDate() const
1626 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDate" );
1627 ::com::sun::star::util::Date aValue;
1628 if(!m_bNull)
1630 switch(m_eTypeKind)
1632 case DataType::CHAR:
1633 case DataType::VARCHAR:
1634 case DataType::LONGVARCHAR:
1635 aValue = DBTypeConversion::toDate(getString());
1636 break;
1637 case DataType::DECIMAL:
1638 case DataType::NUMERIC:
1639 aValue = DBTypeConversion::toDate((double)*this);
1640 break;
1641 case DataType::FLOAT:
1642 case DataType::DOUBLE:
1643 case DataType::REAL:
1644 aValue = DBTypeConversion::toDate((double)*this);
1645 break;
1647 case DataType::DATE:
1648 aValue = *static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1649 break;
1650 case DataType::TIMESTAMP:
1652 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1653 aValue.Day = pDateTime->Day;
1654 aValue.Month = pDateTime->Month;
1655 aValue.Year = pDateTime->Year;
1657 break;
1660 return aValue;
1662 // -----------------------------------------------------------------------------
1663 ::com::sun::star::util::Time ORowSetValue::getTime() const
1665 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getTime" );
1666 ::com::sun::star::util::Time aValue;
1667 if(!m_bNull)
1669 switch(m_eTypeKind)
1671 case DataType::CHAR:
1672 case DataType::VARCHAR:
1673 case DataType::LONGVARCHAR:
1674 aValue = DBTypeConversion::toTime(getString());
1675 break;
1676 case DataType::DECIMAL:
1677 case DataType::NUMERIC:
1678 aValue = DBTypeConversion::toTime((double)*this);
1679 break;
1680 case DataType::FLOAT:
1681 case DataType::DOUBLE:
1682 case DataType::REAL:
1683 aValue = DBTypeConversion::toTime((double)*this);
1684 break;
1685 case DataType::TIMESTAMP:
1687 ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1688 aValue.HundredthSeconds = pDateTime->HundredthSeconds;
1689 aValue.Seconds = pDateTime->Seconds;
1690 aValue.Minutes = pDateTime->Minutes;
1691 aValue.Hours = pDateTime->Hours;
1693 break;
1694 case DataType::TIME:
1695 aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1698 return aValue;
1700 // -----------------------------------------------------------------------------
1701 ::com::sun::star::util::DateTime ORowSetValue::getDateTime() const
1703 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDateTime" );
1704 ::com::sun::star::util::DateTime aValue;
1705 if(!m_bNull)
1707 switch(m_eTypeKind)
1709 case DataType::CHAR:
1710 case DataType::VARCHAR:
1711 case DataType::LONGVARCHAR:
1712 aValue = DBTypeConversion::toDateTime(getString());
1713 break;
1714 case DataType::DECIMAL:
1715 case DataType::NUMERIC:
1716 aValue = DBTypeConversion::toDateTime((double)*this);
1717 break;
1718 case DataType::FLOAT:
1719 case DataType::DOUBLE:
1720 case DataType::REAL:
1721 aValue = DBTypeConversion::toDateTime((double)*this);
1722 break;
1723 case DataType::DATE:
1725 ::com::sun::star::util::Date* pDate = static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1726 aValue.Day = pDate->Day;
1727 aValue.Month = pDate->Month;
1728 aValue.Year = pDate->Year;
1730 break;
1731 case DataType::TIME:
1733 ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1734 aValue.HundredthSeconds = pTime->HundredthSeconds;
1735 aValue.Seconds = pTime->Seconds;
1736 aValue.Minutes = pTime->Minutes;
1737 aValue.Hours = pTime->Hours;
1739 break;
1740 case DataType::TIMESTAMP:
1741 aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1742 break;
1745 return aValue;
1747 // -----------------------------------------------------------------------------
1748 void ORowSetValue::setSigned(sal_Bool _bMod)
1750 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setSigned" );
1751 if ( m_bSigned != _bMod )
1753 m_bSigned = _bMod;
1754 if ( !m_bNull )
1756 sal_Int32 nType = m_eTypeKind;
1757 switch(m_eTypeKind)
1759 case DataType::BIGINT:
1760 if ( m_bSigned ) // now we are signed, so we were unsigned and need to call getString()
1762 m_bSigned = !m_bSigned;
1763 const ::rtl::OUString sValue = getString();
1764 free();
1765 m_bSigned = !m_bSigned;
1766 (*this) = sValue;
1768 else
1770 m_bSigned = !m_bSigned;
1771 const sal_Int64 nValue = getLong();
1772 free();
1773 m_bSigned = !m_bSigned;
1774 (*this) = nValue;
1776 break;
1777 case DataType::TINYINT:
1778 if ( m_bSigned )
1779 (*this) = getInt8();
1780 else
1782 m_bSigned = !m_bSigned;
1783 (*this) = getInt16();
1784 m_bSigned = !m_bSigned;
1786 break;
1787 case DataType::SMALLINT:
1788 if ( m_bSigned )
1789 (*this) = getInt16();
1790 else
1792 m_bSigned = !m_bSigned;
1793 (*this) = getInt32();
1794 m_bSigned = !m_bSigned;
1796 break;
1797 case DataType::INTEGER:
1798 if ( m_bSigned )
1799 (*this) = getInt32();
1800 else
1802 m_bSigned = !m_bSigned;
1803 (*this) = getLong();
1804 m_bSigned = !m_bSigned;
1806 break;
1808 m_eTypeKind = nType;
1812 // -----------------------------------------------------------------------------
1813 void ORowSetValue::fill(sal_Int32 _nPos,
1814 sal_Int32 _nType,
1815 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
1817 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (1)" );
1818 fill(_nPos,_nType,sal_True,_xRow);
1821 // -----------------------------------------------------------------------------
1822 void ORowSetValue::fill(sal_Int32 _nPos,
1823 sal_Int32 _nType,
1824 sal_Bool _bNullable,
1825 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
1827 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (2)" );
1828 sal_Bool bReadData = sal_True;
1829 switch(_nType)
1831 case DataType::CHAR:
1832 case DataType::VARCHAR:
1833 case DataType::DECIMAL:
1834 case DataType::NUMERIC:
1835 case DataType::LONGVARCHAR:
1836 (*this) = _xRow->getString(_nPos);
1837 break;
1838 case DataType::BIGINT:
1839 if ( isSigned() )
1840 (*this) = _xRow->getLong(_nPos);
1841 else
1842 (*this) = _xRow->getString(_nPos);
1843 break;
1844 case DataType::FLOAT:
1845 (*this) = _xRow->getFloat(_nPos);
1846 break;
1847 case DataType::DOUBLE:
1848 case DataType::REAL:
1849 (*this) = _xRow->getDouble(_nPos);
1850 break;
1851 case DataType::DATE:
1852 (*this) = _xRow->getDate(_nPos);
1853 break;
1854 case DataType::TIME:
1855 (*this) = _xRow->getTime(_nPos);
1856 break;
1857 case DataType::TIMESTAMP:
1858 (*this) = _xRow->getTimestamp(_nPos);
1859 break;
1860 case DataType::BINARY:
1861 case DataType::VARBINARY:
1862 case DataType::LONGVARBINARY:
1863 (*this) = _xRow->getBytes(_nPos);
1864 break;
1865 case DataType::BIT:
1866 case DataType::BOOLEAN:
1867 (*this) = _xRow->getBoolean(_nPos);
1868 break;
1869 case DataType::TINYINT:
1870 if ( isSigned() )
1871 (*this) = _xRow->getByte(_nPos);
1872 else
1873 (*this) = _xRow->getShort(_nPos);
1874 break;
1875 case DataType::SMALLINT:
1876 if ( isSigned() )
1877 (*this) = _xRow->getShort(_nPos);
1878 else
1879 (*this) = _xRow->getInt(_nPos);
1880 break;
1881 case DataType::INTEGER:
1882 if ( isSigned() )
1883 (*this) = _xRow->getInt(_nPos);
1884 else
1885 (*this) = _xRow->getLong(_nPos);
1886 break;
1887 case DataType::CLOB:
1888 (*this) = ::com::sun::star::uno::makeAny(_xRow->getCharacterStream(_nPos));
1889 setTypeKind(DataType::CLOB);
1890 break;
1891 case DataType::BLOB:
1892 (*this) = ::com::sun::star::uno::makeAny(_xRow->getBinaryStream(_nPos));
1893 setTypeKind(DataType::BLOB);
1894 break;
1895 default:
1896 OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" );
1897 bReadData = false;
1898 break;
1900 if ( bReadData && _bNullable && _xRow->wasNull() )
1901 setNull();
1902 setTypeKind(_nType);
1904 // -----------------------------------------------------------------------------
1905 void ORowSetValue::fill(const Any& _rValue)
1907 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (3)" );
1908 switch (_rValue.getValueType().getTypeClass())
1910 case TypeClass_VOID:
1911 setNull();
1912 break;
1913 case TypeClass_BOOLEAN:
1915 sal_Bool bValue( sal_False );
1916 _rValue >>= bValue;
1917 (*this) = bValue;
1918 break;
1920 case TypeClass_CHAR:
1922 sal_Unicode aDummy(0);
1923 _rValue >>= aDummy;
1924 (*this) = ::rtl::OUString(aDummy);
1925 break;
1927 case TypeClass_STRING:
1929 ::rtl::OUString sDummy;
1930 _rValue >>= sDummy;
1931 (*this) = sDummy;
1932 break;
1934 case TypeClass_FLOAT:
1936 float aDummy;
1937 _rValue >>= aDummy;
1938 (*this) = aDummy;
1939 break;
1941 case TypeClass_DOUBLE:
1943 double aDummy;
1944 _rValue >>= aDummy;
1945 (*this) = aDummy;
1946 break;
1948 case TypeClass_BYTE:
1950 sal_Int8 aDummy;
1951 _rValue >>= aDummy;
1952 (*this) = aDummy;
1953 break;
1955 case TypeClass_SHORT:
1957 sal_Int16 aDummy;
1958 _rValue >>= aDummy;
1959 (*this) = aDummy;
1960 break;
1962 case TypeClass_LONG:
1964 sal_Int32 aDummy;
1965 _rValue >>= aDummy;
1966 (*this) = aDummy;
1967 break;
1969 case TypeClass_UNSIGNED_SHORT:
1971 sal_uInt16 nValue(0);
1972 _rValue >>= nValue;
1973 (*this) = static_cast<sal_Int32>(nValue);
1974 setSigned(sal_False);
1975 break;
1977 case TypeClass_HYPER:
1979 sal_Int64 nValue(0);
1980 _rValue >>= nValue;
1981 (*this) = nValue;
1982 break;
1984 case TypeClass_UNSIGNED_HYPER:
1986 sal_uInt64 nValue(0);
1987 _rValue >>= nValue;
1988 (*this) = static_cast<sal_Int64>(nValue);
1989 setSigned(sal_False);
1990 break;
1992 case TypeClass_UNSIGNED_LONG:
1994 sal_uInt32 nValue(0);
1995 _rValue >>= nValue;
1996 (*this) = static_cast<sal_Int64>(nValue);
1997 setSigned(sal_False);
1998 break;
2000 case TypeClass_ENUM:
2002 sal_Int32 enumValue( 0 );
2003 ::cppu::enum2int( enumValue, _rValue );
2004 (*this) = enumValue;
2006 break;
2008 case TypeClass_SEQUENCE:
2010 Sequence<sal_Int8> aDummy;
2011 if ( _rValue >>= aDummy )
2012 (*this) = aDummy;
2013 else
2014 OSL_ENSURE( false, "ORowSetValue::fill: unsupported sequence type!" );
2015 break;
2018 case TypeClass_STRUCT:
2020 ::com::sun::star::util::Date aDate;
2021 ::com::sun::star::util::Time aTime;
2022 ::com::sun::star::util::DateTime aDateTime;
2023 if ( _rValue >>= aDate )
2025 (*this) = aDate;
2027 else if ( _rValue >>= aTime )
2029 (*this) = aTime;
2031 else if ( _rValue >>= aDateTime )
2033 (*this) = aDateTime;
2035 else
2036 OSL_ENSURE( false, "ORowSetValue::fill: unsupported structure!" );
2038 break;
2041 default:
2042 OSL_ENSURE(0,"Unknown type");
2043 break;