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

Generated by: LCOV version 1.11