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 .
21 #include "filtask.hxx"
22 #include <com/sun/star/script/CannotConvertException.hpp>
23 #include <com/sun/star/script/Converter.hpp>
24 #include <com/sun/star/sdbc/SQLException.hpp>
26 using namespace fileaccess
;
27 using namespace com::sun::star
;
28 using namespace css::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 static bool convert( TaskManager
const * 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( TaskManager
* pMyShell
,const uno::Sequence
< uno::Any
>& seq
)
81 m_pMyShell( pMyShell
)
85 XRow_impl::~XRow_impl()
99 sal_Int32 columnIndex
)
101 if( isIndexOutOfBounds( columnIndex
) )
102 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
103 return getValue
<OUString
>(columnIndex
);
107 XRow_impl::getBoolean(
108 sal_Int32 columnIndex
)
110 if( isIndexOutOfBounds( columnIndex
) )
111 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
112 return getValue
<bool>(columnIndex
);
118 sal_Int32 columnIndex
)
120 if( isIndexOutOfBounds( columnIndex
) )
121 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
122 return getValue
<sal_Int8
>(columnIndex
);
127 sal_Int32 columnIndex
)
129 if( isIndexOutOfBounds( columnIndex
) )
130 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
131 return getValue
<sal_Int16
>(columnIndex
);
137 sal_Int32 columnIndex
)
139 if( isIndexOutOfBounds( columnIndex
) )
140 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
141 return getValue
<sal_Int32
>(columnIndex
);
146 sal_Int32 columnIndex
)
148 if( isIndexOutOfBounds( columnIndex
) )
149 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
150 return getValue
<sal_Int64
>(columnIndex
);
155 sal_Int32 columnIndex
)
157 if( isIndexOutOfBounds( columnIndex
) )
158 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
159 return getValue
<float>(columnIndex
);
163 XRow_impl::getDouble(
164 sal_Int32 columnIndex
)
166 if( isIndexOutOfBounds( columnIndex
) )
167 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
168 return getValue
<double>(columnIndex
);
171 uno::Sequence
< sal_Int8
> SAL_CALL
173 sal_Int32 columnIndex
)
175 if( isIndexOutOfBounds( columnIndex
) )
176 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
177 return getValue
<uno::Sequence
< sal_Int8
>>(columnIndex
);
182 sal_Int32 columnIndex
)
184 if( isIndexOutOfBounds( columnIndex
) )
185 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
186 return getValue
<util::Date
>(columnIndex
);
191 sal_Int32 columnIndex
)
193 if( isIndexOutOfBounds( columnIndex
) )
194 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
195 return getValue
<util::Time
>(columnIndex
);
198 util::DateTime SAL_CALL
199 XRow_impl::getTimestamp(
200 sal_Int32 columnIndex
)
202 if( isIndexOutOfBounds( columnIndex
) )
203 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
204 return getValue
<util::DateTime
>(columnIndex
);
208 uno::Reference
< io::XInputStream
> SAL_CALL
209 XRow_impl::getBinaryStream(
210 sal_Int32 columnIndex
)
212 if( isIndexOutOfBounds( columnIndex
) )
213 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
214 return getValue
<uno::Reference
< io::XInputStream
>>(columnIndex
);
218 uno::Reference
< io::XInputStream
> SAL_CALL
219 XRow_impl::getCharacterStream(
220 sal_Int32 columnIndex
)
222 if( isIndexOutOfBounds( columnIndex
) )
223 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
224 return getValue
<uno::Reference
< io::XInputStream
>>(columnIndex
);
229 XRow_impl::getObject(
230 sal_Int32 columnIndex
,
231 const uno::Reference
< container::XNameAccess
>& )
233 if( isIndexOutOfBounds( columnIndex
) )
234 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
235 osl::MutexGuard
aGuard( m_aMutex
);
236 uno::Any Value
= m_aValueMap
[columnIndex
- 1];
237 m_nWasNull
= !Value
.hasValue();
241 uno::Reference
< sdbc::XRef
> SAL_CALL
243 sal_Int32 columnIndex
)
245 if( isIndexOutOfBounds( columnIndex
) )
246 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
247 return getValue
<uno::Reference
< sdbc::XRef
>>(columnIndex
);
250 uno::Reference
< sdbc::XBlob
> SAL_CALL
252 sal_Int32 columnIndex
)
254 if( isIndexOutOfBounds( columnIndex
) )
255 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
256 return getValue
<uno::Reference
< sdbc::XBlob
>>(columnIndex
);
259 uno::Reference
< sdbc::XClob
> SAL_CALL
261 sal_Int32 columnIndex
)
263 if( isIndexOutOfBounds( columnIndex
) )
264 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
265 return getValue
<uno::Reference
< sdbc::XClob
>>(columnIndex
);
269 uno::Reference
< sdbc::XArray
> SAL_CALL
271 sal_Int32 columnIndex
)
273 if( isIndexOutOfBounds( columnIndex
) )
274 throw sdbc::SQLException( THROW_WHERE
, uno::Reference
< uno::XInterface
>(), OUString(), 0, uno::Any() );
275 return getValue
<uno::Reference
< sdbc::XArray
>>(columnIndex
);
279 XRow_impl::isIndexOutOfBounds(sal_Int32 nIndex
)
281 return nIndex
< 1 || m_aValueMap
.getLength() < nIndex
;
285 T
XRow_impl::getValue(sal_Int32 columnIndex
)
288 osl::MutexGuard
aGuard( m_aMutex
);
289 m_nWasNull
= ::convert
<T
>( m_pMyShell
, m_xTypeConverter
, m_aValueMap
[ --columnIndex
], aValue
);
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */