1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
33 using namespace fileaccess
;
34 using namespace com::sun::star
;
35 using namespace com::sun::star::uno
;
37 // Funktion for TypeConverting
40 template< class _type_
>
41 sal_Bool
convert( shell
* pShell
,
42 uno::Reference
< script::XTypeConverter
>& xConverter
,
46 // Try first without converting
47 sal_Bool no_success
= ! ( rValue
>>= aReturn
);
51 if( ! xConverter
.is() )
53 xConverter
= uno::Reference
< script::XTypeConverter
>(
54 pShell
->m_xMultiServiceFactory
->createInstance(
55 rtl::OUString("com.sun.star.script.Converter") ), uno::UNO_QUERY
);
60 if( rValue
.hasValue() )
62 uno::Any aConvertedValue
63 = xConverter
->convertTo( rValue
,getCppuType( static_cast< const _type_
* >(0) ) );
64 no_success
= ! ( aConvertedValue
>>= aReturn
);
67 no_success
= sal_True
;
69 catch (const lang::IllegalArgumentException
&)
71 no_success
= sal_True
;
73 catch (const script::CannotConvertException
&)
75 no_success
= sal_True
;
82 XRow_impl::XRow_impl( shell
* pMyShell
,const uno::Sequence
< uno::Any
>& seq
)
84 m_pMyShell( pMyShell
),
85 m_xProvider( pMyShell
->m_pProvider
),
90 XRow_impl::~XRow_impl()
100 OWeakObject::acquire();
108 OWeakObject::release();
113 XRow_impl::queryInterface(
114 const uno::Type
& rType
)
115 throw( uno::RuntimeException
)
117 uno::Any aRet
= cppu::queryInterface( rType
,
118 (static_cast< lang::XTypeProvider
* >(this)),
119 (static_cast< sdbc::XRow
* >(this)) );
120 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
124 XTYPEPROVIDER_IMPL_2( XRow_impl
,
132 throw( sdbc::SQLException
,
133 uno::RuntimeException
)
139 rtl::OUString SAL_CALL
140 XRow_impl::getString(
141 sal_Int32 columnIndex
)
142 throw( sdbc::SQLException
,
143 uno::RuntimeException
)
145 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
146 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
148 osl::MutexGuard
aGuard( m_aMutex
);
149 m_nWasNull
= ::convert
<rtl::OUString
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
154 XRow_impl::getBoolean(
155 sal_Int32 columnIndex
)
156 throw( sdbc::SQLException
,
157 uno::RuntimeException
)
159 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
160 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
161 sal_Bool
Value( false );
162 osl::MutexGuard
aGuard( m_aMutex
);
163 m_nWasNull
= ::convert
<sal_Bool
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
170 sal_Int32 columnIndex
)
171 throw( sdbc::SQLException
,
172 uno::RuntimeException
)
174 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
175 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
177 osl::MutexGuard
aGuard( m_aMutex
);
178 m_nWasNull
= ::convert
<sal_Int8
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
184 sal_Int32 columnIndex
)
185 throw( sdbc::SQLException
,
186 uno::RuntimeException
)
188 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
189 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
190 sal_Int16
Value( 0 );
191 osl::MutexGuard
aGuard( m_aMutex
);
192 m_nWasNull
= ::convert
<sal_Int16
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
199 sal_Int32 columnIndex
)
200 throw( sdbc::SQLException
,
201 uno::RuntimeException
)
203 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
204 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
205 sal_Int32
Value( 0 );
206 osl::MutexGuard
aGuard( m_aMutex
);
207 m_nWasNull
= ::convert
<sal_Int32
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
213 sal_Int32 columnIndex
)
214 throw( sdbc::SQLException
,
215 uno::RuntimeException
)
217 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
218 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
219 sal_Int64
Value( 0 );
220 osl::MutexGuard
aGuard( m_aMutex
);
221 m_nWasNull
= ::convert
<sal_Int64
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
227 sal_Int32 columnIndex
)
228 throw( sdbc::SQLException
,
229 uno::RuntimeException
)
231 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
232 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
234 osl::MutexGuard
aGuard( m_aMutex
);
235 m_nWasNull
= ::convert
<float>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
240 XRow_impl::getDouble(
241 sal_Int32 columnIndex
)
242 throw( sdbc::SQLException
,
243 uno::RuntimeException
)
245 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
246 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
248 osl::MutexGuard
aGuard( m_aMutex
);
249 m_nWasNull
= ::convert
<double>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
253 uno::Sequence
< sal_Int8
> SAL_CALL
255 sal_Int32 columnIndex
)
256 throw( sdbc::SQLException
,
257 uno::RuntimeException
)
259 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
260 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
261 uno::Sequence
< sal_Int8
> Value(0);
262 osl::MutexGuard
aGuard( m_aMutex
);
263 m_nWasNull
= ::convert
<uno::Sequence
< sal_Int8
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
269 sal_Int32 columnIndex
)
270 throw( sdbc::SQLException
,
271 uno::RuntimeException
)
273 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
274 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
276 osl::MutexGuard
aGuard( m_aMutex
);
277 m_nWasNull
= ::convert
<util::Date
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
283 sal_Int32 columnIndex
)
284 throw( sdbc::SQLException
,
285 uno::RuntimeException
)
287 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
288 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
290 osl::MutexGuard
aGuard( m_aMutex
);
291 m_nWasNull
= ::convert
<util::Time
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
295 util::DateTime SAL_CALL
296 XRow_impl::getTimestamp(
297 sal_Int32 columnIndex
)
298 throw( sdbc::SQLException
,
299 uno::RuntimeException
)
301 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
302 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
303 util::DateTime Value
;
304 osl::MutexGuard
aGuard( m_aMutex
);
305 m_nWasNull
= ::convert
<util::DateTime
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
310 uno::Reference
< io::XInputStream
> SAL_CALL
311 XRow_impl::getBinaryStream(
312 sal_Int32 columnIndex
)
313 throw( sdbc::SQLException
,
314 uno::RuntimeException
)
316 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
317 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
318 uno::Reference
< io::XInputStream
> Value
;
319 osl::MutexGuard
aGuard( m_aMutex
);
320 m_nWasNull
= ::convert
<uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
325 uno::Reference
< io::XInputStream
> SAL_CALL
326 XRow_impl::getCharacterStream(
327 sal_Int32 columnIndex
)
328 throw( sdbc::SQLException
,
329 uno::RuntimeException
)
331 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
332 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
333 uno::Reference
< io::XInputStream
> Value
;
334 osl::MutexGuard
aGuard( m_aMutex
);
335 m_nWasNull
= ::convert
< uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
341 XRow_impl::getObject(
342 sal_Int32 columnIndex
,
343 const uno::Reference
< container::XNameAccess
>& )
344 throw( sdbc::SQLException
,
345 uno::RuntimeException
)
347 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
348 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
350 osl::MutexGuard
aGuard( m_aMutex
);
351 m_nWasNull
= ::convert
<uno::Any
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
355 uno::Reference
< sdbc::XRef
> SAL_CALL
357 sal_Int32 columnIndex
)
358 throw( sdbc::SQLException
,
359 uno::RuntimeException
)
361 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
362 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
363 uno::Reference
< sdbc::XRef
> Value
;
364 osl::MutexGuard
aGuard( m_aMutex
);
365 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XRef
> >( m_pMyShell
,
367 m_aValueMap
[ --columnIndex
],
372 uno::Reference
< sdbc::XBlob
> SAL_CALL
374 sal_Int32 columnIndex
)
375 throw( sdbc::SQLException
,
376 uno::RuntimeException
)
378 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
379 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
380 uno::Reference
< sdbc::XBlob
> Value
;
381 osl::MutexGuard
aGuard( m_aMutex
);
382 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XBlob
> >( m_pMyShell
,
384 m_aValueMap
[ --columnIndex
],
389 uno::Reference
< sdbc::XClob
> SAL_CALL
391 sal_Int32 columnIndex
)
392 throw( sdbc::SQLException
,
393 uno::RuntimeException
)
395 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
396 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
397 uno::Reference
< sdbc::XClob
> Value
;
398 osl::MutexGuard
aGuard( m_aMutex
);
399 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XClob
> >( m_pMyShell
,
401 m_aValueMap
[ --columnIndex
],
407 uno::Reference
< sdbc::XArray
> SAL_CALL
409 sal_Int32 columnIndex
)
410 throw( sdbc::SQLException
,
411 uno::RuntimeException
)
413 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
414 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
415 uno::Reference
< sdbc::XArray
> Value
;
416 osl::MutexGuard
aGuard( m_aMutex
);
417 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XArray
> >( m_pMyShell
,
419 m_aValueMap
[ --columnIndex
],
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */