nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / core / api / resultcolumn.cxx
blobafb2e3f574b5126499650d03b6ea5dd97e0af358
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/sdbc/SQLException.hpp>
22 #include <com/sun/star/sdbc/DataType.hpp>
23 #include <com/sun/star/sdbc/ColumnValue.hpp>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <tools/diagnose_ex.h>
26 #include <stringconstants.hxx>
27 #include <apitools.hxx>
29 using namespace ::com::sun::star::sdbc;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::container;
34 using namespace ::osl;
35 using namespace ::comphelper;
36 using namespace ::cppu;
37 using namespace dbaccess;
40 OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
41 const Reference< XDatabaseMetaData >& _rxDBMeta )
42 :OColumn( true )
43 ,m_xMetaData( _xMetaData )
44 ,m_xDBMetaData( _rxDBMeta )
45 ,m_nPos( _nPos )
49 void OResultColumn::impl_determineIsRowVersion_nothrow()
51 if ( m_aIsRowVersion.hasValue() )
52 return;
53 m_aIsRowVersion <<= false;
55 OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
56 if ( !m_xDBMetaData.is() )
57 return;
59 try
61 OUString sCatalog, sSchema, sTable, sColumnName;
62 getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog;
63 getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema;
64 getPropertyValue( PROPERTY_TABLENAME ) >>= sTable;
65 getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
67 try
69 Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
70 makeAny( sCatalog ), sSchema, sTable );
71 if ( xVersionColumns.is() ) // allowed to be NULL
73 Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
74 while ( xVersionColumns->next() )
76 if ( xResultRow->getString( 2 ) == sColumnName )
78 m_aIsRowVersion <<= true;
79 break;
84 catch(const SQLException&)
88 catch( const Exception& )
90 DBG_UNHANDLED_EXCEPTION("dbaccess");
94 OResultColumn::~OResultColumn()
98 // css::lang::XTypeProvider
99 Sequence< sal_Int8 > OResultColumn::getImplementationId()
101 return css::uno::Sequence<sal_Int8>();
104 // XServiceInfo
105 OUString OResultColumn::getImplementationName( )
107 return "com.sun.star.sdb.OResultColumn";
110 Sequence< OUString > OResultColumn::getSupportedServiceNames( )
112 return { SERVICE_SDBCX_COLUMN, SERVICE_SDB_RESULTCOLUMN };
115 // OComponentHelper
116 void OResultColumn::disposing()
118 OColumn::disposing();
120 MutexGuard aGuard(m_aMutex);
121 m_xMetaData = nullptr;
124 // comphelper::OPropertyArrayUsageHelper
125 ::cppu::IPropertyArrayHelper* OResultColumn::createArrayHelper( ) const
127 BEGIN_PROPERTY_HELPER(21)
128 DECL_PROP1(CATALOGNAME, OUString, READONLY);
129 DECL_PROP1(DISPLAYSIZE, sal_Int32, READONLY);
130 DECL_PROP1_BOOL(ISAUTOINCREMENT, READONLY);
131 DECL_PROP1_BOOL(ISCASESENSITIVE, READONLY);
132 DECL_PROP1_BOOL(ISCURRENCY, READONLY);
133 DECL_PROP1_BOOL(ISDEFINITELYWRITABLE, READONLY);
134 DECL_PROP1(ISNULLABLE, sal_Int32, READONLY);
135 DECL_PROP1_BOOL(ISREADONLY, READONLY);
136 DECL_PROP1_BOOL(ISROWVERSION, READONLY);
137 DECL_PROP1_BOOL(ISSEARCHABLE, READONLY);
138 DECL_PROP1_BOOL(ISSIGNED, READONLY);
139 DECL_PROP1_BOOL(ISWRITABLE, READONLY);
140 DECL_PROP1(LABEL, OUString, READONLY);
141 DECL_PROP1(NAME, OUString, READONLY);
142 DECL_PROP1(PRECISION, sal_Int32, READONLY);
143 DECL_PROP1(SCALE, sal_Int32, READONLY);
144 DECL_PROP1(SCHEMANAME, OUString, READONLY);
145 DECL_PROP1(SERVICENAME, OUString, READONLY);
146 DECL_PROP1(TABLENAME, OUString, READONLY);
147 DECL_PROP1(TYPE, sal_Int32, READONLY);
148 DECL_PROP1(TYPENAME, OUString, READONLY);
149 END_PROPERTY_HELPER();
152 // cppu::OPropertySetHelper
153 ::cppu::IPropertyArrayHelper& OResultColumn::getInfoHelper()
155 return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OResultColumn >* >(this)->getArrayHelper();
158 namespace
160 template< typename T >
161 void obtain( Any& _out_rValue, ::std::optional< T > & _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, T (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
163 if ( !_rCache )
164 _rCache = (_rxResultMeta.get()->*Getter)(_nPos);
165 _out_rValue <<= *_rCache;
169 void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
173 if ( OColumn::isRegisteredProperty( nHandle ) )
175 OColumn::getFastPropertyValue( rValue, nHandle );
177 else
179 switch (nHandle)
181 case PROPERTY_ID_ISROWVERSION:
182 const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
183 rValue = m_aIsRowVersion;
184 break;
185 case PROPERTY_ID_TABLENAME:
186 rValue <<= m_xMetaData->getTableName(m_nPos);
187 break;
188 case PROPERTY_ID_SCHEMANAME:
189 rValue <<= m_xMetaData->getSchemaName(m_nPos);
190 break;
191 case PROPERTY_ID_CATALOGNAME:
192 rValue <<= m_xMetaData->getCatalogName(m_nPos);
193 break;
194 case PROPERTY_ID_ISSIGNED:
195 obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
196 break;
197 case PROPERTY_ID_ISCURRENCY:
198 obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
199 break;
200 case PROPERTY_ID_ISSEARCHABLE:
201 obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
202 break;
203 case PROPERTY_ID_ISCASESENSITIVE:
204 obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
205 break;
206 case PROPERTY_ID_ISREADONLY:
207 obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
208 break;
209 case PROPERTY_ID_ISWRITABLE:
210 obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
211 break;
212 case PROPERTY_ID_ISDEFINITELYWRITABLE:
213 obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
214 break;
215 case PROPERTY_ID_ISAUTOINCREMENT:
216 obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
217 break;
218 case PROPERTY_ID_SERVICENAME:
219 rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
220 break;
221 case PROPERTY_ID_LABEL:
222 obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
223 break;
224 case PROPERTY_ID_DISPLAYSIZE:
225 obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
226 break;
227 case PROPERTY_ID_TYPE:
228 obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
229 break;
230 case PROPERTY_ID_PRECISION:
231 obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
232 break;
233 case PROPERTY_ID_SCALE:
234 obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
235 break;
236 case PROPERTY_ID_ISNULLABLE:
237 obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
238 break;
239 case PROPERTY_ID_TYPENAME:
240 rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
241 break;
242 default:
243 OSL_FAIL( "OResultColumn::getFastPropertyValue: unknown property handle!" );
244 break;
248 catch (SQLException& )
250 // default handling if we caught an exception
251 switch (nHandle)
253 case PROPERTY_ID_LABEL:
254 case PROPERTY_ID_TYPENAME:
255 case PROPERTY_ID_SERVICENAME:
256 case PROPERTY_ID_TABLENAME:
257 case PROPERTY_ID_SCHEMANAME:
258 case PROPERTY_ID_CATALOGNAME:
259 // empty string'S
260 rValue <<= OUString();
261 break;
262 case PROPERTY_ID_ISROWVERSION:
263 case PROPERTY_ID_ISAUTOINCREMENT:
264 case PROPERTY_ID_ISWRITABLE:
265 case PROPERTY_ID_ISDEFINITELYWRITABLE:
266 case PROPERTY_ID_ISCASESENSITIVE:
267 case PROPERTY_ID_ISSEARCHABLE:
268 case PROPERTY_ID_ISCURRENCY:
269 case PROPERTY_ID_ISSIGNED:
271 rValue <<= false;
272 } break;
273 case PROPERTY_ID_ISREADONLY:
275 rValue <<= true;
276 } break;
277 case PROPERTY_ID_SCALE:
278 case PROPERTY_ID_PRECISION:
279 case PROPERTY_ID_DISPLAYSIZE:
280 rValue <<= sal_Int32(0);
281 break;
282 case PROPERTY_ID_TYPE:
283 rValue <<= sal_Int32(DataType::SQLNULL);
284 break;
285 case PROPERTY_ID_ISNULLABLE:
286 rValue <<= ColumnValue::NULLABLE_UNKNOWN;
287 break;
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */