LCOV - code coverage report
Current view: top level - connectivity/source/drivers/flat - EDatabaseMetaData.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 140 0.0 %
Date: 2012-08-25 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10