LibreOffice Module connectivity (master) 1
AColumns.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
30#include <comphelper/types.hxx>
32#include <rtl/ref.hxx>
33#include <algorithm>
34#include <string_view>
35#include <strings.hrc>
36
37using namespace connectivity::ado;
38using namespace connectivity;
39using namespace comphelper;
40using namespace com::sun::star::uno;
41using namespace com::sun::star::lang;
42using namespace com::sun::star::beans;
43using namespace com::sun::star::sdbc;
44using namespace com::sun::star::container;
45
46sdbcx::ObjectType OColumns::createObject(const OUString& _rName)
47{
49}
50
51
53{
55}
56
58{
60}
61
62// XAppend
63sdbcx::ObjectType OColumns::appendObject( const OUString&, const Reference< XPropertySet >& descriptor )
64{
65 rtl::Reference<OAdoColumn> pColumn = dynamic_cast<OAdoColumn*>( descriptor.get() );
67 if ( !pColumn.is() )
68 {
69 // m_pConnection->throwGenericSQLException( STR_INVALID_COLUMN_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
71 xColumn = pColumn;
72 ::comphelper::copyProperties(descriptor,xColumn);
73 }
74
75 WpADOColumn aColumn = pColumn->getColumnImpl();
76
77 OUString sTypeName;
78 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName;
79
80 const OTypeInfoMap* pTypeInfoMap = m_pConnection->getTypeInfo();
82 // search for typeinfo where the typename is equal sTypeName
83 OTypeInfoMap::const_iterator aFind = std::find_if(pTypeInfoMap->begin(), pTypeInfoMap->end(),
84 [&aCase, &sTypeName] (const OTypeInfoMap::value_type& typeInfo) {
85 return aCase(typeInfo.second->getDBName(), sTypeName);
86 });
87
88 if ( aFind != pTypeInfoMap->end() ) // change column type if necessary
89 aColumn.put_Type(aFind->first);
90
91 if ( SUCCEEDED(static_cast<ADOColumns*>(m_aCollection)->Append(OLEVariant(aColumn.get_Name()),aColumn.get_Type(),aColumn.get_DefinedSize())) )
92 {
93 WpADOColumn aAddedColumn = m_aCollection.GetItem(OLEVariant(aColumn.get_Name()));
94 if ( aAddedColumn.IsValid() )
95 {
96 bool bAutoIncrement = false;
97 pColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement;
98 if ( bAutoIncrement )
100 aAddedColumn.get_Properties(), std::u16string_view(u"Autoincrement"),
101 bAutoIncrement);
102
103 if ( aFind != pTypeInfoMap->end() && aColumn.get_Type() != aAddedColumn.get_Type() ) // change column type if necessary
104 aColumn.put_Type(aFind->first);
105 aAddedColumn.put_Precision(aColumn.get_Precision());
106 aAddedColumn.put_NumericScale(aColumn.get_NumericScale());
107 aAddedColumn.put_Attributes(aColumn.get_Attributes());
108 aAddedColumn.put_SortOrder(aColumn.get_SortOrder());
109 aAddedColumn.put_RelatedColumn(aColumn.get_RelatedColumn());
110 }
111 }
112 ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
113
114 return new OAdoColumn(isCaseSensitive(),m_pConnection,pColumn->getColumnImpl());
115}
116
117// XDrop
118void OColumns::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
119{
120 if(!m_aCollection.Delete(_sElementName))
121 ADOS::ThrowException(m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
122}
123
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
static void ThrowException(ADOConnection *_pAdoCon, const css::uno::Reference< css::uno::XInterface > &_xInterface)
Definition: ADriver.cxx:207
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: AColumns.cxx:118
WpADOColumns m_aCollection
Definition: AColumns.hxx:33
virtual sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
appends an object described by a descriptor, under a given name
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: AColumns.cxx:57
OConnection * m_pConnection
Definition: AColumns.hxx:34
virtual void impl_refresh() override
Definition: AColumns.cxx:52
WpADOConnection & getConnection()
const OTypeInfoMap * getTypeInfo() const
static void putValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition, const OLEVariant &_aValVar)
putValue set the property value at the ado column
Definition: Awrapado.cxx:1992
DataTypeEnum get_Type() const
Definition: Awrapado.cxx:1007
SortOrderEnum get_SortOrder() const
Definition: Awrapado.cxx:1056
void put_NumericScale(sal_Int8 _nScale)
Definition: Awrapado.cxx:1050
sal_uInt8 get_NumericScale() const
Definition: Awrapado.cxx:1042
sal_Int32 get_DefinedSize() const
Definition: Awrapado.cxx:1035
OUString get_RelatedColumn() const
Definition: Awrapado.cxx:986
sal_Int32 get_Precision() const
Definition: Awrapado.cxx:1021
WpADOProperties get_Properties() const
Definition: Awrapado.cxx:1084
bool put_Attributes(const ColumnAttributesEnum &_eNum)
Definition: Awrapado.cxx:1078
void put_SortOrder(SortOrderEnum _nScale)
Definition: Awrapado.cxx:1064
void put_RelatedColumn(std::u16string_view _rName)
Definition: Awrapado.cxx:1000
void put_Type(const DataTypeEnum &_eNum)
Definition: Awrapado.cxx:1015
void put_Precision(sal_Int32 _nPre)
Definition: Awrapado.cxx:1029
ColumnAttributesEnum get_Attributes() const
Definition: Awrapado.cxx:1070
bool Delete(const OUString &sName)
Definition: Aolewrap.hxx:165
WrapT GetItem(sal_Int32 index) const
Definition: Aolewrap.hxx:102
Reference< XColumn > xColumn
bool bAutoIncrement
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
std::multimap< sal_Int32, TOTypeInfoSP > OTypeInfoMap
#define PROPERTY_ID_ISAUTOINCREMENT
Definition: propertyids.hxx:56
#define PROPERTY_ID_TYPENAME
Definition: propertyids.hxx:52