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