1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ac9096f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ac9096f4SAndrew Rist * distributed with this work for additional information
6*ac9096f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ac9096f4SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*ac9096f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*ac9096f4SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist * KIND, either express or implied. See the License for the
17*ac9096f4SAndrew Rist * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*ac9096f4SAndrew Rist *************************************************************/
21*ac9096f4SAndrew Rist
22*ac9096f4SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir TODO
29cdf0e10cSrcweir **************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweir *************************************************************************/
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "osl/diagnose.h"
34cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
36cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XArray.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdbc/XBlob.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdbc/XClob.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdbc/XRef.hpp>
43cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
44cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
45cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
46cdf0e10cSrcweir #include <ucbhelper/resultsetmetadata.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace com::sun::star::beans;
49cdf0e10cSrcweir using namespace com::sun::star::io;
50cdf0e10cSrcweir using namespace com::sun::star::lang;
51cdf0e10cSrcweir using namespace com::sun::star::sdbc;
52cdf0e10cSrcweir using namespace com::sun::star::uno;
53cdf0e10cSrcweir using namespace com::sun::star::util;
54cdf0e10cSrcweir using namespace rtl;
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace ucbhelper_impl {
57cdf0e10cSrcweir
58cdf0e10cSrcweir struct ResultSetMetaData_Impl
59cdf0e10cSrcweir {
60cdf0e10cSrcweir osl::Mutex m_aMutex;
61cdf0e10cSrcweir std::vector< ::ucbhelper::ResultSetColumnData > m_aColumnData;
62cdf0e10cSrcweir sal_Bool m_bObtainedTypes;
63cdf0e10cSrcweir sal_Bool m_bGlobalReadOnlyValue;
64cdf0e10cSrcweir
ResultSetMetaData_Implucbhelper_impl::ResultSetMetaData_Impl65cdf0e10cSrcweir ResultSetMetaData_Impl( sal_Int32 nSize )
66cdf0e10cSrcweir : m_aColumnData( nSize ), m_bObtainedTypes( sal_False ),
67cdf0e10cSrcweir m_bGlobalReadOnlyValue( sal_True ) {}
68cdf0e10cSrcweir
ResultSetMetaData_Implucbhelper_impl::ResultSetMetaData_Impl69cdf0e10cSrcweir ResultSetMetaData_Impl(
70cdf0e10cSrcweir const std::vector< ::ucbhelper::ResultSetColumnData >& rColumnData )
71cdf0e10cSrcweir : m_aColumnData( rColumnData ), m_bObtainedTypes( sal_False ),
72cdf0e10cSrcweir m_bGlobalReadOnlyValue( sal_False ) {}
73cdf0e10cSrcweir };
74cdf0e10cSrcweir
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir using namespace ucbhelper_impl;
78cdf0e10cSrcweir
79cdf0e10cSrcweir namespace ucbhelper {
80cdf0e10cSrcweir
81cdf0e10cSrcweir //=========================================================================
82cdf0e10cSrcweir //=========================================================================
83cdf0e10cSrcweir //
84cdf0e10cSrcweir // ResultSetMetaData Implementation.
85cdf0e10cSrcweir //
86cdf0e10cSrcweir //=========================================================================
87cdf0e10cSrcweir //=========================================================================
88cdf0e10cSrcweir
ResultSetMetaData(const Reference<XMultiServiceFactory> & rxSMgr,const Sequence<Property> & rProps,sal_Bool bReadOnly)89cdf0e10cSrcweir ResultSetMetaData::ResultSetMetaData(
90cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxSMgr,
91cdf0e10cSrcweir const Sequence< Property >& rProps,
92cdf0e10cSrcweir sal_Bool bReadOnly )
93cdf0e10cSrcweir : m_pImpl( new ResultSetMetaData_Impl( rProps.getLength() ) ),
94cdf0e10cSrcweir m_xSMgr( rxSMgr ),
95cdf0e10cSrcweir m_aProps( rProps ),
96cdf0e10cSrcweir m_bReadOnly( bReadOnly )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir //=========================================================================
ResultSetMetaData(const Reference<XMultiServiceFactory> & rxSMgr,const Sequence<Property> & rProps,const std::vector<ResultSetColumnData> & rColumnData)101cdf0e10cSrcweir ResultSetMetaData::ResultSetMetaData(
102cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rxSMgr,
103cdf0e10cSrcweir const Sequence< Property >& rProps,
104cdf0e10cSrcweir const std::vector< ResultSetColumnData >& rColumnData )
105cdf0e10cSrcweir : m_pImpl( new ResultSetMetaData_Impl( rColumnData ) ),
106cdf0e10cSrcweir m_xSMgr( rxSMgr ),
107cdf0e10cSrcweir m_aProps( rProps ),
108cdf0e10cSrcweir m_bReadOnly( sal_True )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir OSL_ENSURE( rColumnData.size() == sal_uInt32( rProps.getLength() ),
111cdf0e10cSrcweir "ResultSetMetaData ctor - different array sizes!" );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir //=========================================================================
115cdf0e10cSrcweir // virtual
~ResultSetMetaData()116cdf0e10cSrcweir ResultSetMetaData::~ResultSetMetaData()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir delete m_pImpl;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir //=========================================================================
122cdf0e10cSrcweir //
123cdf0e10cSrcweir // XInterface methods.
124cdf0e10cSrcweir //
125cdf0e10cSrcweir //=========================================================================
126cdf0e10cSrcweir
127cdf0e10cSrcweir XINTERFACE_IMPL_2( ResultSetMetaData,
128cdf0e10cSrcweir XTypeProvider,
129cdf0e10cSrcweir XResultSetMetaData );
130cdf0e10cSrcweir
131cdf0e10cSrcweir //=========================================================================
132cdf0e10cSrcweir //
133cdf0e10cSrcweir // XTypeProvider methods.
134cdf0e10cSrcweir //
135cdf0e10cSrcweir //=========================================================================
136cdf0e10cSrcweir
137cdf0e10cSrcweir XTYPEPROVIDER_IMPL_2( ResultSetMetaData,
138cdf0e10cSrcweir XTypeProvider,
139cdf0e10cSrcweir XResultSetMetaData );
140cdf0e10cSrcweir
141cdf0e10cSrcweir //=========================================================================
142cdf0e10cSrcweir //
143cdf0e10cSrcweir // XResultSetMetaData methods.
144cdf0e10cSrcweir //
145cdf0e10cSrcweir //=========================================================================
146cdf0e10cSrcweir
147cdf0e10cSrcweir // virtual
getColumnCount()148cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::getColumnCount()
149cdf0e10cSrcweir throw( SQLException, RuntimeException )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir return m_aProps.getLength();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir
154cdf0e10cSrcweir //=========================================================================
155cdf0e10cSrcweir // virtual
isAutoIncrement(sal_Int32 column)156cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isAutoIncrement( sal_Int32 column )
157cdf0e10cSrcweir throw( SQLException, RuntimeException )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir /*
160cdf0e10cSrcweir Checks whether column is automatically numbered, which makes it
161cdf0e10cSrcweir read-only.
162cdf0e10cSrcweir */
163cdf0e10cSrcweir
164cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
165cdf0e10cSrcweir return sal_False;
166cdf0e10cSrcweir
167cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isAutoIncrement;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir //=========================================================================
171cdf0e10cSrcweir // virtual
isCaseSensitive(sal_Int32 column)172cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isCaseSensitive( sal_Int32 column )
173cdf0e10cSrcweir throw( SQLException, RuntimeException )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
176cdf0e10cSrcweir return sal_False;
177cdf0e10cSrcweir
178cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isCaseSensitive;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir //=========================================================================
182cdf0e10cSrcweir // virtual
isSearchable(sal_Int32 column)183cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isSearchable( sal_Int32 column )
184cdf0e10cSrcweir throw( SQLException, RuntimeException )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir /*
187cdf0e10cSrcweir Checks whether the value stored in column can be used in a
188cdf0e10cSrcweir WHERE clause.
189cdf0e10cSrcweir */
190cdf0e10cSrcweir
191cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
192cdf0e10cSrcweir return sal_False;
193cdf0e10cSrcweir
194cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isSearchable;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir //=========================================================================
198cdf0e10cSrcweir // virtual
isCurrency(sal_Int32 column)199cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isCurrency( sal_Int32 column )
200cdf0e10cSrcweir throw( SQLException, RuntimeException )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir /*
203cdf0e10cSrcweir Checks whether column is a cash value.
204cdf0e10cSrcweir */
205cdf0e10cSrcweir
206cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
207cdf0e10cSrcweir return sal_False;
208cdf0e10cSrcweir
209cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isCurrency;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir //=========================================================================
213cdf0e10cSrcweir // virtual
isNullable(sal_Int32 column)214cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::isNullable( sal_Int32 column )
215cdf0e10cSrcweir throw( SQLException, RuntimeException )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir /*
218cdf0e10cSrcweir Checks whether a NULL can be stored in column.
219cdf0e10cSrcweir Possible values: see com/sun/star/sdbc/ColumnValue.idl
220cdf0e10cSrcweir */
221cdf0e10cSrcweir
222cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
223cdf0e10cSrcweir return ColumnValue::NULLABLE;
224cdf0e10cSrcweir
225cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isNullable;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
228cdf0e10cSrcweir //=========================================================================
229cdf0e10cSrcweir // virtual
isSigned(sal_Int32 column)230cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isSigned( sal_Int32 column )
231cdf0e10cSrcweir throw( SQLException, RuntimeException )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir /*
234cdf0e10cSrcweir Checks whether the value stored in column is a signed number.
235cdf0e10cSrcweir */
236cdf0e10cSrcweir
237cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
238cdf0e10cSrcweir return sal_False;
239cdf0e10cSrcweir
240cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isSigned;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243cdf0e10cSrcweir //=========================================================================
244cdf0e10cSrcweir // virtual
getColumnDisplaySize(sal_Int32 column)245cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::getColumnDisplaySize( sal_Int32 column )
246cdf0e10cSrcweir throw( SQLException, RuntimeException )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir /*
249cdf0e10cSrcweir Gets the normal maximum width in characters for column.
250cdf0e10cSrcweir */
251cdf0e10cSrcweir
252cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
253cdf0e10cSrcweir return 16;
254cdf0e10cSrcweir
255cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].columnDisplaySize;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
258cdf0e10cSrcweir //=========================================================================
259cdf0e10cSrcweir // virtual
getColumnLabel(sal_Int32 column)260cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getColumnLabel( sal_Int32 column )
261cdf0e10cSrcweir throw( SQLException, RuntimeException )
262cdf0e10cSrcweir {
263cdf0e10cSrcweir /*
264cdf0e10cSrcweir Gets the suggested column title for column, to be used in print-
265cdf0e10cSrcweir outs and displays.
266cdf0e10cSrcweir */
267cdf0e10cSrcweir
268cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
269cdf0e10cSrcweir return OUString();
270cdf0e10cSrcweir
271cdf0e10cSrcweir OUString aLabel = m_pImpl->m_aColumnData[ column - 1 ].columnLabel;
272cdf0e10cSrcweir if ( aLabel.getLength() )
273cdf0e10cSrcweir return aLabel;
274cdf0e10cSrcweir
275cdf0e10cSrcweir return m_aProps.getConstArray()[ column - 1 ].Name;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir
278cdf0e10cSrcweir //=========================================================================
279cdf0e10cSrcweir // virtual
getColumnName(sal_Int32 column)280cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getColumnName( sal_Int32 column )
281cdf0e10cSrcweir throw( SQLException, RuntimeException )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir /*
284cdf0e10cSrcweir Gets the name of column.
285cdf0e10cSrcweir */
286cdf0e10cSrcweir
287cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
288cdf0e10cSrcweir return OUString();
289cdf0e10cSrcweir
290cdf0e10cSrcweir return m_aProps.getConstArray()[ column - 1 ].Name;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir //=========================================================================
294cdf0e10cSrcweir // virtual
getSchemaName(sal_Int32 column)295cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getSchemaName( sal_Int32 column )
296cdf0e10cSrcweir throw( SQLException, RuntimeException )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir /*
299cdf0e10cSrcweir Gets the schema name for the table from which column of this
300cdf0e10cSrcweir result set was derived.
301cdf0e10cSrcweir Because this feature is not widely supported, the return value
302cdf0e10cSrcweir for many DBMSs will be an empty string.
303cdf0e10cSrcweir */
304cdf0e10cSrcweir
305cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
306cdf0e10cSrcweir return OUString();
307cdf0e10cSrcweir
308cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].schemaName;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir //=========================================================================
312cdf0e10cSrcweir // virtual
getPrecision(sal_Int32 column)313cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::getPrecision( sal_Int32 column )
314cdf0e10cSrcweir throw( SQLException, RuntimeException )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir /*
317cdf0e10cSrcweir For number types, getprecision gets the number of decimal digits
318cdf0e10cSrcweir in column.
319cdf0e10cSrcweir For character types, it gets the maximum length in characters for
320cdf0e10cSrcweir column.
321cdf0e10cSrcweir For binary types, it gets the maximum length in bytes for column.
322cdf0e10cSrcweir */
323cdf0e10cSrcweir
324cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
325cdf0e10cSrcweir return -1;
326cdf0e10cSrcweir
327cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].precision;
328cdf0e10cSrcweir }
329cdf0e10cSrcweir
330cdf0e10cSrcweir //=========================================================================
331cdf0e10cSrcweir // virtual
getScale(sal_Int32 column)332cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::getScale( sal_Int32 column )
333cdf0e10cSrcweir throw( SQLException, RuntimeException )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir /*
336cdf0e10cSrcweir Gets the number of digits to the right of the decimal point for
337cdf0e10cSrcweir values in column.
338cdf0e10cSrcweir */
339cdf0e10cSrcweir
340cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
341cdf0e10cSrcweir return 0;
342cdf0e10cSrcweir
343cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].scale;
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
346cdf0e10cSrcweir //=========================================================================
347cdf0e10cSrcweir // virtual
getTableName(sal_Int32 column)348cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getTableName( sal_Int32 column )
349cdf0e10cSrcweir throw( SQLException, RuntimeException )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir /*
352cdf0e10cSrcweir Gets the name of the table from which column of this result set
353cdf0e10cSrcweir was derived or "" if there is none (for example, for a join).
354cdf0e10cSrcweir Because this feature is not widely supported, the return value
355cdf0e10cSrcweir for many DBMSs will be an empty string.
356cdf0e10cSrcweir */
357cdf0e10cSrcweir
358cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
359cdf0e10cSrcweir return OUString();
360cdf0e10cSrcweir
361cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].tableName;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
364cdf0e10cSrcweir //=========================================================================
365cdf0e10cSrcweir // virtual
getCatalogName(sal_Int32 column)366cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getCatalogName( sal_Int32 column )
367cdf0e10cSrcweir throw( SQLException, RuntimeException )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir /*
370cdf0e10cSrcweir Gets the catalog name for the table from which column of this
371cdf0e10cSrcweir result set was derived.
372cdf0e10cSrcweir Because this feature is not widely supported, the return value
373cdf0e10cSrcweir for many DBMSs will be an empty string.
374cdf0e10cSrcweir */
375cdf0e10cSrcweir
376cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
377cdf0e10cSrcweir return OUString();
378cdf0e10cSrcweir
379cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].catalogName;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir //=========================================================================
383cdf0e10cSrcweir // virtual
getColumnType(sal_Int32 column)384cdf0e10cSrcweir sal_Int32 SAL_CALL ResultSetMetaData::getColumnType( sal_Int32 column )
385cdf0e10cSrcweir throw( SQLException, RuntimeException )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir /*
388cdf0e10cSrcweir Gets the JDBC type for the value stored in column. ... The STRUCT
389cdf0e10cSrcweir and DISTINCT type codes are always returned for structured and
390cdf0e10cSrcweir distinct types, regardless of whether the value will be mapped
391cdf0e10cSrcweir according to the standard mapping or be a custom mapping.
392cdf0e10cSrcweir */
393cdf0e10cSrcweir
394cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
395cdf0e10cSrcweir return DataType::SQLNULL;
396cdf0e10cSrcweir
397cdf0e10cSrcweir if ( m_aProps.getConstArray()[ column - 1 ].Type
398cdf0e10cSrcweir == getCppuVoidType() )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir // No type given. Try UCB's Properties Manager...
401cdf0e10cSrcweir
402cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
403cdf0e10cSrcweir
404cdf0e10cSrcweir if ( !m_pImpl->m_bObtainedTypes )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir try
407cdf0e10cSrcweir {
408cdf0e10cSrcweir Reference< XPropertySetInfo > xInfo(
409cdf0e10cSrcweir m_xSMgr->createInstance(
410cdf0e10cSrcweir OUString::createFromAscii(
411cdf0e10cSrcweir "com.sun.star.ucb.PropertiesManager" ) ),
412cdf0e10cSrcweir UNO_QUERY );
413cdf0e10cSrcweir if ( xInfo.is() )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir #if 0
416cdf0e10cSrcweir // Convenient...
417cdf0e10cSrcweir
418cdf0e10cSrcweir sal_Int32 nCount = m_pImpl->m_aProps.getLength();
419cdf0e10cSrcweir Property* pProps = m_pImpl->m_aProps.getArray();
420cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir Property& rProp = pProps[ n ];
423cdf0e10cSrcweir
424cdf0e10cSrcweir try
425cdf0e10cSrcweir {
426cdf0e10cSrcweir Property aProp
427cdf0e10cSrcweir = xInfo->getPropertyByName( rProp.Name );
428cdf0e10cSrcweir rProp.Type = aProp.Type;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir catch ( UnknownPropertyException& )
431cdf0e10cSrcweir {
432cdf0e10cSrcweir // getPropertyByName
433cdf0e10cSrcweir }
434cdf0e10cSrcweir }
435cdf0e10cSrcweir #else
436cdf0e10cSrcweir // Less (remote) calls...
437cdf0e10cSrcweir
438cdf0e10cSrcweir Sequence< Property > aProps = xInfo->getProperties();
439cdf0e10cSrcweir const Property* pProps1 = aProps.getConstArray();
440cdf0e10cSrcweir sal_Int32 nCount1 = aProps.getLength();
441cdf0e10cSrcweir
442cdf0e10cSrcweir sal_Int32 nCount = m_aProps.getLength();
443cdf0e10cSrcweir Property* pProps = m_aProps.getArray();
444cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir Property& rProp = pProps[ n ];
447cdf0e10cSrcweir
448cdf0e10cSrcweir for ( sal_Int32 m = 0; m < nCount1; ++m )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir const Property& rProp1 = pProps1[ m ];
451cdf0e10cSrcweir if ( rProp.Name == rProp1.Name )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir // Found...
454cdf0e10cSrcweir rProp.Type = rProp1.Type;
455cdf0e10cSrcweir break;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir #endif
460cdf0e10cSrcweir }
461cdf0e10cSrcweir }
462cdf0e10cSrcweir catch ( RuntimeException& )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir throw;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir catch ( Exception& )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir // createInstance
469cdf0e10cSrcweir }
470cdf0e10cSrcweir
471cdf0e10cSrcweir m_pImpl->m_bObtainedTypes = sal_True;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir
475cdf0e10cSrcweir const Type& rType = m_aProps.getConstArray()[ column - 1 ].Type;
476cdf0e10cSrcweir sal_Int32 nType = DataType::OTHER;
477cdf0e10cSrcweir
478cdf0e10cSrcweir if ( rType == getCppuType( static_cast< const rtl::OUString * >( 0 ) ) )
479cdf0e10cSrcweir nType = DataType::VARCHAR; // XRow::getString
480cdf0e10cSrcweir else if ( rType == getCppuBooleanType() )
481cdf0e10cSrcweir nType = DataType::BIT; // XRow::getBoolean
482cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int32 * >( 0 ) ) )
483cdf0e10cSrcweir nType = DataType::INTEGER; // XRow::getInt
484cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int64 * >( 0 ) ) )
485cdf0e10cSrcweir nType = DataType::BIGINT; // XRow::getLong
486cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int16 * >( 0 ) ) )
487cdf0e10cSrcweir nType = DataType::SMALLINT; // XRow::getShort
488cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const sal_Int8 * >( 0 ) ) )
489cdf0e10cSrcweir nType = DataType::TINYINT; // XRow::getByte
490cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const float * >( 0 ) ) )
491cdf0e10cSrcweir nType = DataType::REAL; // XRow::getFloat
492cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const double * >( 0 ) ) )
493cdf0e10cSrcweir nType = DataType::DOUBLE; // XRow::getDouble
494cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const Sequence< sal_Int8 > * >( 0 ) ) )
495cdf0e10cSrcweir nType = DataType::VARBINARY;// XRow::getBytes
496cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const Date * >( 0 ) ) )
497cdf0e10cSrcweir nType = DataType::DATE; // XRow::getDate
498cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const Time * >( 0 ) ) )
499cdf0e10cSrcweir nType = DataType::TIME; // XRow::getTime
500cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< const DateTime * >( 0 ) ) )
501cdf0e10cSrcweir nType = DataType::TIMESTAMP;// XRow::getTimestamp
502cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< Reference< XInputStream > * >( 0 ) ) )
503cdf0e10cSrcweir nType = DataType::LONGVARBINARY; // XRow::getBinaryStream
504cdf0e10cSrcweir // nType = DataType::LONGVARCHAR; // XRow::getCharacterStream
505cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< Reference< XClob > * >( 0 ) ) )
506cdf0e10cSrcweir nType = DataType::CLOB; // XRow::getClob
507cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< Reference< XBlob > * >( 0 ) ) )
508cdf0e10cSrcweir nType = DataType::BLOB; // XRow::getBlob
509cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< Reference< XArray > * >( 0 ) ) )
510cdf0e10cSrcweir nType = DataType::ARRAY;// XRow::getArray
511cdf0e10cSrcweir else if ( rType == getCppuType( static_cast< Reference< XRef > * >( 0 ) ) )
512cdf0e10cSrcweir nType = DataType::REF;// XRow::getRef
513cdf0e10cSrcweir else
514cdf0e10cSrcweir nType = DataType::OBJECT;// XRow::getObject
515cdf0e10cSrcweir
516cdf0e10cSrcweir return nType;
517cdf0e10cSrcweir }
518cdf0e10cSrcweir
519cdf0e10cSrcweir //=========================================================================
520cdf0e10cSrcweir // virtual
getColumnTypeName(sal_Int32 column)521cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getColumnTypeName( sal_Int32 column )
522cdf0e10cSrcweir throw( SQLException, RuntimeException )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir /*
525cdf0e10cSrcweir Gets the type name used by this particular data source for the
526cdf0e10cSrcweir values stored in column. If the type code for the type of value
527cdf0e10cSrcweir stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
528cdf0e10cSrcweir returns a fully-qualified SQL type name.
529cdf0e10cSrcweir */
530cdf0e10cSrcweir
531cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
532cdf0e10cSrcweir return OUString();
533cdf0e10cSrcweir
534cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].columnTypeName;
535cdf0e10cSrcweir }
536cdf0e10cSrcweir
537cdf0e10cSrcweir //=========================================================================
538cdf0e10cSrcweir // virtual
isReadOnly(sal_Int32 column)539cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isReadOnly( sal_Int32 column )
540cdf0e10cSrcweir throw( SQLException, RuntimeException )
541cdf0e10cSrcweir {
542cdf0e10cSrcweir if ( m_pImpl->m_bGlobalReadOnlyValue )
543cdf0e10cSrcweir return m_bReadOnly;
544cdf0e10cSrcweir
545cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
546cdf0e10cSrcweir return sal_True;
547cdf0e10cSrcweir
548cdf0e10cSrcweir // autoincrement==true => readonly
549cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isAutoIncrement ||
550cdf0e10cSrcweir m_pImpl->m_aColumnData[ column - 1 ].isReadOnly;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir
553cdf0e10cSrcweir //=========================================================================
554cdf0e10cSrcweir // virtual
isWritable(sal_Int32 column)555cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isWritable( sal_Int32 column )
556cdf0e10cSrcweir throw( SQLException, RuntimeException )
557cdf0e10cSrcweir {
558cdf0e10cSrcweir if ( m_pImpl->m_bGlobalReadOnlyValue )
559cdf0e10cSrcweir return !m_bReadOnly;
560cdf0e10cSrcweir
561cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
562cdf0e10cSrcweir return sal_False;
563cdf0e10cSrcweir
564cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isWritable;
565cdf0e10cSrcweir }
566cdf0e10cSrcweir
567cdf0e10cSrcweir //=========================================================================
568cdf0e10cSrcweir // virtual
isDefinitelyWritable(sal_Int32 column)569cdf0e10cSrcweir sal_Bool SAL_CALL ResultSetMetaData::isDefinitelyWritable( sal_Int32 column )
570cdf0e10cSrcweir throw( SQLException, RuntimeException )
571cdf0e10cSrcweir {
572cdf0e10cSrcweir if ( m_pImpl->m_bGlobalReadOnlyValue )
573cdf0e10cSrcweir return !m_bReadOnly;
574cdf0e10cSrcweir
575cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
576cdf0e10cSrcweir return sal_False;
577cdf0e10cSrcweir
578cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].isDefinitelyWritable;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
581cdf0e10cSrcweir //=========================================================================
582cdf0e10cSrcweir // virtual
getColumnServiceName(sal_Int32 column)583cdf0e10cSrcweir OUString SAL_CALL ResultSetMetaData::getColumnServiceName( sal_Int32 column )
584cdf0e10cSrcweir throw( SQLException, RuntimeException )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir /*
587cdf0e10cSrcweir Returns the fully-qualified name of the service whose instances
588cdf0e10cSrcweir are manufactured if XResultSet::getObject is called to retrieve
589cdf0e10cSrcweir a value from the column.
590cdf0e10cSrcweir */
591cdf0e10cSrcweir
592cdf0e10cSrcweir if ( ( column < 1 ) || ( column > m_aProps.getLength() ) )
593cdf0e10cSrcweir return OUString();
594cdf0e10cSrcweir
595cdf0e10cSrcweir return m_pImpl->m_aColumnData[ column - 1 ].columnServiceName;
596cdf0e10cSrcweir }
597cdf0e10cSrcweir
598cdf0e10cSrcweir } // namespace ucbhelper
599