Branch data Line data Source code
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 "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"
30 : :
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;
38 : : // -------------------------------------------------------------------------
39 : 0 : OIndexColumns::OIndexColumns( OIndexHelper* _pIndex,
40 : : ::osl::Mutex& _rMutex,
41 : : const ::std::vector< ::rtl::OUString> &_rVector)
42 : : : connectivity::sdbcx::OCollection(*_pIndex,sal_True,_rMutex,_rVector)
43 : 0 : ,m_pIndex(_pIndex)
44 : : {
45 : 0 : }
46 : : // -------------------------------------------------------------------------
47 : 0 : sdbcx::ObjectType OIndexColumns::createObject(const ::rtl::OUString& _rName)
48 : : {
49 [ # # ]: 0 : ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
50 : 0 : ::rtl::OUString aSchema,aTable;
51 [ # # ][ # # ]: 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
52 [ # # ][ # # ]: 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
53 : :
54 [ # # ][ # # ]: 0 : Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(
[ # # ][ # # ]
55 : 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
56 [ # # ][ # # ]: 0 : aSchema,aTable,sal_False,sal_False);
[ # # ]
57 : :
58 : 0 : sal_Bool bAsc = sal_True;
59 [ # # ]: 0 : if ( xResult.is() )
60 : : {
61 [ # # ]: 0 : Reference< XRow > xRow(xResult,UNO_QUERY);
62 [ # # ]: 0 : ::rtl::OUString aD(RTL_CONSTASCII_USTRINGPARAM("D"));
63 [ # # ][ # # ]: 0 : while( xResult->next() )
[ # # ]
64 : : {
65 [ # # ][ # # ]: 0 : if(xRow->getString(9) == _rName)
[ # # ]
66 [ # # ][ # # ]: 0 : bAsc = xRow->getString(10) != aD;
67 : 0 : }
68 : : }
69 : :
70 [ # # ][ # # ]: 0 : xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(
[ # # ][ # # ]
71 : 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
72 [ # # ][ # # ]: 0 : aSchema,aTable,_rName);
[ # # ][ # # ]
73 : :
74 : 0 : sdbcx::ObjectType xRet;
75 [ # # ]: 0 : if ( xResult.is() )
76 : : {
77 [ # # ]: 0 : Reference< XRow > xRow(xResult,UNO_QUERY);
78 [ # # ][ # # ]: 0 : while( xResult->next() )
[ # # ]
79 : : {
80 [ # # ][ # # ]: 0 : if ( xRow->getString(4) == _rName )
[ # # ]
81 : : {
82 [ # # ][ # # ]: 0 : sal_Int32 nDataType = xRow->getInt(5);
83 [ # # ][ # # ]: 0 : ::rtl::OUString aTypeName(xRow->getString(6));
84 [ # # ][ # # ]: 0 : sal_Int32 nSize = xRow->getInt(7);
85 [ # # ][ # # ]: 0 : sal_Int32 nDec = xRow->getInt(9);
86 [ # # ][ # # ]: 0 : sal_Int32 nNull = xRow->getInt(11);
87 [ # # ][ # # ]: 0 : ::rtl::OUString aColumnDef(xRow->getString(13));
88 : :
89 : : OIndexColumn* pRet = new OIndexColumn(bAsc,
90 : : _rName,
91 : : aTypeName,
92 : : aColumnDef,
93 : : nNull,
94 : : nSize,
95 : : nDec,
96 : : nDataType,
97 [ # # ]: 0 : sal_False,sal_False,sal_False,sal_True);
98 [ # # ][ # # ]: 0 : xRet = pRet;
99 : 0 : break;
100 : : }
101 : 0 : }
102 : : }
103 : :
104 : 0 : return xRet;
105 : : }
106 : : // -------------------------------------------------------------------------
107 : 0 : Reference< XPropertySet > OIndexColumns::createDescriptor()
108 : : {
109 [ # # ][ # # ]: 0 : return new OIndexColumn(sal_True);
110 : : }
111 : : // -------------------------------------------------------------------------
112 : 0 : void OIndexColumns::impl_refresh() throw(RuntimeException)
113 : : {
114 : 0 : m_pIndex->refreshColumns();
115 : 0 : }
116 : : // -----------------------------------------------------------------------------
117 : :
118 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|