LCOV - code coverage report
Current view: top level - connectivity/source/drivers/firebird - Tables.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 15 38 39.5 %
Date: 2014-04-11 Functions: 2 6 33.3 %
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             : 
      10             : #include "Table.hxx"
      11             : #include "Tables.hxx"
      12             : 
      13             : #include <connectivity/dbtools.hxx>
      14             : 
      15             : #include <com/sun/star/sdbc/XRow.hpp>
      16             : 
      17             : using namespace ::connectivity;
      18             : using namespace ::connectivity::firebird;
      19             : using namespace ::connectivity::sdbcx;
      20             : using namespace ::cppu;
      21             : using namespace ::osl;
      22             : using namespace ::rtl;
      23             : 
      24             : using namespace ::com::sun::star;
      25             : using namespace ::com::sun::star::beans;
      26             : using namespace ::com::sun::star::container;
      27             : using namespace ::com::sun::star::lang;
      28             : using namespace ::com::sun::star::sdbc;
      29             : using namespace ::com::sun::star::uno;
      30             : 
      31             : 
      32           2 : Tables::Tables(const uno::Reference< XDatabaseMetaData >& rMetaData,
      33             :                OWeakObject& rParent,
      34             :                Mutex& rMutex,
      35             :                TStringVector& rNames) :
      36             :     OCollection(rParent,
      37             :                 true,
      38             :                 rMutex,
      39             :                 rNames),
      40             :     m_rMutex(rMutex),
      41           2 :     m_xMetaData(rMetaData)
      42             : {
      43           2 : }
      44             : 
      45             : //----- OCollection -----------------------------------------------------------
      46           0 : void Tables::impl_refresh()
      47             :     throw(RuntimeException)
      48             : {
      49             :     // TODO: IMPLEMENT ME
      50           0 : }
      51             : 
      52           1 : ObjectType Tables::createObject(const OUString& rName)
      53             : {
      54             :     // Only retrieving a single table, so table type is irrelevant (param 4)
      55           1 :     uno::Reference< XResultSet > xTables = m_xMetaData->getTables(Any(),
      56             :                                                                   OUString(),
      57             :                                                                   rName,
      58           1 :                                                                   uno::Sequence< OUString >());
      59             : 
      60           1 :     if (!xTables.is())
      61           0 :         throw RuntimeException();
      62             : 
      63           2 :     uno::Reference< XRow > xRow(xTables,UNO_QUERY);
      64             : 
      65           1 :     if (!xRow.is() || !xTables->next())
      66           0 :         throw RuntimeException();
      67             : 
      68             :     ObjectType xRet(new Table(this,
      69             :                               m_rMutex,
      70           1 :                               m_xMetaData->getConnection(),
      71           1 :                               xRow->getString(3), // Name
      72           1 :                               xRow->getString(4), // Type
      73           3 :                               xRow->getString(5))); // Description / Remarks / Comments
      74             : 
      75           1 :     if (xTables->next())
      76           0 :         throw RuntimeException(); // Only one table should be returned
      77             : 
      78           2 :     return xRet;
      79             : }
      80             : 
      81           0 : uno::Reference< XPropertySet > Tables::createDescriptor()
      82             : {
      83             :     // There is some internal magic so that the same class can be used as either
      84             :     // a descriptor or as a normal table. See VTable.cxx for the details. In our
      85             :     // case we just need to ensure we use the correct constructor.
      86           0 :     return new Table(this, m_rMutex, m_xMetaData->getConnection());
      87             : }
      88             : 
      89             : //----- XAppend ---------------------------------------------------------------
      90           0 : ObjectType Tables::appendObject(const OUString& rName,
      91             :                                 const uno::Reference< XPropertySet >& rDescriptor)
      92             : {
      93             :     OUString sSql(::dbtools::createSqlCreateTableStatement(rDescriptor,
      94           0 :                                                             m_xMetaData->getConnection()));
      95           0 :     m_xMetaData->getConnection()->createStatement()->execute(sSql);
      96             : 
      97           0 :     return createObject(rName);
      98             : }
      99             : 
     100             : //----- XDrop -----------------------------------------------------------------
     101           0 : void Tables::dropObject(sal_Int32 nPosition, const OUString& sName)
     102             : {
     103           0 :     uno::Reference< XPropertySet > xTable(getObject(nPosition));
     104             : 
     105           0 :     if (!ODescriptor::isNew(xTable))
     106             :     {
     107           0 :         OUStringBuffer sSql("DROP ");
     108             : 
     109           0 :         OUString sType;
     110           0 :         xTable->getPropertyValue("Type") >>= sType;
     111           0 :         sSql.append(sType);
     112             : 
     113           0 :         const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString();
     114           0 :         sSql.append(::dbtools::quoteName(sQuoteString,sName));
     115             : 
     116           0 :         m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear());
     117           0 :     }
     118           0 : }
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10