LCOV - code coverage report
Current view: top level - connectivity/source/drivers/flat - EDatabaseMetaData.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 139 0.0 %
Date: 2014-04-14 Functions: 0 6 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 "flat/EDatabaseMetaData.hxx"
      21             : #include <com/sun/star/sdbc/DataType.hpp>
      22             : #include <com/sun/star/sdbc/ResultSetType.hpp>
      23             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      24             : #include <com/sun/star/beans/XFastPropertySet.hpp>
      25             : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
      26             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      27             : #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
      28             : #include "FDatabaseMetaDataResultSet.hxx"
      29             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      30             : #include <comphelper/types.hxx>
      31             : 
      32             : using namespace ::comphelper;
      33             : 
      34             : using namespace connectivity;
      35             : using namespace connectivity::flat;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::beans;
      38             : using namespace ::com::sun::star::sdbcx;
      39             : using namespace ::com::sun::star::sdbc;
      40             : using namespace ::com::sun::star::container;
      41             : 
      42             : 
      43             : 
      44           0 : OFlatDatabaseMetaData::OFlatDatabaseMetaData(::connectivity::file::OConnection* _pCon)  :ODatabaseMetaData(_pCon)
      45             : {
      46             :     SAL_INFO( "connectivity.drivers", "flat Ocke.Janssen@sun.com OFlatDatabaseMetaData::OFlatDatabaseMetaData" );
      47           0 : }
      48             : 
      49           0 : OFlatDatabaseMetaData::~OFlatDatabaseMetaData()
      50             : {
      51             :     SAL_INFO( "connectivity.drivers", "flat Ocke.Janssen@sun.com OFlatDatabaseMetaData::~OFlatDatabaseMetaData" );
      52           0 : }
      53             : 
      54           0 : Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw(  )
      55             : {
      56             :     SAL_INFO( "connectivity.drivers", "flat Ocke.Janssen@sun.com OFlatDatabaseMetaData::impl_getTypeInfo_throw" );
      57           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      58             : 
      59           0 :     ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
      60           0 :     Reference< XResultSet > xRef = pResult;
      61             : 
      62           0 :     static ODatabaseMetaDataResultSet::ORows aRows;
      63           0 :     if(aRows.empty())
      64             :     {
      65           0 :         ODatabaseMetaDataResultSet::ORow aRow;
      66             : 
      67           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
      68           0 :         aRow.push_back(new ORowSetValueDecorator(OUString("CHAR")));
      69           0 :         aRow.push_back(new ORowSetValueDecorator(DataType::CHAR));
      70           0 :         aRow.push_back(new ORowSetValueDecorator((sal_Int32)254));
      71           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
      72           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue());
      73           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
      74           0 :         aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE));
      75           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
      76           0 :         aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnSearch::CHAR));
      77           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get1Value());
      78           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
      79           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
      80           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
      81           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
      82           0 :         aRow.push_back(ODatabaseMetaDataResultSet::get0Value());
      83           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
      84           0 :         aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
      85           0 :         aRow.push_back(new ORowSetValueDecorator((sal_Int32)10));
      86             : 
      87           0 :         aRows.push_back(aRow);
      88             : 
      89           0 :         aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR"));
      90           0 :         aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR);
      91           0 :         aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
      92           0 :         aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
      93           0 :         aRows.push_back(aRow);
      94             : 
      95             : 
      96           0 :         aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR"));
      97           0 :         aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR);
      98           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)65535);
      99           0 :         aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
     100           0 :         aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
     101           0 :         aRows.push_back(aRow);
     102             : 
     103           0 :         aRow[1] = new ORowSetValueDecorator(OUString("DATE"));
     104           0 :         aRow[2] = new ORowSetValueDecorator(DataType::DATE);
     105           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)10);
     106           0 :         aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
     107           0 :         aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
     108           0 :         aRows.push_back(aRow);
     109             : 
     110           0 :         aRow[1] = new ORowSetValueDecorator(OUString("TIME"));
     111           0 :         aRow[2] = new ORowSetValueDecorator(DataType::TIME);
     112           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)8);
     113           0 :         aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
     114           0 :         aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
     115           0 :         aRows.push_back(aRow);
     116             : 
     117           0 :         aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
     118           0 :         aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
     119           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)19);
     120           0 :         aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
     121           0 :         aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
     122           0 :         aRows.push_back(aRow);
     123             : 
     124           0 :         aRow[1] = new ORowSetValueDecorator(OUString("BOOL"));
     125           0 :         aRow[2] = new ORowSetValueDecorator(DataType::BIT);
     126           0 :         aRow[3] = ODatabaseMetaDataResultSet::get1Value();
     127           0 :         aRow[9] = ODatabaseMetaDataResultSet::getBasicValue();
     128           0 :         aRows.push_back(aRow);
     129             : 
     130           0 :         aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL"));
     131           0 :         aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL);
     132           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
     133           0 :         aRow[15] = new ORowSetValueDecorator((sal_Int32)15);
     134           0 :         aRows.push_back(aRow);
     135             : 
     136           0 :         aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE"));
     137           0 :         aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE);
     138           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
     139           0 :         aRow[15] = ODatabaseMetaDataResultSet::get0Value();
     140           0 :         aRows.push_back(aRow);
     141             : 
     142           0 :         aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC"));
     143           0 :         aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC);
     144           0 :         aRow[3] = new ORowSetValueDecorator((sal_Int32)20);
     145           0 :         aRow[15] = new ORowSetValueDecorator((sal_Int32)20);
     146           0 :         aRows.push_back(aRow);
     147             :     }
     148             : 
     149           0 :     pResult->setRows(aRows);
     150           0 :     return xRef;
     151             : }
     152             : 
     153           0 : Reference< XResultSet > SAL_CALL OFlatDatabaseMetaData::getColumns(
     154             :     const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern,
     155             :         const OUString& columnNamePattern ) throw(SQLException, RuntimeException, std::exception)
     156             : {
     157             :     SAL_INFO( "connectivity.drivers", "flat Ocke.Janssen@sun.com OFlatDatabaseMetaData::getColumns" );
     158           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     159             : 
     160           0 :     Reference< XTablesSupplier > xTables = m_pConnection->createCatalog();
     161           0 :     if(!xTables.is())
     162           0 :         throw SQLException();
     163             : 
     164           0 :     Reference< XNameAccess> xNames = xTables->getTables();
     165           0 :     if(!xNames.is())
     166           0 :         throw SQLException();
     167             : 
     168           0 :     ODatabaseMetaDataResultSet::ORows aRows;
     169           0 :     ODatabaseMetaDataResultSet::ORow aRow(19);
     170           0 :     aRow[10] = new ORowSetValueDecorator((sal_Int32)10);
     171           0 :     Sequence< OUString> aTabNames(xNames->getElementNames());
     172           0 :     const OUString* pTabBegin    = aTabNames.getConstArray();
     173           0 :     const OUString* pTabEnd      = pTabBegin + aTabNames.getLength();
     174           0 :     for(;pTabBegin != pTabEnd;++pTabBegin)
     175             :     {
     176           0 :         if(match(tableNamePattern,*pTabBegin,'\0'))
     177             :         {
     178             :             Reference< XColumnsSupplier> xTable(
     179           0 :                 xNames->getByName(*pTabBegin), css::uno::UNO_QUERY);
     180           0 :             aRow[3] = new ORowSetValueDecorator(*pTabBegin);
     181             : 
     182           0 :             Reference< XNameAccess> xColumns = xTable->getColumns();
     183           0 :             if(!xColumns.is())
     184           0 :                 throw SQLException();
     185             : 
     186           0 :             Sequence< OUString> aColNames(xColumns->getElementNames());
     187             : 
     188           0 :             const OUString* pBegin = aColNames.getConstArray();
     189           0 :             const OUString* pEnd = pBegin + aColNames.getLength();
     190           0 :             Reference< XPropertySet> xColumn;
     191           0 :             for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i)
     192             :             {
     193           0 :                 if(match(columnNamePattern,*pBegin,'\0'))
     194             :                 {
     195           0 :                     aRow[4] = new ORowSetValueDecorator(*pBegin);
     196             : 
     197             :                     xColumn.set(
     198           0 :                         xColumns->getByName(*pBegin), css::uno::UNO_QUERY);
     199             :                     OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!");
     200           0 :                     aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
     201           0 :                     aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))));
     202           0 :                     aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))));
     203           0 :                     aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
     204           0 :                     aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))));
     205           0 :                     aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))));
     206             : 
     207           0 :                     switch((sal_Int32)aRow[5]->getValue())
     208             :                     {
     209             :                     case DataType::CHAR:
     210             :                     case DataType::VARCHAR:
     211           0 :                         aRow[16] = new ORowSetValueDecorator((sal_Int32)254);
     212           0 :                         break;
     213             :                     case DataType::LONGVARCHAR:
     214           0 :                         aRow[16] = new ORowSetValueDecorator((sal_Int32)65535);
     215           0 :                         break;
     216             :                     default:
     217           0 :                         aRow[16] = new ORowSetValueDecorator((sal_Int32)0);
     218             :                     }
     219           0 :                     aRow[17] = new ORowSetValueDecorator(i);
     220           0 :                     switch(sal_Int32(aRow[11]->getValue()))
     221             :                     {
     222             :                     case ColumnValue::NO_NULLS:
     223           0 :                         aRow[18]  = new ORowSetValueDecorator(OUString("NO"));
     224           0 :                         break;
     225             :                     case ColumnValue::NULLABLE:
     226           0 :                         aRow[18]  = new ORowSetValueDecorator(OUString("YES"));
     227           0 :                         break;
     228             :                     default:
     229           0 :                         aRow[18]  = new ORowSetValueDecorator(OUString());
     230             :                     }
     231           0 :                     aRows.push_back(aRow);
     232             :                 }
     233           0 :             }
     234             :         }
     235             :     }
     236             : 
     237           0 :     ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
     238           0 :     Reference< XResultSet > xRef = pResult;
     239           0 :     pResult->setRows(aRows);
     240             : 
     241           0 :     return xRef;
     242             : }
     243             : 
     244           0 : OUString SAL_CALL OFlatDatabaseMetaData::getURL(  ) throw(SQLException, RuntimeException, std::exception)
     245             : {
     246             :     SAL_INFO( "connectivity.drivers", "flat Ocke.Janssen@sun.com OFlatDatabaseMetaData::getURL" );
     247           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     248           0 :     return OUString("sdbc:flat:") + m_pConnection->getURL();
     249             : }
     250             : 
     251             : 
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10