bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AColumn.cxx
blob236d758760d14f3c5cb30b01aac40bfdd17380ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <ado/AColumn.hxx>
21 #include <ado/AConnection.hxx>
22 #include <ado/Awrapado.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <com/sun/star/sdbc/ColumnValue.hpp>
25 #include <comphelper/extract.hxx>
26 #include <comphelper/types.hxx>
27 #include <ado/ACatalog.hxx>
29 using namespace ::comphelper;
31 using namespace connectivity::ado;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::beans;
35 using namespace com::sun::star::sdbc;
37 void WpADOColumn::Create()
39 _ADOColumn* pColumn = nullptr;
40 HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25,
41 nullptr,
42 CLSCTX_INPROC_SERVER,
43 ADOS::IID_ADOCOLUMN_25,
44 reinterpret_cast<void**>(&pColumn) );
47 if( !FAILED( hr ) )
49 operator=( pColumn );
50 pColumn->Release( );
54 OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn)
55 : connectivity::sdbcx::OColumn(_bCase)
56 ,m_pConnection(_pConnection)
58 construct();
59 OSL_ENSURE(_pColumn,"Column can not be null!");
60 m_aColumn = WpADOColumn(_pColumn);
61 // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
62 fillPropertyValues();
65 OAdoColumn::OAdoColumn(bool _bCase,OConnection* _pConnection)
66 : connectivity::sdbcx::OColumn(_bCase)
67 ,m_pConnection(_pConnection)
69 m_aColumn.Create();
70 m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
71 construct();
72 fillPropertyValues();
73 m_Type = DataType::OTHER;
77 Sequence< sal_Int8 > OAdoColumn::getUnoTunnelImplementationId()
79 static ::cppu::OImplementationId implId;
81 return implId.getImplementationId();
84 // css::lang::XUnoTunnel
86 sal_Int64 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId )
88 return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
89 ? reinterpret_cast< sal_Int64 >( this )
90 : OColumn_ADO::getSomething(rId);
93 void OAdoColumn::construct()
95 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
97 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING, nAttrib,&m_IsAscending, cppu::UnoType<bool>::get());
98 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RELATEDCOLUMN), PROPERTY_ID_RELATEDCOLUMN, nAttrib,&m_ReferencedColumn, ::cppu::UnoType<OUString>::get());
101 void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
103 if(m_aColumn.IsValid())
105 const sal_Char* pAdoPropertyName = nullptr;
107 switch(nHandle)
109 case PROPERTY_ID_ISASCENDING:
110 m_aColumn.put_SortOrder(::cppu::any2bool(rValue) ? adSortAscending : adSortDescending);
111 break;
112 case PROPERTY_ID_RELATEDCOLUMN:
114 OUString aVal;
115 rValue >>= aVal;
116 m_aColumn.put_RelatedColumn(aVal);
118 break;
119 case PROPERTY_ID_NAME:
121 OUString aVal;
122 rValue >>= aVal;
123 m_aColumn.put_Name(aVal);
125 break;
126 case PROPERTY_ID_TYPE:
128 sal_Int32 nVal=0;
129 rValue >>= nVal;
130 m_aColumn.put_Type(ADOS::MapJdbc2ADOType(nVal,m_pConnection->getEngineType()));
132 break;
133 case PROPERTY_ID_TYPENAME:
134 // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find();
135 break;
136 case PROPERTY_ID_PRECISION:
138 sal_Int32 nVal=0;
139 rValue >>= nVal;
140 m_aColumn.put_Precision(nVal);
142 break;
143 case PROPERTY_ID_SCALE:
145 sal_Int32 nVal=0;
146 rValue >>= nVal;
147 if ( !m_IsCurrency )
148 m_aColumn.put_NumericScale(static_cast<sal_Int8>(nVal));
150 break;
151 case PROPERTY_ID_ISNULLABLE:
153 sal_Int32 nVal=0;
154 rValue >>= nVal;
155 if ( nVal == ColumnValue::NULLABLE )
156 m_aColumn.put_Attributes( adColNullable );
158 break;
159 case PROPERTY_ID_ISROWVERSION:
160 break;
162 case PROPERTY_ID_ISAUTOINCREMENT:
163 OTools::putValue( m_aColumn.get_Properties(), OUString( "Autoincrement" ), getBOOL( rValue ) );
164 break;
166 case PROPERTY_ID_IM001:
167 case PROPERTY_ID_DESCRIPTION:
168 pAdoPropertyName = "Description";
169 break;
171 case PROPERTY_ID_DEFAULTVALUE:
172 pAdoPropertyName = "Default";
173 break;
176 if ( pAdoPropertyName )
177 OTools::putValue( m_aColumn.get_Properties(), OUString::createFromAscii( pAdoPropertyName ), getString( rValue ) );
179 OColumn_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue);
182 void OAdoColumn::fillPropertyValues()
184 if(m_aColumn.IsValid())
186 m_IsAscending = m_aColumn.get_SortOrder() == adSortAscending;
187 m_ReferencedColumn = m_aColumn.get_RelatedColumn();
188 m_Name = m_aColumn.get_Name();
189 m_Precision = m_aColumn.get_Precision();
190 m_Scale = m_aColumn.get_NumericScale();
191 m_IsNullable = ((m_aColumn.get_Attributes() & adColNullable) == adColNullable) ? ColumnValue::NULLABLE : ColumnValue::NO_NULLS;
193 DataTypeEnum eType = m_aColumn.get_Type();
194 m_IsCurrency = (eType == adCurrency);
195 if ( m_IsCurrency && !m_Scale)
196 m_Scale = 4;
197 m_Type = ADOS::MapADOType2Jdbc(eType);
199 bool bForceTo = true;
200 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo();
201 const OExtendedTypeInfo* pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),eType,OUString(),m_Precision,m_Scale,bForceTo);
202 if ( pTypeInfo )
203 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
204 else if ( eType == adVarBinary && ADOS::isJetEngine(m_pConnection->getEngineType()) )
206 ::comphelper::UStringMixEqual aCase(false);
207 OTypeInfoMap::const_iterator aFind = std::find_if(pTypeInfoMap->begin(), pTypeInfoMap->end(),
208 [&aCase] (const OTypeInfoMap::value_type& typeInfo) {
209 return aCase(typeInfo.second->getDBName(), OUString("VarBinary"));
212 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary
214 eType = aFind->first;
215 pTypeInfo = aFind->second;
218 if ( !pTypeInfo )
220 pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),adBinary,OUString(),m_Precision,m_Scale,bForceTo);
221 eType = adBinary;
224 if ( pTypeInfo )
226 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
227 m_Type = ADOS::MapADOType2Jdbc(eType);
232 // fill some specific props
234 WpADOProperties aProps( m_aColumn.get_Properties() );
236 if ( aProps.IsValid() )
238 m_IsAutoIncrement = OTools::getValue( aProps, OUString("Autoincrement") ).getBool();
240 m_Description = OTools::getValue( aProps, OUString("Description") ).getString();
242 m_DefaultValue = OTools::getValue( aProps, OUString("Default") ).getString();
248 WpADOColumn OAdoColumn::getColumnImpl() const
250 return m_aColumn;
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */