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_eTypeKind != _rRH.m_eTypeKind )
791     {
792         switch(m_eTypeKind)
793         {
794             case DataType::FLOAT:
795             case DataType::DOUBLE:
796             case DataType::REAL:
797                 return getDouble() == _rRH.getDouble();
798             default:
799                 switch(_rRH.m_eTypeKind)
800                 {
801                     case DataType::FLOAT:
802                     case DataType::DOUBLE:
803                     case DataType::REAL:
804                             return getDouble() == _rRH.getDouble();
805                     default:
806                             break;
807                 }
808                 break;
809             }
810         return false;
811     }
812     if ( m_bNull != _rRH.isNull() )
813             return false;
814 	if(m_bNull && _rRH.isNull())
815 		return true;
816 
817 	bool bRet = false;
818 	OSL_ENSURE(!m_bNull,"SHould not be null!");
819 	switch(m_eTypeKind)
820 	{
821 		case DataType::VARCHAR:
822 		case DataType::CHAR:
823 		case DataType::LONGVARCHAR:
824 		{
825 			::rtl::OUString aVal1(m_aValue.m_pString);
826 			::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
827 			return aVal1 == aVal2;
828 		}
829 		default:
830 			if ( m_bSigned != _rRH.m_bSigned )
831 				return false;
832 			break;
833 	}
834 
835 	switch(m_eTypeKind)
836 	{
837 		case DataType::DECIMAL:
838 		case DataType::NUMERIC:
839 			{
840 				::rtl::OUString aVal1(m_aValue.m_pString);
841 				::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
842 				bRet = aVal1 == aVal2;
843 			}
844 			break;
845 		case DataType::FLOAT:
846 			bRet = *(float*)m_aValue.m_pValue == *(float*)_rRH.m_aValue.m_pValue;
847 			break;
848 		case DataType::DOUBLE:
849 		case DataType::REAL:
850 			bRet = *(double*)m_aValue.m_pValue == *(double*)_rRH.m_aValue.m_pValue;
851 			break;
852 		case DataType::TINYINT:
853 			bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16);
854 			break;
855 		case DataType::SMALLINT:
856 			bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32);
857 			break;
858 		case DataType::INTEGER:
859 			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);
860 			break;
861 		case DataType::BIGINT:
862 			if ( m_bSigned )
863 				bRet = *(sal_Int64*)m_aValue.m_pValue == *(sal_Int64*)_rRH.m_aValue.m_pValue;
864 			else
865 			{
866 				::rtl::OUString aVal1(m_aValue.m_pString);
867 				::rtl::OUString aVal2(_rRH.m_aValue.m_pString);
868 				bRet = aVal1 == aVal2;
869 			}
870 			break;
871 		case DataType::BIT:
872 		case DataType::BOOLEAN:
873 			bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
874 			break;
875 		case DataType::DATE:
876 			bRet = *(Date*)m_aValue.m_pValue == *(Date*)_rRH.m_aValue.m_pValue;
877 			break;
878 		case DataType::TIME:
879 			bRet = *(Time*)m_aValue.m_pValue == *(Time*)_rRH.m_aValue.m_pValue;
880 			break;
881 		case DataType::TIMESTAMP:
882 			bRet = *(DateTime*)m_aValue.m_pValue == *(DateTime*)_rRH.m_aValue.m_pValue;
883 			break;
884 		case DataType::BINARY:
885 		case DataType::VARBINARY:
886 		case DataType::LONGVARBINARY:
887 			bRet = false;
888 			break;
889 		case DataType::BLOB:
890 		case DataType::CLOB:
891 		case DataType::OBJECT:
892 		case DataType::OTHER:
893 			bRet = false;
894 			break;
895 		default:
896             bRet = false;
897 			OSL_ENSURE(0,"ORowSetValue::operator==(): UNSPUPPORTED TYPE!");
898             break;
899 	}
900 	return bRet;
901 }
902 // -------------------------------------------------------------------------
903 Any ORowSetValue::makeAny() const
904 {
905     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::makeAny" );
906 	Any rValue;
907 	if(isBound() && !isNull())
908 	{
909 		switch(getTypeKind())
910 		{
911 			case DataType::CHAR:
912 			case DataType::VARCHAR:
913 			case DataType::DECIMAL:
914 			case DataType::NUMERIC:
915 			case DataType::LONGVARCHAR:
916 				OSL_ENSURE(m_aValue.m_pString,"Value is null!");
917 				rValue <<= (::rtl::OUString)m_aValue.m_pString;
918 				break;
919 			case DataType::BIGINT:
920 				if ( m_bSigned )
921 				{
922 					OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
923 					rValue <<= *(sal_Int64*)m_aValue.m_pValue;
924 				}
925 				else
926 				{
927 					OSL_ENSURE(m_aValue.m_pString,"Value is null!");
928 					rValue <<= (::rtl::OUString)m_aValue.m_pString;
929 				}
930 				break;
931 			case DataType::FLOAT:
932 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
933 				rValue <<= *(float*)m_aValue.m_pValue;
934 				break;
935 			case DataType::DOUBLE:
936 			case DataType::REAL:
937 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
938 				rValue <<= *(double*)m_aValue.m_pValue;
939 				break;
940 			case DataType::DATE:
941 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
942 				rValue <<= *(Date*)m_aValue.m_pValue;
943 				break;
944 			case DataType::TIME:
945 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
946 				rValue <<= *(Time*)m_aValue.m_pValue;
947 				break;
948 			case DataType::TIMESTAMP:
949 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
950 				rValue <<= *(DateTime*)m_aValue.m_pValue;
951 				break;
952 			case DataType::BINARY:
953 			case DataType::VARBINARY:
954 			case DataType::LONGVARBINARY:
955 				OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
956 				rValue <<= *(Sequence<sal_Int8>*)m_aValue.m_pValue;
957 				break;
958 			case DataType::BLOB:
959 			case DataType::CLOB:
960 			case DataType::OBJECT:
961 			case DataType::OTHER:
962 				rValue = getAny();
963 				break;
964 			case DataType::BIT:
965 			case DataType::BOOLEAN:
966 				rValue.setValue( &m_aValue.m_bBool, ::getCppuBooleanType() );
967 				break;
968 			case DataType::TINYINT:
969 				if ( m_bSigned )
970 					rValue <<= m_aValue.m_nInt8;
971 				else
972 					rValue <<= m_aValue.m_nInt16;
973 				break;
974 			case DataType::SMALLINT:
975 				if ( m_bSigned )
976 					rValue <<= m_aValue.m_nInt16;
977 				else
978 					rValue <<= m_aValue.m_nInt32;
979 				break;
980 			case DataType::INTEGER:
981 				if ( m_bSigned )
982 					rValue <<= m_aValue.m_nInt32;
983 				else
984 				{
985 					OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
986 					rValue <<= *(sal_Int64*)m_aValue.m_pValue;
987 				}
988 				break;
989 			default:
990 				OSL_ENSURE(0,"ORowSetValue::makeAny(): UNSPUPPORTED TYPE!");
991                 rValue = getAny();
992 				break;
993 		}
994 	}
995 	return rValue;
996 }
997 // -------------------------------------------------------------------------
998 ::rtl::OUString ORowSetValue::getString( ) const
999 {
1000     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getString" );
1001 	::rtl::OUString aRet;
1002 	if(!m_bNull)
1003 	{
1004 		switch(getTypeKind())
1005 		{
1006 			case DataType::CHAR:
1007 			case DataType::VARCHAR:
1008 			case DataType::DECIMAL:
1009 			case DataType::NUMERIC:
1010 			case DataType::LONGVARCHAR:
1011 				aRet = m_aValue.m_pString;
1012 				break;
1013 			case DataType::BIGINT:
1014 				if ( m_bSigned )
1015 					aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
1016 				else
1017 					aRet = m_aValue.m_pString;
1018 				break;
1019 			case DataType::FLOAT:
1020 				aRet = ::rtl::OUString::valueOf((float)*this);
1021 				break;
1022 			case DataType::DOUBLE:
1023 			case DataType::REAL:
1024 				aRet = ::rtl::OUString::valueOf((double)*this);
1025 				break;
1026 			case DataType::DATE:
1027 				aRet = connectivity::toDateString(*this);
1028 				break;
1029 			case DataType::TIME:
1030 				aRet = connectivity::toTimeString(*this);
1031 				break;
1032 			case DataType::TIMESTAMP:
1033 				aRet = connectivity::toDateTimeString(*this);
1034 				break;
1035 			case DataType::BINARY:
1036 			case DataType::VARBINARY:
1037 			case DataType::LONGVARBINARY:
1038 				{
1039 					::rtl::OUStringBuffer sVal = ::rtl::OUString::createFromAscii("0x");
1040 					Sequence<sal_Int8> aSeq(getSequence());
1041 					const sal_Int8* pBegin	= aSeq.getConstArray();
1042 					const sal_Int8* pEnd	= pBegin + aSeq.getLength();
1043 					for(;pBegin != pEnd;++pBegin)
1044 						sVal.append((sal_Int32)*pBegin,16);
1045                     aRet = sVal.makeStringAndClear();
1046 				}
1047 				break;
1048 			case DataType::BIT:
1049 			case DataType::BOOLEAN:
1050 				aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Bool)*this);
1051 				break;
1052 			case DataType::TINYINT:
1053 				if ( m_bSigned )
1054 					aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int8)*this);
1055 				else
1056 					aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1057 				break;
1058 			case DataType::SMALLINT:
1059 				if ( m_bSigned )
1060 					aRet = ::rtl::OUString::valueOf((sal_Int32)(sal_Int16)*this);
1061 				else
1062 					aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1063 				break;
1064 			case DataType::INTEGER:
1065 				if ( m_bSigned )
1066 					aRet = ::rtl::OUString::valueOf((sal_Int32)*this);
1067 				else
1068 					aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
1069 				break;
1070 			case DataType::CLOB:
1071 				{
1072 					Any aValue( getAny() );
1073 					Reference< XClob > xClob;
1074 					if ( aValue >>= xClob )
1075 					{
1076 						if ( xClob.is() )
1077 						{
1078 							aRet = xClob->getSubString(1,(sal_Int32)xClob->length() );
1079 						}
1080 					}
1081 				}
1082 				break;
1083             default:
1084                 {
1085                     Any aValue = getAny();
1086                     aValue >>= aRet;
1087 				    break;
1088                 }
1089 		}
1090 	}
1091 	return aRet;
1092 }
1093 // -------------------------------------------------------------------------
1094 sal_Bool ORowSetValue::getBool()	const
1095 {
1096     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getBool" );
1097 	sal_Bool bRet = sal_False;
1098 	if(!m_bNull)
1099 	{
1100 		switch(getTypeKind())
1101 		{
1102 			case DataType::CHAR:
1103 			case DataType::VARCHAR:
1104             case DataType::LONGVARCHAR:
1105                 {
1106                     const ::rtl::OUString sValue(m_aValue.m_pString);
1107                     const static ::rtl::OUString s_sTrue(RTL_CONSTASCII_USTRINGPARAM("true"));
1108                     const static ::rtl::OUString s_sFalse(RTL_CONSTASCII_USTRINGPARAM("false"));
1109                     if ( sValue.equalsIgnoreAsciiCase(s_sTrue) )
1110                     {
1111                         bRet = sal_True;
1112                         break;
1113                     }
1114                     else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) )
1115                     {
1116                         bRet = sal_False;
1117                         break;
1118                     }
1119                 }
1120                 // run through
1121 			case DataType::DECIMAL:
1122 			case DataType::NUMERIC:
1123 
1124 				bRet = ::rtl::OUString(m_aValue.m_pString).toInt32() != 0;
1125 				break;
1126 			case DataType::BIGINT:
1127                 if ( m_bSigned )
1128 					bRet = *(sal_Int64*)m_aValue.m_pValue != 0;
1129 				else
1130 					bRet = ::rtl::OUString(m_aValue.m_pString).toInt64() != 0;
1131 				break;
1132 			case DataType::FLOAT:
1133 				bRet = *(float*)m_aValue.m_pValue != 0.0;
1134 				break;
1135 			case DataType::DOUBLE:
1136 			case DataType::REAL:
1137 				bRet = *(double*)m_aValue.m_pValue != 0.0;
1138 				break;
1139 			case DataType::DATE:
1140 			case DataType::TIME:
1141 			case DataType::TIMESTAMP:
1142 			case DataType::BINARY:
1143 			case DataType::VARBINARY:
1144 			case DataType::LONGVARBINARY:
1145 				OSL_ASSERT(!"getBool() for this type is not allowed!");
1146 				break;
1147 			case DataType::BIT:
1148 			case DataType::BOOLEAN:
1149 				bRet = m_aValue.m_bBool;
1150 				break;
1151 			case DataType::TINYINT:
1152 				bRet = m_bSigned ? (m_aValue.m_nInt8  != 0) : (m_aValue.m_nInt16 != 0);
1153 				break;
1154 			case DataType::SMALLINT:
1155 				bRet = m_bSigned ? (m_aValue.m_nInt16  != 0) : (m_aValue.m_nInt32 != 0);
1156 				break;
1157 			case DataType::INTEGER:
1158 				bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0));
1159 				break;
1160 			default:
1161                 {
1162                     Any aValue = getAny();
1163                     aValue >>= bRet;
1164 				    break;
1165                 }
1166 		}
1167 	}
1168 	return bRet;
1169 }
1170 // -------------------------------------------------------------------------
1171 sal_Int8 ORowSetValue::getInt8()	const
1172 {
1173     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt8" );
1174 
1175 
1176 	sal_Int8 nRet = 0;
1177 	if(!m_bNull)
1178 	{
1179 		switch(getTypeKind())
1180 		{
1181 			case DataType::CHAR:
1182 			case DataType::VARCHAR:
1183 			case DataType::DECIMAL:
1184 			case DataType::NUMERIC:
1185 			case DataType::LONGVARCHAR:
1186 				nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1187 				break;
1188 			case DataType::BIGINT:
1189                 if ( m_bSigned )
1190 					nRet = sal_Int8(*(sal_Int64*)m_aValue.m_pValue);
1191 				else
1192 					nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
1193 				break;
1194 			case DataType::FLOAT:
1195 				nRet = sal_Int8(*(float*)m_aValue.m_pValue);
1196 				break;
1197 			case DataType::DOUBLE:
1198 			case DataType::REAL:
1199 				nRet = sal_Int8(*(double*)m_aValue.m_pValue);
1200 				break;
1201 			case DataType::DATE:
1202 			case DataType::TIME:
1203 			case DataType::TIMESTAMP:
1204 			case DataType::BINARY:
1205 			case DataType::VARBINARY:
1206 			case DataType::LONGVARBINARY:
1207 			case DataType::BLOB:
1208 			case DataType::CLOB:
1209 				OSL_ASSERT(!"getInt8() for this type is not allowed!");
1210 				break;
1211 			case DataType::BIT:
1212 			case DataType::BOOLEAN:
1213 				nRet = m_aValue.m_bBool;
1214 				break;
1215 			case DataType::TINYINT:
1216 				if ( m_bSigned )
1217 					nRet = m_aValue.m_nInt8;
1218 				else
1219 					nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1220 				break;
1221 			case DataType::SMALLINT:
1222 				if ( m_bSigned )
1223 					nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1224 				else
1225 					nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1226 				break;
1227 			case DataType::INTEGER:
1228 				if ( m_bSigned )
1229 					nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1230 				else
1231 					nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1232 				break;
1233 			default:
1234                 {
1235                     Any aValue = getAny();
1236                     aValue >>= nRet;
1237 				    break;
1238                 }
1239 		}
1240 	}
1241 	return nRet;
1242 }
1243 // -------------------------------------------------------------------------
1244 sal_Int16 ORowSetValue::getInt16()	const
1245 {
1246     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt16" );
1247 
1248 
1249 	sal_Int16 nRet = 0;
1250 	if(!m_bNull)
1251 	{
1252 		switch(getTypeKind())
1253 		{
1254 			case DataType::CHAR:
1255 			case DataType::VARCHAR:
1256 			case DataType::DECIMAL:
1257 			case DataType::NUMERIC:
1258 			case DataType::LONGVARCHAR:
1259 				nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1260 				break;
1261 			case DataType::BIGINT:
1262                 if ( m_bSigned )
1263 					nRet = sal_Int16(*(sal_Int64*)m_aValue.m_pValue);
1264 				else
1265 					nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
1266 				break;
1267 			case DataType::FLOAT:
1268 				nRet = sal_Int16(*(float*)m_aValue.m_pValue);
1269 				break;
1270 			case DataType::DOUBLE:
1271 			case DataType::REAL:
1272 				nRet = sal_Int16(*(double*)m_aValue.m_pValue);
1273 				break;
1274 			case DataType::DATE:
1275 			case DataType::TIME:
1276 			case DataType::TIMESTAMP:
1277 			case DataType::BINARY:
1278 			case DataType::VARBINARY:
1279 			case DataType::LONGVARBINARY:
1280 			case DataType::BLOB:
1281 			case DataType::CLOB:
1282 				OSL_ASSERT(!"getInt16() for this type is not allowed!");
1283 				break;
1284 			case DataType::BIT:
1285 			case DataType::BOOLEAN:
1286 				nRet = m_aValue.m_bBool;
1287 				break;
1288 			case DataType::TINYINT:
1289 				if ( m_bSigned )
1290 					nRet = m_aValue.m_nInt8;
1291 				else
1292 					nRet = m_aValue.m_nInt16;
1293 				break;
1294 			case DataType::SMALLINT:
1295 				if ( m_bSigned )
1296 					nRet = m_aValue.m_nInt16;
1297 				else
1298 					nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1299 				break;
1300 			case DataType::INTEGER:
1301 				if ( m_bSigned )
1302 					nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1303 				else
1304 					nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1305 				break;
1306 			default:
1307                 {
1308                     Any aValue = getAny();
1309                     aValue >>= nRet;
1310 				    break;
1311                 }
1312 		}
1313 	}
1314 	return nRet;
1315 }
1316 // -------------------------------------------------------------------------
1317 sal_Int32 ORowSetValue::getInt32()	const
1318 {
1319     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getInt32" );
1320 	sal_Int32 nRet = 0;
1321 	if(!m_bNull)
1322 	{
1323 		switch(getTypeKind())
1324 		{
1325 			case DataType::CHAR:
1326 			case DataType::VARCHAR:
1327 			case DataType::DECIMAL:
1328 			case DataType::NUMERIC:
1329 			case DataType::LONGVARCHAR:
1330 				nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1331 				break;
1332 			case DataType::BIGINT:
1333 				if ( m_bSigned )
1334 					nRet = sal_Int32(*(sal_Int64*)m_aValue.m_pValue);
1335 				else
1336 					nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
1337 				break;
1338 			case DataType::FLOAT:
1339 				nRet = sal_Int32(*(float*)m_aValue.m_pValue);
1340 				break;
1341 			case DataType::DOUBLE:
1342 			case DataType::REAL:
1343 				nRet = sal_Int32(*(double*)m_aValue.m_pValue);
1344 				break;
1345 			case DataType::DATE:
1346 				nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1347 				break;
1348 			case DataType::TIME:
1349 			case DataType::TIMESTAMP:
1350 			case DataType::BINARY:
1351 			case DataType::VARBINARY:
1352 			case DataType::LONGVARBINARY:
1353 			case DataType::BLOB:
1354 			case DataType::CLOB:
1355 				OSL_ASSERT(!"getInt32() for this type is not allowed!");
1356 				break;
1357 			case DataType::BIT:
1358 			case DataType::BOOLEAN:
1359 				nRet = m_aValue.m_bBool;
1360 				break;
1361 			case DataType::TINYINT:
1362 				if ( m_bSigned )
1363 					nRet = m_aValue.m_nInt8;
1364 				else
1365 					nRet = m_aValue.m_nInt16;
1366 				break;
1367 			case DataType::SMALLINT:
1368 				if ( m_bSigned )
1369 					nRet = m_aValue.m_nInt16;
1370 				else
1371 					nRet = m_aValue.m_nInt32;
1372 				break;
1373 			case DataType::INTEGER:
1374 				if ( m_bSigned )
1375 					nRet = m_aValue.m_nInt32;
1376 				else
1377 					nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
1378 				break;
1379 			default:
1380                 {
1381                     Any aValue = getAny();
1382                     aValue >>= nRet;
1383 				    break;
1384                 }
1385 		}
1386 	}
1387 	return nRet;
1388 }
1389 // -------------------------------------------------------------------------
1390 sal_Int64 ORowSetValue::getLong()	const
1391 {
1392     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getLong" );
1393 	sal_Int64 nRet = 0;
1394 	if(!m_bNull)
1395 	{
1396 		switch(getTypeKind())
1397 		{
1398 			case DataType::CHAR:
1399 			case DataType::VARCHAR:
1400 			case DataType::DECIMAL:
1401 			case DataType::NUMERIC:
1402 			case DataType::LONGVARCHAR:
1403 				nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1404 				break;
1405 			case DataType::BIGINT:
1406 				if ( m_bSigned )
1407 					nRet = *(sal_Int64*)m_aValue.m_pValue;
1408 				else
1409 					nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
1410 				break;
1411 			case DataType::FLOAT:
1412 				nRet = sal_Int64(*(float*)m_aValue.m_pValue);
1413 				break;
1414 			case DataType::DOUBLE:
1415 			case DataType::REAL:
1416 				nRet = sal_Int64(*(double*)m_aValue.m_pValue);
1417 				break;
1418 			case DataType::DATE:
1419 				nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1420 				break;
1421 			case DataType::TIME:
1422 			case DataType::TIMESTAMP:
1423 			case DataType::BINARY:
1424 			case DataType::VARBINARY:
1425 			case DataType::LONGVARBINARY:
1426 			case DataType::BLOB:
1427 			case DataType::CLOB:
1428 				OSL_ASSERT(!"getInt32() for this type is not allowed!");
1429 				break;
1430 			case DataType::BIT:
1431 			case DataType::BOOLEAN:
1432 				nRet = m_aValue.m_bBool;
1433 				break;
1434 			case DataType::TINYINT:
1435 				if ( m_bSigned )
1436 					nRet = m_aValue.m_nInt8;
1437 				else
1438 					nRet = m_aValue.m_nInt16;
1439 				break;
1440 			case DataType::SMALLINT:
1441 				if ( m_bSigned )
1442 					nRet = m_aValue.m_nInt16;
1443 				else
1444 					nRet = m_aValue.m_nInt32;
1445 				break;
1446 			case DataType::INTEGER:
1447 				if ( m_bSigned )
1448 					nRet = m_aValue.m_nInt32;
1449 				else
1450 					nRet = *(sal_Int64*)m_aValue.m_pValue;
1451 				break;
1452 			default:
1453                 {
1454                     Any aValue = getAny();
1455                     aValue >>= nRet;
1456 				    break;
1457                 }
1458 		}
1459 	}
1460 	return nRet;
1461 }
1462 // -------------------------------------------------------------------------
1463 float ORowSetValue::getFloat()	const
1464 {
1465     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getFloat" );
1466 	float nRet = 0;
1467 	if(!m_bNull)
1468 	{
1469 		switch(getTypeKind())
1470 		{
1471 			case DataType::CHAR:
1472 			case DataType::VARCHAR:
1473 			case DataType::DECIMAL:
1474 			case DataType::NUMERIC:
1475 			case DataType::LONGVARCHAR:
1476 				nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1477 				break;
1478 			case DataType::BIGINT:
1479 				if ( m_bSigned )
1480 					nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1481 				else
1482 					nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
1483 				break;
1484 			case DataType::FLOAT:
1485 				nRet = *(float*)m_aValue.m_pValue;
1486 				break;
1487 			case DataType::DOUBLE:
1488 			case DataType::REAL:
1489 				nRet = (float)*(double*)m_aValue.m_pValue;
1490 				break;
1491 			case DataType::DATE:
1492 				nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1493 				break;
1494 			case DataType::TIME:
1495 				nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1496 				break;
1497 			case DataType::TIMESTAMP:
1498 				nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1499 				break;
1500 			case DataType::BINARY:
1501 			case DataType::VARBINARY:
1502 			case DataType::LONGVARBINARY:
1503 			case DataType::BLOB:
1504 			case DataType::CLOB:
1505 				OSL_ASSERT(!"getDouble() for this type is not allowed!");
1506 				break;
1507 			case DataType::BIT:
1508 			case DataType::BOOLEAN:
1509 				nRet = m_aValue.m_bBool;
1510 				break;
1511 			case DataType::TINYINT:
1512 				if ( m_bSigned )
1513 					nRet = m_aValue.m_nInt8;
1514 				else
1515 					nRet = m_aValue.m_nInt16;
1516 				break;
1517 			case DataType::SMALLINT:
1518 				if ( m_bSigned )
1519 					nRet = m_aValue.m_nInt16;
1520 				else
1521 					nRet = (float)m_aValue.m_nInt32;
1522 				break;
1523 			case DataType::INTEGER:
1524 				if ( m_bSigned )
1525 					nRet = (float)m_aValue.m_nInt32;
1526 				else
1527 					nRet = float(*(sal_Int64*)m_aValue.m_pValue);
1528 				break;
1529 			default:
1530                 {
1531                     Any aValue = getAny();
1532                     aValue >>= nRet;
1533 				    break;
1534                 }
1535 		}
1536 	}
1537 	return nRet;
1538 }
1539 // -------------------------------------------------------------------------
1540 double ORowSetValue::getDouble()	const
1541 {
1542     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDouble" );
1543 
1544 
1545 	double nRet = 0;
1546 	if(!m_bNull)
1547 	{
1548 		switch(getTypeKind())
1549 		{
1550 			case DataType::CHAR:
1551 			case DataType::VARCHAR:
1552 			case DataType::DECIMAL:
1553 			case DataType::NUMERIC:
1554 			case DataType::LONGVARCHAR:
1555 				nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1556 				break;
1557 			case DataType::BIGINT:
1558 				if ( m_bSigned )
1559 					nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1560 				else
1561 					nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
1562 				break;
1563 			case DataType::FLOAT:
1564 				nRet = *(float*)m_aValue.m_pValue;
1565 				break;
1566 			case DataType::DOUBLE:
1567 			case DataType::REAL:
1568 				nRet = *(double*)m_aValue.m_pValue;
1569 				break;
1570 			case DataType::DATE:
1571 				nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
1572 				break;
1573 			case DataType::TIME:
1574 				nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Time*)m_aValue.m_pValue);
1575 				break;
1576 			case DataType::TIMESTAMP:
1577 				nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::DateTime*)m_aValue.m_pValue);
1578 				break;
1579 			case DataType::BINARY:
1580 			case DataType::VARBINARY:
1581 			case DataType::LONGVARBINARY:
1582 			case DataType::BLOB:
1583 			case DataType::CLOB:
1584 				OSL_ASSERT(!"getDouble() for this type is not allowed!");
1585 				break;
1586 			case DataType::BIT:
1587 			case DataType::BOOLEAN:
1588 				nRet = m_aValue.m_bBool;
1589 				break;
1590 			case DataType::TINYINT:
1591 				if ( m_bSigned )
1592 					nRet = m_aValue.m_nInt8;
1593 				else
1594 					nRet = m_aValue.m_nInt16;
1595 				break;
1596 			case DataType::SMALLINT:
1597 				if ( m_bSigned )
1598 					nRet = m_aValue.m_nInt16;
1599 				else
1600 					nRet = m_aValue.m_nInt32;
1601 				break;
1602 			case DataType::INTEGER:
1603 				if ( m_bSigned )
1604 					nRet = m_aValue.m_nInt32;
1605 				else
1606 					nRet = double(*(sal_Int64*)m_aValue.m_pValue);
1607 				break;
1608 			default:
1609                 {
1610                     Any aValue = getAny();
1611                     aValue >>= nRet;
1612 				    break;
1613                 }
1614 		}
1615 	}
1616 	return nRet;
1617 }
1618 // -------------------------------------------------------------------------
1619 void ORowSetValue::setFromDouble(const double& _rVal,sal_Int32 _nDatatype)
1620 {
1621     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setFromDouble" );
1622 	free();
1623 
1624 	m_bNull = sal_False;
1625 	switch(_nDatatype)
1626 	{
1627 		case DataType::CHAR:
1628 		case DataType::VARCHAR:
1629 		case DataType::DECIMAL:
1630 		case DataType::NUMERIC:
1631 		case DataType::LONGVARCHAR:
1632 			{
1633 				::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1634 				m_aValue.m_pString = aVal.pData;
1635 				rtl_uString_acquire(m_aValue.m_pString);
1636 			}
1637 			break;
1638 		case DataType::BIGINT:
1639 			if ( m_bSigned )
1640 			{
1641 				m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1642 				TRACE_ALLOC( sal_Int64 )
1643 			}
1644 			else
1645 			{
1646 				::rtl::OUString aVal = ::rtl::OUString::valueOf(_rVal);
1647 				m_aValue.m_pString = aVal.pData;
1648 				rtl_uString_acquire(m_aValue.m_pString);
1649 			}
1650 			break;
1651 		case DataType::FLOAT:
1652 			m_aValue.m_pValue = new float((float)_rVal);
1653 			TRACE_ALLOC( float )
1654 			break;
1655 		case DataType::DOUBLE:
1656 		case DataType::REAL:
1657 			m_aValue.m_pValue = new double(_rVal);
1658 			TRACE_ALLOC( double )
1659 			break;
1660 		case DataType::DATE:
1661 			m_aValue.m_pValue = new Date(dbtools::DBTypeConversion::toDate(_rVal));
1662 			TRACE_ALLOC( Date )
1663 			break;
1664 		case DataType::TIME:
1665 			m_aValue.m_pValue = new Time(dbtools::DBTypeConversion::toTime(_rVal));
1666 			TRACE_ALLOC( Time )
1667 			break;
1668 		case DataType::TIMESTAMP:
1669 			m_aValue.m_pValue = new DateTime(dbtools::DBTypeConversion::toDateTime(_rVal));
1670 			TRACE_ALLOC( DateTime )
1671 			break;
1672 		case DataType::BINARY:
1673 		case DataType::VARBINARY:
1674 		case DataType::LONGVARBINARY:
1675 		case DataType::BLOB:
1676 		case DataType::CLOB:
1677 			OSL_ASSERT(!"setFromDouble() for this type is not allowed!");
1678 			break;
1679 		case DataType::BIT:
1680 		case DataType::BOOLEAN:
1681 			m_aValue.m_bBool = _rVal != 0.0;
1682 			break;
1683 		case DataType::TINYINT:
1684 			if ( m_bSigned )
1685 				m_aValue.m_nInt8 = sal_Int8(_rVal);
1686 			else
1687 				m_aValue.m_nInt16 = sal_Int16(_rVal);
1688 			break;
1689 		case DataType::SMALLINT:
1690 			if ( m_bSigned )
1691 				m_aValue.m_nInt16 = sal_Int16(_rVal);
1692 			else
1693 				m_aValue.m_nInt32 = sal_Int32(_rVal);
1694 			break;
1695 		case DataType::INTEGER:
1696 			if ( m_bSigned )
1697 				m_aValue.m_nInt32 = sal_Int32(_rVal);
1698 			else
1699 			{
1700 				m_aValue.m_pValue = new sal_Int64((sal_Int64)_rVal);
1701 				TRACE_ALLOC( sal_Int64 )
1702 			}
1703 			break;
1704             default:
1705                 {
1706                     m_aValue.m_pValue = new Any(_rVal);
1707 				    break;
1708                 }
1709 	}
1710 	m_eTypeKind = _nDatatype;
1711 }
1712 // -----------------------------------------------------------------------------
1713 Sequence<sal_Int8>	ORowSetValue::getSequence() const
1714 {
1715     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getSequence" );
1716 	Sequence<sal_Int8> aSeq;
1717 	if (!m_bNull)
1718 	{
1719 		switch(m_eTypeKind)
1720 		{
1721 			case DataType::OBJECT:
1722 			case DataType::CLOB:
1723 			case DataType::BLOB:
1724 			{
1725 				Reference<XInputStream> xStream;
1726 				const Any aValue = makeAny();
1727 				if(aValue.hasValue())
1728 				{
1729                     Reference<XBlob> xBlob(aValue,UNO_QUERY);
1730                     if ( xBlob.is() )
1731                         xStream = xBlob->getBinaryStream();
1732                     else
1733                     {
1734                         Reference<XClob> xClob(aValue,UNO_QUERY);
1735                         if ( xClob.is() )
1736                             xStream = xClob->getCharacterStream();
1737                     }
1738 					if(xStream.is())
1739                     {
1740                         const sal_uInt32	nBytesToRead = 65535;
1741 		                sal_uInt32			nRead;
1742 
1743 		                do
1744 		                {
1745 			                ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq;
1746 
1747 			                nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1748 
1749 			                if( nRead )
1750 			                {
1751 				                const sal_uInt32 nOldLength = aSeq.getLength();
1752 				                aSeq.realloc( nOldLength + nRead );
1753 				                rtl_copyMemory( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1754 			                }
1755 		                }
1756 		                while( nBytesToRead == nRead );
1757                         xStream->closeInput();
1758                     }
1759 				}
1760 			}
1761 			break;
1762 			case DataType::VARCHAR:
1763 			case DataType::LONGVARCHAR:
1764 				{
1765 					::rtl::OUString sVal(m_aValue.m_pString);
1766 					aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sVal.getStr()),sizeof(sal_Unicode)*sVal.getLength());
1767 				}
1768 				break;
1769 			case DataType::BINARY:
1770 			case DataType::VARBINARY:
1771 			case DataType::LONGVARBINARY:
1772 				aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1773 				break;
1774 			default:
1775                 {
1776                     Any aValue = getAny();
1777                     aValue >>= aSeq;
1778 				    break;
1779                 }
1780 		}
1781 	}
1782 	return aSeq;
1783 
1784 }
1785 // -----------------------------------------------------------------------------
1786 ::com::sun::star::util::Date ORowSetValue::getDate() const
1787 {
1788     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDate" );
1789 	::com::sun::star::util::Date aValue;
1790 	if(!m_bNull)
1791 	{
1792 		switch(m_eTypeKind)
1793 		{
1794 			case DataType::CHAR:
1795 			case DataType::VARCHAR:
1796 			case DataType::LONGVARCHAR:
1797 				aValue = DBTypeConversion::toDate(getString());
1798 				break;
1799 			case DataType::DECIMAL:
1800 			case DataType::NUMERIC:
1801 			case DataType::FLOAT:
1802 			case DataType::DOUBLE:
1803 			case DataType::REAL:
1804 				aValue = DBTypeConversion::toDate((double)*this);
1805 				break;
1806 
1807 			case DataType::DATE:
1808 				aValue = *static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1809 				break;
1810 			case DataType::TIMESTAMP:
1811 				{
1812 					::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1813 					aValue.Day		= pDateTime->Day;
1814 					aValue.Month	= pDateTime->Month;
1815 					aValue.Year		= pDateTime->Year;
1816 				}
1817 				break;
1818             case DataType::BIT:
1819             case DataType::BOOLEAN:
1820             case DataType::TINYINT:
1821             case DataType::SMALLINT:
1822 			case DataType::INTEGER:
1823 			case DataType::BIGINT:
1824 				aValue = DBTypeConversion::toDate( double( sal_Int64( *this ) ) );
1825 				break;
1826 
1827 			case DataType::BLOB:
1828 			case DataType::CLOB:
1829 			case DataType::OBJECT:
1830             default:
1831                 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1832                 // NO break!
1833 
1834             case DataType::BINARY:
1835 			case DataType::VARBINARY:
1836 			case DataType::LONGVARBINARY:
1837 			case DataType::TIME:
1838                 aValue = DBTypeConversion::toDate( (double)0 );
1839                 break;
1840 		}
1841 	}
1842 	return aValue;
1843 }
1844 // -----------------------------------------------------------------------------
1845 ::com::sun::star::util::Time ORowSetValue::getTime()		const
1846 {
1847     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getTime" );
1848 	::com::sun::star::util::Time aValue;
1849 	if(!m_bNull)
1850 	{
1851 		switch(m_eTypeKind)
1852 		{
1853 			case DataType::CHAR:
1854 			case DataType::VARCHAR:
1855 			case DataType::LONGVARCHAR:
1856 				aValue = DBTypeConversion::toTime(getString());
1857 				break;
1858 			case DataType::DECIMAL:
1859 			case DataType::NUMERIC:
1860 				aValue = DBTypeConversion::toTime((double)*this);
1861 				break;
1862 			case DataType::FLOAT:
1863 			case DataType::DOUBLE:
1864 			case DataType::REAL:
1865 				aValue = DBTypeConversion::toTime((double)*this);
1866 				break;
1867 			case DataType::TIMESTAMP:
1868 				{
1869 					::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1870 					aValue.HundredthSeconds	= pDateTime->HundredthSeconds;
1871 					aValue.Seconds			= pDateTime->Seconds;
1872 					aValue.Minutes			= pDateTime->Minutes;
1873 					aValue.Hours			= pDateTime->Hours;
1874 				}
1875 				break;
1876 			case DataType::TIME:
1877 				aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1878                 break;
1879 			default:
1880                 {
1881                     Any aAnyValue = getAny();
1882                     aAnyValue >>= aValue;
1883 				    break;
1884                 }
1885 		}
1886 	}
1887 	return aValue;
1888 }
1889 // -----------------------------------------------------------------------------
1890 ::com::sun::star::util::DateTime ORowSetValue::getDateTime()	const
1891 {
1892     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::getDateTime" );
1893 	::com::sun::star::util::DateTime aValue;
1894 	if(!m_bNull)
1895 	{
1896 		switch(m_eTypeKind)
1897 		{
1898 			case DataType::CHAR:
1899 			case DataType::VARCHAR:
1900 			case DataType::LONGVARCHAR:
1901 				aValue = DBTypeConversion::toDateTime(getString());
1902 				break;
1903 			case DataType::DECIMAL:
1904 			case DataType::NUMERIC:
1905 				aValue = DBTypeConversion::toDateTime((double)*this);
1906 				break;
1907 			case DataType::FLOAT:
1908 			case DataType::DOUBLE:
1909 			case DataType::REAL:
1910 				aValue = DBTypeConversion::toDateTime((double)*this);
1911 				break;
1912 			case DataType::DATE:
1913 				{
1914 					::com::sun::star::util::Date* pDate = static_cast< ::com::sun::star::util::Date*>(m_aValue.m_pValue);
1915 					aValue.Day		= pDate->Day;
1916 					aValue.Month	= pDate->Month;
1917 					aValue.Year		= pDate->Year;
1918 				}
1919 				break;
1920 			case DataType::TIME:
1921 				{
1922 					::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
1923 					aValue.HundredthSeconds	= pTime->HundredthSeconds;
1924 					aValue.Seconds			= pTime->Seconds;
1925 					aValue.Minutes			= pTime->Minutes;
1926 					aValue.Hours			= pTime->Hours;
1927 				}
1928 				break;
1929 			case DataType::TIMESTAMP:
1930 				aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
1931 				break;
1932 			default:
1933                 {
1934                     Any aAnyValue = getAny();
1935                     aAnyValue >>= aValue;
1936 				    break;
1937                 }
1938 		}
1939 	}
1940 	return aValue;
1941 }
1942 // -----------------------------------------------------------------------------
1943 void ORowSetValue::setSigned(sal_Bool _bMod)
1944 {
1945     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::setSigned" );
1946 	if ( m_bSigned != _bMod )
1947 	{
1948 		m_bSigned = _bMod;
1949 		if ( !m_bNull )
1950 		{
1951 			sal_Int32 nType = m_eTypeKind;
1952 			switch(m_eTypeKind)
1953 			{
1954 				case DataType::BIGINT:
1955 					if ( m_bSigned ) // now we are signed, so we were unsigned and need to call getString()
1956                     {
1957                         m_bSigned = !m_bSigned;
1958                         const ::rtl::OUString sValue = getString();
1959                         free();
1960                         m_bSigned = !m_bSigned;
1961 						(*this) = sValue;
1962                     }
1963 					else
1964                     {
1965                         m_bSigned = !m_bSigned;
1966                         const sal_Int64 nValue = getLong();
1967                         free();
1968                         m_bSigned = !m_bSigned;
1969 						(*this) = nValue;
1970                     }
1971 					break;
1972 				case DataType::TINYINT:
1973 					if ( m_bSigned )
1974 						(*this) = getInt8();
1975 					else
1976 					{
1977 						m_bSigned = !m_bSigned;
1978 						(*this) = getInt16();
1979 						m_bSigned = !m_bSigned;
1980 					}
1981 					break;
1982 				case DataType::SMALLINT:
1983 					if ( m_bSigned )
1984 						(*this) = getInt16();
1985 					else
1986 					{
1987 						m_bSigned = !m_bSigned;
1988 						(*this) = getInt32();
1989 						m_bSigned = !m_bSigned;
1990 					}
1991 					break;
1992 				case DataType::INTEGER:
1993 					if ( m_bSigned )
1994 						(*this) = getInt32();
1995 					else
1996 					{
1997 						m_bSigned = !m_bSigned;
1998 						(*this) = getLong();
1999 						m_bSigned = !m_bSigned;
2000 					}
2001 					break;
2002 			}
2003 			m_eTypeKind = nType;
2004 		}
2005 	}
2006 }
2007 
2008 // -----------------------------------------------------------------------------
2009 namespace detail
2010 {
2011     class SAL_NO_VTABLE IValueSource
2012     {
2013     public:
2014         virtual ::rtl::OUString             getString() const = 0;
2015         virtual sal_Bool                    getBoolean() const = 0;
2016         virtual sal_Int8                    getByte() const = 0;
2017         virtual sal_Int16                   getShort() const = 0;
2018         virtual sal_Int32                   getInt() const = 0;
2019         virtual sal_Int64                   getLong() const = 0;
2020         virtual float                       getFloat() const = 0;
2021         virtual double                      getDouble() const = 0;
2022         virtual Date                        getDate() const = 0;
2023         virtual Time                        getTime() const = 0;
2024         virtual DateTime                    getTimestamp() const = 0;
2025         virtual Sequence< sal_Int8 >        getBytes() const = 0;
2026         virtual Reference< XInputStream >   getBinaryStream() const = 0;
2027         virtual Reference< XInputStream >   getCharacterStream() const = 0;
2028         virtual Reference< XBlob >   		getBlob() const = 0;
2029         virtual Reference< XClob >   		getClob() const = 0;
2030         virtual Any					   		getObject() const = 0;
2031         virtual sal_Bool                    wasNull() const = 0;
2032 
2033         virtual ~IValueSource() { }
2034     };
2035 
2036     class RowValue : public IValueSource
2037     {
2038     public:
2039         RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2040             :m_xRow( _xRow )
2041             ,m_nPos( _nPos )
2042         {
2043         }
2044 
2045         // IValueSource
2046         virtual ::rtl::OUString             getString() const           { return m_xRow->getString( m_nPos ); };
2047         virtual sal_Bool                    getBoolean() const          { return m_xRow->getBoolean( m_nPos ); };
2048         virtual sal_Int8                    getByte() const             { return m_xRow->getByte( m_nPos ); };
2049         virtual sal_Int16                   getShort() const            { return m_xRow->getShort( m_nPos ); }
2050         virtual sal_Int32                   getInt() const              { return m_xRow->getInt( m_nPos ); }
2051         virtual sal_Int64                   getLong() const             { return m_xRow->getLong( m_nPos ); }
2052         virtual float                       getFloat() const            { return m_xRow->getFloat( m_nPos ); };
2053         virtual double                      getDouble() const           { return m_xRow->getDouble( m_nPos ); };
2054         virtual Date                        getDate() const             { return m_xRow->getDate( m_nPos ); };
2055         virtual Time                        getTime() const             { return m_xRow->getTime( m_nPos ); };
2056         virtual DateTime                    getTimestamp() const        { return m_xRow->getTimestamp( m_nPos ); };
2057         virtual Sequence< sal_Int8 >        getBytes() const            { return m_xRow->getBytes( m_nPos ); };
2058         virtual Reference< XInputStream >   getBinaryStream() const     { return m_xRow->getBinaryStream( m_nPos ); };
2059         virtual Reference< XInputStream >   getCharacterStream() const  { return m_xRow->getCharacterStream( m_nPos ); };
2060         virtual Reference< XBlob >   		getBlob() const  			{ return m_xRow->getBlob( m_nPos ); };
2061         virtual Reference< XClob >   		getClob() const  			{ return m_xRow->getClob( m_nPos ); };
2062         virtual Any					   		getObject() const 			{ return m_xRow->getObject( m_nPos ,NULL); };
2063         virtual sal_Bool                    wasNull() const             { return m_xRow->wasNull( ); };
2064 
2065     private:
2066         const Reference< XRow > m_xRow;
2067         const sal_Int32         m_nPos;
2068     };
2069 
2070     class ColumnValue : public IValueSource
2071     {
2072     public:
2073         ColumnValue( const Reference< XColumn >& _rxColumn )
2074             :m_xColumn( _rxColumn )
2075         {
2076         }
2077 
2078         // IValueSource
2079         virtual ::rtl::OUString             getString() const           { return m_xColumn->getString(); };
2080         virtual sal_Bool                    getBoolean() const          { return m_xColumn->getBoolean(); };
2081         virtual sal_Int8                    getByte() const             { return m_xColumn->getByte(); };
2082         virtual sal_Int16                   getShort() const            { return m_xColumn->getShort(); }
2083         virtual sal_Int32                   getInt() const              { return m_xColumn->getInt(); }
2084         virtual sal_Int64                   getLong() const             { return m_xColumn->getLong(); }
2085         virtual float                       getFloat() const            { return m_xColumn->getFloat(); };
2086         virtual double                      getDouble() const           { return m_xColumn->getDouble(); };
2087         virtual Date                        getDate() const             { return m_xColumn->getDate(); };
2088         virtual Time                        getTime() const             { return m_xColumn->getTime(); };
2089         virtual DateTime                    getTimestamp() const        { return m_xColumn->getTimestamp(); };
2090         virtual Sequence< sal_Int8 >        getBytes() const            { return m_xColumn->getBytes(); };
2091         virtual Reference< XInputStream >   getBinaryStream() const     { return m_xColumn->getBinaryStream(); };
2092         virtual Reference< XInputStream >   getCharacterStream() const  { return m_xColumn->getCharacterStream(); };
2093         virtual Reference< XBlob >   		getBlob() const				{ return m_xColumn->getBlob(); };
2094         virtual Reference< XClob >   		getClob() const 			{ return m_xColumn->getClob(); };
2095         virtual Any                         getObject() const           { return m_xColumn->getObject( NULL ); };
2096         virtual sal_Bool                    wasNull() const             { return m_xColumn->wasNull( ); };
2097 
2098     private:
2099         const Reference< XColumn >  m_xColumn;
2100     };
2101 }
2102 
2103 // -----------------------------------------------------------------------------
2104 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2105 {
2106     detail::ColumnValue aColumnValue( _rxColumn );
2107     impl_fill( _nType, sal_True, aColumnValue );
2108 }
2109 
2110 // -----------------------------------------------------------------------------
2111 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, sal_Bool  _bNullable, const Reference< XRow>& _xRow )
2112 {
2113     detail::RowValue aRowValue( _xRow, _nPos );
2114     impl_fill( _nType, _bNullable, aRowValue );
2115 }
2116 
2117 // -----------------------------------------------------------------------------
2118 void ORowSetValue::fill(sal_Int32 _nPos,
2119 					 sal_Int32 _nType,
2120 					 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow)
2121 {
2122     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (1)" );
2123     fill(_nPos,_nType,sal_True,_xRow);
2124 }
2125 
2126 // -----------------------------------------------------------------------------
2127 void ORowSetValue::impl_fill( const sal_Int32 _nType, sal_Bool _bNullable, const detail::IValueSource& _rValueSource )
2128 
2129 {
2130     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (2)" );
2131     sal_Bool bReadData = sal_True;
2132 	switch(_nType)
2133 	{
2134 	case DataType::CHAR:
2135 	case DataType::VARCHAR:
2136 	case DataType::DECIMAL:
2137 	case DataType::NUMERIC:
2138 	case DataType::LONGVARCHAR:
2139 		(*this) = _rValueSource.getString();
2140 		break;
2141 	case DataType::BIGINT:
2142 		if ( isSigned() )
2143 			(*this) = _rValueSource.getLong();
2144 		else
2145 			(*this) = _rValueSource.getString();
2146 		break;
2147 	case DataType::FLOAT:
2148 		(*this) = _rValueSource.getFloat();
2149 		break;
2150 	case DataType::DOUBLE:
2151 	case DataType::REAL:
2152 		(*this) = _rValueSource.getDouble();
2153 		break;
2154 	case DataType::DATE:
2155 		(*this) = _rValueSource.getDate();
2156 		break;
2157 	case DataType::TIME:
2158 		(*this) = _rValueSource.getTime();
2159 		break;
2160 	case DataType::TIMESTAMP:
2161 		(*this) = _rValueSource.getTimestamp();
2162 		break;
2163 	case DataType::BINARY:
2164 	case DataType::VARBINARY:
2165 	case DataType::LONGVARBINARY:
2166 		(*this) = _rValueSource.getBytes();
2167 		break;
2168 	case DataType::BIT:
2169 	case DataType::BOOLEAN:
2170 		(*this) = _rValueSource.getBoolean();
2171 		break;
2172 	case DataType::TINYINT:
2173 		if ( isSigned() )
2174 			(*this) = _rValueSource.getByte();
2175 		else
2176 			(*this) = _rValueSource.getShort();
2177 		break;
2178 	case DataType::SMALLINT:
2179 		if ( isSigned() )
2180 			(*this) = _rValueSource.getShort();
2181 		else
2182 			(*this) = _rValueSource.getInt();
2183 		break;
2184 	case DataType::INTEGER:
2185 		if ( isSigned() )
2186 			(*this) = _rValueSource.getInt();
2187 		else
2188 			(*this) = _rValueSource.getLong();
2189 		break;
2190 	case DataType::CLOB:
2191         (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob());
2192 		setTypeKind(DataType::CLOB);
2193 		break;
2194 	case DataType::BLOB:
2195 		(*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob());
2196 		setTypeKind(DataType::BLOB);
2197 		break;
2198 	case DataType::OTHER:
2199 		(*this) = _rValueSource.getObject();
2200 		setTypeKind(DataType::OTHER);
2201 		break;
2202 	default:
2203         OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" );
2204         (*this) = _rValueSource.getObject();
2205         break;
2206 	}
2207 	if ( bReadData && _bNullable && _rValueSource.wasNull() )
2208 		setNull();
2209 	setTypeKind(_nType);
2210 }
2211 // -----------------------------------------------------------------------------
2212 void ORowSetValue::fill(const Any& _rValue)
2213 {
2214     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbtools", "Ocke.Janssen@sun.com", "ORowSetValue::fill (3)" );
2215     switch (_rValue.getValueType().getTypeClass())
2216     {
2217         case TypeClass_VOID:
2218             setNull();
2219             break;
2220         case TypeClass_BOOLEAN:
2221         {
2222             sal_Bool bValue( sal_False );
2223             _rValue >>= bValue;
2224             (*this) = bValue;
2225             break;
2226         }
2227         case TypeClass_CHAR:
2228         {
2229             sal_Unicode aDummy(0);
2230             _rValue >>= aDummy;
2231             (*this) = ::rtl::OUString(aDummy);
2232             break;
2233         }
2234         case TypeClass_STRING:
2235         {
2236             ::rtl::OUString sDummy;
2237             _rValue >>= sDummy;
2238             (*this) = sDummy;
2239             break;
2240         }
2241         case TypeClass_FLOAT:
2242         {
2243             float aDummy(0.0);
2244             _rValue >>= aDummy;
2245             (*this) = aDummy;
2246             break;
2247         }
2248         case TypeClass_DOUBLE:
2249         {
2250             double aDummy(0.0);
2251             _rValue >>= aDummy;
2252             (*this) = aDummy;
2253             break;
2254         }
2255         case TypeClass_BYTE:
2256         {
2257             sal_Int8 aDummy(0);
2258             _rValue >>= aDummy;
2259             (*this) = aDummy;
2260             break;
2261         }
2262         case TypeClass_SHORT:
2263         {
2264             sal_Int16 aDummy(0);
2265             _rValue >>= aDummy;
2266             (*this) = aDummy;
2267             break;
2268         }
2269         case TypeClass_LONG:
2270         {
2271             sal_Int32 aDummy(0);
2272             _rValue >>= aDummy;
2273             (*this) = aDummy;
2274             break;
2275         }
2276         case TypeClass_UNSIGNED_SHORT:
2277         {
2278             sal_uInt16 nValue(0);
2279             _rValue >>= nValue;
2280             (*this) = static_cast<sal_Int32>(nValue);
2281             setSigned(sal_False);
2282             break;
2283         }
2284         case TypeClass_HYPER:
2285         {
2286             sal_Int64 nValue(0);
2287             _rValue >>= nValue;
2288             (*this) = nValue;
2289             break;
2290         }
2291         case TypeClass_UNSIGNED_HYPER:
2292         {
2293             sal_uInt64 nValue(0);
2294             _rValue >>= nValue;
2295             (*this) = static_cast<sal_Int64>(nValue);
2296             setSigned(sal_False);
2297             break;
2298         }
2299         case TypeClass_UNSIGNED_LONG:
2300         {
2301             sal_uInt32 nValue(0);
2302             _rValue >>= nValue;
2303             (*this) = static_cast<sal_Int64>(nValue);
2304             setSigned(sal_False);
2305             break;
2306         }
2307         case TypeClass_ENUM:
2308         {
2309             sal_Int32 enumValue( 0 );
2310             ::cppu::enum2int( enumValue, _rValue );
2311             (*this) = enumValue;
2312         }
2313         break;
2314 
2315         case TypeClass_SEQUENCE:
2316         {
2317             Sequence<sal_Int8> aDummy;
2318             if ( _rValue >>= aDummy )
2319                 (*this) = aDummy;
2320             else
2321                 OSL_ENSURE( false, "ORowSetValue::fill: unsupported sequence type!" );
2322             break;
2323         }
2324 
2325         case TypeClass_STRUCT:
2326         {
2327             ::com::sun::star::util::Date aDate;
2328             ::com::sun::star::util::Time aTime;
2329             ::com::sun::star::util::DateTime aDateTime;
2330             if ( _rValue >>= aDate )
2331             {
2332                 (*this) = aDate;
2333             }
2334             else if ( _rValue >>= aTime )
2335             {
2336                 (*this) = aTime;
2337             }
2338             else if ( _rValue >>= aDateTime )
2339             {
2340                 (*this) = aDateTime;
2341             }
2342             else
2343                 OSL_ENSURE( false, "ORowSetValue::fill: unsupported structure!" );
2344 
2345             break;
2346         }
2347 		case TypeClass_INTERFACE:
2348 			{
2349 				Reference< XClob > xClob;
2350 				if ( _rValue >>= xClob )
2351 				{
2352 					(*this) = _rValue;
2353 					setTypeKind(DataType::CLOB);
2354 				}
2355 				else
2356 				{
2357 					Reference< XBlob > xBlob;
2358 					if ( _rValue >>= xBlob )
2359 					{
2360 						(*this) = _rValue;
2361 						setTypeKind(DataType::BLOB);
2362 					}
2363                     else
2364                     {
2365                         (*this) = _rValue;
2366                     }
2367                 }
2368 			}
2369 			break;
2370 
2371         default:
2372             OSL_ENSURE(0,"Unknown type");
2373             break;
2374     }
2375 }
2376 
2377 }   // namespace connectivity
2378