1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AColumns.cxx,v $
10 * $Revision: 1.22.56.1 $
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/AColumns.hxx"
34 #include "ado/AColumn.hxx"
35 #include "ado/AConnection.hxx"
36 #include "ado/Awrapado.hxx"
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <com/sun/star/sdbc/DataType.hpp>
40 #include <com/sun/star/sdbc/ColumnValue.hpp>
41 #include <comphelper/property.hxx>
42 #include <comphelper/types.hxx>
43 #include <connectivity/dbexception.hxx>
47 #include "resource/ado_res.hrc"
49 using namespace connectivity::ado
;
50 using namespace connectivity
;
51 using namespace comphelper
;
52 using namespace com::sun::star::uno
;
53 using namespace com::sun::star::lang
;
54 using namespace com::sun::star::beans
;
55 using namespace com::sun::star::sdbc
;
56 using namespace com::sun::star::container
;
58 sdbcx::ObjectType
OColumns::createObject(const ::rtl::OUString
& _rName
)
60 return new OAdoColumn(isCaseSensitive(),m_pConnection
,m_aCollection
.GetItem(_rName
));
63 // -------------------------------------------------------------------------
64 void OColumns::impl_refresh() throw(RuntimeException
)
66 m_aCollection
.Refresh();
68 // -------------------------------------------------------------------------
69 Reference
< XPropertySet
> OColumns::createDescriptor()
71 return new OAdoColumn(isCaseSensitive(),m_pConnection
);
73 // -------------------------------------------------------------------------
75 sdbcx::ObjectType
OColumns::appendObject( const ::rtl::OUString
&, const Reference
< XPropertySet
>& descriptor
)
77 OAdoColumn
* pColumn
= NULL
;
78 if ( !getImplementation( pColumn
, descriptor
) || pColumn
== NULL
)
79 m_pConnection
->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR
,static_cast<XTypeProvider
*>(this) );
81 WpADOColumn aColumn
= pColumn
->getColumnImpl();
83 #if OSL_DEBUG_LEVEL > 0
87 nPrecision
= aColumn
.get_Precision();
88 nScale
= aColumn
.get_NumericScale();
89 nType
= ADOS::MapADOType2Jdbc(aColumn
.get_Type());
92 ::rtl::OUString sTypeName
;
93 pColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
)) >>= sTypeName
;
95 const OTypeInfoMap
* pTypeInfoMap
= m_pConnection
->getTypeInfo();
96 ::comphelper::TStringMixEqualFunctor
aCase(sal_False
);
97 // search for typeinfo where the typename is equal sTypeName
98 OTypeInfoMap::const_iterator aFind
= ::std::find_if(pTypeInfoMap
->begin(),
101 ::std::bind2nd(aCase
, sTypeName
),
103 ::std::mem_fun(&OExtendedTypeInfo::getDBName
),
104 ::std::select2nd
<OTypeInfoMap::value_type
>())
109 if ( aFind
!= pTypeInfoMap
->end() ) // change column type if necessary
110 aColumn
.put_Type(aFind
->first
);
112 if ( SUCCEEDED(((ADOColumns
*)m_aCollection
)->Append(OLEVariant(aColumn
.get_Name()),aColumn
.get_Type(),aColumn
.get_DefinedSize())) )
114 WpADOColumn aAddedColumn
= m_aCollection
.GetItem(OLEVariant(aColumn
.get_Name()));
115 if ( aAddedColumn
.IsValid() )
117 sal_Bool bAutoIncrement
= sal_False
;
118 pColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
)) >>= bAutoIncrement
;
119 if ( bAutoIncrement
)
120 OTools::putValue( aAddedColumn
.get_Properties(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Autoincrement")), bAutoIncrement
);
122 if ( aFind
!= pTypeInfoMap
->end() && aColumn
.get_Type() != aAddedColumn
.get_Type() ) // change column type if necessary
123 aColumn
.put_Type(aFind
->first
);
124 aAddedColumn
.put_Precision(aColumn
.get_Precision());
125 aAddedColumn
.put_NumericScale(aColumn
.get_NumericScale());
126 aAddedColumn
.put_Attributes(aColumn
.get_Attributes());
127 aAddedColumn
.put_SortOrder(aColumn
.get_SortOrder());
128 aAddedColumn
.put_RelatedColumn(aColumn
.get_RelatedColumn());
131 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
133 return new OAdoColumn(isCaseSensitive(),m_pConnection
,pColumn
->getColumnImpl());
135 // -------------------------------------------------------------------------
137 void OColumns::dropObject(sal_Int32
/*_nPos*/,const ::rtl::OUString _sElementName
)
139 if(!m_aCollection
.Delete(_sElementName
))
140 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
142 // -----------------------------------------------------------------------------