1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ado/AColumns.hxx>
21 #include <ado/AColumn.hxx>
22 #include <ado/AConnection.hxx>
23 #include <ado/Awrapado.hxx>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <com/sun/star/sdbc/DataType.hpp>
27 #include <com/sun/star/sdbc/ColumnValue.hpp>
28 #include <comphelper/property.hxx>
29 #include <comphelper/types.hxx>
30 #include <connectivity/dbexception.hxx>
32 #include <strings.hrc>
34 using namespace connectivity::ado
;
35 using namespace connectivity
;
36 using namespace comphelper
;
37 using namespace com::sun::star::uno
;
38 using namespace com::sun::star::lang
;
39 using namespace com::sun::star::beans
;
40 using namespace com::sun::star::sdbc
;
41 using namespace com::sun::star::container
;
43 sdbcx::ObjectType
OColumns::createObject(const OUString
& _rName
)
45 return new OAdoColumn(isCaseSensitive(),m_pConnection
,m_aCollection
.GetItem(_rName
));
49 void OColumns::impl_refresh()
51 m_aCollection
.Refresh();
54 Reference
< XPropertySet
> OColumns::createDescriptor()
56 return new OAdoColumn(isCaseSensitive(),m_pConnection
);
60 sdbcx::ObjectType
OColumns::appendObject( const OUString
&, const Reference
< XPropertySet
>& descriptor
)
62 OAdoColumn
* pColumn
= nullptr;
63 Reference
< XPropertySet
> xColumn
;
64 if ( !getImplementation( pColumn
, descriptor
) || pColumn
== nullptr )
66 // m_pConnection->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
67 pColumn
= new OAdoColumn(isCaseSensitive(),m_pConnection
);
69 ::comphelper::copyProperties(descriptor
,xColumn
);
72 WpADOColumn aColumn
= pColumn
->getColumnImpl();
74 #if OSL_DEBUG_LEVEL > 0
78 nPrecision
= aColumn
.get_Precision();
79 nScale
= aColumn
.get_NumericScale();
80 nType
= ADOS::MapADOType2Jdbc(aColumn
.get_Type());
84 pColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
)) >>= sTypeName
;
86 const OTypeInfoMap
* pTypeInfoMap
= m_pConnection
->getTypeInfo();
87 ::comphelper::UStringMixEqual
aCase(false);
88 // search for typeinfo where the typename is equal sTypeName
89 OTypeInfoMap::const_iterator aFind
= std::find_if(pTypeInfoMap
->begin(), pTypeInfoMap
->end(),
90 [&aCase
, &sTypeName
] (const OTypeInfoMap::value_type
& typeInfo
) {
91 return aCase(typeInfo
.second
->getDBName(), sTypeName
);
94 if ( aFind
!= pTypeInfoMap
->end() ) // change column type if necessary
95 aColumn
.put_Type(aFind
->first
);
97 if ( SUCCEEDED(static_cast<ADOColumns
*>(m_aCollection
)->Append(OLEVariant(aColumn
.get_Name()),aColumn
.get_Type(),aColumn
.get_DefinedSize())) )
99 WpADOColumn aAddedColumn
= m_aCollection
.GetItem(OLEVariant(aColumn
.get_Name()));
100 if ( aAddedColumn
.IsValid() )
102 bool bAutoIncrement
= false;
103 pColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
)) >>= bAutoIncrement
;
104 if ( bAutoIncrement
)
105 OTools::putValue( aAddedColumn
.get_Properties(), OUString("Autoincrement"), bAutoIncrement
);
107 if ( aFind
!= pTypeInfoMap
->end() && aColumn
.get_Type() != aAddedColumn
.get_Type() ) // change column type if necessary
108 aColumn
.put_Type(aFind
->first
);
109 aAddedColumn
.put_Precision(aColumn
.get_Precision());
110 aAddedColumn
.put_NumericScale(aColumn
.get_NumericScale());
111 aAddedColumn
.put_Attributes(aColumn
.get_Attributes());
112 aAddedColumn
.put_SortOrder(aColumn
.get_SortOrder());
113 aAddedColumn
.put_RelatedColumn(aColumn
.get_RelatedColumn());
116 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
118 return new OAdoColumn(isCaseSensitive(),m_pConnection
,pColumn
->getColumnImpl());
122 void OColumns::dropObject(sal_Int32
/*_nPos*/,const OUString
& _sElementName
)
124 if(!m_aCollection
.Delete(_sElementName
))
125 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */