1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
23 #include "file/FTable.hxx"
24 #include <connectivity/sdbcx/VColumn.hxx>
25 #include <connectivity/CommonTools.hxx>
26 #include <tools/urlobj.hxx>
29 namespace connectivity
33 typedef file::OFileTable ODbaseTable_BASE
;
34 class ODbaseConnection
;
36 class ODbaseTable
: public ODbaseTable_BASE
38 // The first byte of a dBase file specifies its type
40 enum DBFType
{ dBaseIII
= 0x03,
44 VisualFoxProAuto
= 0x31, // Visual FoxPro with AutoIncrement field
49 dBaseIVMemoSQL
= 0x8E,
52 enum DBFMemoType
{ MemodBaseIII
= 0,
58 struct DBFHeader
{ /* Header struct */
59 DBFType db_typ
; /* File type */
60 sal_uInt8 db_aedat
[3]; /* Date of last change */
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 */
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 */
77 DBFMemoType db_typ
; /* File type */
78 sal_uInt32 db_next
; /* Next free block */
79 sal_uInt16 db_size
; /* Block size: dBase 3 fixed */
81 : db_typ(MemodBaseIII
)
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
;
93 DBFMemoHeader m_aMemoHeader
;
94 SvStream
* m_pMemoStream
;
95 rtl_TextEncoding m_eEncoding
;
96 bool m_bWriteableMemo
;
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
);
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 bool HasMemoFields() const { return m_aHeader
.db_typ
> dBaseIV
;}
108 bool ReadMemoHeader();
109 bool ReadMemo(sal_Size nBlockNo
, ORowSetValue
& aVariable
);
111 bool WriteMemo(const ORowSetValue
& aVariable
, sal_Size
& rBlockNr
);
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
);
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
);
122 virtual void FileClose() SAL_OVERRIDE
;
123 // using ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper;
126 virtual void refreshColumns() SAL_OVERRIDE
;
127 virtual void refreshIndexes() SAL_OVERRIDE
;
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()
139 void construct() SAL_OVERRIDE
; // can throw any exception
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
;
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
;
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
;
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();
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
;
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
;
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
;
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
;
170 static OUString
getEntry(file::OConnection
* _pConnection
,const OUString
& _sURL
);
171 static bool Drop_Static(const OUString
& _sUrl
, bool _bHasMemoFields
, sdbcx::OCollection
* _pIndexes
);
173 virtual void refreshHeader() SAL_OVERRIDE
;
175 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> getMetaData() const SAL_OVERRIDE
;
179 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DTABLE_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */