LCOV - code coverage report
Current view: top level - connectivity/source/inc/dbase - DTable.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 5 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.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             : #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
      21             : #define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
      22             : 
      23             : #include "file/FTable.hxx"
      24             : #include <connectivity/sdbcx/VColumn.hxx>
      25             : #include <connectivity/CommonTools.hxx>
      26             : #include <tools/urlobj.hxx>
      27             : 
      28             : 
      29             : namespace connectivity
      30             : {
      31             :     namespace dbase
      32             :     {
      33             :         typedef file::OFileTable ODbaseTable_BASE;
      34             :         class ODbaseConnection;
      35             : 
      36          30 :         class ODbaseTable : public ODbaseTable_BASE
      37             :         {
      38             :         // The first byte of a dBase file specifies its type
      39             :         public:
      40             :             enum DBFType  { dBaseIII         = 0x03,
      41             :                             dBaseIV          = 0x04,
      42             :                             dBaseV           = 0x05,
      43             :                             VisualFoxPro     = 0x30,
      44             :                             VisualFoxProAuto = 0x31, // Visual FoxPro with AutoIncrement field
      45             :                             dBaseFS          = 0x43,
      46             :                             dBaseFSMemo      = 0xB3,
      47             :                             dBaseIIIMemo     = 0x83,
      48             :                             dBaseIVMemo      = 0x8B,
      49             :                             dBaseIVMemoSQL   = 0x8E,
      50             :                             FoxProMemo       = 0xF5
      51             :                           };
      52             :             enum DBFMemoType {  MemodBaseIII = 0,
      53             :                                 MemodBaseIV,
      54             :                                 MemoFoxPro
      55             :                             };
      56             : 
      57             :         private:
      58             :             struct DBFHeader {                       /* Header struct */
      59             :                                 DBFType      db_typ;                        /* File type                    */
      60             :                                 sal_uInt8    db_aedat[3];                   /* Date of last change          */
      61             :                                                                             /* YY MM DD                     */
      62             :                                 sal_uInt32  db_anz;                         /* Data set count               */
      63             :                                 sal_uInt16  db_kopf;                        /* Header length                */
      64             :                                 sal_uInt16  db_slng;                        /* Data set length              */
      65             :                                 sal_uInt8   db_frei[20];                    /* Reserved                     */
      66             :                             };
      67             :             struct DBFColumn {                       /* Column descriptors */
      68             :                                 sal_uInt8    db_fnm[11];                     /* Field name                  */
      69             :                                 sal_uInt8    db_typ;                         /* Field type                  */
      70             :                                 sal_uInt32   db_adr;                         /* Field address               */
      71             :                                 sal_uInt8    db_flng;                        /* Field length                */
      72             :                                 sal_uInt8    db_dez;                         /* Decimal places for N        */
      73             :                                 sal_uInt8    db_frei2[14];                   /* Reserved                    */
      74             :                             };
      75             :             struct DBFMemoHeader
      76             :             {
      77             :                 DBFMemoType db_typ;                         /* File type                    */
      78             :                 sal_uInt32  db_next;                        /* Next free block              */
      79             :                 sal_uInt16  db_size;                        /* Block size: dBase 3 fixed    */
      80          15 :                 DBFMemoHeader()
      81             :                     : db_typ(MemodBaseIII)
      82             :                     , db_next(0)
      83          15 :                     , db_size(0)
      84             :                 {
      85          15 :                 }
      86             :             };
      87             : 
      88             :             ::std::vector<sal_Int32> m_aTypes;      // holds all types for columns just to avoid to ask the propertyset
      89             :             ::std::vector<sal_Int32> m_aPrecisions; // same as above
      90             :             ::std::vector<sal_Int32> m_aScales;
      91             :             ::std::vector<sal_Int32> m_aRealFieldLengths;
      92             :             DBFHeader       m_aHeader;
      93             :             DBFMemoHeader   m_aMemoHeader;
      94             :             SvStream*       m_pMemoStream;
      95             :             rtl_TextEncoding m_eEncoding;
      96             :             bool        m_bWriteableMemo;
      97             : 
      98             :             void alterColumn(sal_Int32 index,
      99             :                              const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& descriptor ,
     100             :                              const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XDataDescriptorFactory>& xOldColumn );
     101             :             void readHeader();
     102             :             void fillColumns();
     103             :             OUString createTempFile();
     104             :             void copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos);
     105             :             bool CreateFile(const INetURLObject& aFile, bool& bCreateMemo);
     106             :             bool CreateMemoFile(const INetURLObject& aFile);
     107          20 :             bool HasMemoFields() const { return m_aHeader.db_typ > dBaseIV;}
     108             :             bool ReadMemoHeader();
     109             :             bool ReadMemo(sal_Size nBlockNo, ORowSetValue& aVariable);
     110             : 
     111             :             bool WriteMemo(const ORowSetValue& aVariable, sal_Size& rBlockNr);
     112             :             bool WriteBuffer();
     113             :             bool UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols, bool bForceAllFields);
     114             :             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos);
     115             :             bool AllocBuffer();
     116             : 
     117             :             void throwInvalidDbaseFormat();
     118             :             void SAL_CALL renameImpl( const OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
     119             :             void throwInvalidColumnType(const sal_uInt16 _nErrorId,const OUString& _sColumnName);
     120             : 
     121             :         protected:
     122             :             virtual void FileClose() SAL_OVERRIDE;
     123             : //          using ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper;
     124             : 
     125             :         public:
     126             :             virtual void refreshColumns() SAL_OVERRIDE;
     127             :             virtual void refreshIndexes() SAL_OVERRIDE;
     128             : 
     129             :         public:
     130             :             ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection);
     131             :             ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection,
     132             :                     const OUString& _Name,
     133             :                     const OUString& _Type,
     134             :                     const OUString& _Description = OUString(),
     135             :                     const OUString& _SchemaName = OUString(),
     136             :                     const OUString& _CatalogName = OUString()
     137             :                 );
     138             : 
     139             :             void construct() SAL_OVERRIDE; // can throw any exception
     140             : 
     141             :             virtual sal_Int32 getCurrentLastPos() const SAL_OVERRIDE;
     142             :             virtual bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) SAL_OVERRIDE;
     143             :             virtual bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, bool _bUseTableDefs, bool bRetrieveData) SAL_OVERRIDE;
     144             : 
     145             :             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             :             //XTypeProvider
     147             :             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     148             :             virtual void SAL_CALL disposing() SAL_OVERRIDE;
     149             : 
     150             :             // com::sun::star::lang::XUnoTunnel
     151             :             virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     152             :             static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
     153             :             // XAlterTable
     154             :             virtual void SAL_CALL alterColumnByName( const OUString& colName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     155             :             virtual void SAL_CALL alterColumnByIndex( sal_Int32 index, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     156             :             // XRename
     157             :             virtual void SAL_CALL rename( const OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     158             : 
     159             :             bool    DropImpl();
     160             :             bool    CreateImpl();
     161             : 
     162             : 
     163             :             virtual bool InsertRow(OValueRefVector& rRow, bool bFlush, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols) SAL_OVERRIDE;
     164             :             virtual bool DeleteRow(const OSQLColumns& _rCols) SAL_OVERRIDE;
     165             :             virtual bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols) SAL_OVERRIDE;
     166             : 
     167             :             virtual void addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& descriptor) SAL_OVERRIDE;
     168             :             virtual void dropColumn(sal_Int32 _nPos) SAL_OVERRIDE;
     169             : 
     170             :             static OUString   getEntry(file::OConnection* _pConnection,const OUString& _sURL );
     171             :             static bool     Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, sdbcx::OCollection* _pIndexes );
     172             : 
     173             :             virtual void refreshHeader() SAL_OVERRIDE;
     174             : 
     175             :             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData() const SAL_OVERRIDE;
     176             :         };
     177             :     }
     178             : }
     179             : #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11