bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / commontools / TIndexColumns.cxx
blob0edd2ec88eeb923af6f964ee43ee65df52956de0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <connectivity/TIndexColumns.hxx>
21 #include <connectivity/sdbcx/VIndexColumn.hxx>
22 #include <com/sun/star/sdbc/XRow.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <com/sun/star/sdbc/ColumnValue.hpp>
26 #include <comphelper/property.hxx>
27 #include <connectivity/TIndex.hxx>
28 #include <connectivity/TTableHelper.hxx>
29 #include "TConnection.hxx"
31 using namespace connectivity;
32 using namespace connectivity::sdbcx;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
39 OIndexColumns::OIndexColumns( OIndexHelper* _pIndex,
40 ::osl::Mutex& _rMutex,
41 const ::std::vector< OUString> &_rVector)
42 : connectivity::sdbcx::OCollection(*_pIndex,true,_rMutex,_rVector)
43 ,m_pIndex(_pIndex)
47 sdbcx::ObjectType OIndexColumns::createObject(const OUString& _rName)
49 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
50 OUString aCatalog, aSchema, aTable;
51 ::com::sun::star::uno::Any Catalog(m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
52 Catalog >>= aCatalog;
53 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
54 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
56 Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(
57 Catalog, aSchema, aTable, sal_False, sal_False);
59 bool bAsc = true;
60 if ( xResult.is() )
62 Reference< XRow > xRow(xResult,UNO_QUERY);
63 OUString aD("D");
64 while( xResult->next() )
66 if(xRow->getString(9) == _rName)
67 bAsc = xRow->getString(10) != aD;
71 xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(
72 Catalog, aSchema, aTable, _rName);
74 sdbcx::ObjectType xRet;
75 if ( xResult.is() )
77 Reference< XRow > xRow(xResult,UNO_QUERY);
78 while( xResult->next() )
80 if ( xRow->getString(4) == _rName )
82 sal_Int32 nDataType = xRow->getInt(5);
83 OUString aTypeName(xRow->getString(6));
84 sal_Int32 nSize = xRow->getInt(7);
85 sal_Int32 nDec = xRow->getInt(9);
86 sal_Int32 nNull = xRow->getInt(11);
87 OUString aColumnDef(xRow->getString(13));
89 OIndexColumn* pRet = new OIndexColumn(bAsc,
90 _rName,
91 aTypeName,
92 aColumnDef,
93 nNull,
94 nSize,
95 nDec,
96 nDataType,
97 false,false,false,true,
98 aCatalog, aSchema, aTable);
99 xRet = pRet;
100 break;
105 return xRet;
108 Reference< XPropertySet > OIndexColumns::createDescriptor()
110 return new OIndexColumn(true);
113 void OIndexColumns::impl_refresh() throw(RuntimeException)
115 m_pIndex->refreshColumns();
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */