Line data Source code
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 :
21 : #include "connectivity/PColumn.hxx"
22 : #include "connectivity/dbtools.hxx"
23 : #include "TConnection.hxx"
24 :
25 : #include <comphelper/types.hxx>
26 : #include <tools/diagnose_ex.h>
27 :
28 : #include <bitset>
29 :
30 : using namespace ::comphelper;
31 : using namespace connectivity;
32 : using namespace dbtools;
33 : using namespace connectivity::parse;
34 : using namespace ::com::sun::star::uno;
35 : using namespace ::com::sun::star::sdbc;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::container;
38 :
39 : // -------------------------------------------------------------------------
40 2 : OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn,sal_Bool _bCase)
41 2 : : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
42 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
43 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
44 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
45 2 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
46 2 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
47 2 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
48 2 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
49 4 : , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
50 : , sal_False
51 4 : , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
52 : , _bCase
53 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME)))
54 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME)))
55 2 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
56 : )
57 : , m_bFunction(sal_False)
58 : , m_bDbasePrecisionChanged(sal_False)
59 : , m_bAggregateFunction(sal_False)
60 28 : , m_bIsSearchable( sal_True )
61 : {
62 2 : construct();
63 2 : }
64 :
65 : // -------------------------------------------------------------------------
66 0 : OParseColumn::OParseColumn( const ::rtl::OUString& _Name,
67 : const ::rtl::OUString& _TypeName,
68 : const ::rtl::OUString& _DefaultValue,
69 : const ::rtl::OUString& _Description,
70 : sal_Int32 _IsNullable,
71 : sal_Int32 _Precision,
72 : sal_Int32 _Scale,
73 : sal_Int32 _Type,
74 : sal_Bool _IsAutoIncrement,
75 : sal_Bool _IsCurrency,
76 : sal_Bool _bCase,
77 : const ::rtl::OUString& _CatalogName,
78 : const ::rtl::OUString& _SchemaName,
79 : const ::rtl::OUString& _TableName
80 : ) : connectivity::sdbcx::OColumn(_Name,
81 : _TypeName,
82 : _DefaultValue,
83 : _Description,
84 : _IsNullable,
85 : _Precision,
86 : _Scale,
87 : _Type,
88 : _IsAutoIncrement,
89 : sal_False,
90 : _IsCurrency,
91 : _bCase,
92 : _CatalogName,
93 : _SchemaName,
94 : _TableName)
95 : , m_bFunction(sal_False)
96 : , m_bDbasePrecisionChanged(sal_False)
97 : , m_bAggregateFunction(sal_False)
98 0 : , m_bIsSearchable( sal_True )
99 : {
100 0 : construct();
101 0 : }
102 :
103 : // -------------------------------------------------------------------------
104 0 : ::rtl::Reference< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
105 : const Reference< XDatabaseMetaData >& _rxDBMetaData,const Reference< XNameAccess>& i_xQueryColumns )
106 : {
107 0 : sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
108 0 : ::rtl::Reference< OSQLColumns > aReturn( new OSQLColumns ); aReturn->get().reserve( nColumnCount );
109 :
110 0 : StringMap aColumnMap;
111 0 : for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
112 : {
113 0 : OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
114 0 : aReturn->get().push_back( pColumn );
115 0 : if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
116 : {
117 0 : Reference<XPropertySet> xColumn(i_xQueryColumns->getByName(pColumn->getRealName()),UNO_QUERY_THROW);
118 0 : ::rtl::OUString sLabel;
119 0 : xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
120 0 : if ( !sLabel.isEmpty() )
121 0 : pColumn->setLabel(sLabel);
122 : }
123 : }
124 :
125 0 : return aReturn;
126 : }
127 :
128 : // -------------------------------------------------------------------------
129 0 : OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
130 : const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
131 : {
132 0 : ::rtl::OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
133 : // retrieve the name of the column
134 : // check for duplicate entries
135 0 : if(_rColumns.find(sLabel) != _rColumns.end())
136 : {
137 0 : ::rtl::OUString sAlias(sLabel);
138 0 : sal_Int32 searchIndex=1;
139 0 : while(_rColumns.find(sAlias) != _rColumns.end())
140 : {
141 0 : (sAlias = sLabel) += ::rtl::OUString::valueOf(searchIndex++);
142 : }
143 0 : sLabel = sAlias;
144 : }
145 0 : _rColumns.insert(StringMap::value_type(sLabel,0));
146 : OParseColumn* pColumn = new OParseColumn(
147 : sLabel,
148 0 : _rxResMetaData->getColumnTypeName( _nColumnPos ),
149 : ::rtl::OUString(),
150 : ::rtl::OUString(),
151 0 : _rxResMetaData->isNullable( _nColumnPos ),
152 0 : _rxResMetaData->getPrecision( _nColumnPos ),
153 0 : _rxResMetaData->getScale( _nColumnPos ),
154 0 : _rxResMetaData->getColumnType( _nColumnPos ),
155 0 : _rxResMetaData->isAutoIncrement( _nColumnPos ),
156 0 : _rxResMetaData->isCurrency( _nColumnPos ),
157 0 : _rxDBMetaData->supportsMixedCaseQuotedIdentifiers(),
158 0 : _rxResMetaData->getCatalogName( _nColumnPos ),
159 0 : _rxResMetaData->getSchemaName( _nColumnPos ),
160 0 : _rxResMetaData->getTableName( _nColumnPos )
161 0 : );
162 0 : pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
163 0 : pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
164 0 : pColumn->setLabel(sLabel);
165 0 : return pColumn;
166 : }
167 :
168 : // -------------------------------------------------------------------------
169 0 : OParseColumn::~OParseColumn()
170 : {
171 0 : }
172 : // -------------------------------------------------------------------------
173 2 : void OParseColumn::construct()
174 : {
175 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION), PROPERTY_ID_FUNCTION, 0, &m_bFunction, ::getCppuType(&m_bFunction));
176 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION), PROPERTY_ID_AGGREGATEFUNCTION, 0, &m_bAggregateFunction, ::getCppuType(&m_bAggregateFunction));
177 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(&m_aRealName));
178 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(&m_bDbasePrecisionChanged));
179 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(&m_bIsSearchable));
180 2 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, ::getCppuType(&m_sLabel));
181 2 : }
182 : // -----------------------------------------------------------------------------
183 1 : ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
184 : {
185 1 : return doCreateArrayHelper();
186 : }
187 : // -----------------------------------------------------------------------------
188 10 : ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
189 : {
190 : OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
191 10 : return *OParseColumn_PROP::getArrayHelper();
192 : }
193 :
194 : // -----------------------------------------------------------------------------
195 1 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const ::rtl::OUString& i_rOriginatingTableName,
196 : sal_Bool _bCase, sal_Bool _bAscending )
197 : : connectivity::sdbcx::OColumn(
198 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
199 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
200 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
201 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
202 1 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
203 1 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
204 1 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
205 1 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
206 2 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
207 : sal_False,
208 2 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
209 : _bCase,
210 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
211 1 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
212 : i_rOriginatingTableName
213 : )
214 13 : ,m_bAscending(_bAscending)
215 : {
216 1 : construct();
217 : OSL_ENSURE( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME))).isEmpty() ||
218 : i_rOriginatingTableName == getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)) ),
219 : "dbaccess::OOrderColumn::OOrderColumn: forced originating table name != underlying column table name" );
220 1 : }
221 :
222 : // -----------------------------------------------------------------------------
223 0 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, sal_Bool _bCase, sal_Bool _bAscending )
224 : : connectivity::sdbcx::OColumn(
225 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
226 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
227 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
228 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
229 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
230 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
231 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
232 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
233 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
234 : sal_False,
235 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
236 : _bCase,
237 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
238 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
239 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
240 : )
241 0 : ,m_bAscending(_bAscending)
242 : {
243 0 : construct();
244 0 : }
245 :
246 : // -------------------------------------------------------------------------
247 0 : OOrderColumn::~OOrderColumn()
248 : {
249 0 : }
250 :
251 : // -------------------------------------------------------------------------
252 1 : void OOrderColumn::construct()
253 : {
254 1 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING,
255 2 : PropertyAttribute::READONLY, const_cast< sal_Bool* >( &m_bAscending ), ::getCppuType( &m_bAscending ) );
256 1 : }
257 : // -----------------------------------------------------------------------------
258 0 : ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
259 : {
260 0 : return doCreateArrayHelper();
261 : }
262 : // -----------------------------------------------------------------------------
263 0 : ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
264 : {
265 : OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
266 0 : return *OOrderColumn_PROP::getArrayHelper();
267 : }
268 : // -----------------------------------------------------------------------------
269 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
270 : {
271 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
272 0 : aSupported[0] = ::rtl::OUString("com.sun.star.sdb.OrderColumn");
273 :
274 0 : return aSupported;
275 : }
276 : // -----------------------------------------------------------------------------
277 :
278 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|