1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 33 // INCLUDE --------------------------------------------------------------- 34 35 #include <stdio.h> 36 #include <tools/urlobj.hxx> 37 #include <svl/converter.hxx> 38 #include <svl/zforlist.hxx> 39 #include <comphelper/types.hxx> 40 #include <ucbhelper/content.hxx> 41 #include <unotools/sharedunocomponent.hxx> 42 #include <comphelper/processfactory.hxx> 43 #include <svx/txenctab.hxx> 44 #include <svx/dbcharsethelper.hxx> 45 46 #include <com/sun/star/sdb/CommandType.hpp> 47 #include <com/sun/star/sdbc/DataType.hpp> 48 #include <com/sun/star/sdbc/XConnection.hpp> 49 #include <com/sun/star/sdbc/XDriver.hpp> 50 #include <com/sun/star/sdbc/XDriverAccess.hpp> 51 #include <com/sun/star/sdbc/XDriverManager.hpp> 52 #include <com/sun/star/sdbc/XResultSetUpdate.hpp> 53 #include <com/sun/star/sdbc/XRow.hpp> 54 #include <com/sun/star/sdbc/XRowSet.hpp> 55 #include <com/sun/star/sdbc/XRowUpdate.hpp> 56 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> 57 #include <com/sun/star/sdbcx/XAppend.hpp> 58 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 59 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> 60 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp> 61 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 62 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 63 #include <com/sun/star/beans/XPropertySet.hpp> 64 #include <com/sun/star/container/XEnumerationAccess.hpp> 65 #include <com/sun/star/lang/XComponent.hpp> 66 #include <com/sun/star/ucb/NameClash.hpp> 67 #include <com/sun/star/ucb/TransferInfo.hpp> 68 #include <com/sun/star/ucb/XCommandInfo.hpp> 69 70 #include "scerrors.hxx" 71 #include "docsh.hxx" 72 #include "filter.hxx" 73 #include "progress.hxx" 74 #include "collect.hxx" 75 #include "cell.hxx" 76 #include "editutil.hxx" 77 #include "cellform.hxx" 78 #include "dbdocutl.hxx" 79 #include "dociter.hxx" 80 #include "globstr.hrc" 81 82 using namespace com::sun::star; 83 84 // ----------------------------------------------------------------------- 85 86 #define SC_SERVICE_ROWSET "com.sun.star.sdb.RowSet" 87 #define SC_SERVICE_DRVMAN "com.sun.star.sdbc.DriverManager" 88 89 //! move to a header file? 90 //#define SC_DBPROP_DATASOURCENAME "DataSourceName" 91 #define SC_DBPROP_ACTIVECONNECTION "ActiveConnection" 92 #define SC_DBPROP_COMMAND "Command" 93 #define SC_DBPROP_COMMANDTYPE "CommandType" 94 95 #define SC_DBPROP_NAME "Name" 96 #define SC_DBPROP_TYPE "Type" 97 #define SC_DBPROP_PRECISION "Precision" 98 #define SC_DBPROP_SCALE "Scale" 99 100 #define SC_DBPROP_EXTENSION "Extension" 101 #define SC_DBPROP_CHARSET "CharSet" 102 103 #define SC_ROWCOUNT_ERROR (-1) 104 105 namespace 106 { 107 sal_uLong lcl_getDBaseConnection(uno::Reference<sdbc::XDriverManager>& _rDrvMgr,uno::Reference<sdbc::XConnection>& _rConnection,String& _rTabName,const String& rFullFileName,rtl_TextEncoding eCharSet) 108 { 109 INetURLObject aURL; 110 aURL.SetSmartProtocol( INET_PROT_FILE ); 111 aURL.SetSmartURL( rFullFileName ); 112 _rTabName = aURL.getBase( INetURLObject::LAST_SEGMENT, true, 113 INetURLObject::DECODE_UNAMBIGUOUS ); 114 String aExtension = aURL.getExtension(); 115 aURL.removeSegment(); 116 aURL.removeFinalSlash(); 117 String aPath = aURL.GetMainURL(INetURLObject::NO_DECODE); 118 uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); 119 if (!xFactory.is()) return SCERR_EXPORT_CONNECT; 120 121 _rDrvMgr.set( xFactory->createInstance( 122 rtl::OUString::createFromAscii( SC_SERVICE_DRVMAN ) ), 123 uno::UNO_QUERY); 124 DBG_ASSERT( _rDrvMgr.is(), "can't get DriverManager" ); 125 if (!_rDrvMgr.is()) return SCERR_EXPORT_CONNECT; 126 127 // get connection 128 129 String aConnUrl = String::CreateFromAscii("sdbc:dbase:"); 130 aConnUrl += aPath; 131 132 svxform::ODataAccessCharsetHelper aHelper; 133 ::std::vector< rtl_TextEncoding > aEncodings; 134 aHelper.getSupportedTextEncodings( aEncodings ); 135 ::std::vector< rtl_TextEncoding >::iterator aIter = ::std::find(aEncodings.begin(),aEncodings.end(),(rtl_TextEncoding) eCharSet); 136 if ( aIter == aEncodings.end() ) 137 { 138 DBG_ERRORFILE( "DBaseImport: dbtools::OCharsetMap doesn't know text encoding" ); 139 return SCERR_IMPORT_CONNECT; 140 } // if ( aIter == aMap.end() ) 141 rtl::OUString aCharSetStr; 142 if ( RTL_TEXTENCODING_DONTKNOW != *aIter ) 143 { // it's not the virtual "system charset" 144 const char* pIanaName = rtl_getMimeCharsetFromTextEncoding( *aIter ); 145 OSL_ENSURE( pIanaName, "invalid mime name!" ); 146 if ( pIanaName ) 147 aCharSetStr = ::rtl::OUString::createFromAscii( pIanaName ); 148 } 149 150 uno::Sequence<beans::PropertyValue> aProps(2); 151 aProps[0].Name = rtl::OUString::createFromAscii(SC_DBPROP_EXTENSION); 152 aProps[0].Value <<= rtl::OUString( aExtension ); 153 aProps[1].Name = rtl::OUString::createFromAscii(SC_DBPROP_CHARSET); 154 aProps[1].Value <<= aCharSetStr; 155 156 _rConnection = _rDrvMgr->getConnectionWithInfo( aConnUrl, aProps ); 157 return 0L; 158 } 159 } 160 // ----------------------------------------------------------------------- 161 // MoveFile/KillFile/IsDocument: similar to SfxContentHelper 162 163 // static 164 sal_Bool ScDocShell::MoveFile( const INetURLObject& rSourceObj, const INetURLObject& rDestObj ) 165 { 166 sal_Bool bMoveData = sal_True; 167 sal_Bool bRet = sal_True, bKillSource = sal_False; 168 if ( rSourceObj.GetProtocol() != rDestObj.GetProtocol() ) 169 { 170 bMoveData = sal_False; 171 bKillSource = sal_True; 172 } 173 String aName = rDestObj.getName(); 174 INetURLObject aDestPathObj = rDestObj; 175 aDestPathObj.removeSegment(); 176 aDestPathObj.setFinalSlash(); 177 178 try 179 { 180 ::ucbhelper::Content aDestPath( aDestPathObj.GetMainURL(INetURLObject::NO_DECODE), 181 uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 182 uno::Reference< ::com::sun::star::ucb::XCommandInfo > xInfo = aDestPath.getCommands(); 183 rtl::OUString aTransferName = rtl::OUString::createFromAscii( "transfer" ); 184 if ( xInfo->hasCommandByName( aTransferName ) ) 185 { 186 aDestPath.executeCommand( aTransferName, uno::makeAny( 187 ::com::sun::star::ucb::TransferInfo( bMoveData, rSourceObj.GetMainURL(INetURLObject::NO_DECODE), aName, 188 ::com::sun::star::ucb::NameClash::ERROR ) ) ); 189 } 190 else 191 { 192 DBG_ERRORFILE( "transfer command not available" ); 193 } 194 } 195 catch( uno::Exception& ) 196 { 197 // ucb may throw different exceptions on failure now 198 bRet = sal_False; 199 } 200 201 if ( bKillSource ) 202 KillFile( rSourceObj ); 203 204 return bRet; 205 } 206 207 208 // static 209 sal_Bool ScDocShell::KillFile( const INetURLObject& rURL ) 210 { 211 sal_Bool bRet = sal_True; 212 try 213 { 214 ::ucbhelper::Content aCnt( rURL.GetMainURL(INetURLObject::NO_DECODE), 215 uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 216 aCnt.executeCommand( rtl::OUString::createFromAscii( "delete" ), 217 comphelper::makeBoolAny( sal_True ) ); 218 } 219 catch( uno::Exception& ) 220 { 221 // ucb may throw different exceptions on failure now 222 bRet = sal_False; 223 } 224 225 return bRet; 226 } 227 228 // static 229 sal_Bool ScDocShell::IsDocument( const INetURLObject& rURL ) 230 { 231 sal_Bool bRet = sal_False; 232 try 233 { 234 ::ucbhelper::Content aCnt( rURL.GetMainURL(INetURLObject::NO_DECODE), 235 uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 236 bRet = aCnt.isDocument(); 237 } 238 catch( uno::Exception& ) 239 { 240 // ucb may throw different exceptions on failure now - warning only 241 DBG_WARNING( "Any other exception" ); 242 } 243 244 return bRet; 245 } 246 247 // ----------------------------------------------------------------------- 248 249 sal_uLong ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet, 250 sal_Bool bSimpleColWidth[MAXCOLCOUNT] ) 251 { 252 sal_uLong nErr = eERR_OK; 253 long i; 254 long nColCount = 0; 255 256 try 257 { 258 String aTabName; 259 uno::Reference<sdbc::XDriverManager> xDrvMan; 260 uno::Reference<sdbc::XConnection> xConnection; 261 sal_uLong nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet); 262 if ( !xConnection.is() || !xDrvMan.is() ) 263 return nRet; 264 ::utl::DisposableComponent aConnectionHelper(xConnection); 265 266 ScProgress aProgress( this, ScGlobal::GetRscString( STR_LOAD_DOC ), 0 ); 267 uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); 268 uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance( 269 rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), 270 uno::UNO_QUERY); 271 ::utl::DisposableComponent aRowSetHelper(xRowSet); 272 uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY ); 273 DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); 274 if (!xRowProp.is()) return SCERR_IMPORT_CONNECT; 275 276 sal_Int32 nType = sdb::CommandType::TABLE; 277 uno::Any aAny; 278 279 aAny <<= xConnection; 280 xRowProp->setPropertyValue( 281 rtl::OUString::createFromAscii(SC_DBPROP_ACTIVECONNECTION), aAny ); 282 283 aAny <<= nType; 284 xRowProp->setPropertyValue( 285 rtl::OUString::createFromAscii(SC_DBPROP_COMMANDTYPE), aAny ); 286 287 aAny <<= rtl::OUString( aTabName ); 288 xRowProp->setPropertyValue( 289 rtl::OUString::createFromAscii(SC_DBPROP_COMMAND), aAny ); 290 291 xRowSet->execute(); 292 293 uno::Reference<sdbc::XResultSetMetaData> xMeta; 294 uno::Reference<sdbc::XResultSetMetaDataSupplier> xMetaSupp( xRowSet, uno::UNO_QUERY ); 295 if ( xMetaSupp.is() ) 296 xMeta = xMetaSupp->getMetaData(); 297 if ( xMeta.is() ) 298 nColCount = xMeta->getColumnCount(); // this is the number of real columns 299 300 if ( nColCount > MAXCOL+1 ) 301 { 302 nColCount = MAXCOL+1; 303 nErr = SCWARN_IMPORT_RANGE_OVERFLOW; // warning 304 } 305 306 uno::Reference<sdbc::XRow> xRow( xRowSet, uno::UNO_QUERY ); 307 DBG_ASSERT( xRow.is(), "can't get Row" ); 308 if (!xRow.is()) return SCERR_IMPORT_CONNECT; 309 310 // currency flag is not needed for dBase 311 uno::Sequence<sal_Int32> aColTypes( nColCount ); // column types 312 sal_Int32* pTypeArr = aColTypes.getArray(); 313 for (i=0; i<nColCount; i++) 314 pTypeArr[i] = xMeta->getColumnType( i+1 ); 315 316 // read column names 317 //! add type descriptions 318 319 aProgress.SetState( 0 ); 320 ScColumn::bDoubleAlloc = sal_True; // row count isn't readily available in advance 321 322 for (i=0; i<nColCount; i++) 323 { 324 String aHeader = xMeta->getColumnLabel( i+1 ); 325 326 switch ( pTypeArr[i] ) 327 { 328 case sdbc::DataType::BIT: 329 aHeader.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",L" )); 330 break; 331 case sdbc::DataType::DATE: 332 aHeader.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",D" )); 333 break; 334 case sdbc::DataType::LONGVARCHAR: 335 aHeader.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",M" )); 336 break; 337 case sdbc::DataType::VARCHAR: 338 aHeader.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",C," )); 339 aHeader += String::CreateFromInt32( xMeta->getColumnDisplaySize( i+1 ) ); 340 break; 341 case sdbc::DataType::DECIMAL: 342 { 343 long nPrec = xMeta->getPrecision( i+1 ); 344 long nScale = xMeta->getScale( i+1 ); 345 aHeader.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",N," )); 346 aHeader += String::CreateFromInt32( 347 SvDbaseConverter::ConvertPrecisionToDbase( 348 nPrec, nScale ) ); 349 aHeader += ','; 350 aHeader += String::CreateFromInt32( nScale ); 351 } 352 break; 353 } 354 355 aDocument.SetString( static_cast<SCCOL>(i), 0, 0, aHeader ); 356 } 357 358 SCROW nRow = 1; // 0 is column titles 359 sal_Bool bEnd = sal_False; 360 while ( !bEnd && xRowSet->next() ) 361 { 362 if ( nRow <= MAXROW ) 363 { 364 SCCOL nCol = 0; 365 for (i=0; i<nColCount; i++) 366 { 367 ScDatabaseDocUtil::PutData( &aDocument, nCol, nRow, 0, 368 xRow, i+1, pTypeArr[i], sal_False, 369 &bSimpleColWidth[nCol] ); 370 ++nCol; 371 } 372 ++nRow; 373 } 374 else // past the end of the spreadsheet 375 { 376 bEnd = sal_True; // don't continue 377 nErr = SCWARN_IMPORT_RANGE_OVERFLOW; // warning message 378 } 379 } 380 } 381 catch ( sdbc::SQLException& ) 382 { 383 nErr = SCERR_IMPORT_CONNECT; 384 } 385 catch ( uno::Exception& ) 386 { 387 DBG_ERROR("Unexpected exception in database"); 388 nErr = ERRCODE_IO_GENERAL; 389 } 390 391 ScColumn::bDoubleAlloc = sal_False; 392 if ( nColCount > 0 ) 393 aDocument.DoColResize( 0, 0, static_cast<SCCOL>(nColCount) - 1, 0 ); 394 395 return nErr; 396 } 397 398 // ----------------------------------------------------------------------- 399 400 inline sal_Bool IsAsciiDigit( sal_Unicode c ) 401 { 402 return 0x30 <= c && c <= 0x39; 403 } 404 405 inline sal_Bool IsAsciiAlpha( sal_Unicode c ) 406 { 407 return (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a); 408 } 409 410 void lcl_GetColumnTypes( ScDocShell& rDocShell, 411 const ScRange& rDataRange, sal_Bool bHasFieldNames, 412 rtl::OUString* pColNames, sal_Int32* pColTypes, 413 sal_Int32* pColLengths, sal_Int32* pColScales, 414 sal_Bool& bHasMemo, CharSet eCharSet ) 415 { 416 // updating of column titles didn't work in 5.2 and isn't always wanted 417 // (saving normally shouldn't modify the document) 418 //! read flag from configuration 419 sal_Bool bUpdateTitles = sal_False; 420 421 ScDocument* pDoc = rDocShell.GetDocument(); 422 SvNumberFormatter* pNumFmt = pDoc->GetFormatTable(); 423 424 SCTAB nTab = rDataRange.aStart.Tab(); 425 SCCOL nFirstCol = rDataRange.aStart.Col(); 426 SCROW nFirstRow = rDataRange.aStart.Row(); 427 SCCOL nLastCol = rDataRange.aEnd.Col(); 428 SCROW nLastRow = rDataRange.aEnd.Row(); 429 430 ScStrCollection aFieldNamesCollection; 431 432 long nField = 0; 433 SCROW nFirstDataRow = ( bHasFieldNames ? nFirstRow + 1 : nFirstRow ); 434 for ( SCCOL nCol = nFirstCol; nCol <= nLastCol; nCol++ ) 435 { 436 sal_Bool bTypeDefined = sal_False; 437 sal_Bool bPrecDefined = sal_False; 438 sal_Int32 nFieldLen = 0; 439 sal_Int32 nPrecision = 0; 440 sal_Int32 nDbType = sdbc::DataType::SQLNULL; 441 String aFieldName, aString; 442 443 // Feldname[,Type[,Width[,Prec]]] 444 // Typ etc.: L; D; C[,W]; N[,W[,P]] 445 if ( bHasFieldNames ) 446 { 447 pDoc->GetString( nCol, nFirstRow, nTab, aString ); 448 aString.ToUpperAscii(); 449 xub_StrLen nToken = aString.GetTokenCount( ',' ); 450 if ( nToken > 1 ) 451 { 452 aFieldName = aString.GetToken( 0, ',' ); 453 aString.EraseAllChars( ' ' ); 454 switch ( aString.GetToken( 1, ',' ).GetChar(0) ) 455 { 456 case 'L' : 457 nDbType = sdbc::DataType::BIT; 458 nFieldLen = 1; 459 bTypeDefined = sal_True; 460 bPrecDefined = sal_True; 461 break; 462 case 'D' : 463 nDbType = sdbc::DataType::DATE; 464 nFieldLen = 8; 465 bTypeDefined = sal_True; 466 bPrecDefined = sal_True; 467 break; 468 case 'M' : 469 nDbType = sdbc::DataType::LONGVARCHAR; 470 nFieldLen = 10; 471 bTypeDefined = sal_True; 472 bPrecDefined = sal_True; 473 bHasMemo = sal_True; 474 break; 475 case 'C' : 476 nDbType = sdbc::DataType::VARCHAR; 477 bTypeDefined = sal_True; 478 bPrecDefined = sal_True; 479 break; 480 case 'N' : 481 nDbType = sdbc::DataType::DECIMAL; 482 bTypeDefined = sal_True; 483 break; 484 } 485 if ( bTypeDefined && !nFieldLen && nToken > 2 ) 486 { 487 nFieldLen = aString.GetToken( 2, ',' ).ToInt32(); 488 if ( !bPrecDefined && nToken > 3 ) 489 { 490 String aTmp( aString.GetToken( 3, ',' ) ); 491 if ( CharClass::isAsciiNumeric(aTmp) ) 492 { 493 nPrecision = aTmp.ToInt32(); 494 bPrecDefined = sal_True; 495 } 496 } 497 } 498 } 499 else 500 aFieldName = aString; 501 502 // Feldnamen pruefen und ggbf. gueltigen Feldnamen erzeugen. 503 // Erstes Zeichen muss Buchstabe sein, 504 // weitere nur alphanumerisch und Unterstrich erlaubt, 505 // "_DBASELOCK" ist reserviert (obsolet weil erstes Zeichen kein Buchstabe), 506 // keine doppelten Namen. 507 if ( !IsAsciiAlpha( aFieldName.GetChar(0) ) ) 508 aFieldName.Insert( 'N', 0 ); 509 String aTmpStr; 510 sal_Unicode c; 511 for ( const sal_Unicode* p = aFieldName.GetBuffer(); ( c = *p ) != 0; p++ ) 512 { 513 if ( IsAsciiAlpha( c ) || IsAsciiDigit( c ) || c == '_' ) 514 aTmpStr += c; 515 else 516 aTmpStr += '_'; 517 } 518 aFieldName = aTmpStr; 519 if ( aFieldName.Len() > 10 ) 520 aFieldName.Erase( 10 ); 521 StrData* pStrData = new StrData( aFieldName ); 522 if ( !aFieldNamesCollection.Insert( pStrData ) ) 523 { // doppelter Feldname, numerisch erweitern 524 sal_uInt16 nSub = 1; 525 String aFixPart( aFieldName ); 526 do 527 { 528 ++nSub; 529 String aVarPart = String::CreateFromInt32( nSub ); 530 if ( aFixPart.Len() + aVarPart.Len() > 10 ) 531 aFixPart.Erase( 10 - aVarPart.Len() ); 532 aFieldName = aFixPart; 533 aFieldName += aVarPart; 534 pStrData->SetString( aFieldName ); 535 } while ( !aFieldNamesCollection.Insert( pStrData ) ); 536 } 537 } 538 else 539 { 540 aFieldName = 'N'; 541 aFieldName += String::CreateFromInt32(nCol+1); 542 } 543 544 if ( !bTypeDefined ) 545 { // Feldtyp 546 ScBaseCell* pCell; 547 pDoc->GetCell( nCol, nFirstDataRow, nTab, pCell ); 548 if ( !pCell || pCell->HasStringData() ) 549 nDbType = sdbc::DataType::VARCHAR; 550 else 551 { 552 sal_uInt32 nFormat; 553 pDoc->GetNumberFormat( nCol, nFirstDataRow, nTab, nFormat ); 554 if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA 555 && ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) ) 556 { 557 nFormat = ScGlobal::GetStandardFormat( 558 ((ScFormulaCell*)pCell)->GetValue(), *pNumFmt, nFormat, 559 ((ScFormulaCell*)pCell)->GetFormatType() ); 560 } 561 switch ( pNumFmt->GetType( nFormat ) ) 562 { 563 case NUMBERFORMAT_LOGICAL : 564 nDbType = sdbc::DataType::BIT; 565 nFieldLen = 1; 566 break; 567 case NUMBERFORMAT_DATE : 568 nDbType = sdbc::DataType::DATE; 569 nFieldLen = 8; 570 break; 571 case NUMBERFORMAT_TIME : 572 case NUMBERFORMAT_DATETIME : 573 nDbType = sdbc::DataType::VARCHAR; 574 break; 575 default: 576 nDbType = sdbc::DataType::DECIMAL; 577 } 578 } 579 } 580 sal_Bool bSdbLenAdjusted = sal_False; 581 sal_Bool bSdbLenBad = sal_False; 582 // Feldlaenge 583 if ( nDbType == sdbc::DataType::VARCHAR && !nFieldLen ) 584 { // maximale Feldbreite bestimmen 585 nFieldLen = pDoc->GetMaxStringLen( nTab, nCol, nFirstDataRow, 586 nLastRow, eCharSet ); 587 if ( nFieldLen == 0 ) 588 nFieldLen = 1; 589 } 590 else if ( nDbType == sdbc::DataType::DECIMAL ) 591 { // maximale Feldbreite und Nachkommastellen bestimmen 592 xub_StrLen nLen; 593 sal_uInt16 nPrec; 594 nLen = pDoc->GetMaxNumberStringLen( nPrec, nTab, nCol, 595 nFirstDataRow, nLastRow ); 596 // dBaseIII Limit Nachkommastellen: 15 597 if ( nPrecision > 15 ) 598 nPrecision = 15; 599 if ( nPrec > 15 ) 600 nPrec = 15; 601 if ( bPrecDefined && nPrecision != nPrec ) 602 { // Laenge auf vorgegebene Nachkommastellen anpassen 603 if ( nPrecision ) 604 nLen = sal::static_int_cast<xub_StrLen>( nLen + ( nPrecision - nPrec ) ); 605 else 606 nLen -= nPrec+1; // auch den . mit raus 607 } 608 if ( nLen > nFieldLen && !bTypeDefined ) 609 nFieldLen = nLen; 610 if ( !bPrecDefined ) 611 nPrecision = nPrec; 612 if ( nFieldLen == 0 ) 613 nFieldLen = 1; 614 else if ( nFieldLen > 19 ) 615 nFieldLen = 19; // dBaseIII Limit Feldlaenge numerisch: 19 616 if ( nPrecision && nFieldLen < nPrecision + 2 ) 617 nFieldLen = nPrecision + 2; // 0. muss mit reinpassen 618 // 538 MUST: Sdb internal representation adds 2 to the field length! 619 // To give the user what he wants we must substract it here. 620 //! CAVEAT! There is no way to define a numeric field with a length 621 //! of 1 and no decimals! 622 if ( nFieldLen == 1 && nPrecision == 0 ) 623 bSdbLenBad = sal_True; 624 nFieldLen = SvDbaseConverter::ConvertPrecisionToOdbc( nFieldLen, nPrecision ); 625 bSdbLenAdjusted = sal_True; 626 } 627 if ( nFieldLen > 254 ) 628 { 629 if ( nDbType == sdbc::DataType::VARCHAR ) 630 { // zu lang fuer normales Textfeld => Memofeld 631 nDbType = sdbc::DataType::LONGVARCHAR; 632 nFieldLen = 10; 633 bHasMemo = sal_True; 634 } 635 else 636 nFieldLen = 254; // dumm gelaufen.. 637 } 638 639 pColNames[nField] = aFieldName; 640 pColTypes[nField] = nDbType; 641 pColLengths[nField] = nFieldLen; 642 pColScales[nField] = nPrecision; 643 644 // undo change to field length, reflect reality 645 if ( bSdbLenAdjusted ) 646 { 647 nFieldLen = SvDbaseConverter::ConvertPrecisionToDbase( nFieldLen, nPrecision ); 648 if ( bSdbLenBad && nFieldLen == 1 ) 649 nFieldLen = 2; // THIS is reality 650 } 651 if ( bUpdateTitles ) 652 { // Angabe anpassen und ausgeben 653 String aOutString = aFieldName; 654 switch ( nDbType ) 655 { 656 case sdbc::DataType::BIT : 657 aOutString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",L" )); 658 break; 659 case sdbc::DataType::DATE : 660 aOutString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",D" )); 661 break; 662 case sdbc::DataType::LONGVARCHAR : 663 aOutString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",M" )); 664 break; 665 case sdbc::DataType::VARCHAR : 666 aOutString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",C," )); 667 aOutString += String::CreateFromInt32( nFieldLen ); 668 break; 669 case sdbc::DataType::DECIMAL : 670 aOutString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ",N," )); 671 aOutString += String::CreateFromInt32( nFieldLen ); 672 aOutString += ','; 673 aOutString += String::CreateFromInt32( nPrecision ); 674 break; 675 } 676 if ( !aOutString.EqualsIgnoreCaseAscii( aString ) ) 677 { 678 pDoc->SetString( nCol, nFirstRow, nTab, aOutString ); 679 rDocShell.PostPaint( nCol, nFirstRow, nTab, nCol, nFirstRow, nTab, PAINT_GRID ); 680 } 681 } 682 ++nField; 683 } 684 } 685 686 687 inline void lcl_getLongVarCharEditString( String& rString, 688 const ScBaseCell* pCell, ScFieldEditEngine& rEditEngine ) 689 { 690 rEditEngine.SetText( *((const ScEditCell*)pCell)->GetData() ); 691 rString = rEditEngine.GetText( LINEEND_CRLF ); 692 } 693 694 inline void lcl_getLongVarCharString( String& rString, ScBaseCell* pCell, 695 ScDocument& rDocument, SCCOL nCol, SCROW nRow, SCTAB nTab, 696 SvNumberFormatter& rNumFmt ) 697 { 698 sal_uInt32 nFormat; 699 Color* pColor; 700 rDocument.GetNumberFormat( nCol, nRow, nTab, nFormat ); 701 ScCellFormat::GetString( pCell, nFormat, rString, &pColor, rNumFmt ); 702 } 703 704 705 sal_uLong ScDocShell::DBaseExport( const String& rFullFileName, CharSet eCharSet, sal_Bool& bHasMemo ) 706 { 707 // remove the file so the dBase driver doesn't find an invalid file 708 INetURLObject aDeleteObj( rFullFileName, INET_PROT_FILE ); 709 KillFile( aDeleteObj ); 710 711 sal_uLong nErr = eERR_OK; 712 uno::Any aAny; 713 714 SCCOL nFirstCol, nLastCol; 715 SCROW nFirstRow, nLastRow; 716 SCTAB nTab = GetSaveTab(); 717 aDocument.GetDataStart( nTab, nFirstCol, nFirstRow ); 718 aDocument.GetCellArea( nTab, nLastCol, nLastRow ); 719 if ( nFirstCol > nLastCol ) 720 nFirstCol = nLastCol; 721 if ( nFirstRow > nLastRow ) 722 nFirstRow = nLastRow; 723 ScProgress aProgress( this, ScGlobal::GetRscString( STR_SAVE_DOC ), 724 nLastRow - nFirstRow ); 725 SvNumberFormatter* pNumFmt = aDocument.GetFormatTable(); 726 727 sal_Bool bHasFieldNames = sal_True; 728 for ( SCCOL nDocCol = nFirstCol; nDocCol <= nLastCol && bHasFieldNames; nDocCol++ ) 729 { // nur Strings in erster Zeile => sind Feldnamen 730 if ( !aDocument.HasStringData( nDocCol, nFirstRow, nTab ) ) 731 bHasFieldNames = sal_False; 732 } 733 734 long nColCount = nLastCol - nFirstCol + 1; 735 uno::Sequence<rtl::OUString> aColNames( nColCount ); 736 uno::Sequence<sal_Int32> aColTypes( nColCount ); 737 uno::Sequence<sal_Int32> aColLengths( nColCount ); 738 uno::Sequence<sal_Int32> aColScales( nColCount ); 739 740 ScRange aDataRange( nFirstCol, nFirstRow, nTab, nLastCol, nLastRow, nTab ); 741 lcl_GetColumnTypes( *this, aDataRange, bHasFieldNames, 742 aColNames.getArray(), aColTypes.getArray(), 743 aColLengths.getArray(), aColScales.getArray(), 744 bHasMemo, eCharSet ); 745 // also needed for exception catch 746 SCROW nDocRow = 0; 747 ScFieldEditEngine aEditEngine( aDocument.GetEditPool() ); 748 String aString; 749 String aTabName; 750 751 try 752 { 753 uno::Reference<sdbc::XDriverManager> xDrvMan; 754 uno::Reference<sdbc::XConnection> xConnection; 755 sal_uLong nRet = lcl_getDBaseConnection(xDrvMan,xConnection,aTabName,rFullFileName,eCharSet); 756 if ( !xConnection.is() || !xDrvMan.is() ) 757 return nRet; 758 ::utl::DisposableComponent aConnectionHelper(xConnection); 759 760 // get dBase driver 761 uno::Reference< sdbc::XDriverAccess> xAccess(xDrvMan,uno::UNO_QUERY); 762 uno::Reference< sdbcx::XDataDefinitionSupplier > xDDSup( xAccess->getDriverByURL( xConnection->getMetaData()->getURL() ), uno::UNO_QUERY ); 763 if ( !xDDSup.is() ) 764 return SCERR_EXPORT_CONNECT; 765 766 // create table 767 uno::Reference<sdbcx::XTablesSupplier> xTablesSupp =xDDSup->getDataDefinitionByConnection( xConnection ); 768 DBG_ASSERT( xTablesSupp.is(), "can't get Data Definition" ); 769 if (!xTablesSupp.is()) return SCERR_EXPORT_CONNECT; 770 771 uno::Reference<container::XNameAccess> xTables = xTablesSupp->getTables(); 772 DBG_ASSERT( xTables.is(), "can't get Tables" ); 773 if (!xTables.is()) return SCERR_EXPORT_CONNECT; 774 775 uno::Reference<sdbcx::XDataDescriptorFactory> xTablesFact( xTables, uno::UNO_QUERY ); 776 DBG_ASSERT( xTablesFact.is(), "can't get tables factory" ); 777 if (!xTablesFact.is()) return SCERR_EXPORT_CONNECT; 778 779 uno::Reference<sdbcx::XAppend> xTablesAppend( xTables, uno::UNO_QUERY ); 780 DBG_ASSERT( xTablesAppend.is(), "can't get tables XAppend" ); 781 if (!xTablesAppend.is()) return SCERR_EXPORT_CONNECT; 782 783 uno::Reference<beans::XPropertySet> xTableDesc = xTablesFact->createDataDescriptor(); 784 DBG_ASSERT( xTableDesc.is(), "can't get table descriptor" ); 785 if (!xTableDesc.is()) return SCERR_EXPORT_CONNECT; 786 787 aAny <<= rtl::OUString( aTabName ); 788 xTableDesc->setPropertyValue( rtl::OUString::createFromAscii(SC_DBPROP_NAME), aAny ); 789 790 // create columns 791 792 uno::Reference<sdbcx::XColumnsSupplier> xColumnsSupp( xTableDesc, uno::UNO_QUERY ); 793 DBG_ASSERT( xColumnsSupp.is(), "can't get columns supplier" ); 794 if (!xColumnsSupp.is()) return SCERR_EXPORT_CONNECT; 795 796 uno::Reference<container::XNameAccess> xColumns = xColumnsSupp->getColumns(); 797 DBG_ASSERT( xColumns.is(), "can't get columns" ); 798 if (!xColumns.is()) return SCERR_EXPORT_CONNECT; 799 800 uno::Reference<sdbcx::XDataDescriptorFactory> xColumnsFact( xColumns, uno::UNO_QUERY ); 801 DBG_ASSERT( xColumnsFact.is(), "can't get columns factory" ); 802 if (!xColumnsFact.is()) return SCERR_EXPORT_CONNECT; 803 804 uno::Reference<sdbcx::XAppend> xColumnsAppend( xColumns, uno::UNO_QUERY ); 805 DBG_ASSERT( xColumnsAppend.is(), "can't get columns XAppend" ); 806 if (!xColumnsAppend.is()) return SCERR_EXPORT_CONNECT; 807 808 const rtl::OUString* pColNames = aColNames.getConstArray(); 809 const sal_Int32* pColTypes = aColTypes.getConstArray(); 810 const sal_Int32* pColLengths = aColLengths.getConstArray(); 811 const sal_Int32* pColScales = aColScales.getConstArray(); 812 long nCol; 813 814 for (nCol=0; nCol<nColCount; nCol++) 815 { 816 uno::Reference<beans::XPropertySet> xColumnDesc = xColumnsFact->createDataDescriptor(); 817 DBG_ASSERT( xColumnDesc.is(), "can't get column descriptor" ); 818 if (!xColumnDesc.is()) return SCERR_EXPORT_CONNECT; 819 820 aAny <<= pColNames[nCol]; 821 xColumnDesc->setPropertyValue( rtl::OUString::createFromAscii(SC_DBPROP_NAME), aAny ); 822 823 aAny <<= pColTypes[nCol]; 824 xColumnDesc->setPropertyValue( rtl::OUString::createFromAscii(SC_DBPROP_TYPE), aAny ); 825 826 aAny <<= pColLengths[nCol]; 827 xColumnDesc->setPropertyValue( rtl::OUString::createFromAscii(SC_DBPROP_PRECISION), aAny ); 828 829 aAny <<= pColScales[nCol]; 830 xColumnDesc->setPropertyValue( rtl::OUString::createFromAscii(SC_DBPROP_SCALE), aAny ); 831 832 xColumnsAppend->appendByDescriptor( xColumnDesc ); 833 } 834 835 xTablesAppend->appendByDescriptor( xTableDesc ); 836 837 // re-open connection 838 // xConnection = xDrvMan->getConnectionWithInfo( aConnUrl, aProps ); 839 // DBG_ASSERT( xConnection.is(), "can't get Connection" ); 840 // if (!xConnection.is()) return SCERR_EXPORT_CONNECT; 841 842 // get row set for writing 843 uno::Reference<lang::XMultiServiceFactory> xFactory = comphelper::getProcessServiceFactory(); 844 uno::Reference<sdbc::XRowSet> xRowSet( xFactory->createInstance( 845 rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), 846 uno::UNO_QUERY); 847 ::utl::DisposableComponent aRowSetHelper(xRowSet); 848 uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY ); 849 DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); 850 if (!xRowProp.is()) return SCERR_EXPORT_CONNECT; 851 852 aAny <<= xConnection; 853 xRowProp->setPropertyValue( 854 rtl::OUString::createFromAscii(SC_DBPROP_ACTIVECONNECTION), aAny ); 855 856 aAny <<= (sal_Int32) sdb::CommandType::TABLE; 857 xRowProp->setPropertyValue( 858 rtl::OUString::createFromAscii(SC_DBPROP_COMMANDTYPE), aAny ); 859 860 aAny <<= rtl::OUString( aTabName ); 861 xRowProp->setPropertyValue( 862 rtl::OUString::createFromAscii(SC_DBPROP_COMMAND), aAny ); 863 864 xRowSet->execute(); 865 866 // write data rows 867 868 uno::Reference<sdbc::XResultSetUpdate> xResultUpdate( xRowSet, uno::UNO_QUERY ); 869 DBG_ASSERT( xResultUpdate.is(), "can't get XResultSetUpdate" ); 870 if (!xResultUpdate.is()) return SCERR_EXPORT_CONNECT; 871 872 uno::Reference<sdbc::XRowUpdate> xRowUpdate( xRowSet, uno::UNO_QUERY ); 873 DBG_ASSERT( xRowUpdate.is(), "can't get XRowUpdate" ); 874 if (!xRowUpdate.is()) return SCERR_EXPORT_CONNECT; 875 876 SCROW nFirstDataRow = ( bHasFieldNames ? nFirstRow + 1 : nFirstRow ); 877 double fVal; 878 879 for ( nDocRow = nFirstDataRow; nDocRow <= nLastRow; nDocRow++ ) 880 { 881 xResultUpdate->moveToInsertRow(); 882 883 for (nCol=0; nCol<nColCount; nCol++) 884 { 885 SCCOL nDocCol = sal::static_int_cast<SCCOL>( nFirstCol + nCol ); 886 887 switch (pColTypes[nCol]) 888 { 889 case sdbc::DataType::LONGVARCHAR: 890 { 891 ScBaseCell* pCell; 892 aDocument.GetCell( nDocCol, nDocRow, nTab, pCell ); 893 if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE ) 894 { 895 if ( pCell->GetCellType() == CELLTYPE_EDIT ) 896 { // #60761# Paragraphs erhalten 897 lcl_getLongVarCharEditString( aString, 898 pCell, aEditEngine); 899 } 900 else 901 { 902 lcl_getLongVarCharString( aString, pCell, 903 aDocument, nDocCol, nDocRow, nTab, 904 *pNumFmt); 905 } 906 xRowUpdate->updateString( nCol+1, aString ); 907 } 908 else 909 xRowUpdate->updateNull( nCol+1 ); 910 } 911 break; 912 913 case sdbc::DataType::VARCHAR: 914 aDocument.GetString( nDocCol, nDocRow, nTab, aString ); 915 xRowUpdate->updateString( nCol+1, aString ); 916 if ( nErr == eERR_OK && pColLengths[nCol] < aString.Len() ) 917 nErr = SCWARN_EXPORT_DATALOST; 918 break; 919 920 case sdbc::DataType::DATE: 921 { 922 aDocument.GetValue( nDocCol, nDocRow, nTab, fVal ); 923 // #39274# zwischen 0 Wert und 0 kein Wert unterscheiden 924 sal_Bool bIsNull = (fVal == 0.0); 925 if ( bIsNull ) 926 bIsNull = !aDocument.HasValueData( nDocCol, nDocRow, nTab ); 927 if ( bIsNull ) 928 { 929 xRowUpdate->updateNull( nCol+1 ); 930 if ( nErr == eERR_OK && 931 aDocument.HasStringData( nDocCol, nDocRow, nTab ) ) 932 nErr = SCWARN_EXPORT_DATALOST; 933 } 934 else 935 { 936 Date aDate = *(pNumFmt->GetNullDate()); // tools date 937 aDate += (long)fVal; //! approxfloor? 938 util::Date aUnoDate( aDate.GetDay(), aDate.GetMonth(), aDate.GetYear() ); 939 xRowUpdate->updateDate( nCol+1, aUnoDate ); 940 } 941 } 942 break; 943 944 case sdbc::DataType::DECIMAL: 945 case sdbc::DataType::BIT: 946 aDocument.GetValue( nDocCol, nDocRow, nTab, fVal ); 947 if ( fVal == 0.0 && nErr == eERR_OK && 948 aDocument.HasStringData( nDocCol, nDocRow, nTab ) ) 949 nErr = SCWARN_EXPORT_DATALOST; 950 if ( pColTypes[nCol] == sdbc::DataType::BIT ) 951 xRowUpdate->updateBoolean( nCol+1, ( fVal != 0.0 ) ); 952 else 953 xRowUpdate->updateDouble( nCol+1, fVal ); 954 break; 955 956 default: 957 DBG_ERROR( "ScDocShell::DBaseExport: unknown FieldType" ); 958 if ( nErr == eERR_OK ) 959 nErr = SCWARN_EXPORT_DATALOST; 960 aDocument.GetValue( nDocCol, nDocRow, nTab, fVal ); 961 xRowUpdate->updateDouble( nCol+1, fVal ); 962 } 963 } 964 965 xResultUpdate->insertRow(); 966 967 //! error handling and recovery of old 968 //! ScDocShell::SbaSdbExport is still missing! 969 970 if ( !aProgress.SetStateOnPercent( nDocRow - nFirstRow ) ) 971 { // UserBreak 972 nErr = SCERR_EXPORT_DATA; 973 break; 974 } 975 } 976 977 comphelper::disposeComponent( xRowSet ); 978 comphelper::disposeComponent( xConnection ); 979 } 980 catch ( sdbc::SQLException& aException ) 981 { 982 sal_Int32 nError = aException.ErrorCode; 983 #if OSL_DEBUG_LEVEL > 1 984 fprintf( stderr, "ScDocShell::DBaseExport: SQLException ErrorCode: %d, SQLState: %s, Message: %s\n", 985 (int)nError, OUStringToOString( aException.SQLState, 986 RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString( 987 aException.Message, RTL_TEXTENCODING_UTF8).getStr()); 988 #endif 989 if (nError == 22018 || nError == 22001) 990 { 991 // SQL error 22018: Character not in target encoding. 992 // SQL error 22001: String length exceeds field width (after encoding). 993 bool bEncErr = (nError == 22018); 994 bool bIsOctetTextEncoding = rtl_isOctetTextEncoding( eCharSet); 995 DBG_ASSERT( !bEncErr || bIsOctetTextEncoding, "ScDocShell::DBaseExport: encoding error and not an octect textencoding"); 996 SCCOL nDocCol = nFirstCol; 997 const sal_Int32* pColTypes = aColTypes.getConstArray(); 998 const sal_Int32* pColLengths = aColLengths.getConstArray(); 999 ScHorizontalCellIterator aIter( &aDocument, nTab, nFirstCol, 1000 nDocRow, nLastCol, nDocRow); 1001 ScBaseCell* pCell = NULL; 1002 bool bTest = true; 1003 while (bTest && ((pCell = aIter.GetNext( nDocCol, nDocRow)) != NULL)) 1004 { 1005 SCCOL nCol = nDocCol - nFirstCol; 1006 switch (pColTypes[nCol]) 1007 { 1008 case sdbc::DataType::LONGVARCHAR: 1009 { 1010 if ( pCell->GetCellType() != CELLTYPE_NOTE ) 1011 { 1012 if ( pCell->GetCellType() == CELLTYPE_EDIT ) 1013 lcl_getLongVarCharEditString( aString, 1014 pCell, aEditEngine); 1015 else 1016 lcl_getLongVarCharString( aString, 1017 pCell, aDocument, nDocCol, 1018 nDocRow, nTab, *pNumFmt); 1019 } 1020 } 1021 break; 1022 1023 case sdbc::DataType::VARCHAR: 1024 aDocument.GetString( nDocCol, nDocRow, nTab, aString); 1025 break; 1026 1027 // NOTE: length of DECIMAL fields doesn't need to be 1028 // checked here, the database driver adjusts the field 1029 // width accordingly. 1030 1031 default: 1032 bTest = false; 1033 } 1034 if (bTest) 1035 { 1036 sal_Int32 nLen; 1037 if (bIsOctetTextEncoding) 1038 { 1039 rtl::OUString aOUString( aString); 1040 rtl::OString aOString; 1041 if (!aOUString.convertToString( &aOString, eCharSet, 1042 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | 1043 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)) 1044 { 1045 bTest = false; 1046 bEncErr = true; 1047 } 1048 nLen = aOString.getLength(); 1049 #if OSL_DEBUG_LEVEL > 1 1050 if (!bTest) 1051 fprintf( stderr, "ScDocShell::DBaseExport encoding error, string with default replacements: ``%s''\n", 1052 OUStringToOString( aOUString, eCharSet).getStr()); 1053 #endif 1054 } 1055 else 1056 nLen = aString.Len() * sizeof(sal_Unicode); 1057 if (!bEncErr && 1058 pColTypes[nCol] != sdbc::DataType::LONGVARCHAR && 1059 pColLengths[nCol] < nLen) 1060 { 1061 bTest = false; 1062 #if OSL_DEBUG_LEVEL > 1 1063 fprintf( stderr, "ScDocShell::DBaseExport: field width: %d, encoded length: %d\n", 1064 (int)pColLengths[nCol], (int)nLen); 1065 #endif 1066 } 1067 } 1068 else 1069 bTest = true; 1070 } 1071 String sPosition( ScAddress( nDocCol, nDocRow, nTab).GetColRowString()); 1072 String sEncoding( SvxTextEncodingTable().GetTextString( eCharSet)); 1073 nErr = *new TwoStringErrorInfo( (bEncErr ? SCERR_EXPORT_ENCODING : 1074 SCERR_EXPORT_FIELDWIDTH), sPosition, sEncoding, 1075 ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR); 1076 } 1077 else if ( aException.Message.getLength() ) 1078 nErr = *new StringErrorInfo( (SCERR_EXPORT_SQLEXCEPTION), aException.Message, ERRCODE_BUTTON_OK | ERRCODE_MSG_ERROR); 1079 else 1080 nErr = SCERR_EXPORT_DATA; 1081 } 1082 catch ( uno::Exception& ) 1083 { 1084 DBG_ERROR("Unexpected exception in database"); 1085 nErr = ERRCODE_IO_GENERAL; 1086 } 1087 1088 return nErr; 1089 } 1090 1091 1092