LibreOffice Module connectivity (master) 1
PColumn.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
22#include <TConnection.hxx>
23
24#include <comphelper/types.hxx>
25
26#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
27#include <com/sun/star/beans/PropertyAttribute.hpp>
28
29using namespace ::comphelper;
30using namespace connectivity;
31using namespace dbtools;
32using namespace connectivity::parse;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::sdbc;
35using namespace ::com::sun::star::beans;
36using namespace ::com::sun::star::container;
37
38
39OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn, bool _bCase)
40 : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
41 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
42 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
43 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
44 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
45 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
46 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
47 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
48 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
49 , false
50 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
51 , _bCase
52 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME)))
53 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME)))
54 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
55 )
56 , m_bFunction(false)
57 , m_bDbasePrecisionChanged(false)
58 , m_bAggregateFunction(false)
59 , m_bIsSearchable( true )
60{
61 construct();
62}
63
64
65OParseColumn::OParseColumn( const OUString& Name,
66 const OUString& TypeName,
67 const OUString& DefaultValue,
68 const OUString& Description,
69 sal_Int32 IsNullable,
70 sal_Int32 Precision,
71 sal_Int32 Scale,
72 sal_Int32 Type,
73 bool IsAutoIncrement,
74 bool IsCurrency,
75 bool _bCase,
76 const OUString& CatalogName,
77 const OUString& SchemaName,
78 const OUString& TableName
79 ) : connectivity::sdbcx::OColumn(Name,
80 TypeName,
81 DefaultValue,
82 Description,
83 IsNullable,
84 Precision,
85 Scale,
86 Type,
87 IsAutoIncrement,
88 false,
89 IsCurrency,
90 _bCase,
91 CatalogName,
92 SchemaName,
93 TableName)
94 , m_bFunction(false)
95 , m_bDbasePrecisionChanged(false)
96 , m_bAggregateFunction(false)
97 , m_bIsSearchable( true )
98{
99 construct();
100}
101
102
103::rtl::Reference< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
104 const Reference< XDatabaseMetaData >& _rxDBMetaData,const Reference< XNameAccess>& i_xQueryColumns )
105{
106 sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
107 ::rtl::Reference aReturn( new OSQLColumns ); aReturn->reserve( nColumnCount );
108
109 StringMap aColumnMap;
110 for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
111 {
112 rtl::Reference<OParseColumn> pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
113 aReturn->push_back( pColumn );
114 if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
115 {
116 Reference<XPropertySet> xColumn(i_xQueryColumns->getByName(pColumn->getRealName()),UNO_QUERY_THROW);
117 OUString sLabel;
118 xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
119 if ( !sLabel.isEmpty() )
120 pColumn->setLabel(sLabel);
121 }
122 }
123
124 return aReturn;
125}
126
127
128rtl::Reference<OParseColumn> OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
129 const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
130{
131 OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
132 // retrieve the name of the column
133 // check for duplicate entries
134 if(_rColumns.find(sLabel) != _rColumns.end())
135 {
136 OUString sAlias(sLabel);
137 sal_Int32 searchIndex=1;
138 while(_rColumns.find(sAlias) != _rColumns.end())
139 {
140 sAlias = sLabel + OUString::number(searchIndex++);
141 }
142 sLabel = sAlias;
143 }
144 _rColumns.emplace(sLabel,0);
146 sLabel,
147 _rxResMetaData->getColumnTypeName( _nColumnPos ),
148 OUString(),
149 OUString(),
150 _rxResMetaData->isNullable( _nColumnPos ),
151 _rxResMetaData->getPrecision( _nColumnPos ),
152 _rxResMetaData->getScale( _nColumnPos ),
153 _rxResMetaData->getColumnType( _nColumnPos ),
154 _rxResMetaData->isAutoIncrement( _nColumnPos ),
155 _rxResMetaData->isCurrency( _nColumnPos ),
156 _rxDBMetaData->supportsMixedCaseQuotedIdentifiers(),
157 _rxResMetaData->getCatalogName( _nColumnPos ),
158 _rxResMetaData->getSchemaName( _nColumnPos ),
159 _rxResMetaData->getTableName( _nColumnPos )
160 );
161 pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
162 pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
163 pColumn->setLabel(sLabel);
164 return pColumn;
165}
166
167
169{
170}
171
173{
180}
181
183{
184 return doCreateArrayHelper();
185}
186
188{
189 OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
191}
192
193
194OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const OUString& i_rOriginatingTableName,
195 bool _bCase, bool _bAscending )
196 : connectivity::sdbcx::OColumn(
197 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
198 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
199 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
200 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
201 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
202 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
203 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
204 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
205 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
206 false,
207 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
208 _bCase,
209 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
210 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
211 i_rOriginatingTableName
212 )
213 ,m_bAscending(_bAscending)
214{
215 construct();
216}
217
218
219OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, bool _bCase, bool _bAscending )
220 : connectivity::sdbcx::OColumn(
221 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
222 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
223 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
224 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
225 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
226 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
227 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
228 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
229 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
230 false,
231 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
232 _bCase,
233 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
234 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
235 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
236 )
237 ,m_bAscending(_bAscending)
238{
239 construct();
240}
241
242
244{
245}
246
247
249{
251 PropertyAttribute::READONLY, const_cast< bool* >( &m_bAscending ), cppu::UnoType<decltype(m_bAscending)>::get() );
252}
253
255{
256 return doCreateArrayHelper();
257}
258
260{
261 OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
263}
264
265css::uno::Sequence< OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( )
266{
267 return { "com.sun.star.sdb.OrderColumn" };
268}
269
270
271/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::cppu::IPropertyArrayHelper * getArrayHelper()
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
OOrderColumn(const css::uno::Reference< css::beans::XPropertySet > &_xColumn, const OUString &i_rOriginatingTableName, bool _bCase, bool _bAscending)
virtual void construct() override
Definition: PColumn.cxx:248
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
Definition: PColumn.cxx:259
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: PColumn.cxx:265
virtual ~OOrderColumn() override
Definition: PColumn.cxx:243
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
Definition: PColumn.cxx:254
static rtl::Reference< OParseColumn > createColumnForResultSet(const css::uno::Reference< css::sdbc::XResultSetMetaData > &_rxResMetaData, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_rxDBMetaData, sal_Int32 _nColumnPos, StringMap &_rColumns)
creates a single OParseColumn, as described by a result set meta data instance.
Definition: PColumn.cxx:128
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
Definition: PColumn.cxx:182
OParseColumn(const css::uno::Reference< css::beans::XPropertySet > &_xColumn, bool _bCase)
static ::rtl::Reference< OSQLColumns > createColumnsForResultSet(const css::uno::Reference< css::sdbc::XResultSetMetaData > &_rxResMetaData, const css::uno::Reference< css::sdbc::XDatabaseMetaData > &_rxDBMetaData, const css::uno::Reference< css::container::XNameAccess > &i_xQueryColumns)
creates a collection of OParseColumn, as described by a result set meta data instance.
Definition: PColumn.cxx:103
virtual void construct() override
Definition: PColumn.cxx:172
virtual ~OParseColumn() override
Definition: PColumn.cxx:168
std::map< OUString, int > StringMap
Definition: PColumn.hxx:93
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
Definition: PColumn.cxx:187
::cppu::IPropertyArrayHelper * doCreateArrayHelper() const
helper for derived classes to implement OPropertyArrayUsageHelper::createArrayHelper
Definition: VDescriptor.cxx:66
Reference< XColumn > xColumn
bool getBOOL(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
OUString getString(const Any &_rAny)
Type
int i
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51
#define PROPERTY_ID_TABLENAME
Definition: propertyids.hxx:78
#define PROPERTY_ID_DESCRIPTION
Definition: propertyids.hxx:58
#define PROPERTY_ID_DBASEPRECISIONCHANGED
Definition: propertyids.hxx:80
#define PROPERTY_ID_AGGREGATEFUNCTION
Definition: propertyids.hxx:98
#define PROPERTY_ID_CATALOGNAME
Definition: propertyids.hxx:70
#define PROPERTY_ID_ISSEARCHABLE
Definition: propertyids.hxx:99
#define PROPERTY_ID_ISASCENDING
Definition: propertyids.hxx:68
#define PROPERTY_ID_ISNULLABLE
Definition: propertyids.hxx:55
#define PROPERTY_ID_FUNCTION
Definition: propertyids.hxx:77
#define PROPERTY_ID_PRECISION
Definition: propertyids.hxx:53
#define PROPERTY_ID_LABEL
Definition: propertyids.hxx:86
#define PROPERTY_ID_SCHEMANAME
Definition: propertyids.hxx:69
#define PROPERTY_ID_ISAUTOINCREMENT
Definition: propertyids.hxx:56
#define PROPERTY_ID_ISCURRENCY
Definition: propertyids.hxx:81
#define PROPERTY_ID_TYPENAME
Definition: propertyids.hxx:52
#define PROPERTY_ID_DEFAULTVALUE
Definition: propertyids.hxx:59
#define PROPERTY_ID_REALNAME
Definition: propertyids.hxx:79
#define PROPERTY_ID_SCALE
Definition: propertyids.hxx:54
OUString Name