LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mysql - YCatalog.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 65 0.0 %
Date: 2014-04-14 Functions: 0 8 0.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 "mysql/YCatalog.hxx"
      21             : #include "mysql/YUsers.hxx"
      22             : #include "mysql/YTables.hxx"
      23             : #include "mysql/YViews.hxx"
      24             : #include <com/sun/star/sdbc/XRow.hpp>
      25             : #include <com/sun/star/sdbc/XResultSet.hpp>
      26             : #include <comphelper/types.hxx>
      27             : 
      28             : 
      29             : 
      30             : using namespace connectivity;
      31             : using namespace connectivity::mysql;
      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::sdbcx;
      36             : using namespace ::com::sun::star::sdbc;
      37             : using namespace ::com::sun::star::container;
      38             : using namespace ::com::sun::star::lang;
      39             : 
      40           0 : OMySQLCatalog::OMySQLCatalog(const Reference< XConnection >& _xConnection) : OCatalog(_xConnection)
      41           0 :                 ,m_xConnection(_xConnection)
      42             : {
      43           0 : }
      44             : 
      45           0 : void OMySQLCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,TStringVector& _rNames)
      46             : {
      47           0 :     Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
      48             :                                                             OUString("%"),
      49             :                                                             OUString("%"),
      50           0 :                                                             _sKindOfObject);
      51           0 :     fillNames(xResult,_rNames);
      52           0 : }
      53             : 
      54           0 : void OMySQLCatalog::refreshTables()
      55             : {
      56           0 :     TStringVector aVector;
      57           0 :     static const OUString s_sTableTypeView("VIEW");
      58           0 :     static const OUString s_sTableTypeTable("TABLE");
      59           0 :     static const OUString s_sAll("%");
      60             : 
      61           0 :     Sequence< OUString > sTableTypes(3);
      62           0 :     sTableTypes[0] = s_sTableTypeView;
      63           0 :     sTableTypes[1] = s_sTableTypeTable;
      64           0 :     sTableTypes[2] = s_sAll;    // just to be sure to include anything else ....
      65             : 
      66           0 :     refreshObjects(sTableTypes,aVector);
      67             : 
      68           0 :     if ( m_pTables )
      69           0 :         m_pTables->reFill(aVector);
      70             :     else
      71           0 :         m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
      72           0 : }
      73             : 
      74           0 : void OMySQLCatalog::refreshViews()
      75             : {
      76           0 :     Sequence< OUString > aTypes(1);
      77           0 :     aTypes[0] = "VIEW";
      78             : 
      79             :     // let's simply assume the server is new enough to support views. Current drivers
      80             :     // as of this writing might not return the proper information in getTableTypes, so
      81             :     // don't rely on it.
      82             :     // during #73245# / 2007-10-26 / frank.schoenheit@sun.com
      83           0 :     bool bSupportsViews = true;
      84             : 
      85           0 :     TStringVector aVector;
      86           0 :     if ( bSupportsViews )
      87           0 :         refreshObjects(aTypes,aVector);
      88             : 
      89           0 :     if ( m_pViews )
      90           0 :         m_pViews->reFill(aVector);
      91             :     else
      92           0 :         m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector);
      93           0 : }
      94             : 
      95           0 : void OMySQLCatalog::refreshGroups()
      96             : {
      97           0 : }
      98             : 
      99           0 : void OMySQLCatalog::refreshUsers()
     100             : {
     101           0 :     TStringVector aVector;
     102           0 :     Reference< XStatement > xStmt = m_xConnection->createStatement(  );
     103           0 :     Reference< XResultSet >  xResult = xStmt->executeQuery(OUString("SELECT grantee FROM information_schema.user_privileges GROUP BY grantee"));
     104           0 :     if ( xResult.is() )
     105             :     {
     106           0 :         Reference< XRow > xRow(xResult,UNO_QUERY);
     107           0 :         TString2IntMap aMap;
     108           0 :         while( xResult->next() )
     109           0 :             aVector.push_back(xRow->getString(1));
     110           0 :         ::comphelper::disposeComponent(xResult);
     111             :     }
     112           0 :     ::comphelper::disposeComponent(xStmt);
     113             : 
     114           0 :     if(m_pUsers)
     115           0 :         m_pUsers->reFill(aVector);
     116             :     else
     117           0 :         m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
     118           0 : }
     119             : 
     120           0 : Any SAL_CALL OMySQLCatalog::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
     121             : {
     122           0 :     if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
     123           0 :         return Any();
     124             : 
     125             : 
     126           0 :     return OCatalog::queryInterface(rType);
     127             : }
     128             : 
     129           0 : Sequence< Type > SAL_CALL OMySQLCatalog::getTypes(  ) throw(RuntimeException, std::exception)
     130             : {
     131           0 :     Sequence< Type > aTypes = OCatalog::getTypes();
     132           0 :     ::std::vector<Type> aOwnTypes;
     133           0 :     aOwnTypes.reserve(aTypes.getLength());
     134           0 :     const Type* pBegin = aTypes.getConstArray();
     135           0 :     const Type* pEnd = pBegin + aTypes.getLength();
     136           0 :     for(;pBegin != pEnd;++pBegin)
     137             :     {
     138           0 :         if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
     139             :         {
     140           0 :             aOwnTypes.push_back(*pBegin);
     141             :         }
     142             :     }
     143           0 :     const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
     144           0 :     return Sequence< Type >(pTypes, aOwnTypes.size());
     145             : }
     146             : 
     147             : 
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10