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 #include "ado/Aolevariant.hxx"
31 #include "connectivity/dbconversion.hxx"
32 #include <com/sun/star/sdbc/SQLException.hpp>
33 #include <com/sun/star/util/Time.hpp>
34 #include <com/sun/star/util/Date.hpp>
35 #include <com/sun/star/util/DateTime.hpp>
36 #include "diagnose_ex.h"
37 #include "resource/sharedresources.hxx"
38 #include "resource/ado_res.hrc"
39 #include "com/sun/star/bridge/oleautomation/Date.hpp"
40 #include "com/sun/star/bridge/oleautomation/Currency.hpp"
41 #include "com/sun/star/bridge/oleautomation/SCode.hpp"
42 #include "com/sun/star/bridge/oleautomation/Decimal.hpp"
43 
44 using namespace com::sun::star::beans;
45 using namespace com::sun::star::uno;
46 using namespace com::sun::star::bridge::oleautomation;
47 using namespace connectivity::ado;
48 using ::rtl::OUString;
49 
50 OLEString::OLEString()
51 	:m_sStr(NULL)
52 {
53 }
54 OLEString::OLEString(const BSTR& _sBStr)
55 	:m_sStr(_sBStr)
56 {
57 }
58 OLEString::OLEString(const ::rtl::OUString& _sBStr)
59 {
60 	m_sStr = ::SysAllocString(reinterpret_cast<LPCOLESTR>(_sBStr.getStr()));
61 }
62 OLEString::~OLEString()
63 {
64 	if(m_sStr)
65 		::SysFreeString(m_sStr);
66 }
67 OLEString& OLEString::operator=(const ::rtl::OUString& _rSrc)
68 {
69 	if(m_sStr)
70 		::SysFreeString(m_sStr);
71 	m_sStr = ::SysAllocString(reinterpret_cast<LPCOLESTR>(_rSrc.getStr()));
72 	return *this;
73 }
74 OLEString& OLEString::operator=(const OLEString& _rSrc)
75 {
76 	if(this != &_rSrc)
77 	{
78 		if(m_sStr)
79 			::SysFreeString(m_sStr);
80 		m_sStr = ::SysAllocString(_rSrc.m_sStr);
81 	}
82 	return *this;
83 }
84 OLEString& OLEString::operator=(const BSTR& _rSrc)
85 {
86 	if(m_sStr)
87 		::SysFreeString(m_sStr);
88 	m_sStr = _rSrc;
89 	return *this;
90 }
91 OLEString::operator ::rtl::OUString() const
92 {
93 	return (m_sStr != NULL) ? ::rtl::OUString(reinterpret_cast<const sal_Unicode*>(LPCOLESTR(m_sStr)),::SysStringLen(m_sStr)) : ::rtl::OUString();
94 }
95 OLEString::operator BSTR() const
96 {
97 	return m_sStr;
98 }
99 BSTR* OLEString::operator &()
100 {
101 	return &m_sStr;
102 }
103 sal_Int32 OLEString::length() const
104 {
105 	return (m_sStr != NULL) ? ::SysStringLen(m_sStr) : 0;
106 }
107 
108 OLEVariant::OLEVariant()
109 {
110 	VariantInit(this);
111 }
112 OLEVariant::OLEVariant(const VARIANT& varSrc)
113 {
114 	::VariantInit(this);
115 	HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(&varSrc));
116 	OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
117     OSL_UNUSED(eRet);
118 }
119 OLEVariant::OLEVariant(const OLEVariant& varSrc)
120 {
121 	::VariantInit(this);
122 	HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)));
123 	OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
124     OSL_UNUSED(eRet);
125 }
126 
127 OLEVariant::OLEVariant(sal_Bool x)				{	VariantInit(this);	vt = VT_BOOL;	boolVal		= (x ? VARIANT_TRUE : VARIANT_FALSE);}
128 OLEVariant::OLEVariant(sal_Int8 n)				{	VariantInit(this);	vt = VT_I1;		bVal		= n;}
129 OLEVariant::OLEVariant(sal_Int16 n)				{	VariantInit(this);	vt = VT_I2;		intVal		= n;}
130 OLEVariant::OLEVariant(sal_Int32 n)				{	VariantInit(this);	vt = VT_I4;		lVal		= n;}
131 OLEVariant::OLEVariant(sal_Int64 x)				{	VariantInit(this);	vt = VT_I4;		lVal		= (LONG)x;}
132 
133 OLEVariant::OLEVariant(const rtl::OUString& us)
134 {
135 	::VariantInit(this);
136 	vt		= VT_BSTR;
137 	bstrVal	= SysAllocString(reinterpret_cast<LPCOLESTR>(us.getStr()));
138 }
139 OLEVariant::~OLEVariant()
140 {
141 	HRESULT eRet = ::VariantClear(this);
142 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
143     OSL_UNUSED(eRet);
144 } // clears all the memory that was allocated before
145 
146 OLEVariant::OLEVariant(const ::com::sun::star::util::Date& x )
147 {
148 	VariantInit(this);
149 	vt		= VT_DATE;
150 	dblVal	= ::dbtools::DBTypeConversion::toDouble(x,::com::sun::star::util::Date(30,12,1899));
151 }
152 OLEVariant::OLEVariant(const ::com::sun::star::util::Time& x )
153 {
154 	VariantInit(this);
155 	vt		= VT_DATE;
156 	dblVal	= ::dbtools::DBTypeConversion::toDouble(x);
157 }
158 OLEVariant::OLEVariant(const ::com::sun::star::util::DateTime& x )
159 {
160 	VariantInit(this);
161 	vt		= VT_DATE;
162 	dblVal	= ::dbtools::DBTypeConversion::toDouble(x,::com::sun::star::util::Date(30,12,1899));
163 }
164 OLEVariant::OLEVariant(const float &x)
165 {
166 	VariantInit(this);
167 	vt		= VT_R4;
168 	fltVal	= x;
169 }
170 OLEVariant::OLEVariant(const double &x)
171 {
172 	VariantInit(this);
173 	vt		= VT_R8;
174 	dblVal	= x;
175 }
176 
177 
178 OLEVariant::OLEVariant(IDispatch* pDispInterface)
179 {
180 	VariantInit(this);
181 	setIDispatch( pDispInterface );
182 }
183 
184 OLEVariant::OLEVariant(const ::com::sun::star::uno::Sequence< sal_Int8 >& x)
185 {
186 	VariantInit(this);
187 
188 	vt		= VT_ARRAY|VT_UI1;
189 
190     SAFEARRAYBOUND rgsabound[1];
191     rgsabound[0].lLbound = 0;
192 	rgsabound[0].cElements = x.getLength();
193     //	parray	= SafeArrayCreate(VT_UI1,1,rgsabound);
194 	parray	= SafeArrayCreateVector(VT_UI1, 0, x.getLength());
195 	const sal_Int8* pBegin = x.getConstArray();
196 	const sal_Int8* pEnd = pBegin + x.getLength();
197 
198 	for(sal_Int32 i=0;pBegin != pEnd;++i,++pBegin)
199 	{
200 		sal_Int32 nData = *pBegin;
201 		HRESULT rs = SafeArrayPutElement(parray,&i,&nData);
202 		OSL_ENSURE(S_OK == rs,"Error while copy byte data");
203         OSL_UNUSED(rs);
204 	}
205 }
206 //
207 OLEVariant& OLEVariant::operator=(const OLEVariant& varSrc)
208 {
209 	HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)));
210 	OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
211     OSL_UNUSED(eRet);
212 	return *this;
213 }
214 // Assign a const VARIANT& (::VariantCopy handles everything)
215 //
216 OLEVariant& OLEVariant::operator=(const tagVARIANT& varSrc)
217 {
218 	HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(&varSrc));
219 	OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
220     OSL_UNUSED(eRet);
221 
222 	return *this;
223 }
224 
225 // Assign a const VARIANT* (::VariantCopy handles everything)
226 //
227 OLEVariant& OLEVariant::operator=(const VARIANT* pSrc)
228 {
229 	HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(pSrc));
230 	OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
231     OSL_UNUSED(eRet);
232 
233 	return *this;
234 }
235 
236 void OLEVariant::setByte(sal_uInt8 n)
237 {
238 	HRESULT eRet = VariantClear(this);
239 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
240     OSL_UNUSED(eRet);
241 	vt = VT_UI1;
242 	bVal = n;
243 }
244 void OLEVariant::setInt16(sal_Int16 n)
245 {
246 	HRESULT eRet = VariantClear(this);
247 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
248     OSL_UNUSED(eRet);
249 	vt		= VT_I2;
250 	iVal	= n;
251 }
252 void OLEVariant::setInt32(sal_Int32 n)
253 {
254 	HRESULT eRet = VariantClear(this);
255 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
256     OSL_UNUSED(eRet);
257 	vt		= VT_I4;
258 	lVal	= n;
259 }
260 void OLEVariant::setFloat(float f)
261 {	HRESULT eRet = VariantClear(this);
262 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
263     OSL_UNUSED(eRet);
264 	vt		= VT_R4;
265 	fltVal	= f;
266 }
267 void OLEVariant::setDouble(double d)
268 {
269 	HRESULT eRet = VariantClear(this);
270 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
271     OSL_UNUSED(eRet);
272 	vt		= VT_R8;
273 	dblVal	= d;
274 }
275 void OLEVariant::setDate(DATE d)
276 {	HRESULT eRet = VariantClear(this);
277 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
278     OSL_UNUSED(eRet);
279 	vt		= VT_DATE;
280 	date	= d;
281 }
282 void OLEVariant::setChar(unsigned char a)
283 {
284 	HRESULT eRet = VariantClear(this);
285 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
286     OSL_UNUSED(eRet);
287 	vt = VT_UI1;
288 	bVal		= a;
289 }
290 void OLEVariant::setCurrency(double aCur)
291 {
292 	HRESULT eRet = VariantClear(this);
293 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
294     OSL_UNUSED(eRet);
295 	vt = VT_CY;
296 	set(aCur*10000);
297 }
298 void OLEVariant::setBool(sal_Bool b)
299 {
300 	HRESULT eRet = VariantClear(this);
301 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
302     OSL_UNUSED(eRet);
303 	vt = VT_BOOL;
304 	boolVal		= b ? VARIANT_TRUE : VARIANT_FALSE;
305 }
306 void OLEVariant::setString(const rtl::OUString& us)
307 {
308 	HRESULT eRet = VariantClear(this);
309 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
310     OSL_UNUSED(eRet);
311 	vt = VT_BSTR;
312 	bstrVal		= ::SysAllocString(reinterpret_cast<LPCOLESTR>(us.getStr()));
313 }
314 void OLEVariant::setNoArg()
315 {
316 	HRESULT eRet = VariantClear(this);
317 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
318     OSL_UNUSED(eRet);
319 	vt = VT_ERROR;
320 	scode		= DISP_E_PARAMNOTFOUND;
321 }
322 
323 void OLEVariant::setNull()
324 {
325 	HRESULT eRet = VariantClear(this);
326 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
327     OSL_UNUSED(eRet);
328 	vt = VT_NULL;
329 }
330 void OLEVariant::setEmpty()
331 {
332 	HRESULT eRet = VariantClear(this);
333 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
334     OSL_UNUSED(eRet);
335 	vt = VT_EMPTY;
336 }
337 
338 void OLEVariant::setUI1SAFEARRAYPtr(SAFEARRAY* pSafeAr)
339 {
340 	HRESULT eRet = VariantClear(this);
341 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
342     OSL_UNUSED(eRet);
343 	vt = VT_ARRAY|VT_UI1; parray = pSafeAr;
344 }
345 
346 void OLEVariant::setArray(SAFEARRAY* pSafeArray, VARTYPE vtType)
347 {
348 	HRESULT eRet = VariantClear(this);
349 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
350     OSL_UNUSED(eRet);
351 	vt = (VARTYPE)(VT_ARRAY|vtType);
352 	parray = pSafeArray;
353 }
354 
355 void OLEVariant::setIDispatch(IDispatch* pDispInterface)
356 {
357 	HRESULT eRet = VariantClear(this);
358 	OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
359     OSL_UNUSED(eRet);
360 
361 	vt = VT_DISPATCH;
362 	pdispVal = pDispInterface;
363 
364 	if ( pDispInterface )
365 		pDispInterface->AddRef();
366 }
367 
368 
369 sal_Bool OLEVariant::isNull() const  {	return (vt == VT_NULL);		}
370 sal_Bool OLEVariant::isEmpty() const {	return (vt == VT_EMPTY);	}
371 
372 VARTYPE OLEVariant::getType() const { return vt; }
373 
374 OLEVariant::operator ::com::sun::star::util::Date() const
375 {
376 	return isNull() ? ::com::sun::star::util::Date(30,12,1899) : ::dbtools::DBTypeConversion::toDate(getDate(),::com::sun::star::util::Date(30,12,1899));
377 }
378 OLEVariant::operator ::com::sun::star::util::Time()	const
379 {
380 	return isNull() ? ::com::sun::star::util::Time() : ::dbtools::DBTypeConversion::toTime(getDate());
381 }
382 OLEVariant::operator ::com::sun::star::util::DateTime()const
383 {
384 	return isNull() ? ::com::sun::star::util::DateTime() : ::dbtools::DBTypeConversion::toDateTime(getDate(),::com::sun::star::util::Date(30,12,1899));
385 }
386 
387 VARIANT_BOOL OLEVariant::VariantBool(sal_Bool bEinBoolean)
388 {
389 	return (bEinBoolean ? VARIANT_TRUE : VARIANT_FALSE);
390 }
391 
392 void OLEVariant::CHS()
393 {
394 	cyVal.Lo  ^= (sal_uInt32)-1;
395 	cyVal.Hi ^= -1;
396 	cyVal.Lo++;
397 	if( !cyVal.Lo )
398 		cyVal.Hi++;
399 }
400 
401 void OLEVariant::set(double n)
402 {
403 	if( n >= 0 )
404 	{
405 		cyVal.Hi = (sal_Int32)(n / (double)4294967296.0);
406 		cyVal.Lo  = (sal_uInt32)(n - ((double)cyVal.Hi * (double)4294967296.0));
407 	}
408 	else {
409 		cyVal.Hi = (sal_Int32)(-n / (double)4294967296.0);
410 		cyVal.Lo  = (sal_uInt32)(-n - ((double)cyVal.Hi * (double)4294967296.0));
411 		CHS();
412 	}
413 }
414 
415 OLEVariant::operator rtl::OUString() const
416 {
417 	if (V_VT(this) == VT_BSTR)
418 		return reinterpret_cast<const sal_Unicode*>(LPCOLESTR(V_BSTR(this)));
419 
420 	if(isNull())
421 		return ::rtl::OUString();
422 
423 	OLEVariant varDest;
424 
425 	varDest.ChangeType(VT_BSTR, this);
426 
427 	return reinterpret_cast<const sal_Unicode*>(LPCOLESTR(V_BSTR(&varDest)));
428 }
429 
430 // -----------------------------------------------------------------------------
431 void OLEVariant::ChangeType(VARTYPE vartype, const OLEVariant* pSrc)
432 {
433 	//
434 	// If pDest is NULL, convert type in place
435 	//
436 	if (pSrc == NULL)
437 		pSrc = this;
438 
439 	if	(	( this != pSrc )
440 		||	( vartype != V_VT( this ) )
441 		)
442 	{
443 		if ( FAILED( ::VariantChangeType(	static_cast< VARIANT* >( this ),
444 											const_cast< VARIANT* >( static_cast< const VARIANT* >( pSrc ) ),
445 											0,
446 											vartype ) ) )
447 		{
448             ::connectivity::SharedResources aResources;
449             const ::rtl::OUString sError( aResources.getResourceString(STR_TYPE_NOT_CONVERT));
450 			throw ::com::sun::star::sdbc::SQLException(
451 				sError,
452 				NULL,
453 				::rtl::OUString::createFromAscii( "S1000" ),
454 				1000,
455 				::com::sun::star::uno::Any()
456 			);
457 		}
458 	}
459 }
460 
461 // -----------------------------------------------------------------------------
462 OLEVariant::operator ::com::sun::star::uno::Sequence< sal_Int8 >() const
463 {
464 	::com::sun::star::uno::Sequence< sal_Int8 > aRet;
465 	if(V_VT(this) == VT_BSTR)
466 	{
467 		OLEString sStr(V_BSTR(this));
468 		aRet = ::com::sun::star::uno::Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>((const wchar_t*)sStr),sizeof(sal_Unicode)*sStr.length());
469 	}
470 	else if(!isNull())
471 	{
472 		SAFEARRAY* pArray = getUI1SAFEARRAYPtr();
473 
474 		if(pArray)
475 		{
476 			HRESULT hresult1,hresult2;
477 			long lBound,uBound;
478 			// Verify that the SafeArray is the proper shape.
479 			hresult1 = ::SafeArrayGetLBound(pArray, 1, &lBound);
480 			hresult2 = ::SafeArrayGetUBound(pArray, 1, &uBound);
481 			if ( SUCCEEDED(hresult1) && SUCCEEDED(hresult2) )
482 			{
483 				long nCount = uBound-lBound+1;
484 				aRet.realloc(nCount);
485 				sal_Int8* pData = aRet.getArray();
486 				for(long i=0; SUCCEEDED(hresult1) && lBound <= uBound ;++i,++lBound)
487 				{
488 					sal_Int32 nData = 0;
489 					hresult1 = ::SafeArrayGetElement(pArray,&lBound,&nData);
490 					if ( SUCCEEDED(hresult1) )
491 					{
492 						*pData = static_cast<sal_Int8>(nData);
493 						++pData;
494 					}
495 				}
496 			}
497 		}
498 	}
499 
500 	return aRet;
501 }
502 // -----------------------------------------------------------------------------
503 ::rtl::OUString OLEVariant::getString() const
504 {
505 	if(isNull())
506 		return ::rtl::OUString();
507 	else
508 		return *this;
509 }
510 // -----------------------------------------------------------------------------
511 sal_Bool OLEVariant::getBool() const
512 {
513 	if (V_VT(this) == VT_BOOL)
514 		return V_BOOL(this) == VARIANT_TRUE ? sal_True : sal_False;
515 	if(isNull())
516 		return sal_False;
517 
518 	OLEVariant varDest;
519 
520 	varDest.ChangeType(VT_BOOL, this);
521 
522 	return V_BOOL(&varDest) == VARIANT_TRUE ? sal_True : sal_False;
523 }
524 // -----------------------------------------------------------------------------
525 IUnknown* OLEVariant::getIUnknown() const
526 {
527 	if (V_VT(this) == VT_UNKNOWN)
528 	{
529 		return V_UNKNOWN(this);
530 	}
531 	if(isNull())
532 		return NULL;
533 
534 	OLEVariant varDest;
535 
536 	varDest.ChangeType(VT_UNKNOWN, this);
537 
538 	V_UNKNOWN(&varDest)->AddRef();
539 	return V_UNKNOWN(&varDest);
540 }
541 // -----------------------------------------------------------------------------
542 IDispatch* OLEVariant::getIDispatch() const
543 {
544 	if (V_VT(this) == VT_DISPATCH)
545 	{
546 		return V_DISPATCH(this);
547 	}
548 
549 	if(isNull())
550 		return NULL;
551 
552 	OLEVariant varDest;
553 
554 	varDest.ChangeType(VT_DISPATCH, this);
555 
556 	V_DISPATCH(&varDest)->AddRef();
557 	return V_DISPATCH(&varDest);
558 }
559 // -----------------------------------------------------------------------------
560 sal_uInt8 OLEVariant::getByte() const
561 {
562 	if (V_VT(this) == VT_UI1)
563 		return V_UI1(this);
564 
565 	if(isNull())
566 		return sal_Int8(0);
567 	OLEVariant varDest;
568 
569 	varDest.ChangeType(VT_UI1, this);
570 
571 	return V_UI1(&varDest);
572 }
573 // -----------------------------------------------------------------------------
574 sal_Int16 OLEVariant::getInt16() const
575 {
576 	if (V_VT(this) == VT_I2)
577 		return V_I2(this);
578 
579 	if(isNull())
580 		return sal_Int16(0);
581 	OLEVariant varDest;
582 
583 	varDest.ChangeType(VT_I2, this);
584 
585 	return V_I2(&varDest);
586 }
587 // -----------------------------------------------------------------------------
588 sal_Int8 OLEVariant::getInt8() const
589 {
590 	if (V_VT(this) == VT_I1)
591 		return V_I1(this);
592 
593 	if(isNull())
594 		return sal_Int8(0);
595 
596 	OLEVariant varDest;
597 
598 	varDest.ChangeType(VT_I1, this);
599 
600 	return V_I1(&varDest);
601 }
602 // -----------------------------------------------------------------------------
603 sal_Int32 OLEVariant::getInt32() const
604 {
605 	if (V_VT(this) == VT_I4)
606 		return V_I4(this);
607 
608 	if(isNull())
609 		return sal_Int32(0);
610 
611 	OLEVariant varDest;
612 
613 	varDest.ChangeType(VT_I4, this);
614 
615 	return V_I4(&varDest);
616 }
617 // -----------------------------------------------------------------------------
618 sal_uInt32 OLEVariant::getUInt32() const
619 {
620 	if (V_VT(this) == VT_UI4)
621 		return V_UI4(this);
622 
623 	if(isNull())
624 		return sal_uInt32(0);
625 
626 	OLEVariant varDest;
627 
628 	varDest.ChangeType(VT_UI4, this);
629 
630 	return V_UI4(&varDest);
631 }
632 // -----------------------------------------------------------------------------
633 float OLEVariant::getFloat() const
634 {
635 	if (V_VT(this) == VT_R4)
636 		return V_R4(this);
637 
638 	if(isNull())
639 		return float(0);
640 	OLEVariant varDest;
641 
642 	varDest.ChangeType(VT_R4, this);
643 
644 	return V_R4(&varDest);
645 }
646 // -----------------------------------------------------------------------------
647 double OLEVariant::getDouble() const
648 {
649 	if (V_VT(this) == VT_R8)
650 		return V_R8(this);
651 
652 	if(isNull())
653 		return double(0);
654 	OLEVariant varDest;
655 
656 	varDest.ChangeType(VT_R8, this);
657 
658 	return V_R8(&varDest);
659 }
660 // -----------------------------------------------------------------------------
661 double OLEVariant::getDate() const
662 {
663 	if (V_VT(this) == VT_DATE)
664 		return V_DATE(this);
665 
666 	if(isNull())
667 		return double(0);
668 	OLEVariant varDest;
669 
670 	varDest.ChangeType(VT_DATE, this);
671 
672 	return V_DATE(&varDest);
673 }
674 // -----------------------------------------------------------------------------
675 CY OLEVariant::getCurrency() const
676 {
677 	if (V_VT(this) == VT_CY)
678 		return V_CY(this);
679 
680 	if(isNull())
681 	{
682 		CY aVar;
683 		aVar.int64 = sal_Int64(0);
684 		return aVar;
685 	}
686 	OLEVariant varDest;
687 
688 	varDest.ChangeType(VT_CY, this);
689 
690 	return V_CY(&varDest);
691 }
692 // -----------------------------------------------------------------------------
693 SAFEARRAY* OLEVariant::getUI1SAFEARRAYPtr() const
694 {
695 	if (V_VT(this) == (VT_ARRAY|VT_UI1))
696 		return V_ARRAY(this);
697 
698 	if(isNull())
699 		return (0);
700 	OLEVariant varDest;
701 
702 	varDest.ChangeType((VT_ARRAY|VT_UI1), this);
703 
704 	return V_ARRAY(&varDest);
705 }
706 // -----------------------------------------------------------------------------
707 ::com::sun::star::uno::Any OLEVariant::makeAny() const
708 {
709     ::com::sun::star::uno::Any aValue;
710     switch (V_VT(this))
711     {
712 	    case VT_EMPTY:
713 	    case VT_NULL:
714 		    aValue.setValue(NULL, Type());
715 		    break;
716 	    case VT_I2:
717 		    aValue.setValue( & iVal, getCppuType( (sal_Int16*)0));
718 		    break;
719 	    case VT_I4:
720 		    aValue.setValue( & lVal, getCppuType( (sal_Int32*)0));
721 		    break;
722 	    case VT_R4:
723 		    aValue.setValue( & fltVal, getCppuType( (float*)0));
724 		    break;
725 	    case VT_R8:
726 		    aValue.setValue(& dblVal, getCppuType( (double*)0));
727 		    break;
728 	    case VT_CY:
729          {
730              Currency cy(cyVal.int64);
731              aValue <<= cy;
732 		    break;
733          }
734 	    case VT_DATE:
735          {
736              aValue <<= (::com::sun::star::util::Date)*this;
737 		    break;
738          }
739 	    case VT_BSTR:
740 	    {
741 		    OUString b(reinterpret_cast<const sal_Unicode*>(bstrVal));
742 		    aValue.setValue( &b, getCppuType( &b));
743 		    break;
744 	    }
745 	    case VT_BOOL:
746 	    {
747 		    sal_Bool b= boolVal == VARIANT_TRUE;
748 		    aValue.setValue( &b, getCppuType( &b));
749 		    break;
750 	    }
751 	    case VT_I1:
752 		    aValue.setValue( & cVal, getCppuType((sal_Int8*)0));
753 		    break;
754 	    case VT_UI1: // there is no unsigned char in UNO
755 		    aValue.setValue( & bVal, getCppuType( (sal_Int8*)0));
756 		    break;
757 	    case VT_UI2:
758 		    aValue.setValue( & uiVal, getCppuType( (sal_uInt16*)0));
759 		    break;
760 	    case VT_UI4:
761 		    aValue.setValue( & ulVal, getCppuType( (sal_uInt32*)0));
762 		    break;
763 	    case VT_INT:
764 		    aValue.setValue( & intVal, getCppuType( (sal_Int32*)0));
765 		    break;
766 	    case VT_UINT:
767 		    aValue.setValue( & uintVal, getCppuType( (sal_uInt32*)0));
768 		    break;
769 	    case VT_VOID:
770 		    aValue.setValue( NULL, Type());
771 		    break;
772          case VT_DECIMAL:
773          {
774              Decimal dec;
775              dec.Scale = decVal.scale;
776              dec.Sign = decVal.sign;
777              dec.LowValue = decVal.Lo32;
778              dec.MiddleValue = decVal.Mid32;
779              dec.HighValue = decVal.Hi32;
780              aValue <<= dec;
781              break;
782          }
783 
784 	    default:
785 		    break;
786     }
787     return aValue;
788 }
789 // -----------------------------------------------------------------------------
790 // -----------------------------------------------------------------------------
791 // -----------------------------------------------------------------------------
792