1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBASE_TABLE_HXX_ 29*cdf0e10cSrcweir #define _CONNECTIVITY_DBASE_TABLE_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "file/FTable.hxx" 32*cdf0e10cSrcweir #include "connectivity/sdbcx/VColumn.hxx" 33*cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 34*cdf0e10cSrcweir #include <tools/urlobj.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir namespace connectivity 38*cdf0e10cSrcweir { 39*cdf0e10cSrcweir namespace dbase 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir typedef file::OFileTable ODbaseTable_BASE; 42*cdf0e10cSrcweir class ODbaseConnection; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir typedef ::std::map< ::rtl::OUString, 45*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNamed>, comphelper::UStringMixLess > OContainer; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir class ODbaseTable : public ODbaseTable_BASE 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir // der Typ einer dBase datei wird mit dem ersten Byte bestimmt 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir enum DBFType { dBaseIII = 0x03, 52*cdf0e10cSrcweir dBaseIV = 0x04, 53*cdf0e10cSrcweir dBaseV = 0x05, 54*cdf0e10cSrcweir VisualFoxPro = 0x30, 55*cdf0e10cSrcweir VisualFoxProAuto = 0x31, // Visual FoxPro w. AutoIncrement field 56*cdf0e10cSrcweir dBaseFS = 0x43, 57*cdf0e10cSrcweir dBaseFSMemo = 0xB3, 58*cdf0e10cSrcweir dBaseIIIMemo = 0x83, 59*cdf0e10cSrcweir dBaseIVMemo = 0x8B, 60*cdf0e10cSrcweir dBaseIVMemoSQL = 0x8E, 61*cdf0e10cSrcweir FoxProMemo = 0xF5 62*cdf0e10cSrcweir }; 63*cdf0e10cSrcweir enum DBFMemoType { MemodBaseIII = 0, 64*cdf0e10cSrcweir MemodBaseIV, 65*cdf0e10cSrcweir MemoFoxPro 66*cdf0e10cSrcweir }; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir private: 69*cdf0e10cSrcweir struct DBFHeader { /* Kopfsatz-Struktur */ 70*cdf0e10cSrcweir DBFType db_typ; /* Dateityp */ 71*cdf0e10cSrcweir sal_uInt8 db_aedat[3]; /* Datum der letzen Aenderung */ 72*cdf0e10cSrcweir /* JJ MM TT */ 73*cdf0e10cSrcweir sal_uInt32 db_anz; /* Anzahl der Saetze */ 74*cdf0e10cSrcweir sal_uInt16 db_kopf; /* laenge Kopfsatz-Struktur */ 75*cdf0e10cSrcweir sal_uInt16 db_slng; /* laenge der Daten-Saetze */ 76*cdf0e10cSrcweir sal_uInt8 db_frei[20]; /* reserviert */ 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir struct DBFColumn { /* Feldbezeichner */ 79*cdf0e10cSrcweir sal_uInt8 db_fnm[11]; /* Feldname */ 80*cdf0e10cSrcweir sal_uInt8 db_typ; /* Feldtyp */ 81*cdf0e10cSrcweir sal_uInt32 db_adr; /* Feldadresse */ 82*cdf0e10cSrcweir sal_uInt8 db_flng; /* Feldlaenge */ 83*cdf0e10cSrcweir sal_uInt8 db_dez; /* Dezimalstellen fuer N */ 84*cdf0e10cSrcweir sal_uInt8 db_frei2[14]; /* reserviert */ 85*cdf0e10cSrcweir }; 86*cdf0e10cSrcweir struct DBFMemoHeader 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir DBFMemoType db_typ; /* Dateityp */ 89*cdf0e10cSrcweir sal_uInt32 db_next; /* naechster freier Block */ 90*cdf0e10cSrcweir sal_uInt16 db_size; /* Blockgroesse: dBase 3 fest */ 91*cdf0e10cSrcweir }; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aTypes; // holds all type for columns just to avoid to ask the propertyset 94*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aPrecisions; // same as aboth 95*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aScales; 96*cdf0e10cSrcweir ::std::vector<sal_Int32> m_aRealFieldLengths; 97*cdf0e10cSrcweir DBFHeader m_aHeader; 98*cdf0e10cSrcweir DBFMemoHeader m_aMemoHeader; 99*cdf0e10cSrcweir SvStream* m_pMemoStream; 100*cdf0e10cSrcweir rtl_TextEncoding m_eEncoding; 101*cdf0e10cSrcweir sal_Bool m_bWriteableMemo; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void alterColumn(sal_Int32 index, 104*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& descriptor , 105*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XDataDescriptorFactory>& xOldColumn ); 106*cdf0e10cSrcweir void readHeader(); 107*cdf0e10cSrcweir void fillColumns(); 108*cdf0e10cSrcweir String createTempFile(); 109*cdf0e10cSrcweir void copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos); 110*cdf0e10cSrcweir sal_Bool CreateFile(const INetURLObject& aFile, sal_Bool& bCreateMemo); 111*cdf0e10cSrcweir sal_Bool CreateMemoFile(const INetURLObject& aFile); 112*cdf0e10cSrcweir sal_Bool HasMemoFields() const { return m_aHeader.db_typ > dBaseIV;} 113*cdf0e10cSrcweir sal_Bool ReadMemoHeader(); 114*cdf0e10cSrcweir sal_Bool ReadMemo(sal_uIntPtr nBlockNo, ORowSetValue& aVariable); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir sal_Bool WriteMemo(ORowSetValue& aVariable, sal_uIntPtr& rBlockNr); 117*cdf0e10cSrcweir sal_Bool WriteBuffer(); 118*cdf0e10cSrcweir sal_Bool UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols); 119*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos); 120*cdf0e10cSrcweir void AllocBuffer(); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void throwInvalidDbaseFormat(); 123*cdf0e10cSrcweir void SAL_CALL renameImpl( const ::rtl::OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 124*cdf0e10cSrcweir void throwInvalidColumnType(const sal_uInt16 _nErrorId,const ::rtl::OUString& _sColumnName); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir protected: 127*cdf0e10cSrcweir virtual void FileClose(); 128*cdf0e10cSrcweir // using ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir public: 131*cdf0e10cSrcweir virtual void refreshColumns(); 132*cdf0e10cSrcweir virtual void refreshIndexes(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir public: 135*cdf0e10cSrcweir ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection); 136*cdf0e10cSrcweir ODbaseTable( sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection, 137*cdf0e10cSrcweir const ::rtl::OUString& _Name, 138*cdf0e10cSrcweir const ::rtl::OUString& _Type, 139*cdf0e10cSrcweir const ::rtl::OUString& _Description = ::rtl::OUString(), 140*cdf0e10cSrcweir const ::rtl::OUString& _SchemaName = ::rtl::OUString(), 141*cdf0e10cSrcweir const ::rtl::OUString& _CatalogName = ::rtl::OUString() 142*cdf0e10cSrcweir ); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void construct(); // can throw any exception 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir virtual sal_Int32 getCurrentLastPos() const; 147*cdf0e10cSrcweir virtual sal_Bool seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos); 148*cdf0e10cSrcweir virtual sal_Bool fetchRow(OValueRefRow& _rRow,const OSQLColumns& _rCols, sal_Bool _bUseTableDefs,sal_Bool bRetrieveData); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); 151*cdf0e10cSrcweir //XTypeProvider 152*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); 153*cdf0e10cSrcweir virtual void SAL_CALL disposing(void); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel 156*cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); 157*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); 158*cdf0e10cSrcweir // XAlterTable 159*cdf0e10cSrcweir virtual void SAL_CALL alterColumnByName( const ::rtl::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); 160*cdf0e10cSrcweir 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); 161*cdf0e10cSrcweir // XRename 162*cdf0e10cSrcweir virtual void SAL_CALL rename( const ::rtl::OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir sal_Bool DropImpl(); 165*cdf0e10cSrcweir sal_Bool CreateImpl(); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir virtual sal_Bool InsertRow(OValueRefVector& rRow, sal_Bool bFlush,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols); 169*cdf0e10cSrcweir virtual sal_Bool DeleteRow(const OSQLColumns& _rCols); 170*cdf0e10cSrcweir virtual sal_Bool UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir virtual void addColumn(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& descriptor); 173*cdf0e10cSrcweir virtual void dropColumn(sal_Int32 _nPos); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir static String getEntry(file::OConnection* _pConnection,const ::rtl::OUString& _sURL ); 176*cdf0e10cSrcweir static sal_Bool Drop_Static(const ::rtl::OUString& _sUrl,sal_Bool _bHasMemoFields,sdbcx::OCollection* _pIndexes ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir virtual void refreshHeader(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> getMetaData() const; 181*cdf0e10cSrcweir }; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir #endif // _CONNECTIVITY_DBASE_TABLE_HXX_ 185*cdf0e10cSrcweir 186