bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / file / filrow.cxx
blob80828ed6f772150db3e5e446e0bdb7a863b0639b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "filrow.hxx"
21 #include "shell.hxx"
22 #include "prov.hxx"
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
32 #else
33 #define THROW_WHERE ""
34 #endif
36 // Function for TypeConverting
38 template< class _type_ >
39 bool convert( shell* pShell,
40 uno::Reference< script::XTypeConverter >& xConverter,
41 uno::Any& rValue,
42 _type_& aReturn )
44 // Try first without converting
45 bool no_success = ! ( rValue >>= aReturn );
47 if ( no_success )
49 if( ! xConverter.is() )
51 xConverter = script::Converter::create(pShell->m_xContext);
54 try
56 if( rValue.hasValue() )
58 uno::Any aConvertedValue
59 = xConverter->convertTo( rValue,cppu::UnoType<_type_>::get() );
60 no_success = ! ( aConvertedValue >>= aReturn );
62 else
63 no_success = true;
65 catch (const lang::IllegalArgumentException&)
67 no_success = true;
69 catch (const script::CannotConvertException&)
71 no_success = true;
74 return no_success;
78 XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq )
79 : m_aValueMap( seq ),
80 m_nWasNull(false),
81 m_pMyShell( pMyShell ),
82 m_xProvider( pMyShell->m_pProvider ),
83 m_xTypeConverter( 0 )
87 XRow_impl::~XRow_impl()
92 sal_Bool SAL_CALL
93 XRow_impl::wasNull(
94 void )
95 throw( sdbc::SQLException,
96 uno::RuntimeException, std::exception)
98 return m_nWasNull;
102 OUString SAL_CALL
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() );
110 OUString Value;
111 osl::MutexGuard aGuard( m_aMutex );
112 m_nWasNull = ::convert<OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
113 return Value;
116 sal_Bool SAL_CALL
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() );
124 bool Value( false );
125 osl::MutexGuard aGuard( m_aMutex );
126 m_nWasNull = ::convert<bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
127 return Value;
131 sal_Int8 SAL_CALL
132 XRow_impl::getByte(
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() );
139 sal_Int8 Value( 0 );
140 osl::MutexGuard aGuard( m_aMutex );
141 m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
142 return Value;
145 sal_Int16 SAL_CALL
146 XRow_impl::getShort(
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 );
156 return Value;
160 sal_Int32 SAL_CALL
161 XRow_impl::getInt(
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 );
171 return Value;
174 sal_Int64 SAL_CALL
175 XRow_impl::getLong(
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 );
185 return Value;
188 float SAL_CALL
189 XRow_impl::getFloat(
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() );
196 float Value( 0 );
197 osl::MutexGuard aGuard( m_aMutex );
198 m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
199 return Value;
202 double SAL_CALL
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() );
210 double Value( 0 );
211 osl::MutexGuard aGuard( m_aMutex );
212 m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
213 return Value;
216 uno::Sequence< sal_Int8 > SAL_CALL
217 XRow_impl::getBytes(
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 );
227 return Value;
230 util::Date SAL_CALL
231 XRow_impl::getDate(
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() );
238 util::Date Value;
239 osl::MutexGuard aGuard( m_aMutex );
240 m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
241 return Value;
244 util::Time SAL_CALL
245 XRow_impl::getTime(
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() );
252 util::Time Value;
253 osl::MutexGuard aGuard( m_aMutex );
254 m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
255 return 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 );
269 return 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 );
284 return 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 );
299 return Value;
303 uno::Any SAL_CALL
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() );
312 uno::Any Value;
313 osl::MutexGuard aGuard( m_aMutex );
314 m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
315 return Value;
318 uno::Reference< sdbc::XRef > SAL_CALL
319 XRow_impl::getRef(
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,
329 m_xTypeConverter,
330 m_aValueMap[ --columnIndex ],
331 Value );
332 return Value;
335 uno::Reference< sdbc::XBlob > SAL_CALL
336 XRow_impl::getBlob(
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,
346 m_xTypeConverter,
347 m_aValueMap[ --columnIndex ],
348 Value );
349 return Value;
352 uno::Reference< sdbc::XClob > SAL_CALL
353 XRow_impl::getClob(
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,
363 m_xTypeConverter,
364 m_aValueMap[ --columnIndex ],
365 Value );
366 return Value;
370 uno::Reference< sdbc::XArray > SAL_CALL
371 XRow_impl::getArray(
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,
381 m_xTypeConverter,
382 m_aValueMap[ --columnIndex ],
383 Value );
384 return Value;
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */