Bump for 3.6-28
[LibreOffice.git] / connectivity / source / parse / PColumn.cxx
blobad88c2587e4b5df04e1f3f7a35eeda92f8f83875
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "connectivity/PColumn.hxx"
31 #include "connectivity/dbtools.hxx"
32 #include "TConnection.hxx"
34 #include <comphelper/types.hxx>
35 #include <tools/diagnose_ex.h>
37 using namespace ::comphelper;
38 using namespace connectivity;
39 using namespace dbtools;
40 using namespace connectivity::parse;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::sdbc;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::container;
46 // -------------------------------------------------------------------------
47 OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn,sal_Bool _bCase)
48 : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
49 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
50 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
51 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
52 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
53 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
54 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
55 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
56 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
57 , sal_False
58 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
59 , _bCase
61 , m_bFunction(sal_False)
62 , m_bDbasePrecisionChanged(sal_False)
63 , m_bAggregateFunction(sal_False)
64 , m_bIsSearchable( sal_True )
66 construct();
69 // -------------------------------------------------------------------------
70 OParseColumn::OParseColumn( const ::rtl::OUString& _Name,
71 const ::rtl::OUString& _TypeName,
72 const ::rtl::OUString& _DefaultValue,
73 const ::rtl::OUString& _Description,
74 sal_Int32 _IsNullable,
75 sal_Int32 _Precision,
76 sal_Int32 _Scale,
77 sal_Int32 _Type,
78 sal_Bool _IsAutoIncrement,
79 sal_Bool _IsCurrency,
80 sal_Bool _bCase
81 ) : connectivity::sdbcx::OColumn(_Name,
82 _TypeName,
83 _DefaultValue,
84 _Description,
85 _IsNullable,
86 _Precision,
87 _Scale,
88 _Type,
89 _IsAutoIncrement,
90 sal_False,
91 _IsCurrency,
92 _bCase)
93 , m_bFunction(sal_False)
94 , m_bDbasePrecisionChanged(sal_False)
95 , m_bAggregateFunction(sal_False)
96 , m_bIsSearchable( sal_True )
98 construct();
101 // -------------------------------------------------------------------------
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 ::rtl::OUString sLabel;
117 xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
118 if ( !sLabel.isEmpty() )
119 pColumn->setLabel(sLabel);
123 return aReturn;
126 // -------------------------------------------------------------------------
127 OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
128 const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos,StringMap& _rColumns )
130 ::rtl::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 ::rtl::OUString sAlias(sLabel);
136 sal_Int32 searchIndex=1;
137 while(_rColumns.find(sAlias) != _rColumns.end())
139 (sAlias = sLabel) += ::rtl::OUString::valueOf(searchIndex++);
141 sLabel = sAlias;
143 _rColumns.insert(StringMap::value_type(sLabel,0));
144 OParseColumn* pColumn = new OParseColumn(
145 sLabel,
146 _rxResMetaData->getColumnTypeName( _nColumnPos ),
147 ::rtl::OUString(),
148 ::rtl::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()
157 const ::rtl::OUString sTableName = _rxResMetaData->getTableName( _nColumnPos );
158 if ( !sTableName.isEmpty() )
159 pColumn->setTableName( ::dbtools::composeTableName( _rxDBMetaData,
160 _rxResMetaData->getCatalogName( _nColumnPos ),
161 _rxResMetaData->getSchemaName( _nColumnPos ),
162 sTableName,
163 sal_False,
164 eComplete
165 ) );
166 pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
167 pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
168 pColumn->setLabel(sLabel);
169 return pColumn;
172 // -------------------------------------------------------------------------
173 OParseColumn::~OParseColumn()
176 // -------------------------------------------------------------------------
177 void OParseColumn::construct()
179 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION), PROPERTY_ID_FUNCTION, 0, &m_bFunction, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
180 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION), PROPERTY_ID_AGGREGATEFUNCTION, 0, &m_bAggregateFunction, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
181 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME), PROPERTY_ID_TABLENAME, 0, &m_aTableName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
182 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
183 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(reinterpret_cast<sal_Bool*>(NULL)));
184 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
185 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
187 // -----------------------------------------------------------------------------
188 ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
190 return doCreateArrayHelper();
192 // -----------------------------------------------------------------------------
193 ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
195 OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
196 return *OParseColumn_PROP::getArrayHelper();
199 // -----------------------------------------------------------------------------
200 namespace
202 ::rtl::OUString lcl_getColumnTableName( const Reference< XPropertySet >& i_parseColumn )
204 ::rtl::OUString sColumnTableName;
207 OSL_VERIFY( i_parseColumn->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_TABLENAME ) ) >>= sColumnTableName );
209 catch( const Exception& )
211 DBG_UNHANDLED_EXCEPTION();
213 return sColumnTableName;
217 // -----------------------------------------------------------------------------
218 OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const ::rtl::OUString& i_rOriginatingTableName,
219 sal_Bool _bCase, sal_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 sal_False,
231 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
232 _bCase
234 ,m_bAscending(_bAscending)
235 ,m_sTableName( i_rOriginatingTableName )
237 construct();
240 // -----------------------------------------------------------------------------
241 OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, sal_Bool _bCase, sal_Bool _bAscending )
242 : connectivity::sdbcx::OColumn(
243 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
244 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
245 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
246 getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
247 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
248 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
249 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
250 getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
251 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
252 sal_False,
253 getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
254 _bCase
256 ,m_bAscending(_bAscending)
257 ,m_sTableName( lcl_getColumnTableName( _xColumn ) )
259 construct();
262 // -------------------------------------------------------------------------
263 OOrderColumn::~OOrderColumn()
267 // -------------------------------------------------------------------------
268 void OOrderColumn::construct()
270 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING,
271 PropertyAttribute::READONLY, const_cast< sal_Bool* >( &m_bAscending ), ::getCppuType( reinterpret_cast< sal_Bool* >( NULL ) ) );
272 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME), PROPERTY_ID_TABLENAME,
273 PropertyAttribute::READONLY, const_cast< ::rtl::OUString* >( &m_sTableName ), ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
275 // -----------------------------------------------------------------------------
276 ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
278 return doCreateArrayHelper();
280 // -----------------------------------------------------------------------------
281 ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
283 OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
284 return *OOrderColumn_PROP::getArrayHelper();
286 // -----------------------------------------------------------------------------
287 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
289 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
290 aSupported[0] = ::rtl::OUString("com.sun.star.sdb.OrderColumn");
292 return aSupported;
294 // -----------------------------------------------------------------------------
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */