1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "connectivity/TKeyColumns.hxx"
30 #include "connectivity/sdbcx/VKeyColumn.hxx"
31 #include <com/sun/star/sdbc/XRow.hpp>
32 #include <com/sun/star/sdbc/XResultSet.hpp>
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/sdbc/ColumnValue.hpp>
35 #include <comphelper/extract.hxx>
36 #include <comphelper/property.hxx>
37 #include "TConnection.hxx"
38 #include "connectivity/TTableHelper.hxx"
40 using namespace connectivity
;
41 using namespace connectivity::sdbcx
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::sdbc
;
45 using namespace ::com::sun::star::container
;
46 using namespace ::com::sun::star::lang
;
48 // -------------------------------------------------------------------------
49 OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper
* _pKey
,
50 ::osl::Mutex
& _rMutex
,
51 const ::std::vector
< ::rtl::OUString
> &_rVector
)
52 : connectivity::sdbcx::OCollection(*_pKey
,sal_True
,_rMutex
,_rVector
)
56 // -------------------------------------------------------------------------
57 sdbcx::ObjectType
OKeyColumnsHelper::createObject(const ::rtl::OUString
& _rName
)
59 ::dbtools::OPropertyMap
& rPropMap
= OMetaConnection::getPropMap();
60 ::rtl::OUString aSchema
,aTable
;
61 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_SCHEMANAME
)) >>= aSchema
;
62 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_NAME
)) >>= aTable
;
64 // frist get the related column to _rName
65 Reference
< XResultSet
> xResult
= m_pKey
->getTable()->getMetaData()->getImportedKeys(
66 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_CATALOGNAME
)),aSchema
,aTable
);
68 ::rtl::OUString aRefColumnName
;
71 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
72 ::rtl::OUString aTemp
;
73 while(xResult
->next())
75 aTemp
= xRow
->getString(4);
76 if(xRow
->getString(8) == _rName
&& m_pKey
->getName() == xRow
->getString(12))
78 aRefColumnName
= aTemp
;
84 sdbcx::ObjectType xRet
;
86 // now describe the column _rName and set his related column
87 xResult
= m_pKey
->getTable()->getMetaData()->getColumns(
88 m_pKey
->getTable()->getPropertyValue(rPropMap
.getNameByIndex(PROPERTY_ID_CATALOGNAME
)),aSchema
,aTable
,_rName
);
92 Reference
< XRow
> xRow(xResult
,UNO_QUERY
);
93 if ( xResult
->next() )
95 if ( xRow
->getString(4) == _rName
)
97 sal_Int32 nDataType
= xRow
->getInt(5);
98 ::rtl::OUString
aTypeName(xRow
->getString(6));
99 sal_Int32 nSize
= xRow
->getInt(7);
100 sal_Int32 nDec
= xRow
->getInt(9);
101 sal_Int32 nNull
= xRow
->getInt(11);
102 ::rtl::OUString sColumnDef
;
105 sColumnDef
= xRow
->getString(13);
107 catch(const SQLException
&)
109 // somethimes we get an error when asking for this param
112 OKeyColumn
* pRet
= new OKeyColumn(aRefColumnName
,
131 // -------------------------------------------------------------------------
132 Reference
< XPropertySet
> OKeyColumnsHelper::createDescriptor()
134 return new OKeyColumn(isCaseSensitive());
136 // -------------------------------------------------------------------------
137 void OKeyColumnsHelper::impl_refresh() throw(::com::sun::star::uno::RuntimeException
)
139 m_pKey
->refreshColumns();
141 // -----------------------------------------------------------------------------
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */