LCOV - code coverage report
Current view: top level - connectivity/source/commontools - TPrivilegesResultSet.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 70 81.4 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.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 "TPrivilegesResultSet.hxx"
      21             : 
      22             : using namespace connectivity;
      23             : 
      24             : using namespace ::com::sun::star::beans;
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::sdbcx;
      27             : using namespace ::com::sun::star::sdbc;
      28             : using namespace ::com::sun::star::container;
      29             : using namespace ::com::sun::star::lang;
      30             : 
      31           9 : OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
      32             :                                            , const Any& catalog
      33             :                                            , const OUString& schemaPattern
      34             :                                            , const OUString& tableNamePattern)
      35             :                                            : ODatabaseMetaDataResultSet(eTablePrivileges)
      36           9 :                                            , m_bResetValues(true)
      37             : {
      38           9 :     osl_atomic_increment( &m_refCount );
      39             :     {
      40           9 :         OUString sUserWorkingFor;
      41          18 :         Sequence< OUString > sTableTypes(3);
      42             :         // we want all catalogues, all schemas, all tables
      43           9 :         sTableTypes[0] = "VIEW";
      44           9 :         sTableTypes[1] = "TABLE";
      45           9 :         sTableTypes[2] = "%"; // just to be sure to include anything else ....
      46             :         try
      47             :         {
      48           9 :             m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
      49           9 :             m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
      50             : 
      51           9 :             sUserWorkingFor = _rxMeta->getUserName();
      52             :         }
      53           0 :         catch(Exception&)
      54             :         {
      55             :         }
      56             : 
      57          18 :         ODatabaseMetaDataResultSet::ORows aRows;
      58           9 :         static ODatabaseMetaDataResultSet::ORow aRow(8);
      59           9 :         aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
      60           9 :         aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
      61           9 :         aRow[7] = new ORowSetValueDecorator(OUString("YES"));
      62           9 :         aRows.push_back(aRow);
      63           9 :         aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
      64           9 :         aRows.push_back(aRow);
      65           9 :         aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
      66           9 :         aRows.push_back(aRow);
      67           9 :         aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
      68           9 :         aRows.push_back(aRow);
      69           9 :         aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
      70           9 :         aRows.push_back(aRow);
      71           9 :         aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
      72           9 :         aRows.push_back(aRow);
      73           9 :         aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
      74           9 :         aRows.push_back(aRow);
      75           9 :         aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
      76           9 :         aRows.push_back(aRow);
      77           9 :         aRow[6] = new ORowSetValueDecorator(OUString("REFERENCE"));
      78           9 :         aRows.push_back(aRow);
      79             : 
      80          18 :         setRows(aRows);
      81             :     }
      82           9 :     osl_atomic_decrement( &m_refCount );
      83           9 : }
      84             : 
      85         162 : const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
      86             : {
      87         162 :     switch(columnIndex)
      88             :     {
      89             :         case 1:
      90             :         case 2:
      91             :         case 3:
      92           0 :             if ( m_xRow.is() && m_bResetValues )
      93             :             {
      94           0 :                 (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
      95           0 :                 if ( m_xRow->wasNull() )
      96           0 :                     (*m_aRowsIter)[1]->setNull();
      97           0 :                 (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
      98           0 :                 if ( m_xRow->wasNull() )
      99           0 :                     (*m_aRowsIter)[2]->setNull();
     100           0 :                 (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
     101           0 :                 if ( m_xRow->wasNull() )
     102           0 :                     (*m_aRowsIter)[3]->setNull();
     103             : 
     104           0 :                 m_bResetValues = false;
     105             :             }
     106             :     }
     107         162 :     return ODatabaseMetaDataResultSet::getValue(columnIndex);
     108             : }
     109             : 
     110           9 : void SAL_CALL OResultSetPrivileges::disposing()
     111             : {
     112           9 :     ODatabaseMetaDataResultSet::disposing();
     113           9 : m_xTables.clear();
     114           9 : m_xRow.clear();
     115           9 : }
     116             : 
     117          90 : sal_Bool SAL_CALL OResultSetPrivileges::next(  ) throw(SQLException, RuntimeException, std::exception)
     118             : {
     119          90 :     ::osl::MutexGuard aGuard( m_aMutex );
     120          90 :     checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
     121             : 
     122          90 :     bool bReturn = false;
     123          90 :     if ( m_xTables.is() )
     124             :     {
     125          90 :         if ( m_bBOF )
     126             :         {
     127           9 :             m_bResetValues = true;
     128           9 :             if ( !m_xTables->next() )
     129           0 :                 return sal_False;
     130             :         }
     131             : 
     132          90 :         bReturn = ODatabaseMetaDataResultSet::next();
     133          90 :         if ( !bReturn )
     134             :         {
     135           9 :             m_bBOF = false;
     136           9 :             m_bResetValues = bReturn = m_xTables->next();
     137             :         }
     138             :     }
     139          90 :     return bReturn;
     140             : }
     141             : 
     142             : 
     143             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11