bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / parse / PColumn.cxx
blob04fc07196f9e26031ff64b70b8328bcb09faff17
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 .
21 #include <connectivity/PColumn.hxx>
22 #include <connectivity/dbtools.hxx>
23 #include "TConnection.hxx"
25 #include <comphelper/types.hxx>
26 #include <tools/diagnose_ex.h>
28 using namespace ::comphelper;
29 using namespace connectivity;
30 using namespace dbtools;
31 using namespace connectivity::parse;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
38 OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn, bool _bCase)
39 : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
40 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
41 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
42 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
43 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
44 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
45 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
46 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
47 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
48 , false
49 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
50 , _bCase
51 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME)))
52 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME)))
53 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
55 , m_bFunction(false)
56 , m_bDbasePrecisionChanged(false)
57 , m_bAggregateFunction(false)
58 , m_bIsSearchable( true )
60 construct();
64 OParseColumn::OParseColumn( const OUString& _Name,
65 const OUString& _TypeName,
66 const OUString& _DefaultValue,
67 const OUString& _Description,
68 sal_Int32 _IsNullable,
69 sal_Int32 _Precision,
70 sal_Int32 _Scale,
71 sal_Int32 _Type,
72 bool _IsAutoIncrement,
73 bool _IsCurrency,
74 bool _bCase,
75 const OUString& _CatalogName,
76 const OUString& _SchemaName,
77 const OUString& _TableName
78 ) : connectivity::sdbcx::OColumn(_Name,
79 _TypeName,
80 _DefaultValue,
81 _Description,
82 _IsNullable,
83 _Precision,
84 _Scale,
85 _Type,
86 _IsAutoIncrement,
87 false,
88 _IsCurrency,
89 _bCase,
90 _CatalogName,
91 _SchemaName,
92 _TableName)
93 , m_bFunction(false)
94 , m_bDbasePrecisionChanged(false)
95 , m_bAggregateFunction(false)
96 , m_bIsSearchable( true )
98 construct();
102 ::rtl::Reference< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
103 const Reference< XDatabaseMetaData >& _rxDBMetaData,const Reference< XNameAccess>& i_xQueryColumns )
105 sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
106 ::rtl::Reference< OSQLColumns > aReturn( new OSQLColumns ); aReturn->get().reserve( nColumnCount );
108 StringMap aColumnMap;
109 for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
111 OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
112 aReturn->get().push_back( pColumn );
113 if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
115 Reference<XPropertySet> xColumn(i_xQueryColumns->getByName(pColumn->getRealName()),UNO_QUERY_THROW);
116 OUString sLabel;
117 xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
118 if ( !sLabel.isEmpty() )
119 pColumn->setLabel(sLabel);
123 return aReturn;
127 OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
128 const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
130 OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
131 // retrieve the name of the column
132 // check for duplicate entries
133 if(_rColumns.find(sLabel) != _rColumns.end())
135 OUString sAlias(sLabel);
136 sal_Int32 searchIndex=1;
137 while(_rColumns.find(sAlias) != _rColumns.end())
139 (sAlias = sLabel) += OUString::number(searchIndex++);
141 sLabel = sAlias;
143 _rColumns.insert(StringMap::value_type(sLabel,0));
144 OParseColumn* pColumn = new OParseColumn(
145 sLabel,
146 _rxResMetaData->getColumnTypeName( _nColumnPos ),
147 OUString(),
148 OUString(),
149 _rxResMetaData->isNullable( _nColumnPos ),
150 _rxResMetaData->getPrecision( _nColumnPos ),
151 _rxResMetaData->getScale( _nColumnPos ),
152 _rxResMetaData->getColumnType( _nColumnPos ),
153 _rxResMetaData->isAutoIncrement( _nColumnPos ),
154 _rxResMetaData->isCurrency( _nColumnPos ),
155 _rxDBMetaData->supportsMixedCaseQuotedIdentifiers(),
156 _rxResMetaData->getCatalogName( _nColumnPos ),
157 _rxResMetaData->getSchemaName( _nColumnPos ),
158 _rxResMetaData->getTableName( _nColumnPos )
160 pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
161 pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
162 pColumn->setLabel(sLabel);
163 return pColumn;
167 OParseColumn::~OParseColumn()
171 void OParseColumn::construct()
173 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION), PROPERTY_ID_FUNCTION, 0, &m_bFunction, cppu::UnoType<decltype(m_bFunction)>::get());
174 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION), PROPERTY_ID_AGGREGATEFUNCTION, 0, &m_bAggregateFunction, cppu::UnoType<decltype(m_bAggregateFunction)>::get());
175 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, cppu::UnoType<decltype(m_aRealName)>::get());
176 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, cppu::UnoType<decltype(m_bDbasePrecisionChanged)>::get());
177 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, cppu::UnoType<decltype(m_bIsSearchable)>::get());
178 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, cppu::UnoType<decltype(m_sLabel)>::get());
181 ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
183 return doCreateArrayHelper();
186 ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
188 OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
189 return *OParseColumn_PROP::getArrayHelper();
193 OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const OUString& i_rOriginatingTableName,
194 bool _bCase, bool _bAscending )
195 : connectivity::sdbcx::OColumn(
196 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
197 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
198 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
199 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
200 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
201 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
202 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
203 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
204 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
205 false,
206 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
207 _bCase,
208 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
209 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
210 i_rOriginatingTableName
212 ,m_bAscending(_bAscending)
214 construct();
218 OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, bool _bCase, bool _bAscending )
219 : connectivity::sdbcx::OColumn(
220 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
221 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
222 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
223 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
224 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
225 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
226 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
227 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
228 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
229 false,
230 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
231 _bCase,
232 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
233 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
234 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
236 ,m_bAscending(_bAscending)
238 construct();
242 OOrderColumn::~OOrderColumn()
247 void OOrderColumn::construct()
249 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING,
250 PropertyAttribute::READONLY, const_cast< bool* >( &m_bAscending ), cppu::UnoType<decltype(m_bAscending)>::get() );
253 ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
255 return doCreateArrayHelper();
258 ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
260 OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
261 return *OOrderColumn_PROP::getArrayHelper();
264 ::com::sun::star::uno::Sequence< OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
266 ::com::sun::star::uno::Sequence< OUString > aSupported(1);
267 aSupported[0] = "com.sun.star.sdb.OrderColumn";
269 return aSupported;
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */