1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 using namespace ::comphelper
;
32 using namespace connectivity
;
33 using namespace dbtools
;
34 using namespace connectivity::parse
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::sdbc
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::container
;
41 OParseColumn::OParseColumn(const Reference
<XPropertySet
>& _xColumn
, bool _bCase
)
42 : connectivity::sdbcx::OColumn( getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
)))
43 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
)))
44 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
)))
45 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
)))
46 , getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
)))
47 , getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
)))
48 , getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
)))
49 , getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
)))
50 , getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
)))
52 , getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY
)))
54 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
)))
55 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
)))
56 , getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME
)))
59 , m_bDbasePrecisionChanged(false)
60 , m_bAggregateFunction(false)
61 , m_bIsSearchable( true )
67 OParseColumn::OParseColumn( const OUString
& Name
,
68 const OUString
& TypeName
,
69 const OUString
& DefaultValue
,
70 const OUString
& Description
,
78 const OUString
& CatalogName
,
79 const OUString
& SchemaName
,
80 const OUString
& TableName
81 ) : connectivity::sdbcx::OColumn(Name
,
97 , m_bDbasePrecisionChanged(false)
98 , m_bAggregateFunction(false)
99 , m_bIsSearchable( true )
105 ::rtl::Reference
< OSQLColumns
> OParseColumn::createColumnsForResultSet( const Reference
< XResultSetMetaData
>& _rxResMetaData
,
106 const Reference
< XDatabaseMetaData
>& _rxDBMetaData
,const Reference
< XNameAccess
>& i_xQueryColumns
)
108 sal_Int32 nColumnCount
= _rxResMetaData
->getColumnCount();
109 ::rtl::Reference
aReturn( new OSQLColumns
); aReturn
->get().reserve( nColumnCount
);
111 StringMap aColumnMap
;
112 for ( sal_Int32 i
= 1; i
<= nColumnCount
; ++i
)
114 OParseColumn
* pColumn
= createColumnForResultSet( _rxResMetaData
, _rxDBMetaData
, i
,aColumnMap
);
115 aReturn
->get().push_back( pColumn
);
116 if ( i_xQueryColumns
.is() && i_xQueryColumns
->hasByName(pColumn
->getRealName()) )
118 Reference
<XPropertySet
> xColumn(i_xQueryColumns
->getByName(pColumn
->getRealName()),UNO_QUERY_THROW
);
120 xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL
)) >>= sLabel
;
121 if ( !sLabel
.isEmpty() )
122 pColumn
->setLabel(sLabel
);
130 OParseColumn
* OParseColumn::createColumnForResultSet( const Reference
< XResultSetMetaData
>& _rxResMetaData
,
131 const Reference
< XDatabaseMetaData
>& _rxDBMetaData
, sal_Int32 _nColumnPos
, StringMap
& _rColumns
)
133 OUString sLabel
= _rxResMetaData
->getColumnLabel( _nColumnPos
);
134 // retrieve the name of the column
135 // check for duplicate entries
136 if(_rColumns
.find(sLabel
) != _rColumns
.end())
138 OUString
sAlias(sLabel
);
139 sal_Int32 searchIndex
=1;
140 while(_rColumns
.find(sAlias
) != _rColumns
.end())
142 sAlias
= sLabel
+ OUString::number(searchIndex
++);
146 _rColumns
.emplace(sLabel
,0);
147 OParseColumn
* pColumn
= new OParseColumn(
149 _rxResMetaData
->getColumnTypeName( _nColumnPos
),
152 _rxResMetaData
->isNullable( _nColumnPos
),
153 _rxResMetaData
->getPrecision( _nColumnPos
),
154 _rxResMetaData
->getScale( _nColumnPos
),
155 _rxResMetaData
->getColumnType( _nColumnPos
),
156 _rxResMetaData
->isAutoIncrement( _nColumnPos
),
157 _rxResMetaData
->isCurrency( _nColumnPos
),
158 _rxDBMetaData
->supportsMixedCaseQuotedIdentifiers(),
159 _rxResMetaData
->getCatalogName( _nColumnPos
),
160 _rxResMetaData
->getSchemaName( _nColumnPos
),
161 _rxResMetaData
->getTableName( _nColumnPos
)
163 pColumn
->setIsSearchable( _rxResMetaData
->isSearchable( _nColumnPos
) );
164 pColumn
->setRealName(_rxResMetaData
->getColumnName( _nColumnPos
));
165 pColumn
->setLabel(sLabel
);
170 OParseColumn::~OParseColumn()
174 void OParseColumn::construct()
176 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION
), PROPERTY_ID_FUNCTION
, 0, &m_bFunction
, cppu::UnoType
<decltype(m_bFunction
)>::get());
177 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION
), PROPERTY_ID_AGGREGATEFUNCTION
, 0, &m_bAggregateFunction
, cppu::UnoType
<decltype(m_bAggregateFunction
)>::get());
178 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME
), PROPERTY_ID_REALNAME
, 0, &m_aRealName
, cppu::UnoType
<decltype(m_aRealName
)>::get());
179 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED
), PROPERTY_ID_DBASEPRECISIONCHANGED
, 0, &m_bDbasePrecisionChanged
, cppu::UnoType
<decltype(m_bDbasePrecisionChanged
)>::get());
180 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE
), PROPERTY_ID_ISSEARCHABLE
, 0, &m_bIsSearchable
, cppu::UnoType
<decltype(m_bIsSearchable
)>::get());
181 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL
), PROPERTY_ID_LABEL
, 0, &m_sLabel
, cppu::UnoType
<decltype(m_sLabel
)>::get());
184 ::cppu::IPropertyArrayHelper
* OParseColumn::createArrayHelper() const
186 return doCreateArrayHelper();
189 ::cppu::IPropertyArrayHelper
& SAL_CALL
OParseColumn::getInfoHelper()
191 OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
192 return *OParseColumn_PROP::getArrayHelper();
196 OOrderColumn::OOrderColumn( const Reference
<XPropertySet
>& _xColumn
, const OUString
& i_rOriginatingTableName
,
197 bool _bCase
, bool _bAscending
)
198 : connectivity::sdbcx::OColumn(
199 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
))),
200 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
))),
201 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
))),
202 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
))),
203 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
))),
204 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
))),
205 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
))),
206 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
))),
207 getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
))),
209 getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY
))),
211 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
))),
212 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
))),
213 i_rOriginatingTableName
215 ,m_bAscending(_bAscending
)
221 OOrderColumn::OOrderColumn( const Reference
<XPropertySet
>& _xColumn
, bool _bCase
, bool _bAscending
)
222 : connectivity::sdbcx::OColumn(
223 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
))),
224 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
))),
225 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
))),
226 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
))),
227 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
))),
228 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
))),
229 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
))),
230 getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
))),
231 getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
))),
233 getBOOL(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY
))),
235 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
))),
236 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
))),
237 getString(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME
)))
239 ,m_bAscending(_bAscending
)
245 OOrderColumn::~OOrderColumn()
250 void OOrderColumn::construct()
252 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING
), PROPERTY_ID_ISASCENDING
,
253 PropertyAttribute::READONLY
, const_cast< bool* >( &m_bAscending
), cppu::UnoType
<decltype(m_bAscending
)>::get() );
256 ::cppu::IPropertyArrayHelper
* OOrderColumn::createArrayHelper() const
258 return doCreateArrayHelper();
261 ::cppu::IPropertyArrayHelper
& SAL_CALL
OOrderColumn::getInfoHelper()
263 OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
264 return *OOrderColumn_PROP::getArrayHelper();
267 css::uno::Sequence
< OUString
> SAL_CALL
OOrderColumn::getSupportedServiceNames( )
269 css::uno::Sequence
< OUString
> aSupported
{ "com.sun.star.sdb.OrderColumn" };
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */