19b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 39b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 49b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 59b5730f6SAndrew Rist * distributed with this work for additional information 69b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 79b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 89b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 99b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 119b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 139b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 149b5730f6SAndrew Rist * software distributed under the License is distributed on an 159b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 169b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 179b5730f6SAndrew Rist * specific language governing permissions and limitations 189b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 209b5730f6SAndrew Rist *************************************************************/ 219b5730f6SAndrew Rist 229b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "dbase/DTable.hxx" 27cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp> 28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 29cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp> 30cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 31cdf0e10cSrcweir #include <svl/converter.hxx> 32cdf0e10cSrcweir #include "dbase/DConnection.hxx" 33cdf0e10cSrcweir #include "dbase/DColumns.hxx" 34cdf0e10cSrcweir #include <osl/thread.h> 35cdf0e10cSrcweir #include <tools/config.hxx> 36cdf0e10cSrcweir #include "dbase/DIndex.hxx" 37cdf0e10cSrcweir #include "dbase/DIndexes.hxx" 38cdf0e10cSrcweir //#include "file/FDriver.hxx" 39cdf0e10cSrcweir #include <comphelper/sequence.hxx> 40cdf0e10cSrcweir #include <svl/zforlist.hxx> 41cdf0e10cSrcweir #include <unotools/syslocale.hxx> 42cdf0e10cSrcweir #include <rtl/math.hxx> 43cdf0e10cSrcweir #include <stdio.h> //sprintf 44cdf0e10cSrcweir #include <ucbhelper/content.hxx> 45cdf0e10cSrcweir #include <comphelper/extract.hxx> 46cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 47cdf0e10cSrcweir #include <connectivity/dbconversion.hxx> 48cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 49cdf0e10cSrcweir #include <comphelper/property.hxx> 50cdf0e10cSrcweir //#include <unotools/calendarwrapper.hxx> 51cdf0e10cSrcweir #include <unotools/tempfile.hxx> 52cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 53cdf0e10cSrcweir #include <comphelper/types.hxx> 54cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 55cdf0e10cSrcweir #include "connectivity/PColumn.hxx" 56cdf0e10cSrcweir #include "connectivity/dbtools.hxx" 57cdf0e10cSrcweir #include "connectivity/FValue.hxx" 58cdf0e10cSrcweir #include "connectivity/dbconversion.hxx" 59cdf0e10cSrcweir #include "resource/dbase_res.hrc" 60cdf0e10cSrcweir #include <rtl/logfile.hxx> 61cdf0e10cSrcweir 62cdf0e10cSrcweir #include <algorithm> 63cdf0e10cSrcweir 64cdf0e10cSrcweir using namespace ::comphelper; 65cdf0e10cSrcweir using namespace connectivity; 66cdf0e10cSrcweir using namespace connectivity::sdbcx; 67cdf0e10cSrcweir using namespace connectivity::dbase; 68cdf0e10cSrcweir using namespace connectivity::file; 69cdf0e10cSrcweir using namespace ::ucbhelper; 70cdf0e10cSrcweir using namespace ::utl; 71cdf0e10cSrcweir using namespace ::cppu; 72cdf0e10cSrcweir using namespace ::dbtools; 73cdf0e10cSrcweir using namespace ::com::sun::star::uno; 74cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 75cdf0e10cSrcweir using namespace ::com::sun::star::beans; 76cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 77cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 78cdf0e10cSrcweir using namespace ::com::sun::star::container; 79cdf0e10cSrcweir using namespace ::com::sun::star::lang; 80cdf0e10cSrcweir using namespace ::com::sun::star::i18n; 81cdf0e10cSrcweir 82cdf0e10cSrcweir // stored as the Field Descriptor terminator 83cdf0e10cSrcweir #define FIELD_DESCRIPTOR_TERMINATOR 0x0D 84cdf0e10cSrcweir #define DBF_EOL 0x1A 85cdf0e10cSrcweir 86cdf0e10cSrcweir namespace 87cdf0e10cSrcweir { 88cdf0e10cSrcweir sal_Int32 lcl_getFileSize(SvStream& _rStream) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir sal_Int32 nFileSize = 0; 91cdf0e10cSrcweir _rStream.Seek(STREAM_SEEK_TO_END); 92cdf0e10cSrcweir _rStream.SeekRel(-1); 93cdf0e10cSrcweir char cEOL; 94cdf0e10cSrcweir _rStream >> cEOL; 95cdf0e10cSrcweir nFileSize = _rStream.Tell(); 96cdf0e10cSrcweir if ( cEOL == DBF_EOL ) 97cdf0e10cSrcweir nFileSize -= 1; 98cdf0e10cSrcweir return nFileSize; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir /** 101cdf0e10cSrcweir calculates the Julian date 102cdf0e10cSrcweir */ 103cdf0e10cSrcweir void lcl_CalcJulDate(sal_Int32& _nJulianDate,sal_Int32& _nJulianTime,const com::sun::star::util::DateTime _aDateTime) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir com::sun::star::util::DateTime aDateTime = _aDateTime; 106cdf0e10cSrcweir // weird: months fix 107cdf0e10cSrcweir if (aDateTime.Month > 12) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir aDateTime.Month--; 110cdf0e10cSrcweir sal_uInt16 delta = _aDateTime.Month / 12; 111cdf0e10cSrcweir aDateTime.Year += delta; 112cdf0e10cSrcweir aDateTime.Month -= delta * 12; 113cdf0e10cSrcweir aDateTime.Month++; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir _nJulianTime = ((aDateTime.Hours*3600000)+(aDateTime.Minutes*60000)+(aDateTime.Seconds*1000)+(aDateTime.HundredthSeconds*10)); 117cdf0e10cSrcweir /* conversion factors */ 118cdf0e10cSrcweir sal_uInt16 iy0; 119cdf0e10cSrcweir sal_uInt16 im0; 120cdf0e10cSrcweir if ( aDateTime.Month <= 2 ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir iy0 = aDateTime.Year - 1; 123cdf0e10cSrcweir im0 = aDateTime.Month + 12; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else 126cdf0e10cSrcweir { 127cdf0e10cSrcweir iy0 = aDateTime.Year; 128cdf0e10cSrcweir im0 = aDateTime.Month; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir sal_Int32 ia = iy0 / 100; 131cdf0e10cSrcweir sal_Int32 ib = 2 - ia + (ia >> 2); 132cdf0e10cSrcweir /* calculate julian date */ 133cdf0e10cSrcweir if ( aDateTime.Year <= 0 ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir _nJulianDate = (sal_Int32) ((365.25 * iy0) - 0.75) 136cdf0e10cSrcweir + (sal_Int32) (30.6001 * (im0 + 1) ) 137cdf0e10cSrcweir + aDateTime.Day + 1720994; 138cdf0e10cSrcweir } // if ( _aDateTime.Year <= 0 ) 139cdf0e10cSrcweir else 140cdf0e10cSrcweir { 141cdf0e10cSrcweir _nJulianDate = static_cast<sal_Int32>( ((365.25 * iy0) 142cdf0e10cSrcweir + (sal_Int32) (30.6001 * (im0 + 1)) 143cdf0e10cSrcweir + aDateTime.Day + 1720994)); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir double JD = _nJulianDate + 0.5; 146cdf0e10cSrcweir _nJulianDate = (sal_Int32)( JD + 0.5); 147cdf0e10cSrcweir const double gyr = aDateTime.Year + (0.01 * aDateTime.Month) + (0.0001 * aDateTime.Day); 148cdf0e10cSrcweir if ( gyr >= 1582.1015 ) /* on or after 15 October 1582 */ 149cdf0e10cSrcweir _nJulianDate += ib; 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir /** 153cdf0e10cSrcweir calculates date time from the Julian Date 154cdf0e10cSrcweir */ 155cdf0e10cSrcweir void lcl_CalDate(sal_Int32 _nJulianDate,sal_Int32 _nJulianTime,com::sun::star::util::DateTime& _rDateTime) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir if ( _nJulianDate ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir sal_Int32 ialp; 160cdf0e10cSrcweir sal_Int32 ka = _nJulianDate; 161cdf0e10cSrcweir if ( _nJulianDate >= 2299161 ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir ialp = (sal_Int32)( ((double) _nJulianDate - 1867216.25 ) / ( 36524.25 )); 164cdf0e10cSrcweir ka = _nJulianDate + 1 + ialp - ( ialp >> 2 ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir sal_Int32 kb = ka + 1524; 167cdf0e10cSrcweir sal_Int32 kc = (sal_Int32) ( ((double) kb - 122.1 ) / 365.25 ); 168cdf0e10cSrcweir sal_Int32 kd = (sal_Int32) ((double) kc * 365.25); 169cdf0e10cSrcweir sal_Int32 ke = (sal_Int32) ((double) ( kb - kd ) / 30.6001 ); 170cdf0e10cSrcweir _rDateTime.Day = static_cast<sal_uInt16>(kb - kd - ((sal_Int32) ( (double) ke * 30.6001 ))); 171cdf0e10cSrcweir if ( ke > 13 ) 172cdf0e10cSrcweir _rDateTime.Month = static_cast<sal_uInt16>(ke - 13); 173cdf0e10cSrcweir else 174cdf0e10cSrcweir _rDateTime.Month = static_cast<sal_uInt16>(ke - 1); 175cdf0e10cSrcweir if ( (_rDateTime.Month == 2) && (_rDateTime.Day > 28) ) 176cdf0e10cSrcweir _rDateTime.Day = 29; 177cdf0e10cSrcweir if ( (_rDateTime.Month == 2) && (_rDateTime.Day == 29) && (ke == 3) ) 178cdf0e10cSrcweir _rDateTime.Year = static_cast<sal_uInt16>(kc - 4716); 179cdf0e10cSrcweir else if ( _rDateTime.Month > 2 ) 180cdf0e10cSrcweir _rDateTime.Year = static_cast<sal_uInt16>(kc - 4716); 181cdf0e10cSrcweir else 182cdf0e10cSrcweir _rDateTime.Year = static_cast<sal_uInt16>(kc - 4715); 183cdf0e10cSrcweir } // if ( _nJulianDate ) 184cdf0e10cSrcweir 185cdf0e10cSrcweir if ( _nJulianTime ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir double d_s = _nJulianTime / 1000; 188cdf0e10cSrcweir double d_m = d_s / 60; 189cdf0e10cSrcweir double d_h = d_m / 60; 190cdf0e10cSrcweir _rDateTime.Hours = (sal_uInt16) (d_h); 191cdf0e10cSrcweir _rDateTime.Minutes = (sal_uInt16) d_m; // integer _aDateTime.Minutes 192cdf0e10cSrcweir //// weird: time fix 193cdf0e10cSrcweir // int test = (_rDateTime.Hours % 3) * 100 + _rDateTime.Minutes; 194cdf0e10cSrcweir //int test_tbl[] = {0, 1, 2, 11, 12, 13, 22, 23, 24, 25, 34, 35, 36, 195cdf0e10cSrcweir // 45, 46, 47, 56, 57, 58, 107, 108, 109, 110, 119, 120, 121, 196cdf0e10cSrcweir // 130, 131, 132, 141, 142, 143, 152, 153, 154, 155, 204, 205, 197cdf0e10cSrcweir // 206, 215, 216, 217, 226, 227, 228, 237, 238, 239, 240, 249, 198cdf0e10cSrcweir // 250, 251}; 199cdf0e10cSrcweir // for (int i = 0; i < sizeof(test_tbl)/sizeof(test_tbl[0]); i++) 200cdf0e10cSrcweir //{ 201cdf0e10cSrcweir // if (test == test_tbl[i]) 202cdf0e10cSrcweir // { 203cdf0e10cSrcweir // // frac += 0.000012; 204cdf0e10cSrcweir // //d_hour = frac * 24.0; 205cdf0e10cSrcweir // _rDateTime.Hours = (sal_uInt16)d_hour; 206cdf0e10cSrcweir // d_minute = (d_hour - (double)_rDateTime.Hours) * 60.0; 207cdf0e10cSrcweir // _rDateTime.Minutes = (sal_uInt16)d_minute; 208cdf0e10cSrcweir // break; 209cdf0e10cSrcweir // } 210cdf0e10cSrcweir // } 211cdf0e10cSrcweir 212cdf0e10cSrcweir _rDateTime.Seconds = static_cast<sal_uInt16>(( d_m - (double) _rDateTime.Minutes ) * 60.0); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // ------------------------------------------------------------------------- 219cdf0e10cSrcweir void ODbaseTable::readHeader() 220cdf0e10cSrcweir { 221cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::readHeader" ); 222cdf0e10cSrcweir OSL_ENSURE(m_pFileStream,"No Stream available!"); 223cdf0e10cSrcweir if(!m_pFileStream) 224cdf0e10cSrcweir return; 225cdf0e10cSrcweir m_pFileStream->RefreshBuffer(); // sicherstellen, dass die Kopfinformationen tatsaechlich neu gelesen werden 226cdf0e10cSrcweir m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); 227cdf0e10cSrcweir 228cdf0e10cSrcweir sal_uInt8 nType=0; 229cdf0e10cSrcweir (*m_pFileStream) >> nType; 230cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 231cdf0e10cSrcweir throwInvalidDbaseFormat(); 232cdf0e10cSrcweir 233cdf0e10cSrcweir m_pFileStream->Read((char*)(&m_aHeader.db_aedat), 3*sizeof(sal_uInt8)); 234cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 235cdf0e10cSrcweir throwInvalidDbaseFormat(); 236cdf0e10cSrcweir (*m_pFileStream) >> m_aHeader.db_anz; 237cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 238cdf0e10cSrcweir throwInvalidDbaseFormat(); 239cdf0e10cSrcweir (*m_pFileStream) >> m_aHeader.db_kopf; 240cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 241cdf0e10cSrcweir throwInvalidDbaseFormat(); 242cdf0e10cSrcweir (*m_pFileStream) >> m_aHeader.db_slng; 243cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 244cdf0e10cSrcweir throwInvalidDbaseFormat(); 245cdf0e10cSrcweir m_pFileStream->Read((char*)(&m_aHeader.db_frei), 20*sizeof(sal_uInt8)); 246cdf0e10cSrcweir if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) 247cdf0e10cSrcweir throwInvalidDbaseFormat(); 248cdf0e10cSrcweir 249cdf0e10cSrcweir if ( ( ( m_aHeader.db_kopf - 1 ) / 32 - 1 ) <= 0 ) // anzahl felder 250cdf0e10cSrcweir { 251cdf0e10cSrcweir // no dbase file 252cdf0e10cSrcweir throwInvalidDbaseFormat(); 253cdf0e10cSrcweir } 254cdf0e10cSrcweir else 255cdf0e10cSrcweir { 256cdf0e10cSrcweir // Konsistenzpruefung des Header: 257cdf0e10cSrcweir m_aHeader.db_typ = (DBFType)nType; 258cdf0e10cSrcweir switch (m_aHeader.db_typ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir case dBaseIII: 261cdf0e10cSrcweir case dBaseIV: 262cdf0e10cSrcweir case dBaseV: 263cdf0e10cSrcweir case VisualFoxPro: 264cdf0e10cSrcweir case VisualFoxProAuto: 265cdf0e10cSrcweir case dBaseFS: 266cdf0e10cSrcweir case dBaseFSMemo: 267cdf0e10cSrcweir case dBaseIVMemoSQL: 268cdf0e10cSrcweir case dBaseIIIMemo: 269cdf0e10cSrcweir case FoxProMemo: 270cdf0e10cSrcweir m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); 271cdf0e10cSrcweir if ( m_aHeader.db_frei[17] != 0x00 272cdf0e10cSrcweir && !m_aHeader.db_frei[18] && !m_aHeader.db_frei[19] && getConnection()->isTextEncodingDefaulted() ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir switch(m_aHeader.db_frei[17]) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir case 0x01: m_eEncoding = RTL_TEXTENCODING_IBM_437; break; // DOS USA code page 437 277cdf0e10cSrcweir case 0x02: m_eEncoding = RTL_TEXTENCODING_IBM_850; break; // DOS Multilingual code page 850 278cdf0e10cSrcweir case 0x03: m_eEncoding = RTL_TEXTENCODING_MS_1252; break; // Windows ANSI code page 1252 279cdf0e10cSrcweir case 0x04: m_eEncoding = RTL_TEXTENCODING_APPLE_ROMAN; break; // Standard Macintosh 280cdf0e10cSrcweir case 0x64: m_eEncoding = RTL_TEXTENCODING_IBM_852; break; // EE MS-DOS code page 852 281cdf0e10cSrcweir case 0x65: m_eEncoding = RTL_TEXTENCODING_IBM_865; break; // Nordic MS-DOS code page 865 282cdf0e10cSrcweir case 0x66: m_eEncoding = RTL_TEXTENCODING_IBM_866; break; // Russian MS-DOS code page 866 283cdf0e10cSrcweir case 0x67: m_eEncoding = RTL_TEXTENCODING_IBM_861; break; // Icelandic MS-DOS 284cdf0e10cSrcweir //case 0x68: m_eEncoding = ; break; // Kamenicky (Czech) MS-DOS 285cdf0e10cSrcweir //case 0x69: m_eEncoding = ; break; // Mazovia (Polish) MS-DOS 286cdf0e10cSrcweir case 0x6A: m_eEncoding = RTL_TEXTENCODING_IBM_737; break; // Greek MS-DOS (437G) 287cdf0e10cSrcweir case 0x6B: m_eEncoding = RTL_TEXTENCODING_IBM_857; break; // Turkish MS-DOS 288cdf0e10cSrcweir case 0x96: m_eEncoding = RTL_TEXTENCODING_APPLE_CYRILLIC; break; // Russian Macintosh 289cdf0e10cSrcweir case 0x97: m_eEncoding = RTL_TEXTENCODING_APPLE_CENTEURO; break; // Eastern European Macintosh 290cdf0e10cSrcweir case 0x98: m_eEncoding = RTL_TEXTENCODING_APPLE_GREEK; break; // Greek Macintosh 291cdf0e10cSrcweir case 0xC8: m_eEncoding = RTL_TEXTENCODING_MS_1250; break; // Windows EE code page 1250 292cdf0e10cSrcweir case 0xC9: m_eEncoding = RTL_TEXTENCODING_MS_1251; break; // Russian Windows 293cdf0e10cSrcweir case 0xCA: m_eEncoding = RTL_TEXTENCODING_MS_1254; break; // Turkish Windows 294cdf0e10cSrcweir case 0xCB: m_eEncoding = RTL_TEXTENCODING_MS_1253; break; // Greek Windows 295cdf0e10cSrcweir default: 296cdf0e10cSrcweir break; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir break; 300cdf0e10cSrcweir case dBaseIVMemo: 301cdf0e10cSrcweir m_pFileStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); 302cdf0e10cSrcweir break; 303cdf0e10cSrcweir default: 304cdf0e10cSrcweir { 305cdf0e10cSrcweir throwInvalidDbaseFormat(); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir } 308cdf0e10cSrcweir } 309cdf0e10cSrcweir } 310cdf0e10cSrcweir // ------------------------------------------------------------------------- 311cdf0e10cSrcweir void ODbaseTable::fillColumns() 312cdf0e10cSrcweir { 313cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::fillColumns" ); 314cdf0e10cSrcweir m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); 315cdf0e10cSrcweir m_pFileStream->Seek(32L); 316cdf0e10cSrcweir 317cdf0e10cSrcweir if(!m_aColumns.isValid()) 318cdf0e10cSrcweir m_aColumns = new OSQLColumns(); 319cdf0e10cSrcweir else 320cdf0e10cSrcweir m_aColumns->get().clear(); 321cdf0e10cSrcweir 322cdf0e10cSrcweir m_aTypes.clear(); 323cdf0e10cSrcweir m_aPrecisions.clear(); 324cdf0e10cSrcweir m_aScales.clear(); 325cdf0e10cSrcweir 326cdf0e10cSrcweir // Anzahl Felder: 327cdf0e10cSrcweir const sal_Int32 nFieldCount = (m_aHeader.db_kopf - 1) / 32 - 1; 328cdf0e10cSrcweir OSL_ENSURE(nFieldCount,"No columns in table!"); 329cdf0e10cSrcweir 330cdf0e10cSrcweir m_aColumns->get().reserve(nFieldCount); 331cdf0e10cSrcweir m_aTypes.reserve(nFieldCount); 332cdf0e10cSrcweir m_aPrecisions.reserve(nFieldCount); 333cdf0e10cSrcweir m_aScales.reserve(nFieldCount); 334cdf0e10cSrcweir 335cdf0e10cSrcweir String aStrFieldName; 336cdf0e10cSrcweir aStrFieldName.AssignAscii("Column"); 337cdf0e10cSrcweir ::rtl::OUString aTypeName; 338cdf0e10cSrcweir static const ::rtl::OUString sVARCHAR(RTL_CONSTASCII_USTRINGPARAM("VARCHAR")); 339cdf0e10cSrcweir const sal_Bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); 340cdf0e10cSrcweir const bool bFoxPro = m_aHeader.db_typ == VisualFoxPro || m_aHeader.db_typ == VisualFoxProAuto || m_aHeader.db_typ == FoxProMemo; 341cdf0e10cSrcweir 342cdf0e10cSrcweir sal_Int32 i = 0; 343cdf0e10cSrcweir for (; i < nFieldCount; i++) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir DBFColumn aDBFColumn; 346cdf0e10cSrcweir m_pFileStream->Read((char*)&aDBFColumn, sizeof(aDBFColumn)); 347cdf0e10cSrcweir if ( FIELD_DESCRIPTOR_TERMINATOR == aDBFColumn.db_fnm[0] ) // 0x0D stored as the Field Descriptor terminator. 348cdf0e10cSrcweir break; 349cdf0e10cSrcweir 350cdf0e10cSrcweir sal_Bool bIsRowVersion = bFoxPro && ( aDBFColumn.db_frei2[0] & 0x01 ) == 0x01; 351cdf0e10cSrcweir //if ( bFoxPro && ( aDBFColumn.db_frei2[0] & 0x01 ) == 0x01 ) // system column not visible to user 352cdf0e10cSrcweir // continue; 353cdf0e10cSrcweir const String aColumnName((const char *)aDBFColumn.db_fnm,m_eEncoding); 354cdf0e10cSrcweir 355cdf0e10cSrcweir m_aRealFieldLengths.push_back(aDBFColumn.db_flng); 356cdf0e10cSrcweir sal_Int32 nPrecision = aDBFColumn.db_flng; 357cdf0e10cSrcweir sal_Int32 eType; 358cdf0e10cSrcweir sal_Bool bIsCurrency = sal_False; 359cdf0e10cSrcweir 360cdf0e10cSrcweir char cType[2]; 361cdf0e10cSrcweir cType[0] = aDBFColumn.db_typ; 362cdf0e10cSrcweir cType[1] = 0; 363cdf0e10cSrcweir aTypeName = ::rtl::OUString::createFromAscii(cType); 364cdf0e10cSrcweir OSL_TRACE("column type: %c",aDBFColumn.db_typ); 365cdf0e10cSrcweir 366cdf0e10cSrcweir switch (aDBFColumn.db_typ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir case 'C': 369cdf0e10cSrcweir eType = DataType::VARCHAR; 370cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VARCHAR")); 371cdf0e10cSrcweir break; 372cdf0e10cSrcweir case 'F': 373cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DECIMAL")); 374cdf0e10cSrcweir case 'N': 375cdf0e10cSrcweir if ( aDBFColumn.db_typ == 'N' ) 376cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NUMERIC")); 377cdf0e10cSrcweir eType = DataType::DECIMAL; 378cdf0e10cSrcweir 379cdf0e10cSrcweir // Bei numerischen Feldern werden zwei Zeichen mehr geschrieben, als die Precision der Spaltenbeschreibung eigentlich 380cdf0e10cSrcweir // angibt, um Platz fuer das eventuelle Vorzeichen und das Komma zu haben. Das muss ich jetzt aber wieder rausrechnen. 381cdf0e10cSrcweir nPrecision = SvDbaseConverter::ConvertPrecisionToOdbc(nPrecision,aDBFColumn.db_dez); 382cdf0e10cSrcweir // leider gilt das eben Gesagte nicht fuer aeltere Versionen .... 383cdf0e10cSrcweir break; 384cdf0e10cSrcweir case 'L': 385cdf0e10cSrcweir eType = DataType::BIT; 386cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BOOLEAN")); 387cdf0e10cSrcweir break; 388cdf0e10cSrcweir case 'Y': 389cdf0e10cSrcweir bIsCurrency = sal_True; 390cdf0e10cSrcweir eType = DataType::DOUBLE; 391cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOUBLE")); 392cdf0e10cSrcweir break; 393cdf0e10cSrcweir case 'D': 394cdf0e10cSrcweir eType = DataType::DATE; 395cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATE")); 396cdf0e10cSrcweir break; 397cdf0e10cSrcweir case 'T': 398cdf0e10cSrcweir eType = DataType::TIMESTAMP; 399cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TIMESTAMP")); 400cdf0e10cSrcweir break; 401cdf0e10cSrcweir case 'I': 402cdf0e10cSrcweir eType = DataType::INTEGER; 403cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INTEGER")); 404cdf0e10cSrcweir break; 405cdf0e10cSrcweir case 'M': 406cdf0e10cSrcweir if ( bFoxPro && ( aDBFColumn.db_frei2[0] & 0x04 ) == 0x04 ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir eType = DataType::LONGVARBINARY; 409cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LONGVARBINARY")); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir else 412cdf0e10cSrcweir { 413cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LONGVARCHAR")); 414cdf0e10cSrcweir eType = DataType::LONGVARCHAR; 415cdf0e10cSrcweir } 416cdf0e10cSrcweir nPrecision = 2147483647; 417cdf0e10cSrcweir break; 418cdf0e10cSrcweir case 'P': 419cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LONGVARBINARY")); 420cdf0e10cSrcweir eType = DataType::LONGVARBINARY; 421cdf0e10cSrcweir nPrecision = 2147483647; 422cdf0e10cSrcweir break; 423cdf0e10cSrcweir case '0': 424cdf0e10cSrcweir case 'B': 425cdf0e10cSrcweir if ( m_aHeader.db_typ == VisualFoxPro || m_aHeader.db_typ == VisualFoxProAuto ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOUBLE")); 428cdf0e10cSrcweir eType = DataType::DOUBLE; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir else 431cdf0e10cSrcweir { 432cdf0e10cSrcweir aTypeName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LONGVARBINARY")); 433cdf0e10cSrcweir eType = DataType::LONGVARBINARY; 434cdf0e10cSrcweir nPrecision = 2147483647; 435cdf0e10cSrcweir } 436cdf0e10cSrcweir break; 437cdf0e10cSrcweir default: 438cdf0e10cSrcweir eType = DataType::OTHER; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir m_aTypes.push_back(eType); 442cdf0e10cSrcweir m_aPrecisions.push_back(nPrecision); 443cdf0e10cSrcweir m_aScales.push_back(aDBFColumn.db_dez); 444cdf0e10cSrcweir 445cdf0e10cSrcweir Reference< XPropertySet> xCol = new sdbcx::OColumn(aColumnName, 446cdf0e10cSrcweir aTypeName, 447cdf0e10cSrcweir ::rtl::OUString(), 448cdf0e10cSrcweir ::rtl::OUString(), 449cdf0e10cSrcweir ColumnValue::NULLABLE, 450cdf0e10cSrcweir nPrecision, 451cdf0e10cSrcweir aDBFColumn.db_dez, 452cdf0e10cSrcweir eType, 453cdf0e10cSrcweir sal_False, 454cdf0e10cSrcweir bIsRowVersion, 455cdf0e10cSrcweir bIsCurrency, 456cdf0e10cSrcweir bCase); 457cdf0e10cSrcweir m_aColumns->get().push_back(xCol); 458cdf0e10cSrcweir } // for (; i < nFieldCount; i++) 459cdf0e10cSrcweir OSL_ENSURE(i,"No columns in table!"); 460cdf0e10cSrcweir } 461cdf0e10cSrcweir // ------------------------------------------------------------------------- 462cdf0e10cSrcweir ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection) 463cdf0e10cSrcweir :ODbaseTable_BASE(_pTables,_pConnection) 464cdf0e10cSrcweir ,m_pMemoStream(NULL) 465cdf0e10cSrcweir ,m_bWriteableMemo(sal_False) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::ODbaseTable" ); 468cdf0e10cSrcweir // initialize the header 469cdf0e10cSrcweir m_aHeader.db_typ = dBaseIII; 470cdf0e10cSrcweir m_aHeader.db_anz = 0; 471cdf0e10cSrcweir m_aHeader.db_kopf = 0; 472cdf0e10cSrcweir m_aHeader.db_slng = 0; 473cdf0e10cSrcweir m_eEncoding = getConnection()->getTextEncoding(); 474cdf0e10cSrcweir } 475cdf0e10cSrcweir // ------------------------------------------------------------------------- 476cdf0e10cSrcweir ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables,ODbaseConnection* _pConnection, 477cdf0e10cSrcweir const ::rtl::OUString& _Name, 478cdf0e10cSrcweir const ::rtl::OUString& _Type, 479cdf0e10cSrcweir const ::rtl::OUString& _Description , 480cdf0e10cSrcweir const ::rtl::OUString& _SchemaName, 481cdf0e10cSrcweir const ::rtl::OUString& _CatalogName 482cdf0e10cSrcweir ) : ODbaseTable_BASE(_pTables,_pConnection,_Name, 483cdf0e10cSrcweir _Type, 484cdf0e10cSrcweir _Description, 485cdf0e10cSrcweir _SchemaName, 486cdf0e10cSrcweir _CatalogName) 487cdf0e10cSrcweir ,m_pMemoStream(NULL) 488cdf0e10cSrcweir ,m_bWriteableMemo(sal_False) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::ODbaseTable" ); 491cdf0e10cSrcweir m_eEncoding = getConnection()->getTextEncoding(); 492cdf0e10cSrcweir } 493cdf0e10cSrcweir 494cdf0e10cSrcweir // ----------------------------------------------------------------------------- 495cdf0e10cSrcweir void ODbaseTable::construct() 496cdf0e10cSrcweir { 497cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::construct" ); 498cdf0e10cSrcweir // initialize the header 499cdf0e10cSrcweir m_aHeader.db_typ = dBaseIII; 500cdf0e10cSrcweir m_aHeader.db_anz = 0; 501cdf0e10cSrcweir m_aHeader.db_kopf = 0; 502cdf0e10cSrcweir m_aHeader.db_slng = 0; 503cdf0e10cSrcweir m_aMemoHeader.db_size = 0; 504cdf0e10cSrcweir 505cdf0e10cSrcweir String sFileName(getEntry(m_pConnection,m_Name)); 506cdf0e10cSrcweir 507cdf0e10cSrcweir INetURLObject aURL; 508cdf0e10cSrcweir aURL.SetURL(sFileName); 509cdf0e10cSrcweir 510cdf0e10cSrcweir OSL_ENSURE( m_pConnection->matchesExtension( aURL.getExtension() ), 511cdf0e10cSrcweir "ODbaseTable::ODbaseTable: invalid extension!"); 512cdf0e10cSrcweir // getEntry is expected to ensure the corect file name 513cdf0e10cSrcweir 514cdf0e10cSrcweir m_pFileStream = createStream_simpleError( sFileName, STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); 515cdf0e10cSrcweir m_bWriteable = ( m_pFileStream != NULL ); 516cdf0e10cSrcweir 517cdf0e10cSrcweir if ( !m_pFileStream ) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir m_bWriteable = sal_False; 520cdf0e10cSrcweir m_pFileStream = createStream_simpleError( sFileName, STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir if(m_pFileStream) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir readHeader(); 526cdf0e10cSrcweir if (HasMemoFields()) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir // Memo-Dateinamen bilden (.DBT): 529cdf0e10cSrcweir // nyi: Unschoen fuer Unix und Mac! 530cdf0e10cSrcweir 531cdf0e10cSrcweir if ( m_aHeader.db_typ == FoxProMemo || VisualFoxPro == m_aHeader.db_typ || VisualFoxProAuto == m_aHeader.db_typ ) // foxpro uses another extension 532cdf0e10cSrcweir aURL.SetExtension(String::CreateFromAscii("fpt")); 533cdf0e10cSrcweir else 534cdf0e10cSrcweir aURL.SetExtension(String::CreateFromAscii("dbt")); 535cdf0e10cSrcweir 536cdf0e10cSrcweir // Wenn die Memodatei nicht gefunden wird, werden die Daten trotzdem angezeigt 537cdf0e10cSrcweir // allerdings koennen keine Updates durchgefuehrt werden 538cdf0e10cSrcweir // jedoch die Operation wird ausgefuehrt 539cdf0e10cSrcweir m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE); 540cdf0e10cSrcweir if ( !m_pMemoStream ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir m_bWriteableMemo = sal_False; 543cdf0e10cSrcweir m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir if (m_pMemoStream) 546cdf0e10cSrcweir ReadMemoHeader(); 547cdf0e10cSrcweir } 548cdf0e10cSrcweir // if(!m_pColumns && (!m_aColumns.isValid() || !m_aColumns->size())) 549cdf0e10cSrcweir fillColumns(); 550cdf0e10cSrcweir 551cdf0e10cSrcweir sal_uInt32 nFileSize = lcl_getFileSize(*m_pFileStream); 552cdf0e10cSrcweir m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); 553cdf0e10cSrcweir 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 554cdf0e10cSrcweir m_aHeader.db_anz = ((nFileSize-m_aHeader.db_kopf)/m_aHeader.db_slng); 555cdf0e10cSrcweir 556cdf0e10cSrcweir // Buffersize abhaengig von der Filegroesse 557cdf0e10cSrcweir m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : 558cdf0e10cSrcweir nFileSize > 100000 ? 16384 : 559cdf0e10cSrcweir nFileSize > 10000 ? 4096 : 1024); 560cdf0e10cSrcweir 561cdf0e10cSrcweir if (m_pMemoStream) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir // Puffer genau auf Laenge eines Satzes stellen 564cdf0e10cSrcweir m_pMemoStream->Seek(STREAM_SEEK_TO_END); 565cdf0e10cSrcweir nFileSize = m_pMemoStream->Tell(); 566cdf0e10cSrcweir m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN); 567cdf0e10cSrcweir 568cdf0e10cSrcweir // Buffersize abhaengig von der Filegroesse 569cdf0e10cSrcweir m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : 570cdf0e10cSrcweir nFileSize > 100000 ? 16384 : 571cdf0e10cSrcweir nFileSize > 10000 ? 4096 : 572cdf0e10cSrcweir m_aMemoHeader.db_size); 573cdf0e10cSrcweir } 574cdf0e10cSrcweir 575cdf0e10cSrcweir AllocBuffer(); 576cdf0e10cSrcweir } 577cdf0e10cSrcweir } 578cdf0e10cSrcweir //------------------------------------------------------------------ 579cdf0e10cSrcweir sal_Bool ODbaseTable::ReadMemoHeader() 580cdf0e10cSrcweir { 581cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::ReadMemoHeader" ); 582cdf0e10cSrcweir m_pMemoStream->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN); 583cdf0e10cSrcweir m_pMemoStream->RefreshBuffer(); // sicherstellen das die Kopfinformationen tatsaechlich neu gelesen werden 584cdf0e10cSrcweir m_pMemoStream->Seek(0L); 585cdf0e10cSrcweir 586cdf0e10cSrcweir (*m_pMemoStream) >> m_aMemoHeader.db_next; 587cdf0e10cSrcweir switch (m_aHeader.db_typ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir case dBaseIIIMemo: // dBase III: feste Blockgroesse 590cdf0e10cSrcweir case dBaseIVMemo: 591cdf0e10cSrcweir // manchmal wird aber auch dBase3 dBase4 Memo zugeordnet 592cdf0e10cSrcweir m_pMemoStream->Seek(20L); 593cdf0e10cSrcweir (*m_pMemoStream) >> m_aMemoHeader.db_size; 594cdf0e10cSrcweir if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size != 512) // 1 steht auch fuer dBase 3 595cdf0e10cSrcweir m_aMemoHeader.db_typ = MemodBaseIV; 596cdf0e10cSrcweir else if (m_aMemoHeader.db_size > 1 && m_aMemoHeader.db_size == 512) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir // nun gibt es noch manche Dateien, die verwenden eine Groessenangabe, 599cdf0e10cSrcweir // sind aber dennoch dBase Dateien 600cdf0e10cSrcweir char sHeader[4]; 601cdf0e10cSrcweir m_pMemoStream->Seek(m_aMemoHeader.db_size); 602cdf0e10cSrcweir m_pMemoStream->Read(sHeader,4); 603cdf0e10cSrcweir 604cdf0e10cSrcweir if ((m_pMemoStream->GetErrorCode() != ERRCODE_NONE) || ((sal_uInt8)sHeader[0]) != 0xFF || ((sal_uInt8)sHeader[1]) != 0xFF || ((sal_uInt8)sHeader[2]) != 0x08) 605cdf0e10cSrcweir m_aMemoHeader.db_typ = MemodBaseIII; 606cdf0e10cSrcweir else 607cdf0e10cSrcweir m_aMemoHeader.db_typ = MemodBaseIV; 608cdf0e10cSrcweir } 609cdf0e10cSrcweir else 610cdf0e10cSrcweir { 611cdf0e10cSrcweir m_aMemoHeader.db_typ = MemodBaseIII; 612cdf0e10cSrcweir m_aMemoHeader.db_size = 512; 613cdf0e10cSrcweir } 614cdf0e10cSrcweir break; 615cdf0e10cSrcweir case VisualFoxPro: 616cdf0e10cSrcweir case VisualFoxProAuto: 617cdf0e10cSrcweir case FoxProMemo: 618cdf0e10cSrcweir m_aMemoHeader.db_typ = MemoFoxPro; 619cdf0e10cSrcweir m_pMemoStream->Seek(6L); 620cdf0e10cSrcweir m_pMemoStream->SetNumberFormatInt(NUMBERFORMAT_INT_BIGENDIAN); 621cdf0e10cSrcweir (*m_pMemoStream) >> m_aMemoHeader.db_size; 622cdf0e10cSrcweir break; 623cdf0e10cSrcweir default: 624cdf0e10cSrcweir OSL_ENSURE( false, "ODbaseTable::ReadMemoHeader: unsupported memo type!" ); 625cdf0e10cSrcweir break; 626cdf0e10cSrcweir } 627cdf0e10cSrcweir return sal_True; 628cdf0e10cSrcweir } 629cdf0e10cSrcweir // ------------------------------------------------------------------------- 630cdf0e10cSrcweir String ODbaseTable::getEntry(OConnection* _pConnection,const ::rtl::OUString& _sName ) 631cdf0e10cSrcweir { 632cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getEntry" ); 633cdf0e10cSrcweir ::rtl::OUString sURL; 634cdf0e10cSrcweir try 635cdf0e10cSrcweir { 636cdf0e10cSrcweir Reference< XResultSet > xDir = _pConnection->getDir()->getStaticResultSet(); 637cdf0e10cSrcweir Reference< XRow> xRow(xDir,UNO_QUERY); 638cdf0e10cSrcweir ::rtl::OUString sName; 639cdf0e10cSrcweir ::rtl::OUString sExt; 640cdf0e10cSrcweir INetURLObject aURL; 641cdf0e10cSrcweir static const ::rtl::OUString s_sSeparator(RTL_CONSTASCII_USTRINGPARAM("/")); 642cdf0e10cSrcweir xDir->beforeFirst(); 643cdf0e10cSrcweir while(xDir->next()) 644cdf0e10cSrcweir { 645cdf0e10cSrcweir sName = xRow->getString(1); 646cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE); 647cdf0e10cSrcweir String sUrl = _pConnection->getURL() + s_sSeparator + sName; 648cdf0e10cSrcweir aURL.SetSmartURL( sUrl ); 649cdf0e10cSrcweir 650cdf0e10cSrcweir // cut the extension 651cdf0e10cSrcweir sExt = aURL.getExtension(); 652cdf0e10cSrcweir 653cdf0e10cSrcweir // name and extension have to coincide 654cdf0e10cSrcweir if ( _pConnection->matchesExtension( sExt ) ) 655cdf0e10cSrcweir { 656cdf0e10cSrcweir sName = sName.replaceAt(sName.getLength()-(sExt.getLength()+1),sExt.getLength()+1,::rtl::OUString()); 657cdf0e10cSrcweir if ( sName == _sName ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); 660cdf0e10cSrcweir sURL = xContentAccess->queryContentIdentifierString(); 661cdf0e10cSrcweir break; 662cdf0e10cSrcweir } 663cdf0e10cSrcweir } 664cdf0e10cSrcweir } 665cdf0e10cSrcweir xDir->beforeFirst(); // move back to before first record 666cdf0e10cSrcweir } 667cdf0e10cSrcweir catch(Exception&) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir OSL_ASSERT(0); 670cdf0e10cSrcweir } 671cdf0e10cSrcweir return sURL; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir // ------------------------------------------------------------------------- 674cdf0e10cSrcweir void ODbaseTable::refreshColumns() 675cdf0e10cSrcweir { 676cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::refreshColumns" ); 677cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 678cdf0e10cSrcweir 679cdf0e10cSrcweir TStringVector aVector; 680cdf0e10cSrcweir aVector.reserve(m_aColumns->get().size()); 681cdf0e10cSrcweir 682cdf0e10cSrcweir for(OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin();aIter != m_aColumns->get().end();++aIter) 683cdf0e10cSrcweir aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName()); 684cdf0e10cSrcweir 685cdf0e10cSrcweir if(m_pColumns) 686cdf0e10cSrcweir m_pColumns->reFill(aVector); 687cdf0e10cSrcweir else 688cdf0e10cSrcweir m_pColumns = new ODbaseColumns(this,m_aMutex,aVector); 689cdf0e10cSrcweir } 690cdf0e10cSrcweir // ------------------------------------------------------------------------- 691cdf0e10cSrcweir void ODbaseTable::refreshIndexes() 692cdf0e10cSrcweir { 693cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::refreshIndexes" ); 694cdf0e10cSrcweir TStringVector aVector; 695cdf0e10cSrcweir if(m_pFileStream && (!m_pIndexes || m_pIndexes->getCount() == 0)) 696cdf0e10cSrcweir { 697cdf0e10cSrcweir INetURLObject aURL; 698cdf0e10cSrcweir aURL.SetURL(getEntry(m_pConnection,m_Name)); 699cdf0e10cSrcweir 700cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("inf")); 701cdf0e10cSrcweir Config aInfFile(aURL.getFSysPath(INetURLObject::FSYS_DETECT)); 702cdf0e10cSrcweir aInfFile.SetGroup(dBASE_III_GROUP); 703cdf0e10cSrcweir sal_uInt16 nKeyCnt = aInfFile.GetKeyCount(); 704cdf0e10cSrcweir ByteString aKeyName; 705cdf0e10cSrcweir ByteString aIndexName; 706cdf0e10cSrcweir 707cdf0e10cSrcweir for (sal_uInt16 nKey = 0; nKey < nKeyCnt; nKey++) 708cdf0e10cSrcweir { 709cdf0e10cSrcweir // Verweist der Key auf ein Indexfile?... 710cdf0e10cSrcweir aKeyName = aInfFile.GetKeyName( nKey ); 711cdf0e10cSrcweir //...wenn ja, Indexliste der Tabelle hinzufuegen 712cdf0e10cSrcweir if (aKeyName.Copy(0,3) == ByteString("NDX") ) 713cdf0e10cSrcweir { 714cdf0e10cSrcweir aIndexName = aInfFile.ReadKey(aKeyName); 715cdf0e10cSrcweir aURL.setName(String(aIndexName,m_eEncoding)); 716cdf0e10cSrcweir try 717cdf0e10cSrcweir { 718cdf0e10cSrcweir Content aCnt(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 719cdf0e10cSrcweir if (aCnt.isDocument()) 720cdf0e10cSrcweir { 721cdf0e10cSrcweir aVector.push_back(aURL.getBase()); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir } 724cdf0e10cSrcweir catch(Exception&) // a execption is thrown when no file exists 725cdf0e10cSrcweir { 726cdf0e10cSrcweir } 727cdf0e10cSrcweir } 728cdf0e10cSrcweir } 729cdf0e10cSrcweir } 730cdf0e10cSrcweir if(m_pIndexes) 731cdf0e10cSrcweir m_pIndexes->reFill(aVector); 732cdf0e10cSrcweir else 733cdf0e10cSrcweir m_pIndexes = new ODbaseIndexes(this,m_aMutex,aVector); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir // ------------------------------------------------------------------------- 737cdf0e10cSrcweir void SAL_CALL ODbaseTable::disposing(void) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::disposing" ); 740cdf0e10cSrcweir OFileTable::disposing(); 741cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 742cdf0e10cSrcweir m_aColumns = NULL; 743cdf0e10cSrcweir } 744cdf0e10cSrcweir // ------------------------------------------------------------------------- 745cdf0e10cSrcweir Sequence< Type > SAL_CALL ODbaseTable::getTypes( ) throw(RuntimeException) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getTypes" ); 748cdf0e10cSrcweir Sequence< Type > aTypes = OTable_TYPEDEF::getTypes(); 749cdf0e10cSrcweir ::std::vector<Type> aOwnTypes; 750cdf0e10cSrcweir aOwnTypes.reserve(aTypes.getLength()); 751cdf0e10cSrcweir 752cdf0e10cSrcweir const Type* pBegin = aTypes.getConstArray(); 753cdf0e10cSrcweir const Type* pEnd = pBegin + aTypes.getLength(); 754cdf0e10cSrcweir for(;pBegin != pEnd;++pBegin) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir if(!(*pBegin == ::getCppuType((const Reference<XKeysSupplier>*)0) || 757cdf0e10cSrcweir // *pBegin == ::getCppuType((const Reference<XAlterTable>*)0) || 758cdf0e10cSrcweir *pBegin == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))) 759cdf0e10cSrcweir { 760cdf0e10cSrcweir aOwnTypes.push_back(*pBegin); 761cdf0e10cSrcweir } 762cdf0e10cSrcweir } 763cdf0e10cSrcweir aOwnTypes.push_back(::getCppuType( (const Reference< ::com::sun::star::lang::XUnoTunnel > *)0 )); 764cdf0e10cSrcweir Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; 765cdf0e10cSrcweir return Sequence< Type >(pTypes, aOwnTypes.size()); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir // ------------------------------------------------------------------------- 769cdf0e10cSrcweir Any SAL_CALL ODbaseTable::queryInterface( const Type & rType ) throw(RuntimeException) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::queryInterface" ); 772cdf0e10cSrcweir if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) || 773cdf0e10cSrcweir rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)) 774cdf0e10cSrcweir return Any(); 775cdf0e10cSrcweir 776cdf0e10cSrcweir Any aRet = OTable_TYPEDEF::queryInterface(rType); 777cdf0e10cSrcweir return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this)); 778cdf0e10cSrcweir } 779cdf0e10cSrcweir 780cdf0e10cSrcweir //-------------------------------------------------------------------------- 781cdf0e10cSrcweir Sequence< sal_Int8 > ODbaseTable::getUnoTunnelImplementationId() 782cdf0e10cSrcweir { 783cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getUnoTunnelImplementationId" ); 784cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0; 785cdf0e10cSrcweir if (! pId) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 788cdf0e10cSrcweir if (! pId) 789cdf0e10cSrcweir { 790cdf0e10cSrcweir static ::cppu::OImplementationId aId; 791cdf0e10cSrcweir pId = &aId; 792cdf0e10cSrcweir } 793cdf0e10cSrcweir } 794cdf0e10cSrcweir return pId->getImplementationId(); 795cdf0e10cSrcweir } 796cdf0e10cSrcweir 797cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel 798cdf0e10cSrcweir //------------------------------------------------------------------ 799cdf0e10cSrcweir sal_Int64 ODbaseTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getSomething" ); 802cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) 803cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this ) 804cdf0e10cSrcweir : ODbaseTable_BASE::getSomething(rId); 805cdf0e10cSrcweir } 806cdf0e10cSrcweir //------------------------------------------------------------------ 807cdf0e10cSrcweir sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, sal_Bool _bUseTableDefs,sal_Bool bRetrieveData) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::fetchRow" ); 810cdf0e10cSrcweir // Einlesen der Daten 811cdf0e10cSrcweir sal_Bool bIsCurRecordDeleted = ((char)m_pBuffer[0] == '*') ? sal_True : sal_False; 812cdf0e10cSrcweir 813cdf0e10cSrcweir // only read the bookmark 814cdf0e10cSrcweir 815cdf0e10cSrcweir // Satz als geloescht markieren 816cdf0e10cSrcweir // rRow.setState(bIsCurRecordDeleted ? ROW_DELETED : ROW_CLEAN ); 817cdf0e10cSrcweir _rRow->setDeleted(bIsCurRecordDeleted); 818cdf0e10cSrcweir *(_rRow->get())[0] = m_nFilePos; 819cdf0e10cSrcweir 820cdf0e10cSrcweir if (!bRetrieveData) 821cdf0e10cSrcweir return sal_True; 822cdf0e10cSrcweir 823cdf0e10cSrcweir sal_Size nByteOffset = 1; 824cdf0e10cSrcweir // Felder: 825cdf0e10cSrcweir OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); 826cdf0e10cSrcweir OSQLColumns::Vector::const_iterator aEnd = _rCols.get().end(); 827cdf0e10cSrcweir const sal_Size nCount = _rRow->get().size(); 828cdf0e10cSrcweir for (sal_Size i = 1; aIter != aEnd && nByteOffset <= m_nBufferSize && i < nCount;++aIter, i++) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir // Laengen je nach Datentyp: 831cdf0e10cSrcweir sal_Int32 nLen = 0; 832cdf0e10cSrcweir sal_Int32 nType = 0; 833cdf0e10cSrcweir if(_bUseTableDefs) 834cdf0e10cSrcweir { 835cdf0e10cSrcweir nLen = m_aPrecisions[i-1]; 836cdf0e10cSrcweir nType = m_aTypes[i-1]; 837cdf0e10cSrcweir } 838cdf0e10cSrcweir else 839cdf0e10cSrcweir { 840cdf0e10cSrcweir (*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen; 841cdf0e10cSrcweir (*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType; 842cdf0e10cSrcweir } 843cdf0e10cSrcweir switch(nType) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir case DataType::INTEGER: 846cdf0e10cSrcweir case DataType::DOUBLE: 847cdf0e10cSrcweir case DataType::TIMESTAMP: 848cdf0e10cSrcweir case DataType::DATE: 849cdf0e10cSrcweir case DataType::BIT: 850cdf0e10cSrcweir case DataType::LONGVARCHAR: 851cdf0e10cSrcweir case DataType::LONGVARBINARY: 852cdf0e10cSrcweir nLen = m_aRealFieldLengths[i-1]; 853cdf0e10cSrcweir break; 854cdf0e10cSrcweir case DataType::DECIMAL: 855cdf0e10cSrcweir if(_bUseTableDefs) 856cdf0e10cSrcweir nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,m_aScales[i-1]); 857cdf0e10cSrcweir else 858cdf0e10cSrcweir nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,getINT32((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); 859cdf0e10cSrcweir break; // das Vorzeichen und das Komma 860cdf0e10cSrcweir 861cdf0e10cSrcweir case DataType::BINARY: 862cdf0e10cSrcweir case DataType::OTHER: 863cdf0e10cSrcweir nByteOffset += nLen; 864cdf0e10cSrcweir continue; 865cdf0e10cSrcweir } 866cdf0e10cSrcweir 867cdf0e10cSrcweir // Ist die Variable ueberhaupt gebunden? 868cdf0e10cSrcweir if ( !(_rRow->get())[i]->isBound() ) 869cdf0e10cSrcweir { 870cdf0e10cSrcweir // Nein - naechstes Feld. 871cdf0e10cSrcweir nByteOffset += nLen; 872cdf0e10cSrcweir OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!"); 873cdf0e10cSrcweir continue; 874cdf0e10cSrcweir } // if ( !(_rRow->get())[i]->isBound() ) 875cdf0e10cSrcweir if ( ( nByteOffset + nLen) > m_nBufferSize ) 876cdf0e10cSrcweir break; // length doesn't match buffer size. 877cdf0e10cSrcweir 878cdf0e10cSrcweir char *pData = (char *) (m_pBuffer + nByteOffset); 879cdf0e10cSrcweir 880cdf0e10cSrcweir // (*_rRow)[i].setType(nType); 881cdf0e10cSrcweir 882cdf0e10cSrcweir if (nType == DataType::CHAR || nType == DataType::VARCHAR) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir char cLast = pData[nLen]; 885cdf0e10cSrcweir pData[nLen] = 0; 886cdf0e10cSrcweir String aStr(pData,(xub_StrLen)nLen,m_eEncoding); 887cdf0e10cSrcweir aStr.EraseTrailingChars(); 888cdf0e10cSrcweir 889cdf0e10cSrcweir if ( aStr.Len() ) 890cdf0e10cSrcweir *(_rRow->get())[i] = ::rtl::OUString(aStr); 891cdf0e10cSrcweir else// keine StringLaenge, dann NULL 892cdf0e10cSrcweir (_rRow->get())[i]->setNull(); 893cdf0e10cSrcweir 894cdf0e10cSrcweir pData[nLen] = cLast; 895cdf0e10cSrcweir } // if (nType == DataType::CHAR || nType == DataType::VARCHAR) 896cdf0e10cSrcweir else if ( DataType::TIMESTAMP == nType ) 897cdf0e10cSrcweir { 898cdf0e10cSrcweir sal_Int32 nDate = 0,nTime = 0; 899*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for date field"); 900*efddaef0SArrigo Marchiori if (nLen != 8) { 901*efddaef0SArrigo Marchiori return false; 902*efddaef0SArrigo Marchiori } 903cdf0e10cSrcweir memcpy(&nDate, pData, 4); 904cdf0e10cSrcweir memcpy(&nTime, pData+ 4, 4); 905cdf0e10cSrcweir if ( !nDate && !nTime ) 906cdf0e10cSrcweir { 907cdf0e10cSrcweir (_rRow->get())[i]->setNull(); 908cdf0e10cSrcweir } 909cdf0e10cSrcweir else 910cdf0e10cSrcweir { 911cdf0e10cSrcweir ::com::sun::star::util::DateTime aDateTime; 912cdf0e10cSrcweir lcl_CalDate(nDate,nTime,aDateTime); 913cdf0e10cSrcweir *(_rRow->get())[i] = aDateTime; 914cdf0e10cSrcweir } 915cdf0e10cSrcweir } 916cdf0e10cSrcweir else if ( DataType::INTEGER == nType ) 917cdf0e10cSrcweir { 918*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 4, "Invalid length for integer field"); 919*efddaef0SArrigo Marchiori if (nLen != 4) { 920*efddaef0SArrigo Marchiori return false; 921*efddaef0SArrigo Marchiori } 922cdf0e10cSrcweir sal_Int32 nValue = 0; 923cdf0e10cSrcweir memcpy(&nValue, pData, nLen); 924cdf0e10cSrcweir *(_rRow->get())[i] = nValue; 925cdf0e10cSrcweir } 926cdf0e10cSrcweir else if ( DataType::DOUBLE == nType ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir double d = 0.0; 929*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for double field"); 930*efddaef0SArrigo Marchiori if (nLen != 8) { 931*efddaef0SArrigo Marchiori return false; 932*efddaef0SArrigo Marchiori } 933cdf0e10cSrcweir if (getBOOL((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt 934cdf0e10cSrcweir { 935cdf0e10cSrcweir sal_Int64 nValue = 0; 936cdf0e10cSrcweir memcpy(&nValue, pData, nLen); 937cdf0e10cSrcweir 938cdf0e10cSrcweir if ( m_aScales[i-1] ) 939cdf0e10cSrcweir d = (double)(nValue / pow(10.0,(int)m_aScales[i-1])); 940cdf0e10cSrcweir else 941cdf0e10cSrcweir d = (double)(nValue); 942cdf0e10cSrcweir } 943cdf0e10cSrcweir else 944cdf0e10cSrcweir { 945cdf0e10cSrcweir memcpy(&d, pData, nLen); 946cdf0e10cSrcweir } 947cdf0e10cSrcweir 948cdf0e10cSrcweir *(_rRow->get())[i] = d; 949cdf0e10cSrcweir } 950cdf0e10cSrcweir else 951cdf0e10cSrcweir { 952cdf0e10cSrcweir // Falls Nul-Zeichen im String enthalten sind, in Blanks umwandeln! 953cdf0e10cSrcweir for (sal_Int32 k = 0; k < nLen; k++) 954cdf0e10cSrcweir { 955cdf0e10cSrcweir if (pData[k] == '\0') 956cdf0e10cSrcweir pData[k] = ' '; 957cdf0e10cSrcweir } 958cdf0e10cSrcweir 959cdf0e10cSrcweir String aStr(pData, (xub_StrLen)nLen,m_eEncoding); // Spaces am Anfang und am Ende entfernen: 960cdf0e10cSrcweir aStr.EraseLeadingChars(); 961cdf0e10cSrcweir aStr.EraseTrailingChars(); 962cdf0e10cSrcweir 963cdf0e10cSrcweir if (!aStr.Len()) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir nByteOffset += nLen; 966cdf0e10cSrcweir (_rRow->get())[i]->setNull(); // keine Werte -> fertig 967cdf0e10cSrcweir continue; 968cdf0e10cSrcweir } 969cdf0e10cSrcweir 970cdf0e10cSrcweir switch (nType) 971cdf0e10cSrcweir { 972cdf0e10cSrcweir case DataType::DATE: 973cdf0e10cSrcweir { 974*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for date field"); 975*efddaef0SArrigo Marchiori if (nLen != 8) { 976*efddaef0SArrigo Marchiori return false; 977*efddaef0SArrigo Marchiori } 978cdf0e10cSrcweir if (aStr.Len() != nLen) 979cdf0e10cSrcweir { 980cdf0e10cSrcweir (_rRow->get())[i]->setNull(); 981cdf0e10cSrcweir break; 982cdf0e10cSrcweir } 983cdf0e10cSrcweir const sal_uInt16 nYear = (sal_uInt16)aStr.Copy( 0, 4 ).ToInt32(); 984cdf0e10cSrcweir const sal_uInt16 nMonth = (sal_uInt16)aStr.Copy( 4, 2 ).ToInt32(); 985cdf0e10cSrcweir const sal_uInt16 nDay = (sal_uInt16)aStr.Copy( 6, 2 ).ToInt32(); 986cdf0e10cSrcweir 987cdf0e10cSrcweir const ::com::sun::star::util::Date aDate(nDay,nMonth,nYear); 988cdf0e10cSrcweir *(_rRow->get())[i] = aDate; 989cdf0e10cSrcweir } 990cdf0e10cSrcweir break; 991cdf0e10cSrcweir case DataType::DECIMAL: 992cdf0e10cSrcweir *(_rRow->get())[i] = ORowSetValue(aStr); 993cdf0e10cSrcweir // pVal->setDouble(SdbTools::ToDouble(aStr)); 994cdf0e10cSrcweir break; 995cdf0e10cSrcweir case DataType::BIT: 996cdf0e10cSrcweir { 997*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 1, "Invalid length for bit field"); 998*efddaef0SArrigo Marchiori if (nLen != 1) { 999*efddaef0SArrigo Marchiori return false; 1000*efddaef0SArrigo Marchiori } 1001cdf0e10cSrcweir sal_Bool b; 1002cdf0e10cSrcweir switch (* ((const char *)pData)) 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir case 'T': 1005cdf0e10cSrcweir case 'Y': 1006cdf0e10cSrcweir case 'J': b = sal_True; break; 1007cdf0e10cSrcweir default: b = sal_False; break; 1008cdf0e10cSrcweir } 1009cdf0e10cSrcweir *(_rRow->get())[i] = b; 1010cdf0e10cSrcweir // pVal->setDouble(b); 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir break; 1013cdf0e10cSrcweir case DataType::LONGVARBINARY: 1014cdf0e10cSrcweir case DataType::BINARY: 1015cdf0e10cSrcweir case DataType::LONGVARCHAR: 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir const long nBlockNo = aStr.ToInt32(); // Blocknummer lesen 1018cdf0e10cSrcweir if (nBlockNo > 0 && m_pMemoStream) // Daten aus Memo-Datei lesen, nur wenn 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir if ( !ReadMemo(nBlockNo, (_rRow->get())[i]->get()) ) 1021cdf0e10cSrcweir break; 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir else 1024cdf0e10cSrcweir (_rRow->get())[i]->setNull(); 1025cdf0e10cSrcweir } break; 1026cdf0e10cSrcweir default: 1027cdf0e10cSrcweir OSL_ASSERT("Falscher Type"); 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir (_rRow->get())[i]->setTypeKind(nType); 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir nByteOffset += nLen; 1033cdf0e10cSrcweir OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!"); 1034cdf0e10cSrcweir } 1035cdf0e10cSrcweir return sal_True; 1036cdf0e10cSrcweir } 1037cdf0e10cSrcweir //------------------------------------------------------------------ 1038cdf0e10cSrcweir // ------------------------------------------------------------------------- 1039cdf0e10cSrcweir void ODbaseTable::FileClose() 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::FileClose" ); 1042cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 1043cdf0e10cSrcweir // falls noch nicht alles geschrieben wurde 1044cdf0e10cSrcweir if (m_pMemoStream && m_pMemoStream->IsWritable()) 1045cdf0e10cSrcweir m_pMemoStream->Flush(); 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir delete m_pMemoStream; 1048cdf0e10cSrcweir m_pMemoStream = NULL; 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir ODbaseTable_BASE::FileClose(); 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir // ------------------------------------------------------------------------- 1053cdf0e10cSrcweir sal_Bool ODbaseTable::CreateImpl() 1054cdf0e10cSrcweir { 1055cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::CreateImpl" ); 1056cdf0e10cSrcweir OSL_ENSURE(!m_pFileStream, "SequenceError"); 1057cdf0e10cSrcweir 1058cdf0e10cSrcweir if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name,::rtl::OUString()) != m_Name ) 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 1061cdf0e10cSrcweir STR_SQL_NAME_ERROR, 1062cdf0e10cSrcweir "$name$", m_Name 1063cdf0e10cSrcweir ) ); 1064cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir 1067cdf0e10cSrcweir INetURLObject aURL; 1068cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE); 1069cdf0e10cSrcweir String aName = getEntry(m_pConnection,m_Name); 1070cdf0e10cSrcweir if(!aName.Len()) 1071cdf0e10cSrcweir { 1072cdf0e10cSrcweir ::rtl::OUString aIdent = m_pConnection->getContent()->getIdentifier()->getContentIdentifier(); 1073cdf0e10cSrcweir if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) 1074cdf0e10cSrcweir aIdent += ::rtl::OUString::createFromAscii("/"); 1075cdf0e10cSrcweir aIdent += m_Name; 1076cdf0e10cSrcweir aName = aIdent.getStr(); 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir aURL.SetURL(aName); 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir if ( !m_pConnection->matchesExtension( aURL.getExtension() ) ) 1081cdf0e10cSrcweir aURL.setExtension(m_pConnection->getExtension()); 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir try 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 1086cdf0e10cSrcweir if (aContent.isDocument()) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir // Hack fuer Bug #30609 , nur wenn das File existiert und die Laenge > 0 gibt es einen Fehler 1089cdf0e10cSrcweir SvStream* pFileStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::NO_DECODE),STREAM_READ); 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir if (pFileStream && pFileStream->Seek(STREAM_SEEK_TO_END)) 1092cdf0e10cSrcweir { 1093cdf0e10cSrcweir // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,TABLE,aFile.GetFull()); 1094cdf0e10cSrcweir return sal_False; 1095cdf0e10cSrcweir } 1096cdf0e10cSrcweir delete pFileStream; 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir } 1099cdf0e10cSrcweir catch(Exception&) // a execption is thrown when no file exists 1100cdf0e10cSrcweir { 1101cdf0e10cSrcweir } 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir sal_Bool bMemoFile = sal_False; 1104cdf0e10cSrcweir 1105cdf0e10cSrcweir sal_Bool bOk = CreateFile(aURL, bMemoFile); 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir FileClose(); 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir if (!bOk) 1110cdf0e10cSrcweir { 1111cdf0e10cSrcweir try 1112cdf0e10cSrcweir { 1113cdf0e10cSrcweir Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 1114cdf0e10cSrcweir aContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir catch(Exception&) // a execption is thrown when no file exists 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir } 1119cdf0e10cSrcweir return sal_False; 1120cdf0e10cSrcweir } 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir if (bMemoFile) 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir String aExt = aURL.getExtension(); 1125cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("dbt")); // extension for memo file 1126cdf0e10cSrcweir Content aMemo1Content(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir sal_Bool bMemoAlreadyExists = sal_False; 1129cdf0e10cSrcweir try 1130cdf0e10cSrcweir { 1131cdf0e10cSrcweir bMemoAlreadyExists = aMemo1Content.isDocument(); 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir catch(Exception&) // a execption is thrown when no file exists 1134cdf0e10cSrcweir { 1135cdf0e10cSrcweir } 1136cdf0e10cSrcweir if (bMemoAlreadyExists) 1137cdf0e10cSrcweir { 1138cdf0e10cSrcweir // aStatus.SetError(ERRCODE_IO_ALREADYEXISTS,MEMO,aFile.GetFull()); 1139cdf0e10cSrcweir aURL.setExtension(aExt); // kill dbf file 1140cdf0e10cSrcweir try 1141cdf0e10cSrcweir { 1142cdf0e10cSrcweir Content aMemoContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 1143cdf0e10cSrcweir aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); 1144cdf0e10cSrcweir } 1145cdf0e10cSrcweir catch(const Exception&) 1146cdf0e10cSrcweir { 1147cdf0e10cSrcweir 1148cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 1149cdf0e10cSrcweir STR_COULD_NOT_DELETE_FILE, 1150cdf0e10cSrcweir "$name$", aName 1151cdf0e10cSrcweir ) ); 1152cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir if (!CreateMemoFile(aURL)) 1156cdf0e10cSrcweir { 1157cdf0e10cSrcweir aURL.setExtension(aExt); // kill dbf file 1158cdf0e10cSrcweir Content aMemoContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 1159cdf0e10cSrcweir aMemoContent.executeCommand( rtl::OUString::createFromAscii( "delete" ),bool2any( sal_True ) ); 1160cdf0e10cSrcweir return sal_False; 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir m_aHeader.db_typ = dBaseIIIMemo; 1163cdf0e10cSrcweir } 1164cdf0e10cSrcweir else 1165cdf0e10cSrcweir m_aHeader.db_typ = dBaseIII; 1166cdf0e10cSrcweir 1167cdf0e10cSrcweir return sal_True; 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1170cdf0e10cSrcweir void ODbaseTable::throwInvalidColumnType(const sal_uInt16 _nErrorId,const ::rtl::OUString& _sColumnName) 1171cdf0e10cSrcweir { 1172cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::throwInvalidColumnType" ); 1173cdf0e10cSrcweir try 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir // we have to drop the file because it is corrupted now 1176cdf0e10cSrcweir DropImpl(); 1177cdf0e10cSrcweir } 1178cdf0e10cSrcweir catch(const Exception&) 1179cdf0e10cSrcweir { 1180cdf0e10cSrcweir } 1181cdf0e10cSrcweir 1182cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 1183cdf0e10cSrcweir _nErrorId, 1184cdf0e10cSrcweir "$columnname$", _sColumnName 1185cdf0e10cSrcweir ) ); 1186cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 1187cdf0e10cSrcweir } 1188cdf0e10cSrcweir //------------------------------------------------------------------ 1189cdf0e10cSrcweir // erzeugt grundsaetzlich dBase IV Datei Format 1190cdf0e10cSrcweir sal_Bool ODbaseTable::CreateFile(const INetURLObject& aFile, sal_Bool& bCreateMemo) 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::CreateFile" ); 1193cdf0e10cSrcweir bCreateMemo = sal_False; 1194cdf0e10cSrcweir Date aDate; // aktuelles Datum 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir m_pFileStream = createStream_simpleError( aFile.GetMainURL(INetURLObject::NO_DECODE),STREAM_READWRITE | STREAM_SHARE_DENYWRITE | STREAM_TRUNC ); 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir if (!m_pFileStream) 1199cdf0e10cSrcweir return sal_False; 1200cdf0e10cSrcweir 1201cdf0e10cSrcweir sal_uInt8 nDbaseType = dBaseIII; 1202cdf0e10cSrcweir Reference<XIndexAccess> xColumns(getColumns(),UNO_QUERY); 1203cdf0e10cSrcweir Reference<XPropertySet> xCol; 1204cdf0e10cSrcweir const ::rtl::OUString sPropType = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE); 1205cdf0e10cSrcweir 1206cdf0e10cSrcweir try 1207cdf0e10cSrcweir { 1208cdf0e10cSrcweir const sal_Int32 nCount = xColumns->getCount(); 1209cdf0e10cSrcweir for(sal_Int32 i=0;i<nCount;++i) 1210cdf0e10cSrcweir { 1211cdf0e10cSrcweir xColumns->getByIndex(i) >>= xCol; 1212cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"This should be a column!"); 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir switch (getINT32(xCol->getPropertyValue(sPropType))) 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir case DataType::DOUBLE: 1217cdf0e10cSrcweir case DataType::INTEGER: 1218cdf0e10cSrcweir case DataType::TIMESTAMP: 1219cdf0e10cSrcweir case DataType::LONGVARBINARY: 1220cdf0e10cSrcweir nDbaseType = VisualFoxPro; 1221cdf0e10cSrcweir i = nCount; // no more columns need to be checked 1222cdf0e10cSrcweir break; 1223cdf0e10cSrcweir } // switch (getINT32(xCol->getPropertyValue(sPropType))) 1224cdf0e10cSrcweir } 1225cdf0e10cSrcweir } 1226cdf0e10cSrcweir catch ( const Exception& e ) 1227cdf0e10cSrcweir { 1228cdf0e10cSrcweir (void)e; 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir try 1231cdf0e10cSrcweir { 1232cdf0e10cSrcweir // we have to drop the file because it is corrupted now 1233cdf0e10cSrcweir DropImpl(); 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir catch(const Exception&) { } 1236cdf0e10cSrcweir throw; 1237cdf0e10cSrcweir } 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir char aBuffer[21]; // write buffer 1240cdf0e10cSrcweir memset(aBuffer,0,sizeof(aBuffer)); 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir m_pFileStream->Seek(0L); 1243cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) nDbaseType; // dBase format 1244cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) (aDate.GetYear() % 100); // aktuelles Datum 1245cdf0e10cSrcweir 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) aDate.GetMonth(); 1248cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) aDate.GetDay(); 1249cdf0e10cSrcweir (*m_pFileStream) << 0L; // Anzahl der Datensaetze 1250cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt16)((m_pColumns->getCount()+1) * 32 + 1); // Kopfinformationen, 1251cdf0e10cSrcweir // pColumns erhaelt immer eine Spalte mehr 1252cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt16) 0; // Satzlaenge wird spaeter bestimmt 1253cdf0e10cSrcweir m_pFileStream->Write(aBuffer, 20); 1254cdf0e10cSrcweir 1255cdf0e10cSrcweir sal_uInt16 nRecLength = 1; // Laenge 1 fuer deleted flag 1256cdf0e10cSrcweir sal_Int32 nMaxFieldLength = m_pConnection->getMetaData()->getMaxColumnNameLength(); 1257cdf0e10cSrcweir ::rtl::OUString aName; 1258cdf0e10cSrcweir const ::rtl::OUString sPropName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); 1259cdf0e10cSrcweir const ::rtl::OUString sPropPrec = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION); 1260cdf0e10cSrcweir const ::rtl::OUString sPropScale = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE); 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir try 1263cdf0e10cSrcweir { 1264cdf0e10cSrcweir const sal_Int32 nCount = xColumns->getCount(); 1265cdf0e10cSrcweir for(sal_Int32 i=0;i<nCount;++i) 1266cdf0e10cSrcweir { 1267cdf0e10cSrcweir xColumns->getByIndex(i) >>= xCol; 1268cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"This should be a column!"); 1269cdf0e10cSrcweir 1270cdf0e10cSrcweir char cTyp( 'C' ); 1271cdf0e10cSrcweir 1272cdf0e10cSrcweir xCol->getPropertyValue(sPropName) >>= aName; 1273cdf0e10cSrcweir 1274cdf0e10cSrcweir ::rtl::OString aCol; 1275cdf0e10cSrcweir if ( DBTypeConversion::convertUnicodeString( aName, aCol, m_eEncoding ) > nMaxFieldLength) 1276cdf0e10cSrcweir { 1277cdf0e10cSrcweir throwInvalidColumnType( STR_INVALID_COLUMN_NAME_LENGTH, aName ); 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir (*m_pFileStream) << aCol.getStr(); 1281cdf0e10cSrcweir m_pFileStream->Write(aBuffer, 11 - aCol.getLength()); 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir sal_Int32 nPrecision = 0; 1284cdf0e10cSrcweir xCol->getPropertyValue(sPropPrec) >>= nPrecision; 1285cdf0e10cSrcweir sal_Int32 nScale = 0; 1286cdf0e10cSrcweir xCol->getPropertyValue(sPropScale) >>= nScale; 1287cdf0e10cSrcweir 1288cdf0e10cSrcweir bool bBinary = false; 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir switch (getINT32(xCol->getPropertyValue(sPropType))) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir case DataType::CHAR: 1293cdf0e10cSrcweir case DataType::VARCHAR: 1294cdf0e10cSrcweir cTyp = 'C'; 1295cdf0e10cSrcweir break; 1296cdf0e10cSrcweir case DataType::DOUBLE: 1297cdf0e10cSrcweir if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt 1298cdf0e10cSrcweir cTyp = 'Y'; 1299cdf0e10cSrcweir else 1300cdf0e10cSrcweir cTyp = 'B'; 1301cdf0e10cSrcweir break; 1302cdf0e10cSrcweir case DataType::INTEGER: 1303cdf0e10cSrcweir cTyp = 'I'; 1304cdf0e10cSrcweir break; 1305cdf0e10cSrcweir case DataType::TINYINT: 1306cdf0e10cSrcweir case DataType::SMALLINT: 1307cdf0e10cSrcweir case DataType::BIGINT: 1308cdf0e10cSrcweir case DataType::DECIMAL: 1309cdf0e10cSrcweir case DataType::NUMERIC: 1310cdf0e10cSrcweir case DataType::REAL: 1311cdf0e10cSrcweir cTyp = 'N'; // nur dBase 3 format 1312cdf0e10cSrcweir break; 1313cdf0e10cSrcweir case DataType::TIMESTAMP: 1314cdf0e10cSrcweir cTyp = 'T'; 1315cdf0e10cSrcweir break; 1316cdf0e10cSrcweir case DataType::DATE: 1317cdf0e10cSrcweir cTyp = 'D'; 1318cdf0e10cSrcweir break; 1319cdf0e10cSrcweir case DataType::BIT: 1320cdf0e10cSrcweir cTyp = 'L'; 1321cdf0e10cSrcweir break; 1322cdf0e10cSrcweir case DataType::LONGVARBINARY: 1323cdf0e10cSrcweir bBinary = true; 1324cdf0e10cSrcweir // run through 1325cdf0e10cSrcweir case DataType::LONGVARCHAR: 1326cdf0e10cSrcweir cTyp = 'M'; 1327cdf0e10cSrcweir break; 1328cdf0e10cSrcweir default: 1329cdf0e10cSrcweir { 1330cdf0e10cSrcweir throwInvalidColumnType(STR_INVALID_COLUMN_TYPE, aName); 1331cdf0e10cSrcweir } 1332cdf0e10cSrcweir } 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir (*m_pFileStream) << cTyp; 1335cdf0e10cSrcweir if ( nDbaseType == VisualFoxPro ) 1336cdf0e10cSrcweir (*m_pFileStream) << (nRecLength-1); 1337cdf0e10cSrcweir else 1338cdf0e10cSrcweir m_pFileStream->Write(aBuffer, 4); 1339cdf0e10cSrcweir 1340cdf0e10cSrcweir switch(cTyp) 1341cdf0e10cSrcweir { 1342cdf0e10cSrcweir case 'C': 1343cdf0e10cSrcweir OSL_ENSURE(nPrecision < 255, "ODbaseTable::Create: Column zu lang!"); 1344cdf0e10cSrcweir if (nPrecision > 254) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir throwInvalidColumnType(STR_INVALID_COLUMN_PRECISION, aName); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) Min((sal_uIntPtr)nPrecision, 255UL); //Feldlaenge 1349cdf0e10cSrcweir nRecLength = nRecLength + (sal_uInt16)::std::min((sal_uInt16)nPrecision, (sal_uInt16)255UL); 1350cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)0; //Nachkommastellen 1351cdf0e10cSrcweir break; 1352cdf0e10cSrcweir case 'F': 1353cdf0e10cSrcweir case 'N': 1354cdf0e10cSrcweir OSL_ENSURE(nPrecision >= nScale, 1355cdf0e10cSrcweir "ODbaseTable::Create: Feldlaenge muss groesser Nachkommastellen sein!"); 1356cdf0e10cSrcweir if (nPrecision < nScale) 1357cdf0e10cSrcweir { 1358cdf0e10cSrcweir throwInvalidColumnType(STR_INVALID_PRECISION_SCALE, aName); 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt 1361cdf0e10cSrcweir { 1362cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)10; // Standard Laenge 1363cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)4; 1364cdf0e10cSrcweir nRecLength += 10; 1365cdf0e10cSrcweir } 1366cdf0e10cSrcweir else 1367cdf0e10cSrcweir { 1368cdf0e10cSrcweir sal_Int32 nPrec = SvDbaseConverter::ConvertPrecisionToDbase(nPrecision,nScale); 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)( nPrec); 1371cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)nScale; 1372cdf0e10cSrcweir nRecLength += (sal_uInt16)nPrec; 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir break; 1375cdf0e10cSrcweir case 'L': 1376cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)1; 1377cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)0; 1378cdf0e10cSrcweir ++nRecLength; 1379cdf0e10cSrcweir break; 1380cdf0e10cSrcweir case 'I': 1381cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)4; 1382cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)0; 1383cdf0e10cSrcweir nRecLength += 4; 1384cdf0e10cSrcweir break; 1385cdf0e10cSrcweir case 'Y': 1386cdf0e10cSrcweir case 'B': 1387cdf0e10cSrcweir case 'T': 1388cdf0e10cSrcweir case 'D': 1389cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)8; 1390cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)0; 1391cdf0e10cSrcweir nRecLength += 8; 1392cdf0e10cSrcweir break; 1393cdf0e10cSrcweir case 'M': 1394cdf0e10cSrcweir bCreateMemo = sal_True; 1395cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)10; 1396cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)0; 1397cdf0e10cSrcweir nRecLength += 10; 1398cdf0e10cSrcweir if ( bBinary ) 1399cdf0e10cSrcweir aBuffer[0] = 0x06; 1400cdf0e10cSrcweir break; 1401cdf0e10cSrcweir default: 1402cdf0e10cSrcweir throwInvalidColumnType(STR_INVALID_COLUMN_TYPE, aName); 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir m_pFileStream->Write(aBuffer, 14); 1405cdf0e10cSrcweir aBuffer[0] = 0x00; 1406cdf0e10cSrcweir } 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)FIELD_DESCRIPTOR_TERMINATOR; // kopf ende 1409cdf0e10cSrcweir (*m_pFileStream) << (char)DBF_EOL; 1410cdf0e10cSrcweir m_pFileStream->Seek(10L); 1411cdf0e10cSrcweir (*m_pFileStream) << nRecLength; // Satzlaenge nachtraeglich eintragen 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir if (bCreateMemo) 1414cdf0e10cSrcweir { 1415cdf0e10cSrcweir m_pFileStream->Seek(0L); 1416cdf0e10cSrcweir if (nDbaseType == VisualFoxPro) 1417cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) FoxProMemo; 1418cdf0e10cSrcweir else 1419cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8) dBaseIIIMemo; 1420cdf0e10cSrcweir } // if (bCreateMemo) 1421cdf0e10cSrcweir } 1422cdf0e10cSrcweir catch ( const Exception& e ) 1423cdf0e10cSrcweir { 1424cdf0e10cSrcweir (void)e; 1425cdf0e10cSrcweir 1426cdf0e10cSrcweir try 1427cdf0e10cSrcweir { 1428cdf0e10cSrcweir // we have to drop the file because it is corrupted now 1429cdf0e10cSrcweir DropImpl(); 1430cdf0e10cSrcweir } 1431cdf0e10cSrcweir catch(const Exception&) { } 1432cdf0e10cSrcweir throw; 1433cdf0e10cSrcweir } 1434cdf0e10cSrcweir return sal_True; 1435cdf0e10cSrcweir } 1436cdf0e10cSrcweir 1437cdf0e10cSrcweir //------------------------------------------------------------------ 1438cdf0e10cSrcweir // erzeugt grundsaetzlich dBase III Datei Format 1439cdf0e10cSrcweir sal_Bool ODbaseTable::CreateMemoFile(const INetURLObject& aFile) 1440cdf0e10cSrcweir { 1441cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::CreateMemoFile" ); 1442cdf0e10cSrcweir // Makro zum Filehandling fuers Erzeugen von Tabellen 1443cdf0e10cSrcweir m_pMemoStream = createStream_simpleError( aFile.GetMainURL(INetURLObject::NO_DECODE),STREAM_READWRITE | STREAM_SHARE_DENYWRITE); 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir if (!m_pMemoStream) 1446cdf0e10cSrcweir return sal_False; 1447cdf0e10cSrcweir 1448cdf0e10cSrcweir char aBuffer[512]; // write buffer 1449cdf0e10cSrcweir memset(aBuffer,0,sizeof(aBuffer)); 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir m_pMemoStream->SetFiller('\0'); 1452cdf0e10cSrcweir m_pMemoStream->SetStreamSize(512); 1453cdf0e10cSrcweir 1454cdf0e10cSrcweir m_pMemoStream->Seek(0L); 1455cdf0e10cSrcweir (*m_pMemoStream) << long(1); // Zeiger auf ersten freien Block 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir m_pMemoStream->Flush(); 1458cdf0e10cSrcweir delete m_pMemoStream; 1459cdf0e10cSrcweir m_pMemoStream = NULL; 1460cdf0e10cSrcweir return sal_True; 1461cdf0e10cSrcweir } 1462cdf0e10cSrcweir //------------------------------------------------------------------ 1463cdf0e10cSrcweir sal_Bool ODbaseTable::Drop_Static(const ::rtl::OUString& _sUrl,sal_Bool _bHasMemoFields,OCollection* _pIndexes ) 1464cdf0e10cSrcweir { 1465cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::Drop_Static" ); 1466cdf0e10cSrcweir INetURLObject aURL; 1467cdf0e10cSrcweir aURL.SetURL(_sUrl); 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir sal_Bool bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE)); 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir if(bDropped) 1472cdf0e10cSrcweir { 1473cdf0e10cSrcweir if (_bHasMemoFields) 1474cdf0e10cSrcweir { // delete the memo fields 1475cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("dbt")); 1476cdf0e10cSrcweir bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::NO_DECODE)); 1477cdf0e10cSrcweir } 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir if(bDropped) 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir if(_pIndexes) 1482cdf0e10cSrcweir { 1483cdf0e10cSrcweir try 1484cdf0e10cSrcweir { 1485cdf0e10cSrcweir sal_Int32 i = _pIndexes->getCount(); 1486cdf0e10cSrcweir while (i) 1487cdf0e10cSrcweir { 1488cdf0e10cSrcweir _pIndexes->dropByIndex(--i); 1489cdf0e10cSrcweir } 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir catch(SQLException) 1492cdf0e10cSrcweir { 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir } 1495cdf0e10cSrcweir // aFile.SetBase(m_Name); 1496cdf0e10cSrcweir aURL.setExtension(String::CreateFromAscii("inf")); 1497cdf0e10cSrcweir 1498cdf0e10cSrcweir // as the inf file does not necessarily exist, we aren't allowed to use UCBContentHelper::Kill 1499cdf0e10cSrcweir // 89711 - 16.07.2001 - frank.schoenheit@sun.com 1500cdf0e10cSrcweir try 1501cdf0e10cSrcweir { 1502cdf0e10cSrcweir ::ucbhelper::Content aDeleteContent( aURL.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment > () ); 1503cdf0e10cSrcweir aDeleteContent.executeCommand( ::rtl::OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) ); 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir catch(Exception&) 1506cdf0e10cSrcweir { 1507cdf0e10cSrcweir // silently ignore this .... 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir } 1511cdf0e10cSrcweir return bDropped; 1512cdf0e10cSrcweir } 1513cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1514cdf0e10cSrcweir sal_Bool ODbaseTable::DropImpl() 1515cdf0e10cSrcweir { 1516cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::DropImpl" ); 1517cdf0e10cSrcweir FileClose(); 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir if(!m_pIndexes) 1520cdf0e10cSrcweir refreshIndexes(); // look for indexes which must be deleted as well 1521cdf0e10cSrcweir 1522cdf0e10cSrcweir sal_Bool bDropped = Drop_Static(getEntry(m_pConnection,m_Name),HasMemoFields(),m_pIndexes); 1523cdf0e10cSrcweir if(!bDropped) 1524cdf0e10cSrcweir {// we couldn't drop the table so we have to reopen it 1525cdf0e10cSrcweir construct(); 1526cdf0e10cSrcweir if(m_pColumns) 1527cdf0e10cSrcweir m_pColumns->refresh(); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir return bDropped; 1530cdf0e10cSrcweir } 1531cdf0e10cSrcweir 1532cdf0e10cSrcweir //------------------------------------------------------------------ 1533cdf0e10cSrcweir sal_Bool ODbaseTable::InsertRow(OValueRefVector& rRow, sal_Bool bFlush,const Reference<XIndexAccess>& _xCols) 1534cdf0e10cSrcweir { 1535cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::InsertRow" ); 1536cdf0e10cSrcweir // Buffer mit Leerzeichen fuellen 1537cdf0e10cSrcweir AllocBuffer(); 1538cdf0e10cSrcweir memset(m_pBuffer, 0, m_aHeader.db_slng); 1539cdf0e10cSrcweir m_pBuffer[0] = ' '; 1540cdf0e10cSrcweir 1541cdf0e10cSrcweir // Gesamte neue Row uebernehmen: 1542cdf0e10cSrcweir // ... und am Ende als neuen Record hinzufuegen: 1543cdf0e10cSrcweir sal_uInt32 nTempPos = m_nFilePos, 1544cdf0e10cSrcweir nFileSize = 0, 1545cdf0e10cSrcweir nMemoFileSize = 0; 1546cdf0e10cSrcweir 1547cdf0e10cSrcweir m_nFilePos = (sal_uIntPtr)m_aHeader.db_anz + 1; 1548cdf0e10cSrcweir sal_Bool bInsertRow = UpdateBuffer( rRow, NULL, _xCols ); 1549cdf0e10cSrcweir if ( bInsertRow ) 1550cdf0e10cSrcweir { 1551cdf0e10cSrcweir nFileSize = lcl_getFileSize(*m_pFileStream); 1552cdf0e10cSrcweir 1553cdf0e10cSrcweir if (HasMemoFields() && m_pMemoStream) 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir m_pMemoStream->Seek(STREAM_SEEK_TO_END); 1556cdf0e10cSrcweir nMemoFileSize = m_pMemoStream->Tell(); 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir if (!WriteBuffer()) 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir m_pFileStream->SetStreamSize(nFileSize); // alte Groesse restaurieren 1562cdf0e10cSrcweir 1563cdf0e10cSrcweir if (HasMemoFields() && m_pMemoStream) 1564cdf0e10cSrcweir m_pMemoStream->SetStreamSize(nMemoFileSize); // alte Groesse restaurieren 1565cdf0e10cSrcweir m_nFilePos = nTempPos; // Fileposition restaurieren 1566cdf0e10cSrcweir } 1567cdf0e10cSrcweir else 1568cdf0e10cSrcweir { 1569cdf0e10cSrcweir (*m_pFileStream) << (char)DBF_EOL; // write EOL 1570cdf0e10cSrcweir // Anzahl Datensaetze im Header erhoehen: 1571cdf0e10cSrcweir m_pFileStream->Seek( 4L ); 1572cdf0e10cSrcweir (*m_pFileStream) << (m_aHeader.db_anz + 1); 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir // beim AppendOnly kein Flush! 1575cdf0e10cSrcweir if (bFlush) 1576cdf0e10cSrcweir m_pFileStream->Flush(); 1577cdf0e10cSrcweir 1578cdf0e10cSrcweir // bei Erfolg # erhoehen 1579cdf0e10cSrcweir m_aHeader.db_anz++; 1580cdf0e10cSrcweir *rRow.get()[0] = m_nFilePos; // BOOKmark setzen 1581cdf0e10cSrcweir m_nFilePos = nTempPos; 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir } 1584cdf0e10cSrcweir else 1585cdf0e10cSrcweir m_nFilePos = nTempPos; 1586cdf0e10cSrcweir 1587cdf0e10cSrcweir return bInsertRow; 1588cdf0e10cSrcweir } 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir //------------------------------------------------------------------ 1591cdf0e10cSrcweir sal_Bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow,const Reference<XIndexAccess>& _xCols) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::UpdateRow" ); 1594cdf0e10cSrcweir // Buffer mit Leerzeichen fuellen 1595cdf0e10cSrcweir AllocBuffer(); 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir // Auf gewuenschten Record positionieren: 1598cdf0e10cSrcweir long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; 1599cdf0e10cSrcweir m_pFileStream->Seek(nPos); 1600cdf0e10cSrcweir m_pFileStream->Read((char*)m_pBuffer, m_aHeader.db_slng); 1601cdf0e10cSrcweir 1602cdf0e10cSrcweir sal_uInt32 nMemoFileSize( 0 ); 1603cdf0e10cSrcweir if (HasMemoFields() && m_pMemoStream) 1604cdf0e10cSrcweir { 1605cdf0e10cSrcweir m_pMemoStream->Seek(STREAM_SEEK_TO_END); 1606cdf0e10cSrcweir nMemoFileSize = m_pMemoStream->Tell(); 1607cdf0e10cSrcweir } 1608cdf0e10cSrcweir if (!UpdateBuffer(rRow, pOrgRow,_xCols) || !WriteBuffer()) 1609cdf0e10cSrcweir { 1610cdf0e10cSrcweir if (HasMemoFields() && m_pMemoStream) 1611cdf0e10cSrcweir m_pMemoStream->SetStreamSize(nMemoFileSize); // alte Groesse restaurieren 1612cdf0e10cSrcweir } 1613cdf0e10cSrcweir else 1614cdf0e10cSrcweir { 1615cdf0e10cSrcweir m_pFileStream->Flush(); 1616cdf0e10cSrcweir } 1617cdf0e10cSrcweir return sal_True; 1618cdf0e10cSrcweir } 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir //------------------------------------------------------------------ 1621cdf0e10cSrcweir sal_Bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols) 1622cdf0e10cSrcweir { 1623cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::DeleteRow" ); 1624cdf0e10cSrcweir // Einfach das Loesch-Flag setzen (egal, ob es schon gesetzt war 1625cdf0e10cSrcweir // oder nicht): 1626cdf0e10cSrcweir // Auf gewuenschten Record positionieren: 1627cdf0e10cSrcweir long nFilePos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; 1628cdf0e10cSrcweir m_pFileStream->Seek(nFilePos); 1629cdf0e10cSrcweir 1630cdf0e10cSrcweir OValueRefRow aRow = new OValueRefVector(_rCols.get().size()); 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir if (!fetchRow(aRow,_rCols,sal_True,sal_True)) 1633cdf0e10cSrcweir return sal_False; 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir Reference<XPropertySet> xCol; 1636cdf0e10cSrcweir ::rtl::OUString aColName; 1637cdf0e10cSrcweir ::comphelper::UStringMixEqual aCase(isCaseSensitive()); 1638cdf0e10cSrcweir for (sal_uInt16 i = 0; i < m_pColumns->getCount(); i++) 1639cdf0e10cSrcweir { 1640cdf0e10cSrcweir Reference<XPropertySet> xIndex = isUniqueByColumnName(i); 1641cdf0e10cSrcweir if (xIndex.is()) 1642cdf0e10cSrcweir { 1643cdf0e10cSrcweir ::cppu::extractInterface(xCol,m_pColumns->getByIndex(i)); 1644cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::DeleteRow column is null!"); 1645cdf0e10cSrcweir if(xCol.is()) 1646cdf0e10cSrcweir { 1647cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 1648cdf0e10cSrcweir 1649cdf0e10cSrcweir Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); 1650cdf0e10cSrcweir OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); 1651cdf0e10cSrcweir ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) ); 1652cdf0e10cSrcweir OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!"); 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); 1655cdf0e10cSrcweir sal_Int32 nPos = 1; 1656cdf0e10cSrcweir for(;aIter != _rCols.get().end();++aIter,++nPos) 1657cdf0e10cSrcweir { 1658cdf0e10cSrcweir if(aCase(getString((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME))),aColName)) 1659cdf0e10cSrcweir break; 1660cdf0e10cSrcweir } 1661cdf0e10cSrcweir if (aIter == _rCols.get().end()) 1662cdf0e10cSrcweir continue; 1663cdf0e10cSrcweir 1664cdf0e10cSrcweir pIndex->Delete(m_nFilePos,*(aRow->get())[nPos]); 1665cdf0e10cSrcweir } 1666cdf0e10cSrcweir } 1667cdf0e10cSrcweir } 1668cdf0e10cSrcweir 1669cdf0e10cSrcweir m_pFileStream->Seek(nFilePos); 1670cdf0e10cSrcweir (*m_pFileStream) << (sal_uInt8)'*'; // mark the row in the table as deleted 1671cdf0e10cSrcweir m_pFileStream->Flush(); 1672cdf0e10cSrcweir return sal_True; 1673cdf0e10cSrcweir } 1674cdf0e10cSrcweir // ------------------------------------------------------------------------- 1675cdf0e10cSrcweir Reference<XPropertySet> ODbaseTable::isUniqueByColumnName(sal_Int32 _nColumnPos) 1676cdf0e10cSrcweir { 1677cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::isUniqueByColumnName" ); 1678cdf0e10cSrcweir if(!m_pIndexes) 1679cdf0e10cSrcweir refreshIndexes(); 1680cdf0e10cSrcweir if(m_pIndexes->hasElements()) 1681cdf0e10cSrcweir { 1682cdf0e10cSrcweir Reference<XPropertySet> xCol; 1683cdf0e10cSrcweir m_pColumns->getByIndex(_nColumnPos) >>= xCol; 1684cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::isUniqueByColumnName column is null!"); 1685cdf0e10cSrcweir ::rtl::OUString sColName; 1686cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sColName; 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir Reference<XPropertySet> xIndex; 1689cdf0e10cSrcweir for(sal_Int32 i=0;i<m_pIndexes->getCount();++i) 1690cdf0e10cSrcweir { 1691cdf0e10cSrcweir ::cppu::extractInterface(xIndex,m_pIndexes->getByIndex(i)); 1692cdf0e10cSrcweir if(xIndex.is() && getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE)))) 1693cdf0e10cSrcweir { 1694cdf0e10cSrcweir Reference<XNameAccess> xCols(Reference<XColumnsSupplier>(xIndex,UNO_QUERY)->getColumns()); 1695cdf0e10cSrcweir if(xCols->hasByName(sColName)) 1696cdf0e10cSrcweir return xIndex; 1697cdf0e10cSrcweir 1698cdf0e10cSrcweir } 1699cdf0e10cSrcweir } 1700cdf0e10cSrcweir } 1701cdf0e10cSrcweir return Reference<XPropertySet>(); 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir //------------------------------------------------------------------ 1704cdf0e10cSrcweir double toDouble(const ByteString& rString) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir return ::rtl::math::stringToDouble( rString, '.', ',', NULL, NULL ); 1707cdf0e10cSrcweir } 1708cdf0e10cSrcweir 1709cdf0e10cSrcweir //------------------------------------------------------------------ 1710cdf0e10cSrcweir sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const Reference<XIndexAccess>& _xCols) 1711cdf0e10cSrcweir { 1712cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::UpdateBuffer" ); 1713cdf0e10cSrcweir OSL_ENSURE(m_pBuffer,"Buffer is NULL!"); 1714cdf0e10cSrcweir if ( !m_pBuffer ) 1715cdf0e10cSrcweir return sal_False; 1716cdf0e10cSrcweir sal_Int32 nByteOffset = 1; 1717cdf0e10cSrcweir 1718cdf0e10cSrcweir // Felder aktualisieren: 1719cdf0e10cSrcweir Reference<XPropertySet> xCol; 1720cdf0e10cSrcweir Reference<XPropertySet> xIndex; 1721cdf0e10cSrcweir sal_uInt16 i; 1722cdf0e10cSrcweir ::rtl::OUString aColName; 1723cdf0e10cSrcweir const sal_Int32 nColumnCount = m_pColumns->getCount(); 1724cdf0e10cSrcweir ::std::vector< Reference<XPropertySet> > aIndexedCols(nColumnCount); 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir ::comphelper::UStringMixEqual aCase(isCaseSensitive()); 1727cdf0e10cSrcweir 1728cdf0e10cSrcweir Reference<XIndexAccess> xColumns = m_pColumns; 1729cdf0e10cSrcweir // first search a key that exist already in the table 1730cdf0e10cSrcweir for (i = 0; i < nColumnCount; ++i) 1731cdf0e10cSrcweir { 1732cdf0e10cSrcweir sal_Int32 nPos = i; 1733cdf0e10cSrcweir if(_xCols != xColumns) 1734cdf0e10cSrcweir { 1735cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1736cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); 1737cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 1738cdf0e10cSrcweir 1739cdf0e10cSrcweir for(nPos = 0;nPos<_xCols->getCount();++nPos) 1740cdf0e10cSrcweir { 1741cdf0e10cSrcweir Reference<XPropertySet> xFindCol; 1742cdf0e10cSrcweir ::cppu::extractInterface(xFindCol,_xCols->getByIndex(nPos)); 1743cdf0e10cSrcweir OSL_ENSURE(xFindCol.is(),"ODbaseTable::UpdateBuffer column is null!"); 1744cdf0e10cSrcweir if(aCase(getString(xFindCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),aColName)) 1745cdf0e10cSrcweir break; 1746cdf0e10cSrcweir } 1747cdf0e10cSrcweir if (nPos >= _xCols->getCount()) 1748cdf0e10cSrcweir continue; 1749cdf0e10cSrcweir } 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir ++nPos; 1752cdf0e10cSrcweir xIndex = isUniqueByColumnName(i); 1753cdf0e10cSrcweir aIndexedCols[i] = xIndex; 1754cdf0e10cSrcweir if (xIndex.is()) 1755cdf0e10cSrcweir { 1756cdf0e10cSrcweir // first check if the value is different to the old one and when if it conform to the index 1757cdf0e10cSrcweir if(pOrgRow.isValid() && (rRow.get()[nPos]->getValue().isNull() || rRow.get()[nPos] == (pOrgRow->get())[nPos])) 1758cdf0e10cSrcweir continue; 1759cdf0e10cSrcweir else 1760cdf0e10cSrcweir { 1761cdf0e10cSrcweir // ODbVariantRef xVar = (pVal == NULL) ? new ODbVariant() : pVal; 1762cdf0e10cSrcweir Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); 1763cdf0e10cSrcweir OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); 1764cdf0e10cSrcweir ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) ); 1765cdf0e10cSrcweir OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); 1766cdf0e10cSrcweir 1767cdf0e10cSrcweir if (pIndex->Find(0,*rRow.get()[nPos])) 1768cdf0e10cSrcweir { 1769cdf0e10cSrcweir // es existiert kein eindeutiger Wert 1770cdf0e10cSrcweir if ( !aColName.getLength() ) 1771cdf0e10cSrcweir { 1772cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1773cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); 1774cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 1775cdf0e10cSrcweir xCol.clear(); 1776cdf0e10cSrcweir } // if ( !aColName.getLength() ) 1777cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 1778cdf0e10cSrcweir STR_DUPLICATE_VALUE_IN_COLUMN 1779cdf0e10cSrcweir ,"$columnname$", aColName 1780cdf0e10cSrcweir ) ); 1781cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 1782cdf0e10cSrcweir } 1783cdf0e10cSrcweir } 1784cdf0e10cSrcweir } 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir // when we are here there is no double key in the table 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir for (i = 0; i < nColumnCount && nByteOffset <= m_nBufferSize ; ++i) 1790cdf0e10cSrcweir { 1791cdf0e10cSrcweir // Laengen je nach Datentyp: 1792cdf0e10cSrcweir OSL_ENSURE(i < m_aPrecisions.size(),"Illegal index!"); 1793cdf0e10cSrcweir sal_Int32 nLen = 0; 1794cdf0e10cSrcweir sal_Int32 nType = 0; 1795cdf0e10cSrcweir sal_Int32 nScale = 0; 1796cdf0e10cSrcweir if ( i < m_aPrecisions.size() ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir nLen = m_aPrecisions[i]; 1799cdf0e10cSrcweir nType = m_aTypes[i]; 1800cdf0e10cSrcweir nScale = m_aScales[i]; 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir else 1803cdf0e10cSrcweir { 1804cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1805cdf0e10cSrcweir if ( xCol.is() ) 1806cdf0e10cSrcweir { 1807cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen; 1808cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType; 1809cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; 1810cdf0e10cSrcweir } 1811cdf0e10cSrcweir } 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir bool bSetZero = false; 1814cdf0e10cSrcweir switch (nType) 1815cdf0e10cSrcweir { 1816cdf0e10cSrcweir case DataType::INTEGER: 1817cdf0e10cSrcweir case DataType::DOUBLE: 1818cdf0e10cSrcweir case DataType::TIMESTAMP: 1819cdf0e10cSrcweir bSetZero = true; 1820cdf0e10cSrcweir case DataType::LONGVARBINARY: 1821cdf0e10cSrcweir case DataType::DATE: 1822cdf0e10cSrcweir case DataType::BIT: 1823cdf0e10cSrcweir case DataType::LONGVARCHAR: 1824cdf0e10cSrcweir nLen = m_aRealFieldLengths[i]; 1825cdf0e10cSrcweir break; 1826cdf0e10cSrcweir case DataType::DECIMAL: 1827cdf0e10cSrcweir nLen = SvDbaseConverter::ConvertPrecisionToDbase(nLen,nScale); 1828cdf0e10cSrcweir break; // das Vorzeichen und das Komma 1829cdf0e10cSrcweir default: 1830cdf0e10cSrcweir break; 1831cdf0e10cSrcweir 1832cdf0e10cSrcweir } // switch (nType) 1833cdf0e10cSrcweir 1834cdf0e10cSrcweir sal_Int32 nPos = i; 1835cdf0e10cSrcweir if(_xCols != xColumns) 1836cdf0e10cSrcweir { 1837cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1838cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); 1839cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 1840cdf0e10cSrcweir for(nPos = 0;nPos<_xCols->getCount();++nPos) 1841cdf0e10cSrcweir { 1842cdf0e10cSrcweir Reference<XPropertySet> xFindCol; 1843cdf0e10cSrcweir ::cppu::extractInterface(xFindCol,_xCols->getByIndex(nPos)); 1844cdf0e10cSrcweir if(aCase(getString(xFindCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),aColName)) 1845cdf0e10cSrcweir break; 1846cdf0e10cSrcweir } 1847cdf0e10cSrcweir if (nPos >= _xCols->getCount()) 1848cdf0e10cSrcweir { 1849cdf0e10cSrcweir nByteOffset += nLen; 1850cdf0e10cSrcweir continue; 1851cdf0e10cSrcweir } 1852cdf0e10cSrcweir } 1853cdf0e10cSrcweir 1854cdf0e10cSrcweir 1855cdf0e10cSrcweir 1856cdf0e10cSrcweir ++nPos; // the row values start at 1 1857cdf0e10cSrcweir // Ist die Variable ueberhaupt gebunden? 1858cdf0e10cSrcweir if ( !rRow.get()[nPos]->isBound() ) 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir // Nein - naechstes Feld. 1861cdf0e10cSrcweir nByteOffset += nLen; 1862cdf0e10cSrcweir continue; 1863cdf0e10cSrcweir } 1864cdf0e10cSrcweir if (aIndexedCols[i].is()) 1865cdf0e10cSrcweir { 1866cdf0e10cSrcweir Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY); 1867cdf0e10cSrcweir OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); 1868cdf0e10cSrcweir ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelImplementationId()) ); 1869cdf0e10cSrcweir OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); 1870cdf0e10cSrcweir // Update !! 1871cdf0e10cSrcweir if (pOrgRow.isValid() && !rRow.get()[nPos]->getValue().isNull() )//&& pVal->isModified()) 1872cdf0e10cSrcweir pIndex->Update(m_nFilePos,*(pOrgRow->get())[nPos],*rRow.get()[nPos]); 1873cdf0e10cSrcweir else 1874cdf0e10cSrcweir pIndex->Insert(m_nFilePos,*rRow.get()[nPos]); 1875cdf0e10cSrcweir } 1876cdf0e10cSrcweir 1877cdf0e10cSrcweir char* pData = (char *)(m_pBuffer + nByteOffset); 1878cdf0e10cSrcweir if (rRow.get()[nPos]->getValue().isNull()) 1879cdf0e10cSrcweir { 1880cdf0e10cSrcweir if ( bSetZero ) 1881cdf0e10cSrcweir memset(pData,0,nLen); // Zuruecksetzen auf NULL 1882cdf0e10cSrcweir else 1883cdf0e10cSrcweir memset(pData,' ',nLen); // Zuruecksetzen auf NULL 1884cdf0e10cSrcweir nByteOffset += nLen; 1885cdf0e10cSrcweir OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!"); 1886cdf0e10cSrcweir continue; 1887cdf0e10cSrcweir } 1888cdf0e10cSrcweir 1889cdf0e10cSrcweir sal_Bool bHadError = sal_False; 1890cdf0e10cSrcweir try 1891cdf0e10cSrcweir { 1892cdf0e10cSrcweir switch (nType) 1893cdf0e10cSrcweir { 1894cdf0e10cSrcweir case DataType::TIMESTAMP: 1895cdf0e10cSrcweir { 1896*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for timestamp field"); 1897*efddaef0SArrigo Marchiori if (nLen != 8) { 1898*efddaef0SArrigo Marchiori bHadError = true; 1899*efddaef0SArrigo Marchiori break; 1900*efddaef0SArrigo Marchiori } 1901cdf0e10cSrcweir sal_Int32 nJulianDate = 0, nJulianTime = 0; 1902cdf0e10cSrcweir lcl_CalcJulDate(nJulianDate,nJulianTime,rRow.get()[nPos]->getValue()); 1903cdf0e10cSrcweir // Genau 8 Byte kopieren: 1904cdf0e10cSrcweir memcpy(pData,&nJulianDate,4); 1905cdf0e10cSrcweir memcpy(pData+4,&nJulianTime,4); 1906cdf0e10cSrcweir } 1907cdf0e10cSrcweir break; 1908cdf0e10cSrcweir case DataType::DATE: 1909cdf0e10cSrcweir { 1910*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for date field"); 1911*efddaef0SArrigo Marchiori if (nLen != 8) { 1912*efddaef0SArrigo Marchiori bHadError = true; 1913*efddaef0SArrigo Marchiori break; 1914*efddaef0SArrigo Marchiori } 1915cdf0e10cSrcweir ::com::sun::star::util::Date aDate; 1916cdf0e10cSrcweir if(rRow.get()[nPos]->getValue().getTypeKind() == DataType::DOUBLE) 1917cdf0e10cSrcweir aDate = ::dbtools::DBTypeConversion::toDate(rRow.get()[nPos]->getValue().getDouble()); 1918cdf0e10cSrcweir else 1919cdf0e10cSrcweir aDate = rRow.get()[nPos]->getValue(); 1920cdf0e10cSrcweir char s[9]; 1921cdf0e10cSrcweir snprintf(s, 1922cdf0e10cSrcweir sizeof(s), 1923cdf0e10cSrcweir "%04d%02d%02d", 1924cdf0e10cSrcweir (int)aDate.Year, 1925cdf0e10cSrcweir (int)aDate.Month, 1926cdf0e10cSrcweir (int)aDate.Day); 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir // Genau 8 Byte kopieren: 1929cdf0e10cSrcweir strncpy(pData,s,sizeof s - 1); 1930cdf0e10cSrcweir } break; 1931cdf0e10cSrcweir case DataType::INTEGER: 1932cdf0e10cSrcweir { 1933*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 4, "Invalid length for integer field"); 1934*efddaef0SArrigo Marchiori if (nLen != 4) { 1935*efddaef0SArrigo Marchiori bHadError = true; 1936*efddaef0SArrigo Marchiori break; 1937*efddaef0SArrigo Marchiori } 1938cdf0e10cSrcweir sal_Int32 nValue = rRow.get()[nPos]->getValue(); 1939cdf0e10cSrcweir memcpy(pData,&nValue,nLen); 1940cdf0e10cSrcweir } 1941cdf0e10cSrcweir break; 1942cdf0e10cSrcweir case DataType::DOUBLE: 1943cdf0e10cSrcweir { 1944*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 8, "Invalid length for double field"); 1945*efddaef0SArrigo Marchiori if (nLen != 8) { 1946*efddaef0SArrigo Marchiori bHadError = true; 1947*efddaef0SArrigo Marchiori break; 1948*efddaef0SArrigo Marchiori } 1949cdf0e10cSrcweir const double d = rRow.get()[nPos]->getValue(); 1950cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1951cdf0e10cSrcweir 1952cdf0e10cSrcweir if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt 1953cdf0e10cSrcweir { 1954cdf0e10cSrcweir sal_Int64 nValue = 0; 1955cdf0e10cSrcweir if ( m_aScales[i] ) 1956cdf0e10cSrcweir nValue = (sal_Int64)(d * pow(10.0,(int)m_aScales[i])); 1957cdf0e10cSrcweir else 1958cdf0e10cSrcweir nValue = (sal_Int64)(d); 1959cdf0e10cSrcweir memcpy(pData,&nValue,nLen); 1960cdf0e10cSrcweir } // if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt 1961cdf0e10cSrcweir else 1962cdf0e10cSrcweir memcpy(pData,&d,nLen); 1963cdf0e10cSrcweir } 1964cdf0e10cSrcweir break; 1965cdf0e10cSrcweir case DataType::DECIMAL: 1966cdf0e10cSrcweir { 1967cdf0e10cSrcweir memset(pData,' ',nLen); // Zuruecksetzen auf NULL 1968cdf0e10cSrcweir 1969cdf0e10cSrcweir const double n = rRow.get()[nPos]->getValue(); 1970cdf0e10cSrcweir 1971cdf0e10cSrcweir // ein const_cast, da GetFormatPrecision am SvNumberFormat nicht const ist, obwohl es das eigentlich 1972cdf0e10cSrcweir // sein koennte und muesste 1973cdf0e10cSrcweir 1974cdf0e10cSrcweir const ByteString aDefaultValue( ::rtl::math::doubleToString( n, rtl_math_StringFormat_F, nScale, '.', NULL, 0)); 1975cdf0e10cSrcweir sal_Bool bValidLength = aDefaultValue.Len() <= nLen; 1976cdf0e10cSrcweir if ( bValidLength ) 1977cdf0e10cSrcweir { 1978cdf0e10cSrcweir strncpy(pData,aDefaultValue.GetBuffer(),nLen); 1979cdf0e10cSrcweir // write the resulting double back 1980cdf0e10cSrcweir *rRow.get()[nPos] = toDouble(aDefaultValue); 1981cdf0e10cSrcweir } 1982cdf0e10cSrcweir else 1983cdf0e10cSrcweir { 1984cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 1985cdf0e10cSrcweir OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); 1986cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 1987cdf0e10cSrcweir ::std::list< ::std::pair<const sal_Char* , ::rtl::OUString > > aStringToSubstitutes; 1988cdf0e10cSrcweir aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$columnname$", aColName)); 1989cdf0e10cSrcweir aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$precision$", String::CreateFromInt32(nLen))); 1990cdf0e10cSrcweir aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$scale$", String::CreateFromInt32(nScale))); 1991cdf0e10cSrcweir aStringToSubstitutes.push_back(::std::pair<const sal_Char* , ::rtl::OUString >("$value$", ::rtl::OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8))); 1992cdf0e10cSrcweir 1993cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 1994cdf0e10cSrcweir STR_INVALID_COLUMN_DECIMAL_VALUE 1995cdf0e10cSrcweir ,aStringToSubstitutes 1996cdf0e10cSrcweir ) ); 1997cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 1998cdf0e10cSrcweir } 1999cdf0e10cSrcweir } break; 2000cdf0e10cSrcweir case DataType::BIT: 2001*efddaef0SArrigo Marchiori OSL_ENSURE(nLen == 1, "Invalid length for bit field"); 2002*efddaef0SArrigo Marchiori if (nLen != 1) { 2003*efddaef0SArrigo Marchiori bHadError = true; 2004*efddaef0SArrigo Marchiori break; 2005*efddaef0SArrigo Marchiori } 2006cdf0e10cSrcweir *pData = rRow.get()[nPos]->getValue().getBool() ? 'T' : 'F'; 2007cdf0e10cSrcweir break; 2008cdf0e10cSrcweir case DataType::LONGVARBINARY: 2009cdf0e10cSrcweir case DataType::LONGVARCHAR: 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir char cNext = pData[nLen]; // merken und temporaer durch 0 ersetzen 2012cdf0e10cSrcweir pData[nLen] = '\0'; // das geht, da der Puffer immer ein Zeichen groesser ist ... 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir sal_uIntPtr nBlockNo = strtol((const char *)pData,NULL,10); // Blocknummer lesen 2015cdf0e10cSrcweir 2016cdf0e10cSrcweir // Naechstes Anfangszeichen wieder restaurieren: 2017cdf0e10cSrcweir pData[nLen] = cNext; 2018cdf0e10cSrcweir if (!m_pMemoStream || !WriteMemo(rRow.get()[nPos]->get(), nBlockNo)) 2019cdf0e10cSrcweir break; 2020cdf0e10cSrcweir 2021cdf0e10cSrcweir ByteString aStr; 2022cdf0e10cSrcweir ByteString aBlock(ByteString::CreateFromInt32(nBlockNo)); 2023cdf0e10cSrcweir aStr.Expand(static_cast<sal_uInt16>(nLen - aBlock.Len()), '0' ); 2024cdf0e10cSrcweir aStr += aBlock; 2025cdf0e10cSrcweir // Zeichen kopieren: 2026cdf0e10cSrcweir memset(pData,' ',nLen); // Zuruecksetzen auf NULL 2027cdf0e10cSrcweir memcpy(pData, aStr.GetBuffer(), nLen); 2028cdf0e10cSrcweir } break; 2029cdf0e10cSrcweir default: 2030cdf0e10cSrcweir { 2031cdf0e10cSrcweir memset(pData,' ',nLen); // Zuruecksetzen auf NULL 2032cdf0e10cSrcweir 2033cdf0e10cSrcweir ::rtl::OUString sStringToWrite( rRow.get()[nPos]->getValue().getString() ); 2034cdf0e10cSrcweir 2035cdf0e10cSrcweir // convert the string, using the connection's encoding 2036cdf0e10cSrcweir ::rtl::OString sEncoded; 2037cdf0e10cSrcweir 2038cdf0e10cSrcweir DBTypeConversion::convertUnicodeStringToLength( sStringToWrite, sEncoded, nLen, m_eEncoding ); 2039cdf0e10cSrcweir memcpy( pData, sEncoded.getStr(), sEncoded.getLength() ); 2040cdf0e10cSrcweir 2041cdf0e10cSrcweir } 2042cdf0e10cSrcweir break; 2043cdf0e10cSrcweir } 2044cdf0e10cSrcweir } 2045cdf0e10cSrcweir catch( SQLException& ) 2046cdf0e10cSrcweir { 2047cdf0e10cSrcweir throw; 2048cdf0e10cSrcweir } 2049cdf0e10cSrcweir catch ( Exception& ) { bHadError = sal_True; } 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir if ( bHadError ) 2052cdf0e10cSrcweir { 2053cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xCol; 2054cdf0e10cSrcweir OSL_ENSURE( xCol.is(), "ODbaseTable::UpdateBuffer column is null!" ); 2055cdf0e10cSrcweir if ( xCol.is() ) 2056cdf0e10cSrcweir xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; 2057cdf0e10cSrcweir 2058cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 2059cdf0e10cSrcweir STR_INVALID_COLUMN_VALUE, 2060cdf0e10cSrcweir "$columnname$", aColName 2061cdf0e10cSrcweir ) ); 2062cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 2063cdf0e10cSrcweir } 2064cdf0e10cSrcweir // Und weiter ... 2065cdf0e10cSrcweir nByteOffset += nLen; 2066cdf0e10cSrcweir OSL_ENSURE( nByteOffset <= m_nBufferSize ,"ByteOffset > m_nBufferSize!"); 2067cdf0e10cSrcweir } 2068cdf0e10cSrcweir return sal_True; 2069cdf0e10cSrcweir } 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2072cdf0e10cSrcweir sal_Bool ODbaseTable::WriteMemo(ORowSetValue& aVariable, sal_uIntPtr& rBlockNr) 2073cdf0e10cSrcweir { 2074cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::WriteMemo" ); 2075cdf0e10cSrcweir // wird die BlockNr 0 vorgegeben, wird der block ans Ende gehaengt 2076cdf0e10cSrcweir sal_uIntPtr nSize = 0; 2077cdf0e10cSrcweir ::rtl::OString aStr; 2078cdf0e10cSrcweir ::com::sun::star::uno::Sequence<sal_Int8> aValue; 2079cdf0e10cSrcweir sal_uInt8 nHeader[4]; 2080cdf0e10cSrcweir const bool bBinary = aVariable.getTypeKind() == DataType::LONGVARBINARY && m_aMemoHeader.db_typ == MemoFoxPro; 2081cdf0e10cSrcweir if ( bBinary ) 2082cdf0e10cSrcweir { 2083cdf0e10cSrcweir aValue = aVariable.getSequence(); 2084cdf0e10cSrcweir nSize = aValue.getLength(); 2085cdf0e10cSrcweir } 2086cdf0e10cSrcweir else 2087cdf0e10cSrcweir { 2088cdf0e10cSrcweir nSize = DBTypeConversion::convertUnicodeString( aVariable.getString(), aStr, m_eEncoding ); 2089cdf0e10cSrcweir } 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir // Anhaengen oder ueberschreiben 2092cdf0e10cSrcweir sal_Bool bAppend = rBlockNr == 0; 2093cdf0e10cSrcweir 2094cdf0e10cSrcweir if (!bAppend) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir switch (m_aMemoHeader.db_typ) 2097cdf0e10cSrcweir { 2098cdf0e10cSrcweir case MemodBaseIII: // dBase III-Memofeld, endet mit 2 * Ctrl-Z 2099cdf0e10cSrcweir bAppend = nSize > (512 - 2); 2100cdf0e10cSrcweir break; 2101cdf0e10cSrcweir case MemoFoxPro: 2102cdf0e10cSrcweir case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe 2103cdf0e10cSrcweir { 2104cdf0e10cSrcweir char sHeader[4]; 2105cdf0e10cSrcweir m_pMemoStream->Seek(rBlockNr * m_aMemoHeader.db_size); 2106cdf0e10cSrcweir m_pMemoStream->SeekRel(4L); 2107cdf0e10cSrcweir m_pMemoStream->Read(sHeader,4); 2108cdf0e10cSrcweir 2109cdf0e10cSrcweir sal_uIntPtr nOldSize; 2110cdf0e10cSrcweir if (m_aMemoHeader.db_typ == MemoFoxPro) 2111cdf0e10cSrcweir nOldSize = ((((unsigned char)sHeader[0]) * 256 + 2112cdf0e10cSrcweir (unsigned char)sHeader[1]) * 256 + 2113cdf0e10cSrcweir (unsigned char)sHeader[2]) * 256 + 2114cdf0e10cSrcweir (unsigned char)sHeader[3]; 2115cdf0e10cSrcweir else 2116cdf0e10cSrcweir nOldSize = ((((unsigned char)sHeader[3]) * 256 + 2117cdf0e10cSrcweir (unsigned char)sHeader[2]) * 256 + 2118cdf0e10cSrcweir (unsigned char)sHeader[1]) * 256 + 2119cdf0e10cSrcweir (unsigned char)sHeader[0] - 8; 2120cdf0e10cSrcweir 2121cdf0e10cSrcweir // passt die neue Laenge in die belegten Bloecke 2122cdf0e10cSrcweir sal_uIntPtr nUsedBlocks = ((nSize + 8) / m_aMemoHeader.db_size) + (((nSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0), 2123cdf0e10cSrcweir nOldUsedBlocks = ((nOldSize + 8) / m_aMemoHeader.db_size) + (((nOldSize + 8) % m_aMemoHeader.db_size > 0) ? 1 : 0); 2124cdf0e10cSrcweir bAppend = nUsedBlocks > nOldUsedBlocks; 2125cdf0e10cSrcweir } 2126cdf0e10cSrcweir } 2127cdf0e10cSrcweir } 2128cdf0e10cSrcweir 2129cdf0e10cSrcweir if (bAppend) 2130cdf0e10cSrcweir { 2131cdf0e10cSrcweir sal_uIntPtr nStreamSize = m_pMemoStream->Seek(STREAM_SEEK_TO_END); 2132cdf0e10cSrcweir // letzten block auffuellen 2133cdf0e10cSrcweir rBlockNr = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0); 2134cdf0e10cSrcweir 2135cdf0e10cSrcweir m_pMemoStream->SetStreamSize(rBlockNr * m_aMemoHeader.db_size); 2136cdf0e10cSrcweir m_pMemoStream->Seek(STREAM_SEEK_TO_END); 2137cdf0e10cSrcweir } 2138cdf0e10cSrcweir else 2139cdf0e10cSrcweir { 2140cdf0e10cSrcweir m_pMemoStream->Seek(rBlockNr * m_aMemoHeader.db_size); 2141cdf0e10cSrcweir } 2142cdf0e10cSrcweir 2143cdf0e10cSrcweir switch (m_aMemoHeader.db_typ) 2144cdf0e10cSrcweir { 2145cdf0e10cSrcweir case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z 2146cdf0e10cSrcweir { 2147cdf0e10cSrcweir const char cEOF = (char) DBF_EOL; 2148cdf0e10cSrcweir nSize++; 2149cdf0e10cSrcweir m_pMemoStream->Write( aStr.getStr(), aStr.getLength() ); 2150cdf0e10cSrcweir (*m_pMemoStream) << cEOF << cEOF; 2151cdf0e10cSrcweir } break; 2152cdf0e10cSrcweir case MemoFoxPro: 2153cdf0e10cSrcweir case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe 2154cdf0e10cSrcweir { 2155cdf0e10cSrcweir if ( MemodBaseIV == m_aMemoHeader.db_typ ) 2156cdf0e10cSrcweir (*m_pMemoStream) << (sal_uInt8)0xFF 2157cdf0e10cSrcweir << (sal_uInt8)0xFF 2158cdf0e10cSrcweir << (sal_uInt8)0x08; 2159cdf0e10cSrcweir else 2160cdf0e10cSrcweir (*m_pMemoStream) << (sal_uInt8)0x00 2161cdf0e10cSrcweir << (sal_uInt8)0x00 2162cdf0e10cSrcweir << (sal_uInt8)0x00; 2163cdf0e10cSrcweir 2164cdf0e10cSrcweir sal_uInt32 nWriteSize = nSize; 2165cdf0e10cSrcweir if (m_aMemoHeader.db_typ == MemoFoxPro) 2166cdf0e10cSrcweir { 2167cdf0e10cSrcweir if ( bBinary ) 2168cdf0e10cSrcweir (*m_pMemoStream) << (sal_uInt8) 0x00; // Picture 2169cdf0e10cSrcweir else 2170cdf0e10cSrcweir (*m_pMemoStream) << (sal_uInt8) 0x01; // Memo 2171cdf0e10cSrcweir for (int i = 4; i > 0; nWriteSize >>= 8) 2172cdf0e10cSrcweir nHeader[--i] = (sal_uInt8) (nWriteSize % 256); 2173cdf0e10cSrcweir } 2174cdf0e10cSrcweir else 2175cdf0e10cSrcweir { 2176cdf0e10cSrcweir (*m_pMemoStream) << (sal_uInt8) 0x00; 2177cdf0e10cSrcweir nWriteSize += 8; 2178cdf0e10cSrcweir for (int i = 0; i < 4; nWriteSize >>= 8) 2179cdf0e10cSrcweir nHeader[i++] = (sal_uInt8) (nWriteSize % 256); 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir m_pMemoStream->Write(nHeader,4); 2183cdf0e10cSrcweir if ( bBinary ) 2184cdf0e10cSrcweir m_pMemoStream->Write( aValue.getConstArray(), aValue.getLength() ); 2185cdf0e10cSrcweir else 2186cdf0e10cSrcweir m_pMemoStream->Write( aStr.getStr(), aStr.getLength() ); 2187cdf0e10cSrcweir m_pMemoStream->Flush(); 2188cdf0e10cSrcweir } 2189cdf0e10cSrcweir } 2190cdf0e10cSrcweir 2191cdf0e10cSrcweir 2192cdf0e10cSrcweir // Schreiben der neuen Blocknummer 2193cdf0e10cSrcweir if (bAppend) 2194cdf0e10cSrcweir { 2195cdf0e10cSrcweir sal_uIntPtr nStreamSize = m_pMemoStream->Seek(STREAM_SEEK_TO_END); 2196cdf0e10cSrcweir m_aMemoHeader.db_next = (nStreamSize / m_aMemoHeader.db_size) + ((nStreamSize % m_aMemoHeader.db_size) > 0 ? 1 : 0); 2197cdf0e10cSrcweir 2198cdf0e10cSrcweir // Schreiben der neuen Blocknummer 2199cdf0e10cSrcweir m_pMemoStream->Seek(0L); 2200cdf0e10cSrcweir (*m_pMemoStream) << m_aMemoHeader.db_next; 2201cdf0e10cSrcweir m_pMemoStream->Flush(); 2202cdf0e10cSrcweir } 2203cdf0e10cSrcweir return sal_True; 2204cdf0e10cSrcweir } 2205cdf0e10cSrcweir 2206cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2207cdf0e10cSrcweir // XAlterTable 2208cdf0e10cSrcweir void SAL_CALL ODbaseTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException) 2209cdf0e10cSrcweir { 2210cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::alterColumnByName" ); 2211cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 2212cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 2213cdf0e10cSrcweir 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir Reference<XDataDescriptorFactory> xOldColumn; 2216cdf0e10cSrcweir m_pColumns->getByName(colName) >>= xOldColumn; 2217cdf0e10cSrcweir 2218cdf0e10cSrcweir alterColumn(m_pColumns->findColumn(colName)-1,descriptor,xOldColumn); 2219cdf0e10cSrcweir } 2220cdf0e10cSrcweir // ------------------------------------------------------------------------- 2221cdf0e10cSrcweir void SAL_CALL ODbaseTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) 2222cdf0e10cSrcweir { 2223cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::alterColumnByIndex" ); 2224cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 2225cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 2226cdf0e10cSrcweir 2227cdf0e10cSrcweir if(index < 0 || index >= m_pColumns->getCount()) 2228cdf0e10cSrcweir throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this); 2229cdf0e10cSrcweir 2230cdf0e10cSrcweir Reference<XDataDescriptorFactory> xOldColumn; 2231cdf0e10cSrcweir m_pColumns->getByIndex(index) >>= xOldColumn; 2232cdf0e10cSrcweir alterColumn(index,descriptor,xOldColumn); 2233cdf0e10cSrcweir } 2234cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2235cdf0e10cSrcweir void ODbaseTable::alterColumn(sal_Int32 index, 2236cdf0e10cSrcweir const Reference< XPropertySet >& descriptor , 2237cdf0e10cSrcweir const Reference< XDataDescriptorFactory >& xOldColumn ) 2238cdf0e10cSrcweir { 2239cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::alterColumn" ); 2240cdf0e10cSrcweir if(index < 0 || index >= m_pColumns->getCount()) 2241cdf0e10cSrcweir throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),*this); 2242cdf0e10cSrcweir 2243cdf0e10cSrcweir ODbaseTable* pNewTable = NULL; 2244cdf0e10cSrcweir try 2245cdf0e10cSrcweir { 2246cdf0e10cSrcweir OSL_ENSURE(descriptor.is(),"ODbaseTable::alterColumn: descriptor can not be null!"); 2247cdf0e10cSrcweir // creates a copy of the the original column and copy all properties from descriptor in xCopyColumn 2248cdf0e10cSrcweir Reference<XPropertySet> xCopyColumn; 2249cdf0e10cSrcweir if(xOldColumn.is()) 2250cdf0e10cSrcweir xCopyColumn = xOldColumn->createDataDescriptor(); 2251cdf0e10cSrcweir else 2252cdf0e10cSrcweir xCopyColumn = new OColumn(getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers()); 2253cdf0e10cSrcweir 2254cdf0e10cSrcweir ::comphelper::copyProperties(descriptor,xCopyColumn); 2255cdf0e10cSrcweir 2256cdf0e10cSrcweir // creates a temp file 2257cdf0e10cSrcweir 2258cdf0e10cSrcweir String sTempName = createTempFile(); 2259cdf0e10cSrcweir 2260cdf0e10cSrcweir pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); 2261cdf0e10cSrcweir Reference<XPropertySet> xHoldTable = pNewTable; 2262cdf0e10cSrcweir pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName))); 2263cdf0e10cSrcweir Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY); 2264cdf0e10cSrcweir OSL_ENSURE(xAppend.is(),"ODbaseTable::alterColumn: No XAppend interface!"); 2265cdf0e10cSrcweir 2266cdf0e10cSrcweir // copy the structure 2267cdf0e10cSrcweir sal_Int32 i=0; 2268cdf0e10cSrcweir for(;i < index;++i) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir Reference<XPropertySet> xProp; 2271cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xProp; 2272cdf0e10cSrcweir Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY); 2273cdf0e10cSrcweir Reference<XPropertySet> xCpy; 2274cdf0e10cSrcweir if(xColumn.is()) 2275cdf0e10cSrcweir xCpy = xColumn->createDataDescriptor(); 2276cdf0e10cSrcweir else 2277cdf0e10cSrcweir xCpy = new OColumn(getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers()); 2278cdf0e10cSrcweir ::comphelper::copyProperties(xProp,xCpy); 2279cdf0e10cSrcweir xAppend->appendByDescriptor(xCpy); 2280cdf0e10cSrcweir } 2281cdf0e10cSrcweir ++i; // now insert our new column 2282cdf0e10cSrcweir xAppend->appendByDescriptor(xCopyColumn); 2283cdf0e10cSrcweir 2284cdf0e10cSrcweir for(;i < m_pColumns->getCount();++i) 2285cdf0e10cSrcweir { 2286cdf0e10cSrcweir Reference<XPropertySet> xProp; 2287cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xProp; 2288cdf0e10cSrcweir Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY); 2289cdf0e10cSrcweir Reference<XPropertySet> xCpy; 2290cdf0e10cSrcweir if(xColumn.is()) 2291cdf0e10cSrcweir xCpy = xColumn->createDataDescriptor(); 2292cdf0e10cSrcweir else 2293cdf0e10cSrcweir xCpy = new OColumn(getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers()); 2294cdf0e10cSrcweir ::comphelper::copyProperties(xProp,xCpy); 2295cdf0e10cSrcweir xAppend->appendByDescriptor(xCpy); 2296cdf0e10cSrcweir } 2297cdf0e10cSrcweir 2298cdf0e10cSrcweir // construct the new table 2299cdf0e10cSrcweir if(!pNewTable->CreateImpl()) 2300cdf0e10cSrcweir { 2301cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 2302cdf0e10cSrcweir STR_COLUMN_NOT_ALTERABLE, 2303cdf0e10cSrcweir "$columnname$", ::comphelper::getString(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))) 2304cdf0e10cSrcweir ) ); 2305cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 2306cdf0e10cSrcweir } 2307cdf0e10cSrcweir 2308cdf0e10cSrcweir pNewTable->construct(); 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir // copy the data 2311cdf0e10cSrcweir copyData(pNewTable,0); 2312cdf0e10cSrcweir 2313cdf0e10cSrcweir // now drop the old one 2314cdf0e10cSrcweir if( DropImpl() ) // we don't want to delete the memo columns too 2315cdf0e10cSrcweir { 2316cdf0e10cSrcweir // rename the new one to the old one 2317cdf0e10cSrcweir pNewTable->renameImpl(m_Name); 2318cdf0e10cSrcweir // release the temp file 2319cdf0e10cSrcweir pNewTable = NULL; 2320cdf0e10cSrcweir ::comphelper::disposeComponent(xHoldTable); 2321cdf0e10cSrcweir } 2322cdf0e10cSrcweir else 2323cdf0e10cSrcweir { 2324cdf0e10cSrcweir pNewTable = NULL; 2325cdf0e10cSrcweir } 2326cdf0e10cSrcweir FileClose(); 2327cdf0e10cSrcweir construct(); 2328cdf0e10cSrcweir if(m_pColumns) 2329cdf0e10cSrcweir m_pColumns->refresh(); 2330cdf0e10cSrcweir 2331cdf0e10cSrcweir } 2332cdf0e10cSrcweir catch(const SQLException&) 2333cdf0e10cSrcweir { 2334cdf0e10cSrcweir throw; 2335cdf0e10cSrcweir } 2336cdf0e10cSrcweir catch(const Exception&) 2337cdf0e10cSrcweir { 2338cdf0e10cSrcweir OSL_ENSURE(0,"ODbaseTable::alterColumn: Exception occured!"); 2339cdf0e10cSrcweir throw; 2340cdf0e10cSrcweir } 2341cdf0e10cSrcweir } 2342cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2343cdf0e10cSrcweir Reference< XDatabaseMetaData> ODbaseTable::getMetaData() const 2344cdf0e10cSrcweir { 2345cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getMetaData" ); 2346cdf0e10cSrcweir return getConnection()->getMetaData(); 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir // ------------------------------------------------------------------------- 2349cdf0e10cSrcweir 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) 2350cdf0e10cSrcweir { 2351cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::rename" ); 2352cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 2353cdf0e10cSrcweir checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); 2354cdf0e10cSrcweir if(m_pTables && m_pTables->hasByName(newName)) 2355cdf0e10cSrcweir throw ElementExistException(newName,*this); 2356cdf0e10cSrcweir 2357cdf0e10cSrcweir 2358cdf0e10cSrcweir renameImpl(newName); 2359cdf0e10cSrcweir 2360cdf0e10cSrcweir ODbaseTable_BASE::rename(newName); 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir construct(); 2363cdf0e10cSrcweir if(m_pColumns) 2364cdf0e10cSrcweir m_pColumns->refresh(); 2365cdf0e10cSrcweir } 2366cdf0e10cSrcweir namespace 2367cdf0e10cSrcweir { 2368cdf0e10cSrcweir void renameFile(OConnection* _pConenction,const ::rtl::OUString& oldName, 2369cdf0e10cSrcweir const ::rtl::OUString& newName,const String& _sExtension) 2370cdf0e10cSrcweir { 2371cdf0e10cSrcweir String aName = ODbaseTable::getEntry(_pConenction,oldName); 2372cdf0e10cSrcweir if(!aName.Len()) 2373cdf0e10cSrcweir { 2374cdf0e10cSrcweir ::rtl::OUString aIdent = _pConenction->getContent()->getIdentifier()->getContentIdentifier(); 2375cdf0e10cSrcweir if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) 2376cdf0e10cSrcweir aIdent += ::rtl::OUString::createFromAscii("/"); 2377cdf0e10cSrcweir aIdent += oldName; 2378cdf0e10cSrcweir aName = aIdent; 2379cdf0e10cSrcweir } 2380cdf0e10cSrcweir INetURLObject aURL; 2381cdf0e10cSrcweir aURL.SetURL(aName); 2382cdf0e10cSrcweir 2383cdf0e10cSrcweir aURL.setExtension( _sExtension ); 2384cdf0e10cSrcweir String sNewName(newName); 2385cdf0e10cSrcweir sNewName.AppendAscii("."); 2386cdf0e10cSrcweir sNewName += _sExtension; 2387cdf0e10cSrcweir 2388cdf0e10cSrcweir try 2389cdf0e10cSrcweir { 2390cdf0e10cSrcweir Content aContent(aURL.GetMainURL(INetURLObject::NO_DECODE),Reference<XCommandEnvironment>()); 2391cdf0e10cSrcweir 2392cdf0e10cSrcweir Sequence< PropertyValue > aProps( 1 ); 2393cdf0e10cSrcweir aProps[0].Name = ::rtl::OUString::createFromAscii("Title"); 2394cdf0e10cSrcweir aProps[0].Handle = -1; // n/a 2395cdf0e10cSrcweir aProps[0].Value = makeAny( ::rtl::OUString(sNewName) ); 2396cdf0e10cSrcweir Sequence< Any > aValues; 2397cdf0e10cSrcweir aContent.executeCommand( rtl::OUString::createFromAscii( "setPropertyValues" ),makeAny(aProps) ) >>= aValues; 2398cdf0e10cSrcweir if(aValues.getLength() && aValues[0].hasValue()) 2399cdf0e10cSrcweir throw Exception(); 2400cdf0e10cSrcweir } 2401cdf0e10cSrcweir catch(Exception&) 2402cdf0e10cSrcweir { 2403cdf0e10cSrcweir throw ElementExistException(newName,NULL); 2404cdf0e10cSrcweir } 2405cdf0e10cSrcweir } 2406cdf0e10cSrcweir } 2407cdf0e10cSrcweir // ------------------------------------------------------------------------- 2408cdf0e10cSrcweir 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) 2409cdf0e10cSrcweir { 2410cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getEntry" ); 2411cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 2412cdf0e10cSrcweir 2413cdf0e10cSrcweir FileClose(); 2414cdf0e10cSrcweir 2415cdf0e10cSrcweir 2416cdf0e10cSrcweir renameFile(m_pConnection,m_Name,newName,m_pConnection->getExtension()); 2417cdf0e10cSrcweir if ( HasMemoFields() ) 2418cdf0e10cSrcweir { // delete the memo fields 2419cdf0e10cSrcweir String sExt = String::CreateFromAscii("dbt"); 2420cdf0e10cSrcweir renameFile(m_pConnection,m_Name,newName,sExt); 2421cdf0e10cSrcweir } 2422cdf0e10cSrcweir } 2423cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2424cdf0e10cSrcweir void ODbaseTable::addColumn(const Reference< XPropertySet >& _xNewColumn) 2425cdf0e10cSrcweir { 2426cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::addColumn" ); 2427cdf0e10cSrcweir String sTempName = createTempFile(); 2428cdf0e10cSrcweir 2429cdf0e10cSrcweir ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); 2430cdf0e10cSrcweir Reference< XPropertySet > xHold = pNewTable; 2431cdf0e10cSrcweir pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName))); 2432cdf0e10cSrcweir { 2433cdf0e10cSrcweir Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY); 2434cdf0e10cSrcweir sal_Bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); 2435cdf0e10cSrcweir // copy the structure 2436cdf0e10cSrcweir for(sal_Int32 i=0;i < m_pColumns->getCount();++i) 2437cdf0e10cSrcweir { 2438cdf0e10cSrcweir Reference<XPropertySet> xProp; 2439cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xProp; 2440cdf0e10cSrcweir Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY); 2441cdf0e10cSrcweir Reference<XPropertySet> xCpy; 2442cdf0e10cSrcweir if(xColumn.is()) 2443cdf0e10cSrcweir xCpy = xColumn->createDataDescriptor(); 2444cdf0e10cSrcweir else 2445cdf0e10cSrcweir { 2446cdf0e10cSrcweir xCpy = new OColumn(bCase); 2447cdf0e10cSrcweir ::comphelper::copyProperties(xProp,xCpy); 2448cdf0e10cSrcweir } 2449cdf0e10cSrcweir 2450cdf0e10cSrcweir xAppend->appendByDescriptor(xCpy); 2451cdf0e10cSrcweir } 2452cdf0e10cSrcweir Reference<XPropertySet> xCpy = new OColumn(bCase); 2453cdf0e10cSrcweir ::comphelper::copyProperties(_xNewColumn,xCpy); 2454cdf0e10cSrcweir xAppend->appendByDescriptor(xCpy); 2455cdf0e10cSrcweir } 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir // construct the new table 2458cdf0e10cSrcweir if(!pNewTable->CreateImpl()) 2459cdf0e10cSrcweir { 2460cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 2461cdf0e10cSrcweir STR_COLUMN_NOT_ADDABLE, 2462cdf0e10cSrcweir "$columnname$", ::comphelper::getString(_xNewColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))) 2463cdf0e10cSrcweir ) ); 2464cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 2465cdf0e10cSrcweir } 2466cdf0e10cSrcweir 2467cdf0e10cSrcweir sal_Bool bAlreadyDroped = sal_False; 2468cdf0e10cSrcweir try 2469cdf0e10cSrcweir { 2470cdf0e10cSrcweir pNewTable->construct(); 2471cdf0e10cSrcweir // copy the data 2472cdf0e10cSrcweir copyData(pNewTable,pNewTable->m_pColumns->getCount()); 2473cdf0e10cSrcweir // drop the old table 2474cdf0e10cSrcweir if(DropImpl()) 2475cdf0e10cSrcweir { 2476cdf0e10cSrcweir bAlreadyDroped = sal_True; 2477cdf0e10cSrcweir pNewTable->renameImpl(m_Name); 2478cdf0e10cSrcweir // release the temp file 2479cdf0e10cSrcweir } 2480cdf0e10cSrcweir xHold = pNewTable = NULL; 2481cdf0e10cSrcweir 2482cdf0e10cSrcweir FileClose(); 2483cdf0e10cSrcweir construct(); 2484cdf0e10cSrcweir if(m_pColumns) 2485cdf0e10cSrcweir m_pColumns->refresh(); 2486cdf0e10cSrcweir } 2487cdf0e10cSrcweir catch(const SQLException&) 2488cdf0e10cSrcweir { 2489cdf0e10cSrcweir // here we know that the old table wasn't droped before 2490cdf0e10cSrcweir if(!bAlreadyDroped) 2491cdf0e10cSrcweir xHold = pNewTable = NULL; 2492cdf0e10cSrcweir 2493cdf0e10cSrcweir throw; 2494cdf0e10cSrcweir } 2495cdf0e10cSrcweir } 2496cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2497cdf0e10cSrcweir void ODbaseTable::dropColumn(sal_Int32 _nPos) 2498cdf0e10cSrcweir { 2499cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::dropColumn" ); 2500cdf0e10cSrcweir String sTempName = createTempFile(); 2501cdf0e10cSrcweir 2502cdf0e10cSrcweir ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); 2503cdf0e10cSrcweir Reference< XPropertySet > xHold = pNewTable; 2504cdf0e10cSrcweir pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(::rtl::OUString(sTempName))); 2505cdf0e10cSrcweir { 2506cdf0e10cSrcweir Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY); 2507cdf0e10cSrcweir sal_Bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); 2508cdf0e10cSrcweir // copy the structure 2509cdf0e10cSrcweir for(sal_Int32 i=0;i < m_pColumns->getCount();++i) 2510cdf0e10cSrcweir { 2511cdf0e10cSrcweir if(_nPos != i) 2512cdf0e10cSrcweir { 2513cdf0e10cSrcweir Reference<XPropertySet> xProp; 2514cdf0e10cSrcweir m_pColumns->getByIndex(i) >>= xProp; 2515cdf0e10cSrcweir Reference<XDataDescriptorFactory> xColumn(xProp,UNO_QUERY); 2516cdf0e10cSrcweir Reference<XPropertySet> xCpy; 2517cdf0e10cSrcweir if(xColumn.is()) 2518cdf0e10cSrcweir xCpy = xColumn->createDataDescriptor(); 2519cdf0e10cSrcweir else 2520cdf0e10cSrcweir { 2521cdf0e10cSrcweir xCpy = new OColumn(bCase); 2522cdf0e10cSrcweir ::comphelper::copyProperties(xProp,xCpy); 2523cdf0e10cSrcweir } 2524cdf0e10cSrcweir xAppend->appendByDescriptor(xCpy); 2525cdf0e10cSrcweir } 2526cdf0e10cSrcweir } 2527cdf0e10cSrcweir } 2528cdf0e10cSrcweir 2529cdf0e10cSrcweir // construct the new table 2530cdf0e10cSrcweir if(!pNewTable->CreateImpl()) 2531cdf0e10cSrcweir { 2532cdf0e10cSrcweir xHold = pNewTable = NULL; 2533cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 2534cdf0e10cSrcweir STR_COLUMN_NOT_DROP, 2535cdf0e10cSrcweir "$position$", ::rtl::OUString::valueOf(_nPos) 2536cdf0e10cSrcweir ) ); 2537cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 2538cdf0e10cSrcweir } 2539cdf0e10cSrcweir pNewTable->construct(); 2540cdf0e10cSrcweir // copy the data 2541cdf0e10cSrcweir copyData(pNewTable,_nPos); 2542cdf0e10cSrcweir // drop the old table 2543cdf0e10cSrcweir if(DropImpl()) 2544cdf0e10cSrcweir pNewTable->renameImpl(m_Name); 2545cdf0e10cSrcweir // release the temp file 2546cdf0e10cSrcweir 2547cdf0e10cSrcweir xHold = pNewTable = NULL; 2548cdf0e10cSrcweir 2549cdf0e10cSrcweir FileClose(); 2550cdf0e10cSrcweir construct(); 2551cdf0e10cSrcweir } 2552cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2553cdf0e10cSrcweir String ODbaseTable::createTempFile() 2554cdf0e10cSrcweir { 2555cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::createTempFile" ); 2556cdf0e10cSrcweir ::rtl::OUString aIdent = m_pConnection->getContent()->getIdentifier()->getContentIdentifier(); 2557cdf0e10cSrcweir if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) 2558cdf0e10cSrcweir aIdent += ::rtl::OUString::createFromAscii("/"); 2559cdf0e10cSrcweir String sTempName(aIdent); 2560cdf0e10cSrcweir String sExt; 2561cdf0e10cSrcweir sExt.AssignAscii("."); 2562cdf0e10cSrcweir sExt += m_pConnection->getExtension(); 2563cdf0e10cSrcweir 2564cdf0e10cSrcweir String sName(m_Name); 2565cdf0e10cSrcweir TempFile aTempFile(sName,&sExt,&sTempName); 2566cdf0e10cSrcweir if(!aTempFile.IsValid()) 2567cdf0e10cSrcweir getConnection()->throwGenericSQLException(STR_COULD_NOT_ALTER_TABLE,*this); 2568cdf0e10cSrcweir 2569cdf0e10cSrcweir INetURLObject aURL; 2570cdf0e10cSrcweir aURL.SetSmartProtocol(INET_PROT_FILE); 2571cdf0e10cSrcweir aURL.SetURL(aTempFile.GetURL()); 2572cdf0e10cSrcweir 2573cdf0e10cSrcweir String sNewName(aURL.getName()); 2574cdf0e10cSrcweir sNewName.Erase(sNewName.Len() - sExt.Len()); 2575cdf0e10cSrcweir return sNewName; 2576cdf0e10cSrcweir } 2577cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2578cdf0e10cSrcweir void ODbaseTable::copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos) 2579cdf0e10cSrcweir { 2580cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::copyData" ); 2581cdf0e10cSrcweir sal_Int32 nPos = _nPos + 1; // +1 because we always have the bookmark clumn as well 2582cdf0e10cSrcweir OValueRefRow aRow = new OValueRefVector(m_pColumns->getCount()); 2583cdf0e10cSrcweir OValueRefRow aInsertRow; 2584cdf0e10cSrcweir if(_nPos) 2585cdf0e10cSrcweir { 2586cdf0e10cSrcweir aInsertRow = new OValueRefVector(_pNewTable->m_pColumns->getCount()); 2587cdf0e10cSrcweir ::std::for_each(aInsertRow->get().begin(),aInsertRow->get().end(),TSetRefBound(sal_True)); 2588cdf0e10cSrcweir } 2589cdf0e10cSrcweir else 2590cdf0e10cSrcweir aInsertRow = aRow; 2591cdf0e10cSrcweir 2592cdf0e10cSrcweir // we only have to bind the values which we need to copy into the new table 2593cdf0e10cSrcweir ::std::for_each(aRow->get().begin(),aRow->get().end(),TSetRefBound(sal_True)); 2594cdf0e10cSrcweir if(_nPos && (_nPos < (sal_Int32)aRow->get().size())) 2595cdf0e10cSrcweir (aRow->get())[nPos]->setBound(sal_False); 2596cdf0e10cSrcweir 2597cdf0e10cSrcweir 2598cdf0e10cSrcweir sal_Bool bOk = sal_True; 2599cdf0e10cSrcweir sal_Int32 nCurPos; 2600cdf0e10cSrcweir OValueRefVector::Vector::iterator aIter; 2601cdf0e10cSrcweir for(sal_uInt32 nRowPos = 0; nRowPos < m_aHeader.db_anz;++nRowPos) 2602cdf0e10cSrcweir { 2603cdf0e10cSrcweir bOk = seekRow( IResultSetHelper::BOOKMARK, nRowPos+1, nCurPos ); 2604cdf0e10cSrcweir if ( bOk ) 2605cdf0e10cSrcweir { 2606cdf0e10cSrcweir bOk = fetchRow( aRow, m_aColumns.getBody(), sal_True, sal_True); 2607cdf0e10cSrcweir if ( bOk && !aRow->isDeleted() ) // copy only not deleted rows 2608cdf0e10cSrcweir { 2609cdf0e10cSrcweir // special handling when pos == 0 then we don't have to distinguish between the two rows 2610cdf0e10cSrcweir if(_nPos) 2611cdf0e10cSrcweir { 2612cdf0e10cSrcweir aIter = aRow->get().begin()+1; 2613cdf0e10cSrcweir sal_Int32 nCount = 1; 2614cdf0e10cSrcweir for(OValueRefVector::Vector::iterator aInsertIter = aInsertRow->get().begin()+1; aIter != aRow->get().end() && aInsertIter != aInsertRow->get().end();++aIter,++nCount) 2615cdf0e10cSrcweir { 2616cdf0e10cSrcweir if(nPos != nCount) 2617cdf0e10cSrcweir { 2618cdf0e10cSrcweir (*aInsertIter)->setValue( (*aIter)->getValue() ); 2619cdf0e10cSrcweir ++aInsertIter; 2620cdf0e10cSrcweir } 2621cdf0e10cSrcweir } 2622cdf0e10cSrcweir } 2623cdf0e10cSrcweir bOk = _pNewTable->InsertRow(*aInsertRow,sal_True,_pNewTable->m_pColumns); 2624cdf0e10cSrcweir OSL_ENSURE(bOk,"Row could not be inserted!"); 2625cdf0e10cSrcweir } 2626cdf0e10cSrcweir else 2627cdf0e10cSrcweir OSL_ENSURE(bOk,"Row could not be fetched!"); 2628cdf0e10cSrcweir } 2629cdf0e10cSrcweir else 2630cdf0e10cSrcweir { 2631cdf0e10cSrcweir OSL_ASSERT(0); 2632cdf0e10cSrcweir } 2633cdf0e10cSrcweir } // for(sal_uInt32 nRowPos = 0; nRowPos < m_aHeader.db_anz;++nRowPos) 2634cdf0e10cSrcweir } 2635cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2636cdf0e10cSrcweir void ODbaseTable::throwInvalidDbaseFormat() 2637cdf0e10cSrcweir { 2638cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::throwInvalidDbaseFormat" ); 2639cdf0e10cSrcweir FileClose(); 2640cdf0e10cSrcweir // no dbase file 2641cdf0e10cSrcweir 2642cdf0e10cSrcweir const ::rtl::OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( 2643cdf0e10cSrcweir STR_INVALID_DBASE_FILE, 2644cdf0e10cSrcweir "$filename$", getEntry(m_pConnection,m_Name) 2645cdf0e10cSrcweir ) ); 2646cdf0e10cSrcweir ::dbtools::throwGenericSQLException( sError, *this ); 2647cdf0e10cSrcweir } 2648cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2649cdf0e10cSrcweir void ODbaseTable::refreshHeader() 2650cdf0e10cSrcweir { 2651cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::refreshHeader" ); 2652cdf0e10cSrcweir if ( m_aHeader.db_anz == 0 ) 2653cdf0e10cSrcweir readHeader(); 2654cdf0e10cSrcweir } 2655cdf0e10cSrcweir //------------------------------------------------------------------ 2656cdf0e10cSrcweir sal_Bool ODbaseTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) 2657cdf0e10cSrcweir { 2658cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::seekRow" ); 2659cdf0e10cSrcweir // ---------------------------------------------------------- 2660cdf0e10cSrcweir // Positionierung vorbereiten: 2661cdf0e10cSrcweir OSL_ENSURE(m_pFileStream,"ODbaseTable::seekRow: FileStream is NULL!"); 2662cdf0e10cSrcweir 2663cdf0e10cSrcweir sal_uInt32 nNumberOfRecords = (sal_uInt32)m_aHeader.db_anz; 2664cdf0e10cSrcweir sal_uInt32 nTempPos = m_nFilePos; 2665cdf0e10cSrcweir m_nFilePos = nCurPos; 2666cdf0e10cSrcweir 2667cdf0e10cSrcweir switch(eCursorPosition) 2668cdf0e10cSrcweir { 2669cdf0e10cSrcweir case IResultSetHelper::NEXT: 2670cdf0e10cSrcweir ++m_nFilePos; 2671cdf0e10cSrcweir break; 2672cdf0e10cSrcweir case IResultSetHelper::PRIOR: 2673cdf0e10cSrcweir if (m_nFilePos > 0) 2674cdf0e10cSrcweir --m_nFilePos; 2675cdf0e10cSrcweir break; 2676cdf0e10cSrcweir case IResultSetHelper::FIRST: 2677cdf0e10cSrcweir m_nFilePos = 1; 2678cdf0e10cSrcweir break; 2679cdf0e10cSrcweir case IResultSetHelper::LAST: 2680cdf0e10cSrcweir m_nFilePos = nNumberOfRecords; 2681cdf0e10cSrcweir break; 2682cdf0e10cSrcweir case IResultSetHelper::RELATIVE: 2683cdf0e10cSrcweir m_nFilePos = (((sal_Int32)m_nFilePos) + nOffset < 0) ? 0L 2684cdf0e10cSrcweir : (sal_uInt32)(((sal_Int32)m_nFilePos) + nOffset); 2685cdf0e10cSrcweir break; 2686cdf0e10cSrcweir case IResultSetHelper::ABSOLUTE: 2687cdf0e10cSrcweir case IResultSetHelper::BOOKMARK: 2688cdf0e10cSrcweir m_nFilePos = (sal_uInt32)nOffset; 2689cdf0e10cSrcweir break; 2690cdf0e10cSrcweir } 2691cdf0e10cSrcweir 2692cdf0e10cSrcweir if (m_nFilePos > (sal_Int32)nNumberOfRecords) 2693cdf0e10cSrcweir m_nFilePos = (sal_Int32)nNumberOfRecords + 1; 2694cdf0e10cSrcweir 2695cdf0e10cSrcweir if (m_nFilePos == 0 || m_nFilePos == (sal_Int32)nNumberOfRecords + 1) 2696cdf0e10cSrcweir goto Error; 2697cdf0e10cSrcweir else 2698cdf0e10cSrcweir { 2699cdf0e10cSrcweir sal_uInt16 nEntryLen = m_aHeader.db_slng; 2700cdf0e10cSrcweir 2701cdf0e10cSrcweir OSL_ENSURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position"); 2702cdf0e10cSrcweir sal_Int32 nPos = m_aHeader.db_kopf + (sal_Int32)(m_nFilePos-1) * nEntryLen; 2703cdf0e10cSrcweir 2704cdf0e10cSrcweir sal_uIntPtr nLen = m_pFileStream->Seek(nPos); 2705cdf0e10cSrcweir if (m_pFileStream->GetError() != ERRCODE_NONE) 2706cdf0e10cSrcweir goto Error; 2707cdf0e10cSrcweir 2708cdf0e10cSrcweir nLen = m_pFileStream->Read((char*)m_pBuffer, nEntryLen); 2709cdf0e10cSrcweir if (m_pFileStream->GetError() != ERRCODE_NONE) 2710cdf0e10cSrcweir goto Error; 2711cdf0e10cSrcweir } 2712cdf0e10cSrcweir goto End; 2713cdf0e10cSrcweir 2714cdf0e10cSrcweir Error: 2715cdf0e10cSrcweir switch(eCursorPosition) 2716cdf0e10cSrcweir { 2717cdf0e10cSrcweir case IResultSetHelper::PRIOR: 2718cdf0e10cSrcweir case IResultSetHelper::FIRST: 2719cdf0e10cSrcweir m_nFilePos = 0; 2720cdf0e10cSrcweir break; 2721cdf0e10cSrcweir case IResultSetHelper::LAST: 2722cdf0e10cSrcweir case IResultSetHelper::NEXT: 2723cdf0e10cSrcweir case IResultSetHelper::ABSOLUTE: 2724cdf0e10cSrcweir case IResultSetHelper::RELATIVE: 2725cdf0e10cSrcweir if (nOffset > 0) 2726cdf0e10cSrcweir m_nFilePos = nNumberOfRecords + 1; 2727cdf0e10cSrcweir else if (nOffset < 0) 2728cdf0e10cSrcweir m_nFilePos = 0; 2729cdf0e10cSrcweir break; 2730cdf0e10cSrcweir case IResultSetHelper::BOOKMARK: 2731cdf0e10cSrcweir m_nFilePos = nTempPos; // vorherige Position 2732cdf0e10cSrcweir } 2733cdf0e10cSrcweir // aStatus.Set(SDB_STAT_NO_DATA_FOUND); 2734cdf0e10cSrcweir return sal_False; 2735cdf0e10cSrcweir 2736cdf0e10cSrcweir End: 2737cdf0e10cSrcweir nCurPos = m_nFilePos; 2738cdf0e10cSrcweir return sal_True; 2739cdf0e10cSrcweir } 2740cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2741cdf0e10cSrcweir sal_Bool ODbaseTable::ReadMemo(sal_uIntPtr nBlockNo, ORowSetValue& aVariable) 2742cdf0e10cSrcweir { 2743cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::ReadMemo" ); 2744cdf0e10cSrcweir sal_Bool bIsText = sal_True; 2745cdf0e10cSrcweir // SdbConnection* pConnection = GetConnection(); 2746cdf0e10cSrcweir 2747cdf0e10cSrcweir m_pMemoStream->Seek(nBlockNo * m_aMemoHeader.db_size); 2748cdf0e10cSrcweir switch (m_aMemoHeader.db_typ) 2749cdf0e10cSrcweir { 2750cdf0e10cSrcweir case MemodBaseIII: // dBase III-Memofeld, endet mit Ctrl-Z 2751cdf0e10cSrcweir { 2752cdf0e10cSrcweir const char cEOF = (char) DBF_EOL; 2753cdf0e10cSrcweir ByteString aBStr; 2754cdf0e10cSrcweir static char aBuf[514]; 2755cdf0e10cSrcweir aBuf[512] = 0; // sonst kann der Zufall uebel mitspielen 2756cdf0e10cSrcweir sal_Bool bReady = sal_False; 2757cdf0e10cSrcweir 2758cdf0e10cSrcweir do 2759cdf0e10cSrcweir { 2760cdf0e10cSrcweir m_pMemoStream->Read(&aBuf,512); 2761cdf0e10cSrcweir 2762cdf0e10cSrcweir sal_uInt16 i = 0; 2763cdf0e10cSrcweir while (aBuf[i] != cEOF && ++i < 512) 2764cdf0e10cSrcweir ; 2765cdf0e10cSrcweir bReady = aBuf[i] == cEOF; 2766cdf0e10cSrcweir 2767cdf0e10cSrcweir aBuf[i] = 0; 2768cdf0e10cSrcweir aBStr += aBuf; 2769cdf0e10cSrcweir 2770cdf0e10cSrcweir } while (!bReady && !m_pMemoStream->IsEof() && aBStr.Len() < STRING_MAXLEN); 2771cdf0e10cSrcweir 2772cdf0e10cSrcweir ::rtl::OUString aStr(aBStr.GetBuffer(), aBStr.Len(),m_eEncoding); 2773cdf0e10cSrcweir aVariable = aStr; 2774cdf0e10cSrcweir 2775cdf0e10cSrcweir } break; 2776cdf0e10cSrcweir case MemoFoxPro: 2777cdf0e10cSrcweir case MemodBaseIV: // dBase IV-Memofeld mit Laengenangabe 2778cdf0e10cSrcweir { 2779cdf0e10cSrcweir char sHeader[4]; 2780cdf0e10cSrcweir m_pMemoStream->Read(sHeader,4); 2781cdf0e10cSrcweir // Foxpro stores text and binary data 2782cdf0e10cSrcweir if (m_aMemoHeader.db_typ == MemoFoxPro) 2783cdf0e10cSrcweir { 2784cdf0e10cSrcweir // if (((sal_uInt8)sHeader[0]) != 0 || ((sal_uInt8)sHeader[1]) != 0 || ((sal_uInt8)sHeader[2]) != 0) 2785cdf0e10cSrcweir // { 2786cdf0e10cSrcweir //// String aText = String(SdbResId(STR_STAT_IResultSetHelper::INVALID)); 2787cdf0e10cSrcweir //// aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_pMemoStream->GetFileName()); 2788cdf0e10cSrcweir //// aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO)); 2789cdf0e10cSrcweir //// aStatus.Set(SDB_STAT_ERROR, 2790cdf0e10cSrcweir //// String::CreateFromAscii("01000"), 2791cdf0e10cSrcweir //// aStatus.CreateErrorMessage(aText), 2792cdf0e10cSrcweir //// 0, String() ); 2793cdf0e10cSrcweir // return sal_False; 2794cdf0e10cSrcweir // } 2795cdf0e10cSrcweir // 2796cdf0e10cSrcweir bIsText = sHeader[3] != 0; 2797cdf0e10cSrcweir } 2798cdf0e10cSrcweir else if (((sal_uInt8)sHeader[0]) != 0xFF || ((sal_uInt8)sHeader[1]) != 0xFF || ((sal_uInt8)sHeader[2]) != 0x08) 2799cdf0e10cSrcweir { 2800cdf0e10cSrcweir // String aText = String(SdbResId(STR_STAT_IResultSetHelper::INVALID)); 2801cdf0e10cSrcweir // aText.SearchAndReplace(String::CreateFromAscii("%%d"),m_pMemoStream->GetFileName()); 2802cdf0e10cSrcweir // aText.SearchAndReplace(String::CreateFromAscii("%%t"),aStatus.TypeToString(MEMO)); 2803cdf0e10cSrcweir // aStatus.Set(SDB_STAT_ERROR, 2804cdf0e10cSrcweir // String::CreateFromAscii("01000"), 2805cdf0e10cSrcweir // aStatus.CreateErrorMessage(aText), 2806cdf0e10cSrcweir // 0, String() ); 2807cdf0e10cSrcweir return sal_False; 2808cdf0e10cSrcweir } 2809cdf0e10cSrcweir 2810cdf0e10cSrcweir sal_uInt32 nLength(0); 2811cdf0e10cSrcweir (*m_pMemoStream) >> nLength; 2812cdf0e10cSrcweir 2813cdf0e10cSrcweir if (m_aMemoHeader.db_typ == MemodBaseIV) 2814cdf0e10cSrcweir nLength -= 8; 2815cdf0e10cSrcweir 2816cdf0e10cSrcweir if ( nLength ) 2817cdf0e10cSrcweir { 2818cdf0e10cSrcweir if ( bIsText ) 2819cdf0e10cSrcweir { 2820cdf0e10cSrcweir // char cChar; 2821cdf0e10cSrcweir ::rtl::OUStringBuffer aStr; 2822cdf0e10cSrcweir while ( nLength > STRING_MAXLEN ) 2823cdf0e10cSrcweir { 2824cdf0e10cSrcweir ByteString aBStr; 2825cdf0e10cSrcweir aBStr.Expand(STRING_MAXLEN); 2826cdf0e10cSrcweir m_pMemoStream->Read(aBStr.AllocBuffer(STRING_MAXLEN),STRING_MAXLEN); 2827cdf0e10cSrcweir aStr.append(::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding)); 2828cdf0e10cSrcweir nLength -= STRING_MAXLEN; 2829cdf0e10cSrcweir } 2830cdf0e10cSrcweir if ( nLength > 0 ) 2831cdf0e10cSrcweir { 2832cdf0e10cSrcweir ByteString aBStr; 2833cdf0e10cSrcweir aBStr.Expand(static_cast<xub_StrLen>(nLength)); 2834cdf0e10cSrcweir m_pMemoStream->Read(aBStr.AllocBuffer(static_cast<xub_StrLen>(nLength)),nLength); 2835cdf0e10cSrcweir // aBStr.ReleaseBufferAccess(); 2836cdf0e10cSrcweir aStr.append(::rtl::OUString(aBStr.GetBuffer(),aBStr.Len(), m_eEncoding)); 2837cdf0e10cSrcweir } 2838cdf0e10cSrcweir if ( aStr.getLength() ) 2839cdf0e10cSrcweir aVariable = aStr.makeStringAndClear(); 2840cdf0e10cSrcweir } // if ( bIsText ) 2841cdf0e10cSrcweir else 2842cdf0e10cSrcweir { 2843cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > aData(nLength); 2844cdf0e10cSrcweir m_pMemoStream->Read(aData.getArray(),nLength); 2845cdf0e10cSrcweir aVariable = aData; 2846cdf0e10cSrcweir } 2847cdf0e10cSrcweir } // if ( nLength ) 2848cdf0e10cSrcweir } 2849cdf0e10cSrcweir } 2850cdf0e10cSrcweir return sal_True; 2851cdf0e10cSrcweir } 2852cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2853cdf0e10cSrcweir void ODbaseTable::AllocBuffer() 2854cdf0e10cSrcweir { 2855cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::AllocBuffer" ); 2856cdf0e10cSrcweir sal_uInt16 nSize = m_aHeader.db_slng; 2857cdf0e10cSrcweir OSL_ENSURE(nSize > 0, "Size too small"); 2858cdf0e10cSrcweir 2859cdf0e10cSrcweir if (m_nBufferSize != nSize) 2860cdf0e10cSrcweir { 2861cdf0e10cSrcweir delete m_pBuffer; 2862cdf0e10cSrcweir m_pBuffer = NULL; 2863cdf0e10cSrcweir } 2864cdf0e10cSrcweir 2865cdf0e10cSrcweir // Falls noch kein Puffer vorhanden: allozieren: 2866cdf0e10cSrcweir if (m_pBuffer == NULL && nSize > 0) 2867cdf0e10cSrcweir { 2868cdf0e10cSrcweir m_nBufferSize = nSize; 2869cdf0e10cSrcweir m_pBuffer = new sal_uInt8[m_nBufferSize+1]; 2870cdf0e10cSrcweir } 2871cdf0e10cSrcweir } 2872cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2873cdf0e10cSrcweir sal_Bool ODbaseTable::WriteBuffer() 2874cdf0e10cSrcweir { 2875cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::WriteBuffer" ); 2876cdf0e10cSrcweir OSL_ENSURE(m_nFilePos >= 1,"SdbDBFCursor::FileFetchRow: ungueltige Record-Position"); 2877cdf0e10cSrcweir 2878cdf0e10cSrcweir // Auf gewuenschten Record positionieren: 2879cdf0e10cSrcweir long nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; 2880cdf0e10cSrcweir m_pFileStream->Seek(nPos); 2881cdf0e10cSrcweir return m_pFileStream->Write((char*) m_pBuffer, m_aHeader.db_slng) > 0; 2882cdf0e10cSrcweir } 2883cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2884cdf0e10cSrcweir sal_Int32 ODbaseTable::getCurrentLastPos() const 2885cdf0e10cSrcweir { 2886cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbase", "Ocke.Janssen@sun.com", "ODbaseTable::getCurrentLastPos" ); 2887cdf0e10cSrcweir return m_aHeader.db_anz; 2888cdf0e10cSrcweir } 2889