LCOV - code coverage report
Current view: top level - connectivity/source/commontools - TColumnsHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 78 9.0 %
Date: 2012-08-25 Functions: 2 10 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 176 1.1 %

           Branch data     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/TColumnsHelper.hxx"
      21                 :            : #include "connectivity/sdbcx/VColumn.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 <com/sun/star/sdbcx/KeyType.hpp>
      27                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      28                 :            : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      29                 :            : #include <comphelper/types.hxx>
      30                 :            : #include "connectivity/dbtools.hxx"
      31                 :            : #include "TConnection.hxx"
      32                 :            : #include "connectivity/TTableHelper.hxx"
      33                 :            : #include <comphelper/property.hxx>
      34                 :            : 
      35                 :            : using namespace ::comphelper;
      36                 :            : 
      37                 :            : 
      38                 :            : using namespace connectivity::sdbcx;
      39                 :            : using namespace connectivity;
      40                 :            : using namespace dbtools;
      41                 :            : using namespace ::com::sun::star::uno;
      42                 :            : using namespace ::com::sun::star::beans;
      43                 :            : using namespace ::com::sun::star::sdbcx;
      44                 :            : using namespace ::com::sun::star::sdbc;
      45                 :            : using namespace ::com::sun::star::container;
      46                 :            : using namespace ::com::sun::star::lang;
      47                 :            : 
      48                 :            : namespace connectivity
      49                 :            : {
      50                 :          0 :     class OColumnsHelperImpl
      51                 :            :     {
      52                 :            :     public:
      53                 :          0 :         OColumnsHelperImpl(sal_Bool _bCase)
      54         [ #  # ]:          0 :             : m_aColumnInfo(_bCase)
      55                 :            :         {
      56                 :          0 :         }
      57                 :            :         ColumnInformationMap m_aColumnInfo;
      58                 :            :     };
      59                 :            : }
      60                 :            : 
      61                 :        196 : OColumnsHelper::OColumnsHelper( ::cppu::OWeakObject& _rParent
      62                 :            :                                 ,sal_Bool _bCase
      63                 :            :                                 ,::osl::Mutex& _rMutex
      64                 :            :                                 ,const TStringVector &_rVector
      65                 :            :                                 ,sal_Bool _bUseHardRef
      66                 :            :             ) : OCollection(_rParent,_bCase,_rMutex,_rVector,sal_False,_bUseHardRef)
      67                 :            :     ,m_pImpl(NULL)
      68                 :        196 :     ,m_pTable(NULL)
      69                 :            : {
      70                 :        196 : }
      71                 :            : // -----------------------------------------------------------------------------
      72                 :        196 : OColumnsHelper::~OColumnsHelper()
      73                 :            : {
      74         [ -  + ]:        196 :     delete m_pImpl;
      75                 :        196 :     m_pImpl = NULL;
      76         [ -  + ]:        196 : }
      77                 :            : // -----------------------------------------------------------------------------
      78                 :            : 
      79                 :          0 : sdbcx::ObjectType OColumnsHelper::createObject(const ::rtl::OUString& _rName)
      80                 :            : {
      81                 :            :     OSL_ENSURE(m_pTable,"NO Table set. Error!");
      82         [ #  # ]:          0 :     Reference<XConnection> xConnection = m_pTable->getConnection();
      83                 :            : 
      84         [ #  # ]:          0 :     if ( !m_pImpl )
      85 [ #  # ][ #  # ]:          0 :         m_pImpl = new OColumnsHelperImpl(isCaseSensitive());
                 [ #  # ]
      86                 :            : 
      87                 :          0 :     sal_Bool bQueryInfo     = sal_True;
      88                 :          0 :     sal_Bool bAutoIncrement = sal_False;
      89                 :          0 :     sal_Bool bIsCurrency    = sal_False;
      90                 :          0 :     sal_Int32 nDataType     = DataType::OTHER;
      91                 :            : 
      92         [ #  # ]:          0 :     ColumnInformationMap::iterator aFind = m_pImpl->m_aColumnInfo.find(_rName);
      93         [ #  # ]:          0 :     if ( aFind == m_pImpl->m_aColumnInfo.end() ) // we have to fill it
      94                 :            :     {
      95 [ #  # ][ #  # ]:          0 :         ::rtl::OUString sComposedName = ::dbtools::composeTableNameForSelect( xConnection, m_pTable );
                 [ #  # ]
      96 [ #  # ][ #  # ]:          0 :         collectColumnInformation(xConnection,sComposedName,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*")) ,m_pImpl->m_aColumnInfo);
      97         [ #  # ]:          0 :         aFind = m_pImpl->m_aColumnInfo.find(_rName);
      98                 :            :     }
      99         [ #  # ]:          0 :     if ( aFind != m_pImpl->m_aColumnInfo.end() )
     100                 :            :     {
     101                 :          0 :         bQueryInfo      = sal_False;
     102                 :          0 :         bAutoIncrement  = aFind->second.first.first;
     103                 :          0 :         bIsCurrency     = aFind->second.first.second;
     104                 :          0 :         nDataType       = aFind->second.second;
     105                 :            :     } // if ( aFind != m_pImpl->m_aColumnInfo.end() )
     106                 :            : 
     107                 :          0 :     sdbcx::ObjectType xRet;
     108         [ #  # ]:          0 :     const ColumnDesc* pColDesc = m_pTable->getColumnDescription(_rName);
     109         [ #  # ]:          0 :     if ( pColDesc )
     110                 :            :     {
     111 [ #  # ][ #  # ]:          0 :         Reference<XPropertySet> xPr = m_pTable;
     112         [ #  # ]:          0 :         const Reference<XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(xPr);
     113                 :          0 :         sal_Int32 nField11 = pColDesc->nField11;
     114 [ #  # ][ #  # ]:          0 :         if ( nField11 != ColumnValue::NO_NULLS && xPrimaryKeyColumns.is() && xPrimaryKeyColumns->hasByName(_rName) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     115                 :            :         {
     116                 :          0 :             nField11 = ColumnValue::NO_NULLS;
     117                 :            :         } // if ( xKeys.is() )
     118                 :            :         connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName,
     119                 :            :                                                 pColDesc->aField6,
     120                 :            :                                                 pColDesc->sField13,
     121                 :            :                                                 pColDesc->sField12,
     122                 :            :                                                 nField11,
     123                 :            :                                                 pColDesc->nField7,
     124                 :            :                                                 pColDesc->nField9,
     125                 :            :                                                 pColDesc->nField5,
     126                 :            :                                                 bAutoIncrement,
     127                 :            :                                                 sal_False,
     128                 :            :                                                 bIsCurrency,
     129 [ #  # ][ #  # ]:          0 :                                                 isCaseSensitive());
     130                 :            : 
     131 [ #  # ][ #  # ]:          0 :         xRet = pRet;
     132                 :            :     }
     133                 :            :     else
     134                 :            :     {
     135                 :            : 
     136                 :            :         xRet.set(::dbtools::createSDBCXColumn(  m_pTable,
     137                 :            :                                                 xConnection,
     138                 :            :                                                 _rName,
     139         [ #  # ]:          0 :                                                 isCaseSensitive(),
     140                 :            :                                                 bQueryInfo,
     141                 :            :                                                 bAutoIncrement,
     142                 :            :                                                 bIsCurrency,
     143 [ #  # ][ #  # ]:          0 :                                                 nDataType),UNO_QUERY);
         [ #  # ][ #  # ]
     144                 :            :     }
     145                 :          0 :     return xRet;
     146                 :            : }
     147                 :            : 
     148                 :            : // -------------------------------------------------------------------------
     149                 :          0 : void OColumnsHelper::impl_refresh() throw(RuntimeException)
     150                 :            : {
     151         [ #  # ]:          0 :     if ( m_pTable )
     152                 :            :     {
     153                 :          0 :         m_pImpl->m_aColumnInfo.clear();
     154                 :          0 :         m_pTable->refreshColumns();
     155                 :            :     }
     156                 :          0 : }
     157                 :            : // -------------------------------------------------------------------------
     158                 :          0 : Reference< XPropertySet > OColumnsHelper::createDescriptor()
     159                 :            : {
     160 [ #  # ][ #  # ]:          0 :     return new OColumn(sal_True);
     161                 :            : }
     162                 :            : // -----------------------------------------------------------------------------
     163                 :            : // XAppend
     164                 :          0 : sdbcx::ObjectType OColumnsHelper::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
     165                 :            : {
     166         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_rMutex);
     167                 :            :     OSL_ENSURE(m_pTable,"OColumnsHelper::appendByDescriptor: Table is null!");
     168 [ #  # ][ #  # ]:          0 :     if ( !m_pTable || m_pTable->isNew() )
                 [ #  # ]
     169         [ #  # ]:          0 :         return cloneDescriptor( descriptor );
     170                 :            : 
     171 [ #  # ][ #  # ]:          0 :     Reference<XDatabaseMetaData> xMetaData = m_pTable->getConnection()->getMetaData();
                 [ #  # ]
     172         [ #  # ]:          0 :     ::rtl::OUString aSql( RTL_CONSTASCII_USTRINGPARAM( "ALTER TABLE " ));
     173 [ #  # ][ #  # ]:          0 :     ::rtl::OUString aQuote  = xMetaData->getIdentifierQuoteString(  );
     174                 :            : 
     175 [ #  # ][ #  # ]:          0 :     aSql += ::dbtools::composeTableName( xMetaData, m_pTable, ::dbtools::eInTableDefinitions, false, false, true );
                 [ #  # ]
     176         [ #  # ]:          0 :     aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ADD "));
     177 [ #  # ][ #  # ]:          0 :     aSql += ::dbtools::createStandardColumnPart(descriptor,m_pTable->getConnection(),NULL,m_pTable->getTypeCreatePattern());
                 [ #  # ]
     178                 :            : 
     179 [ #  # ][ #  # ]:          0 :     Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement(  );
                 [ #  # ]
     180         [ #  # ]:          0 :     if ( xStmt.is() )
     181                 :            :     {
     182 [ #  # ][ #  # ]:          0 :         xStmt->execute(aSql);
     183         [ #  # ]:          0 :         ::comphelper::disposeComponent(xStmt);
     184                 :            :     }
     185 [ #  # ][ #  # ]:          0 :     return createObject( _rForName );
     186                 :            : }
     187                 :            : // -------------------------------------------------------------------------
     188                 :            : // XDrop
     189                 :          0 : void OColumnsHelper::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName)
     190                 :            : {
     191                 :            :     OSL_ENSURE(m_pTable,"OColumnsHelper::dropByName: Table is null!");
     192 [ #  # ][ #  # ]:          0 :     if ( m_pTable && !m_pTable->isNew() )
                 [ #  # ]
     193                 :            :     {
     194         [ #  # ]:          0 :         ::rtl::OUString aSql( RTL_CONSTASCII_USTRINGPARAM( "ALTER TABLE " ));
     195 [ #  # ][ #  # ]:          0 :         Reference<XDatabaseMetaData> xMetaData = m_pTable->getConnection()->getMetaData();
                 [ #  # ]
     196 [ #  # ][ #  # ]:          0 :         ::rtl::OUString aQuote  = xMetaData->getIdentifierQuoteString(  );
     197                 :            : 
     198 [ #  # ][ #  # ]:          0 :         aSql += ::dbtools::composeTableName( xMetaData, m_pTable, ::dbtools::eInTableDefinitions, false, false, true );
                 [ #  # ]
     199         [ #  # ]:          0 :         aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP "));
     200         [ #  # ]:          0 :         aSql += ::dbtools::quoteName( aQuote,_sElementName);
     201                 :            : 
     202 [ #  # ][ #  # ]:          0 :         Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement(  );
                 [ #  # ]
     203         [ #  # ]:          0 :         if ( xStmt.is() )
     204                 :            :         {
     205 [ #  # ][ #  # ]:          0 :             xStmt->execute(aSql);
     206         [ #  # ]:          0 :             ::comphelper::disposeComponent(xStmt);
     207                 :          0 :         }
     208                 :            :     }
     209                 :          0 : }
     210                 :            : // -----------------------------------------------------------------------------
     211                 :            : 
     212                 :            : 
     213                 :            : 
     214                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10