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 /**************************************************************************
23 **************************************************************************
25 *************************************************************************/
27 #include <osl/diagnose.h>
28 #include <com/sun/star/beans/Property.hpp>
29 #include <com/sun/star/beans/XPropertySetInfo.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/sdbc/ColumnValue.hpp>
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/sdbc/XArray.hpp>
35 #include <com/sun/star/sdbc/XBlob.hpp>
36 #include <com/sun/star/sdbc/XClob.hpp>
37 #include <com/sun/star/sdbc/XRef.hpp>
38 #include <com/sun/star/util/Date.hpp>
39 #include <com/sun/star/util/Time.hpp>
40 #include <com/sun/star/util/DateTime.hpp>
41 #include <com/sun/star/ucb/PropertiesManager.hpp>
42 #include <ucbhelper/macros.hxx>
43 #include <ucbhelper/resultsetmetadata.hxx>
44 #include <cppuhelper/queryinterface.hxx>
46 using namespace com::sun::star::beans
;
47 using namespace com::sun::star::io
;
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::sdbc
;
50 using namespace com::sun::star::ucb
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::util
;
55 namespace ucbhelper_impl
{
57 struct ResultSetMetaData_Impl
60 std::vector
< ::ucbhelper::ResultSetColumnData
> m_aColumnData
;
61 bool m_bObtainedTypes
;
63 explicit ResultSetMetaData_Impl( sal_Int32 nSize
)
64 : m_aColumnData( nSize
), m_bObtainedTypes( false ) {}
66 explicit ResultSetMetaData_Impl(
67 const std::vector
< ::ucbhelper::ResultSetColumnData
>& rColumnData
)
68 : m_aColumnData( rColumnData
), m_bObtainedTypes( false ) {}
73 using namespace ucbhelper_impl
;
78 // ResultSetMetaData Implementation.
81 ResultSetMetaData::ResultSetMetaData(
82 const Reference
< XComponentContext
>& rxContext
,
83 const Sequence
< Property
>& rProps
)
84 : m_pImpl( new ResultSetMetaData_Impl( rProps
.getLength() ) ),
85 m_xContext( rxContext
),
91 ResultSetMetaData::ResultSetMetaData(
92 const Reference
< XComponentContext
>& rxContext
,
93 const Sequence
< Property
>& rProps
,
94 const std::vector
< ResultSetColumnData
>& rColumnData
)
95 : m_pImpl( new ResultSetMetaData_Impl( rColumnData
) ),
96 m_xContext( rxContext
),
99 OSL_ENSURE( rColumnData
.size() == sal_uInt32( rProps
.getLength() ),
100 "ResultSetMetaData ctor - different array sizes!" );
105 ResultSetMetaData::~ResultSetMetaData()
110 // XInterface methods.
112 void SAL_CALL
ResultSetMetaData::acquire()
115 OWeakObject::acquire();
118 void SAL_CALL
ResultSetMetaData::release()
121 OWeakObject::release();
124 css::uno::Any SAL_CALL
ResultSetMetaData::queryInterface( const css::uno::Type
& rType
)
126 css::uno::Any aRet
= cppu::queryInterface( rType
,
127 static_cast< XTypeProvider
* >(this),
128 static_cast< XResultSetMetaData
* >(this)
130 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
133 // XTypeProvider methods.
136 XTYPEPROVIDER_IMPL_2( ResultSetMetaData
,
138 XResultSetMetaData
);
141 // XResultSetMetaData methods.
145 sal_Int32 SAL_CALL
ResultSetMetaData::getColumnCount()
147 return m_aProps
.getLength();
152 sal_Bool SAL_CALL
ResultSetMetaData::isAutoIncrement( sal_Int32
/*column*/ )
155 Checks whether column is automatically numbered, which makes it
163 sal_Bool SAL_CALL
ResultSetMetaData::isCaseSensitive( sal_Int32 column
)
165 if ( ( column
< 1 ) || ( column
> m_aProps
.getLength() ) )
168 return m_pImpl
->m_aColumnData
[ column
- 1 ].isCaseSensitive
;
173 sal_Bool SAL_CALL
ResultSetMetaData::isSearchable( sal_Int32
/*column*/ )
180 sal_Bool SAL_CALL
ResultSetMetaData::isCurrency( sal_Int32
/*column*/ )
187 sal_Int32 SAL_CALL
ResultSetMetaData::isNullable( sal_Int32
/*column*/ )
189 return ColumnValue::NULLABLE
;
194 sal_Bool SAL_CALL
ResultSetMetaData::isSigned( sal_Int32
/*column*/ )
201 sal_Int32 SAL_CALL
ResultSetMetaData::getColumnDisplaySize( sal_Int32
/*column*/ )
204 Gets the normal maximum width in characters for column.
211 OUString SAL_CALL
ResultSetMetaData::getColumnLabel( sal_Int32 column
)
214 Gets the suggested column title for column, to be used in print-
218 if ( ( column
< 1 ) || ( column
> m_aProps
.getLength() ) )
221 return m_aProps
.getConstArray()[ column
- 1 ].Name
;
226 OUString SAL_CALL
ResultSetMetaData::getColumnName( sal_Int32 column
)
229 Gets the name of column.
232 if ( ( column
< 1 ) || ( column
> m_aProps
.getLength() ) )
235 return m_aProps
.getConstArray()[ column
- 1 ].Name
;
240 OUString SAL_CALL
ResultSetMetaData::getSchemaName( sal_Int32
/*column*/ )
243 Gets the schema name for the table from which column of this
244 result set was derived.
245 Because this feature is not widely supported, the return value
246 for many DBMSs will be an empty string.
253 sal_Int32 SAL_CALL
ResultSetMetaData::getPrecision( sal_Int32
/*column*/ )
260 sal_Int32 SAL_CALL
ResultSetMetaData::getScale( sal_Int32
/*column*/ )
267 OUString SAL_CALL
ResultSetMetaData::getTableName( sal_Int32
/*column*/ )
270 Gets the name of the table from which column of this result set
271 was derived or "" if there is none (for example, for a join).
272 Because this feature is not widely supported, the return value
273 for many DBMSs will be an empty string.
280 OUString SAL_CALL
ResultSetMetaData::getCatalogName( sal_Int32
/*column*/ )
283 Gets the catalog name for the table from which column of this
284 result set was derived.
285 Because this feature is not widely supported, the return value
286 for many DBMSs will be an empty string.
293 sal_Int32 SAL_CALL
ResultSetMetaData::getColumnType( sal_Int32 column
)
296 Gets the JDBC type for the value stored in column. ... The STRUCT
297 and DISTINCT type codes are always returned for structured and
298 distinct types, regardless of whether the value will be mapped
299 according to the standard mapping or be a custom mapping.
302 if ( ( column
< 1 ) || ( column
> m_aProps
.getLength() ) )
303 return DataType::SQLNULL
;
305 if ( m_aProps
.getConstArray()[ column
- 1 ].Type
306 == cppu::UnoType
<void>::get() )
308 // No type given. Try UCB's Properties Manager...
310 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
312 if ( !m_pImpl
->m_bObtainedTypes
)
316 Reference
< XPropertySetInfo
> xInfo
= PropertiesManager::create( m_xContext
);
317 // Less (remote) calls...
319 Sequence
< Property
> aProps
= xInfo
->getProperties();
320 const Property
* pProps1
= aProps
.getConstArray();
321 sal_Int32 nCount1
= aProps
.getLength();
323 sal_Int32 nCount
= m_aProps
.getLength();
324 Property
* pProps
= m_aProps
.getArray();
325 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
327 Property
& rProp
= pProps
[ n
];
329 for ( sal_Int32 m
= 0; m
< nCount1
; ++m
)
331 const Property
& rProp1
= pProps1
[ m
];
332 if ( rProp
.Name
== rProp1
.Name
)
335 rProp
.Type
= rProp1
.Type
;
341 catch ( RuntimeException
& )
350 m_pImpl
->m_bObtainedTypes
= true;
354 const Type
& rType
= m_aProps
.getConstArray()[ column
- 1 ].Type
;
355 sal_Int32 nType
= DataType::OTHER
;
357 if ( rType
== cppu::UnoType
<OUString
>::get() )
358 nType
= DataType::VARCHAR
; // XRow::getString
359 else if ( rType
== cppu::UnoType
<bool>::get() )
360 nType
= DataType::BIT
; // XRow::getBoolean
361 else if ( rType
== cppu::UnoType
<sal_Int32
>::get() )
362 nType
= DataType::INTEGER
; // XRow::getInt
363 else if ( rType
== cppu::UnoType
<sal_Int64
>::get() )
364 nType
= DataType::BIGINT
; // XRow::getLong
365 else if ( rType
== cppu::UnoType
<sal_Int16
>::get() )
366 nType
= DataType::SMALLINT
; // XRow::getShort
367 else if ( rType
== cppu::UnoType
<sal_Int8
>::get() )
368 nType
= DataType::TINYINT
; // XRow::getByte
369 else if ( rType
== cppu::UnoType
<float>::get() )
370 nType
= DataType::REAL
; // XRow::getFloat
371 else if ( rType
== cppu::UnoType
<double>::get() )
372 nType
= DataType::DOUBLE
; // XRow::getDouble
373 else if ( rType
== cppu::UnoType
<Sequence
<sal_Int8
>>::get() )
374 nType
= DataType::VARBINARY
;// XRow::getBytes
375 else if ( rType
== cppu::UnoType
<Date
>::get() )
376 nType
= DataType::DATE
; // XRow::getDate
377 else if ( rType
== cppu::UnoType
<Time
>::get() )
378 nType
= DataType::TIME
; // XRow::getTime
379 else if ( rType
== cppu::UnoType
<DateTime
>::get() )
380 nType
= DataType::TIMESTAMP
;// XRow::getTimestamp
381 else if ( rType
== cppu::UnoType
<XInputStream
>::get() )
382 nType
= DataType::LONGVARBINARY
; // XRow::getBinaryStream
383 // nType = DataType::LONGVARCHAR; // XRow::getCharacterStream
384 else if ( rType
== cppu::UnoType
<XClob
>::get() )
385 nType
= DataType::CLOB
; // XRow::getClob
386 else if ( rType
== cppu::UnoType
<XBlob
>::get() )
387 nType
= DataType::BLOB
; // XRow::getBlob
388 else if ( rType
== cppu::UnoType
<XArray
>::get() )
389 nType
= DataType::ARRAY
;// XRow::getArray
390 else if ( rType
== cppu::UnoType
<XRef
>::get() )
391 nType
= DataType::REF
;// XRow::getRef
393 nType
= DataType::OBJECT
;// XRow::getObject
400 OUString SAL_CALL
ResultSetMetaData::getColumnTypeName( sal_Int32
/*column*/ )
403 Gets the type name used by this particular data source for the
404 values stored in column. If the type code for the type of value
405 stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
406 returns a fully-qualified SQL type name.
413 sal_Bool SAL_CALL
ResultSetMetaData::isReadOnly( sal_Int32
/*column*/ )
420 sal_Bool SAL_CALL
ResultSetMetaData::isWritable( sal_Int32
/*column*/ )
427 sal_Bool SAL_CALL
ResultSetMetaData::isDefinitelyWritable( sal_Int32
/*column*/ )
434 OUString SAL_CALL
ResultSetMetaData::getColumnServiceName( sal_Int32
/*column*/ )
437 Returns the fully-qualified name of the service whose instances
438 are manufactured if XResultSet::getObject is called to retrieve
439 a value from the column.
444 } // namespace ucbhelper
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */