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 : 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;
36 :
37 :
38 0 : OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn, bool _bCase)
39 0 : : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
40 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
41 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
42 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
43 0 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
44 0 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
45 0 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
46 0 : , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
47 0 : , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
48 : , false
49 0 : , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
50 : , _bCase
51 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME)))
52 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME)))
53 0 : , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
54 : )
55 : , m_bFunction(false)
56 : , m_bDbasePrecisionChanged(false)
57 : , m_bAggregateFunction(false)
58 0 : , m_bIsSearchable( true )
59 : {
60 0 : construct();
61 0 : }
62 :
63 :
64 0 : 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 0 : , m_bIsSearchable( true )
97 : {
98 0 : construct();
99 0 : }
100 :
101 :
102 0 : ::rtl::Reference< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
103 : const Reference< XDatabaseMetaData >& _rxDBMetaData,const Reference< XNameAccess>& i_xQueryColumns )
104 : {
105 0 : sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
106 0 : ::rtl::Reference< OSQLColumns > aReturn( new OSQLColumns ); aReturn->get().reserve( nColumnCount );
107 :
108 0 : StringMap aColumnMap;
109 0 : for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
110 : {
111 0 : OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
112 0 : aReturn->get().push_back( pColumn );
113 0 : if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
114 : {
115 0 : Reference<XPropertySet> xColumn(i_xQueryColumns->getByName(pColumn->getRealName()),UNO_QUERY_THROW);
116 0 : OUString sLabel;
117 0 : xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
118 0 : if ( !sLabel.isEmpty() )
119 0 : pColumn->setLabel(sLabel);
120 : }
121 : }
122 :
123 0 : return aReturn;
124 : }
125 :
126 :
127 0 : OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
128 : const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
129 : {
130 0 : OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
131 : // retrieve the name of the column
132 : // check for duplicate entries
133 0 : if(_rColumns.find(sLabel) != _rColumns.end())
134 : {
135 0 : OUString sAlias(sLabel);
136 0 : sal_Int32 searchIndex=1;
137 0 : while(_rColumns.find(sAlias) != _rColumns.end())
138 : {
139 0 : (sAlias = sLabel) += OUString::number(searchIndex++);
140 : }
141 0 : sLabel = sAlias;
142 : }
143 0 : _rColumns.insert(StringMap::value_type(sLabel,0));
144 : OParseColumn* pColumn = new OParseColumn(
145 : sLabel,
146 0 : _rxResMetaData->getColumnTypeName( _nColumnPos ),
147 : OUString(),
148 : OUString(),
149 0 : _rxResMetaData->isNullable( _nColumnPos ),
150 0 : _rxResMetaData->getPrecision( _nColumnPos ),
151 0 : _rxResMetaData->getScale( _nColumnPos ),
152 0 : _rxResMetaData->getColumnType( _nColumnPos ),
153 0 : _rxResMetaData->isAutoIncrement( _nColumnPos ),
154 0 : _rxResMetaData->isCurrency( _nColumnPos ),
155 0 : _rxDBMetaData->supportsMixedCaseQuotedIdentifiers(),
156 0 : _rxResMetaData->getCatalogName( _nColumnPos ),
157 0 : _rxResMetaData->getSchemaName( _nColumnPos ),
158 0 : _rxResMetaData->getTableName( _nColumnPos )
159 0 : );
160 0 : pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
161 0 : pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
162 0 : pColumn->setLabel(sLabel);
163 0 : return pColumn;
164 : }
165 :
166 :
167 0 : OParseColumn::~OParseColumn()
168 : {
169 0 : }
170 :
171 0 : void OParseColumn::construct()
172 : {
173 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION), PROPERTY_ID_FUNCTION, 0, &m_bFunction, ::getCppuType(&m_bFunction));
174 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION), PROPERTY_ID_AGGREGATEFUNCTION, 0, &m_bAggregateFunction, ::getCppuType(&m_bAggregateFunction));
175 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(&m_aRealName));
176 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(&m_bDbasePrecisionChanged));
177 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(&m_bIsSearchable));
178 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, ::getCppuType(&m_sLabel));
179 0 : }
180 :
181 0 : ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
182 : {
183 0 : return doCreateArrayHelper();
184 : }
185 :
186 0 : ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
187 : {
188 : OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
189 0 : return *OParseColumn_PROP::getArrayHelper();
190 : }
191 :
192 :
193 0 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const OUString& i_rOriginatingTableName,
194 : bool _bCase, bool _bAscending )
195 : : connectivity::sdbcx::OColumn(
196 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
197 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
198 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
199 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
200 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
201 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
202 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
203 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
204 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
205 : false,
206 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
207 : _bCase,
208 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
209 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
210 : i_rOriginatingTableName
211 : )
212 0 : ,m_bAscending(_bAscending)
213 : {
214 0 : construct();
215 0 : }
216 :
217 :
218 0 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, bool _bCase, bool _bAscending )
219 : : connectivity::sdbcx::OColumn(
220 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
221 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
222 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
223 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
224 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
225 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
226 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
227 0 : getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
228 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
229 : false,
230 0 : getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
231 : _bCase,
232 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
233 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
234 0 : getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
235 : )
236 0 : ,m_bAscending(_bAscending)
237 : {
238 0 : construct();
239 0 : }
240 :
241 :
242 0 : OOrderColumn::~OOrderColumn()
243 : {
244 0 : }
245 :
246 :
247 0 : void OOrderColumn::construct()
248 : {
249 0 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING,
250 0 : PropertyAttribute::READONLY, const_cast< sal_Bool* >( &m_bAscending ), ::getCppuType( &m_bAscending ) );
251 0 : }
252 :
253 0 : ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
254 : {
255 0 : return doCreateArrayHelper();
256 : }
257 :
258 0 : ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
259 : {
260 : OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
261 0 : return *OOrderColumn_PROP::getArrayHelper();
262 : }
263 :
264 0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
265 : {
266 0 : ::com::sun::star::uno::Sequence< OUString > aSupported(1);
267 0 : aSupported[0] = "com.sun.star.sdb.OrderColumn";
268 :
269 0 : return aSupported;
270 : }
271 :
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|