update dev300-m58
[ooovba.git] / connectivity / source / drivers / ado / AColumn.cxx
blob9b25535c310fce18b9bba31a4d8de6c1746e575e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AColumn.cxx,v $
10 * $Revision: 1.27 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/AColumn.hxx"
34 #include "ado/AConnection.hxx"
35 #include "ado/Awrapado.hxx"
36 #include <cppuhelper/typeprovider.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <com/sun/star/sdbc/ColumnValue.hpp>
39 #include <comphelper/extract.hxx>
40 #include <comphelper/types.hxx>
41 #include "ado/ACatalog.hxx"
43 using namespace ::comphelper;
45 using namespace connectivity::ado;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::sdbc;
51 void WpADOColumn::Create()
53 HRESULT hr = -1;
55 _ADOColumn* pColumn = NULL;
56 hr = CoCreateInstance(ADOS::CLSID_ADOCOLUMN_25,
57 NULL,
58 CLSCTX_INPROC_SERVER,
59 ADOS::IID_ADOCOLUMN_25,
60 (void**)&pColumn );
63 if( !FAILED( hr ) )
65 operator=( pColumn );
66 pColumn->Release( );
69 // -------------------------------------------------------------------------
70 OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection,_ADOColumn* _pColumn)
71 : connectivity::sdbcx::OColumn(::rtl::OUString(),::rtl::OUString(),::rtl::OUString(),0,0,0,0,sal_False,sal_False,sal_False,_bCase)
72 ,m_pConnection(_pConnection)
74 construct();
75 OSL_ENSURE(_pColumn,"Column can not be null!");
76 m_aColumn = WpADOColumn(_pColumn);
77 // m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
78 fillPropertyValues();
80 // -------------------------------------------------------------------------
81 OAdoColumn::OAdoColumn(sal_Bool _bCase,OConnection* _pConnection)
82 : connectivity::sdbcx::OColumn(_bCase)
83 ,m_pConnection(_pConnection)
85 m_aColumn.Create();
86 m_aColumn.put_ParentCatalog(_pConnection->getAdoCatalog()->getCatalog());
87 construct();
88 fillPropertyValues();
89 m_Type = DataType::OTHER;
92 //--------------------------------------------------------------------------
93 Sequence< sal_Int8 > OAdoColumn::getUnoTunnelImplementationId()
95 static ::cppu::OImplementationId * pId = 0;
96 if (! pId)
98 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
99 if (! pId)
101 static ::cppu::OImplementationId aId;
102 pId = &aId;
105 return pId->getImplementationId();
108 // com::sun::star::lang::XUnoTunnel
109 //------------------------------------------------------------------
110 sal_Int64 OAdoColumn::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
112 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
113 ? reinterpret_cast< sal_Int64 >( this )
114 : OColumn_ADO::getSomething(rId);
116 // -------------------------------------------------------------------------
117 void OAdoColumn::construct()
119 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
121 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING, nAttrib,&m_IsAscending, ::getBooleanCppuType());
122 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RELATEDCOLUMN), PROPERTY_ID_RELATEDCOLUMN, nAttrib,&m_ReferencedColumn, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
124 // -----------------------------------------------------------------------------
125 void OAdoColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
127 if(m_aColumn.IsValid())
129 const sal_Char* pAdoPropertyName = NULL;
131 switch(nHandle)
133 case PROPERTY_ID_ISASCENDING:
134 m_aColumn.put_SortOrder(::cppu::any2bool(rValue) ? adSortAscending : adSortDescending);
135 break;
136 case PROPERTY_ID_RELATEDCOLUMN:
138 ::rtl::OUString aVal;
139 rValue >>= aVal;
140 m_aColumn.put_RelatedColumn(aVal);
142 break;
143 case PROPERTY_ID_NAME:
145 ::rtl::OUString aVal;
146 rValue >>= aVal;
147 m_aColumn.put_Name(aVal);
149 break;
150 case PROPERTY_ID_TYPE:
152 sal_Int32 nVal=0;
153 rValue >>= nVal;
154 m_aColumn.put_Type(ADOS::MapJdbc2ADOType(nVal,m_pConnection->getEngineType()));
156 break;
157 case PROPERTY_ID_TYPENAME:
158 // rValue <<= m_pTable->getCatalog()->getConnection()->getTypeInfo()->find();
159 break;
160 case PROPERTY_ID_PRECISION:
162 sal_Int32 nVal=0;
163 rValue >>= nVal;
164 m_aColumn.put_Precision(nVal);
166 break;
167 case PROPERTY_ID_SCALE:
169 sal_Int32 nVal=0;
170 rValue >>= nVal;
171 m_aColumn.put_NumericScale((sal_Int8)nVal);
173 break;
174 case PROPERTY_ID_ISNULLABLE:
176 sal_Int32 nVal=0;
177 rValue >>= nVal;
178 if ( nVal == ColumnValue::NULLABLE )
179 m_aColumn.put_Attributes( adColNullable );
181 break;
182 case PROPERTY_ID_ISROWVERSION:
183 break;
185 case PROPERTY_ID_ISAUTOINCREMENT:
186 OTools::putValue( m_aColumn.get_Properties(), ::rtl::OUString::createFromAscii( "Autoincrement" ), getBOOL( rValue ) );
187 break;
189 case PROPERTY_ID_DESCRIPTION:
190 pAdoPropertyName = "Default";
191 break;
193 case PROPERTY_ID_DEFAULTVALUE:
194 pAdoPropertyName = "Description";
195 break;
198 if ( pAdoPropertyName )
199 OTools::putValue( m_aColumn.get_Properties(), ::rtl::OUString::createFromAscii( pAdoPropertyName ), getString( rValue ) );
201 OColumn_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue);
203 // -----------------------------------------------------------------------------
204 void OAdoColumn::fillPropertyValues()
206 if(m_aColumn.IsValid())
208 m_IsAscending = m_aColumn.get_SortOrder() == adSortAscending;
209 m_ReferencedColumn = m_aColumn.get_RelatedColumn();
210 m_Name = m_aColumn.get_Name();
211 m_Precision = m_aColumn.get_Precision();
212 m_Scale = m_aColumn.get_NumericScale();
213 m_IsNullable = ((m_aColumn.get_Attributes() & adColNullable) == adColNullable) ? ColumnValue::NULLABLE : ColumnValue::NO_NULLS;
215 DataTypeEnum eType = m_aColumn.get_Type();
216 m_IsCurrency = (eType == adCurrency);
217 m_Type = ADOS::MapADOType2Jdbc(eType);
219 sal_Bool bForceTo = sal_True;
220 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo();
221 const OExtendedTypeInfo* pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),eType,::rtl::OUString(),m_Precision,m_Scale,bForceTo);
222 if ( pTypeInfo )
223 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
224 else if ( eType == adVarBinary && ADOS::isJetEngine(m_pConnection->getEngineType()) )
226 ::comphelper::TStringMixEqualFunctor aCase(sal_False);
227 OTypeInfoMap::const_iterator aFind = ::std::find_if(pTypeInfoMap->begin(),
228 pTypeInfoMap->end(),
229 ::std::compose1(
230 ::std::bind2nd(aCase, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VarBinary"))),
231 ::std::compose1(
232 ::std::mem_fun(&OExtendedTypeInfo::getDBName),
233 ::std::select2nd<OTypeInfoMap::value_type>())
238 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary
240 eType = aFind->first;
241 pTypeInfo = aFind->second;
244 if ( !pTypeInfo )
246 pTypeInfo = OConnection::getTypeInfoFromType(*m_pConnection->getTypeInfo(),adBinary,::rtl::OUString(),m_Precision,m_Scale,bForceTo);
247 eType = adBinary;
250 if ( pTypeInfo )
252 m_TypeName = pTypeInfo->aSimpleType.aTypeName;
253 m_Type = ADOS::MapADOType2Jdbc(eType);
258 // fill some specific props
260 WpADOProperties aProps( m_aColumn.get_Properties() );
262 if ( aProps.IsValid() )
264 m_IsAutoIncrement = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Autoincrement")) );
266 m_Description = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description")) );
268 m_DefaultValue = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Default")) );
270 #if OSL_DEBUG_LEVEL > 0
271 sal_Int32 nCount = aProps.GetItemCount();
272 for (sal_Int32 i = 0; i<nCount; ++i)
274 WpADOProperty aProp = aProps.GetItem(i);
275 ::rtl::OUString sName = aProp.GetName();
276 ::rtl::OUString sVal = aProp.GetValue();
278 #endif
283 // -----------------------------------------------------------------------------
284 WpADOColumn OAdoColumn::getColumnImpl() const
286 return m_aColumn;
288 // -----------------------------------------------------------------------------
289 // -----------------------------------------------------------------------------
290 void SAL_CALL OAdoColumn::acquire() throw()
292 OColumn_ADO::acquire();
294 // -----------------------------------------------------------------------------
295 void SAL_CALL OAdoColumn::release() throw()
297 OColumn_ADO::release();
299 // -----------------------------------------------------------------------------