1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "ado/AColumns.hxx" 31 #include "ado/AColumn.hxx" 32 #include "ado/AConnection.hxx" 33 #include "ado/Awrapado.hxx" 34 #include <com/sun/star/sdbc/XRow.hpp> 35 #include <com/sun/star/sdbc/XResultSet.hpp> 36 #include <com/sun/star/sdbc/DataType.hpp> 37 #include <com/sun/star/sdbc/ColumnValue.hpp> 38 #include <comphelper/property.hxx> 39 #include <comphelper/types.hxx> 40 #include <connectivity/dbexception.hxx> 41 #ifdef __MINGW32__ 42 #include <algorithm> 43 #endif 44 #include "resource/ado_res.hrc" 45 46 using namespace connectivity::ado; 47 using namespace connectivity; 48 using namespace comphelper; 49 using namespace com::sun::star::uno; 50 using namespace com::sun::star::lang; 51 using namespace com::sun::star::beans; 52 using namespace com::sun::star::sdbc; 53 using namespace com::sun::star::container; 54 55 sdbcx::ObjectType OColumns::createObject(const ::rtl::OUString& _rName) 56 { 57 return new OAdoColumn(isCaseSensitive(),m_pConnection,m_aCollection.GetItem(_rName)); 58 } 59 60 // ------------------------------------------------------------------------- 61 void OColumns::impl_refresh() throw(RuntimeException) 62 { 63 m_aCollection.Refresh(); 64 } 65 // ------------------------------------------------------------------------- 66 Reference< XPropertySet > OColumns::createDescriptor() 67 { 68 return new OAdoColumn(isCaseSensitive(),m_pConnection); 69 } 70 // ------------------------------------------------------------------------- 71 // XAppend 72 sdbcx::ObjectType OColumns::appendObject( const ::rtl::OUString&, const Reference< XPropertySet >& descriptor ) 73 { 74 OAdoColumn* pColumn = NULL; 75 Reference< XPropertySet > xColumn; 76 if ( !getImplementation( pColumn, descriptor ) || pColumn == NULL ) 77 { 78 // m_pConnection->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); 79 pColumn = new OAdoColumn(isCaseSensitive(),m_pConnection); 80 xColumn = pColumn; 81 ::comphelper::copyProperties(descriptor,xColumn); 82 } 83 84 WpADOColumn aColumn = pColumn->getColumnImpl(); 85 86 #if OSL_DEBUG_LEVEL > 0 87 sal_Int32 nPrecision; 88 sal_Int32 nScale; 89 sal_Int32 nType; 90 nPrecision = aColumn.get_Precision(); 91 nScale = aColumn.get_NumericScale(); 92 nType = ADOS::MapADOType2Jdbc(aColumn.get_Type()); 93 #endif 94 95 ::rtl::OUString sTypeName; 96 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName; 97 98 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo(); 99 ::comphelper::TStringMixEqualFunctor aCase(sal_False); 100 // search for typeinfo where the typename is equal sTypeName 101 OTypeInfoMap::const_iterator aFind = ::std::find_if(pTypeInfoMap->begin(), 102 pTypeInfoMap->end(), 103 ::std::compose1( 104 ::std::bind2nd(aCase, sTypeName), 105 ::std::compose1( 106 ::std::mem_fun(&OExtendedTypeInfo::getDBName), 107 ::std::select2nd<OTypeInfoMap::value_type>()) 108 ) 109 110 ); 111 112 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary 113 aColumn.put_Type(aFind->first); 114 115 if ( SUCCEEDED(((ADOColumns*)m_aCollection)->Append(OLEVariant(aColumn.get_Name()),aColumn.get_Type(),aColumn.get_DefinedSize())) ) 116 { 117 WpADOColumn aAddedColumn = m_aCollection.GetItem(OLEVariant(aColumn.get_Name())); 118 if ( aAddedColumn.IsValid() ) 119 { 120 sal_Bool bAutoIncrement = sal_False; 121 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement; 122 if ( bAutoIncrement ) 123 OTools::putValue( aAddedColumn.get_Properties(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Autoincrement")), bAutoIncrement ); 124 125 if ( aFind != pTypeInfoMap->end() && aColumn.get_Type() != aAddedColumn.get_Type() ) // change column type if necessary 126 aColumn.put_Type(aFind->first); 127 aAddedColumn.put_Precision(aColumn.get_Precision()); 128 aAddedColumn.put_NumericScale(aColumn.get_NumericScale()); 129 aAddedColumn.put_Attributes(aColumn.get_Attributes()); 130 aAddedColumn.put_SortOrder(aColumn.get_SortOrder()); 131 aAddedColumn.put_RelatedColumn(aColumn.get_RelatedColumn()); 132 } 133 } 134 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); 135 136 return new OAdoColumn(isCaseSensitive(),m_pConnection,pColumn->getColumnImpl()); 137 } 138 // ------------------------------------------------------------------------- 139 // XDrop 140 void OColumns::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName) 141 { 142 if(!m_aCollection.Delete(_sElementName)) 143 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); 144 } 145 // ----------------------------------------------------------------------------- 146 147 148 149