1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "connectivity/TKeyColumns.hxx"
27cdf0e10cSrcweir #include "connectivity/sdbcx/VKeyColumn.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
32cdf0e10cSrcweir #include <comphelper/extract.hxx>
33cdf0e10cSrcweir #include <comphelper/property.hxx>
34cdf0e10cSrcweir #include "TConnection.hxx"
35cdf0e10cSrcweir #include "connectivity/TTableHelper.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace connectivity;
38cdf0e10cSrcweir using namespace connectivity::sdbcx;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::beans;
41cdf0e10cSrcweir // using namespace ::com::sun::star::sdbcx;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
43cdf0e10cSrcweir using namespace ::com::sun::star::container;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir
46cdf0e10cSrcweir // -------------------------------------------------------------------------
OKeyColumnsHelper(OTableKeyHelper * _pKey,::osl::Mutex & _rMutex,const::std::vector<::rtl::OUString> & _rVector)47cdf0e10cSrcweir OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper* _pKey,
48cdf0e10cSrcweir ::osl::Mutex& _rMutex,
49cdf0e10cSrcweir const ::std::vector< ::rtl::OUString> &_rVector)
50cdf0e10cSrcweir : connectivity::sdbcx::OCollection(*_pKey,sal_True,_rMutex,_rVector)
51cdf0e10cSrcweir ,m_pKey(_pKey)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir // -------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)55cdf0e10cSrcweir sdbcx::ObjectType OKeyColumnsHelper::createObject(const ::rtl::OUString& _rName)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
58cdf0e10cSrcweir ::rtl::OUString aSchema,aTable;
59cdf0e10cSrcweir m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
60cdf0e10cSrcweir m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
61cdf0e10cSrcweir
62cdf0e10cSrcweir // frist get the related column to _rName
63cdf0e10cSrcweir Reference< XResultSet > xResult = m_pKey->getTable()->getMetaData()->getImportedKeys(
64cdf0e10cSrcweir m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),aSchema,aTable);
65cdf0e10cSrcweir
66cdf0e10cSrcweir ::rtl::OUString aRefColumnName;
67cdf0e10cSrcweir if ( xResult.is() )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir Reference< XRow > xRow(xResult,UNO_QUERY);
70cdf0e10cSrcweir ::rtl::OUString aTemp;
71cdf0e10cSrcweir while(xResult->next())
72cdf0e10cSrcweir {
73cdf0e10cSrcweir aTemp = xRow->getString(4);
74cdf0e10cSrcweir if(xRow->getString(8) == _rName && m_pKey->getName() == xRow->getString(12))
75cdf0e10cSrcweir {
76cdf0e10cSrcweir aRefColumnName = aTemp;
77cdf0e10cSrcweir break;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir sdbcx::ObjectType xRet;
83cdf0e10cSrcweir
84cdf0e10cSrcweir // now describe the column _rName and set his related column
85cdf0e10cSrcweir xResult = m_pKey->getTable()->getMetaData()->getColumns(
86cdf0e10cSrcweir m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),aSchema,aTable,_rName);
87cdf0e10cSrcweir
88cdf0e10cSrcweir if ( xResult.is() )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir Reference< XRow > xRow(xResult,UNO_QUERY);
91cdf0e10cSrcweir if ( xResult->next() )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir if ( xRow->getString(4) == _rName )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir sal_Int32 nDataType = xRow->getInt(5);
96cdf0e10cSrcweir ::rtl::OUString aTypeName(xRow->getString(6));
97cdf0e10cSrcweir sal_Int32 nSize = xRow->getInt(7);
98cdf0e10cSrcweir sal_Int32 nDec = xRow->getInt(9);
99cdf0e10cSrcweir sal_Int32 nNull = xRow->getInt(11);
100cdf0e10cSrcweir ::rtl::OUString sColumnDef;
101cdf0e10cSrcweir try
102cdf0e10cSrcweir {
103cdf0e10cSrcweir sColumnDef = xRow->getString(13);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir catch(const SQLException&)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir // somethimes we get an error when asking for this param
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir OKeyColumn* pRet = new OKeyColumn(aRefColumnName,
111cdf0e10cSrcweir _rName,
112cdf0e10cSrcweir aTypeName,
113cdf0e10cSrcweir sColumnDef,
114cdf0e10cSrcweir nNull,
115cdf0e10cSrcweir nSize,
116cdf0e10cSrcweir nDec,
117cdf0e10cSrcweir nDataType,
118cdf0e10cSrcweir sal_False,
119cdf0e10cSrcweir sal_False,
120cdf0e10cSrcweir sal_False,
121cdf0e10cSrcweir isCaseSensitive());
122cdf0e10cSrcweir xRet = pRet;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir return xRet;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir // -------------------------------------------------------------------------
createDescriptor()130cdf0e10cSrcweir Reference< XPropertySet > OKeyColumnsHelper::createDescriptor()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir return new OKeyColumn(isCaseSensitive());
133cdf0e10cSrcweir }
134cdf0e10cSrcweir // -------------------------------------------------------------------------
impl_refresh()135cdf0e10cSrcweir void OKeyColumnsHelper::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir m_pKey->refreshColumns();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir // -----------------------------------------------------------------------------
140cdf0e10cSrcweir
141cdf0e10cSrcweir
142