#81418# check if file format is dbase conform

This commit is contained in:
Ocke Janssen 2000-12-08 11:55:13 +00:00
parent 46bb0dc447
commit 4b2fba1ef5
3 changed files with 93 additions and 60 deletions

View file

@ -2,9 +2,9 @@
* *
* $RCSfile: DTable.cxx,v $ * $RCSfile: DTable.cxx,v $
* *
* $Revision: 1.21 $ * $Revision: 1.22 $
* *
* last change: $Author: oj $ $Date: 2000-12-06 12:04:52 $ * last change: $Author: oj $ $Date: 2000-12-08 12:52:36 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@ -161,6 +161,7 @@ void ODbaseTable::readHeader()
((m_aHeader.db_kopf - 1) / 32 - 1) <= 0) // anzahl felder ((m_aHeader.db_kopf - 1) / 32 - 1) <= 0) // anzahl felder
{ {
// Dies ist keine DBase Datei // Dies ist keine DBase Datei
m_bValid = sal_False;
} }
else else
{ {
@ -177,6 +178,7 @@ void ODbaseTable::readHeader()
case dBaseIIIMemo: case dBaseIIIMemo:
case dBaseIVMemo: case dBaseIVMemo:
case FoxProMemo: case FoxProMemo:
m_bValid = sal_True;
m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
break; break;
default: default:
@ -192,13 +194,13 @@ void ODbaseTable::fillColumns()
m_pFileStream->Seek(32L); m_pFileStream->Seek(32L);
// Anzahl Felder: // Anzahl Felder:
sal_uInt32 nFieldCount = (m_aHeader.db_kopf - 1) / 32 - 1; sal_Int32 nFieldCount = (m_aHeader.db_kopf - 1) / 32 - 1;
String aStrFieldName;aStrFieldName.AssignAscii("Column"); String aStrFieldName;aStrFieldName.AssignAscii("Column");
sal_Int32 nFieldCnt = 0; sal_Int32 nFieldCnt = 0;
::rtl::OUString aTypeName; ::rtl::OUString aTypeName;
for (sal_uInt32 i = 0; i < nFieldCount; i++) for (sal_Int32 i = 0; i < nFieldCount; i++)
{ {
DBFColumn aDBFColumn; DBFColumn aDBFColumn;
m_pFileStream->Read((char*)&aDBFColumn, sizeof(aDBFColumn)); m_pFileStream->Read((char*)&aDBFColumn, sizeof(aDBFColumn));
@ -273,7 +275,7 @@ void ODbaseTable::fillColumns()
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection) : ODbaseTable_BASE(_pConnection) ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection) : ODbaseTable_BASE(_pConnection),m_pMemoStream(NULL),m_bWriteableMemo(sal_False),m_bValid(sal_False)
{ {
// initialize the header // initialize the header
m_aHeader.db_typ = dBaseIII; m_aHeader.db_typ = dBaseIII;
@ -294,6 +296,8 @@ ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection,
_SchemaName, _SchemaName,
_CatalogName) _CatalogName)
,m_pMemoStream(NULL) ,m_pMemoStream(NULL)
,m_bWriteableMemo(sal_False)
,m_bValid(sal_False)
{ {
// initialize the header // initialize the header
m_aHeader.db_typ = dBaseIII; m_aHeader.db_typ = dBaseIII;
@ -318,53 +322,58 @@ ODbaseTable::ODbaseTable(ODbaseConnection* _pConnection,
if(m_pFileStream) if(m_pFileStream)
{ {
readHeader(); readHeader();
if(isValid())
if (HasMemoFields())
{ {
// Memo-Dateinamen bilden (.DBT):
// nyi: Unschoen fuer Unix und Mac!
if (m_aHeader.db_typ == FoxProMemo) // foxpro verwendet andere extension if (HasMemoFields())
aURL.SetExtension(String::CreateFromAscii("fpt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener. {
else // Memo-Dateinamen bilden (.DBT):
aURL.SetExtension(String::CreateFromAscii("dbt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener. // nyi: Unschoen fuer Unix und Mac!
// Wenn die Memodatei nicht gefunden wird, werden die Daten trotzdem angezeigt if (m_aHeader.db_typ == FoxProMemo) // foxpro verwendet andere extension
// allerdings koennen keine Updates durchgefuehrt werden aURL.SetExtension(String::CreateFromAscii("fpt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener.
// jedoch die Operation wird ausgefuehrt else
m_pMemoStream = ::utl::UcbStreamHelper::CreateStream( aURL.GetURLNoPass(), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); aURL.SetExtension(String::CreateFromAscii("dbt")); // nyi: Gross-/Kleinschreibung bei Unix? Klein ist sicherlich schoener.
if (m_pMemoStream)
ReadMemoHeader();
}
fillColumns();
m_pFileStream->Seek(STREAM_SEEK_TO_END); // Wenn die Memodatei nicht gefunden wird, werden die Daten trotzdem angezeigt
UINT32 nFileSize = m_pFileStream->Tell(); // allerdings koennen keine Updates durchgefuehrt werden
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); // jedoch die Operation wird ausgefuehrt
m_pMemoStream = ::utl::UcbStreamHelper::CreateStream( aURL.GetURLNoPass(), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE);
if (m_bWriteableMemo = !m_pMemoStream)
m_pMemoStream = ::utl::UcbStreamHelper::CreateStream( aFileName,STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE );
if (m_pMemoStream)
ReadMemoHeader();
}
fillColumns();
// Buffersize abhaengig von der Filegroesse m_pFileStream->Seek(STREAM_SEEK_TO_END);
m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : UINT32 nFileSize = m_pFileStream->Tell();
nFileSize > 100000 ? 16384 : m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
nFileSize > 10000 ? 4096 : 1024);
if (m_pMemoStream)
{
// Puffer genau auf Laenge eines Satzes stellen
m_pMemoStream->Seek(STREAM_SEEK_TO_END);
nFileSize = m_pMemoStream->Tell();
m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN);
// Buffersize abhaengig von der Filegroesse // Buffersize abhaengig von der Filegroesse
m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 :
nFileSize > 100000 ? 16384 : nFileSize > 100000 ? 16384 :
nFileSize > 10000 ? 4096 : nFileSize > 10000 ? 4096 : 1024);
m_aMemoHeader.db_size);
if (m_pMemoStream)
{
// Puffer genau auf Laenge eines Satzes stellen
m_pMemoStream->Seek(STREAM_SEEK_TO_END);
nFileSize = m_pMemoStream->Tell();
m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN);
// Buffersize abhaengig von der Filegroesse
m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 :
nFileSize > 100000 ? 16384 :
nFileSize > 10000 ? 4096 :
m_aMemoHeader.db_size);
}
AllocBuffer();
refreshColumns();
refreshIndexes();
} }
AllocBuffer();
refreshColumns();
refreshIndexes();
} }
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
@ -477,10 +486,16 @@ void ODbaseTable::refreshIndexes()
{ {
aIndexName = aInfFile.ReadKey(aKeyName); aIndexName = aInfFile.ReadKey(aKeyName);
aURL.setName(String(aIndexName,getConnection()->getTextEncoding())); aURL.setName(String(aIndexName,getConnection()->getTextEncoding()));
Content aCnt(aURL.GetURLNoPass(),Reference<XCommandEnvironment>()); try
if (aCnt.isDocument()) {
Content aCnt(aURL.GetURLNoPass(),Reference<XCommandEnvironment>());
if (aCnt.isDocument())
{
aVector.push_back(aURL.getBase());
}
}
catch(Exception&) // a execption is thrown when no file exists
{ {
aVector.push_back(aURL.getBase());
} }
} }
} }
@ -948,18 +963,23 @@ BOOL ODbaseTable::CreateImpl()
aURL.setExtension(m_pConnection->getExtension()); aURL.setExtension(m_pConnection->getExtension());
Content aContent(aURL.GetURLNoPass(),Reference<XCommandEnvironment>()); Content aContent(aURL.GetURLNoPass(),Reference<XCommandEnvironment>());
try
if (aContent.isDocument())
{ {
// Hack fuer Bug #30609 , nur wenn das File existiert und die Laenge > 0 gibt es einen Fehler if (aContent.isDocument())
SvStream* pFileStream = ::utl::UcbStreamHelper::CreateStream( aURL.GetURLNoPass(),STREAM_READ);
if (pFileStream && pFileStream->Seek(STREAM_SEEK_TO_END))
{ {
// aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,TABLE,aFile.GetFull()); // Hack fuer Bug #30609 , nur wenn das File existiert und die Laenge > 0 gibt es einen Fehler
return sal_False; SvStream* pFileStream = ::utl::UcbStreamHelper::CreateStream( aURL.GetURLNoPass(),STREAM_READ);
if (pFileStream && pFileStream->Seek(STREAM_SEEK_TO_END))
{
// aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,TABLE,aFile.GetFull());
return sal_False;
}
delete pFileStream;
} }
delete pFileStream; }
catch(Exception&) // a execption is thrown when no file exists
{
} }
BOOL bMemoFile = sal_False; BOOL bMemoFile = sal_False;

View file

@ -2,9 +2,9 @@
* *
* $RCSfile: DTables.cxx,v $ * $RCSfile: DTables.cxx,v $
* *
* $Revision: 1.5 $ * $Revision: 1.6 $
* *
* last change: $Author: oj $ $Date: 2000-11-03 14:17:57 $ * last change: $Author: oj $ $Date: 2000-12-08 12:55:13 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@ -96,6 +96,11 @@
#ifndef _CONNECTIVITY_PROPERTYIDS_HXX_ #ifndef _CONNECTIVITY_PROPERTYIDS_HXX_
#include "propertyids.hxx" #include "propertyids.hxx"
#endif #endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
using namespace connectivity::dbase; using namespace connectivity::dbase;
using namespace connectivity::file; using namespace connectivity::file;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
@ -113,6 +118,11 @@ Reference< XNamed > ODbaseTables::createObject(const ::rtl::OUString& _rName)
_rName,::rtl::OUString::createFromAscii("TABLE")); _rName,::rtl::OUString::createFromAscii("TABLE"));
Reference< XNamed > xRet = pRet; Reference< XNamed > xRet = pRet;
if(!pRet->isValid())
{
::comphelper::disposeComponent(xRet);
throw SQLException(::rtl::OUString::createFromAscii("Invalid DBase file found!"),m_rParent,_rName,1000,Any());
}
return xRet; return xRet;
} }

View file

@ -2,9 +2,9 @@
* *
* $RCSfile: DTable.hxx,v $ * $RCSfile: DTable.hxx,v $
* *
* $Revision: 1.9 $ * $Revision: 1.10 $
* *
* last change: $Author: oj $ $Date: 2000-11-27 10:28:51 $ * last change: $Author: oj $ $Date: 2000-12-08 12:54:30 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@ -136,6 +136,8 @@ namespace connectivity
DBFHeader m_aHeader; DBFHeader m_aHeader;
DBFMemoHeader m_aMemoHeader; DBFMemoHeader m_aMemoHeader;
SvStream* m_pMemoStream; SvStream* m_pMemoStream;
sal_Bool m_bWriteableMemo;
sal_Bool m_bValid; // set to false when this isn't a correct dbase table
void readHeader(); void readHeader();
void fillColumns(); void fillColumns();
@ -184,6 +186,7 @@ namespace connectivity
BOOL DropImpl(); BOOL DropImpl();
BOOL CreateImpl(); BOOL CreateImpl();
String getEntry(); String getEntry();
sal_Bool isValid() { return m_bValid; }
virtual BOOL InsertRow(file::OValueVector& rRow, BOOL bFlush,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols); virtual BOOL InsertRow(file::OValueVector& rRow, BOOL bFlush,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols);
virtual BOOL DeleteRow(const OSQLColumns& _rCols); virtual BOOL DeleteRow(const OSQLColumns& _rCols);