merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / parse / PColumn.cxx
blob34b3f3a58210352da745e8b8a2522467ba6fdbbc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PColumn.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #ifndef _CONNECTIVITY_SDBCX_COLUMN_HXX_
35 #include "connectivity/PColumn.hxx"
36 #endif
37 #include "connectivity/dbtools.hxx"
38 #include "TConnection.hxx"
39 #include <comphelper/types.hxx>
41 using namespace ::comphelper;
42 using namespace connectivity;
43 using namespace dbtools;
44 using namespace connectivity::parse;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::beans;
49 // -------------------------------------------------------------------------
50 OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn,sal_Bool _bCase)
51 : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
52 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
53 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
54 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
55 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
56 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
57 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
58 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
59 , sal_False
60 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
61 , _bCase
63 , m_bFunction(sal_False)
64 , m_bDbasePrecisionChanged(sal_False)
65 , m_bAggregateFunction(sal_False)
66 , m_bIsSearchable( sal_True )
68 construct();
71 // -------------------------------------------------------------------------
72 OParseColumn::OParseColumn( const ::rtl::OUString& _Name,
73 const ::rtl::OUString& _TypeName,
74 const ::rtl::OUString& _DefaultValue,
75 sal_Int32 _IsNullable,
76 sal_Int32 _Precision,
77 sal_Int32 _Scale,
78 sal_Int32 _Type,
79 sal_Bool _IsAutoIncrement,
80 sal_Bool _IsCurrency,
81 sal_Bool _bCase
82 ) : connectivity::sdbcx::OColumn(_Name,
83 _TypeName,
84 _DefaultValue,
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 ::vos::ORef< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
103 const Reference< XDatabaseMetaData >& _rxDBMetaData )
105 sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
106 ::vos::ORef< OSQLColumns > aReturn( new OSQLColumns ); aReturn->get().reserve( nColumnCount );
108 for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
109 aReturn->get().push_back( createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i ) );
111 return aReturn;
114 // -------------------------------------------------------------------------
115 OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
116 const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos )
118 OParseColumn* pColumn = new OParseColumn(
119 _rxResMetaData->getColumnName( _nColumnPos ),
120 _rxResMetaData->getColumnTypeName( _nColumnPos ),
121 ::rtl::OUString(),
122 _rxResMetaData->isNullable( _nColumnPos ),
123 _rxResMetaData->getPrecision( _nColumnPos ),
124 _rxResMetaData->getScale( _nColumnPos ),
125 _rxResMetaData->getColumnType( _nColumnPos ),
126 _rxResMetaData->isAutoIncrement( _nColumnPos ),
127 _rxResMetaData->isCurrency( _nColumnPos ),
128 _rxDBMetaData->storesMixedCaseQuotedIdentifiers()
130 pColumn->setTableName( ::dbtools::composeTableName( _rxDBMetaData,
131 _rxResMetaData->getCatalogName( _nColumnPos ),
132 _rxResMetaData->getSchemaName( _nColumnPos ),
133 _rxResMetaData->getTableName( _nColumnPos ),
134 sal_False,
135 eComplete
136 ) );
137 pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
138 return pColumn;
141 // -------------------------------------------------------------------------
142 OParseColumn::~OParseColumn()
145 // -------------------------------------------------------------------------
146 void OParseColumn::construct()
148 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION), PROPERTY_ID_FUNCTION, 0, &m_bFunction, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
149 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION), PROPERTY_ID_AGGREGATEFUNCTION, 0, &m_bAggregateFunction, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
150 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME), PROPERTY_ID_TABLENAME, 0, &m_aTableName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
151 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
152 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(reinterpret_cast<sal_Bool*>(NULL)));
153 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
156 // -----------------------------------------------------------------------------
157 ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
159 return doCreateArrayHelper();
161 // -----------------------------------------------------------------------------
162 ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
164 OSL_ENSURE( !isNew(), "OParseColumn::OOrderColumn: a *new* OrderColumn?" );
165 return *OParseColumn_PROP::getArrayHelper();
167 // -----------------------------------------------------------------------------
168 OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn
169 ,sal_Bool _bCase
170 ,sal_Bool _bAscending)
171 : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
172 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
173 , getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
174 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
175 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
176 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
177 , getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
178 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
179 , sal_False
180 , getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
181 , _bCase
183 , m_bAscending(_bAscending)
185 construct();
187 // -------------------------------------------------------------------------
188 OOrderColumn::OOrderColumn( const ::rtl::OUString& _Name,
189 const ::rtl::OUString& _TypeName,
190 const ::rtl::OUString& _DefaultValue,
191 sal_Int32 _IsNullable,
192 sal_Int32 _Precision,
193 sal_Int32 _Scale,
194 sal_Int32 _Type,
195 sal_Bool _IsAutoIncrement,
196 sal_Bool _IsCurrency,
197 sal_Bool _bCase
198 ,sal_Bool _bAscending
199 ) : connectivity::sdbcx::OColumn(_Name,
200 _TypeName,
201 _DefaultValue,
202 _IsNullable,
203 _Precision,
204 _Scale,
205 _Type,
206 _IsAutoIncrement,
207 sal_False,
208 _IsCurrency,
209 _bCase)
210 , m_bAscending(_bAscending)
212 construct();
214 // -------------------------------------------------------------------------
215 OOrderColumn::~OOrderColumn()
218 // -------------------------------------------------------------------------
219 void OOrderColumn::construct()
221 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING),PROPERTY_ID_ISASCENDING,0,&m_bAscending, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
223 // -----------------------------------------------------------------------------
224 ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
226 return doCreateArrayHelper();
228 // -----------------------------------------------------------------------------
229 ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
231 OSL_ENSURE( !isNew(), "OOrderColumn::OOrderColumn: a *new* OrderColumn?" );
232 return *OOrderColumn_PROP::getArrayHelper();
234 // -----------------------------------------------------------------------------
235 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OOrderColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
237 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
238 if ( m_bOrder )
239 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.OrderColumn");
240 else
241 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.GroupColumn");
243 return aSupported;
245 // -----------------------------------------------------------------------------