diff options
author | Eike Rathke <er@openoffice.org> | 2002-08-08 12:05:31 +0000 |
---|---|---|
committer | Eike Rathke <er@openoffice.org> | 2002-08-08 12:05:31 +0000 |
commit | 58e298c928404b0bd99c27cd406bd6e3c9279687 (patch) | |
tree | 2b89def39fb13bbdf4e238e7d1f2e3b1da9bc786 /sc/source/ui | |
parent | 15929a98b98f0de8bc497d0e110b89e2ab48b578 (diff) |
#101692# in DB import use result set if available
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/docshell/dbdocimp.cxx | 101 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh4.cxx | 12 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh5.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/inc/dbdocfun.hxx | 30 | ||||
-rw-r--r-- | sc/source/ui/unoobj/cellsuno.cxx | 9 | ||||
-rw-r--r-- | sc/source/ui/unoobj/datauno.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh2.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/view/dbfunc.cxx | 9 |
9 files changed, 122 insertions, 84 deletions
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index e103eb6488b0..dd8b0e3713b9 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dbdocfun.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: nn $ $Date: 2001-03-08 14:28:19 $ + * last change: $Author: er $ $Date: 2002-08-08 13:02:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,8 @@ #include <vcl/msgbox.hxx> #include <vcl/waitobj.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> + #include "dbdocfun.hxx" #include "sc.hrc" #include "dbcolect.hxx" @@ -1363,9 +1365,10 @@ BOOL ScDBDocFunc::DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewOb // Datenbank-Import... void ScDBDocFunc::UpdateImport( const String& rTarget, const String& rDBName, - const String& rTableName, const String& rStatement, - BOOL bNative, BYTE nType, - const SbaSelectionList* pSelection ) + const String& rTableName, const String& rStatement, BOOL bNative, + BYTE nType, const ::com::sun::star::uno::Reference< + ::com::sun::star::sdbc::XResultSet >& xResultSet, + const SbaSelectionList* pSelection ) { // Target ist jetzt einfach der Bereichsname @@ -1402,7 +1405,7 @@ void ScDBDocFunc::UpdateImport( const String& rTarget, const String& rDBName, aImportParam.bNative = bNative; aImportParam.nType = nType; aImportParam.bImport = TRUE; - BOOL bContinue = DoImport( nTab, aImportParam, pSelection, TRUE ); + BOOL bContinue = DoImport( nTab, aImportParam, xResultSet, pSelection, TRUE ); // DB-Operationen wiederholen diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx index ca3fcce422d0..6d394fefb965 100644 --- a/sc/source/ui/docshell/dbdocimp.cxx +++ b/sc/source/ui/docshell/dbdocimp.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dbdocimp.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: nn $ $Date: 2001-06-25 15:59:08 $ + * last change: $Author: er $ $Date: 2002-08-08 13:02:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,6 +68,7 @@ // INCLUDE --------------------------------------------------------- #include <comphelper/processfactory.hxx> +#include <comphelper/types.hxx> #include <vcl/msgbox.hxx> #include <tools/debug.hxx> #include <offmgr/sbaitems.hxx> // SbaSelectionList @@ -84,6 +85,7 @@ #include <com/sun/star/frame/FrameSearchFlag.hpp> #include <com/sun/star/view/XSelectionSupplier.hpp> + #include "dbdocfun.hxx" #include "docsh.hxx" #include "globstr.hrc" @@ -213,7 +215,7 @@ BOOL ScDBDocFunc::DoImportUno( const ScAddress& rPos, BOOL bAddrInsert = FALSE; //!??? if ( bAddrInsert ) { - bDone = DoImport( rPos.Tab(), aImParam, &aList, TRUE, bAddrInsert ); + bDone = DoImport( rPos.Tab(), aImParam, xResSet, &aList, TRUE, bAddrInsert ); } else { @@ -232,10 +234,8 @@ BOOL ScDBDocFunc::DoImportUno( const ScAddress& rPos, else aTableName = aImParam.aStatement; - UpdateImport( sTarget, aImParam.aDBName, - aTableName, aStatement, - aImParam.bNative, aImParam.nType, - &aList ); + UpdateImport( sTarget, aImParam.aDBName, aTableName, aStatement, + aImParam.bNative, aImParam.nType, xResSet, &aList ); bDone = TRUE; } @@ -245,8 +245,8 @@ BOOL ScDBDocFunc::DoImportUno( const ScAddress& rPos, // ----------------------------------------------------------------- BOOL ScDBDocFunc::DoImport( USHORT nTab, const ScImportParam& rParam, - const SbaSelectionList* pSelection, - BOOL bRecord, BOOL bAddrInsert ) + const uno::Reference< sdbc::XResultSet >& xResultSet, + const SbaSelectionList* pSelection, BOOL bRecord, BOOL bAddrInsert ) { ScDocument* pDoc = rDocShell.GetDocument(); @@ -311,47 +311,56 @@ BOOL ScDBDocFunc::DoImport( USHORT nTab, const ScImportParam& rParam, ScProgress aProgress( &rDocShell, ScGlobal::GetRscString(STR_UNDO_IMPORTDATA), 0 ); USHORT nInserted = 0; - uno::Reference<sdbc::XRowSet> xRowSet( - comphelper::getProcessServiceFactory()->createInstance( - rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), - uno::UNO_QUERY); - uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY ); - DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); - if ( xRowProp.is() ) + uno::Reference<sdbc::XRowSet> xRowSet = uno::Reference<sdbc::XRowSet>( + xResultSet, uno::UNO_QUERY ); + sal_Bool bDispose = sal_False; + if ( !xRowSet.is() ) { - // - // set source parameters - // + bDispose = sal_True; + xRowSet = uno::Reference<sdbc::XRowSet>( + comphelper::getProcessServiceFactory()->createInstance( + rtl::OUString::createFromAscii( SC_SERVICE_ROWSET ) ), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xRowProp( xRowSet, uno::UNO_QUERY ); + DBG_ASSERT( xRowProp.is(), "can't get RowSet" ); + if ( xRowProp.is() ) + { + // + // set source parameters + // - sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND : - ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY : - sdb::CommandType::TABLE ); - uno::Any aAny; + sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND : + ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY : + sdb::CommandType::TABLE ); + uno::Any aAny; - aAny <<= rtl::OUString( rParam.aDBName ); - xRowProp->setPropertyValue( - rtl::OUString::createFromAscii(SC_DBPROP_DATASOURCENAME), aAny ); + aAny <<= rtl::OUString( rParam.aDBName ); + xRowProp->setPropertyValue( + rtl::OUString::createFromAscii(SC_DBPROP_DATASOURCENAME), aAny ); - aAny <<= rtl::OUString( rParam.aStatement ); - xRowProp->setPropertyValue( - rtl::OUString::createFromAscii(SC_DBPROP_COMMAND), aAny ); + aAny <<= rtl::OUString( rParam.aStatement ); + xRowProp->setPropertyValue( + rtl::OUString::createFromAscii(SC_DBPROP_COMMAND), aAny ); - aAny <<= nType; - xRowProp->setPropertyValue( - rtl::OUString::createFromAscii(SC_DBPROP_COMMANDTYPE), aAny ); + aAny <<= nType; + xRowProp->setPropertyValue( + rtl::OUString::createFromAscii(SC_DBPROP_COMMANDTYPE), aAny ); - uno::Reference<sdb::XCompletedExecution> xExecute( xRowSet, uno::UNO_QUERY ); - if ( xExecute.is() ) - { - uno::Reference<task::XInteractionHandler> xHandler( - comphelper::getProcessServiceFactory()->createInstance( - rtl::OUString::createFromAscii( SC_SERVICE_INTHANDLER ) ), - uno::UNO_QUERY); - xExecute->executeWithCompletion( xHandler ); + uno::Reference<sdb::XCompletedExecution> xExecute( xRowSet, uno::UNO_QUERY ); + if ( xExecute.is() ) + { + uno::Reference<task::XInteractionHandler> xHandler( + comphelper::getProcessServiceFactory()->createInstance( + rtl::OUString::createFromAscii( SC_SERVICE_INTHANDLER ) ), + uno::UNO_QUERY); + xExecute->executeWithCompletion( xHandler ); + } + else + xRowSet->execute(); } - else - xRowSet->execute(); - + } + if ( xRowSet.is() ) + { // // get column descriptions // @@ -398,6 +407,7 @@ BOOL ScDBDocFunc::DoImport( USHORT nTab, const ScImportParam& rParam, } BOOL bEnd = FALSE; + xRowSet->beforeFirst(); while ( !bEnd && xRowSet->next() ) { // skip rows that are not selected @@ -468,9 +478,8 @@ BOOL ScDBDocFunc::DoImport( USHORT nTab, const ScImportParam& rParam, bSuccess = TRUE; } - uno::Reference<lang::XComponent> xComponent( xRowSet, uno::UNO_QUERY ); - if (xComponent.is()) - xComponent->dispose(); + if ( bDispose ) + ::comphelper::disposeComponent( xRowSet ); } } catch ( sdbc::SQLException& rError ) diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 00cbe91d11d5..8ae2e78f6a7c 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -2,9 +2,9 @@ * * $RCSfile: docsh4.cxx,v $ * - * $Revision: 1.20 $ + * $Revision: 1.21 $ * - * last change: $Author: sab $ $Date: 2002-07-24 09:18:05 $ + * last change: $Author: er $ $Date: 2002-08-08 13:02:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -334,9 +334,11 @@ void ScDocShell::Execute( SfxRequest& rReq ) if (bDo) { - ScDBDocFunc(*this). - UpdateImport( sTarget, sDBName, sDBTable, sDBSql, - TRUE, nType, pSelectionList ); + ::com::sun::star::uno::Reference< + ::com::sun::star::sdbc::XResultSet > xResultSet; + ScDBDocFunc(*this).UpdateImport( sTarget, sDBName, + sDBTable, sDBSql, TRUE, nType, xResultSet, + pSelectionList ); rReq.Done(); // UpdateImport aktualisiert auch die internen Operationen diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 8924741c263c..236fb047d092 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -2,9 +2,9 @@ * * $RCSfile: docsh5.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: nn $ $Date: 2001-05-11 17:10:37 $ + * last change: $Author: er $ $Date: 2002-08-08 13:02:40 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -189,6 +189,7 @@ #include <sfx2/bindings.hxx> #include <svtools/smplhint.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> // INCLUDE --------------------------------------------------------------- @@ -966,7 +967,8 @@ IMPL_LINK( ScDocShell, RefreshDBDataHdl, ScDBData*, pDBData ) { ScRange aRange; pDBData->GetArea( aRange ); - bContinue = aFunc.DoImport( aRange.aStart.Tab(), aImportParam, NULL, TRUE, FALSE ); //! Api-Flag as parameter + ::com::sun::star::uno::Reference<::com::sun::star::sdbc::XResultSet> xResultSet; + bContinue = aFunc.DoImport( aRange.aStart.Tab(), aImportParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag as parameter // internal operations (sort, query, subtotal) only if no error if (bContinue) { diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx index e2119e687205..adb261edc88e 100644 --- a/sc/source/ui/inc/dbdocfun.hxx +++ b/sc/source/ui/inc/dbdocfun.hxx @@ -2,9 +2,9 @@ * * $RCSfile: dbdocfun.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: nn $ $Date: 2000-11-13 19:23:21 $ + * last change: $Author: er $ $Date: 2002-08-08 13:02:16 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -85,9 +85,14 @@ class ScAddress; class ScRange; class ScDPObject; -namespace com { namespace sun { namespace star { namespace beans { - struct PropertyValue; -} } } } +namespace com { namespace sun { namespace star { + namespace beans { + struct PropertyValue; + } + namespace sdbc { + class XResultSet; + } +} } } // --------------------------------------------------------------------------- @@ -103,12 +108,17 @@ public: ~ScDBDocFunc() {} void UpdateImport( const String& rTarget, const String& rDBName, - const String& rTableName, const String& rStatement, - BOOL bNative, BYTE nType, - const SbaSelectionList* pSelection ); + const String& rTableName, const String& rStatement, + BOOL bNative, BYTE nType, + const ::com::sun::star::uno::Reference< + ::com::sun::star::sdbc::XResultSet >& xResultSet, + const SbaSelectionList* pSelection ); + BOOL DoImport( USHORT nTab, const ScImportParam& rParam, - const SbaSelectionList* pSelection, - BOOL bRecord, BOOL bAddrInsert = FALSE ); + const ::com::sun::star::uno::Reference< + ::com::sun::star::sdbc::XResultSet >& xResultSet, + const SbaSelectionList* pSelection, BOOL bRecord, + BOOL bAddrInsert = FALSE ); BOOL DoImportUno( const ScAddress& rPos, const com::sun::star::uno::Sequence< diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 8304e8598242..5f28a5904950 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: cellsuno.cxx,v $ * - * $Revision: 1.63 $ + * $Revision: 1.64 $ * - * last change: $Author: dr $ $Date: 2002-07-17 16:14:11 $ + * last change: $Author: er $ $Date: 2002-08-08 13:03:43 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -5258,10 +5258,13 @@ void SAL_CALL ScCellRangeObj::doImport( const uno::Sequence<beans::PropertyValue aParam.nCol2 = aRange.aEnd.Col(); aParam.nRow2 = aRange.aEnd.Row(); + //! TODO: could we get passed a valid result set by any means? + uno::Reference< sdbc::XResultSet > xResultSet; + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen ScDBDocFunc aFunc(*pDocSh); // Bereich muss angelegt sein - aFunc.DoImport( nTab, aParam, NULL, TRUE, FALSE ); //! Api-Flag als Parameter + aFunc.DoImport( nTab, aParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag als Parameter } } diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx index 2c9cf75e7fe3..247c7ef94e26 100644 --- a/sc/source/ui/unoobj/datauno.cxx +++ b/sc/source/ui/unoobj/datauno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: datauno.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: nn $ $Date: 2001-03-15 20:34:11 $ + * last change: $Author: er $ $Date: 2002-08-08 13:03:43 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1701,7 +1701,8 @@ void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException) { USHORT nTab, nDummy; pData->GetArea( nTab, nDummy,nDummy,nDummy,nDummy ); - bContinue = aFunc.DoImport( nTab, aImportParam, NULL, TRUE, FALSE ); //! Api-Flag als Parameter + uno::Reference< sdbc::XResultSet > xResultSet; + bContinue = aFunc.DoImport( nTab, aImportParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag als Parameter } // interne Operationen (sort, query, subtotal) nur, wenn kein Fehler diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx index 61c2016df8a5..9a826054f4cc 100644 --- a/sc/source/ui/view/cellsh2.cxx +++ b/sc/source/ui/view/cellsh2.cxx @@ -2,9 +2,9 @@ * * $RCSfile: cellsh2.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: nn $ $Date: 2002-07-19 12:20:27 $ + * last change: $Author: er $ $Date: 2002-08-08 13:05:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -167,6 +167,7 @@ #include <vcl/msgbox.hxx> #include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> #include "cellsh.hxx" #include "tabvwsh.hxx" @@ -347,9 +348,13 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq ) aImParam.aDBName = rDBNameItem.GetValue(); aImParam.aStatement = rStatementItem.GetValue(); - ScDBDocFunc( *pViewData->GetDocShell() ). - DoImport( pViewData->GetTabNo(), aImParam, - rSelectionItem.GetSelectionList(), TRUE, TRUE ); + ::com::sun::star::uno::Reference< + ::com::sun::star::sdbc::XResultSet > xResultSet; + + ScDBDocFunc( *pViewData->GetDocShell() ).DoImport( + pViewData->GetTabNo(), aImParam, xResultSet, + rSelectionItem.GetSelectionList(), TRUE, TRUE ); + rReq.Done(); } else diff --git a/sc/source/ui/view/dbfunc.cxx b/sc/source/ui/view/dbfunc.cxx index 25979495387a..a88a6245669a 100644 --- a/sc/source/ui/view/dbfunc.cxx +++ b/sc/source/ui/view/dbfunc.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dbfunc.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: sab $ $Date: 2001-02-14 15:34:07 $ + * last change: $Author: er $ $Date: 2002-08-08 13:05:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -72,6 +72,8 @@ #include <sfx2/bindings.hxx> #include <vcl/msgbox.hxx> +#include <com/sun/star/sdbc/XResultSet.hpp> + #include "dbfunc.hxx" #include "docsh.hxx" #include "attrib.hxx" @@ -443,7 +445,8 @@ BOOL ScDBFunc::ImportData( const ScImportParam& rParam, BOOL bRecord ) } ScDBDocFunc aDBDocFunc( *GetViewData()->GetDocShell() ); - return aDBDocFunc.DoImport( GetViewData()->GetTabNo(), rParam, NULL, bRecord ); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > xResultSet; + return aDBDocFunc.DoImport( GetViewData()->GetTabNo(), rParam, xResultSet, NULL, bRecord ); } |