xref: /AOO41X/main/connectivity/source/commontools/FValue.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #include <stdio.h>
28 #include "connectivity/FValue.hxx"
29 #include "connectivity/CommonTools.hxx"
30 #include <connectivity/dbconversion.hxx>
31 #include <comphelper/extract.hxx>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <rtl/ustrbuf.hxx>
34 #include <rtl/logfile.hxx>
35 
36 using namespace ::dbtools;
37 using namespace ::com::sun::star::sdbc;
38 using namespace ::com::sun::star::sdb;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::util;
41 using namespace ::com::sun::star::io;
42 
43 namespace connectivity
44 {
45 
46 namespace {
isStorageCompatible(sal_Int32 _eType1,sal_Int32 _eType2)47     static sal_Bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
48     {
49         RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::isStorageCompatible" );
50         sal_Bool bIsCompatible = sal_True;
51 
52         if (_eType1 != _eType2)
53         {
54             RTL_LOGFILE_CONTEXT_TRACE( aLogger, "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
55             switch (_eType1)
56             {
57                 case DataType::CHAR:
58                 case DataType::VARCHAR:
59                 case DataType::DECIMAL:
60                 case DataType::NUMERIC:
61                 case DataType::LONGVARCHAR:
62                     bIsCompatible = (DataType::CHAR         == _eType2)
63                                 ||  (DataType::VARCHAR      == _eType2)
64                                 ||  (DataType::DECIMAL      == _eType2)
65                                 ||  (DataType::NUMERIC      == _eType2)
66                                 ||  (DataType::LONGVARCHAR  == _eType2);
67                     break;
68 
69                 case DataType::DOUBLE:
70                 case DataType::REAL:
71                     bIsCompatible = (DataType::DOUBLE   == _eType2)
72                                 ||  (DataType::REAL     == _eType2);
73                     break;
74 
75                 case DataType::BINARY:
76                 case DataType::VARBINARY:
77                 case DataType::LONGVARBINARY:
78                     bIsCompatible = (DataType::BINARY           == _eType2)
79                                 ||  (DataType::VARBINARY        == _eType2)
80                                 ||  (DataType::LONGVARBINARY    == _eType2);
81                     break;
82 
83                 case DataType::INTEGER:
84                     bIsCompatible = (DataType::SMALLINT == _eType2)
85                                 ||  (DataType::TINYINT  == _eType2)
86                                 ||  (DataType::BIT      == _eType2)
87                                 ||  (DataType::BOOLEAN  == _eType2);
88                     break;
89                 case DataType::SMALLINT:
90                     bIsCompatible = (DataType::TINYINT  == _eType2)
91                                 ||  (DataType::BIT      == _eType2)
92                                 ||  (DataType::BOOLEAN  == _eType2);
93                     break;
94                 case DataType::TINYINT:
95                     bIsCompatible = (DataType::BIT      == _eType2)
96                                 ||  (DataType::BOOLEAN  == _eType2);
97                     break;
98 
99                 case DataType::BLOB:
100                 case DataType::CLOB:
101                 case DataType::OBJECT:
102                     bIsCompatible = (DataType::BLOB     == _eType2)
103                                 ||  (DataType::CLOB     == _eType2)
104                                 ||  (DataType::OBJECT   == _eType2);
105                     break;
106 
107                 default:
108                     bIsCompatible = sal_False;
109             }
110         }
111         return bIsCompatible;
112     }
113 }
114 
115 // -----------------------------------------------------------------------------
116 #ifdef DBG_UTIL
117 
118 #include <vector>
119 #include <rtl/string.h>
120 
121 namespace tracing
122 {
123     struct AllocationType
124     {
125         const sal_Char* pName;
126         sal_Int32       nAllocatedUnits;
127 
AllocationTypeconnectivity::tracing::AllocationType128         AllocationType( ) : pName( NULL ), nAllocatedUnits( 0 ) { }
129     };
130 
131     // =============================================================================
132     class AllocationTracer
133     {
134     public:
135         typedef ::std::vector< AllocationType > AllocationState;
136         static AllocationState                  s_aAllocated;
137         static ::osl::Mutex                     s_aMutex;
138 
139     public:
140         static void registerUnit( const sal_Char* _pName );
141         static void revokeUnit( const sal_Char* _pName );
142 
143     private:
144         static AllocationState::iterator    getLocation( const sal_Char* _pName );
145     };
146 
147     // =============================================================================
getLocation(const sal_Char * _pName)148     AllocationTracer::AllocationState::iterator AllocationTracer::getLocation( const sal_Char* _pName )
149     {
150         AllocationState::iterator aLookFor = s_aAllocated.begin();
151         for (   ;
152                 aLookFor != s_aAllocated.end();
153                 ++aLookFor
154             )
155         {
156             if ( 0 == rtl_str_compare( aLookFor->pName, _pName ) )
157                 // found
158                 return aLookFor;
159         }
160         // not found
161         s_aAllocated.push_back( AllocationType() );
162         aLookFor = s_aAllocated.end(); --aLookFor;
163         aLookFor->pName = _pName;   // note that this assumes that _pName is a constant string ....
164         return aLookFor;
165     }
166 
167     // =============================================================================
168     AllocationTracer::AllocationState           AllocationTracer::s_aAllocated;
169     ::osl::Mutex                                AllocationTracer::s_aMutex;
170 
171     // =============================================================================
registerUnit(const sal_Char * _pName)172     void AllocationTracer::registerUnit( const sal_Char* _pName )
173     {
174         ::osl::MutexGuard aGuard( s_aMutex );
175 
176         AllocationState::iterator aPos = getLocation( _pName );
177         ++aPos->nAllocatedUnits;
178     }
179 
180     // =============================================================================
revokeUnit(const sal_Char * _pName)181     void AllocationTracer::revokeUnit( const sal_Char* _pName )
182     {
183         ::osl::MutexGuard aGuard( s_aMutex );
184 
185         AllocationState::iterator aPos = getLocation( _pName );
186         --aPos->nAllocatedUnits;
187     }
188 
189 #define TRACE_ALLOC( type ) tracing::AllocationTracer::registerUnit( #type );
190 #define TRACE_FREE( type )  tracing::AllocationTracer::revokeUnit( #type );
191 }
192 #else
193 #define TRACE_ALLOC( type )
194 #define TRACE_FREE( type )
195 #endif
196 
197 // -----------------------------------------------------------------------------
setTypeKind(sal_Int32 _eType)198 void ORowSetValue::setTypeKind(sal_Int32 _eType)
199 {
200     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setTypeKind" );
201     if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
202     {
203         switch(_eType)
204         {
205             case DataType::VARCHAR:
206             case DataType::CHAR:
207             case DataType::DECIMAL:
208             case DataType::NUMERIC:
209             case DataType::LONGVARCHAR:
210                 (*this) = getString();
211                 break;
212             case DataType::BIGINT:
213                 (*this) = getLong();
214                 break;
215 
216             case DataType::FLOAT:
217                 (*this) = getFloat();
218                 break;
219             case DataType::DOUBLE:
220             case DataType::REAL:
221                 (*this) = getDouble();
222                 break;
223             case DataType::TINYINT:
224                 (*this) = getInt8();
225                 break;
226             case DataType::SMALLINT:
227                 (*this) = getInt16();
228                 break;
229             case DataType::INTEGER:
230                 (*this) = getInt32();
231                 break;
232             case DataType::BIT:
233             case DataType::BOOLEAN:
234                 (*this) = getBool();
235                 break;
236             case DataType::DATE:
237                 (*this) = getDate();
238                 break;
239             case DataType::TIME:
240                 (*this) = getTime();
241                 break;
242             case DataType::TIMESTAMP:
243                 (*this) = getDateTime();
244                 break;
245             case DataType::BINARY:
246             case DataType::VARBINARY:
247             case DataType::LONGVARBINARY:
248                 (*this) = getSequence();
249                 break;
250             case DataType::BLOB:
251             case DataType::CLOB:
252             case DataType::OBJECT:
253             case DataType::OTHER:
254                 (*this) = getAny();
255                 break;
256             default:
257                 (*this) = getAny();
258                 OSL_ENSURE(0,"ORowSetValue:operator==(): UNSPUPPORTED TYPE!");
259         }
260     }
261 
262     m_eTypeKind = _eType;
263 }
264 
265 // -----------------------------------------------------------------------------
free()266 void ORowSetValue::free()
267 {
268     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::free" );
269     if(!m_bNull)
270     {
271         switch(m_eTypeKind)
272         {
273             case DataType::CHAR:
274             case DataType::VARCHAR:
275             case DataType::DECIMAL:
276             case DataType::NUMERIC:
277             case DataType::LONGVARCHAR:
278                 OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
279                 rtl_uString_release(m_aValue.m_pString);
280                 m_aValue.m_pString = NULL;
281                 break;
282             case DataType::INTEGER:
283                 if ( !m_bSigned )
284                 {
285                     delete (sal_Int64*)m_aValue.m_pValue;
286                     TRACE_FREE( sal_Int64 )
287                     m_aValue.m_pValue = NULL;
288                 }
289                 break;
290             case DataType::BIGINT:
291                 if ( m_bSigned )
292                 {
293                     delete (sal_Int64*)m_aValue.m_pValue;
294                     TRACE_FREE( sal_Int64 )
295                     m_aValue.m_pValue = NULL;
296                 }
297                 else
298                 {
299                     OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
300                     rtl_uString_release(m_aValue.m_pString);
301                     m_aValue.m_pString = NULL;
302                 }
303                 break;
304             case DataType::FLOAT:
305                 delete (float*)m_aValue.m_pValue;
306                 TRACE_FREE( float )
307                 m_aValue.m_pValue = NULL;
308                 break;
309             case DataType::DOUBLE:
310             case DataType::REAL:
311                 delete (double*)m_aValue.m_pValue;
312                 TRACE_FREE( double )
313                 m_aValue.m_pValue = NULL;
314                 break;
315             case DataType::DATE:
316                 delete (::com::sun::star::util::Date*)m_aValue.m_pValue;
317                 TRACE_FREE( Date )
318                 m_aValue.m_pValue = NULL;
319                 break;
320             case DataType::TIME:
321                 delete (::com::sun::star::util::Time*)m_aValue.m_pValue;
322                 TRACE_FREE( Time )
323                 m_aValue.m_pValue = NULL;
324                 break;
325             case DataType::TIMESTAMP:
326                 delete (::com::sun::star::util::DateTime*)m_aValue.m_pValue;
327                 TRACE_FREE( DateTime )
328                 m_aValue.m_pValue = NULL;
329                 break;
330             case DataType::BINARY:
331             case DataType::VARBINARY:
332             case DataType::LONGVARBINARY:
333                 delete (Sequence<sal_Int8>*)m_aValue.m_pValue;
334                 TRACE_FREE( Sequence_sal_Int8 )
335                 m_aValue.m_pValue = NULL;
336                 break;
337             case DataType::BLOB:
338             case DataType::CLOB:
339             case DataType::OBJECT:
340                 delete (Any*)m_aValue.m_pValue;
341                 TRACE_FREE( Any )
342                 m_aValue.m_pValue = NULL;
343                 break;
344             case DataType::BIT:
345             case DataType::TINYINT:
346             case DataType::SMALLINT:
347             case DataType::BOOLEAN:
348                 break;
349             default:
350                 if ( m_aValue.m_pValue )
351                 {
352                     delete (Any*)m_aValue.m_pValue;
353                     TRACE_FREE( Any )
354                     m_aValue.m_pValue = NULL;
355                 }
356                 break;
357 
358         }
359         m_bNull = sal_True;
360     }
361 }
362 // -----------------------------------------------------------------------------
operator =(const ORowSetValue & _rRH)363 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
364 {
365     if(&_rRH == this)
366         return *this;
367 
368     if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
369         free();
370 
371     m_bBound    = _rRH.m_bBound;
372     m_eTypeKind = _rRH.m_eTypeKind;
373     m_bSigned   = _rRH.m_bSigned;
374 
375     if(m_bNull && !_rRH.m_bNull)
376     {
377         switch(_rRH.m_eTypeKind)
378         {
379             case DataType::CHAR:
380             case DataType::VARCHAR:
381             case DataType::DECIMAL:
382             case DataType::NUMERIC:
383             case DataType::LONGVARCHAR:
384                 rtl_uString_acquire(_rRH.m_aValue.m_pString);
385                 m_aValue.m_pString = _rRH.m_aValue.m_pString;
386                 break;
387             case DataType::BIGINT:
388                 if ( _rRH.m_bSigned )
389                 {
390                     m_aValue.m_pValue   = new sal_Int64(*(sal_Int64*)_rRH.m_aValue.m_pValue);
391                     TRACE_ALLOC( sal_Int64 )
392                 }
393                 else
394                 {
395                     rtl_uString_acquire(_rRH.m_aValue.m_pString);
396                     m_aValue.m_pString = _rRH.m_aValue.m_pString;
397                 }
398                 break;
399             case DataType::FLOAT:
400                 m_aValue.m_pValue   = new float(*(float*)_rRH.m_aValue.m_pValue);
401                 TRACE_ALLOC( float )
402                 break;
403             case DataType::DOUBLE:
404             case DataType::REAL:
405                 m_aValue.m_pValue   = new double(*(double*)_rRH.m_aValue.m_pValue);
406                 TRACE_ALLOC( double )
407                 break;
408             case DataType::DATE:
409                 m_aValue.m_pValue   = new Date(*(Date*)_rRH.m_aValue.m_pValue);
410                 TRACE_ALLOC( Date )
411                 break;
412             case DataType::TIME:
413                 m_aValue.m_pValue   = new Time(*(Time*)_rRH.m_aValue.m_pValue);
414                 TRACE_ALLOC( Time )
415                 break;
416             case DataType::TIMESTAMP:
417                 m_aValue.m_pValue   = new DateTime(*(DateTime*)_rRH.m_aValue.m_pValue);
418                 TRACE_ALLOC( DateTime )
419                 break;
420             case DataType::BINARY:
421             case DataType::VARBINARY:
422             case DataType::LONGVARBINARY:
423                 m_aValue.m_pValue   = new Sequence<sal_Int8>(*(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue);
424                 TRACE_ALLOC( Sequence_sal_Int8 )
425                 break;
426             case DataType::BIT:
427             case DataType::BOOLEAN:
428                 m_aValue.m_bBool    = _rRH.m_aValue.m_bBool;
429                 break;
430             case DataType::TINYINT:
431                 if ( _rRH.m_bSigned )
432                     m_aValue.m_nInt8    = _rRH.m_aValue.m_nInt8;
433                 else
434                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
435                 break;
436             case DataType::SMALLINT:
437                 if ( _rRH.m_bSigned )
438                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
439                 else
440                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
441                 break;
442             case DataType::INTEGER:
443                 if ( _rRH.m_bSigned )
444                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
445                 else
446                 {
447                     m_aValue.m_pValue   = new sal_Int64(*(sal_Int64*)_rRH.m_aValue.m_pValue);
448                     TRACE_ALLOC( sal_Int64 )
449                 }
450                 break;
451             default:
452                 m_aValue.m_pValue   = new Any(*(Any*)_rRH.m_aValue.m_pValue);
453                 TRACE_ALLOC( Any )
454         }
455     }
456     else if(!_rRH.m_bNull)
457     {
458         switch(_rRH.m_eTypeKind)
459         {
460             case DataType::CHAR:
461             case DataType::VARCHAR:
462             case DataType::DECIMAL:
463             case DataType::NUMERIC:
464             case DataType::LONGVARCHAR:
465                 (*this) = ::rtl::OUString(_rRH.m_aValue.m_pString);
466                 break;
467             case DataType::BIGINT:
468                 if ( _rRH.m_bSigned )
469                     (*this) = *(sal_Int64*)_rRH.m_aValue.m_pValue;
470                 else
471                     (*this) = ::rtl::OUString(_rRH.m_aValue.m_pString);
472                 break;
473             case DataType::FLOAT:
474                 (*this) = *(float*)_rRH.m_aValue.m_pValue;
475                 break;
476             case DataType::DOUBLE:
477             case DataType::REAL:
478                 (*this) = *(double*)_rRH.m_aValue.m_pValue;
479                 break;
480             case DataType::DATE:
481                 (*this) = *(Date*)_rRH.m_aValue.m_pValue;
482                 break;
483             case DataType::TIME:
484                 (*this) = *(Time*)_rRH.m_aValue.m_pValue;
485                 break;
486             case DataType::TIMESTAMP:
487                 (*this) = *(DateTime*)_rRH.m_aValue.m_pValue;
488                 break;
489             case DataType::BINARY:
490             case DataType::VARBINARY:
491             case DataType::LONGVARBINARY:
492                 (*this) = *(Sequence<sal_Int8>*)_rRH.m_aValue.m_pValue;
493                 break;
494             case DataType::BIT:
495             case DataType::BOOLEAN:
496                 m_aValue.m_bBool    = _rRH.m_aValue.m_bBool;
497                 break;
498             case DataType::TINYINT:
499                 if ( _rRH.m_bSigned )
500                     m_aValue.m_nInt8    = _rRH.m_aValue.m_nInt8;
501                 else
502                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
503                 break;
504             case DataType::SMALLINT:
505                 if ( _rRH.m_bSigned )
506                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
507                 else
508                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
509                 break;
510             case DataType::INTEGER:
511                 if ( _rRH.m_bSigned )
512                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
513                 else
514                     *static_cast<sal_Int64*>(m_aValue.m_pValue) = *(sal_Int64*)_rRH.m_aValue.m_pValue;
515                 break;
516             default:
517                 (*(Any*)m_aValue.m_pValue)  = (*(Any*)_rRH.m_aValue.m_pValue);
518         }
519     }
520 
521     m_bNull     = _rRH.m_bNull;
522     // OJ: BUGID: 96277
523     m_eTypeKind = _rRH.m_eTypeKind;
524 
525     return *this;
526 }
527 // -------------------------------------------------------------------------
528 
operator =(const Date & _rRH)529 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
530 {
531     if(m_eTypeKind != DataType::DATE)
532         free();
533 
534     if(m_bNull)
535     {
536         m_aValue.m_pValue = new Date(_rRH);
537         TRACE_ALLOC( Date )
538         m_eTypeKind = DataType::DATE;
539         m_bNull = sal_False;
540     }
541     else
542         *(Date*)m_aValue.m_pValue = _rRH;
543 
544     return *this;
545 }
546 // -------------------------------------------------------------------------
operator =(const Time & _rRH)547 ORowSetValue& ORowSetValue::operator=(const Time& _rRH)
548 {
549     if(m_eTypeKind != DataType::TIME)
550         free();
551 
552     if(m_bNull)
553     {
554         m_aValue.m_pValue = new Time(_rRH);
555         TRACE_ALLOC( Time )
556         m_eTypeKind = DataType::TIME;
557         m_bNull = sal_False;
558     }
559     else
560         *(Time*)m_aValue.m_pValue = _rRH;
561 
562     return *this;
563 }
564 // -------------------------------------------------------------------------
operator =(const DateTime & _rRH)565 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
566 {
567     if(m_eTypeKind != DataType::TIMESTAMP)
568         free();
569     if(m_bNull)
570     {
571         m_aValue.m_pValue = new DateTime(_rRH);
572         TRACE_ALLOC( DateTime )
573         m_eTypeKind = DataType::TIMESTAMP;
574         m_bNull = sal_False;
575     }
576     else
577         *(DateTime*)m_aValue.m_pValue = _rRH;
578 
579     return *this;
580 }
581 // -------------------------------------------------------------------------
582 
operator =(const::rtl::OUString & _rRH)583 ORowSetValue& ORowSetValue::operator=(const ::rtl::OUString& _rRH)
584 {
585     if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
586     {
587         free();
588         m_bNull = sal_False;
589 
590         m_aValue.m_pString = _rRH.pData;
591         rtl_uString_acquire(m_aValue.m_pString);
592         m_eTypeKind = DataType::VARCHAR;
593     }
594 
595     return *this;
596 }
597 // -------------------------------------------------------------------------
598 
operator =(const double & _rRH)599 ORowSetValue& ORowSetValue::operator=(const double& _rRH)
600 {
601     if( !isStorageCompatible(m_eTypeKind,DataType::DOUBLE) )
602         free();
603 
604     if(m_bNull)
605     {
606         m_aValue.m_pValue = new double(_rRH);
607         TRACE_ALLOC( double )
608         m_eTypeKind = DataType::DOUBLE;
609         m_bNull = sal_False;
610     }
611     else
612         *(double*)m_aValue.m_pValue = _rRH;
613 
614     return *this;
615 }
616 // -----------------------------------------------------------------------------
operator =(const float & _rRH)617 ORowSetValue& ORowSetValue::operator=(const float& _rRH)
618 {
619     if(m_eTypeKind != DataType::FLOAT)
620         free();
621 
622     if(m_bNull)
623     {
624         m_aValue.m_pValue = new float(_rRH);
625         TRACE_ALLOC( float )
626         m_eTypeKind = DataType::FLOAT;
627         m_bNull = sal_False;
628     }
629     else
630         *(float*)m_aValue.m_pValue = _rRH;
631 
632     return *this;
633 }
634 // -------------------------------------------------------------------------
635 
operator =(const sal_Int8 & _rRH)636 ORowSetValue& ORowSetValue::operator=(const sal_Int8& _rRH)
637 {
638     if(m_eTypeKind != DataType::TINYINT )
639         free();
640 
641     m_aValue.m_nInt8 = _rRH;
642     m_eTypeKind = DataType::TINYINT;
643     m_bNull = sal_False;
644     return *this;
645 }
646 // -------------------------------------------------------------------------
647 
operator =(const sal_Int16 & _rRH)648 ORowSetValue& ORowSetValue::operator=(const sal_Int16& _rRH)
649 {
650     if(m_eTypeKind != DataType::SMALLINT )
651         free();
652 
653     m_aValue.m_nInt16 = _rRH;
654     m_eTypeKind = DataType::SMALLINT;
655     m_bNull = sal_False;
656 
657     return *this;
658 }
659 // -------------------------------------------------------------------------
660 
operator =(const sal_Int32 & _rRH)661 ORowSetValue& ORowSetValue::operator=(const sal_Int32& _rRH)
662 {
663     if(m_eTypeKind != DataType::INTEGER )
664         free();
665 
666     if ( m_bSigned )
667         m_aValue.m_nInt32 = _rRH;
668     else
669     {
670         if ( m_bNull )
671         {
672             m_aValue.m_pValue = new sal_Int64(_rRH);
673             TRACE_ALLOC( sal_Int64 )
674         }
675         else
676             *static_cast<sal_Int64*>(m_aValue.m_pValue) = static_cast<sal_Int64>(_rRH);
677     }
678 
679     m_eTypeKind = DataType::INTEGER;
680     m_bNull = sal_False;
681 
682     return *this;
683 }
684 // -------------------------------------------------------------------------
685 
operator =(const sal_Bool _rRH)686 ORowSetValue& ORowSetValue::operator=(const sal_Bool _rRH)
687 {
688     if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
689         free();
690 
691     m_aValue.m_bBool = _rRH;
692     m_eTypeKind = DataType::BIT;
693     m_bNull = sal_False;
694 
695     return *this;
696 }
697 // -------------------------------------------------------------------------
operator =(const sal_Int64 & _rRH)698 ORowSetValue& ORowSetValue::operator=(const sal_Int64& _rRH)
699 {
700     if ( DataType::BIGINT != m_eTypeKind || !m_bSigned )
701         free();
702 
703     if ( m_bSigned )
704     {
705         if(m_bNull)
706         {
707             m_aValue.m_pValue = new sal_Int64(_rRH);
708             TRACE_ALLOC( sal_Int64 )
709         }
710         else
711             *static_cast<sal_Int64*>(m_aValue.m_pValue) = _rRH;
712     }
713     else
714     {
715         ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rRH);
716         m_aValue.m_pString = aVal.pData;
717         rtl_uString_acquire(m_aValue.m_pString);
718     }
719 
720     m_eTypeKind = DataType::BIGINT;
721     m_bNull = sal_False;
722 
723     return *this;
724 }
725 // -------------------------------------------------------------------------
operator =(const Sequence<sal_Int8> & _rRH)726 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
727 {
728     if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
729         free();
730 
731     if (m_bNull)
732     {
733         m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
734         TRACE_ALLOC( Sequence_sal_Int8 )
735     }
736     else
737         *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
738 
739     m_eTypeKind = DataType::LONGVARBINARY;
740     m_bNull = sal_False;
741 
742     return *this;
743 }
744 // -------------------------------------------------------------------------
operator =(const Any & _rAny)745 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
746 {
747     if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
748         free();
749 
750     if ( m_bNull )
751     {
752         m_aValue.m_pValue = new Any(_rAny);
753         TRACE_ALLOC( Any )
754     }
755     else
756         *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
757 
758     m_eTypeKind = DataType::OBJECT;
759     m_bNull = sal_False;
760 
761     return *this;
762 }
763 // -------------------------------------------------------------------------
764 
operator ==(const Date & _rLH,const Date & _rRH)765 sal_Bool operator==(const Date& _rLH,const Date& _rRH)
766 {
767     return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year;
768 }
769 // -------------------------------------------------------------------------
770 
operator ==(const Time & _rLH,const Time & _rRH)771 sal_Bool operator==(const Time& _rLH,const Time& _rRH)
772 {
773     return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds;
774 }
775 // -------------------------------------------------------------------------
776 
operator ==(const DateTime & _rLH,const DateTime & _rRH)777 sal_Bool operator==(const DateTime& _rLH,const DateTime& _rRH)
778 {
779     return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year &&
780         _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds;
781 }
782 // -------------------------------------------------------------------------
783 
operator ==(const ORowSetValue & _rRH) const784 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
785 {
786     if ( m_bNull != _rRH.isNull() )
787         return false;
788 
789     if(m_bNull && _rRH.isNull())
790         return true;
791 
792     if ( m_eTypeKind != _rRH.m_eTypeKind )
793     {
794         switch(m_eTypeKind)
795         {
796             case DataType::FLOAT:
797             case DataType::DOUBLE:
798             case DataType::REAL:
799                 return getDouble() == _rRH.getDouble();
800             default:
801                 switch(_rRH.m_eTypeKind)
802                 {
803                     case DataType::FLOAT:
804                     case DataType::DOUBLE:
805                     case DataType::REAL:
806                             return getDouble() == _rRH.getDouble();
807                     default:
808                             break;
809                 }
810                 break;
811             }
812         return false;
813     }
814 
815     bool bRet = false;
816     OSL_ENSURE(!m_bNull,"SHould not be null!");
817     switch(m_eTypeKind)
818     {
819         case DataType::VARCHAR:
820         case DataType::CHAR:
821         case DataType::LONGVARCHAR:
822         {
823             ::rtl::OUString aVal1(m_aValue.m_pString);
824             ::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
825             return aVal1 == aVal2;
826         }
827         default:
828             if ( m_bSigned != _rRH.m_bSigned )
829                 return false;
830             break;
831     }
832 
833     switch(m_eTypeKind)
834     {
835         case DataType::DECIMAL:
836         case DataType::NUMERIC:
837             {
838                 ::rtl::OUString aVal1(m_aValue.m_pString);
839                 ::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
840                 bRet = aVal1 == aVal2;
841             }
842             break;
843         case DataType::FLOAT:
844             bRet = *(float*)m_aValue.m_pValue == *(float*)_rRH.m_aValue.m_pValue;
845             break;
846         case DataType::DOUBLE:
847         case DataType::REAL:
848             bRet = *(double*)m_aValue.m_pValue == *(double*)_rRH.m_aValue.m_pValue;
849             break;
850         case DataType::TINYINT:
851             bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16);
852             break;
853         case DataType::SMALLINT:
854             bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32);
855             break;
856         case DataType::INTEGER:
857             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);
858             break;
859         case DataType::BIGINT:
860             if ( m_bSigned )
861                 bRet = *(sal_Int64*)m_aValue.m_pValue == *(sal_Int64*)_rRH.m_aValue.m_pValue;
862             else
863             {
864                 ::rtl::OUString aVal1(m_aValue.m_pString);
865                 ::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
866                 bRet = aVal1 == aVal2;
867             }
868             break;
869         case DataType::BIT:
870         case DataType::BOOLEAN:
871             bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
872             break;
873         case DataType::DATE:
874             bRet = *(Date*)m_aValue.m_pValue == *(Date*)_rRH.m_aValue.m_pValue;
875             break;
876         case DataType::TIME:
877             bRet = *(Time*)m_aValue.m_pValue == *(Time*)_rRH.m_aValue.m_pValue;
878             break;
879         case DataType::TIMESTAMP:
880             bRet = *(DateTime*)m_aValue.m_pValue == *(DateTime*)_rRH.m_aValue.m_pValue;
881             break;
882         case DataType::BINARY:
883         case DataType::VARBINARY:
884         case DataType::LONGVARBINARY:
885             bRet = false;
886             break;
887         case DataType::BLOB:
888         case DataType::CLOB:
889         case DataType::OBJECT:
890         case DataType::OTHER:
891             bRet = false;
892             break;
893         default:
894             bRet = false;
895             OSL_ENSURE(0,"ORowSetValue::operator==(): UNSPUPPORTED TYPE!");
896             break;
897     }
898     return bRet;
899 }
900 // -------------------------------------------------------------------------
makeAny() const901 Any ORowSetValue::makeAny() const
902 {
903     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::makeAny" );
904     Any rValue;
905     if(isBound() && !isNull())
906     {
907         switch(getTypeKind())
908         {
909             case DataType::CHAR:
910             case DataType::VARCHAR:
911             case DataType::DECIMAL:
912             case DataType::NUMERIC:
913             case DataType::LONGVARCHAR:
914                 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
915                 rValue <<= (::rtl::OUString)m_aValue.m_pString;
916                 break;
917             case DataType::BIGINT:
918                 if ( m_bSigned )
919                 {
920                     OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
921                     rValue <<= *(sal_Int64*)m_aValue.m_pValue;
922                 }
923                 else
924                 {
925                     OSL_ENSURE(m_aValue.m_pString,"Value is null!");
926                     rValue <<= (::rtl::OUString)m_aValue.m_pString;
927                 }
928                 break;
929             case DataType::FLOAT:
930                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
931                 rValue <<= *(float*)m_aValue.m_pValue;
932                 break;
933             case DataType::DOUBLE:
934             case DataType::REAL:
935                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
936                 rValue <<= *(double*)m_aValue.m_pValue;
937                 break;
938             case DataType::DATE:
939                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
940                 rValue <<= *(Date*)m_aValue.m_pValue;
941                 break;
942             case DataType::TIME:
943                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
944                 rValue <<= *(Time*)m_aValue.m_pValue;
945                 break;
946             case DataType::TIMESTAMP:
947                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
948                 rValue <<= *(DateTime*)m_aValue.m_pValue;
949                 break;
950             case DataType::BINARY:
951             case DataType::VARBINARY:
952             case DataType::LONGVARBINARY:
953                 OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
954                 rValue <<= *(Sequence<sal_Int8>*)m_aValue.m_pValue;
955                 break;
956             case DataType::BLOB:
957             case DataType::CLOB:
958             case DataType::OBJECT:
959             case DataType::OTHER:
960                 rValue = getAny();
961                 break;
962             case DataType::BIT:
963             case DataType::BOOLEAN:
964                 rValue.setValue( &m_aValue.m_bBool, ::getCppuBooleanType() );
965                 break;
966             case DataType::TINYINT:
967                 if ( m_bSigned )
968                     rValue <<= m_aValue.m_nInt8;
969                 else
970                     rValue <<= m_aValue.m_nInt16;
971                 break;
972             case DataType::SMALLINT:
973                 if ( m_bSigned )
974                     rValue <<= m_aValue.m_nInt16;
975                 else
976                     rValue <<= m_aValue.m_nInt32;
977                 break;
978             case DataType::INTEGER:
979                 if ( m_bSigned )
980                     rValue <<= m_aValue.m_nInt32;
981                 else
982                 {
983                     OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
984                     rValue <<= *(sal_Int64*)m_aValue.m_pValue;
985                 }
986                 break;
987             default:
988                 OSL_ENSURE(0,"ORowSetValue::makeAny(): UNSPUPPORTED TYPE!");
989                 rValue = getAny();
990                 break;
991         }
992     }
993     return rValue;
994 }
995 // -------------------------------------------------------------------------
getString() const996 ::rtl::OUString ORowSetValue::getString( ) const
997 {
998     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getString" );
999     ::rtl::OUString aRet;
1000     if(!m_bNull)
1001     {
1002         switch(getTypeKind())
1003         {
1004             case DataType::CHAR:
1005             case DataType::VARCHAR:
1006             case DataType::DECIMAL:
1007             case DataType::NUMERIC:
1008             case DataType::LONGVARCHAR:
1009                 aRet = m_aValue.m_pString;
1010                 break;
1011             case DataType::BIGINT:
1012                 if ( m_bSigned )
1013                     aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
1014                 else
1015                     aRet = m_aValue.m_pString;
1016                 break;
1017             case DataType::FLOAT:
1018                 aRet = ::rtl::OUString::valueOf((float)*this);
1019                 break;
1020             case DataType::DOUBLE:
1021             case DataType::REAL:
1022                 aRet = ::rtl::OUString::valueOf((double)*this);
1023                 break;
1024             case DataType::DATE:
1025                 aRet = connectivity::toDateString(*this);
1026                 break;
1027             case DataType::TIME:
1028                 aRet = connectivity::toTimeString(*this);
1029                 break;
1030             case DataType::TIMESTAMP:
1031                 aRet = connectivity::toDateTimeString(*this);
1032                 break;
1033             case DataType::BINARY:
1034             case DataType::VARBINARY:
1035             case DataType::LONGVARBINARY:
1036                 {
1037                     ::rtl::OUStringBuffer sVal = ::rtl::OUString::createFromAscii("0x");
1038                     Sequence<sal_Int8> aSeq(getSequence());
1039                     const sal_Int8* pBegin  = aSeq.getConstArray();
1040                     const sal_Int8* pEnd    = pBegin + aSeq.getLength();
1041                     for(;pBegin != pEnd;++pBegin)
1042                         sVal.append((sal_Int32)*pBegin,16);
1043                     aRet = sVal.makeStringAndClear();
1044                 }
1045                 break;
1046             case DataType::BIT:
1047             case DataType::BOOLEAN:
1048                 aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Bool)*this);
1049                 break;
1050             case DataType::TINYINT:
1051                 if ( m_bSigned )
1052                     aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int8)*this);
1053                 else
1054                     aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1055                 break;
1056             case DataType::SMALLINT:
1057                 if ( m_bSigned )
1058                     aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1059                 else
1060                     aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1061                 break;
1062             case DataType::INTEGER:
1063                 if ( m_bSigned )
1064                     aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1065                 else
1066                     aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
1067                 break;
1068             case DataType::CLOB:
1069                 {
1070                     Any aValue( getAny() );
1071                     Reference< XClob > xClob;
1072                     if ( aValue >>= xClob )
1073                     {
1074                         if ( xClob.is() )
1075                         {
1076                             aRet = xClob->getSubString(1,(sal_Int32)xClob->length() );
1077                         }
1078                     }
1079                 }
1080                 break;
1081             default:
1082                 {
1083                     Any aValue = getAny();
1084                     aValue >>= aRet;
1085                     break;
1086                 }
1087         }
1088     }
1089     return aRet;
1090 }
1091 // -------------------------------------------------------------------------
getBool() const1092 sal_Bool ORowSetValue::getBool()    const
1093 {
1094     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getBool" );
1095     sal_Bool bRet = sal_False;
1096     if(!m_bNull)
1097     {
1098         switch(getTypeKind())
1099         {
1100             case DataType::CHAR:
1101             case DataType::VARCHAR:
1102             case DataType::LONGVARCHAR:
1103                 {
1104                     const ::rtl::OUString sValue(m_aValue.m_pString);
1105                     const static ::rtl::OUString s_sTrue(RTL_CONSTASCII_USTRINGPARAM("true"));
1106                     const static ::rtl::OUString s_sFalse(RTL_CONSTASCII_USTRINGPARAM("false"));
1107                     if ( sValue.equalsIgnoreAsciiCase(s_sTrue) )
1108                     {
1109                         bRet = sal_True;
1110                         break;
1111                     }
1112                     else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) )
1113                     {
1114                         bRet = sal_False;
1115                         break;
1116                     }
1117                 }
1118                 // run through
1119             case DataType::DECIMAL:
1120             case DataType::NUMERIC:
1121 
1122                 bRet = ::rtl::OUString(m_aValue.m_pString).toInt32() != 0;
1123                 break;
1124             case DataType::BIGINT:
1125                 if ( m_bSigned )
1126                     bRet = *(sal_Int64*)m_aValue.m_pValue != 0;
1127                 else
1128                     bRet = ::rtl::OUString(m_aValue.m_pString).toInt64() != 0;
1129                 break;
1130             case DataType::FLOAT:
1131                 bRet = *(float*)m_aValue.m_pValue != 0.0;
1132                 break;
1133             case DataType::DOUBLE:
1134             case DataType::REAL:
1135                 bRet = *(double*)m_aValue.m_pValue != 0.0;
1136                 break;
1137             case DataType::DATE:
1138             case DataType::TIME:
1139             case DataType::TIMESTAMP:
1140             case DataType::BINARY:
1141             case DataType::VARBINARY:
1142             case DataType::LONGVARBINARY:
1143                 OSL_ASSERT(!"getBool() for this type is not allowed!");
1144                 break;
1145             case DataType::BIT:
1146             case DataType::BOOLEAN:
1147                 bRet = m_aValue.m_bBool;
1148                 break;
1149             case DataType::TINYINT:
1150                 bRet = m_bSigned ? (m_aValue.m_nInt8  != 0) : (m_aValue.m_nInt16 != 0);
1151                 break;
1152             case DataType::SMALLINT:
1153                 bRet = m_bSigned ? (m_aValue.m_nInt16  != 0) : (m_aValue.m_nInt32 != 0);
1154                 break;
1155             case DataType::INTEGER:
1156                 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0));
1157                 break;
1158             default:
1159                 {
1160                     Any aValue = getAny();
1161                     aValue >>= bRet;
1162                     break;
1163                 }
1164         }
1165     }
1166     return bRet;
1167 }
1168 // -------------------------------------------------------------------------
getInt8() const1169 sal_Int8 ORowSetValue::getInt8()    const
1170 {
1171     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt8" );
1172 
1173 
1174     sal_Int8 nRet = 0;
1175     if(!m_bNull)
1176     {
1177         switch(getTypeKind())
1178         {
1179             case DataType::CHAR:
1180             case DataType::VARCHAR:
1181             case DataType::DECIMAL:
1182             case DataType::NUMERIC:
1183             case DataType::LONGVARCHAR:
1184                 nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1185                 break;
1186             case DataType::BIGINT:
1187                 if ( m_bSigned )
1188                     nRet = sal_Int8(*(sal_Int64*)m_aValue.m_pValue);
1189                 else
1190                     nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1191                 break;
1192             case DataType::FLOAT:
1193                 nRet = sal_Int8(*(float*)m_aValue.m_pValue);
1194                 break;
1195             case DataType::DOUBLE:
1196             case DataType::REAL:
1197                 nRet = sal_Int8(*(double*)m_aValue.m_pValue);
1198                 break;
1199             case DataType::DATE:
1200             case DataType::TIME:
1201             case DataType::TIMESTAMP:
1202             case DataType::BINARY:
1203             case DataType::VARBINARY:
1204             case DataType::LONGVARBINARY:
1205             case DataType::BLOB:
1206             case DataType::CLOB:
1207                 OSL_ASSERT(!"getInt8() for this type is not allowed!");
1208                 break;
1209             case DataType::BIT:
1210             case DataType::BOOLEAN:
1211                 nRet = m_aValue.m_bBool;
1212                 break;
1213             case DataType::TINYINT:
1214                 if ( m_bSigned )
1215                     nRet = m_aValue.m_nInt8;
1216                 else
1217                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1218                 break;
1219             case DataType::SMALLINT:
1220                 if ( m_bSigned )
1221                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1222                 else
1223                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1224                 break;
1225             case DataType::INTEGER:
1226                 if ( m_bSigned )
1227                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1228                 else
1229                     nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1230                 break;
1231             default:
1232                 {
1233                     Any aValue = getAny();
1234                     aValue >>= nRet;
1235                     break;
1236                 }
1237         }
1238     }
1239     return nRet;
1240 }
1241 // -------------------------------------------------------------------------
getInt16() const1242 sal_Int16 ORowSetValue::getInt16()  const
1243 {
1244     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt16" );
1245 
1246 
1247     sal_Int16 nRet = 0;
1248     if(!m_bNull)
1249     {
1250         switch(getTypeKind())
1251         {
1252             case DataType::CHAR:
1253             case DataType::VARCHAR:
1254             case DataType::DECIMAL:
1255             case DataType::NUMERIC:
1256             case DataType::LONGVARCHAR:
1257                 nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1258                 break;
1259             case DataType::BIGINT:
1260                 if ( m_bSigned )
1261                     nRet = sal_Int16(*(sal_Int64*)m_aValue.m_pValue);
1262                 else
1263                     nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1264                 break;
1265             case DataType::FLOAT:
1266                 nRet = sal_Int16(*(float*)m_aValue.m_pValue);
1267                 break;
1268             case DataType::DOUBLE:
1269             case DataType::REAL:
1270                 nRet = sal_Int16(*(double*)m_aValue.m_pValue);
1271                 break;
1272             case DataType::DATE:
1273             case DataType::TIME:
1274             case DataType::TIMESTAMP:
1275             case DataType::BINARY:
1276             case DataType::VARBINARY:
1277             case DataType::LONGVARBINARY:
1278             case DataType::BLOB:
1279             case DataType::CLOB:
1280                 OSL_ASSERT(!"getInt16() for this type is not allowed!");
1281                 break;
1282             case DataType::BIT:
1283             case DataType::BOOLEAN:
1284                 nRet = m_aValue.m_bBool;
1285                 break;
1286             case DataType::TINYINT:
1287                 if ( m_bSigned )
1288                     nRet = m_aValue.m_nInt8;
1289                 else
1290                     nRet = m_aValue.m_nInt16;
1291                 break;
1292             case DataType::SMALLINT:
1293                 if ( m_bSigned )
1294                     nRet = m_aValue.m_nInt16;
1295                 else
1296                     nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1297                 break;
1298             case DataType::INTEGER:
1299                 if ( m_bSigned )
1300                     nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1301                 else
1302                     nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1303                 break;
1304             default:
1305                 {
1306                     Any aValue = getAny();
1307                     aValue >>= nRet;
1308                     break;
1309                 }
1310         }
1311     }
1312     return nRet;
1313 }
1314 // -------------------------------------------------------------------------
getInt32() const1315 sal_Int32 ORowSetValue::getInt32()  const
1316 {
1317     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt32" );
1318     sal_Int32 nRet = 0;
1319     if(!m_bNull)
1320     {
1321         switch(getTypeKind())
1322         {
1323             case DataType::CHAR:
1324             case DataType::VARCHAR:
1325             case DataType::DECIMAL:
1326             case DataType::NUMERIC:
1327             case DataType::LONGVARCHAR:
1328                 nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1329                 break;
1330             case DataType::BIGINT:
1331                 if ( m_bSigned )
1332                     nRet = sal_Int32(*(sal_Int64*)m_aValue.m_pValue);
1333                 else
1334                     nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1335                 break;
1336             case DataType::FLOAT:
1337                 nRet = sal_Int32(*(float*)m_aValue.m_pValue);
1338                 break;
1339             case DataType::DOUBLE:
1340             case DataType::REAL:
1341                 nRet = sal_Int32(*(double*)m_aValue.m_pValue);
1342                 break;
1343             case DataType::DATE:
1344                 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1345                 break;
1346             case DataType::TIME:
1347             case DataType::TIMESTAMP:
1348             case DataType::BINARY:
1349             case DataType::VARBINARY:
1350             case DataType::LONGVARBINARY:
1351             case DataType::BLOB:
1352             case DataType::CLOB:
1353                 OSL_ASSERT(!"getInt32() for this type is not allowed!");
1354                 break;
1355             case DataType::BIT:
1356             case DataType::BOOLEAN:
1357                 nRet = m_aValue.m_bBool;
1358                 break;
1359             case DataType::TINYINT:
1360                 if ( m_bSigned )
1361                     nRet = m_aValue.m_nInt8;
1362                 else
1363                     nRet = m_aValue.m_nInt16;
1364                 break;
1365             case DataType::SMALLINT:
1366                 if ( m_bSigned )
1367                     nRet = m_aValue.m_nInt16;
1368                 else
1369                     nRet = m_aValue.m_nInt32;
1370                 break;
1371             case DataType::INTEGER:
1372                 if ( m_bSigned )
1373                     nRet = m_aValue.m_nInt32;
1374                 else
1375                     nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1376                 break;
1377             default:
1378                 {
1379                     Any aValue = getAny();
1380                     aValue >>= nRet;
1381                     break;
1382                 }
1383         }
1384     }
1385     return nRet;
1386 }
1387 // -------------------------------------------------------------------------
getLong() const1388 sal_Int64 ORowSetValue::getLong()   const
1389 {
1390     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getLong" );
1391     sal_Int64 nRet = 0;
1392     if(!m_bNull)
1393     {
1394         switch(getTypeKind())
1395         {
1396             case DataType::CHAR:
1397             case DataType::VARCHAR:
1398             case DataType::DECIMAL:
1399             case DataType::NUMERIC:
1400             case DataType::LONGVARCHAR:
1401                 nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1402                 break;
1403             case DataType::BIGINT:
1404                 if ( m_bSigned )
1405                     nRet = *(sal_Int64*)m_aValue.m_pValue;
1406                 else
1407                     nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1408                 break;
1409             case DataType::FLOAT:
1410                 nRet = sal_Int64(*(float*)m_aValue.m_pValue);
1411                 break;
1412             case DataType::DOUBLE:
1413             case DataType::REAL:
1414                 nRet = sal_Int64(*(double*)m_aValue.m_pValue);
1415                 break;
1416             case DataType::DATE:
1417                 nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1418                 break;
1419             case DataType::TIME:
1420             case DataType::TIMESTAMP:
1421             case DataType::BINARY:
1422             case DataType::VARBINARY:
1423             case DataType::LONGVARBINARY:
1424             case DataType::BLOB:
1425             case DataType::CLOB:
1426                 OSL_ASSERT(!"getInt32() for this type is not allowed!");
1427                 break;
1428             case DataType::BIT:
1429             case DataType::BOOLEAN:
1430                 nRet = m_aValue.m_bBool;
1431                 break;
1432             case DataType::TINYINT:
1433                 if ( m_bSigned )
1434                     nRet = m_aValue.m_nInt8;
1435                 else
1436                     nRet = m_aValue.m_nInt16;
1437                 break;
1438             case DataType::SMALLINT:
1439                 if ( m_bSigned )
1440                     nRet = m_aValue.m_nInt16;
1441                 else
1442                     nRet = m_aValue.m_nInt32;
1443                 break;
1444             case DataType::INTEGER:
1445                 if ( m_bSigned )
1446                     nRet = m_aValue.m_nInt32;
1447                 else
1448                     nRet = *(sal_Int64*)m_aValue.m_pValue;
1449                 break;
1450             default:
1451                 {
1452                     Any aValue = getAny();
1453                     aValue >>= nRet;
1454                     break;
1455                 }
1456         }
1457     }
1458     return nRet;
1459 }
1460 // -------------------------------------------------------------------------
getFloat() const1461 float ORowSetValue::getFloat()  const
1462 {
1463     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getFloat" );
1464     float nRet = 0;
1465     if(!m_bNull)
1466     {
1467         switch(getTypeKind())
1468         {
1469             case DataType::CHAR:
1470             case DataType::VARCHAR:
1471             case DataType::DECIMAL:
1472             case DataType::NUMERIC:
1473             case DataType::LONGVARCHAR:
1474                 nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1475                 break;
1476             case DataType::BIGINT:
1477                 if ( m_bSigned )
1478                     nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1479                 else
1480                     nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1481                 break;
1482             case DataType::FLOAT:
1483                 nRet = *(float*)m_aValue.m_pValue;
1484                 break;
1485             case DataType::DOUBLE:
1486             case DataType::REAL:
1487                 nRet = (float)*(double*)m_aValue.m_pValue;
1488                 break;
1489             case DataType::DATE:
1490                 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1491                 break;
1492             case DataType::TIME:
1493                 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1494                 break;
1495             case DataType::TIMESTAMP:
1496                 nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1497                 break;
1498             case DataType::BINARY:
1499             case DataType::VARBINARY:
1500             case DataType::LONGVARBINARY:
1501             case DataType::BLOB:
1502             case DataType::CLOB:
1503                 OSL_ASSERT(!"getDouble() for this type is not allowed!");
1504                 break;
1505             case DataType::BIT:
1506             case DataType::BOOLEAN:
1507                 nRet = m_aValue.m_bBool;
1508                 break;
1509             case DataType::TINYINT:
1510                 if ( m_bSigned )
1511                     nRet = m_aValue.m_nInt8;
1512                 else
1513                     nRet = m_aValue.m_nInt16;
1514                 break;
1515             case DataType::SMALLINT:
1516                 if ( m_bSigned )
1517                     nRet = m_aValue.m_nInt16;
1518                 else
1519                     nRet = (float)m_aValue.m_nInt32;
1520                 break;
1521             case DataType::INTEGER:
1522                 if ( m_bSigned )
1523                     nRet = (float)m_aValue.m_nInt32;
1524                 else
1525                     nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1526                 break;
1527             default:
1528                 {
1529                     Any aValue = getAny();
1530                     aValue >>= nRet;
1531                     break;
1532                 }
1533         }
1534     }
1535     return nRet;
1536 }
1537 // -------------------------------------------------------------------------
getDouble() const1538 double ORowSetValue::getDouble()    const
1539 {
1540     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDouble" );
1541 
1542 
1543     double nRet = 0;
1544     if(!m_bNull)
1545     {
1546         switch(getTypeKind())
1547         {
1548             case DataType::CHAR:
1549             case DataType::VARCHAR:
1550             case DataType::DECIMAL:
1551             case DataType::NUMERIC:
1552             case DataType::LONGVARCHAR:
1553                 nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1554                 break;
1555             case DataType::BIGINT:
1556                 if ( m_bSigned )
1557                     nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1558                 else
1559                     nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1560                 break;
1561             case DataType::FLOAT:
1562                 nRet = *(float*)m_aValue.m_pValue;
1563                 break;
1564             case DataType::DOUBLE:
1565             case DataType::REAL:
1566                 nRet = *(double*)m_aValue.m_pValue;
1567                 break;
1568             case DataType::DATE:
1569                 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1570                 break;
1571             case DataType::TIME:
1572                 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1573                 break;
1574             case DataType::TIMESTAMP:
1575                 nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1576                 break;
1577             case DataType::BINARY:
1578             case DataType::VARBINARY:
1579             case DataType::LONGVARBINARY:
1580             case DataType::BLOB:
1581             case DataType::CLOB:
1582                 OSL_ASSERT(!"getDouble() for this type is not allowed!");
1583                 break;
1584             case DataType::BIT:
1585             case DataType::BOOLEAN:
1586                 nRet = m_aValue.m_bBool;
1587                 break;
1588             case DataType::TINYINT:
1589                 if ( m_bSigned )
1590                     nRet = m_aValue.m_nInt8;
1591                 else
1592                     nRet = m_aValue.m_nInt16;
1593                 break;
1594             case DataType::SMALLINT:
1595                 if ( m_bSigned )
1596                     nRet = m_aValue.m_nInt16;
1597                 else
1598                     nRet = m_aValue.m_nInt32;
1599                 break;
1600             case DataType::INTEGER:
1601                 if ( m_bSigned )
1602                     nRet = m_aValue.m_nInt32;
1603                 else
1604                     nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1605                 break;
1606             default:
1607                 {
1608                     Any aValue = getAny();
1609                     aValue >>= nRet;
1610                     break;
1611                 }
1612         }
1613     }
1614     return nRet;
1615 }
1616 // -------------------------------------------------------------------------
setFromDouble(const double & _rVal,sal_Int32 _nDatatype)1617 void ORowSetValue::setFromDouble(const double& _rVal,sal_Int32 _nDatatype)
1618 {
1619     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setFromDouble" );
1620     free();
1621 
1622     m_bNull = sal_False;
1623     switch(_nDatatype)
1624     {
1625         case DataType::CHAR:
1626         case DataType::VARCHAR:
1627         case DataType::DECIMAL:
1628         case DataType::NUMERIC:
1629         case DataType::LONGVARCHAR:
1630             {
1631                 ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1632                 m_aValue.m_pString = aVal.pData;
1633                 rtl_uString_acquire(m_aValue.m_pString);
1634             }
1635             break;
1636         case DataType::BIGINT:
1637             if ( m_bSigned )
1638             {
1639                 m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1640                 TRACE_ALLOC( sal_Int64 )
1641             }
1642             else
1643             {
1644                 ::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1645                 m_aValue.m_pString = aVal.pData;
1646                 rtl_uString_acquire(m_aValue.m_pString);
1647             }
1648             break;
1649         case DataType::FLOAT:
1650             m_aValue.m_pValue = new float((float)_rVal);
1651             TRACE_ALLOC( float )
1652             break;
1653         case DataType::DOUBLE:
1654         case DataType::REAL:
1655             m_aValue.m_pValue = new double(_rVal);
1656             TRACE_ALLOC( double )
1657             break;
1658         case DataType::DATE:
1659             m_aValue.m_pValue = new Date(dbtools::DBTypeConversion::toDate(_rVal));
1660             TRACE_ALLOC( Date )
1661             break;
1662         case DataType::TIME:
1663             m_aValue.m_pValue = new Time(dbtools::DBTypeConversion::toTime(_rVal));
1664             TRACE_ALLOC( Time )
1665             break;
1666         case DataType::TIMESTAMP:
1667             m_aValue.m_pValue = new DateTime(dbtools::DBTypeConversion::toDateTime(_rVal));
1668             TRACE_ALLOC( DateTime )
1669             break;
1670         case DataType::BINARY:
1671         case DataType::VARBINARY:
1672         case DataType::LONGVARBINARY:
1673         case DataType::BLOB:
1674         case DataType::CLOB:
1675             OSL_ASSERT(!"setFromDouble() for this type is not allowed!");
1676             break;
1677         case DataType::BIT:
1678         case DataType::BOOLEAN:
1679             m_aValue.m_bBool = _rVal != 0.0;
1680             break;
1681         case DataType::TINYINT:
1682             if ( m_bSigned )
1683                 m_aValue.m_nInt8 = sal_Int8(_rVal);
1684             else
1685                 m_aValue.m_nInt16 = sal_Int16(_rVal);
1686             break;
1687         case DataType::SMALLINT:
1688             if ( m_bSigned )
1689                 m_aValue.m_nInt16 = sal_Int16(_rVal);
1690             else
1691                 m_aValue.m_nInt32 = sal_Int32(_rVal);
1692             break;
1693         case DataType::INTEGER:
1694             if ( m_bSigned )
1695                 m_aValue.m_nInt32 = sal_Int32(_rVal);
1696             else
1697             {
1698                 m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1699                 TRACE_ALLOC( sal_Int64 )
1700             }
1701             break;
1702             default:
1703                 {
1704                     m_aValue.m_pValue = new Any(_rVal);
1705                     break;
1706                 }
1707     }
1708     m_eTypeKind = _nDatatype;
1709 }
1710 // -----------------------------------------------------------------------------
getSequence() const1711 Sequence<sal_Int8>  ORowSetValue::getSequence() const
1712 {
1713     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getSequence" );
1714     Sequence<sal_Int8> aSeq;
1715     if (!m_bNull)
1716     {
1717         switch(m_eTypeKind)
1718         {
1719             case DataType::OBJECT:
1720             case DataType::CLOB:
1721             case DataType::BLOB:
1722             {
1723                 Reference<XInputStream> xStream;
1724                 const Any aValue = makeAny();
1725                 if(aValue.hasValue())
1726                 {
1727                     Reference<XBlob> xBlob(aValue,UNO_QUERY);
1728                     if ( xBlob.is() )
1729                         xStream = xBlob->getBinaryStream();
1730                     else
1731                     {
1732                         Reference<XClob> xClob(aValue,UNO_QUERY);
1733                         if ( xClob.is() )
1734                             xStream = xClob->getCharacterStream();
1735                     }
1736                     if(xStream.is())
1737                     {
1738                         const sal_uInt32    nBytesToRead = 65535;
1739                         sal_uInt32          nRead;
1740 
1741                         do
1742                         {
1743                             ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
1744 
1745                             nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1746 
1747                             if( nRead )
1748                             {
1749                                 const sal_uInt32 nOldLength = aSeq.getLength();
1750                                 aSeq.realloc( nOldLength + nRead );
1751                                 rtl_copyMemory( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1752                             }
1753                         }
1754                         while( nBytesToRead == nRead );
1755                         xStream->closeInput();
1756                     }
1757                 }
1758             }
1759             break;
1760             case DataType::VARCHAR:
1761             case DataType::LONGVARCHAR:
1762                 {
1763                     ::rtl::OUString sVal(m_aValue.m_pString);
1764                     aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sVal.getStr()),sizeof(sal_Unicode)*sVal.getLength());
1765                 }
1766                 break;
1767             case DataType::BINARY:
1768             case DataType::VARBINARY:
1769             case DataType::LONGVARBINARY:
1770                 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1771                 break;
1772             default:
1773                 {
1774                     Any aValue = getAny();
1775                     aValue >>= aSeq;
1776                     break;
1777                 }
1778         }
1779     }
1780     return aSeq;
1781 
1782 }
1783 // -----------------------------------------------------------------------------
getDate() const1784 ::com::sun::star::util::Date ORowSetValue::getDate() const
1785 {
1786     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDate" );
1787     ::com::sun::star::util::Date aValue;
1788     if(!m_bNull)
1789     {
1790         switch(m_eTypeKind)
1791         {
1792             case DataType::CHAR:
1793             case DataType::VARCHAR:
1794             case DataType::LONGVARCHAR:
1795                 aValue = DBTypeConversion::toDate(getString());
1796                 break;
1797             case DataType::DECIMAL:
1798             case DataType::NUMERIC:
1799             case DataType::FLOAT:
1800             case DataType::DOUBLE:
1801             case DataType::REAL:
1802                 aValue = DBTypeConversion::toDate((double)*this);
1803                 break;
1804 
1805             case DataType::DATE:
1806                 aValue = *static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1807                 break;
1808             case DataType::TIMESTAMP:
1809                 {
1810                     ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1811                     aValue.Day      = pDateTime->Day;
1812                     aValue.Month    = pDateTime->Month;
1813                     aValue.Year     = pDateTime->Year;
1814                 }
1815                 break;
1816             case DataType::BIT:
1817             case DataType::BOOLEAN:
1818             case DataType::TINYINT:
1819             case DataType::SMALLINT:
1820             case DataType::INTEGER:
1821             case DataType::BIGINT:
1822                 aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1823                 break;
1824 
1825             case DataType::BLOB:
1826             case DataType::CLOB:
1827             case DataType::OBJECT:
1828             default:
1829                 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1830                 // NO break!
1831 
1832             case DataType::BINARY:
1833             case DataType::VARBINARY:
1834             case DataType::LONGVARBINARY:
1835             case DataType::TIME:
1836                 aValue = DBTypeConversion::toDate( (double)0 );
1837                 break;
1838         }
1839     }
1840     return aValue;
1841 }
1842 // -----------------------------------------------------------------------------
getTime() const1843 ::com::sun::star::util::Time ORowSetValue::getTime()        const
1844 {
1845     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getTime" );
1846     ::com::sun::star::util::Time aValue;
1847     if(!m_bNull)
1848     {
1849         switch(m_eTypeKind)
1850         {
1851             case DataType::CHAR:
1852             case DataType::VARCHAR:
1853             case DataType::LONGVARCHAR:
1854                 aValue = DBTypeConversion::toTime(getString());
1855                 break;
1856             case DataType::DECIMAL:
1857             case DataType::NUMERIC:
1858                 aValue = DBTypeConversion::toTime((double)*this);
1859                 break;
1860             case DataType::FLOAT:
1861             case DataType::DOUBLE:
1862             case DataType::REAL:
1863                 aValue = DBTypeConversion::toTime((double)*this);
1864                 break;
1865             case DataType::TIMESTAMP:
1866                 {
1867                     ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1868                     aValue.HundredthSeconds = pDateTime->HundredthSeconds;
1869                     aValue.Seconds          = pDateTime->Seconds;
1870                     aValue.Minutes          = pDateTime->Minutes;
1871                     aValue.Hours            = pDateTime->Hours;
1872                 }
1873                 break;
1874             case DataType::TIME:
1875                 aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1876                 break;
1877             default:
1878                 {
1879                     Any aAnyValue = getAny();
1880                     aAnyValue >>= aValue;
1881                     break;
1882                 }
1883         }
1884     }
1885     return aValue;
1886 }
1887 // -----------------------------------------------------------------------------
getDateTime() const1888 ::com::sun::star::util::DateTime ORowSetValue::getDateTime()    const
1889 {
1890     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDateTime" );
1891     ::com::sun::star::util::DateTime aValue;
1892     if(!m_bNull)
1893     {
1894         switch(m_eTypeKind)
1895         {
1896             case DataType::CHAR:
1897             case DataType::VARCHAR:
1898             case DataType::LONGVARCHAR:
1899                 aValue = DBTypeConversion::toDateTime(getString());
1900                 break;
1901             case DataType::DECIMAL:
1902             case DataType::NUMERIC:
1903                 aValue = DBTypeConversion::toDateTime((double)*this);
1904                 break;
1905             case DataType::FLOAT:
1906             case DataType::DOUBLE:
1907             case DataType::REAL:
1908                 aValue = DBTypeConversion::toDateTime((double)*this);
1909                 break;
1910             case DataType::DATE:
1911                 {
1912                     ::com::sun::star::util::Date* pDate = static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1913                     aValue.Day      = pDate->Day;
1914                     aValue.Month    = pDate->Month;
1915                     aValue.Year     = pDate->Year;
1916                 }
1917                 break;
1918             case DataType::TIME:
1919                 {
1920                     ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1921                     aValue.HundredthSeconds = pTime->HundredthSeconds;
1922                     aValue.Seconds          = pTime->Seconds;
1923                     aValue.Minutes          = pTime->Minutes;
1924                     aValue.Hours            = pTime->Hours;
1925                 }
1926                 break;
1927             case DataType::TIMESTAMP:
1928                 aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1929                 break;
1930             default:
1931                 {
1932                     Any aAnyValue = getAny();
1933                     aAnyValue >>= aValue;
1934                     break;
1935                 }
1936         }
1937     }
1938     return aValue;
1939 }
1940 // -----------------------------------------------------------------------------
setSigned(sal_Bool _bMod)1941 void ORowSetValue::setSigned(sal_Bool _bMod)
1942 {
1943     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setSigned" );
1944     if ( m_bSigned != _bMod )
1945     {
1946         m_bSigned = _bMod;
1947         if ( !m_bNull )
1948         {
1949             sal_Int32 nType = m_eTypeKind;
1950             switch(m_eTypeKind)
1951             {
1952                 case DataType::BIGINT:
1953                     if ( m_bSigned ) // now we are signed, so we were unsigned and need to call getString()
1954                     {
1955                         m_bSigned = !m_bSigned;
1956                         const ::rtl::OUString sValue = getString();
1957                         free();
1958                         m_bSigned = !m_bSigned;
1959                         (*this) = sValue;
1960                     }
1961                     else
1962                     {
1963                         m_bSigned = !m_bSigned;
1964                         const sal_Int64 nValue = getLong();
1965                         free();
1966                         m_bSigned = !m_bSigned;
1967                         (*this) = nValue;
1968                     }
1969                     break;
1970                 case DataType::TINYINT:
1971                     if ( m_bSigned )
1972                         (*this) = getInt8();
1973                     else
1974                     {
1975                         m_bSigned = !m_bSigned;
1976                         (*this) = getInt16();
1977                         m_bSigned = !m_bSigned;
1978                     }
1979                     break;
1980                 case DataType::SMALLINT:
1981                     if ( m_bSigned )
1982                         (*this) = getInt16();
1983                     else
1984                     {
1985                         m_bSigned = !m_bSigned;
1986                         (*this) = getInt32();
1987                         m_bSigned = !m_bSigned;
1988                     }
1989                     break;
1990                 case DataType::INTEGER:
1991                     if ( m_bSigned )
1992                         (*this) = getInt32();
1993                     else
1994                     {
1995                         m_bSigned = !m_bSigned;
1996                         (*this) = getLong();
1997                         m_bSigned = !m_bSigned;
1998                     }
1999                     break;
2000             }
2001             m_eTypeKind = nType;
2002         }
2003     }
2004 }
2005 
2006 // -----------------------------------------------------------------------------
2007 namespace detail
2008 {
2009     class SAL_NO_VTABLE IValueSource
2010     {
2011     public:
2012         virtual ::rtl::OUString             getString() const = 0;
2013         virtual sal_Bool                    getBoolean() const = 0;
2014         virtual sal_Int8                    getByte() const = 0;
2015         virtual sal_Int16                   getShort() const = 0;
2016         virtual sal_Int32                   getInt() const = 0;
2017         virtual sal_Int64                   getLong() const = 0;
2018         virtual float                       getFloat() const = 0;
2019         virtual double                      getDouble() const = 0;
2020         virtual Date                        getDate() const = 0;
2021         virtual Time                        getTime() const = 0;
2022         virtual DateTime                    getTimestamp() const = 0;
2023         virtual Sequence< sal_Int8 >        getBytes() const = 0;
2024         virtual Reference< XInputStream >   getBinaryStream() const = 0;
2025         virtual Reference< XInputStream >   getCharacterStream() const = 0;
2026         virtual Reference< XBlob >          getBlob() const = 0;
2027         virtual Reference< XClob >          getClob() const = 0;
2028         virtual Any                         getObject() const = 0;
2029         virtual sal_Bool                    wasNull() const = 0;
2030 
~IValueSource()2031         virtual ~IValueSource() { }
2032     };
2033 
2034     class RowValue : public IValueSource
2035     {
2036     public:
RowValue(const Reference<XRow> & _xRow,const sal_Int32 _nPos)2037         RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2038             :m_xRow( _xRow )
2039             ,m_nPos( _nPos )
2040         {
2041         }
2042 
2043         // IValueSource
getString() const2044         virtual ::rtl::OUString             getString() const           { return m_xRow->getString( m_nPos ); };
getBoolean() const2045         virtual sal_Bool                    getBoolean() const          { return m_xRow->getBoolean( m_nPos ); };
getByte() const2046         virtual sal_Int8                    getByte() const             { return m_xRow->getByte( m_nPos ); };
getShort() const2047         virtual sal_Int16                   getShort() const            { return m_xRow->getShort( m_nPos ); }
getInt() const2048         virtual sal_Int32                   getInt() const              { return m_xRow->getInt( m_nPos ); }
getLong() const2049         virtual sal_Int64                   getLong() const             { return m_xRow->getLong( m_nPos ); }
getFloat() const2050         virtual float                       getFloat() const            { return m_xRow->getFloat( m_nPos ); };
getDouble() const2051         virtual double                      getDouble() const           { return m_xRow->getDouble( m_nPos ); };
getDate() const2052         virtual Date                        getDate() const             { return m_xRow->getDate( m_nPos ); };
getTime() const2053         virtual Time                        getTime() const             { return m_xRow->getTime( m_nPos ); };
getTimestamp() const2054         virtual DateTime                    getTimestamp() const        { return m_xRow->getTimestamp( m_nPos ); };
getBytes() const2055         virtual Sequence< sal_Int8 >        getBytes() const            { return m_xRow->getBytes( m_nPos ); };
getBinaryStream() const2056         virtual Reference< XInputStream >   getBinaryStream() const     { return m_xRow->getBinaryStream( m_nPos ); };
getCharacterStream() const2057         virtual Reference< XInputStream >   getCharacterStream() const  { return m_xRow->getCharacterStream( m_nPos ); };
getBlob() const2058         virtual Reference< XBlob >          getBlob() const             { return m_xRow->getBlob( m_nPos ); };
getClob() const2059         virtual Reference< XClob >          getClob() const             { return m_xRow->getClob( m_nPos ); };
getObject() const2060         virtual Any                         getObject() const           { return m_xRow->getObject( m_nPos ,NULL); };
wasNull() const2061         virtual sal_Bool                    wasNull() const             { return m_xRow->wasNull( ); };
2062 
2063     private:
2064         const Reference< XRow > m_xRow;
2065         const sal_Int32         m_nPos;
2066     };
2067 
2068     class ColumnValue : public IValueSource
2069     {
2070     public:
ColumnValue(const Reference<XColumn> & _rxColumn)2071         ColumnValue( const Reference< XColumn >& _rxColumn )
2072             :m_xColumn( _rxColumn )
2073         {
2074         }
2075 
2076         // IValueSource
getString() const2077         virtual ::rtl::OUString             getString() const           { return m_xColumn->getString(); };
getBoolean() const2078         virtual sal_Bool                    getBoolean() const          { return m_xColumn->getBoolean(); };
getByte() const2079         virtual sal_Int8                    getByte() const             { return m_xColumn->getByte(); };
getShort() const2080         virtual sal_Int16                   getShort() const            { return m_xColumn->getShort(); }
getInt() const2081         virtual sal_Int32                   getInt() const              { return m_xColumn->getInt(); }
getLong() const2082         virtual sal_Int64                   getLong() const             { return m_xColumn->getLong(); }
getFloat() const2083         virtual float                       getFloat() const            { return m_xColumn->getFloat(); };
getDouble() const2084         virtual double                      getDouble() const           { return m_xColumn->getDouble(); };
getDate() const2085         virtual Date                        getDate() const             { return m_xColumn->getDate(); };
getTime() const2086         virtual Time                        getTime() const             { return m_xColumn->getTime(); };
getTimestamp() const2087         virtual DateTime                    getTimestamp() const        { return m_xColumn->getTimestamp(); };
getBytes() const2088         virtual Sequence< sal_Int8 >        getBytes() const            { return m_xColumn->getBytes(); };
getBinaryStream() const2089         virtual Reference< XInputStream >   getBinaryStream() const     { return m_xColumn->getBinaryStream(); };
getCharacterStream() const2090         virtual Reference< XInputStream >   getCharacterStream() const  { return m_xColumn->getCharacterStream(); };
getBlob() const2091         virtual Reference< XBlob >          getBlob() const             { return m_xColumn->getBlob(); };
getClob() const2092         virtual Reference< XClob >          getClob() const             { return m_xColumn->getClob(); };
getObject() const2093         virtual Any                         getObject() const           { return m_xColumn->getObject( NULL ); };
wasNull() const2094         virtual sal_Bool                    wasNull() const             { return m_xColumn->wasNull( ); };
2095 
2096     private:
2097         const Reference< XColumn >  m_xColumn;
2098     };
2099 }
2100 
2101 // -----------------------------------------------------------------------------
fill(const sal_Int32 _nType,const Reference<XColumn> & _rxColumn)2102 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2103 {
2104     detail::ColumnValue aColumnValue( _rxColumn );
2105     impl_fill( _nType, sal_True, aColumnValue );
2106 }
2107 
2108 // -----------------------------------------------------------------------------
fill(sal_Int32 _nPos,sal_Int32 _nType,sal_Bool _bNullable,const Reference<XRow> & _xRow)2109 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, sal_Bool  _bNullable, const Reference< XRow>& _xRow )
2110 {
2111     detail::RowValue aRowValue( _xRow, _nPos );
2112     impl_fill( _nType, _bNullable, aRowValue );
2113 }
2114 
2115 // -----------------------------------------------------------------------------
fill(sal_Int32 _nPos,sal_Int32 _nType,const::com::sun::star::uno::Reference<::com::sun::star::sdbc::XRow> & _xRow)2116 void ORowSetValue::fill(sal_Int32 _nPos,
2117                      sal_Int32 _nType,
2118                      const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
2119 {
2120     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (1)" );
2121     fill(_nPos,_nType,sal_True,_xRow);
2122 }
2123 
2124 // -----------------------------------------------------------------------------
impl_fill(const sal_Int32 _nType,sal_Bool _bNullable,const detail::IValueSource & _rValueSource)2125 void ORowSetValue::impl_fill( const sal_Int32 _nType, sal_Bool _bNullable, const detail::IValueSource& _rValueSource )
2126 
2127 {
2128     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (2)" );
2129     sal_Bool bReadData = sal_True;
2130     switch(_nType)
2131     {
2132     case DataType::CHAR:
2133     case DataType::VARCHAR:
2134     case DataType::DECIMAL:
2135     case DataType::NUMERIC:
2136     case DataType::LONGVARCHAR:
2137         (*this) = _rValueSource.getString();
2138         break;
2139     case DataType::BIGINT:
2140         if ( isSigned() )
2141             (*this) = _rValueSource.getLong();
2142         else
2143             (*this) = _rValueSource.getString();
2144         break;
2145     case DataType::FLOAT:
2146         (*this) = _rValueSource.getFloat();
2147         break;
2148     case DataType::DOUBLE:
2149     case DataType::REAL:
2150         (*this) = _rValueSource.getDouble();
2151         break;
2152     case DataType::DATE:
2153         (*this) = _rValueSource.getDate();
2154         break;
2155     case DataType::TIME:
2156         (*this) = _rValueSource.getTime();
2157         break;
2158     case DataType::TIMESTAMP:
2159         (*this) = _rValueSource.getTimestamp();
2160         break;
2161     case DataType::BINARY:
2162     case DataType::VARBINARY:
2163     case DataType::LONGVARBINARY:
2164         (*this) = _rValueSource.getBytes();
2165         break;
2166     case DataType::BIT:
2167     case DataType::BOOLEAN:
2168         (*this) = _rValueSource.getBoolean();
2169         break;
2170     case DataType::TINYINT:
2171         if ( isSigned() )
2172             (*this) = _rValueSource.getByte();
2173         else
2174             (*this) = _rValueSource.getShort();
2175         break;
2176     case DataType::SMALLINT:
2177         if ( isSigned() )
2178             (*this) = _rValueSource.getShort();
2179         else
2180             (*this) = _rValueSource.getInt();
2181         break;
2182     case DataType::INTEGER:
2183         if ( isSigned() )
2184             (*this) = _rValueSource.getInt();
2185         else
2186             (*this) = _rValueSource.getLong();
2187         break;
2188     case DataType::CLOB:
2189         (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob());
2190         setTypeKind(DataType::CLOB);
2191         break;
2192     case DataType::BLOB:
2193         (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob());
2194         setTypeKind(DataType::BLOB);
2195         break;
2196     case DataType::OTHER:
2197         (*this) = _rValueSource.getObject();
2198         setTypeKind(DataType::OTHER);
2199         break;
2200     default:
2201         OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" );
2202         (*this) = _rValueSource.getObject();
2203         break;
2204     }
2205     if ( bReadData && _bNullable && _rValueSource.wasNull() )
2206         setNull();
2207     setTypeKind(_nType);
2208 }
2209 // -----------------------------------------------------------------------------
fill(const Any & _rValue)2210 void ORowSetValue::fill(const Any& _rValue)
2211 {
2212     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (3)" );
2213     switch (_rValue.getValueType().getTypeClass())
2214     {
2215         case TypeClass_VOID:
2216             setNull();
2217             break;
2218         case TypeClass_BOOLEAN:
2219         {
2220             sal_Bool bValue( sal_False );
2221             _rValue >>= bValue;
2222             (*this) = bValue;
2223             break;
2224         }
2225         case TypeClass_CHAR:
2226         {
2227             sal_Unicode aDummy(0);
2228             _rValue >>= aDummy;
2229             (*this) = ::rtl::OUString(aDummy);
2230             break;
2231         }
2232         case TypeClass_STRING:
2233         {
2234             ::rtl::OUString sDummy;
2235             _rValue >>= sDummy;
2236             (*this) = sDummy;
2237             break;
2238         }
2239         case TypeClass_FLOAT:
2240         {
2241             float aDummy(0.0);
2242             _rValue >>= aDummy;
2243             (*this) = aDummy;
2244             break;
2245         }
2246         case TypeClass_DOUBLE:
2247         {
2248             double aDummy(0.0);
2249             _rValue >>= aDummy;
2250             (*this) = aDummy;
2251             break;
2252         }
2253         case TypeClass_BYTE:
2254         {
2255             sal_Int8 aDummy(0);
2256             _rValue >>= aDummy;
2257             (*this) = aDummy;
2258             break;
2259         }
2260         case TypeClass_SHORT:
2261         {
2262             sal_Int16 aDummy(0);
2263             _rValue >>= aDummy;
2264             (*this) = aDummy;
2265             break;
2266         }
2267         case TypeClass_LONG:
2268         {
2269             sal_Int32 aDummy(0);
2270             _rValue >>= aDummy;
2271             (*this) = aDummy;
2272             break;
2273         }
2274         case TypeClass_UNSIGNED_SHORT:
2275         {
2276             sal_uInt16 nValue(0);
2277             _rValue >>= nValue;
2278             (*this) = static_cast<sal_Int32>(nValue);
2279             setSigned(sal_False);
2280             break;
2281         }
2282         case TypeClass_HYPER:
2283         {
2284             sal_Int64 nValue(0);
2285             _rValue >>= nValue;
2286             (*this) = nValue;
2287             break;
2288         }
2289         case TypeClass_UNSIGNED_HYPER:
2290         {
2291             sal_uInt64 nValue(0);
2292             _rValue >>= nValue;
2293             (*this) = static_cast<sal_Int64>(nValue);
2294             setSigned(sal_False);
2295             break;
2296         }
2297         case TypeClass_UNSIGNED_LONG:
2298         {
2299             sal_uInt32 nValue(0);
2300             _rValue >>= nValue;
2301             (*this) = static_cast<sal_Int64>(nValue);
2302             setSigned(sal_False);
2303             break;
2304         }
2305         case TypeClass_ENUM:
2306         {
2307             sal_Int32 enumValue( 0 );
2308             ::cppu::enum2int( enumValue, _rValue );
2309             (*this) = enumValue;
2310         }
2311         break;
2312 
2313         case TypeClass_SEQUENCE:
2314         {
2315             Sequence<sal_Int8> aDummy;
2316             if ( _rValue >>= aDummy )
2317                 (*this) = aDummy;
2318             else
2319                 OSL_ENSURE( false, "ORowSetValue::fill: unsupported sequence type!" );
2320             break;
2321         }
2322 
2323         case TypeClass_STRUCT:
2324         {
2325             ::com::sun::star::util::Date aDate;
2326             ::com::sun::star::util::Time aTime;
2327             ::com::sun::star::util::DateTime aDateTime;
2328             if ( _rValue >>= aDate )
2329             {
2330                 (*this) = aDate;
2331             }
2332             else if ( _rValue >>= aTime )
2333             {
2334                 (*this) = aTime;
2335             }
2336             else if ( _rValue >>= aDateTime )
2337             {
2338                 (*this) = aDateTime;
2339             }
2340             else
2341                 OSL_ENSURE( false, "ORowSetValue::fill: unsupported structure!" );
2342 
2343             break;
2344         }
2345         case TypeClass_INTERFACE:
2346             {
2347                 Reference< XClob > xClob;
2348                 if ( _rValue >>= xClob )
2349                 {
2350                     (*this) = _rValue;
2351                     setTypeKind(DataType::CLOB);
2352                 }
2353                 else
2354                 {
2355                     Reference< XBlob > xBlob;
2356                     if ( _rValue >>= xBlob )
2357                     {
2358                         (*this) = _rValue;
2359                         setTypeKind(DataType::BLOB);
2360                     }
2361                     else
2362                     {
2363                         (*this) = _rValue;
2364                     }
2365                 }
2366             }
2367             break;
2368 
2369         default:
2370             OSL_ENSURE(0,"Unknown type");
2371             break;
2372     }
2373 }
2374 
2375 }   // namespace connectivity
2376