2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* $RCSfile: DTable.cxx,v $
|
2008-10-01 12:28:29 +00:00
|
|
|
* $Revision: 1.107.30.2 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 07:37:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 01:23:49 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_connectivity.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "dbase/DTable.hxx"
|
|
|
|
#include <com/sun/star/sdbc/ColumnValue.hpp>
|
|
|
|
#include <com/sun/star/sdbc/DataType.hpp>
|
|
|
|
#include <com/sun/star/ucb/XContentAccess.hpp>
|
|
|
|
#include <com/sun/star/sdbc/XRow.hpp>
|
|
|
|
#include <svtools/converter.hxx>
|
|
|
|
#include "dbase/DConnection.hxx"
|
|
|
|
#include "dbase/DColumns.hxx"
|
|
|
|
#include <osl/thread.h>
|
2004-01-06 16:04:51 +00:00
|
|
|
#include <tools/config.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "dbase/DIndex.hxx"
|
|
|
|
#include "dbase/DIndexes.hxx"
|
2000-10-09 11:34:19 +00:00
|
|
|
#include <comphelper/sequence.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <svtools/zforlist.hxx>
|
2003-03-19 15:38:50 +00:00
|
|
|
#include <rtl/math.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <stdio.h> //sprintf
|
|
|
|
#include <ucbhelper/content.hxx>
|
2001-03-15 07:47:25 +00:00
|
|
|
#include <comphelper/extract.hxx>
|
2000-12-10 18:25:56 +00:00
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
#include <connectivity/dbconversion.hxx>
|
2001-03-28 10:32:43 +00:00
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
|
|
|
#include <comphelper/property.hxx>
|
|
|
|
#include <unotools/tempfile.hxx>
|
2001-05-28 12:03:37 +00:00
|
|
|
#include <unotools/ucbhelper.hxx>
|
2001-03-28 10:32:43 +00:00
|
|
|
#include <comphelper/types.hxx>
|
2007-01-25 10:00:45 +00:00
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
2001-05-28 12:03:37 +00:00
|
|
|
#include "connectivity/PColumn.hxx"
|
2002-11-29 11:50:57 +00:00
|
|
|
#include "connectivity/dbtools.hxx"
|
2003-09-04 07:24:07 +00:00
|
|
|
#include "connectivity/FValue.hxx"
|
2004-11-17 13:05:48 +00:00
|
|
|
#include "connectivity/dbconversion.hxx"
|
2008-10-01 12:28:29 +00:00
|
|
|
#include "resource/dbase_res.hrc"
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-10-12 14:21:00 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2001-05-18 07:51:34 +00:00
|
|
|
using namespace ::comphelper;
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace connectivity;
|
2001-03-30 11:46:36 +00:00
|
|
|
using namespace connectivity::sdbcx;
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace connectivity::dbase;
|
|
|
|
using namespace connectivity::file;
|
2007-06-05 13:21:31 +00:00
|
|
|
using namespace ::ucbhelper;
|
2001-03-28 10:32:43 +00:00
|
|
|
using namespace ::utl;
|
2000-12-10 18:25:56 +00:00
|
|
|
using namespace ::cppu;
|
|
|
|
using namespace ::dbtools;
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::ucb;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
// stored as the Field Descriptor terminator
|
|
|
|
#define FIELD_DESCRIPTOR_TERMINATOR 0x0D
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::readHeader()
|
|
|
|
{
|
2001-09-19 10:03:04 +00:00
|
|
|
OSL_ENSURE(m_pFileStream,"No Stream available!");
|
|
|
|
if(!m_pFileStream)
|
|
|
|
return;
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->RefreshBuffer(); // sicherstellen, dass die Kopfinformationen tatsaechlich neu gelesen werden
|
|
|
|
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-08-02 06:59:15 +00:00
|
|
|
BYTE nType=0;
|
2000-12-10 18:25:56 +00:00
|
|
|
(*m_pFileStream) >> nType;
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
|
|
|
|
2000-12-10 18:25:56 +00:00
|
|
|
m_pFileStream->Read((char*)(&m_aHeader.db_aedat), 3*sizeof(BYTE));
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pFileStream) >> m_aHeader.db_anz;
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pFileStream) >> m_aHeader.db_kopf;
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pFileStream) >> m_aHeader.db_slng;
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
2000-12-10 18:25:56 +00:00
|
|
|
m_pFileStream->Read((char*)(&m_aHeader.db_frei), 20*sizeof(BYTE));
|
2001-08-02 06:59:15 +00:00
|
|
|
if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
|
|
|
|
throwInvalidDbaseFormat();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
if ( ( ( m_aHeader.db_kopf - 1 ) / 32 - 1 ) <= 0 ) // anzahl felder
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-12-10 18:25:56 +00:00
|
|
|
// no dbase file
|
2001-08-02 06:59:15 +00:00
|
|
|
throwInvalidDbaseFormat();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Konsistenzpruefung des Header:
|
2000-12-10 18:25:56 +00:00
|
|
|
m_aHeader.db_typ = (DBFType)nType;
|
2000-09-18 15:18:56 +00:00
|
|
|
switch (m_aHeader.db_typ)
|
|
|
|
{
|
|
|
|
case dBaseIII:
|
|
|
|
case dBaseIV:
|
|
|
|
case dBaseV:
|
2008-06-06 12:20:24 +00:00
|
|
|
case VisualFoxPro:
|
2000-09-18 15:18:56 +00:00
|
|
|
case dBaseFS:
|
|
|
|
case dBaseFSMemo:
|
|
|
|
case dBaseIVMemoSQL:
|
|
|
|
case dBaseIIIMemo:
|
|
|
|
case FoxProMemo:
|
2008-06-06 12:20:24 +00:00
|
|
|
m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
|
|
|
|
if ( m_aHeader.db_frei[17] != 0x00
|
|
|
|
&& !m_aHeader.db_frei[18] && !m_aHeader.db_frei[19] && getConnection()->isTextEncodingDefaulted() )
|
|
|
|
{
|
|
|
|
switch(m_aHeader.db_frei[17])
|
|
|
|
{
|
|
|
|
case 0x01: m_eEncoding = RTL_TEXTENCODING_IBM_437; break; // DOS USA code page 437
|
|
|
|
case 0x02: m_eEncoding = RTL_TEXTENCODING_IBM_850; break; // DOS Multilingual code page 850
|
|
|
|
case 0x03: m_eEncoding = RTL_TEXTENCODING_MS_1252; break; // Windows ANSI code page 1252
|
|
|
|
case 0x04: m_eEncoding = RTL_TEXTENCODING_APPLE_ROMAN; break; // Standard Macintosh
|
|
|
|
case 0x64: m_eEncoding = RTL_TEXTENCODING_IBM_852; break; // EE MS-DOS code page 852
|
|
|
|
case 0x65: m_eEncoding = RTL_TEXTENCODING_IBM_865; break; // Nordic MS-DOS code page 865
|
|
|
|
case 0x66: m_eEncoding = RTL_TEXTENCODING_IBM_866; break; // Russian MS-DOS code page 866
|
|
|
|
case 0x67: m_eEncoding = RTL_TEXTENCODING_IBM_861; break; // Icelandic MS-DOS
|
|
|
|
//case 0x68: m_eEncoding = ; break; // Kamenicky (Czech) MS-DOS
|
|
|
|
//case 0x69: m_eEncoding = ; break; // Mazovia (Polish) MS-DOS
|
|
|
|
case 0x6A: m_eEncoding = RTL_TEXTENCODING_IBM_737; break; // Greek MS-DOS (437G)
|
|
|
|
case 0x6B: m_eEncoding = RTL_TEXTENCODING_IBM_857; break; // Turkish MS-DOS
|
|
|
|
case 0x96: m_eEncoding = RTL_TEXTENCODING_APPLE_CYRILLIC; break; // Russian Macintosh
|
|
|
|
case 0x97: m_eEncoding = RTL_TEXTENCODING_APPLE_CENTEURO; break; // Eastern European Macintosh
|
|
|
|
case 0x98: m_eEncoding = RTL_TEXTENCODING_APPLE_GREEK; break; // Greek Macintosh
|
|
|
|
case 0xC8: m_eEncoding = RTL_TEXTENCODING_MS_1250; break; // Windows EE code page 1250
|
|
|
|
case 0xC9: m_eEncoding = RTL_TEXTENCODING_MS_1251; break; // Russian Windows
|
|
|
|
case 0xCA: m_eEncoding = RTL_TEXTENCODING_MS_1254; break; // Turkish Windows
|
|
|
|
case 0xCB: m_eEncoding = RTL_TEXTENCODING_MS_1253; break; // Greek Windows
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dBaseIVMemo:
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-12-10 18:25:56 +00:00
|
|
|
{
|
2001-08-02 06:59:15 +00:00
|
|
|
throwInvalidDbaseFormat();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::fillColumns()
|
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
|
|
|
|
m_pFileStream->Seek(32L);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-05-30 09:44:16 +00:00
|
|
|
if(!m_aColumns.isValid())
|
|
|
|
m_aColumns = new OSQLColumns();
|
|
|
|
else
|
2008-12-30 13:32:01 +00:00
|
|
|
m_aColumns->get().clear();
|
2001-05-30 09:44:16 +00:00
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
m_aTypes.clear();
|
|
|
|
m_aPrecisions.clear();
|
|
|
|
m_aScales.clear();
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// Anzahl Felder:
|
2007-09-26 13:28:34 +00:00
|
|
|
const sal_Int32 nFieldCount = (m_aHeader.db_kopf - 1) / 32 - 1;
|
2003-12-01 09:47:51 +00:00
|
|
|
OSL_ENSURE(nFieldCount,"No columns in table!");
|
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
m_aColumns->get().reserve(nFieldCount);
|
2001-08-24 05:05:37 +00:00
|
|
|
m_aTypes.reserve(nFieldCount);
|
|
|
|
m_aPrecisions.reserve(nFieldCount);
|
|
|
|
m_aScales.reserve(nFieldCount);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2003-12-01 09:47:51 +00:00
|
|
|
String aStrFieldName;
|
|
|
|
aStrFieldName.AssignAscii("Column");
|
2000-09-18 15:18:56 +00:00
|
|
|
::rtl::OUString aTypeName;
|
2007-09-26 13:28:34 +00:00
|
|
|
static const ::rtl::OUString sVARCHAR(RTL_CONSTASCII_USTRINGPARAM("VARCHAR"));
|
|
|
|
const sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
sal_Int32 i = 0;
|
|
|
|
for (; i < nFieldCount; i++)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
DBFColumn aDBFColumn;
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Read((char*)&aDBFColumn, sizeof(aDBFColumn));
|
2008-06-06 12:20:24 +00:00
|
|
|
if ( FIELD_DESCRIPTOR_TERMINATOR == aDBFColumn.db_fnm[0] ) // 0x0D stored as the Field Descriptor terminator.
|
|
|
|
break;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
const String aColumnName((const char *)aDBFColumn.db_fnm,m_eEncoding);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
sal_Int32 nPrecision = aDBFColumn.db_flng;
|
|
|
|
sal_Int32 eType;
|
|
|
|
|
|
|
|
switch (aDBFColumn.db_typ)
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
eType = DataType::VARCHAR;
|
2001-08-24 05:05:37 +00:00
|
|
|
aTypeName = sVARCHAR;
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
case 'N':
|
|
|
|
eType = DataType::DECIMAL;
|
|
|
|
aTypeName = ::rtl::OUString::createFromAscii("DECIMAL");
|
|
|
|
|
|
|
|
// Bei numerischen Feldern werden zwei Zeichen mehr geschrieben, als die Precision der Spaltenbeschreibung eigentlich
|
|
|
|
// angibt, um Platz fuer das eventuelle Vorzeichen und das Komma zu haben. Das muss ich jetzt aber wieder rausrechnen.
|
|
|
|
nPrecision = SvDbaseConverter::ConvertPrecisionToOdbc(nPrecision,aDBFColumn.db_dez);
|
|
|
|
// leider gilt das eben Gesagte nicht fuer aeltere Versionen ....
|
|
|
|
;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
eType = DataType::BIT;
|
|
|
|
aTypeName = ::rtl::OUString::createFromAscii("BIT");
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
eType = DataType::DATE;
|
|
|
|
aTypeName = ::rtl::OUString::createFromAscii("DATE");
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
eType = DataType::LONGVARCHAR;
|
|
|
|
aTypeName = ::rtl::OUString::createFromAscii("LONGVARCHAR");
|
2003-09-04 07:24:07 +00:00
|
|
|
nPrecision = 65535;
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aTypeName = ::rtl::OUString::createFromAscii("OTHER");
|
|
|
|
eType = DataType::OTHER;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
// sal_Int32 nFlags = 0;
|
|
|
|
// switch (aDBFColumn.db_typ)
|
|
|
|
// {
|
|
|
|
// case 'C':
|
|
|
|
// case 'D':
|
|
|
|
// case 'L': nFlags = ColumnSearch::FULL; break;
|
|
|
|
// case 'F':
|
|
|
|
// case 'N': nFlags = ColumnSearch::BASIC; break;
|
|
|
|
// case 'M': nFlags = ColumnSearch::CHAR; break;
|
|
|
|
// default:
|
|
|
|
// nFlags = ColumnSearch::NONE;
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
2003-12-01 09:47:51 +00:00
|
|
|
m_aTypes.push_back(eType);
|
|
|
|
m_aPrecisions.push_back(nPrecision);
|
|
|
|
m_aScales.push_back(aDBFColumn.db_dez);
|
|
|
|
|
|
|
|
Reference< XPropertySet> xCol = new sdbcx::OColumn(aColumnName,
|
2001-08-24 05:05:37 +00:00
|
|
|
aTypeName,
|
|
|
|
::rtl::OUString(),
|
|
|
|
ColumnValue::NULLABLE,
|
|
|
|
nPrecision,
|
|
|
|
aDBFColumn.db_dez,
|
|
|
|
eType,
|
|
|
|
sal_False,
|
|
|
|
sal_False,
|
|
|
|
sal_False,
|
|
|
|
bCase);
|
2008-12-30 13:32:01 +00:00
|
|
|
m_aColumns->get().push_back(xCol);
|
2008-06-06 12:20:24 +00:00
|
|
|
} // for (; i < nFieldCount; i++)
|
|
|
|
OSL_ENSURE(i,"No columns in table!");
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-09-25 12:12:51 +00:00
|
|
|
ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection)
|
|
|
|
:ODbaseTable_BASE(_pTables,_pConnection)
|
2000-12-10 18:25:56 +00:00
|
|
|
,m_pMemoStream(NULL)
|
|
|
|
,m_bWriteableMemo(sal_False)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
// initialize the header
|
|
|
|
m_aHeader.db_typ = dBaseIII;
|
|
|
|
m_aHeader.db_anz = 0;
|
|
|
|
m_aHeader.db_kopf = 0;
|
|
|
|
m_aHeader.db_slng = 0;
|
2008-06-06 12:20:24 +00:00
|
|
|
m_eEncoding = getConnection()->getTextEncoding();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-09-25 12:12:51 +00:00
|
|
|
ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection,
|
2000-09-18 15:18:56 +00:00
|
|
|
const ::rtl::OUString& _Name,
|
|
|
|
const ::rtl::OUString& _Type,
|
|
|
|
const ::rtl::OUString& _Description ,
|
|
|
|
const ::rtl::OUString& _SchemaName,
|
|
|
|
const ::rtl::OUString& _CatalogName
|
2001-09-25 12:12:51 +00:00
|
|
|
) : ODbaseTable_BASE(_pTables,_pConnection,_Name,
|
2000-09-18 15:18:56 +00:00
|
|
|
_Type,
|
|
|
|
_Description,
|
|
|
|
_SchemaName,
|
|
|
|
_CatalogName)
|
2000-11-17 06:37:01 +00:00
|
|
|
,m_pMemoStream(NULL)
|
2000-12-08 11:55:13 +00:00
|
|
|
,m_bWriteableMemo(sal_False)
|
2001-02-22 12:53:00 +00:00
|
|
|
{
|
2008-06-06 12:20:24 +00:00
|
|
|
m_eEncoding = getConnection()->getTextEncoding();
|
2001-02-22 12:53:00 +00:00
|
|
|
}
|
2001-07-17 11:37:19 +00:00
|
|
|
|
2001-02-22 12:53:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::construct()
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
// initialize the header
|
|
|
|
m_aHeader.db_typ = dBaseIII;
|
|
|
|
m_aHeader.db_anz = 0;
|
|
|
|
m_aHeader.db_kopf = 0;
|
|
|
|
m_aHeader.db_slng = 0;
|
2007-09-26 13:28:34 +00:00
|
|
|
m_aMemoHeader.db_size = 0;
|
2000-11-16 09:47:23 +00:00
|
|
|
|
2001-08-10 10:05:34 +00:00
|
|
|
String sFileName(getEntry(m_pConnection,m_Name));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-12-10 18:25:56 +00:00
|
|
|
INetURLObject aURL;
|
|
|
|
aURL.SetURL(sFileName);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-10-26 09:33:26 +00:00
|
|
|
OSL_ENSURE( m_pConnection->matchesExtension( aURL.getExtension() ),
|
2000-12-10 18:25:56 +00:00
|
|
|
"ODbaseTable::ODbaseTable: invalid extension!");
|
|
|
|
// getEntry is expected to ensure the corect file name
|
2000-11-16 09:47:23 +00:00
|
|
|
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pFileStream = createStream_simpleError( sFileName, STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE);
|
2006-06-20 00:21:12 +00:00
|
|
|
m_bWriteable = ( m_pFileStream != NULL );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
if ( !m_pFileStream )
|
|
|
|
{
|
|
|
|
m_bWriteable = sal_False;
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pFileStream = createStream_simpleError( sFileName, STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE);
|
2006-06-20 00:21:12 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
if(m_pFileStream)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
readHeader();
|
2001-03-01 09:56:00 +00:00
|
|
|
if (HasMemoFields())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-03-01 09:56:00 +00:00
|
|
|
// Memo-Dateinamen bilden (.DBT):
|
|
|
|
// nyi: Unschoen fuer Unix und Mac!
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
if ( m_aHeader.db_typ == FoxProMemo || VisualFoxPro == m_aHeader.db_typ ) // foxpro uses another extension
|
2001-03-01 09:56:00 +00:00
|
|
|
aURL.SetExtension(String::CreateFromAscii("fpt"));
|
|
|
|
else
|
|
|
|
aURL.SetExtension(String::CreateFromAscii("dbt"));
|
2000-12-08 11:55:13 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
// Wenn die Memodatei nicht gefunden wird, werden die Daten trotzdem angezeigt
|
|
|
|
// allerdings koennen keine Updates durchgefuehrt werden
|
|
|
|
// jedoch die Operation wird ausgefuehrt
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE);
|
2006-06-20 00:21:12 +00:00
|
|
|
if ( !m_pMemoStream )
|
|
|
|
{
|
|
|
|
m_bWriteableMemo = sal_False;
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE);
|
2006-06-20 00:21:12 +00:00
|
|
|
}
|
2001-03-01 09:56:00 +00:00
|
|
|
if (m_pMemoStream)
|
|
|
|
ReadMemoHeader();
|
|
|
|
}
|
2001-05-30 09:44:16 +00:00
|
|
|
// if(!m_pColumns && (!m_aColumns.isValid() || !m_aColumns->size()))
|
|
|
|
fillColumns();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
m_pFileStream->Seek(STREAM_SEEK_TO_END);
|
|
|
|
UINT32 nFileSize = m_pFileStream->Tell();
|
|
|
|
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
|
2008-01-30 06:50:29 +00:00
|
|
|
if ( m_aHeader.db_anz == 0 && ((nFileSize-m_aHeader.db_kopf)/m_aHeader.db_slng) > 0) // seems to be empty or someone wrote bullshit into the dbase file
|
|
|
|
m_aHeader.db_anz = ((nFileSize-m_aHeader.db_kopf)/m_aHeader.db_slng);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
// Buffersize abhaengig von der Filegroesse
|
|
|
|
m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 :
|
|
|
|
nFileSize > 100000 ? 16384 :
|
|
|
|
nFileSize > 10000 ? 4096 : 1024);
|
2000-12-08 11:55:13 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
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);
|
2000-12-08 11:55:13 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
// Buffersize abhaengig von der Filegroesse
|
|
|
|
m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 :
|
|
|
|
nFileSize > 100000 ? 16384 :
|
|
|
|
nFileSize > 10000 ? 4096 :
|
|
|
|
m_aMemoHeader.db_size);
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-03-01 09:56:00 +00:00
|
|
|
AllocBuffer();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::ReadMemoHeader()
|
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
|
|
|
|
m_pMemoStream->RefreshBuffer(); // sicherstellen das die Kopfinformationen tatsaechlich neu gelesen werden
|
|
|
|
m_pMemoStream->Seek(0L);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pMemoStream) >> m_aMemoHeader.db_next;
|
2000-09-18 15:18:56 +00:00
|
|
|
switch (m_aHeader.db_typ)
|
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
case dBaseIIIMemo: // dBase III: feste Blockgroesse
|
2000-09-18 15:18:56 +00:00
|
|
|
case dBaseIVMemo:
|
|
|
|
// manchmal wird aber auch dBase3 dBase4 Memo zugeordnet
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(20L);
|
|
|
|
(*m_pMemoStream) >> m_aMemoHeader.db_size;
|
2000-09-18 15:18:56 +00:00
|
|
|
if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size != 512) // 1 steht auch fuer dBase 3
|
|
|
|
m_aMemoHeader.db_typ = MemodBaseIV;
|
|
|
|
else if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size == 512)
|
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
// nun gibt es noch manche Dateien, die verwenden eine Groessenangabe,
|
2000-09-18 15:18:56 +00:00
|
|
|
// sind aber dennoch dBase Dateien
|
|
|
|
char sHeader[4];
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(m_aMemoHeader.db_size);
|
|
|
|
m_pMemoStream->Read(sHeader,4);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
if ((m_pMemoStream->GetErrorCode() != ERRCODE_NONE) || ((BYTE)sHeader[0]) != 0xFF || ((BYTE)sHeader[1]) != 0xFF || ((BYTE)sHeader[2]) != 0x08)
|
2000-09-18 15:18:56 +00:00
|
|
|
m_aMemoHeader.db_typ = MemodBaseIII;
|
|
|
|
else
|
|
|
|
m_aMemoHeader.db_typ = MemodBaseIV;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_aMemoHeader.db_typ = MemodBaseIII;
|
|
|
|
m_aMemoHeader.db_size = 512;
|
|
|
|
}
|
|
|
|
break;
|
2008-06-06 12:20:24 +00:00
|
|
|
case VisualFoxPro:
|
2000-09-18 15:18:56 +00:00
|
|
|
case FoxProMemo:
|
|
|
|
m_aMemoHeader.db_typ = MemoFoxPro;
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(6L);
|
|
|
|
m_pMemoStream->SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN);
|
|
|
|
(*m_pMemoStream) >> m_aMemoHeader.db_size;
|
2008-06-06 12:20:24 +00:00
|
|
|
break;
|
2006-06-20 00:21:12 +00:00
|
|
|
default:
|
|
|
|
OSL_ENSURE( false, "ODbaseTable::ReadMemoHeader: unsupported memo type!" );
|
|
|
|
break;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-08-10 10:05:34 +00:00
|
|
|
String ODbaseTable::getEntry(OConnection* _pConnection,const ::rtl::OUString& _sName )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2004-08-02 16:01:01 +00:00
|
|
|
::rtl::OUString sURL;
|
2001-03-30 11:07:07 +00:00
|
|
|
try
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-10 10:05:34 +00:00
|
|
|
Reference< XResultSet > xDir = _pConnection->getDir()->getStaticResultSet();
|
2001-03-30 11:07:07 +00:00
|
|
|
Reference< XRow> xRow(xDir,UNO_QUERY);
|
|
|
|
::rtl::OUString sName;
|
|
|
|
::rtl::OUString sExt;
|
2004-08-02 16:01:01 +00:00
|
|
|
INetURLObject aURL;
|
|
|
|
static const ::rtl::OUString s_sSeparator(RTL_CONSTASCII_USTRINGPARAM("/"));
|
2001-03-30 11:07:07 +00:00
|
|
|
xDir->beforeFirst();
|
|
|
|
while(xDir->next())
|
|
|
|
{
|
|
|
|
sName = xRow->getString(1);
|
2004-08-02 16:01:01 +00:00
|
|
|
aURL.SetSmartProtocol(INET_PROT_FILE);
|
|
|
|
String sUrl = _pConnection->getURL() + s_sSeparator + sName;
|
|
|
|
aURL.SetSmartURL( sUrl );
|
2000-12-10 18:25:56 +00:00
|
|
|
|
2001-03-30 11:07:07 +00:00
|
|
|
// cut the extension
|
2004-08-02 16:01:01 +00:00
|
|
|
sExt = aURL.getExtension();
|
2000-12-10 18:25:56 +00:00
|
|
|
|
2001-03-30 11:07:07 +00:00
|
|
|
// name and extension have to coincide
|
2004-08-02 16:01:01 +00:00
|
|
|
if ( _pConnection->matchesExtension( sExt ) )
|
2001-03-30 11:07:07 +00:00
|
|
|
{
|
2004-08-02 16:01:01 +00:00
|
|
|
sName = sName.replaceAt(sName.getLength()-(sExt.getLength()+1),sExt.getLength()+1,::rtl::OUString());
|
|
|
|
if ( sName == _sName )
|
|
|
|
{
|
|
|
|
Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY );
|
|
|
|
sURL = xContentAccess->queryContentIdentifierString();
|
|
|
|
break;
|
|
|
|
}
|
2001-03-30 11:07:07 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2001-03-30 11:07:07 +00:00
|
|
|
xDir->beforeFirst(); // move back to before first record
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(0);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2004-08-02 16:01:01 +00:00
|
|
|
return sURL;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::refreshColumns()
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
|
2001-05-02 11:57:37 +00:00
|
|
|
TStringVector aVector;
|
2008-12-30 13:32:01 +00:00
|
|
|
aVector.reserve(m_aColumns->get().size());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != m_aColumns->get().end();++aIter)
|
2000-09-18 15:18:56 +00:00
|
|
|
aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName());
|
|
|
|
|
|
|
|
if(m_pColumns)
|
2001-05-07 09:37:54 +00:00
|
|
|
m_pColumns->reFill(aVector);
|
|
|
|
else
|
|
|
|
m_pColumns = new ODbaseColumns(this,m_aMutex,aVector);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::refreshIndexes()
|
|
|
|
{
|
2001-05-02 11:57:37 +00:00
|
|
|
TStringVector aVector;
|
2001-07-16 08:58:40 +00:00
|
|
|
if(m_pFileStream && (!m_pIndexes || m_pIndexes->getCount() == 0))
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
INetURLObject aURL;
|
2001-08-10 10:05:34 +00:00
|
|
|
aURL.SetURL(getEntry(m_pConnection,m_Name));
|
2000-11-16 09:47:23 +00:00
|
|
|
|
|
|
|
aURL.setExtension(String::CreateFromAscii("inf"));
|
2001-03-08 08:18:58 +00:00
|
|
|
Config aInfFile(aURL.getFSysPath(INetURLObject::FSYS_DETECT));
|
2000-11-16 09:47:23 +00:00
|
|
|
aInfFile.SetGroup(dBASE_III_GROUP);
|
2001-03-01 09:51:00 +00:00
|
|
|
USHORT nKeyCnt = aInfFile.GetKeyCount();
|
2000-11-16 09:47:23 +00:00
|
|
|
ByteString aKeyName;
|
|
|
|
ByteString aIndexName;
|
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
for (USHORT nKey = 0; nKey < nKeyCnt; nKey++)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
// Verweist der Key auf ein Indexfile?...
|
|
|
|
aKeyName = aInfFile.GetKeyName( nKey );
|
|
|
|
//...wenn ja, Indexliste der Tabelle hinzufuegen
|
|
|
|
if (aKeyName.Copy(0,3) == ByteString("NDX") )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
aIndexName = aInfFile.ReadKey(aKeyName);
|
2008-06-06 12:20:24 +00:00
|
|
|
aURL.setName(String(aIndexName,m_eEncoding));
|
2000-12-08 11:55:13 +00:00
|
|
|
try
|
|
|
|
{
|
2001-07-16 08:58:40 +00:00
|
|
|
Content aCnt(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
2000-12-08 11:55:13 +00:00
|
|
|
if (aCnt.isDocument())
|
|
|
|
{
|
|
|
|
aVector.push_back(aURL.getBase());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception&) // a execption is thrown when no file exists
|
2000-11-16 09:47:23 +00:00
|
|
|
{
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(m_pIndexes)
|
2001-05-30 09:44:16 +00:00
|
|
|
m_pIndexes->reFill(aVector);
|
|
|
|
else
|
|
|
|
m_pIndexes = new ODbaseIndexes(this,m_aMutex,aVector);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL ODbaseTable::disposing(void)
|
|
|
|
{
|
|
|
|
OFileTable::disposing();
|
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
2001-05-07 09:37:54 +00:00
|
|
|
m_aColumns = NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Sequence< Type > SAL_CALL ODbaseTable::getTypes( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
Sequence< Type > aTypes = OTable_TYPEDEF::getTypes();
|
2001-10-18 12:24:06 +00:00
|
|
|
::std::vector<Type> aOwnTypes;
|
|
|
|
aOwnTypes.reserve(aTypes.getLength());
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
const Type* pBegin = aTypes.getConstArray();
|
|
|
|
const Type* pEnd = pBegin + aTypes.getLength();
|
2001-05-31 05:11:58 +00:00
|
|
|
for(;pBegin != pEnd;++pBegin)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-03-28 10:32:43 +00:00
|
|
|
if(!(*pBegin == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
|
2001-05-30 09:44:16 +00:00
|
|
|
// *pBegin == ::getCppuType((const Reference<XAlterTable>*)0) ||
|
2000-09-18 15:18:56 +00:00
|
|
|
*pBegin == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)))
|
|
|
|
{
|
2001-10-18 12:24:06 +00:00
|
|
|
aOwnTypes.push_back(*pBegin);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-18 12:24:06 +00:00
|
|
|
aOwnTypes.push_back(::getCppuType( (const Reference< ::com::sun::star::lang::XUnoTunnel > *)0 ));
|
2004-09-08 15:19:47 +00:00
|
|
|
Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
|
|
|
|
return Sequence< Type >(pTypes, aOwnTypes.size());
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Any SAL_CALL ODbaseTable::queryInterface( const Type & rType ) throw(RuntimeException)
|
|
|
|
{
|
2001-03-28 10:32:43 +00:00
|
|
|
if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
|
2000-09-18 15:18:56 +00:00
|
|
|
rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))
|
|
|
|
return Any();
|
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
Any aRet = OTable_TYPEDEF::queryInterface(rType);
|
|
|
|
return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this));
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
Sequence< sal_Int8 > ODbaseTable::getUnoTunnelImplementationId()
|
|
|
|
{
|
|
|
|
static ::cppu::OImplementationId * pId = 0;
|
|
|
|
if (! pId)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
|
|
|
|
if (! pId)
|
|
|
|
{
|
|
|
|
static ::cppu::OImplementationId aId;
|
|
|
|
pId = &aId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pId->getImplementationId();
|
|
|
|
}
|
|
|
|
|
|
|
|
// com::sun::star::lang::XUnoTunnel
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
sal_Int64 ODbaseTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
|
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
|
2006-06-20 00:21:12 +00:00
|
|
|
? reinterpret_cast< sal_Int64 >( this )
|
|
|
|
: ODbaseTable_BASE::getSomething(rId);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
2003-09-04 07:24:07 +00:00
|
|
|
sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, sal_Bool _bUseTableDefs,sal_Bool bRetrieveData)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// Einlesen der Daten
|
2000-09-29 14:30:09 +00:00
|
|
|
BOOL bIsCurRecordDeleted = ((char)m_pBuffer[0] == '*') ? TRUE : sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
// only read the bookmark
|
|
|
|
|
|
|
|
// Satz als geloescht markieren
|
|
|
|
// rRow.setState(bIsCurRecordDeleted ? ROW_DELETED : ROW_CLEAN );
|
|
|
|
_rRow->setDeleted(bIsCurRecordDeleted);
|
2008-12-30 13:32:01 +00:00
|
|
|
*(_rRow->get())[0] = m_nFilePos;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
if (!bRetrieveData)
|
|
|
|
return TRUE;
|
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
sal_Size nByteOffset = 1;
|
2000-09-18 15:18:56 +00:00
|
|
|
// Felder:
|
2008-12-30 13:32:01 +00:00
|
|
|
OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin();
|
|
|
|
OSQLColumns::Vector::const_iterator aEnd = _rCols.get().end();
|
|
|
|
const sal_Size nCount = _rRow->get().size();
|
2008-12-10 13:41:25 +00:00
|
|
|
for (sal_Size i = 1; aIter != aEnd && nByteOffset <= m_nBufferSize && i < nCount;++aIter, i++)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// Laengen je nach Datentyp:
|
2006-11-21 15:59:57 +00:00
|
|
|
sal_Int32 nLen = 0;
|
|
|
|
sal_Int32 nType = 0;
|
2000-11-27 07:00:26 +00:00
|
|
|
if(_bUseTableDefs)
|
|
|
|
{
|
2000-12-13 14:21:14 +00:00
|
|
|
nLen = m_aPrecisions[i-1];
|
|
|
|
nType = m_aTypes[i-1];
|
2000-11-27 07:00:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
(*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen;
|
|
|
|
(*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
|
2000-11-27 07:00:26 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
switch(nType)
|
|
|
|
{
|
|
|
|
case DataType::DATE: nLen = 8; break;
|
|
|
|
case DataType::DECIMAL:
|
2000-11-27 07:00:26 +00:00
|
|
|
if(_bUseTableDefs)
|
2000-12-13 14:21:14 +00:00
|
|
|
nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,m_aScales[i-1]);
|
2000-11-27 07:00:26 +00:00
|
|
|
else
|
2001-08-24 05:05:37 +00:00
|
|
|
nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,getINT32((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))));
|
2000-09-18 15:18:56 +00:00
|
|
|
break; // das Vorzeichen und das Komma
|
|
|
|
case DataType::BIT: nLen = 1; break;
|
|
|
|
case DataType::LONGVARCHAR: nLen = 10; break;
|
|
|
|
case DataType::OTHER:
|
|
|
|
nByteOffset += nLen;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ist die Variable ueberhaupt gebunden?
|
2008-12-30 13:32:01 +00:00
|
|
|
if ( !(_rRow->get())[i]->isBound() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// Nein - naechstes Feld.
|
|
|
|
nByteOffset += nLen;
|
2006-01-16 14:03:59 +00:00
|
|
|
OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!");
|
2000-09-18 15:18:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *pData = (char *) (m_pBuffer + nByteOffset);
|
|
|
|
|
2000-09-29 14:30:09 +00:00
|
|
|
// (*_rRow)[i].setType(nType);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
if (nType == DataType::CHAR || nType == DataType::VARCHAR)
|
|
|
|
{
|
|
|
|
char cLast = pData[nLen];
|
|
|
|
pData[nLen] = 0;
|
2008-06-06 12:20:24 +00:00
|
|
|
String aStr(pData,(xub_StrLen)nLen,m_eEncoding);
|
2000-09-18 15:18:56 +00:00
|
|
|
aStr.EraseTrailingChars();
|
|
|
|
|
2008-12-10 13:41:25 +00:00
|
|
|
if ( aStr.Len() )
|
2008-12-30 13:32:01 +00:00
|
|
|
*(*(_rRow).get())[i] = ::rtl::OUString(aStr);
|
2008-12-10 13:41:25 +00:00
|
|
|
else// keine StringLaenge, dann NULL
|
2008-12-30 13:32:01 +00:00
|
|
|
(*(_rRow.get()))[i]->setNull();
|
2008-12-10 13:41:25 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
pData[nLen] = cLast;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Falls Nul-Zeichen im String enthalten sind, in Blanks umwandeln!
|
|
|
|
for (sal_Int32 k = 0; k < nLen; k++)
|
|
|
|
{
|
|
|
|
if (pData[k] == '\0')
|
|
|
|
pData[k] = ' ';
|
|
|
|
}
|
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
String aStr(pData, (xub_StrLen)nLen,m_eEncoding); // Spaces am Anfang und am Ende entfernen:
|
2000-09-18 15:18:56 +00:00
|
|
|
aStr.EraseLeadingChars();
|
|
|
|
aStr.EraseTrailingChars();
|
|
|
|
|
|
|
|
if (!aStr.Len())
|
|
|
|
{
|
|
|
|
nByteOffset += nLen;
|
2008-12-30 13:32:01 +00:00
|
|
|
(_rRow->get())[i]->setNull(); // keine Werte -> fertig
|
2000-09-18 15:18:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case DataType::DATE:
|
|
|
|
{
|
|
|
|
if (aStr.Len() != nLen)
|
|
|
|
{
|
2008-12-30 13:32:01 +00:00
|
|
|
(_rRow->get())[i]->setNull();
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-10 13:41:25 +00:00
|
|
|
const sal_uInt16 nYear = (sal_uInt16)aStr.Copy( 0, 4 ).ToInt32();
|
|
|
|
const sal_uInt16 nMonth = (sal_uInt16)aStr.Copy( 4, 2 ).ToInt32();
|
|
|
|
const sal_uInt16 nDay = (sal_uInt16)aStr.Copy( 6, 2 ).ToInt32();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-12-10 13:41:25 +00:00
|
|
|
const ::com::sun::star::util::Date aDate(nDay,nMonth,nYear);
|
2008-12-30 13:32:01 +00:00
|
|
|
*(_rRow->get())[i] = aDate;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DataType::DECIMAL:
|
2008-12-30 13:32:01 +00:00
|
|
|
*(_rRow->get())[i] = ORowSetValue(aStr);
|
2000-09-18 15:18:56 +00:00
|
|
|
// pVal->setDouble(SdbTools::ToDouble(aStr));
|
|
|
|
break;
|
|
|
|
case DataType::BIT:
|
|
|
|
{
|
|
|
|
BOOL b;
|
|
|
|
switch (* ((const char *)pData))
|
|
|
|
{
|
|
|
|
case 'T':
|
|
|
|
case 'Y':
|
|
|
|
case 'J': b = TRUE; break;
|
2008-12-10 13:41:25 +00:00
|
|
|
default: b = FALSE; break;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2008-12-30 13:32:01 +00:00
|
|
|
*(_rRow->get())[i] = b;
|
2000-09-18 15:18:56 +00:00
|
|
|
// pVal->setDouble(b);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DataType::LONGVARCHAR:
|
|
|
|
{
|
2008-12-10 13:41:25 +00:00
|
|
|
const long nBlockNo = aStr.ToInt32(); // Blocknummer lesen
|
2000-11-16 09:47:23 +00:00
|
|
|
if (nBlockNo > 0 && m_pMemoStream) // Daten aus Memo-Datei lesen, nur wenn
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2008-12-30 13:32:01 +00:00
|
|
|
if ( !ReadMemo(nBlockNo, (_rRow->get())[i]->get()) )
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2008-12-30 13:32:01 +00:00
|
|
|
(_rRow->get())[i]->setNull();
|
2000-09-18 15:18:56 +00:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
OSL_ASSERT("Falscher Type");
|
|
|
|
}
|
2008-12-30 13:32:01 +00:00
|
|
|
(_rRow->get())[i]->setTypeKind(nType);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if (aStatus.IsError())
|
|
|
|
// break;
|
|
|
|
// Und weiter ...
|
|
|
|
nByteOffset += nLen;
|
2006-01-16 14:03:59 +00:00
|
|
|
OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!");
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::FileClose()
|
|
|
|
{
|
2000-11-03 13:21:22 +00:00
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
2000-09-18 15:18:56 +00:00
|
|
|
// falls noch nicht alles geschrieben wurde
|
2000-11-16 09:47:23 +00:00
|
|
|
if (m_pMemoStream && m_pMemoStream->IsWritable())
|
|
|
|
m_pMemoStream->Flush();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
delete m_pMemoStream;
|
|
|
|
m_pMemoStream = NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-03 13:21:22 +00:00
|
|
|
ODbaseTable_BASE::FileClose();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::CreateImpl()
|
|
|
|
{
|
2001-02-14 06:22:50 +00:00
|
|
|
OSL_ENSURE(!m_pFileStream, "SequenceError");
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2002-11-29 11:50:57 +00:00
|
|
|
if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name,::rtl::OUString()) != m_Name )
|
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_SQL_NAME_ERROR,
|
|
|
|
"$name$", m_Name
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2002-11-29 11:50:57 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
INetURLObject aURL;
|
|
|
|
aURL.SetSmartProtocol(INET_PROT_FILE);
|
2001-08-10 10:05:34 +00:00
|
|
|
String aName = getEntry(m_pConnection,m_Name);
|
2000-10-25 12:31:00 +00:00
|
|
|
if(!aName.Len())
|
|
|
|
{
|
|
|
|
::rtl::OUString aIdent = m_pConnection->getContent()->getIdentifier()->getContentIdentifier();
|
2003-04-24 12:18:52 +00:00
|
|
|
if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) )
|
|
|
|
aIdent += ::rtl::OUString::createFromAscii("/");
|
2000-10-25 12:31:00 +00:00
|
|
|
aIdent += m_Name;
|
|
|
|
aName = aIdent.getStr();
|
|
|
|
}
|
2000-11-16 09:47:23 +00:00
|
|
|
aURL.SetURL(aName);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-10-26 09:33:26 +00:00
|
|
|
if ( !m_pConnection->matchesExtension( aURL.getExtension() ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
aURL.setExtension(m_pConnection->getExtension());
|
|
|
|
|
2000-12-08 11:55:13 +00:00
|
|
|
try
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2002-07-05 07:02:12 +00:00
|
|
|
Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
2000-12-08 11:55:13 +00:00
|
|
|
if (aContent.isDocument())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-12-08 11:55:13 +00:00
|
|
|
// Hack fuer Bug #30609 , nur wenn das File existiert und die Laenge > 0 gibt es einen Fehler
|
2001-07-17 11:37:19 +00:00
|
|
|
SvStream* pFileStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE),STREAM_READ);
|
2000-12-08 11:55:13 +00:00
|
|
|
|
|
|
|
if (pFileStream && pFileStream->Seek(STREAM_SEEK_TO_END))
|
|
|
|
{
|
|
|
|
// aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,TABLE,aFile.GetFull());
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
delete pFileStream;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2000-12-08 11:55:13 +00:00
|
|
|
}
|
|
|
|
catch(Exception&) // a execption is thrown when no file exists
|
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2000-09-29 14:30:09 +00:00
|
|
|
BOOL bMemoFile = sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
sal_Bool bOk = CreateFile(aURL, bMemoFile);
|
|
|
|
|
|
|
|
FileClose();
|
|
|
|
|
|
|
|
if (!bOk)
|
|
|
|
{
|
2002-07-05 07:02:12 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
|
|
|
aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) );
|
|
|
|
}
|
|
|
|
catch(Exception&) // a execption is thrown when no file exists
|
|
|
|
{
|
|
|
|
}
|
2000-09-29 14:30:09 +00:00
|
|
|
return sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bMemoFile)
|
|
|
|
{
|
|
|
|
String aExt = aURL.getExtension();
|
|
|
|
aURL.setExtension(String::CreateFromAscii("dbt")); // extension for memo file
|
2001-07-16 08:58:40 +00:00
|
|
|
Content aMemo1Content(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-03-02 12:29:11 +00:00
|
|
|
sal_Bool bMemoAlreadyExists = sal_False;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bMemoAlreadyExists = aMemo1Content.isDocument();
|
|
|
|
}
|
|
|
|
catch(Exception&) // a execption is thrown when no file exists
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if (bMemoAlreadyExists)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,MEMO,aFile.GetFull());
|
|
|
|
aURL.setExtension(aExt); // kill dbf file
|
2001-05-28 12:03:37 +00:00
|
|
|
try
|
|
|
|
{
|
2001-07-16 08:58:40 +00:00
|
|
|
Content aMemoContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
2001-05-28 12:03:37 +00:00
|
|
|
aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) );
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
|
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_COULD_NOT_DELETE_FILE,
|
|
|
|
"$name$", aName
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2001-05-28 12:03:37 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
if (!CreateMemoFile(aURL))
|
|
|
|
{
|
|
|
|
aURL.setExtension(aExt); // kill dbf file
|
2001-07-16 08:58:40 +00:00
|
|
|
Content aMemoContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
2000-09-18 15:18:56 +00:00
|
|
|
aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) );
|
2000-09-29 14:30:09 +00:00
|
|
|
return sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
m_aHeader.db_typ = dBaseIIIMemo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_aHeader.db_typ = dBaseIII;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-03-19 15:38:50 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2008-10-01 12:28:29 +00:00
|
|
|
void ODbaseTable::throwInvalidColumnType(const sal_uInt16 _nErrorId,const ::rtl::OUString& _sColumnName)
|
2003-03-19 15:38:50 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// we have to drop the file because it is corrupted now
|
|
|
|
DropImpl();
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
_nErrorId,
|
|
|
|
"$columnname$", _sColumnName
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2003-03-19 15:38:50 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
//------------------------------------------------------------------
|
2005-02-16 16:24:00 +00:00
|
|
|
// erzeugt grundsaetzlich dBase IV Datei Format
|
2000-09-18 15:18:56 +00:00
|
|
|
BOOL ODbaseTable::CreateFile(const INetURLObject& aFile, BOOL& bCreateMemo)
|
|
|
|
{
|
2000-09-29 14:30:09 +00:00
|
|
|
bCreateMemo = sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
Date aDate; // aktuelles Datum
|
|
|
|
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pFileStream = createStream_simpleError( aFile.GetMainURL(INetURLObject::NO_DECODE),STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC );
|
2000-11-16 09:47:23 +00:00
|
|
|
|
|
|
|
if (!m_pFileStream)
|
2000-09-29 14:30:09 +00:00
|
|
|
return sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
char aBuffer[21]; // write buffer
|
|
|
|
memset(aBuffer,0,sizeof(aBuffer));
|
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Seek(0L);
|
|
|
|
(*m_pFileStream) << (BYTE) dBaseIII; // dBase format
|
|
|
|
(*m_pFileStream) << (BYTE) (aDate.GetYear() % 100); // aktuelles Datum
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pFileStream) << (BYTE) aDate.GetMonth();
|
|
|
|
(*m_pFileStream) << (BYTE) aDate.GetDay();
|
2005-02-16 16:24:00 +00:00
|
|
|
(*m_pFileStream) << 0L; // Anzahl der Datensaetze
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pFileStream) << (USHORT)((m_pColumns->getCount()+1) * 32 + 1); // Kopfinformationen,
|
2005-02-16 16:24:00 +00:00
|
|
|
// pColumns erhaelt immer eine Spalte mehr
|
|
|
|
(*m_pFileStream) << (USHORT) 0; // Satzlaenge wird spaeter bestimmt
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Write(aBuffer, 20);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-02-16 16:24:00 +00:00
|
|
|
USHORT nRecLength = 1; // Laenge 1 fuer deleted flag
|
2001-03-01 09:51:00 +00:00
|
|
|
sal_Int32 nMaxFieldLength = m_pConnection->getMetaData()->getMaxColumnNameLength();
|
2000-09-18 15:18:56 +00:00
|
|
|
Reference<XIndexAccess> xColumns(getColumns(),UNO_QUERY);
|
|
|
|
|
|
|
|
::rtl::OUString aName;
|
2000-10-30 07:07:33 +00:00
|
|
|
Reference<XPropertySet> xCol;
|
2005-10-24 07:20:50 +00:00
|
|
|
try
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2005-10-24 07:20:50 +00:00
|
|
|
for(sal_Int32 i=0;i<xColumns->getCount();++i)
|
|
|
|
{
|
|
|
|
::cppu::extractInterface(xCol,xColumns->getByIndex(i));
|
|
|
|
OSL_ENSURE(xCol.is(),"This should be a column!");
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
char cTyp( 'C' );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aName;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
::rtl::OString aCol;
|
2008-06-06 12:20:24 +00:00
|
|
|
if ( DBTypeConversion::convertUnicodeString( aName, aCol, m_eEncoding ) > nMaxFieldLength)
|
2003-03-19 15:38:50 +00:00
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
throwInvalidColumnType( STR_INVALID_COLUMN_NAME_LENGTH, aName );
|
2003-03-19 15:38:50 +00:00
|
|
|
}
|
2005-10-24 07:20:50 +00:00
|
|
|
|
|
|
|
(*m_pFileStream) << aCol.getStr();
|
|
|
|
m_pFileStream->Write(aBuffer, 11 - aCol.getLength());
|
|
|
|
|
|
|
|
switch (getINT32(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
|
2003-03-19 15:38:50 +00:00
|
|
|
{
|
2005-10-24 07:20:50 +00:00
|
|
|
case DataType::CHAR:
|
|
|
|
case DataType::VARCHAR:
|
|
|
|
cTyp = 'C';
|
|
|
|
break;
|
|
|
|
case DataType::TINYINT:
|
|
|
|
case DataType::SMALLINT:
|
|
|
|
case DataType::INTEGER:
|
|
|
|
case DataType::BIGINT:
|
|
|
|
case DataType::DECIMAL:
|
|
|
|
case DataType::NUMERIC:
|
|
|
|
case DataType::REAL:
|
|
|
|
case DataType::DOUBLE:
|
|
|
|
cTyp = 'N'; // nur dBase 3 format
|
|
|
|
break;
|
|
|
|
case DataType::DATE:
|
|
|
|
cTyp = 'D';
|
|
|
|
break;
|
|
|
|
case DataType::BIT:
|
|
|
|
cTyp = 'L';
|
|
|
|
break;
|
|
|
|
case DataType::LONGVARBINARY:
|
|
|
|
case DataType::LONGVARCHAR:
|
|
|
|
cTyp = 'M';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
throwInvalidColumnType(STR_INVALID_COLUMN_TYPE, aName);
|
2005-10-24 07:20:50 +00:00
|
|
|
}
|
2003-03-19 15:38:50 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
(*m_pFileStream) << cTyp;
|
|
|
|
m_pFileStream->Write(aBuffer, 4);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
sal_Int32 nPrecision = 0;
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nPrecision;
|
|
|
|
sal_Int32 nScale = 0;
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
switch(cTyp)
|
|
|
|
{
|
|
|
|
case 'C':
|
|
|
|
OSL_ENSURE(nPrecision < 255, "ODbaseTable::Create: Column zu lang!");
|
|
|
|
if (nPrecision > 254)
|
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
throwInvalidColumnType(STR_INVALID_COLUMN_PRECISION, aName);
|
2005-10-24 07:20:50 +00:00
|
|
|
}
|
|
|
|
(*m_pFileStream) << (BYTE) Min((ULONG)nPrecision, 255UL); //Feldlaenge
|
2006-06-20 00:21:12 +00:00
|
|
|
nRecLength = nRecLength + (USHORT)::std::min((USHORT)nPrecision, (USHORT)255UL);
|
2005-10-24 07:20:50 +00:00
|
|
|
(*m_pFileStream) << (BYTE)0; //Nachkommastellen
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
case 'N':
|
|
|
|
OSL_ENSURE(nPrecision >= nScale,
|
|
|
|
"ODbaseTable::Create: Feldlaenge muss groesser Nachkommastellen sein!");
|
|
|
|
if (nPrecision < nScale)
|
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
throwInvalidColumnType(STR_INVALID_PRECISION_SCALE, aName);
|
2005-10-24 07:20:50 +00:00
|
|
|
}
|
|
|
|
if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt
|
|
|
|
{
|
|
|
|
(*m_pFileStream) << (BYTE)10; // Standard Laenge
|
|
|
|
(*m_pFileStream) << (BYTE)4;
|
|
|
|
nRecLength += 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_Int32 nPrec = SvDbaseConverter::ConvertPrecisionToDbase(nPrecision,nScale);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
(*m_pFileStream) << (BYTE)( nPrec);
|
|
|
|
(*m_pFileStream) << (BYTE)nScale;
|
2006-06-20 00:21:12 +00:00
|
|
|
nRecLength = nRecLength + (USHORT)nPrec;
|
2005-10-24 07:20:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
(*m_pFileStream) << (BYTE)1;
|
|
|
|
(*m_pFileStream) << (BYTE)0;
|
|
|
|
nRecLength++;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
(*m_pFileStream) << (BYTE)8;
|
|
|
|
(*m_pFileStream) << (BYTE)0;
|
|
|
|
nRecLength += 8;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
bCreateMemo = TRUE;
|
|
|
|
(*m_pFileStream) << (BYTE)10;
|
|
|
|
(*m_pFileStream) << (BYTE)0;
|
2000-09-18 15:18:56 +00:00
|
|
|
nRecLength += 10;
|
2005-10-24 07:20:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-10-01 12:28:29 +00:00
|
|
|
throwInvalidColumnType(STR_INVALID_COLUMN_TYPE, aName);
|
2005-10-24 07:20:50 +00:00
|
|
|
}
|
|
|
|
m_pFileStream->Write(aBuffer, 14);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
(*m_pFileStream) << (BYTE)0x0d; // kopf ende
|
|
|
|
m_pFileStream->Seek(10L);
|
|
|
|
(*m_pFileStream) << nRecLength; // Satzlaenge nachtraeglich eintragen
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
if (bCreateMemo)
|
|
|
|
{
|
|
|
|
m_pFileStream->Seek(0L);
|
|
|
|
(*m_pFileStream) << (BYTE) dBaseIIIMemo;
|
|
|
|
} // if (bCreateMemo)
|
|
|
|
}
|
2006-07-10 13:25:43 +00:00
|
|
|
catch ( const Exception& e )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-07-10 13:25:43 +00:00
|
|
|
(void)e;
|
|
|
|
|
2005-10-24 07:20:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// we have to drop the file because it is corrupted now
|
|
|
|
DropImpl();
|
|
|
|
}
|
2006-07-10 13:25:43 +00:00
|
|
|
catch(const Exception&) { }
|
2006-03-29 11:15:02 +00:00
|
|
|
throw;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2005-02-16 16:24:00 +00:00
|
|
|
// erzeugt grundsaetzlich dBase III Datei Format
|
2000-09-18 15:18:56 +00:00
|
|
|
BOOL ODbaseTable::CreateMemoFile(const INetURLObject& aFile)
|
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
// Makro zum Filehandling fuers Erzeugen von Tabellen
|
2001-07-17 11:37:19 +00:00
|
|
|
m_pMemoStream = createStream_simpleError( aFile.GetMainURL(INetURLObject::NO_DECODE),STREAM_READWRITE | STREAM_SHARE_DENYWRITE);
|
2000-11-16 09:47:23 +00:00
|
|
|
|
|
|
|
if (!m_pMemoStream)
|
2000-09-29 14:30:09 +00:00
|
|
|
return sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
char aBuffer[512]; // write buffer
|
|
|
|
memset(aBuffer,0,sizeof(aBuffer));
|
|
|
|
|
|
|
|
#ifdef WIN
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(0L);
|
2000-09-18 15:18:56 +00:00
|
|
|
for (UINT16 i = 0; i < 512; i++)
|
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
(*m_pMemoStream) << BYTE(0);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
#else
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->SetFiller('\0');
|
|
|
|
m_pMemoStream->SetStreamSize(512);
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(0L);
|
|
|
|
(*m_pMemoStream) << long(1); // Zeiger auf ersten freien Block
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Flush();
|
|
|
|
delete m_pMemoStream;
|
|
|
|
m_pMemoStream = NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
2001-08-10 10:05:34 +00:00
|
|
|
BOOL ODbaseTable::Drop_Static(const ::rtl::OUString& _sUrl,sal_Bool _bHasMemoFields,OCollection* _pIndexes )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
INetURLObject aURL;
|
2001-08-10 10:05:34 +00:00
|
|
|
aURL.SetURL(_sUrl);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-07-19 14:52:31 +00:00
|
|
|
BOOL bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-07-19 14:52:31 +00:00
|
|
|
if(bDropped)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-10 10:05:34 +00:00
|
|
|
if (_bHasMemoFields)
|
2001-06-29 07:29:14 +00:00
|
|
|
{ // delete the memo fields
|
|
|
|
aURL.setExtension(String::CreateFromAscii("dbt"));
|
2001-07-16 08:58:40 +00:00
|
|
|
bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE));
|
2001-06-29 07:29:14 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
if(bDropped)
|
2001-03-28 10:32:43 +00:00
|
|
|
{
|
2001-08-10 10:05:34 +00:00
|
|
|
if(_pIndexes)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
2001-10-19 06:30:39 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
sal_Int32 i = _pIndexes->getCount();
|
|
|
|
while (i)
|
|
|
|
{
|
|
|
|
_pIndexes->dropByIndex(--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(SQLException)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// aFile.SetBase(m_Name);
|
|
|
|
aURL.setExtension(String::CreateFromAscii("inf"));
|
2001-07-16 14:13:25 +00:00
|
|
|
|
|
|
|
// as the inf file does not necessarily exist, we aren't allowed to use UCBContentHelper::Kill
|
|
|
|
// 89711 - 16.07.2001 - frank.schoenheit@sun.com
|
|
|
|
try
|
|
|
|
{
|
2007-06-05 13:21:31 +00:00
|
|
|
::ucbhelper::Content aDeleteContent( aURL.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment > () );
|
2001-07-16 14:13:25 +00:00
|
|
|
aDeleteContent.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) );
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
// silently ignore this ....
|
|
|
|
}
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2001-08-10 10:05:34 +00:00
|
|
|
return bDropped;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::DropImpl()
|
|
|
|
{
|
|
|
|
FileClose();
|
|
|
|
|
2001-10-19 06:30:39 +00:00
|
|
|
if(!m_pIndexes)
|
|
|
|
refreshIndexes(); // look for indexes which must be deleted as well
|
2001-08-10 10:05:34 +00:00
|
|
|
|
|
|
|
BOOL bDropped = Drop_Static(getEntry(m_pConnection,m_Name),HasMemoFields(),m_pIndexes);
|
2001-06-29 07:29:14 +00:00
|
|
|
if(!bDropped)
|
|
|
|
{// we couldn't drop the table so we have to reopen it
|
|
|
|
construct();
|
|
|
|
if(m_pColumns)
|
|
|
|
m_pColumns->refresh();
|
|
|
|
}
|
|
|
|
return bDropped;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
2003-09-04 07:24:07 +00:00
|
|
|
BOOL ODbaseTable::InsertRow(OValueRefVector& rRow, BOOL bFlush,const Reference<XIndexAccess>& _xCols)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
// Buffer mit Leerzeichen fuellen
|
2000-09-18 15:18:56 +00:00
|
|
|
AllocBuffer();
|
|
|
|
memset(m_pBuffer, ' ', m_aHeader.db_slng);
|
|
|
|
|
|
|
|
// Gesamte neue Row uebernehmen:
|
|
|
|
// ... und am Ende als neuen Record hinzufuegen:
|
|
|
|
UINT32 nTempPos = m_nFilePos,
|
2006-06-20 00:21:12 +00:00
|
|
|
nFileSize = 0,
|
|
|
|
nMemoFileSize = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
m_nFilePos = (ULONG)m_aHeader.db_anz + 1;
|
2006-06-20 00:21:12 +00:00
|
|
|
BOOL bInsertRow = UpdateBuffer( rRow, NULL, _xCols );
|
|
|
|
if ( bInsertRow )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-06-29 07:29:14 +00:00
|
|
|
m_pFileStream->Seek(STREAM_SEEK_TO_END);
|
|
|
|
nFileSize = m_pFileStream->Tell();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
if (HasMemoFields() && m_pMemoStream)
|
|
|
|
{
|
|
|
|
m_pMemoStream->Seek(STREAM_SEEK_TO_END);
|
|
|
|
nMemoFileSize = m_pMemoStream->Tell();
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
if (!WriteBuffer())
|
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
m_pFileStream->SetStreamSize(nFileSize); // alte Groesse restaurieren
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
if (HasMemoFields() && m_pMemoStream)
|
2005-02-16 16:24:00 +00:00
|
|
|
m_pMemoStream->SetStreamSize(nMemoFileSize); // alte Groesse restaurieren
|
2001-06-29 07:29:14 +00:00
|
|
|
m_nFilePos = nTempPos; // Fileposition restaurieren
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Anzahl Datensaetze im Header erhoehen:
|
|
|
|
m_pFileStream->Seek( 4L );
|
|
|
|
(*m_pFileStream) << (m_aHeader.db_anz + 1);
|
|
|
|
|
|
|
|
// beim AppendOnly kein Flush!
|
|
|
|
if (bFlush)
|
|
|
|
m_pFileStream->Flush();
|
|
|
|
|
2005-02-16 16:24:00 +00:00
|
|
|
// bei Erfolg # erhoehen
|
2001-06-29 07:29:14 +00:00
|
|
|
m_aHeader.db_anz++;
|
2008-12-30 13:32:01 +00:00
|
|
|
*rRow.get()[0] = m_nFilePos; // BOOKmark setzen
|
2001-06-29 07:29:14 +00:00
|
|
|
m_nFilePos = nTempPos;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m_nFilePos = nTempPos;
|
|
|
|
|
2003-12-01 09:47:51 +00:00
|
|
|
return bInsertRow;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2003-09-04 07:24:07 +00:00
|
|
|
BOOL ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const Reference<XIndexAccess>& _xCols)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2005-02-16 16:24:00 +00:00
|
|
|
// Buffer mit Leerzeichen fuellen
|
2000-09-18 15:18:56 +00:00
|
|
|
AllocBuffer();
|
|
|
|
|
|
|
|
// Auf gewuenschten Record positionieren:
|
|
|
|
long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng;
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Seek(nPos);
|
|
|
|
m_pFileStream->Read((char*)m_pBuffer, m_aHeader.db_slng);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-06-20 00:21:12 +00:00
|
|
|
UINT32 nMemoFileSize( 0 );
|
2000-11-16 09:47:23 +00:00
|
|
|
if (HasMemoFields() && m_pMemoStream)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pMemoStream->Seek(STREAM_SEEK_TO_END);
|
|
|
|
nMemoFileSize = m_pMemoStream->Tell();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
if (!UpdateBuffer(rRow, pOrgRow,_xCols) || !WriteBuffer())
|
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
if (HasMemoFields() && m_pMemoStream)
|
2005-02-16 16:24:00 +00:00
|
|
|
m_pMemoStream->SetStreamSize(nMemoFileSize); // alte Groesse restaurieren
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Flush();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::DeleteRow(const OSQLColumns& _rCols)
|
|
|
|
{
|
|
|
|
// Einfach das Loesch-Flag setzen (egal, ob es schon gesetzt war
|
|
|
|
// oder nicht):
|
|
|
|
// Auf gewuenschten Record positionieren:
|
2001-08-24 05:05:37 +00:00
|
|
|
long nFilePos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng;
|
|
|
|
m_pFileStream->Seek(nFilePos);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
OValueRefRow aRow = new OValueRefVector(_rCols.get().size());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-11-27 07:00:26 +00:00
|
|
|
if (!fetchRow(aRow,_rCols,TRUE,TRUE))
|
2000-09-29 14:30:09 +00:00
|
|
|
return sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-10-30 07:07:33 +00:00
|
|
|
Reference<XPropertySet> xCol;
|
2000-09-18 15:18:56 +00:00
|
|
|
::rtl::OUString aColName;
|
2000-10-11 09:48:50 +00:00
|
|
|
::comphelper::UStringMixEqual aCase(isCaseSensitive());
|
2000-09-18 15:18:56 +00:00
|
|
|
for (USHORT i = 0; i < m_pColumns->getCount(); i++)
|
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
Reference<XPropertySet> xIndex = isUniqueByColumnName(i);
|
|
|
|
if (xIndex.is())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
::cppu::extractInterface(xCol,m_pColumns->getByIndex(i));
|
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::DeleteRow column is null!");
|
|
|
|
if(xCol.is())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
|
|
|
|
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
|
2006-06-20 00:21:12 +00:00
|
|
|
ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
|
2001-06-29 07:29:14 +00:00
|
|
|
OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!");
|
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin();
|
2001-08-24 05:05:37 +00:00
|
|
|
sal_Int32 nPos = 1;
|
2008-12-30 13:32:01 +00:00
|
|
|
for(;aIter != _rCols.get().end();++aIter,++nPos)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
|
|
|
if(aCase(getString((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))),aColName))
|
|
|
|
break;
|
|
|
|
}
|
2008-12-30 13:32:01 +00:00
|
|
|
if (aIter == _rCols.get().end())
|
2001-06-29 07:29:14 +00:00
|
|
|
continue;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
pIndex->Delete(m_nFilePos,*(aRow->get())[nPos]);
|
2001-06-29 07:29:14 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
m_pFileStream->Seek(nFilePos);
|
2001-06-29 07:29:14 +00:00
|
|
|
(*m_pFileStream) << (BYTE)'*'; // mark the row in the table as deleted
|
2000-11-16 09:47:23 +00:00
|
|
|
m_pFileStream->Flush();
|
2001-08-24 05:05:37 +00:00
|
|
|
return sal_True;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-08-24 05:05:37 +00:00
|
|
|
Reference<XPropertySet> ODbaseTable::isUniqueByColumnName(sal_Int32 _nColumnPos)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
if(!m_pIndexes)
|
|
|
|
refreshIndexes();
|
2001-08-24 05:05:37 +00:00
|
|
|
if(m_pIndexes->hasElements())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
Reference<XPropertySet> xCol;
|
|
|
|
m_pColumns->getByIndex(_nColumnPos) >>= xCol;
|
2003-12-01 09:47:51 +00:00
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::isUniqueByColumnName column is null!");
|
2001-08-24 05:05:37 +00:00
|
|
|
::rtl::OUString sColName;
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sColName;
|
|
|
|
|
|
|
|
Reference<XPropertySet> xIndex;
|
|
|
|
for(sal_Int32 i=0;i<m_pIndexes->getCount();++i)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
::cppu::extractInterface(xIndex,m_pIndexes->getByIndex(i));
|
|
|
|
if(xIndex.is() && getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))
|
|
|
|
{
|
|
|
|
Reference<XNameAccess> xCols(Reference<XColumnsSupplier>(xIndex,UNO_QUERY)->getColumns());
|
|
|
|
if(xCols->hasByName(sColName))
|
|
|
|
return xIndex;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-30 07:07:33 +00:00
|
|
|
return Reference<XPropertySet>();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
double toDouble(const ByteString& rString)
|
|
|
|
{
|
2003-03-19 15:38:50 +00:00
|
|
|
return ::rtl::math::stringToDouble( rString, '.', ',', NULL, NULL );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2003-09-04 07:24:07 +00:00
|
|
|
BOOL ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const Reference<XIndexAccess>& _xCols)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-01-16 14:03:59 +00:00
|
|
|
OSL_ENSURE(m_pBuffer,"Buffer is NULL!");
|
|
|
|
if ( !m_pBuffer )
|
|
|
|
return FALSE;
|
2001-03-01 09:51:00 +00:00
|
|
|
sal_Int32 nByteOffset = 1;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
// Felder aktualisieren:
|
2000-10-30 07:07:33 +00:00
|
|
|
Reference<XPropertySet> xCol;
|
|
|
|
Reference<XPropertySet> xIndex;
|
2000-09-18 15:18:56 +00:00
|
|
|
USHORT i;
|
|
|
|
::rtl::OUString aColName;
|
2001-08-24 05:05:37 +00:00
|
|
|
sal_Int32 nColumnCount = m_pColumns->getCount();
|
|
|
|
::std::vector< Reference<XPropertySet> > aIndexedCols(nColumnCount);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2000-10-11 09:48:50 +00:00
|
|
|
::comphelper::UStringMixEqual aCase(isCaseSensitive());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
Reference<XIndexAccess> xColumns = m_pColumns;
|
2000-09-18 15:18:56 +00:00
|
|
|
// first search a key that exist already in the table
|
2001-08-24 05:05:37 +00:00
|
|
|
for (i = 0; i < nColumnCount; ++i)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
sal_Int32 nPos = i;
|
|
|
|
if(_xCols != xColumns)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!");
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
|
|
|
|
|
|
|
for(nPos = 0;nPos<_xCols->getCount();++nPos)
|
|
|
|
{
|
|
|
|
Reference<XPropertySet> xFindCol;
|
|
|
|
::cppu::extractInterface(xFindCol,_xCols->getByIndex(nPos));
|
|
|
|
OSL_ENSURE(xFindCol.is(),"ODbaseTable::UpdateBuffer column is null!");
|
|
|
|
if(aCase(getString(xFindCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),aColName))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nPos >= _xCols->getCount())
|
|
|
|
continue;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++nPos;
|
2001-08-24 05:05:37 +00:00
|
|
|
xIndex = isUniqueByColumnName(i);
|
2000-09-18 15:18:56 +00:00
|
|
|
aIndexedCols[i] = xIndex;
|
|
|
|
if (xIndex.is())
|
|
|
|
{
|
2000-09-29 14:30:09 +00:00
|
|
|
// first check if the value is different to the old one and when if it conform to the index
|
2008-12-30 13:32:01 +00:00
|
|
|
if(pOrgRow.isValid() && (rRow.get()[nPos]->getValue().isNull() || rRow.get()[nPos] == (pOrgRow->get())[nPos]))
|
2000-09-18 15:18:56 +00:00
|
|
|
continue;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ODbVariantRef xVar = (pVal == NULL) ? new ODbVariant() : pVal;
|
|
|
|
Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
|
2001-02-14 06:22:50 +00:00
|
|
|
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
|
2006-06-20 00:21:12 +00:00
|
|
|
ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
|
2001-02-14 06:22:50 +00:00
|
|
|
OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!");
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
if (pIndex->Find(0,*rRow.get()[nPos]))
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// es existiert kein eindeutiger Wert
|
2003-05-19 11:58:42 +00:00
|
|
|
if ( !aColName.getLength() )
|
|
|
|
{
|
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!");
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
|
|
|
xCol = NULL;
|
2008-10-01 12:28:29 +00:00
|
|
|
} // if ( !aColName.getLength() )
|
|
|
|
throwInvalidColumnType(STR_DUPLICATE_VALUE_IN_COLUMN,aColName);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// when we are here there is no double key in the table
|
|
|
|
|
2006-01-16 14:03:59 +00:00
|
|
|
for (i = 0; i < nColumnCount && nByteOffset <= m_nBufferSize ; ++i)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
// Laengen je nach Datentyp:
|
2003-12-01 09:47:51 +00:00
|
|
|
OSL_ENSURE(i < m_aPrecisions.size(),"Illegal index!");
|
|
|
|
sal_Int32 nLen = 0;
|
|
|
|
sal_Int32 nType = 0;
|
|
|
|
sal_Int32 nScale = 0;
|
|
|
|
if ( i < m_aPrecisions.size() )
|
|
|
|
{
|
|
|
|
nLen = m_aPrecisions[i];
|
|
|
|
nType = m_aTypes[i];
|
|
|
|
nScale = m_aScales[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
|
|
|
if ( xCol.is() )
|
|
|
|
{
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen;
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale;
|
|
|
|
}
|
|
|
|
}
|
2001-07-30 07:53:02 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case DataType::DATE: nLen = 8; break;
|
|
|
|
case DataType::DECIMAL:
|
2003-12-01 09:47:51 +00:00
|
|
|
nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,nScale);
|
2000-09-18 15:18:56 +00:00
|
|
|
break; // das Vorzeichen und das Komma
|
2001-06-29 07:29:14 +00:00
|
|
|
case DataType::BIT: nLen = 1; break;
|
|
|
|
case DataType::LONGVARCHAR: nLen = 10; break;
|
2000-09-18 15:18:56 +00:00
|
|
|
default: break;
|
|
|
|
|
2008-12-10 13:41:25 +00:00
|
|
|
} // switch (nType)
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
sal_Int32 nPos = i;
|
|
|
|
if(_xCols != xColumns)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!");
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
|
|
|
for(nPos = 0;nPos<_xCols->getCount();++nPos)
|
|
|
|
{
|
|
|
|
Reference<XPropertySet> xFindCol;
|
|
|
|
::cppu::extractInterface(xFindCol,_xCols->getByIndex(nPos));
|
|
|
|
if(aCase(getString(xFindCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),aColName))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nPos >= _xCols->getCount())
|
|
|
|
{
|
|
|
|
nByteOffset += nLen;
|
|
|
|
continue;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2001-08-24 05:05:37 +00:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
++nPos; // the row values start at 1
|
2001-05-11 05:14:11 +00:00
|
|
|
// Ist die Variable ueberhaupt gebunden?
|
2008-12-30 13:32:01 +00:00
|
|
|
if ( !rRow.get()[nPos]->isBound() )
|
2001-05-11 05:14:11 +00:00
|
|
|
{
|
|
|
|
// Nein - naechstes Feld.
|
|
|
|
nByteOffset += nLen;
|
|
|
|
continue;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
if (aIndexedCols[i].is())
|
|
|
|
{
|
|
|
|
Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY);
|
2001-02-14 06:22:50 +00:00
|
|
|
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
|
2006-06-20 00:21:12 +00:00
|
|
|
ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) );
|
2001-02-14 06:22:50 +00:00
|
|
|
OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!");
|
2000-09-18 15:18:56 +00:00
|
|
|
// Update !!
|
2008-12-30 13:32:01 +00:00
|
|
|
if (pOrgRow.isValid() && !rRow.get()[nPos]->getValue().isNull() )//&& pVal->isModified())
|
|
|
|
pIndex->Update(m_nFilePos,*(pOrgRow->get())[nPos],*rRow.get()[nPos]);
|
2000-09-18 15:18:56 +00:00
|
|
|
else
|
2008-12-30 13:32:01 +00:00
|
|
|
pIndex->Insert(m_nFilePos,*rRow.get()[nPos]);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char* pData = (char *)(m_pBuffer + nByteOffset);
|
2008-12-30 13:32:01 +00:00
|
|
|
if (rRow.get()[nPos]->getValue().isNull())
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
memset(pData,' ',nLen); // Zuruecksetzen auf NULL
|
|
|
|
nByteOffset += nLen;
|
2006-01-16 14:03:59 +00:00
|
|
|
OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!");
|
2000-09-18 15:18:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-08-28 07:58:03 +00:00
|
|
|
|
|
|
|
sal_Bool bHadError = sal_False;
|
2000-09-18 15:18:56 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case DataType::DATE:
|
|
|
|
{
|
2000-12-06 11:07:47 +00:00
|
|
|
::com::sun::star::util::Date aDate;
|
2008-12-30 13:32:01 +00:00
|
|
|
if(rRow.get()[nPos]->getValue().getTypeKind() == DataType::DOUBLE)
|
|
|
|
aDate = ::dbtools::DBTypeConversion::toDate(rRow.get()[nPos]->getValue().getDouble());
|
2000-12-06 11:07:47 +00:00
|
|
|
else
|
2008-12-30 13:32:01 +00:00
|
|
|
aDate = rRow.get()[nPos]->getValue();
|
2000-09-18 15:18:56 +00:00
|
|
|
char s[9];
|
2003-03-19 15:38:50 +00:00
|
|
|
snprintf(s,
|
|
|
|
sizeof(s),
|
|
|
|
"%04d%02d%02d",
|
2000-09-18 15:18:56 +00:00
|
|
|
(int)aDate.Year,
|
|
|
|
(int)aDate.Month,
|
|
|
|
(int)aDate.Day);
|
|
|
|
|
|
|
|
// Genau 8 Byte kopieren:
|
|
|
|
strncpy(pData,s,sizeof s - 1);
|
|
|
|
} break;
|
|
|
|
case DataType::DECIMAL:
|
|
|
|
{
|
|
|
|
memset(pData,' ',nLen); // Zuruecksetzen auf NULL
|
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
const double n = rRow.get()[nPos]->getValue();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
// ein const_cast, da GetFormatPrecision am SvNumberFormat nicht const ist, obwohl es das eigentlich
|
|
|
|
// sein koennte und muesste
|
|
|
|
|
2008-10-01 12:28:29 +00:00
|
|
|
const ByteString aDefaultValue( ::rtl::math::doubleToString( n, rtl_math_StringFormat_F, nScale, '.', NULL, 0));
|
2008-12-10 13:41:25 +00:00
|
|
|
BOOL bValidLength = aDefaultValue.Len() <= nLen;
|
2008-05-05 13:50:20 +00:00
|
|
|
if ( bValidLength )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2008-12-10 13:41:25 +00:00
|
|
|
strncpy(pData,aDefaultValue.GetBuffer(),nLen);
|
|
|
|
// write the resulting double back
|
2008-12-30 13:32:01 +00:00
|
|
|
*rRow.get()[nPos] = toDouble(aDefaultValue);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2008-12-10 13:41:25 +00:00
|
|
|
else
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2003-12-01 09:47:51 +00:00
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
|
|
|
OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!");
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
2008-12-10 13:41:25 +00:00
|
|
|
::std::list< ::std::pair<const sal_Char* , ::rtl::OUString > > aStringToSubstitutes;
|
|
|
|
aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$columnname$", aColName));
|
|
|
|
aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$precision$", String::CreateFromInt32(nLen)));
|
|
|
|
aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$scale$", String::CreateFromInt32(nScale)));
|
|
|
|
aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$value$", ::rtl::OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8)));
|
2003-12-01 09:47:51 +00:00
|
|
|
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
2008-12-10 13:41:25 +00:00
|
|
|
STR_INVALID_COLUMN_DECIMAL_VALUE
|
|
|
|
,aStringToSubstitutes
|
2008-10-01 12:28:29 +00:00
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case DataType::BIT:
|
2008-12-30 13:32:01 +00:00
|
|
|
*pData = rRow.get()[nPos]->getValue().getBool() ? 'T' : 'F';
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
case DataType::LONGVARCHAR:
|
|
|
|
{
|
|
|
|
char cNext = pData[nLen]; // merken und temporaer durch 0 ersetzen
|
|
|
|
pData[nLen] = '\0'; // das geht, da der Puffer immer ein Zeichen groesser ist ...
|
|
|
|
|
|
|
|
ULONG nBlockNo = strtol((const char *)pData,NULL,10); // Blocknummer lesen
|
|
|
|
|
|
|
|
// Naechstes Anfangszeichen wieder restaurieren:
|
|
|
|
pData[nLen] = cNext;
|
2008-12-30 13:32:01 +00:00
|
|
|
if (!m_pMemoStream || !WriteMemo(rRow.get()[nPos]->get(), nBlockNo))
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
ByteString aStr;
|
|
|
|
ByteString aBlock(ByteString::CreateFromInt32(nBlockNo));
|
2004-03-15 11:46:15 +00:00
|
|
|
aStr.Expand(static_cast<sal_uInt16>(nLen - aBlock.Len()), '0' );
|
2000-09-18 15:18:56 +00:00
|
|
|
aStr += aBlock;
|
|
|
|
// Zeichen kopieren:
|
|
|
|
memset(pData,' ',nLen); // Zuruecksetzen auf NULL
|
|
|
|
memcpy(pData, aStr.GetBuffer(), nLen);
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
memset(pData,' ',nLen); // Zuruecksetzen auf NULL
|
2004-11-17 13:05:48 +00:00
|
|
|
|
2008-12-30 13:32:01 +00:00
|
|
|
::rtl::OUString sStringToWrite( rRow.get()[nPos]->getValue().getString() );
|
2004-11-17 13:05:48 +00:00
|
|
|
|
|
|
|
// convert the string, using the connection's encoding
|
|
|
|
::rtl::OString sEncoded;
|
2008-06-06 12:20:24 +00:00
|
|
|
|
|
|
|
DBTypeConversion::convertUnicodeStringToLength( sStringToWrite, sEncoded, nLen, m_eEncoding );
|
2006-12-13 15:16:24 +00:00
|
|
|
memcpy( pData, sEncoded.getStr(), sEncoded.getLength() );
|
2004-11-17 13:05:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-10 13:41:25 +00:00
|
|
|
catch( SQLException& )
|
2007-01-25 10:00:45 +00:00
|
|
|
{
|
2008-12-10 13:41:25 +00:00
|
|
|
throw;
|
2007-01-25 10:00:45 +00:00
|
|
|
}
|
2001-08-28 07:58:03 +00:00
|
|
|
catch ( Exception& ) { bHadError = sal_True; }
|
|
|
|
|
|
|
|
if ( bHadError )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2001-08-24 05:05:37 +00:00
|
|
|
m_pColumns->getByIndex(i) >>= xCol;
|
2004-11-17 13:05:48 +00:00
|
|
|
OSL_ENSURE( xCol.is(), "ODbaseTable::UpdateBuffer column is null!" );
|
|
|
|
if ( xCol.is() )
|
|
|
|
xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
|
2001-08-24 05:05:37 +00:00
|
|
|
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_INVALID_COLUMN_VALUE,
|
|
|
|
"$columnname$", aColName
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// Und weiter ...
|
|
|
|
nByteOffset += nLen;
|
2006-01-16 14:03:59 +00:00
|
|
|
OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!");
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return sal_True;
|
|
|
|
}
|
2004-11-17 13:05:48 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::WriteMemo(ORowSetValue& aVariable, ULONG& rBlockNr)
|
|
|
|
{
|
|
|
|
// wird die BlockNr 0 vorgegeben, wird der block ans Ende gehaengt
|
|
|
|
|
|
|
|
BYTE nHeader[4];
|
|
|
|
|
|
|
|
::rtl::OUString sStringToWrite( aVariable.getString() );
|
|
|
|
::rtl::OString aStr;
|
2008-06-06 12:20:24 +00:00
|
|
|
ULONG nSize = DBTypeConversion::convertUnicodeString( sStringToWrite, aStr, m_eEncoding );
|
2004-11-17 13:05:48 +00:00
|
|
|
|
|
|
|
// Anhaengen oder ueberschreiben
|
|
|
|
BOOL bAppend = rBlockNr == 0;
|
|
|
|
|
|
|
|
if (!bAppend)
|
|
|
|
{
|
|
|
|
switch (m_aMemoHeader.db_typ)
|
|
|
|
{
|
|
|
|
case MemodBaseIII: // dBase III-Memofeld, endet mit 2 * Ctrl-Z
|
|
|
|
bAppend = nSize > (512 - 2);
|
|
|
|
break;
|
|
|
|
case MemoFoxPro:
|
|
|
|
case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe
|
|
|
|
{
|
|
|
|
char sHeader[4];
|
|
|
|
m_pMemoStream->Seek(rBlockNr * m_aMemoHeader.db_size);
|
|
|
|
m_pMemoStream->SeekRel(4L);
|
|
|
|
m_pMemoStream->Read(sHeader,4);
|
|
|
|
|
|
|
|
ULONG nOldSize;
|
|
|
|
if (m_aMemoHeader.db_typ == MemoFoxPro)
|
|
|
|
nOldSize = ((((unsigned char)sHeader[0]) * 256 +
|
|
|
|
(unsigned char)sHeader[1]) * 256 +
|
|
|
|
(unsigned char)sHeader[2]) * 256 +
|
|
|
|
(unsigned char)sHeader[3];
|
|
|
|
else
|
|
|
|
nOldSize = ((((unsigned char)sHeader[3]) * 256 +
|
|
|
|
(unsigned char)sHeader[2]) * 256 +
|
|
|
|
(unsigned char)sHeader[1]) * 256 +
|
|
|
|
(unsigned char)sHeader[0] - 8;
|
|
|
|
|
|
|
|
// passt die neue Laenge in die belegten Bloecke
|
|
|
|
ULONG nUsedBlocks = ((nSize + 8) / m_aMemoHeader.db_size) + (((nSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0),
|
|
|
|
nOldUsedBlocks = ((nOldSize + 8) / m_aMemoHeader.db_size) + (((nOldSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0);
|
|
|
|
bAppend = nUsedBlocks > nOldUsedBlocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bAppend)
|
|
|
|
{
|
2006-06-20 00:21:12 +00:00
|
|
|
ULONG nStreamSize = m_pMemoStream->Seek(STREAM_SEEK_TO_END);
|
2004-11-17 13:05:48 +00:00
|
|
|
// letzten block auffuellen
|
|
|
|
rBlockNr = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0);
|
|
|
|
|
|
|
|
m_pMemoStream->SetStreamSize(rBlockNr * m_aMemoHeader.db_size);
|
|
|
|
m_pMemoStream->Seek(STREAM_SEEK_TO_END);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pMemoStream->Seek(rBlockNr * m_aMemoHeader.db_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_aMemoHeader.db_typ)
|
|
|
|
{
|
|
|
|
case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z
|
|
|
|
{
|
|
|
|
const char cEOF = (char) 0x1a;
|
|
|
|
nSize++;
|
|
|
|
|
|
|
|
// if (pData)
|
|
|
|
// {
|
|
|
|
// m_pMemoStream->Write((const char*) pData->getConstArray(), pData->getLength());
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
m_pMemoStream->Write( aStr.getStr(), aStr.getLength() );
|
|
|
|
// }
|
|
|
|
|
|
|
|
(*m_pMemoStream) << cEOF << cEOF;
|
|
|
|
} break;
|
|
|
|
case MemoFoxPro:
|
|
|
|
case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe
|
|
|
|
{
|
|
|
|
(*m_pMemoStream) << (BYTE)0xFF
|
|
|
|
<< (BYTE)0xFF
|
|
|
|
<< (BYTE)0x08;
|
|
|
|
|
|
|
|
UINT32 nWriteSize = nSize;
|
|
|
|
if (m_aMemoHeader.db_typ == MemoFoxPro)
|
|
|
|
{
|
|
|
|
(*m_pMemoStream) << (BYTE) 0x01; // ((pData = NULL) ? 0x01 : 0x00);
|
|
|
|
for (int i = 4; i > 0; nWriteSize >>= 8)
|
|
|
|
nHeader[--i] = (BYTE) (nWriteSize % 256);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(*m_pMemoStream) << (BYTE) 0x00;
|
|
|
|
nWriteSize += 8;
|
|
|
|
for (int i = 0; i < 4; nWriteSize >>= 8)
|
|
|
|
nHeader[i++] = (BYTE) (nWriteSize % 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pMemoStream->Write(nHeader,4);
|
|
|
|
// if (pData)
|
|
|
|
// {
|
|
|
|
// m_pMemoStream->Write((const char*) pData->getConstArray(), pData->getLength());
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
m_pMemoStream->Write( aStr.getStr(), aStr.getLength() );
|
|
|
|
// }
|
|
|
|
m_pMemoStream->Flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Schreiben der neuen Blocknummer
|
|
|
|
if (bAppend)
|
|
|
|
{
|
2006-06-20 00:21:12 +00:00
|
|
|
ULONG nStreamSize = m_pMemoStream->Seek(STREAM_SEEK_TO_END);
|
2004-11-17 13:05:48 +00:00
|
|
|
m_aMemoHeader.db_next = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0);
|
|
|
|
|
|
|
|
// Schreiben der neuen Blocknummer
|
|
|
|
m_pMemoStream->Seek(0L);
|
|
|
|
(*m_pMemoStream) << m_aMemoHeader.db_next;
|
|
|
|
m_pMemoStream->Flush();
|
|
|
|
}
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
|
2000-10-30 07:07:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-03-28 10:32:43 +00:00
|
|
|
// XAlterTable
|
|
|
|
void SAL_CALL ODbaseTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
2001-05-17 05:46:55 +00:00
|
|
|
checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
|
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
|
|
|
|
Reference<XDataDescriptorFactory> xOldColumn;
|
|
|
|
m_pColumns->getByName(colName) >>= xOldColumn;
|
|
|
|
|
2001-05-30 09:44:16 +00:00
|
|
|
alterColumn(m_pColumns->findColumn(colName)-1,descriptor,xOldColumn);
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL ODbaseTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
2001-05-17 05:46:55 +00:00
|
|
|
checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
|
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
if(index < 0 || index >= m_pColumns->getCount())
|
2001-03-30 11:07:07 +00:00
|
|
|
throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
|
|
|
Reference<XDataDescriptorFactory> xOldColumn;
|
|
|
|
m_pColumns->getByIndex(index) >>= xOldColumn;
|
|
|
|
alterColumn(index,descriptor,xOldColumn);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::alterColumn(sal_Int32 index,
|
|
|
|
const Reference< XPropertySet >& descriptor ,
|
|
|
|
const Reference< XDataDescriptorFactory >& xOldColumn )
|
|
|
|
{
|
|
|
|
if(index < 0 || index >= m_pColumns->getCount())
|
2001-03-30 11:07:07 +00:00
|
|
|
throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
ODbaseTable* pNewTable = NULL;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
OSL_ENSURE(descriptor.is(),"ODbaseTable::alterColumn: descriptor can not be null!");
|
|
|
|
// creates a copy of the the original column and copy all properties from descriptor in xCopyColumn
|
|
|
|
Reference<XPropertySet> xCopyColumn;
|
|
|
|
if(xOldColumn.is())
|
|
|
|
xCopyColumn = xOldColumn->createDataDescriptor();
|
|
|
|
else
|
|
|
|
xCopyColumn = new OColumn(getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers());
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
::comphelper::copyProperties(descriptor,xCopyColumn);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
// creates a temp file
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
String sTempName = createTempFile();
|
|
|
|
|
2001-09-25 12:12:51 +00:00
|
|
|
pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection));
|
2001-06-29 07:29:14 +00:00
|
|
|
Reference<XPropertySet> xHoldTable = pNewTable;
|
|
|
|
pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName)));
|
|
|
|
Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY);
|
|
|
|
OSL_ENSURE(xAppend.is(),"ODbaseTable::alterColumn: No XAppend interface!");
|
|
|
|
|
|
|
|
// copy the structure
|
|
|
|
sal_Int32 i=0;
|
|
|
|
for(;i < index;++i)
|
2001-05-28 12:03:37 +00:00
|
|
|
{
|
2001-06-29 07:29:14 +00:00
|
|
|
Reference<XPropertySet> xProp;
|
|
|
|
m_pColumns->getByIndex(i) >>= xProp;
|
|
|
|
Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY);
|
|
|
|
Reference<XPropertySet> xCpy;
|
|
|
|
if(xColumn.is())
|
|
|
|
xCpy = xColumn->createDataDescriptor();
|
|
|
|
else
|
|
|
|
xCpy = new OColumn(getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers());
|
2001-10-15 12:22:24 +00:00
|
|
|
::comphelper::copyProperties(xProp,xCpy);
|
2001-06-29 07:29:14 +00:00
|
|
|
xAppend->appendByDescriptor(xCpy);
|
2001-05-28 12:03:37 +00:00
|
|
|
}
|
2001-06-29 07:29:14 +00:00
|
|
|
++i; // now insert our new column
|
|
|
|
xAppend->appendByDescriptor(xCopyColumn);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
for(;i < m_pColumns->getCount();++i)
|
2001-05-28 12:03:37 +00:00
|
|
|
{
|
2001-06-29 07:29:14 +00:00
|
|
|
Reference<XPropertySet> xProp;
|
|
|
|
m_pColumns->getByIndex(i) >>= xProp;
|
|
|
|
Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY);
|
|
|
|
Reference<XPropertySet> xCpy;
|
|
|
|
if(xColumn.is())
|
|
|
|
xCpy = xColumn->createDataDescriptor();
|
|
|
|
else
|
|
|
|
xCpy = new OColumn(getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers());
|
2001-10-15 12:22:24 +00:00
|
|
|
::comphelper::copyProperties(xProp,xCpy);
|
2001-06-29 07:29:14 +00:00
|
|
|
xAppend->appendByDescriptor(xCpy);
|
2001-05-28 12:03:37 +00:00
|
|
|
}
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
// construct the new table
|
|
|
|
if(!pNewTable->CreateImpl())
|
2002-07-05 07:02:12 +00:00
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_COLUMN_NOT_ALTERABLE,
|
|
|
|
"$columnname$", ::comphelper::getString(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2002-07-05 07:02:12 +00:00
|
|
|
}
|
2002-01-21 13:50:26 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
pNewTable->construct();
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
// copy the data
|
|
|
|
copyData(pNewTable,0);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
// now drop the old one
|
2002-05-10 10:09:45 +00:00
|
|
|
if( DropImpl() ) // we don't want to delete the memo columns too
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
|
|
|
// rename the new one to the old one
|
2001-10-12 11:02:56 +00:00
|
|
|
pNewTable->renameImpl(m_Name);
|
2001-06-29 07:29:14 +00:00
|
|
|
// release the temp file
|
|
|
|
pNewTable = NULL;
|
|
|
|
::comphelper::disposeComponent(xHoldTable);
|
|
|
|
}
|
|
|
|
else
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
|
|
|
pNewTable = NULL;
|
|
|
|
}
|
2001-06-29 07:29:14 +00:00
|
|
|
FileClose();
|
|
|
|
construct();
|
|
|
|
if(m_pColumns)
|
|
|
|
m_pColumns->refresh();
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
}
|
|
|
|
catch(const SQLException&)
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(0,"ODbaseTable::alterColumn: Exception occured!");
|
|
|
|
throw;
|
|
|
|
}
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
2004-08-02 16:01:01 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XDatabaseMetaData> ODbaseTable::getMetaData() const
|
|
|
|
{
|
|
|
|
return getConnection()->getMetaData();
|
|
|
|
}
|
2001-03-28 10:32:43 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL ODbaseTable::rename( const ::rtl::OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
2001-05-17 05:46:55 +00:00
|
|
|
checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
|
2001-09-25 12:12:51 +00:00
|
|
|
if(m_pTables && m_pTables->hasByName(newName))
|
|
|
|
throw ElementExistException(newName,*this);
|
2001-05-17 05:46:55 +00:00
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
|
2001-10-12 11:02:56 +00:00
|
|
|
renameImpl(newName);
|
2001-10-15 12:22:24 +00:00
|
|
|
|
|
|
|
ODbaseTable_BASE::rename(newName);
|
|
|
|
|
|
|
|
construct();
|
|
|
|
if(m_pColumns)
|
|
|
|
m_pColumns->refresh();
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
2002-05-10 10:09:45 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void renameFile(OConnection* _pConenction,const ::rtl::OUString& oldName,
|
|
|
|
const ::rtl::OUString& newName,const String& _sExtension)
|
|
|
|
{
|
|
|
|
String aName = ODbaseTable::getEntry(_pConenction,oldName);
|
|
|
|
if(!aName.Len())
|
|
|
|
{
|
|
|
|
::rtl::OUString aIdent = _pConenction->getContent()->getIdentifier()->getContentIdentifier();
|
2003-04-24 12:18:52 +00:00
|
|
|
if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) )
|
|
|
|
aIdent += ::rtl::OUString::createFromAscii("/");
|
2002-05-10 10:09:45 +00:00
|
|
|
aIdent += oldName;
|
|
|
|
aName = aIdent;
|
|
|
|
}
|
|
|
|
INetURLObject aURL;
|
|
|
|
aURL.SetURL(aName);
|
|
|
|
|
|
|
|
aURL.setExtension( _sExtension );
|
|
|
|
String sNewName(newName);
|
|
|
|
sNewName.AppendAscii(".");
|
|
|
|
sNewName += _sExtension;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>());
|
|
|
|
|
|
|
|
Sequence< PropertyValue > aProps( 1 );
|
|
|
|
aProps[0].Name = ::rtl::OUString::createFromAscii("Title");
|
|
|
|
aProps[0].Handle = -1; // n/a
|
|
|
|
aProps[0].Value = makeAny( ::rtl::OUString(sNewName) );
|
|
|
|
Sequence< Any > aValues;
|
|
|
|
aContent.executeCommand( rtl::OUString::createFromAscii( "setPropertyValues" ),makeAny(aProps) ) >>= aValues;
|
|
|
|
if(aValues.getLength() && aValues[0].hasValue())
|
|
|
|
throw Exception();
|
|
|
|
}
|
|
|
|
catch(Exception&)
|
|
|
|
{
|
|
|
|
throw ElementExistException(newName,NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-12 11:02:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL ODbaseTable::renameImpl( const ::rtl::OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_aMutex);
|
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
FileClose();
|
|
|
|
|
|
|
|
|
2002-05-10 10:09:45 +00:00
|
|
|
renameFile(m_pConnection,m_Name,newName,m_pConnection->getExtension());
|
|
|
|
if ( HasMemoFields() )
|
|
|
|
{ // delete the memo fields
|
|
|
|
String sExt = String::CreateFromAscii("dbt");
|
|
|
|
renameFile(m_pConnection,m_Name,newName,sExt);
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::addColumn(const Reference< XPropertySet >& _xNewColumn)
|
|
|
|
{
|
|
|
|
String sTempName = createTempFile();
|
|
|
|
|
2001-09-25 12:12:51 +00:00
|
|
|
ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection));
|
2002-01-21 13:50:26 +00:00
|
|
|
Reference< XPropertySet > xHold = pNewTable;
|
2001-05-14 10:42:44 +00:00
|
|
|
pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName)));
|
2001-03-28 10:32:43 +00:00
|
|
|
{
|
|
|
|
Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY);
|
2001-05-30 09:44:16 +00:00
|
|
|
sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers();
|
2001-03-28 10:32:43 +00:00
|
|
|
// copy the structure
|
|
|
|
for(sal_Int32 i=0;i < m_pColumns->getCount();++i)
|
|
|
|
{
|
2001-05-28 12:03:37 +00:00
|
|
|
Reference<XPropertySet> xProp;
|
|
|
|
m_pColumns->getByIndex(i) >>= xProp;
|
|
|
|
Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY);
|
|
|
|
Reference<XPropertySet> xCpy;
|
|
|
|
if(xColumn.is())
|
|
|
|
xCpy = xColumn->createDataDescriptor();
|
|
|
|
else
|
|
|
|
{
|
2001-05-30 09:44:16 +00:00
|
|
|
xCpy = new OColumn(bCase);
|
2001-05-28 12:03:37 +00:00
|
|
|
::comphelper::copyProperties(xProp,xCpy);
|
|
|
|
}
|
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
xAppend->appendByDescriptor(xCpy);
|
|
|
|
}
|
2001-05-30 09:44:16 +00:00
|
|
|
Reference<XPropertySet> xCpy = new OColumn(bCase);
|
|
|
|
::comphelper::copyProperties(_xNewColumn,xCpy);
|
|
|
|
xAppend->appendByDescriptor(xCpy);
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// construct the new table
|
|
|
|
if(!pNewTable->CreateImpl())
|
2002-07-05 07:02:12 +00:00
|
|
|
{
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_COLUMN_NOT_ADDABLE,
|
|
|
|
"$columnname$", ::comphelper::getString(_xNewColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2002-07-05 07:02:12 +00:00
|
|
|
}
|
2002-01-21 13:50:26 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
BOOL bAlreadyDroped = FALSE;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pNewTable->construct();
|
|
|
|
// copy the data
|
|
|
|
copyData(pNewTable,pNewTable->m_pColumns->getCount());
|
|
|
|
// drop the old table
|
|
|
|
if(DropImpl())
|
|
|
|
{
|
|
|
|
bAlreadyDroped = TRUE;
|
2001-10-12 11:02:56 +00:00
|
|
|
pNewTable->renameImpl(m_Name);
|
2001-06-29 07:29:14 +00:00
|
|
|
// release the temp file
|
|
|
|
}
|
2002-01-21 13:50:26 +00:00
|
|
|
xHold = pNewTable = NULL;
|
2001-05-28 12:03:37 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
FileClose();
|
|
|
|
construct();
|
|
|
|
if(m_pColumns)
|
|
|
|
m_pColumns->refresh();
|
|
|
|
}
|
|
|
|
catch(const SQLException&)
|
|
|
|
{
|
|
|
|
// here we know that the old table wasn't droped before
|
|
|
|
if(!bAlreadyDroped)
|
2002-01-21 13:50:26 +00:00
|
|
|
xHold = pNewTable = NULL;
|
2001-05-28 12:03:37 +00:00
|
|
|
|
2001-06-29 07:29:14 +00:00
|
|
|
throw;
|
|
|
|
}
|
2001-05-30 09:44:16 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::dropColumn(sal_Int32 _nPos)
|
|
|
|
{
|
|
|
|
String sTempName = createTempFile();
|
|
|
|
|
2001-09-25 12:12:51 +00:00
|
|
|
ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection));
|
2002-01-21 13:50:26 +00:00
|
|
|
Reference< XPropertySet > xHold = pNewTable;
|
2001-05-30 09:44:16 +00:00
|
|
|
pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName)));
|
|
|
|
{
|
|
|
|
Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY);
|
|
|
|
sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers();
|
|
|
|
// copy the structure
|
|
|
|
for(sal_Int32 i=0;i < m_pColumns->getCount();++i)
|
|
|
|
{
|
|
|
|
if(_nPos != i)
|
|
|
|
{
|
|
|
|
Reference<XPropertySet> xProp;
|
|
|
|
m_pColumns->getByIndex(i) >>= xProp;
|
|
|
|
Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY);
|
|
|
|
Reference<XPropertySet> xCpy;
|
|
|
|
if(xColumn.is())
|
|
|
|
xCpy = xColumn->createDataDescriptor();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xCpy = new OColumn(bCase);
|
|
|
|
::comphelper::copyProperties(xProp,xCpy);
|
|
|
|
}
|
|
|
|
xAppend->appendByDescriptor(xCpy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct the new table
|
|
|
|
if(!pNewTable->CreateImpl())
|
|
|
|
{
|
2002-01-21 13:50:26 +00:00
|
|
|
xHold = pNewTable = NULL;
|
2008-10-01 12:28:29 +00:00
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_COLUMN_NOT_DROP,
|
|
|
|
"$position$", ::rtl::OUString::valueOf(_nPos)
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2001-05-30 09:44:16 +00:00
|
|
|
}
|
2001-06-14 14:16:41 +00:00
|
|
|
pNewTable->construct();
|
2001-05-30 09:44:16 +00:00
|
|
|
// copy the data
|
2001-06-29 07:29:14 +00:00
|
|
|
copyData(pNewTable,_nPos);
|
2001-05-30 09:44:16 +00:00
|
|
|
// drop the old table
|
2001-06-29 07:29:14 +00:00
|
|
|
if(DropImpl())
|
2001-10-12 11:02:56 +00:00
|
|
|
pNewTable->renameImpl(m_Name);
|
2001-06-29 07:29:14 +00:00
|
|
|
// release the temp file
|
2001-05-30 09:44:16 +00:00
|
|
|
|
2002-01-21 13:50:26 +00:00
|
|
|
xHold = pNewTable = NULL;
|
2001-05-30 09:44:16 +00:00
|
|
|
|
|
|
|
FileClose();
|
|
|
|
construct();
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
String ODbaseTable::createTempFile()
|
|
|
|
{
|
|
|
|
::rtl::OUString aIdent = m_pConnection->getContent()->getIdentifier()->getContentIdentifier();
|
2003-04-24 12:18:52 +00:00
|
|
|
if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) )
|
|
|
|
aIdent += ::rtl::OUString::createFromAscii("/");
|
2001-03-28 10:32:43 +00:00
|
|
|
String sTempName(aIdent);
|
|
|
|
String sExt;
|
|
|
|
sExt.AssignAscii(".");
|
|
|
|
sExt += m_pConnection->getExtension();
|
|
|
|
|
2001-03-30 09:16:42 +00:00
|
|
|
String sName(m_Name);
|
|
|
|
TempFile aTempFile(sName,&sExt,&sTempName);
|
2001-03-28 10:32:43 +00:00
|
|
|
if(!aTempFile.IsValid())
|
2008-10-01 12:28:29 +00:00
|
|
|
getConnection()->throwGenericSQLException(STR_COULD_NOT_ALTER_TABLE,*this);
|
2001-03-28 10:32:43 +00:00
|
|
|
|
|
|
|
INetURLObject aURL;
|
|
|
|
aURL.SetSmartProtocol(INET_PROT_FILE);
|
|
|
|
aURL.SetURL(aTempFile.GetURL());
|
2001-05-30 09:44:16 +00:00
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
String sNewName(aURL.getName());
|
|
|
|
sNewName.Erase(sNewName.Len() - sExt.Len());
|
|
|
|
return sNewName;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-06-29 07:29:14 +00:00
|
|
|
void ODbaseTable::copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos)
|
2001-03-28 10:32:43 +00:00
|
|
|
{
|
2001-06-29 07:29:14 +00:00
|
|
|
sal_Int32 nPos = _nPos + 1; // +1 because we always have the bookmark clumn as well
|
2003-09-04 07:24:07 +00:00
|
|
|
OValueRefRow aRow = new OValueRefVector(m_pColumns->getCount());
|
|
|
|
OValueRefRow aInsertRow;
|
2001-10-15 12:22:24 +00:00
|
|
|
if(_nPos)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
2003-09-04 07:24:07 +00:00
|
|
|
aInsertRow = new OValueRefVector(_pNewTable->m_pColumns->getCount());
|
2008-12-30 13:32:01 +00:00
|
|
|
::std::for_each(aInsertRow->get().begin(),aInsertRow->get().end(),TSetRefBound(sal_True));
|
2001-06-29 07:29:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
aInsertRow = aRow;
|
|
|
|
|
|
|
|
// we only have to bind the values which we need to copy into the new table
|
2008-12-30 13:32:01 +00:00
|
|
|
::std::for_each(aRow->get().begin(),aRow->get().end(),TSetRefBound(sal_True));
|
|
|
|
if(_nPos && (_nPos < (sal_Int32)aRow->get().size()))
|
|
|
|
(aRow->get())[nPos]->setBound(sal_False);
|
2001-06-29 07:29:14 +00:00
|
|
|
|
2001-03-28 10:32:43 +00:00
|
|
|
|
|
|
|
sal_Bool bOk = sal_True;
|
|
|
|
sal_Int32 nCurPos;
|
2008-12-30 13:32:01 +00:00
|
|
|
OValueRefVector::Vector::iterator aIter;
|
2001-03-28 10:32:43 +00:00
|
|
|
for(sal_uInt32 nRowPos = 0; nRowPos < m_aHeader.db_anz;++nRowPos)
|
|
|
|
{
|
2006-06-20 00:21:12 +00:00
|
|
|
bOk = seekRow( IResultSetHelper::BOOKMARK, nRowPos+1, nCurPos );
|
|
|
|
if ( bOk )
|
2001-03-28 10:32:43 +00:00
|
|
|
{
|
2006-06-20 00:21:12 +00:00
|
|
|
bOk = fetchRow( aRow, m_aColumns.getBody(), sal_True, sal_True);
|
2008-06-06 12:20:24 +00:00
|
|
|
if ( bOk && !aRow->isDeleted() ) // copy only not deleted rows
|
2001-03-28 10:32:43 +00:00
|
|
|
{
|
2001-06-29 07:29:14 +00:00
|
|
|
// special handling when pos == 0 then we don't have to distinguish between the two rows
|
2001-10-15 12:22:24 +00:00
|
|
|
if(_nPos)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
2008-12-30 13:32:01 +00:00
|
|
|
aIter = aRow->get().begin()+1;
|
2001-06-29 07:29:14 +00:00
|
|
|
sal_Int32 nCount = 1;
|
2008-12-30 13:32:01 +00:00
|
|
|
for(OValueRefVector::Vector::iterator aInsertIter = aInsertRow->get().begin()+1; aIter != aRow->get().end() && aInsertIter != aInsertRow->get().end();++aIter,++nCount)
|
2001-06-29 07:29:14 +00:00
|
|
|
{
|
|
|
|
if(nPos != nCount)
|
|
|
|
{
|
2003-09-04 07:24:07 +00:00
|
|
|
(*aInsertIter)->setValue( (*aIter)->getValue() );
|
2001-06-29 07:29:14 +00:00
|
|
|
++aInsertIter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bOk = _pNewTable->InsertRow(*aInsertRow,sal_True,_pNewTable->m_pColumns);
|
2001-03-28 10:32:43 +00:00
|
|
|
OSL_ENSURE(bOk,"Row could not be inserted!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
OSL_ENSURE(bOk,"Row could not be fetched!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ASSERT(0);
|
|
|
|
}
|
2005-10-24 07:20:50 +00:00
|
|
|
} // for(sal_uInt32 nRowPos = 0; nRowPos < m_aHeader.db_anz;++nRowPos)
|
2001-03-28 10:32:43 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:59:15 +00:00
|
|
|
void ODbaseTable::throwInvalidDbaseFormat()
|
|
|
|
{
|
2001-08-10 10:05:34 +00:00
|
|
|
FileClose();
|
2001-08-02 06:59:15 +00:00
|
|
|
// no dbase file
|
2008-10-01 12:28:29 +00:00
|
|
|
|
|
|
|
const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution(
|
|
|
|
STR_SQL_NAME_ERROR,
|
|
|
|
"$filename$", getEntry(m_pConnection,m_Name)
|
|
|
|
) );
|
|
|
|
::dbtools::throwGenericSQLException( sError, *this );
|
2001-08-02 06:59:15 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-09-19 10:03:04 +00:00
|
|
|
void ODbaseTable::refreshHeader()
|
|
|
|
{
|
2008-01-30 06:50:29 +00:00
|
|
|
if ( m_aHeader.db_anz == 0 )
|
|
|
|
readHeader();
|
2001-09-19 10:03:04 +00:00
|
|
|
}
|
2006-06-20 00:21:12 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
sal_Bool ODbaseTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos)
|
|
|
|
{
|
|
|
|
// ----------------------------------------------------------
|
|
|
|
// Positionierung vorbereiten:
|
|
|
|
OSL_ENSURE(m_pFileStream,"ODbaseTable::seekRow: FileStream is NULL!");
|
|
|
|
|
|
|
|
sal_uInt32 nNumberOfRecords = (sal_uInt32)m_aHeader.db_anz;
|
|
|
|
sal_uInt32 nTempPos = m_nFilePos;
|
|
|
|
m_nFilePos = nCurPos;
|
|
|
|
|
|
|
|
switch(eCursorPosition)
|
|
|
|
{
|
|
|
|
case IResultSetHelper::NEXT:
|
|
|
|
++m_nFilePos;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::PRIOR:
|
|
|
|
if (m_nFilePos > 0)
|
|
|
|
--m_nFilePos;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::FIRST:
|
|
|
|
m_nFilePos = 1;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::LAST:
|
|
|
|
m_nFilePos = nNumberOfRecords;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::RELATIVE:
|
|
|
|
m_nFilePos = (((sal_Int32)m_nFilePos) + nOffset < 0) ? 0L
|
|
|
|
: (sal_uInt32)(((sal_Int32)m_nFilePos) + nOffset);
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::ABSOLUTE:
|
|
|
|
case IResultSetHelper::BOOKMARK:
|
|
|
|
m_nFilePos = (sal_uInt32)nOffset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_nFilePos > (sal_Int32)nNumberOfRecords)
|
|
|
|
m_nFilePos = (sal_Int32)nNumberOfRecords + 1;
|
|
|
|
|
|
|
|
if (m_nFilePos == 0 || m_nFilePos == (sal_Int32)nNumberOfRecords + 1)
|
|
|
|
goto Error;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sal_uInt16 nEntryLen = m_aHeader.db_slng;
|
|
|
|
|
|
|
|
OSL_ENSURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position");
|
|
|
|
sal_Int32 nPos = m_aHeader.db_kopf + (sal_Int32)(m_nFilePos-1) * nEntryLen;
|
|
|
|
|
|
|
|
ULONG nLen = m_pFileStream->Seek(nPos);
|
|
|
|
if (m_pFileStream->GetError() != ERRCODE_NONE)
|
|
|
|
goto Error;
|
|
|
|
|
|
|
|
nLen = m_pFileStream->Read((char*)m_pBuffer, nEntryLen);
|
|
|
|
if (m_pFileStream->GetError() != ERRCODE_NONE)
|
|
|
|
goto Error;
|
|
|
|
}
|
|
|
|
goto End;
|
|
|
|
|
|
|
|
Error:
|
|
|
|
switch(eCursorPosition)
|
|
|
|
{
|
|
|
|
case IResultSetHelper::PRIOR:
|
|
|
|
case IResultSetHelper::FIRST:
|
|
|
|
m_nFilePos = 0;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::LAST:
|
|
|
|
case IResultSetHelper::NEXT:
|
|
|
|
case IResultSetHelper::ABSOLUTE:
|
|
|
|
case IResultSetHelper::RELATIVE:
|
|
|
|
if (nOffset > 0)
|
|
|
|
m_nFilePos = nNumberOfRecords + 1;
|
|
|
|
else if (nOffset < 0)
|
|
|
|
m_nFilePos = 0;
|
|
|
|
break;
|
|
|
|
case IResultSetHelper::BOOKMARK:
|
|
|
|
m_nFilePos = nTempPos; // vorherige Position
|
|
|
|
}
|
|
|
|
// aStatus.Set(SDB_STAT_NO_DATA_FOUND);
|
|
|
|
return sal_False;
|
|
|
|
|
|
|
|
End:
|
|
|
|
nCurPos = m_nFilePos;
|
|
|
|
return sal_True;
|
|
|
|
}
|
2001-10-12 14:21:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2006-06-20 00:21:12 +00:00
|
|
|
BOOL ODbaseTable::ReadMemo(ULONG nBlockNo, ORowSetValue& aVariable)
|
|
|
|
{
|
|
|
|
BOOL bIsText = TRUE;
|
|
|
|
// SdbConnection* pConnection = GetConnection();
|
|
|
|
|
|
|
|
m_pMemoStream->Seek(nBlockNo * m_aMemoHeader.db_size);
|
|
|
|
switch (m_aMemoHeader.db_typ)
|
|
|
|
{
|
|
|
|
case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z
|
|
|
|
{
|
|
|
|
const char cEOF = (char) 0x1a;
|
|
|
|
ByteString aBStr;
|
|
|
|
static char aBuf[514];
|
|
|
|
aBuf[512] = 0; // sonst kann der Zufall uebel mitspielen
|
|
|
|
BOOL bReady = sal_False;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
m_pMemoStream->Read(&aBuf,512);
|
|
|
|
|
|
|
|
USHORT i = 0;
|
|
|
|
while (aBuf[i] != cEOF && ++i < 512)
|
|
|
|
;
|
|
|
|
bReady = aBuf[i] == cEOF;
|
|
|
|
|
|
|
|
aBuf[i] = 0;
|
|
|
|
aBStr += aBuf;
|
|
|
|
|
|
|
|
} while (!bReady && !m_pMemoStream->IsEof() && aBStr.Len() < STRING_MAXLEN);
|
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
::rtl::OUString aStr(aBStr.GetBuffer(), aBStr.Len(),m_eEncoding);
|
2006-06-20 00:21:12 +00:00
|
|
|
aVariable = aStr;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case MemoFoxPro:
|
|
|
|
case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe
|
|
|
|
{
|
|
|
|
char sHeader[4];
|
|
|
|
m_pMemoStream->Read(sHeader,4);
|
|
|
|
// Foxpro stores text and binary data
|
|
|
|
if (m_aMemoHeader.db_typ == MemoFoxPro)
|
|
|
|
{
|
|
|
|
if (((BYTE)sHeader[0]) != 0 || ((BYTE)sHeader[1]) != 0 || ((BYTE)sHeader[2]) != 0)
|
|
|
|
{
|
|
|
|
// String aText = String(SdbResId(STR_STAT_IResultSetHelper::INVALID));
|
|
|
|
// aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_pMemoStream->GetFileName());
|
|
|
|
// aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO));
|
|
|
|
// aStatus.Set(SDB_STAT_ERROR,
|
|
|
|
// String::CreateFromAscii("01000"),
|
|
|
|
// aStatus.CreateErrorMessage(aText),
|
|
|
|
// 0, String() );
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
bIsText = sHeader[3] != 0;
|
|
|
|
}
|
|
|
|
else if (((BYTE)sHeader[0]) != 0xFF || ((BYTE)sHeader[1]) != 0xFF || ((BYTE)sHeader[2]) != 0x08)
|
|
|
|
{
|
|
|
|
// String aText = String(SdbResId(STR_STAT_IResultSetHelper::INVALID));
|
|
|
|
// aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_pMemoStream->GetFileName());
|
|
|
|
// aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO));
|
|
|
|
// aStatus.Set(SDB_STAT_ERROR,
|
|
|
|
// String::CreateFromAscii("01000"),
|
|
|
|
// aStatus.CreateErrorMessage(aText),
|
|
|
|
// 0, String() );
|
|
|
|
return sal_False;
|
|
|
|
}
|
|
|
|
|
2006-07-06 13:17:15 +00:00
|
|
|
sal_uInt32 nLength(0);
|
2006-06-20 00:21:12 +00:00
|
|
|
(*m_pMemoStream) >> nLength;
|
|
|
|
|
|
|
|
if (m_aMemoHeader.db_typ == MemodBaseIV)
|
|
|
|
nLength -= 8;
|
|
|
|
|
|
|
|
// char cChar;
|
|
|
|
::rtl::OUString aStr;
|
|
|
|
while ( nLength > STRING_MAXLEN )
|
|
|
|
{
|
|
|
|
ByteString aBStr;
|
|
|
|
aBStr.Expand(STRING_MAXLEN);
|
|
|
|
m_pMemoStream->Read(aBStr.AllocBuffer(STRING_MAXLEN),STRING_MAXLEN);
|
2008-06-06 12:20:24 +00:00
|
|
|
aStr += ::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding);
|
2006-06-20 00:21:12 +00:00
|
|
|
nLength -= STRING_MAXLEN;
|
|
|
|
}
|
|
|
|
if ( nLength > 0 )
|
|
|
|
{
|
|
|
|
ByteString aBStr;
|
|
|
|
aBStr.Expand(static_cast<xub_StrLen>(nLength));
|
|
|
|
m_pMemoStream->Read(aBStr.AllocBuffer(static_cast<xub_StrLen>(nLength)),nLength);
|
|
|
|
// aBStr.ReleaseBufferAccess();
|
|
|
|
|
2008-06-06 12:20:24 +00:00
|
|
|
aStr += ::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding);
|
2006-06-20 00:21:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if ( aStr.getLength() )
|
|
|
|
aVariable = aStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sal_True;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void ODbaseTable::AllocBuffer()
|
|
|
|
{
|
|
|
|
UINT16 nSize = m_aHeader.db_slng;
|
|
|
|
OSL_ENSURE(nSize > 0, "Size too small");
|
|
|
|
|
|
|
|
if (m_nBufferSize != nSize)
|
|
|
|
{
|
|
|
|
delete m_pBuffer;
|
|
|
|
m_pBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Falls noch kein Puffer vorhanden: allozieren:
|
|
|
|
if (m_pBuffer == NULL && nSize)
|
|
|
|
{
|
|
|
|
m_nBufferSize = nSize;
|
|
|
|
m_pBuffer = new BYTE[m_nBufferSize+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
BOOL ODbaseTable::WriteBuffer()
|
|
|
|
{
|
|
|
|
OSL_ENSURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position");
|
|
|
|
|
|
|
|
// Auf gewuenschten Record positionieren:
|
|
|
|
long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng;
|
|
|
|
m_pFileStream->Seek(nPos);
|
|
|
|
return m_pFileStream->Write((char*) m_pBuffer, m_aHeader.db_slng) > 0;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Int32 ODbaseTable::getCurrentLastPos() const
|
|
|
|
{
|
|
|
|
return m_aHeader.db_anz;
|
|
|
|
}
|