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