1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/TKeyColumns.hxx"
21 #include "connectivity/sdbcx/VKeyColumn.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/extract.hxx>
27 #include <comphelper/property.hxx>
28 #include "TConnection.hxx"
29 #include "connectivity/TTableHelper.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
;
40 OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper
* _pKey
,
41 ::osl::Mutex
& _rMutex
,
42 const ::std::vector
< OUString
> &_rVector
)
43 : connectivity::sdbcx::OCollection(*_pKey
,true,_rMutex
,_rVector
)
48 sdbcx::ObjectType
OKeyColumnsHelper::createObject(const OUString
& _rName
)
50 ::dbtools::OPropertyMap
& rPropMap
= OMetaConnection::getPropMap();
51 OUString aCatalog
, aSchema
, aTable
;
52 ::com::sun::star::uno::Any
Catalog(m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_CATALOGNAME
)));
54 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_SCHEMANAME
)) >>= aSchema
;
55 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_NAME
)) >>= aTable
;
57 // frist get the related column to _rName
58 Reference
< XResultSet
> xResult
= m_pKey
->getTable()->getMetaData()->getImportedKeys(
59 Catalog
, aSchema
, aTable
);
61 OUString aRefColumnName
;
64 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
66 while(xResult
->next())
68 aTemp
= xRow
->getString(4);
69 if(xRow
->getString(8) == _rName
&& m_pKey
->getName() == xRow
->getString(12))
71 aRefColumnName
= aTemp
;
77 sdbcx::ObjectType xRet
;
79 // now describe the column _rName and set his related column
80 xResult
= m_pKey
->getTable()->getMetaData()->getColumns(Catalog
, aSchema
, aTable
, _rName
);
84 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
85 if ( xResult
->next() )
87 if ( xRow
->getString(4) == _rName
)
89 sal_Int32 nDataType
= xRow
->getInt(5);
90 OUString
aTypeName(xRow
->getString(6));
91 sal_Int32 nSize
= xRow
->getInt(7);
92 sal_Int32 nDec
= xRow
->getInt(9);
93 sal_Int32 nNull
= xRow
->getInt(11);
97 sColumnDef
= xRow
->getString(13);
99 catch(const SQLException
&)
101 // somethimes we get an error when asking for this param
104 OKeyColumn
* pRet
= new OKeyColumn(aRefColumnName
,
127 Reference
< XPropertySet
> OKeyColumnsHelper::createDescriptor()
129 return new OKeyColumn(isCaseSensitive());
132 void OKeyColumnsHelper::impl_refresh() throw(::com::sun::star::uno::RuntimeException
)
134 m_pKey
->refreshColumns();
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */