1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <com/sun/star/script/Converter.hpp>
24 #include <comphelper/processfactory.hxx>
26 using namespace fileaccess
;
27 using namespace com::sun::star
;
28 using namespace com::sun::star::uno
;
30 // Funktion for TypeConverting
33 template< class _type_
>
34 sal_Bool
convert( shell
* pShell
,
35 uno::Reference
< script::XTypeConverter
>& xConverter
,
39 // Try first without converting
40 sal_Bool no_success
= ! ( rValue
>>= aReturn
);
44 if( ! xConverter
.is() )
46 xConverter
= script::Converter::create(pShell
->m_xContext
);
51 if( rValue
.hasValue() )
53 uno::Any aConvertedValue
54 = xConverter
->convertTo( rValue
,getCppuType( static_cast< const _type_
* >(0) ) );
55 no_success
= ! ( aConvertedValue
>>= aReturn
);
58 no_success
= sal_True
;
60 catch (const lang::IllegalArgumentException
&)
62 no_success
= sal_True
;
64 catch (const script::CannotConvertException
&)
66 no_success
= sal_True
;
73 XRow_impl::XRow_impl( shell
* pMyShell
,const uno::Sequence
< uno::Any
>& seq
)
75 m_pMyShell( pMyShell
),
76 m_xProvider( pMyShell
->m_pProvider
),
81 XRow_impl::~XRow_impl()
91 OWeakObject::acquire();
99 OWeakObject::release();
104 XRow_impl::queryInterface(
105 const uno::Type
& rType
)
106 throw( uno::RuntimeException
)
108 uno::Any aRet
= cppu::queryInterface( rType
,
109 (static_cast< lang::XTypeProvider
* >(this)),
110 (static_cast< sdbc::XRow
* >(this)) );
111 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
115 XTYPEPROVIDER_IMPL_2( XRow_impl
,
123 throw( sdbc::SQLException
,
124 uno::RuntimeException
)
130 rtl::OUString SAL_CALL
131 XRow_impl::getString(
132 sal_Int32 columnIndex
)
133 throw( sdbc::SQLException
,
134 uno::RuntimeException
)
136 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
137 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
139 osl::MutexGuard
aGuard( m_aMutex
);
140 m_nWasNull
= ::convert
<rtl::OUString
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
145 XRow_impl::getBoolean(
146 sal_Int32 columnIndex
)
147 throw( sdbc::SQLException
,
148 uno::RuntimeException
)
150 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
151 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
152 sal_Bool
Value( false );
153 osl::MutexGuard
aGuard( m_aMutex
);
154 m_nWasNull
= ::convert
<sal_Bool
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
161 sal_Int32 columnIndex
)
162 throw( sdbc::SQLException
,
163 uno::RuntimeException
)
165 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
166 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
168 osl::MutexGuard
aGuard( m_aMutex
);
169 m_nWasNull
= ::convert
<sal_Int8
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
175 sal_Int32 columnIndex
)
176 throw( sdbc::SQLException
,
177 uno::RuntimeException
)
179 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
180 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
181 sal_Int16
Value( 0 );
182 osl::MutexGuard
aGuard( m_aMutex
);
183 m_nWasNull
= ::convert
<sal_Int16
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
190 sal_Int32 columnIndex
)
191 throw( sdbc::SQLException
,
192 uno::RuntimeException
)
194 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
195 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
196 sal_Int32
Value( 0 );
197 osl::MutexGuard
aGuard( m_aMutex
);
198 m_nWasNull
= ::convert
<sal_Int32
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
204 sal_Int32 columnIndex
)
205 throw( sdbc::SQLException
,
206 uno::RuntimeException
)
208 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
209 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
210 sal_Int64
Value( 0 );
211 osl::MutexGuard
aGuard( m_aMutex
);
212 m_nWasNull
= ::convert
<sal_Int64
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
218 sal_Int32 columnIndex
)
219 throw( sdbc::SQLException
,
220 uno::RuntimeException
)
222 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
223 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
225 osl::MutexGuard
aGuard( m_aMutex
);
226 m_nWasNull
= ::convert
<float>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
231 XRow_impl::getDouble(
232 sal_Int32 columnIndex
)
233 throw( sdbc::SQLException
,
234 uno::RuntimeException
)
236 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
237 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
239 osl::MutexGuard
aGuard( m_aMutex
);
240 m_nWasNull
= ::convert
<double>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
244 uno::Sequence
< sal_Int8
> SAL_CALL
246 sal_Int32 columnIndex
)
247 throw( sdbc::SQLException
,
248 uno::RuntimeException
)
250 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
251 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
252 uno::Sequence
< sal_Int8
> Value(0);
253 osl::MutexGuard
aGuard( m_aMutex
);
254 m_nWasNull
= ::convert
<uno::Sequence
< sal_Int8
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
260 sal_Int32 columnIndex
)
261 throw( sdbc::SQLException
,
262 uno::RuntimeException
)
264 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
265 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
267 osl::MutexGuard
aGuard( m_aMutex
);
268 m_nWasNull
= ::convert
<util::Date
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
274 sal_Int32 columnIndex
)
275 throw( sdbc::SQLException
,
276 uno::RuntimeException
)
278 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
279 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
281 osl::MutexGuard
aGuard( m_aMutex
);
282 m_nWasNull
= ::convert
<util::Time
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
286 util::DateTime SAL_CALL
287 XRow_impl::getTimestamp(
288 sal_Int32 columnIndex
)
289 throw( sdbc::SQLException
,
290 uno::RuntimeException
)
292 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
293 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
294 util::DateTime Value
;
295 osl::MutexGuard
aGuard( m_aMutex
);
296 m_nWasNull
= ::convert
<util::DateTime
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
301 uno::Reference
< io::XInputStream
> SAL_CALL
302 XRow_impl::getBinaryStream(
303 sal_Int32 columnIndex
)
304 throw( sdbc::SQLException
,
305 uno::RuntimeException
)
307 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
308 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
309 uno::Reference
< io::XInputStream
> Value
;
310 osl::MutexGuard
aGuard( m_aMutex
);
311 m_nWasNull
= ::convert
<uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
316 uno::Reference
< io::XInputStream
> SAL_CALL
317 XRow_impl::getCharacterStream(
318 sal_Int32 columnIndex
)
319 throw( sdbc::SQLException
,
320 uno::RuntimeException
)
322 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
323 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
324 uno::Reference
< io::XInputStream
> Value
;
325 osl::MutexGuard
aGuard( m_aMutex
);
326 m_nWasNull
= ::convert
< uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
332 XRow_impl::getObject(
333 sal_Int32 columnIndex
,
334 const uno::Reference
< container::XNameAccess
>& )
335 throw( sdbc::SQLException
,
336 uno::RuntimeException
)
338 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
339 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
341 osl::MutexGuard
aGuard( m_aMutex
);
342 m_nWasNull
= ::convert
<uno::Any
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
346 uno::Reference
< sdbc::XRef
> SAL_CALL
348 sal_Int32 columnIndex
)
349 throw( sdbc::SQLException
,
350 uno::RuntimeException
)
352 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
353 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
354 uno::Reference
< sdbc::XRef
> Value
;
355 osl::MutexGuard
aGuard( m_aMutex
);
356 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XRef
> >( m_pMyShell
,
358 m_aValueMap
[ --columnIndex
],
363 uno::Reference
< sdbc::XBlob
> SAL_CALL
365 sal_Int32 columnIndex
)
366 throw( sdbc::SQLException
,
367 uno::RuntimeException
)
369 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
370 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
371 uno::Reference
< sdbc::XBlob
> Value
;
372 osl::MutexGuard
aGuard( m_aMutex
);
373 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XBlob
> >( m_pMyShell
,
375 m_aValueMap
[ --columnIndex
],
380 uno::Reference
< sdbc::XClob
> SAL_CALL
382 sal_Int32 columnIndex
)
383 throw( sdbc::SQLException
,
384 uno::RuntimeException
)
386 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
387 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
388 uno::Reference
< sdbc::XClob
> Value
;
389 osl::MutexGuard
aGuard( m_aMutex
);
390 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XClob
> >( m_pMyShell
,
392 m_aValueMap
[ --columnIndex
],
398 uno::Reference
< sdbc::XArray
> SAL_CALL
400 sal_Int32 columnIndex
)
401 throw( sdbc::SQLException
,
402 uno::RuntimeException
)
404 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
405 throw sdbc::SQLException( ::rtl::OUString( OSL_LOG_PREFIX
), uno::Reference
< uno::XInterface
>(), ::rtl::OUString(), 0, uno::Any() );
406 uno::Reference
< sdbc::XArray
> Value
;
407 osl::MutexGuard
aGuard( m_aMutex
);
408 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XArray
> >( m_pMyShell
,
410 m_aValueMap
[ --columnIndex
],
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */