1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "ado/AColumns.hxx" 27 #include "ado/AColumn.hxx" 28 #include "ado/AConnection.hxx" 29 #include "ado/Awrapado.hxx" 30 #include <com/sun/star/sdbc/XRow.hpp> 31 #include <com/sun/star/sdbc/XResultSet.hpp> 32 #include <com/sun/star/sdbc/DataType.hpp> 33 #include <com/sun/star/sdbc/ColumnValue.hpp> 34 #include <comphelper/property.hxx> 35 #include <comphelper/types.hxx> 36 #include <connectivity/dbexception.hxx> 37 #include <algorithm> 38 #include "resource/ado_res.hrc" 39 40 using namespace connectivity::ado; 41 using namespace connectivity; 42 using namespace comphelper; 43 using namespace com::sun::star::uno; 44 using namespace com::sun::star::lang; 45 using namespace com::sun::star::beans; 46 using namespace com::sun::star::sdbc; 47 using namespace com::sun::star::container; 48 49 sdbcx::ObjectType OColumns::createObject(const ::rtl::OUString& _rName) 50 { 51 return new OAdoColumn(isCaseSensitive(),m_pConnection,m_aCollection.GetItem(_rName)); 52 } 53 54 // ------------------------------------------------------------------------- 55 void OColumns::impl_refresh() throw(RuntimeException) 56 { 57 m_aCollection.Refresh(); 58 } 59 // ------------------------------------------------------------------------- 60 Reference< XPropertySet > OColumns::createDescriptor() 61 { 62 return new OAdoColumn(isCaseSensitive(),m_pConnection); 63 } 64 // ------------------------------------------------------------------------- 65 // XAppend 66 sdbcx::ObjectType OColumns::appendObject( const ::rtl::OUString&, const Reference< XPropertySet >& descriptor ) 67 { 68 OAdoColumn* pColumn = NULL; 69 Reference< XPropertySet > xColumn; 70 if ( !getImplementation( pColumn, descriptor ) || pColumn == NULL ) 71 { 72 // m_pConnection->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) ); 73 pColumn = new OAdoColumn(isCaseSensitive(),m_pConnection); 74 xColumn = pColumn; 75 ::comphelper::copyProperties(descriptor,xColumn); 76 } 77 78 WpADOColumn aColumn = pColumn->getColumnImpl(); 79 80 #if OSL_DEBUG_LEVEL > 0 81 sal_Int32 nPrecision; 82 sal_Int32 nScale; 83 sal_Int32 nType; 84 nPrecision = aColumn.get_Precision(); 85 nScale = aColumn.get_NumericScale(); 86 nType = ADOS::MapADOType2Jdbc(aColumn.get_Type()); 87 #endif 88 89 ::rtl::OUString sTypeName; 90 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName; 91 92 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo(); 93 ::comphelper::TStringMixEqualFunctor aCase(sal_False); 94 // search for typeinfo where the typename is equal sTypeName 95 OTypeInfoMap::const_iterator aFind = ::std::find_if(pTypeInfoMap->begin(), 96 pTypeInfoMap->end(), 97 ::std::compose1( 98 ::std::bind2nd(aCase, sTypeName), 99 ::std::compose1( 100 ::std::mem_fun(&OExtendedTypeInfo::getDBName), 101 ::std::select2nd<OTypeInfoMap::value_type>()) 102 ) 103 104 ); 105 106 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary 107 aColumn.put_Type(aFind->first); 108 109 if ( SUCCEEDED(((ADOColumns*)m_aCollection)->Append(OLEVariant(aColumn.get_Name()),aColumn.get_Type(),aColumn.get_DefinedSize())) ) 110 { 111 WpADOColumn aAddedColumn = m_aCollection.GetItem(OLEVariant(aColumn.get_Name())); 112 if ( aAddedColumn.IsValid() ) 113 { 114 sal_Bool bAutoIncrement = sal_False; 115 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement; 116 if ( bAutoIncrement ) 117 OTools::putValue( aAddedColumn.get_Properties(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Autoincrement")), bAutoIncrement ); 118 119 if ( aFind != pTypeInfoMap->end() && aColumn.get_Type() != aAddedColumn.get_Type() ) // change column type if necessary 120 aColumn.put_Type(aFind->first); 121 aAddedColumn.put_Precision(aColumn.get_Precision()); 122 aAddedColumn.put_NumericScale(aColumn.get_NumericScale()); 123 aAddedColumn.put_Attributes(aColumn.get_Attributes()); 124 aAddedColumn.put_SortOrder(aColumn.get_SortOrder()); 125 aAddedColumn.put_RelatedColumn(aColumn.get_RelatedColumn()); 126 } 127 } 128 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); 129 130 return new OAdoColumn(isCaseSensitive(),m_pConnection,pColumn->getColumnImpl()); 131 } 132 // ------------------------------------------------------------------------- 133 // XDrop 134 void OColumns::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName) 135 { 136 if(!m_aCollection.Delete(_sElementName)) 137 ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this)); 138 } 139 // ----------------------------------------------------------------------------- 140 141 142 143