LibreOffice Module connectivity (master) 1
AColumn.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <string_view>
23
24#include <ado/AColumn.hxx>
25#include <ado/AConnection.hxx>
26#include <ado/Awrapado.hxx>
27#include <com/sun/star/sdbc/ColumnValue.hpp>
30#include <comphelper/types.hxx>
31#include <ado/ACatalog.hxx>
32
33using namespace ::comphelper;
34
35using namespace connectivity::ado;
36using namespace com::sun::star::uno;
37using namespace com::sun::star::lang;
38using namespace com::sun::star::beans;
39using namespace com::sun::star::sdbc;
40
41void WpADOColumn::Create()
42{
43 pInterface.CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, nullptr, CLSCTX_INPROC_SERVER);
44}
45
46OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn)
47 : connectivity::sdbcx::OColumn(_bCase)
48 ,m_pConnection(_pConnection)
49{
50 construct();
51 OSL_ENSURE(_pColumn,"Column can not be null!");
52 m_aColumn.set(_pColumn);
53 // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
55}
56
57OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection)
58 : connectivity::sdbcx::OColumn(_bCase)
59 ,m_pConnection(_pConnection)
60{
63 construct();
65 m_Type = DataType::OTHER;
66}
67
68
70{
71 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
72
75}
76
77void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
78{
79 if(m_aColumn.IsValid())
80 {
81 std::u16string_view sAdoPropertyName;
82
83 switch(nHandle)
84 {
86 m_aColumn.put_SortOrder(::cppu::any2bool(rValue) ? adSortAscending : adSortDescending);
87 break;
89 {
90 OUString aVal;
91 rValue >>= aVal;
93 }
94 break;
96 {
97 OUString aVal;
98 rValue >>= aVal;
99 m_aColumn.put_Name(aVal);
100 }
101 break;
102 case PROPERTY_ID_TYPE:
103 {
104 sal_Int32 nVal=0;
105 rValue >>= nVal;
107 }
108 break;
110 // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find();
111 break;
113 {
114 sal_Int32 nVal=0;
115 rValue >>= nVal;
117 }
118 break;
120 {
121 sal_Int32 nVal=0;
122 rValue >>= nVal;
123 if ( !m_IsCurrency )
124 m_aColumn.put_NumericScale(static_cast<sal_Int8>(nVal));
125 }
126 break;
128 {
129 sal_Int32 nVal=0;
130 rValue >>= nVal;
131 if ( nVal == ColumnValue::NULLABLE )
132 m_aColumn.put_Attributes( adColNullable );
133 }
134 break;
136 break;
137
140 m_aColumn.get_Properties(), std::u16string_view(u"Autoincrement"),
141 getBOOL(rValue));
142 break;
143
146 sAdoPropertyName = u"Description";
147 break;
148
150 sAdoPropertyName = u"Default";
151 break;
152 }
153
154 if (!sAdoPropertyName.empty())
155 OTools::putValue(m_aColumn.get_Properties(), sAdoPropertyName, getString(rValue));
156 }
158}
159
161{
162 if(m_aColumn.IsValid())
163 {
164 m_IsAscending = m_aColumn.get_SortOrder() == adSortAscending;
169 m_IsNullable = ((m_aColumn.get_Attributes() & adColNullable) == adColNullable) ? ColumnValue::NULLABLE : ColumnValue::NO_NULLS;
170
171 DataTypeEnum eType = m_aColumn.get_Type();
172 m_IsCurrency = (eType == adCurrency);
173 if ( m_IsCurrency && !m_Scale)
174 m_Scale = 4;
176
177 bool bForceTo = true;
178 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo();
180 if ( pTypeInfo )
181 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
182 else if ( eType == adVarBinary && ADOS::isJetEngine(m_pConnection->getEngineType()) )
183 {
185 OTypeInfoMap::const_iterator aFind = std::find_if(pTypeInfoMap->begin(), pTypeInfoMap->end(),
186 [&aCase] (const OTypeInfoMap::value_type& typeInfo) {
187 return aCase(typeInfo.second->getDBName(), u"VarBinary");
188 });
189
190 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary
191 {
192 eType = aFind->first;
193 pTypeInfo = aFind->second;
194 }
195
196 if ( !pTypeInfo )
197 {
198 pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),adBinary,OUString(),m_Precision,m_Scale,bForceTo);
199 eType = adBinary;
200 }
201
202 if ( pTypeInfo )
203 {
204 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
206 }
207 }
208
209
210 // fill some specific props
211 {
213
214 if ( aProps.IsValid() )
215 {
217 = OTools::getValue(aProps, std::u16string_view(u"Autoincrement")).getBool();
218
220 = OTools::getValue(aProps, std::u16string_view(u"Description")).getString();
221
223 = OTools::getValue(aProps, std::u16string_view(u"Default")).getString();
224 }
225 }
226 }
227}
228
230{
231 return m_aColumn;
232}
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
static bool isJetEngine(sal_Int32 _nEngineType)
Definition: adoimp.cxx:189
static const CLSID CLSID_ADOCOLUMN_25
Definition: adoimp.hxx:54
static DataTypeEnum MapJdbc2ADOType(sal_Int32 _nType, sal_Int32 _nJetEngine)
Definition: adoimp.cxx:131
static sal_Int32 MapADOType2Jdbc(DataTypeEnum eType)
Definition: adoimp.cxx:78
OAdoColumn(bool _bCase, OConnection *_pConnection, _ADOColumn *_pColumn)
Definition: AColumn.cxx:46
OConnection * m_pConnection
Definition: AColumn.hxx:32
WpADOColumn getColumnImpl() const
Definition: AColumn.cxx:229
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: AColumn.cxx:77
virtual void construct() override
Definition: AColumn.cxx:69
WpADOCatalog getCatalog() const
Definition: ACatalog.hxx:45
const OTypeInfoMap * getTypeInfo() const
sal_Int32 getEngineType() const
static const OExtendedTypeInfo * getTypeInfoFromType(const OTypeInfoMap &_rTypeInfo, DataTypeEnum _nType, const OUString &_sTypeName, sal_Int32 _nPrecision, sal_Int32 _nScale, bool &_brForceToType)
OCatalog * getAdoCatalog() const
static OLEVariant getValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition)
getValue returns a specific property value
Definition: Awrapado.cxx:2003
static void putValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition, const OLEVariant &_aValVar)
putValue set the property value at the ado column
Definition: Awrapado.cxx:1992
DataTypeEnum get_Type() const
Definition: Awrapado.cxx:1007
SortOrderEnum get_SortOrder() const
Definition: Awrapado.cxx:1056
void put_Name(std::u16string_view _rName)
Definition: Awrapado.cxx:994
void put_NumericScale(sal_Int8 _nScale)
Definition: Awrapado.cxx:1050
sal_uInt8 get_NumericScale() const
Definition: Awrapado.cxx:1042
OUString get_RelatedColumn() const
Definition: Awrapado.cxx:986
sal_Int32 get_Precision() const
Definition: Awrapado.cxx:1021
WpADOProperties get_Properties() const
Definition: Awrapado.cxx:1084
bool put_Attributes(const ColumnAttributesEnum &_eNum)
Definition: Awrapado.cxx:1078
void put_SortOrder(SortOrderEnum _nScale)
Definition: Awrapado.cxx:1064
void put_RelatedColumn(std::u16string_view _rName)
Definition: Awrapado.cxx:1000
void put_Type(const DataTypeEnum &_eNum)
Definition: Awrapado.cxx:1015
void put_Precision(sal_Int32 _nPre)
Definition: Awrapado.cxx:1029
void put_ParentCatalog(_ADOCatalog __RPC_FAR *ppvObject)
Definition: Awrapado.cxx:1978
ColumnAttributesEnum get_Attributes() const
Definition: Awrapado.cxx:1070
sal::systools::COMReference< _ADOColumn > pInterface
Definition: Aolewrap.hxx:44
float u
DocumentType eType
bool getBOOL(const Any &_rAny)
OUString getString(const Any &_rAny)
std::multimap< DataTypeEnum, OExtendedTypeInfo * > OTypeInfoMap
Definition: AConnection.hxx:43
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51
#define PROPERTY_ID_DESCRIPTION
Definition: propertyids.hxx:58
#define PROPERTY_ID_ISROWVERSION
Definition: propertyids.hxx:57
#define PROPERTY_ID_ISASCENDING
Definition: propertyids.hxx:68
#define PROPERTY_ID_ISNULLABLE
Definition: propertyids.hxx:55
#define PROPERTY_ID_RELATEDCOLUMN
Definition: propertyids.hxx:75
#define PROPERTY_ID_PRECISION
Definition: propertyids.hxx:53
#define PROPERTY_ID_ISAUTOINCREMENT
Definition: propertyids.hxx:56
#define PROPERTY_ID_TYPENAME
Definition: propertyids.hxx:52
#define PROPERTY_ID_DEFAULTVALUE
Definition: propertyids.hxx:59
#define PROPERTY_ID_IM001
Definition: propertyids.hxx:90
#define PROPERTY_ID_SCALE
Definition: propertyids.hxx:54
sal_Int32 nHandle
::connectivity::OTypeInfo aSimpleType
Definition: AConnection.hxx:35
signed char sal_Int8