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 #if OSL_DEBUG_LEVEL > 0
31 #define THROW_WHERE SAL_WHERE
33 #define THROW_WHERE ""
36 // Function for TypeConverting
38 template< class _type_
>
39 bool convert( shell
* pShell
,
40 uno::Reference
< script::XTypeConverter
>& xConverter
,
44 // Try first without converting
45 bool no_success
= ! ( rValue
>>= aReturn
);
49 if( ! xConverter
.is() )
51 xConverter
= script::Converter::create(pShell
->m_xContext
);
56 if( rValue
.hasValue() )
58 uno::Any aConvertedValue
59 = xConverter
->convertTo( rValue
,cppu::UnoType
<_type_
>::get() );
60 no_success
= ! ( aConvertedValue
>>= aReturn
);
65 catch (const lang::IllegalArgumentException
&)
69 catch (const script::CannotConvertException
&)
78 XRow_impl::XRow_impl( shell
* pMyShell
,const uno::Sequence
< uno::Any
>& seq
)
81 m_pMyShell( pMyShell
),
82 m_xProvider( pMyShell
->m_pProvider
),
87 XRow_impl::~XRow_impl()
95 throw( sdbc::SQLException
,
96 uno::RuntimeException
, std::exception
)
103 XRow_impl::getString(
104 sal_Int32 columnIndex
)
105 throw( sdbc::SQLException
,
106 uno::RuntimeException
, std::exception
)
108 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
109 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
111 osl::MutexGuard
aGuard( m_aMutex
);
112 m_nWasNull
= ::convert
<OUString
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
117 XRow_impl::getBoolean(
118 sal_Int32 columnIndex
)
119 throw( sdbc::SQLException
,
120 uno::RuntimeException
, std::exception
)
122 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
123 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
125 osl::MutexGuard
aGuard( m_aMutex
);
126 m_nWasNull
= ::convert
<bool>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
133 sal_Int32 columnIndex
)
134 throw( sdbc::SQLException
,
135 uno::RuntimeException
, std::exception
)
137 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
138 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
140 osl::MutexGuard
aGuard( m_aMutex
);
141 m_nWasNull
= ::convert
<sal_Int8
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
147 sal_Int32 columnIndex
)
148 throw( sdbc::SQLException
,
149 uno::RuntimeException
, std::exception
)
151 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
152 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
153 sal_Int16
Value( 0 );
154 osl::MutexGuard
aGuard( m_aMutex
);
155 m_nWasNull
= ::convert
<sal_Int16
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
162 sal_Int32 columnIndex
)
163 throw( sdbc::SQLException
,
164 uno::RuntimeException
, std::exception
)
166 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
167 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
168 sal_Int32
Value( 0 );
169 osl::MutexGuard
aGuard( m_aMutex
);
170 m_nWasNull
= ::convert
<sal_Int32
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
176 sal_Int32 columnIndex
)
177 throw( sdbc::SQLException
,
178 uno::RuntimeException
, std::exception
)
180 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
181 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
182 sal_Int64
Value( 0 );
183 osl::MutexGuard
aGuard( m_aMutex
);
184 m_nWasNull
= ::convert
<sal_Int64
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
190 sal_Int32 columnIndex
)
191 throw( sdbc::SQLException
,
192 uno::RuntimeException
, std::exception
)
194 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
195 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
197 osl::MutexGuard
aGuard( m_aMutex
);
198 m_nWasNull
= ::convert
<float>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
203 XRow_impl::getDouble(
204 sal_Int32 columnIndex
)
205 throw( sdbc::SQLException
,
206 uno::RuntimeException
, std::exception
)
208 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
209 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
211 osl::MutexGuard
aGuard( m_aMutex
);
212 m_nWasNull
= ::convert
<double>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
216 uno::Sequence
< sal_Int8
> SAL_CALL
218 sal_Int32 columnIndex
)
219 throw( sdbc::SQLException
,
220 uno::RuntimeException
, std::exception
)
222 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
223 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
224 uno::Sequence
< sal_Int8
> Value(0);
225 osl::MutexGuard
aGuard( m_aMutex
);
226 m_nWasNull
= ::convert
<uno::Sequence
< sal_Int8
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
232 sal_Int32 columnIndex
)
233 throw( sdbc::SQLException
,
234 uno::RuntimeException
, std::exception
)
236 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
237 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
239 osl::MutexGuard
aGuard( m_aMutex
);
240 m_nWasNull
= ::convert
<util::Date
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
246 sal_Int32 columnIndex
)
247 throw( sdbc::SQLException
,
248 uno::RuntimeException
, std::exception
)
250 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
251 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
253 osl::MutexGuard
aGuard( m_aMutex
);
254 m_nWasNull
= ::convert
<util::Time
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
258 util::DateTime SAL_CALL
259 XRow_impl::getTimestamp(
260 sal_Int32 columnIndex
)
261 throw( sdbc::SQLException
,
262 uno::RuntimeException
, std::exception
)
264 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
265 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
266 util::DateTime Value
;
267 osl::MutexGuard
aGuard( m_aMutex
);
268 m_nWasNull
= ::convert
<util::DateTime
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
273 uno::Reference
< io::XInputStream
> SAL_CALL
274 XRow_impl::getBinaryStream(
275 sal_Int32 columnIndex
)
276 throw( sdbc::SQLException
,
277 uno::RuntimeException
, std::exception
)
279 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
280 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
281 uno::Reference
< io::XInputStream
> Value
;
282 osl::MutexGuard
aGuard( m_aMutex
);
283 m_nWasNull
= ::convert
<uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
288 uno::Reference
< io::XInputStream
> SAL_CALL
289 XRow_impl::getCharacterStream(
290 sal_Int32 columnIndex
)
291 throw( sdbc::SQLException
,
292 uno::RuntimeException
, std::exception
)
294 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
295 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
296 uno::Reference
< io::XInputStream
> Value
;
297 osl::MutexGuard
aGuard( m_aMutex
);
298 m_nWasNull
= ::convert
< uno::Reference
< io::XInputStream
> >( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
304 XRow_impl::getObject(
305 sal_Int32 columnIndex
,
306 const uno::Reference
< container::XNameAccess
>& )
307 throw( sdbc::SQLException
,
308 uno::RuntimeException
, std::exception
)
310 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
311 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
313 osl::MutexGuard
aGuard( m_aMutex
);
314 m_nWasNull
= ::convert
<uno::Any
>( m_pMyShell
,m_xTypeConverter
,m_aValueMap
[ --columnIndex
],Value
);
318 uno::Reference
< sdbc::XRef
> SAL_CALL
320 sal_Int32 columnIndex
)
321 throw( sdbc::SQLException
,
322 uno::RuntimeException
, std::exception
)
324 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
325 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
326 uno::Reference
< sdbc::XRef
> Value
;
327 osl::MutexGuard
aGuard( m_aMutex
);
328 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XRef
> >( m_pMyShell
,
330 m_aValueMap
[ --columnIndex
],
335 uno::Reference
< sdbc::XBlob
> SAL_CALL
337 sal_Int32 columnIndex
)
338 throw( sdbc::SQLException
,
339 uno::RuntimeException
, std::exception
)
341 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
342 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
343 uno::Reference
< sdbc::XBlob
> Value
;
344 osl::MutexGuard
aGuard( m_aMutex
);
345 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XBlob
> >( m_pMyShell
,
347 m_aValueMap
[ --columnIndex
],
352 uno::Reference
< sdbc::XClob
> SAL_CALL
354 sal_Int32 columnIndex
)
355 throw( sdbc::SQLException
,
356 uno::RuntimeException
, std::exception
)
358 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
359 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
360 uno::Reference
< sdbc::XClob
> Value
;
361 osl::MutexGuard
aGuard( m_aMutex
);
362 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XClob
> >( m_pMyShell
,
364 m_aValueMap
[ --columnIndex
],
370 uno::Reference
< sdbc::XArray
> SAL_CALL
372 sal_Int32 columnIndex
)
373 throw( sdbc::SQLException
,
374 uno::RuntimeException
, std::exception
)
376 if( columnIndex
< 1 || columnIndex
> m_aValueMap
.getLength() )
377 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
378 uno::Reference
< sdbc::XArray
> Value
;
379 osl::MutexGuard
aGuard( m_aMutex
);
380 m_nWasNull
= ::convert
<uno::Reference
< sdbc::XArray
> >( m_pMyShell
,
382 m_aValueMap
[ --columnIndex
],
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */