Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / api / resultcolumn.cxx
blobc0d7b58e8cd2454c6f5f842903b461290907b28c
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 "resultcolumn.hxx"
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/sdbc/ColumnValue.hpp>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <tools/debug.hxx>
27 #include <tools/diagnose_ex.h>
28 #include "dbastrings.hrc"
29 #include "apitools.hxx"
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <cppuhelper/exc_hlp.hxx>
32 #include <osl/thread.h>
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::container;
39 using namespace ::osl;
40 using namespace ::comphelper;
41 using namespace ::cppu;
42 using namespace dbaccess;
45 OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
46 const Reference< XDatabaseMetaData >& _rxDBMeta )
47 :OColumn( true )
48 ,m_xMetaData( _xMetaData )
49 ,m_xDBMetaData( _rxDBMeta )
50 ,m_nPos( _nPos )
54 void OResultColumn::impl_determineIsRowVersion_nothrow()
56 if ( m_aIsRowVersion.hasValue() )
57 return;
58 m_aIsRowVersion <<= false;
60 OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
61 if ( !m_xDBMetaData.is() )
62 return;
64 try
66 OUString sCatalog, sSchema, sTable, sColumnName;
67 getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog;
68 getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema;
69 getPropertyValue( PROPERTY_TABLENAME ) >>= sTable;
70 getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
72 try
74 Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
75 makeAny( sCatalog ), sSchema, sTable );
76 if ( xVersionColumns.is() ) // allowed to be NULL
78 Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
79 while ( xVersionColumns->next() )
81 if ( xResultRow->getString( 2 ) == sColumnName )
83 m_aIsRowVersion <<= true;
84 break;
89 catch(const SQLException&)
93 catch( const Exception& )
95 DBG_UNHANDLED_EXCEPTION();
99 OResultColumn::~OResultColumn()
103 // com::sun::star::lang::XTypeProvider
104 Sequence< sal_Int8 > OResultColumn::getImplementationId() throw (RuntimeException, std::exception)
106 return css::uno::Sequence<sal_Int8>();
109 // XServiceInfo
110 OUString OResultColumn::getImplementationName( ) throw(RuntimeException, std::exception)
112 return OUString("com.sun.star.sdb.OResultColumn");
115 Sequence< OUString > OResultColumn::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
117 Sequence< OUString > aSNS( 2 );
118 aSNS[0] = SERVICE_SDBCX_COLUMN;
119 aSNS[1] = SERVICE_SDB_RESULTCOLUMN;
120 return aSNS;
123 // OComponentHelper
124 void OResultColumn::disposing()
126 OColumn::disposing();
128 MutexGuard aGuard(m_aMutex);
129 m_xMetaData = NULL;
132 // comphelper::OPropertyArrayUsageHelper
133 ::cppu::IPropertyArrayHelper* OResultColumn::createArrayHelper( ) const
135 BEGIN_PROPERTY_HELPER(21)
136 DECL_PROP1(CATALOGNAME, OUString, READONLY);
137 DECL_PROP1(DISPLAYSIZE, sal_Int32, READONLY);
138 DECL_PROP1_BOOL(ISAUTOINCREMENT, READONLY);
139 DECL_PROP1_BOOL(ISCASESENSITIVE, READONLY);
140 DECL_PROP1_BOOL(ISCURRENCY, READONLY);
141 DECL_PROP1_BOOL(ISDEFINITELYWRITABLE, READONLY);
142 DECL_PROP1(ISNULLABLE, sal_Int32, READONLY);
143 DECL_PROP1_BOOL(ISREADONLY, READONLY);
144 DECL_PROP1_BOOL(ISROWVERSION, READONLY);
145 DECL_PROP1_BOOL(ISSEARCHABLE, READONLY);
146 DECL_PROP1_BOOL(ISSIGNED, READONLY);
147 DECL_PROP1_BOOL(ISWRITABLE, READONLY);
148 DECL_PROP1(LABEL, OUString, READONLY);
149 DECL_PROP1(NAME, OUString, READONLY);
150 DECL_PROP1(PRECISION, sal_Int32, READONLY);
151 DECL_PROP1(SCALE, sal_Int32, READONLY);
152 DECL_PROP1(SCHEMANAME, OUString, READONLY);
153 DECL_PROP1(SERVICENAME, OUString, READONLY);
154 DECL_PROP1(TABLENAME, OUString, READONLY);
155 DECL_PROP1(TYPE, sal_Int32, READONLY);
156 DECL_PROP1(TYPENAME, OUString, READONLY);
157 END_PROPERTY_HELPER();
160 // cppu::OPropertySetHelper
161 ::cppu::IPropertyArrayHelper& OResultColumn::getInfoHelper()
163 return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OResultColumn >* >(this)->getArrayHelper();
166 namespace
168 template< typename T >
169 void obtain( Any& _out_rValue, ::boost::optional< T > _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, T (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
171 if ( !_rCache )
172 _rCache.reset( (_rxResultMeta.get()->*Getter)( _nPos ) );
173 _out_rValue <<= *_rCache;
177 void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
181 if ( OColumn::isRegisteredProperty( nHandle ) )
183 OColumn::getFastPropertyValue( rValue, nHandle );
185 else
187 switch (nHandle)
189 case PROPERTY_ID_ISROWVERSION:
190 const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
191 rValue = m_aIsRowVersion;
192 break;
193 case PROPERTY_ID_TABLENAME:
194 rValue <<= m_xMetaData->getTableName(m_nPos);
195 break;
196 case PROPERTY_ID_SCHEMANAME:
197 rValue <<= m_xMetaData->getSchemaName(m_nPos);
198 break;
199 case PROPERTY_ID_CATALOGNAME:
200 rValue <<= m_xMetaData->getCatalogName(m_nPos);
201 break;
202 case PROPERTY_ID_ISSIGNED:
203 obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
204 break;
205 case PROPERTY_ID_ISCURRENCY:
206 obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
207 break;
208 case PROPERTY_ID_ISSEARCHABLE:
209 obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
210 break;
211 case PROPERTY_ID_ISCASESENSITIVE:
212 obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
213 break;
214 case PROPERTY_ID_ISREADONLY:
215 obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
216 break;
217 case PROPERTY_ID_ISWRITABLE:
218 obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
219 break;
220 case PROPERTY_ID_ISDEFINITELYWRITABLE:
221 obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
222 break;
223 case PROPERTY_ID_ISAUTOINCREMENT:
224 obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
225 break;
226 case PROPERTY_ID_SERVICENAME:
227 rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
228 break;
229 case PROPERTY_ID_LABEL:
230 obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
231 break;
232 case PROPERTY_ID_DISPLAYSIZE:
233 obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
234 break;
235 case PROPERTY_ID_TYPE:
236 obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
237 break;
238 case PROPERTY_ID_PRECISION:
239 obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
240 break;
241 case PROPERTY_ID_SCALE:
242 obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
243 break;
244 case PROPERTY_ID_ISNULLABLE:
245 obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
246 break;
247 case PROPERTY_ID_TYPENAME:
248 rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
249 break;
250 default:
251 OSL_FAIL( "OResultColumn::getFastPropertyValue: unknown property handle!" );
252 break;
256 catch (SQLException& )
258 // default handling if we caught an exception
259 switch (nHandle)
261 case PROPERTY_ID_LABEL:
262 case PROPERTY_ID_TYPENAME:
263 case PROPERTY_ID_SERVICENAME:
264 case PROPERTY_ID_TABLENAME:
265 case PROPERTY_ID_SCHEMANAME:
266 case PROPERTY_ID_CATALOGNAME:
267 // empty string'S
268 rValue <<= OUString();
269 break;
270 case PROPERTY_ID_ISROWVERSION:
271 case PROPERTY_ID_ISAUTOINCREMENT:
272 case PROPERTY_ID_ISWRITABLE:
273 case PROPERTY_ID_ISDEFINITELYWRITABLE:
274 case PROPERTY_ID_ISCASESENSITIVE:
275 case PROPERTY_ID_ISSEARCHABLE:
276 case PROPERTY_ID_ISCURRENCY:
277 case PROPERTY_ID_ISSIGNED:
279 sal_Bool bVal = sal_False;
280 rValue.setValue(&bVal, cppu::UnoType<bool>::get());
281 } break;
282 case PROPERTY_ID_ISREADONLY:
284 sal_Bool bVal = sal_True;
285 rValue.setValue(&bVal, cppu::UnoType<bool>::get());
286 } break;
287 case PROPERTY_ID_SCALE:
288 case PROPERTY_ID_PRECISION:
289 case PROPERTY_ID_DISPLAYSIZE:
290 rValue <<= sal_Int32(0);
291 break;
292 case PROPERTY_ID_TYPE:
293 rValue <<= sal_Int32(DataType::SQLNULL);
294 break;
295 case PROPERTY_ID_ISNULLABLE:
296 rValue <<= ColumnValue::NULLABLE_UNKNOWN;
297 break;
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */