/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "ado/AColumn.hxx" #include "ado/AConnection.hxx" #include "ado/Awrapado.hxx" #include #include #include #include #include #include "ado/ACatalog.hxx" #include using namespace ::comphelper; using namespace connectivity::ado; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; void WpADOColumn::Create() { _ADOColumn* pColumn = NULL; HRESULT hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, NULL, CLSCTX_INPROC_SERVER, ADOS::IID_ADOCOLUMN_25, (void**)&pColumn ); if( !FAILED( hr ) ) { operator=( pColumn ); pColumn->Release( ); } } OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn) : connectivity::sdbcx::OColumn(_bCase) ,m_pConnection(_pConnection) { construct(); OSL_ENSURE(_pColumn,"Column can not be null!"); m_aColumn = WpADOColumn(_pColumn); // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog()); fillPropertyValues(); } OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection) : connectivity::sdbcx::OColumn(_bCase) ,m_pConnection(_pConnection) { m_aColumn.Create(); m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog()); construct(); fillPropertyValues(); m_Type = DataType::OTHER; } Sequence< sal_Int8 > OAdoColumn::getUnoTunnelImplementationId() { static ::cppu::OImplementationId * pId = 0; if (! pId) { ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); if (! pId) { static ::cppu::OImplementationId aId; pId = &aId; } } return pId->getImplementationId(); } // com::sun::star::lang::XUnoTunnel sal_Int64 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) { return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ? reinterpret_cast< sal_Int64 >( this ) : OColumn_ADO::getSomething(rId); } void OAdoColumn::construct() { sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING, nAttrib,&m_IsAscending, cppu::UnoType::get()); registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RELATEDCOLUMN), PROPERTY_ID_RELATEDCOLUMN, nAttrib,&m_ReferencedColumn, ::cppu::UnoType::get()); } void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) { if(m_aColumn.IsValid()) { const sal_Char* pAdoPropertyName = NULL; switch(nHandle) { case PROPERTY_ID_ISASCENDING: m_aColumn.put_SortOrder(::cppu::any2bool(rValue) ? adSortAscending : adSortDescending); break; case PROPERTY_ID_RELATEDCOLUMN: { OUString aVal; rValue >>= aVal; m_aColumn.put_RelatedColumn(aVal); } break; case PROPERTY_ID_NAME: { OUString aVal; rValue >>= aVal; m_aColumn.put_Name(aVal); } break; case PROPERTY_ID_TYPE: { sal_Int32 nVal=0; rValue >>= nVal; m_aColumn.put_Type(ADOS::MapJdbc2ADOType(nVal,m_pConnection->getEngineType())); } break; case PROPERTY_ID_TYPENAME: // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find(); break; case PROPERTY_ID_PRECISION: { sal_Int32 nVal=0; rValue >>= nVal; m_aColumn.put_Precision(nVal); } break; case PROPERTY_ID_SCALE: { sal_Int32 nVal=0; rValue >>= nVal; if ( !m_IsCurrency ) m_aColumn.put_NumericScale((sal_Int8)nVal); } break; case PROPERTY_ID_ISNULLABLE: { sal_Int32 nVal=0; rValue >>= nVal; if ( nVal == ColumnValue::NULLABLE ) m_aColumn.put_Attributes( adColNullable ); } break; case PROPERTY_ID_ISROWVERSION: break; case PROPERTY_ID_ISAUTOINCREMENT: OTools::putValue( m_aColumn.get_Properties(), OUString( "Autoincrement" ), getBOOL( rValue ) ); break; case PROPERTY_ID_IM001: case PROPERTY_ID_DESCRIPTION: pAdoPropertyName = "Description"; break; case PROPERTY_ID_DEFAULTVALUE: pAdoPropertyName = "Default"; break; } if ( pAdoPropertyName ) OTools::putValue( m_aColumn.get_Properties(), OUString::createFromAscii( pAdoPropertyName ), getString( rValue ) ); } OColumn_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue); } void OAdoColumn::fillPropertyValues() { if(m_aColumn.IsValid()) { m_IsAscending = m_aColumn.get_SortOrder() == adSortAscending; m_ReferencedColumn = m_aColumn.get_RelatedColumn(); m_Name = m_aColumn.get_Name(); m_Precision = m_aColumn.get_Precision(); m_Scale = m_aColumn.get_NumericScale(); m_IsNullable = ((m_aColumn.get_Attributes() & adColNullable) == adColNullable) ? ColumnValue::NULLABLE : ColumnValue::NO_NULLS; DataTypeEnum eType = m_aColumn.get_Type(); m_IsCurrency = (eType == adCurrency); if ( m_IsCurrency && !m_Scale) m_Scale = 4; m_Type = ADOS::MapADOType2Jdbc(eType); sal_Bool bForceTo = sal_True; const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo(); const OExtendedTypeInfo* pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),eType,OUString(),m_Precision,m_Scale,bForceTo); if ( pTypeInfo ) m_TypeName = pTypeInfo->aSimpleType.aTypeName; else if ( eType == adVarBinary && ADOS::isJetEngine(m_pConnection->getEngineType()) ) { ::comphelper::UStringMixEqual aCase(sal_False); OTypeInfoMap::const_iterator aFind = ::std::find_if(pTypeInfoMap->begin(), pTypeInfoMap->end(), ::o3tl::compose1( ::std::bind2nd(aCase, OUString("VarBinary")), ::o3tl::compose1( ::std::mem_fun(&OExtendedTypeInfo::getDBName), ::o3tl::select2nd()) ) ); if ( aFind != pTypeInfoMap->end() ) // change column type if necessary { eType = aFind->first; pTypeInfo = aFind->second; } if ( !pTypeInfo ) { pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),adBinary,OUString(),m_Precision,m_Scale,bForceTo); eType = adBinary; } if ( pTypeInfo ) { m_TypeName = pTypeInfo->aSimpleType.aTypeName; m_Type = ADOS::MapADOType2Jdbc(eType); } } // fill some specific props { WpADOProperties aProps( m_aColumn.get_Properties() ); if ( aProps.IsValid() ) { m_IsAutoIncrement = static_cast( OTools::getValue( aProps, OUString("Autoincrement") ) ) == 1; m_Description = OTools::getValue( aProps, OUString("Description") ); m_DefaultValue = OTools::getValue( aProps, OUString("Default") ); #if OSL_DEBUG_LEVEL > 0 sal_Int32 nCount = aProps.GetItemCount(); for (sal_Int32 i = 0; i