LibreOffice Module dbaccess (master) 1
resultcolumn.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "resultcolumn.hxx"
21#include <com/sun/star/beans/PropertyAttribute.hpp>
22#include <com/sun/star/sdbc/SQLException.hpp>
23#include <com/sun/star/sdbc/DataType.hpp>
24#include <com/sun/star/sdbc/ColumnValue.hpp>
25#include <com/sun/star/sdbc/XRow.hpp>
27#include <stringconstants.hxx>
28#include <strings.hxx>
29
30using namespace ::com::sun::star::sdbc;
31using namespace ::com::sun::star::beans;
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::lang;
34using namespace ::com::sun::star::container;
35using namespace ::osl;
36using namespace ::comphelper;
37using namespace ::cppu;
38using namespace dbaccess;
39
40
41OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
42 const Reference< XDatabaseMetaData >& _rxDBMeta )
43 :OColumn( true )
44 ,m_xMetaData( _xMetaData )
45 ,m_xDBMetaData( _rxDBMeta )
46 ,m_nPos( _nPos )
47{
48}
49
51{
52 if ( m_aIsRowVersion.hasValue() )
53 return;
54 m_aIsRowVersion <<= false;
55
56 OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
57 if ( !m_xDBMetaData.is() )
58 return;
59
60 try
61 {
62 OUString sCatalog, sSchema, sTable, sColumnName;
66 getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
67
68 try
69 {
70 Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
71 Any( sCatalog ), sSchema, sTable );
72 if ( xVersionColumns.is() ) // allowed to be NULL
73 {
74 Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
75 while ( xVersionColumns->next() )
76 {
77 if ( xResultRow->getString( 2 ) == sColumnName )
78 {
79 m_aIsRowVersion <<= true;
80 break;
81 }
82 }
83 }
84 }
85 catch(const SQLException&)
86 {
87 }
88 }
89 catch( const Exception& )
90 {
91 DBG_UNHANDLED_EXCEPTION("dbaccess");
92 }
93}
94
96{
97}
98
99// css::lang::XTypeProvider
101{
102 return css::uno::Sequence<sal_Int8>();
103}
104
105// XServiceInfo
107{
108 return "com.sun.star.sdb.OResultColumn";
109}
110
112{
114}
115
116// OComponentHelper
118{
119 OColumn::disposing();
120
121 MutexGuard aGuard(m_aMutex);
122 m_xMetaData = nullptr;
123}
124
125// comphelper::OPropertyArrayUsageHelper
127{
128 return new ::cppu::OPropertyArrayHelper
129 {
130 {
131 { PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
132 { PROPERTY_DISPLAYSIZE, PROPERTY_ID_DISPLAYSIZE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
133 { PROPERTY_ISAUTOINCREMENT, PROPERTY_ID_ISAUTOINCREMENT, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
134 { PROPERTY_ISCASESENSITIVE, PROPERTY_ID_ISCASESENSITIVE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
135 { PROPERTY_ISCURRENCY, PROPERTY_ID_ISCURRENCY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
136 { PROPERTY_ISDEFINITELYWRITABLE, PROPERTY_ID_ISDEFINITELYWRITABLE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
137 { PROPERTY_ISNULLABLE, PROPERTY_ID_ISNULLABLE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
138 { PROPERTY_ISREADONLY, PROPERTY_ID_ISREADONLY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
139 { PROPERTY_ISROWVERSION, PROPERTY_ID_ISROWVERSION, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
140 { PROPERTY_ISSEARCHABLE, PROPERTY_ID_ISSEARCHABLE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
141 { PROPERTY_ISSIGNED, PROPERTY_ID_ISSIGNED, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
142 { PROPERTY_ISWRITABLE, PROPERTY_ID_ISWRITABLE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
143 { PROPERTY_LABEL, PROPERTY_ID_LABEL, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
144 { PROPERTY_NAME, PROPERTY_ID_NAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
145 { PROPERTY_PRECISION, PROPERTY_ID_PRECISION, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
146 { PROPERTY_SCALE, PROPERTY_ID_SCALE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
147 { PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
148 { PROPERTY_SERVICENAME, PROPERTY_ID_SERVICENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
149 { PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
150 { PROPERTY_TYPE, PROPERTY_ID_TYPE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
151 { PROPERTY_TYPENAME, PROPERTY_ID_TYPENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY }
152 }
153 };
154}
155
156// cppu::OPropertySetHelper
158{
160}
161
162namespace
163{
164 template< typename T >
165 void obtain( Any& _out_rValue, ::std::optional< T > & _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, T (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
166 {
167 if ( !_rCache )
168 _rCache = (_rxResultMeta.get()->*Getter)(_nPos);
169 _out_rValue <<= *_rCache;
170 }
171}
172
173void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
174{
175 try
176 {
177 if ( OColumn::isRegisteredProperty( nHandle ) )
178 {
179 OColumn::getFastPropertyValue( rValue, nHandle );
180 }
181 else
182 {
183 switch (nHandle)
184 {
186 const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
187 rValue = m_aIsRowVersion;
188 break;
190 rValue <<= m_xMetaData->getTableName(m_nPos);
191 break;
193 rValue <<= m_xMetaData->getSchemaName(m_nPos);
194 break;
196 rValue <<= m_xMetaData->getCatalogName(m_nPos);
197 break;
199 obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
200 break;
202 obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
203 break;
205 obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
206 break;
208 obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
209 break;
211 obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
212 break;
214 obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
215 break;
217 obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
218 break;
220 obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
221 break;
223 rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
224 break;
226 obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
227 break;
229 obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
230 break;
231 case PROPERTY_ID_TYPE:
232 obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
233 break;
235 obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
236 break;
238 obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
239 break;
241 obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
242 break;
244 rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
245 break;
246 default:
247 OSL_FAIL( "OResultColumn::getFastPropertyValue: unknown property handle!" );
248 break;
249 }
250 }
251 }
252 catch (SQLException& )
253 {
254 // default handling if we caught an exception
255 switch (nHandle)
256 {
263 // empty string'S
264 rValue <<= OUString();
265 break;
274 {
275 rValue <<= false;
276 } break;
278 {
279 rValue <<= true;
280 } break;
284 rValue <<= sal_Int32(0);
285 break;
286 case PROPERTY_ID_TYPE:
287 rValue <<= sal_Int32(DataType::SQLNULL);
288 break;
290 rValue <<= ColumnValue::NULLABLE_UNKNOWN;
291 break;
292 }
293 }
294}
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sSchema
OptionalString sCatalog
::cppu::IPropertyArrayHelper * getArrayHelper()
css::uno::Type const & get()
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
mutable ::std::optional< sal_Bool > m_isSigned
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
void impl_determineIsRowVersion_nothrow()
mutable ::std::optional< sal_Bool > m_isAutoIncrement
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
mutable ::std::optional< sal_Bool > m_bSearchable
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
mutable ::std::optional< sal_Int32 > m_nColumnDisplaySize
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xDBMetaData
virtual ~OResultColumn() override
mutable ::std::optional< sal_Int32 > m_isNullable
mutable ::std::optional< sal_Bool > m_isReadOnly
mutable ::std::optional< sal_Bool > m_isCaseSensitive
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
mutable ::std::optional< sal_Int32 > m_nPrecision
virtual void SAL_CALL disposing() override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Any m_aIsRowVersion
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
mutable ::std::optional< sal_Bool > m_isWritable
mutable ::std::optional< sal_Int32 > m_nColumnType
mutable ::std::optional< OUString > m_sColumnLabel
mutable ::std::optional< sal_Int32 > m_nScale
mutable ::std::optional< sal_Bool > m_isDefinitelyWritable
mutable ::std::optional< sal_Bool > m_isCurrency
#define DBG_UNHANDLED_EXCEPTION(...)
size_t m_nPos
std::mutex m_aMutex
@ Exception
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
sal_Int32 nHandle
#define PROPERTY_ID_ISSIGNED
#define PROPERTY_ID_NAME
#define PROPERTY_ID_DISPLAYSIZE
#define PROPERTY_ID_ISCASESENSITIVE
#define PROPERTY_ID_TYPE
#define PROPERTY_ID_ISREADONLY
#define PROPERTY_ID_TABLENAME
#define PROPERTY_ID_SERVICENAME
#define PROPERTY_ID_CATALOGNAME
#define PROPERTY_ID_ISWRITABLE
#define PROPERTY_ID_ISROWVERSION
#define PROPERTY_ID_ISSEARCHABLE
#define PROPERTY_ID_ISNULLABLE
#define PROPERTY_ID_PRECISION
#define PROPERTY_ID_LABEL
#define PROPERTY_ID_SCHEMANAME
#define PROPERTY_ID_ISAUTOINCREMENT
#define PROPERTY_ID_ISCURRENCY
#define PROPERTY_ID_TYPENAME
#define PROPERTY_ID_ISDEFINITELYWRITABLE
#define PROPERTY_ID_SCALE
constexpr OUStringLiteral PROPERTY_ISAUTOINCREMENT(u"IsAutoIncrement")
constexpr OUStringLiteral PROPERTY_ISCURRENCY(u"IsCurrency")
constexpr OUStringLiteral PROPERTY_ISWRITABLE(u"IsWritable")
constexpr OUStringLiteral PROPERTY_PRECISION(u"Precision")
constexpr OUStringLiteral PROPERTY_SERVICENAME(u"ServiceName")
constexpr OUStringLiteral PROPERTY_ISREADONLY(u"IsReadOnly")
constexpr OUStringLiteral PROPERTY_TYPENAME(u"TypeName")
constexpr OUStringLiteral PROPERTY_LABEL(u"Label")
constexpr OUStringLiteral PROPERTY_ISROWVERSION(u"IsRowVersion")
constexpr OUStringLiteral PROPERTY_ISNULLABLE(u"IsNullable")
constexpr OUStringLiteral PROPERTY_SCHEMANAME(u"SchemaName")
constexpr OUStringLiteral PROPERTY_ISDEFINITELYWRITABLE(u"IsDefinitelyWritable")
constexpr OUStringLiteral PROPERTY_SCALE(u"Scale")
constexpr OUStringLiteral SERVICE_SDB_RESULTCOLUMN
Definition: strings.hxx:179
constexpr OUStringLiteral PROPERTY_ISSEARCHABLE(u"IsSearchable")
constexpr OUStringLiteral PROPERTY_TABLENAME(u"TableName")
constexpr OUStringLiteral PROPERTY_DISPLAYSIZE(u"DisplaySize")
constexpr OUStringLiteral SERVICE_SDBCX_COLUMN
Definition: strings.hxx:175
constexpr OUStringLiteral PROPERTY_CATALOGNAME(u"CatalogName")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_ISSIGNED(u"IsSigned")
constexpr OUStringLiteral PROPERTY_ISCASESENSITIVE(u"IsCaseSensitive")
sal_Int32 _nPos