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 .
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
,
43 ADOS::IID_ADOCOLUMN_25
,
44 reinterpret_cast<void**>(&pColumn
) );
54 OAdoColumn::OAdoColumn(bool _bCase
,OConnection
* _pConnection
,_ADOColumn
* _pColumn
)
55 : connectivity::sdbcx::OColumn(_bCase
)
56 ,m_pConnection(_pConnection
)
59 OSL_ENSURE(_pColumn
,"Column can not be null!");
60 m_aColumn
= WpADOColumn(_pColumn
);
61 // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
65 OAdoColumn::OAdoColumn(bool _bCase
,OConnection
* _pConnection
)
66 : connectivity::sdbcx::OColumn(_bCase
)
67 ,m_pConnection(_pConnection
)
70 m_aColumn
.put_ParentCatalog(_pConnection
->getAdoCatalog()->getCatalog());
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;
109 case PROPERTY_ID_ISASCENDING
:
110 m_aColumn
.put_SortOrder(::cppu::any2bool(rValue
) ? adSortAscending
: adSortDescending
);
112 case PROPERTY_ID_RELATEDCOLUMN
:
116 m_aColumn
.put_RelatedColumn(aVal
);
119 case PROPERTY_ID_NAME
:
123 m_aColumn
.put_Name(aVal
);
126 case PROPERTY_ID_TYPE
:
130 m_aColumn
.put_Type(ADOS::MapJdbc2ADOType(nVal
,m_pConnection
->getEngineType()));
133 case PROPERTY_ID_TYPENAME
:
134 // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find();
136 case PROPERTY_ID_PRECISION
:
140 m_aColumn
.put_Precision(nVal
);
143 case PROPERTY_ID_SCALE
:
148 m_aColumn
.put_NumericScale(static_cast<sal_Int8
>(nVal
));
151 case PROPERTY_ID_ISNULLABLE
:
155 if ( nVal
== ColumnValue::NULLABLE
)
156 m_aColumn
.put_Attributes( adColNullable
);
159 case PROPERTY_ID_ISROWVERSION
:
162 case PROPERTY_ID_ISAUTOINCREMENT
:
163 OTools::putValue( m_aColumn
.get_Properties(), OUString( "Autoincrement" ), getBOOL( rValue
) );
166 case PROPERTY_ID_IM001
:
167 case PROPERTY_ID_DESCRIPTION
:
168 pAdoPropertyName
= "Description";
171 case PROPERTY_ID_DEFAULTVALUE
:
172 pAdoPropertyName
= "Default";
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
)
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
);
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
;
220 pTypeInfo
= OConnection::getTypeInfoFromType(*m_pConnection
->getTypeInfo(),adBinary
,OUString(),m_Precision
,m_Scale
,bForceTo
);
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
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */