LibreOffice Module connectivity (master) 1
TKeyColumns.cxx
Go to the documentation of this file.
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 <TKeyColumns.hxx>
21#include <TKey.hxx>
22#include <sdbcx/VKeyColumn.hxx>
23#include <com/sun/star/sdbc/SQLException.hpp>
24#include <com/sun/star/sdbc/XRow.hpp>
25#include <com/sun/star/sdbc/XResultSet.hpp>
26#include <TConnection.hxx>
28
29using namespace connectivity;
30using namespace connectivity::sdbcx;
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::beans;
33using namespace ::com::sun::star::sdbc;
34using namespace ::com::sun::star::container;
35using namespace ::com::sun::star::lang;
36
37
38OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper* _pKey,
39 ::osl::Mutex& _rMutex,
40 const std::vector< OUString> &_rVector)
41 : connectivity::sdbcx::OCollection(*_pKey,true,_rMutex,_rVector)
42 ,m_pKey(_pKey)
43{
44}
45
47{
49 OUString aCatalog, aSchema, aTable;
50 css::uno::Any Catalog(m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
51 Catalog >>= aCatalog;
52 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
53 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
54
55 // first get the related column to _rName
56 Reference< XResultSet > xResult = m_pKey->getTable()->getMetaData()->getImportedKeys(
57 Catalog, aSchema, aTable);
58
59 OUString aRefColumnName;
60 if ( xResult.is() )
61 {
62 Reference< XRow > xRow(xResult,UNO_QUERY);
63 OUString aTemp;
64 while(xResult->next())
65 {
66 aTemp = xRow->getString(4);
67 if(xRow->getString(8) == _rName && m_pKey->getName() == xRow->getString(12))
68 {
69 aRefColumnName = aTemp;
70 break;
71 }
72 }
73 }
74
76
77 // now describe the column _rName and set his related column
78 xResult = m_pKey->getTable()->getMetaData()->getColumns(Catalog, aSchema, aTable, _rName);
79
80 if ( xResult.is() )
81 {
82 Reference< XRow > xRow(xResult,UNO_QUERY);
83 if ( xResult->next() )
84 {
85 if ( xRow->getString(4) == _rName )
86 {
87 sal_Int32 nDataType = xRow->getInt(5);
88 OUString aTypeName(xRow->getString(6));
89 sal_Int32 nSize = xRow->getInt(7);
90 sal_Int32 nDec = xRow->getInt(9);
91 sal_Int32 nNull = xRow->getInt(11);
92 OUString sColumnDef;
93 try
94 {
95 sColumnDef = xRow->getString(13);
96 }
97 catch(const SQLException&)
98 {
99 // sometimes we get an error when asking for this param
100 }
101
102 xRet = new OKeyColumn(aRefColumnName,
103 _rName,
104 aTypeName,
105 sColumnDef,
106 nNull,
107 nSize,
108 nDec,
109 nDataType,
111 aCatalog,
112 aSchema,
113 aTable);
114 }
115 }
116 }
117
118 return xRet;
119}
120
121Reference< XPropertySet > OKeyColumnsHelper::createDescriptor()
122{
123 return new OKeyColumn(isCaseSensitive());
124}
125
127{
129}
130
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nDataType
virtual sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: TKeyColumns.cxx:46
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
virtual void impl_refresh() override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > getMetaData() const override
OTableHelper * getTable() const
Definition: TKey.hxx:38
virtual void refreshColumns() override
Definition: TKey.cxx:50
virtual OUString SAL_CALL getName() override
Definition: VKey.cxx:182
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
#define PROPERTY_ID_CATALOGNAME
Definition: propertyids.hxx:70
#define PROPERTY_ID_SCHEMANAME
Definition: propertyids.hxx:69