LCOV - code coverage report
Current view: top level - connectivity/source/commontools - TKeyColumns.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 3 46 6.5 %
Date: 2014-11-03 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <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>
      30             : 
      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;
      38             : 
      39             : 
      40           4 : OKeyColumnsHelper::OKeyColumnsHelper(   OTableKeyHelper* _pKey,
      41             :                 ::osl::Mutex& _rMutex,
      42             :                 const ::std::vector< OUString> &_rVector)
      43             :             : connectivity::sdbcx::OCollection(*_pKey,true,_rMutex,_rVector)
      44           4 :             ,m_pKey(_pKey)
      45             : {
      46           4 : }
      47             : 
      48           0 : sdbcx::ObjectType OKeyColumnsHelper::createObject(const OUString& _rName)
      49             : {
      50           0 :     ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
      51           0 :     OUString aCatalog, aSchema, aTable;
      52           0 :     ::com::sun::star::uno::Any Catalog(m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
      53           0 :     Catalog >>= aCatalog;
      54           0 :     m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME))   >>= aSchema;
      55           0 :     m_pKey->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))         >>= aTable;
      56             : 
      57             :     // frist get the related column to _rName
      58           0 :     Reference< XResultSet > xResult = m_pKey->getTable()->getMetaData()->getImportedKeys(
      59           0 :             Catalog, aSchema, aTable);
      60             : 
      61           0 :     OUString aRefColumnName;
      62           0 :     if ( xResult.is() )
      63             :     {
      64           0 :         Reference< XRow > xRow(xResult,UNO_QUERY);
      65           0 :         OUString aTemp;
      66           0 :         while(xResult->next())
      67             :         {
      68           0 :             aTemp = xRow->getString(4);
      69           0 :             if(xRow->getString(8) == _rName && m_pKey->getName() == xRow->getString(12))
      70             :             {
      71           0 :                 aRefColumnName = aTemp;
      72           0 :                 break;
      73             :             }
      74           0 :         }
      75             :     }
      76             : 
      77           0 :     sdbcx::ObjectType xRet;
      78             : 
      79             :     // now describe the column _rName and set his related column
      80           0 :     xResult = m_pKey->getTable()->getMetaData()->getColumns(Catalog, aSchema, aTable, _rName);
      81             : 
      82           0 :     if ( xResult.is() )
      83             :     {
      84           0 :         Reference< XRow > xRow(xResult,UNO_QUERY);
      85           0 :         if ( xResult->next() )
      86             :         {
      87           0 :             if ( xRow->getString(4) == _rName )
      88             :             {
      89           0 :                 sal_Int32 nDataType = xRow->getInt(5);
      90           0 :                 OUString aTypeName(xRow->getString(6));
      91           0 :                 sal_Int32 nSize = xRow->getInt(7);
      92           0 :                 sal_Int32 nDec  = xRow->getInt(9);
      93           0 :                 sal_Int32 nNull = xRow->getInt(11);
      94           0 :                 OUString sColumnDef;
      95             :                 try
      96             :                 {
      97           0 :                     sColumnDef = xRow->getString(13);
      98             :                 }
      99           0 :                 catch(const SQLException&)
     100             :                 {
     101             :                     // somethimes we get an error when asking for this param
     102             :                 }
     103             : 
     104             :                 OKeyColumn* pRet = new OKeyColumn(aRefColumnName,
     105             :                                                   _rName,
     106             :                                                   aTypeName,
     107             :                                                   sColumnDef,
     108             :                                                   nNull,
     109             :                                                   nSize,
     110             :                                                   nDec,
     111             :                                                   nDataType,
     112             :                                                   false,
     113             :                                                   false,
     114             :                                                   false,
     115           0 :                                                   isCaseSensitive(),
     116             :                                                   aCatalog,
     117             :                                                   aSchema,
     118           0 :                                                   aTable);
     119           0 :                 xRet = pRet;
     120             :             }
     121           0 :         }
     122             :     }
     123             : 
     124           0 :     return xRet;
     125             : }
     126             : 
     127           0 : Reference< XPropertySet > OKeyColumnsHelper::createDescriptor()
     128             : {
     129           0 :     return new OKeyColumn(isCaseSensitive());
     130             : }
     131             : 
     132           0 : void OKeyColumnsHelper::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
     133             : {
     134           0 :     m_pKey->refreshColumns();
     135           0 : }
     136             : 
     137             : 
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10