bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / commontools / TKeyColumns.cxx
blob682114e13e34e7c3690a7a00ee6cd49f7e1a9080
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 <connectivity/TKeyColumns.hxx>
21 #include <connectivity/TKey.hxx>
22 #include <connectivity/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 <com/sun/star/sdbc/DataType.hpp>
27 #include <com/sun/star/sdbc/ColumnValue.hpp>
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)
44 ,m_pKey(_pKey)
48 sdbcx::ObjectType OKeyColumnsHelper::createObject(const OUString& _rName)
50 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
51 OUString aCatalog, aSchema, aTable;
52 css::uno::Any Catalog(m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
53 Catalog >>= aCatalog;
54 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
55 m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
57 // first get the related column to _rName
58 Reference< XResultSet > xResult = m_pKey->getTable()->getMetaData()->getImportedKeys(
59 Catalog, aSchema, aTable);
61 OUString aRefColumnName;
62 if ( xResult.is() )
64 Reference< XRow > xRow(xResult,UNO_QUERY);
65 OUString aTemp;
66 while(xResult->next())
68 aTemp = xRow->getString(4);
69 if(xRow->getString(8) == _rName && m_pKey->getName() == xRow->getString(12))
71 aRefColumnName = aTemp;
72 break;
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);
82 if ( xResult.is() )
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);
94 OUString sColumnDef;
95 try
97 sColumnDef = xRow->getString(13);
99 catch(const SQLException&)
101 // sometimes we get an error when asking for this param
104 OKeyColumn* pRet = new OKeyColumn(aRefColumnName,
105 _rName,
106 aTypeName,
107 sColumnDef,
108 nNull,
109 nSize,
110 nDec,
111 nDataType,
112 isCaseSensitive(),
113 aCatalog,
114 aSchema,
115 aTable);
116 xRet = pRet;
121 return xRet;
124 Reference< XPropertySet > OKeyColumnsHelper::createDescriptor()
126 return new OKeyColumn(isCaseSensitive());
129 void OKeyColumnsHelper::impl_refresh()
131 m_pKey->refreshColumns();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */