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/AColumn.hxx" 27 #include "ado/AConnection.hxx" 28 #include "ado/Awrapado.hxx" 29 #include <cppuhelper/typeprovider.hxx> 30 #include <comphelper/sequence.hxx> 31 #include <com/sun/star/sdbc/ColumnValue.hpp> 32 #include <comphelper/extract.hxx> 33 #include <comphelper/types.hxx> 34 #include "ado/ACatalog.hxx" 35 36 using namespace ::comphelper; 37 38 using namespace connectivity::ado; 39 using namespace com::sun::star::uno; 40 using namespace com::sun::star::lang; 41 using namespace com::sun::star::beans; 42 using namespace com::sun::star::sdbc; 43 44 void WpADOColumn::Create() 45 { 46 HRESULT hr = -1; 47 48 _ADOColumn* pColumn = NULL; 49 hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25, 50 NULL, 51 CLSCTX_INPROC_SERVER, 52 ADOS::IID_ADOCOLUMN_25, 53 (void**)&pColumn ); 54 55 56 if( !FAILED( hr ) ) 57 { 58 operator=( pColumn ); 59 pColumn->Release( ); 60 } 61 } 62 // ------------------------------------------------------------------------- 63 OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn) 64 : connectivity::sdbcx::OColumn(::rtl::OUString(),::rtl::OUString(),::rtl::OUString(),::rtl::OUString(),0,0,0,0,sal_False,sal_False,sal_False,_bCase) 65 ,m_pConnection(_pConnection) 66 { 67 construct(); 68 OSL_ENSURE(_pColumn,"Column can not be null!"); 69 m_aColumn = WpADOColumn(_pColumn); 70 // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog()); 71 fillPropertyValues(); 72 } 73 // ------------------------------------------------------------------------- 74 OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection) 75 : connectivity::sdbcx::OColumn(_bCase) 76 ,m_pConnection(_pConnection) 77 { 78 m_aColumn.Create(); 79 m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog()); 80 construct(); 81 fillPropertyValues(); 82 m_Type = DataType::OTHER; 83 } 84 85 //-------------------------------------------------------------------------- 86 Sequence< sal_Int8 > OAdoColumn::getUnoTunnelImplementationId() 87 { 88 static ::cppu::OImplementationId * pId = 0; 89 if (! pId) 90 { 91 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 92 if (! pId) 93 { 94 static ::cppu::OImplementationId aId; 95 pId = &aId; 96 } 97 } 98 return pId->getImplementationId(); 99 } 100 101 // com::sun::star::lang::XUnoTunnel 102 //------------------------------------------------------------------ 103 sal_Int64 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) 104 { 105 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) 106 ? reinterpret_cast< sal_Int64 >( this ) 107 : OColumn_ADO::getSomething(rId); 108 } 109 // ------------------------------------------------------------------------- 110 void OAdoColumn::construct() 111 { 112 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; 113 114 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING, nAttrib,&m_IsAscending, ::getBooleanCppuType()); 115 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RELATEDCOLUMN), PROPERTY_ID_RELATEDCOLUMN, nAttrib,&m_ReferencedColumn, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); 116 } 117 // ----------------------------------------------------------------------------- 118 void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception) 119 { 120 if(m_aColumn.IsValid()) 121 { 122 const sal_Char* pAdoPropertyName = NULL; 123 124 switch(nHandle) 125 { 126 case PROPERTY_ID_ISASCENDING: 127 m_aColumn.put_SortOrder(::cppu::any2bool(rValue) ? adSortAscending : adSortDescending); 128 break; 129 case PROPERTY_ID_RELATEDCOLUMN: 130 { 131 ::rtl::OUString aVal; 132 rValue >>= aVal; 133 m_aColumn.put_RelatedColumn(aVal); 134 } 135 break; 136 case PROPERTY_ID_NAME: 137 { 138 ::rtl::OUString aVal; 139 rValue >>= aVal; 140 m_aColumn.put_Name(aVal); 141 } 142 break; 143 case PROPERTY_ID_TYPE: 144 { 145 sal_Int32 nVal=0; 146 rValue >>= nVal; 147 m_aColumn.put_Type(ADOS::MapJdbc2ADOType(nVal,m_pConnection->getEngineType())); 148 } 149 break; 150 case PROPERTY_ID_TYPENAME: 151 // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find(); 152 break; 153 case PROPERTY_ID_PRECISION: 154 { 155 sal_Int32 nVal=0; 156 rValue >>= nVal; 157 m_aColumn.put_Precision(nVal); 158 } 159 break; 160 case PROPERTY_ID_SCALE: 161 { 162 sal_Int32 nVal=0; 163 rValue >>= nVal; 164 if ( !m_IsCurrency ) 165 m_aColumn.put_NumericScale((sal_Int8)nVal); 166 } 167 break; 168 case PROPERTY_ID_ISNULLABLE: 169 { 170 sal_Int32 nVal=0; 171 rValue >>= nVal; 172 if ( nVal == ColumnValue::NULLABLE ) 173 m_aColumn.put_Attributes( adColNullable ); 174 } 175 break; 176 case PROPERTY_ID_ISROWVERSION: 177 break; 178 179 case PROPERTY_ID_ISAUTOINCREMENT: 180 OTools::putValue( m_aColumn.get_Properties(), ::rtl::OUString::createFromAscii( "Autoincrement" ), getBOOL( rValue ) ); 181 break; 182 183 case PROPERTY_ID_IM001: 184 case PROPERTY_ID_DESCRIPTION: 185 pAdoPropertyName = "Description"; 186 break; 187 188 case PROPERTY_ID_DEFAULTVALUE: 189 pAdoPropertyName = "Default"; 190 break; 191 } 192 193 if ( pAdoPropertyName ) 194 OTools::putValue( m_aColumn.get_Properties(), ::rtl::OUString::createFromAscii( pAdoPropertyName ), getString( rValue ) ); 195 } 196 OColumn_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue); 197 } 198 // ----------------------------------------------------------------------------- 199 void OAdoColumn::fillPropertyValues() 200 { 201 if(m_aColumn.IsValid()) 202 { 203 m_IsAscending = m_aColumn.get_SortOrder() == adSortAscending; 204 m_ReferencedColumn = m_aColumn.get_RelatedColumn(); 205 m_Name = m_aColumn.get_Name(); 206 m_Precision = m_aColumn.get_Precision(); 207 m_Scale = m_aColumn.get_NumericScale(); 208 m_IsNullable = ((m_aColumn.get_Attributes() & adColNullable) == adColNullable) ? ColumnValue::NULLABLE : ColumnValue::NO_NULLS; 209 210 DataTypeEnum eType = m_aColumn.get_Type(); 211 m_IsCurrency = (eType == adCurrency); 212 if ( m_IsCurrency && !m_Scale) 213 m_Scale = 4; 214 m_Type = ADOS::MapADOType2Jdbc(eType); 215 216 sal_Bool bForceTo = sal_True; 217 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo(); 218 const OExtendedTypeInfo* pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),eType,::rtl::OUString(),m_Precision,m_Scale,bForceTo); 219 if ( pTypeInfo ) 220 m_TypeName = pTypeInfo->aSimpleType.aTypeName; 221 else if ( eType == adVarBinary && ADOS::isJetEngine(m_pConnection->getEngineType()) ) 222 { 223 ::comphelper::TStringMixEqualFunctor aCase(sal_False); 224 OTypeInfoMap::const_iterator aFind = ::std::find_if(pTypeInfoMap->begin(), 225 pTypeInfoMap->end(), 226 ::std::compose1( 227 ::std::bind2nd(aCase, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VarBinary"))), 228 ::std::compose1( 229 ::std::mem_fun(&OExtendedTypeInfo::getDBName), 230 ::std::select2nd<OTypeInfoMap::value_type>()) 231 ) 232 233 ); 234 235 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary 236 { 237 eType = aFind->first; 238 pTypeInfo = aFind->second; 239 } 240 241 if ( !pTypeInfo ) 242 { 243 pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),adBinary,::rtl::OUString(),m_Precision,m_Scale,bForceTo); 244 eType = adBinary; 245 } 246 247 if ( pTypeInfo ) 248 { 249 m_TypeName = pTypeInfo->aSimpleType.aTypeName; 250 m_Type = ADOS::MapADOType2Jdbc(eType); 251 } 252 } 253 254 255 // fill some specific props 256 { 257 WpADOProperties aProps( m_aColumn.get_Properties() ); 258 259 if ( aProps.IsValid() ) 260 { 261 m_IsAutoIncrement = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Autoincrement")) ); 262 263 m_Description = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description")) ); 264 265 m_DefaultValue = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Default")) ); 266 267 #if OSL_DEBUG_LEVEL > 0 268 sal_Int32 nCount = aProps.GetItemCount(); 269 for (sal_Int32 i = 0; i<nCount; ++i) 270 { 271 WpADOProperty aProp = aProps.GetItem(i); 272 ::rtl::OUString sName = aProp.GetName(); 273 ::rtl::OUString sVal = aProp.GetValue(); 274 } 275 #endif 276 } 277 } 278 } 279 } 280 // ----------------------------------------------------------------------------- 281 WpADOColumn OAdoColumn::getColumnImpl() const 282 { 283 return m_aColumn; 284 } 285 // ----------------------------------------------------------------------------- 286 // ----------------------------------------------------------------------------- 287 void SAL_CALL OAdoColumn::acquire() throw() 288 { 289 OColumn_ADO::acquire(); 290 } 291 // ----------------------------------------------------------------------------- 292 void SAL_CALL OAdoColumn::release() throw() 293 { 294 OColumn_ADO::release(); 295 } 296 // ----------------------------------------------------------------------------- 297 298 299 300