sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / connectivity / source / commontools / TKeyColumns.cxx
bloba26628765417499efec76c6467abd037eaf04c90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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>
27 #include <connectivity/TTableHelper.hxx>
29 using namespace connectivity;
30 using namespace connectivity::sdbcx;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::sdbc;
36 OKeyColumnsHelper::OKeyColumnsHelper( OTableKeyHelper* _pKey,
37 ::osl::Mutex& _rMutex,
38 const std::vector< OUString> &_rVector)
39 : connectivity::sdbcx::OCollection(*_pKey,true,_rMutex,_rVector)
40 ,m_pKey(_pKey)
44 sdbcx::ObjectType OKeyColumnsHelper::createObject(const OUString& _rName)
46 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
47 OUString aCatalog, aSchema, aTable;
48 css::uno::Any Catalog(m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
49 Catalog >>= aCatalog;
50 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
51 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
53 // first get the related column to _rName
54 Reference< XResultSet > xResult = m_pKey->getTable()->getMetaData()->getImportedKeys(
55 Catalog, aSchema, aTable);
57 OUString aRefColumnName;
58 if ( xResult.is() )
60 Reference< XRow > xRow(xResult,UNO_QUERY);
61 OUString aTemp;
62 while(xResult->next())
64 aTemp = xRow->getString(4);
65 if(xRow->getString(8) == _rName && m_pKey->getName() == xRow->getString(12))
67 aRefColumnName = aTemp;
68 break;
73 sdbcx::ObjectType xRet;
75 // now describe the column _rName and set his related column
76 xResult = m_pKey->getTable()->getMetaData()->getColumns(Catalog, aSchema, aTable, _rName);
78 if ( xResult.is() )
80 Reference< XRow > xRow(xResult,UNO_QUERY);
81 if ( xResult->next() )
83 if ( xRow->getString(4) == _rName )
85 sal_Int32 nDataType = xRow->getInt(5);
86 OUString aTypeName(xRow->getString(6));
87 sal_Int32 nSize = xRow->getInt(7);
88 sal_Int32 nDec = xRow->getInt(9);
89 sal_Int32 nNull = xRow->getInt(11);
90 OUString sColumnDef;
91 try
93 sColumnDef = xRow->getString(13);
95 catch(const SQLException&)
97 // sometimes we get an error when asking for this param
100 xRet = new OKeyColumn(aRefColumnName,
101 _rName,
102 aTypeName,
103 sColumnDef,
104 nNull,
105 nSize,
106 nDec,
107 nDataType,
108 isCaseSensitive(),
109 aCatalog,
110 aSchema,
111 aTable);
116 return xRet;
119 Reference< XPropertySet > OKeyColumnsHelper::createDescriptor()
121 return new OKeyColumn(isCaseSensitive());
124 void OKeyColumnsHelper::impl_refresh()
126 m_pKey->refreshColumns();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */