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