From 1863a6a42df03ffcff486d0d24c0a8704bf083fc Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Tue, 6 Jul 2010 15:20:20 +0200 Subject: dba33g: #i112520# don't use getBestRowIdent.. --- dbaccess/source/core/api/KeySet.cxx | 4 +++- dbaccess/source/core/api/OptimisticSet.cxx | 3 ++- dbaccess/source/core/api/RowSetCache.cxx | 3 ++- dbaccess/source/core/api/WrappedResultSet.cxx | 20 +++++++++----------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx index 3db4acdbc..fa8510b3c 100644 --- a/dbaccess/source/core/api/KeySet.cxx +++ b/dbaccess/source/core/api/KeySet.cxx @@ -358,15 +358,17 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O xTableProp->getPropertyValue(PROPERTY_NAME) >>= sTable; ::std::vector< ::rtl::OUString> aBestRowColumnNames; + /* doesn't work with hsqldb Reference xBestRes(xMeta->getBestRowIdentifier(aCatalog,sSchema,sTable,0,sal_False)); Reference xBestRow(xBestRes,uno::UNO_QUERY); while ( xBestRes->next() ) { aBestRowColumnNames.push_back(xBestRow->getString(2)); } - + */ Sequence< ::rtl::OUString> aBestColumnNames; if ( !aBestRowColumnNames.empty() ) + { aBestColumnNames = Sequence< ::rtl::OUString>(&aBestRowColumnNames[0],aBestRowColumnNames.size()); ::dbaccess::getColumnPositions(xSup->getColumns(),aBestColumnNames,m_sUpdateTableName,(*m_pKeyColumnNames)); diff --git a/dbaccess/source/core/api/OptimisticSet.cxx b/dbaccess/source/core/api/OptimisticSet.cxx index 1dc198140..3495b2e55 100644 --- a/dbaccess/source/core/api/OptimisticSet.cxx +++ b/dbaccess/source/core/api/OptimisticSet.cxx @@ -1303,13 +1303,14 @@ void OptimisticSet::findTableColumnsMatching_throw(const Any& i_aTable // first ask the database itself for the best columns which can be used ::std::vector< ::rtl::OUString> aBestRowColumnNames; + /* Reference xBestRes(i_xMeta->getBestRowIdentifier(aCatalog,sSchema,sTable,0,sal_False)); Reference xBestRow(xBestRes,uno::UNO_QUERY); while ( xBestRes->next() ) { aBestRowColumnNames.push_back(xBestRow->getString(2)); } - + */ Sequence< ::rtl::OUString> aBestColumnNames; if ( aBestRowColumnNames.empty() ) { diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index 295e29ebe..8716a2132 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -167,8 +167,9 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, m_pCacheSet->construct(_xRs,i_sRowSetFilter); return; } - catch(const Exception&) + catch(const Exception& ex) { + (void)ex; } _xRs->beforeFirst(); diff --git a/dbaccess/source/core/api/WrappedResultSet.cxx b/dbaccess/source/core/api/WrappedResultSet.cxx index 6e8175b2e..d56765186 100644 --- a/dbaccess/source/core/api/WrappedResultSet.cxx +++ b/dbaccess/source/core/api/WrappedResultSet.cxx @@ -64,43 +64,41 @@ void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::getBookmark" ); + if ( m_xRowLocate.is() ) + { + return m_xRowLocate->getBookmark( ); + } return makeAny(m_xDriverSet->getRow()); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToBookmark" ); - sal_Int32 nPos = 1; - bookmark >>= nPos; - return m_xDriverSet->absolute(nPos); + return m_xRowLocate->moveToBookmark( bookmark ); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveRelativeToBookmark" ); - sal_Int32 nPos = 1; - bookmark >>= nPos; - return m_xDriverSet->absolute(nPos + rows); + return m_xRowLocate->moveRelativeToBookmark( bookmark,rows ); } // ------------------------------------------------------------------------- sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::compareBookmarks" ); - return _first != _second; + return m_xRowLocate->compareBookmarks( _first,_second ); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL WrappedResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hasOrderedBookmarks" ); - return sal_True; + return m_xRowLocate->hasOrderedBookmarks(); } // ------------------------------------------------------------------------- sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hashBookmark" ); - sal_Int32 nPos = 1; - bookmark >>= nPos; - return nPos; + return m_xRowLocate->hashBookmark(bookmark); } // ------------------------------------------------------------------------- // ::com::sun::star::sdbcx::XDeleteRows -- cgit v1.2.3 From 77d0850d26bb99f53429aaf68de477d6a97ca8e9 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 7 Jul 2010 08:07:40 +0200 Subject: dba33g: #i112609# do not limited tables to the selection --- dbaccess/source/ui/browser/brwctrlr.cxx | 1 + dbaccess/source/ui/browser/unodatbr.cxx | 4 +--- dbaccess/source/ui/inc/unodatbr.hxx | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx index 41bb28651..23bd7bd99 100644 --- a/dbaccess/source/ui/browser/brwctrlr.cxx +++ b/dbaccess/source/ui/browser/brwctrlr.cxx @@ -2751,6 +2751,7 @@ void SbaXDataBrowserController::unloading(const EventObject& /*aEvent*/) throw( void SbaXDataBrowserController::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException ) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaui", "Ocke.Janssen@sun.com", "SbaXDataBrowserController::unloaded" ); + m_xParser.clear(); InvalidateAll(); // do this asynchron, there are other listeners reacting on this message ... // (it's a little hack : the grid columns are listening to this event, too, and their bound field may diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx index bdd31895a..451840e9a 100644 --- a/dbaccess/source/ui/browser/unodatbr.cxx +++ b/dbaccess/source/ui/browser/unodatbr.cxx @@ -1106,9 +1106,7 @@ SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataS // expand if required so if (_bExpandAncestors) { - m_sToBeLoaded = _rCommand; m_pTreeView->getListBox().Expand(pCommandType); - m_sToBeLoaded = ::rtl::OUString(); } // look for the object @@ -2054,7 +2052,7 @@ void SbaTableQueryBrowser::populateTree(const Reference& _xNameAcce const ::rtl::OUString* pEnd = pIter + aNames.getLength(); for (; pIter != pEnd; ++pIter) { - if( (!m_sToBeLoaded.getLength() || m_sToBeLoaded == *pIter) && !m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent)) + if( !m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent)) { Reference xChild(_xNameAccess->getByName(*pIter),UNO_QUERY); DBTreeListUserData* pEntryData = new DBTreeListUserData; diff --git a/dbaccess/source/ui/inc/unodatbr.hxx b/dbaccess/source/ui/inc/unodatbr.hxx index 0fb37b65d..e87f1caf1 100644 --- a/dbaccess/source/ui/inc/unodatbr.hxx +++ b/dbaccess/source/ui/inc/unodatbr.hxx @@ -157,7 +157,7 @@ namespace dbaui OTableCopyHelper m_aTableCopyHelper; ::rtl::OUString m_sQueryCommand; // the command of the query currently loaded (if any) - ::rtl::OUString m_sToBeLoaded; // contains the element name which should be loaded if any + //::rtl::OUString m_sToBeLoaded; // contains the element name which should be loaded if any DBTreeView* m_pTreeView; Splitter* m_pSplitter; -- cgit v1.2.3 From 8741dbd2cefcd99782179d0cdf6ea740eed15a85 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 7 Jul 2010 08:25:19 +0200 Subject: dba33g: clear warnings when free resource to avoid disposed exception when reloaded --- dbaccess/source/core/api/RowSet.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 20483cff0..1f7c0294f 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -580,6 +580,9 @@ void ORowSet::freeResources( bool _bComplete ) m_xComposer = NULL; } + // let our warnings container forget the reference to the (possibly disposed) old result set + m_aWarnings.setExternalWarnings( NULL ); + DELETEZ(m_pCache); impl_resetTables_nothrow(); -- cgit v1.2.3 From 608286b94d247efc158021d7ccd4f1fcdbb1792b Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 7 Jul 2010 12:43:22 +0200 Subject: dba33g: #i112620# modified state is not set correctly at sdrmodel --- reportdesign/source/core/api/ReportDefinition.cxx | 1 + reportdesign/source/ui/report/FormattedFieldBeautifier.cxx | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx index d1622dd59..6e9408207 100644 --- a/reportdesign/source/core/api/ReportDefinition.cxx +++ b/reportdesign/source/core/api/ReportDefinition.cxx @@ -1299,6 +1299,7 @@ void SAL_CALL OReportDefinition::close( ::sal_Bool _bDeliverOwnership ) throw (u ::connectivity::checkDisposed(ReportDefinitionBase::rBHelper.bDisposed); ::comphelper::MediaDescriptor aDescriptor( _aArguments ); fillArgs(aDescriptor); + m_pImpl->m_pReportModel->SetModified(sal_False); return sal_True; } // ----------------------------------------------------------------------------- diff --git a/reportdesign/source/ui/report/FormattedFieldBeautifier.cxx b/reportdesign/source/ui/report/FormattedFieldBeautifier.cxx index 6bfe1a913..b060eef09 100644 --- a/reportdesign/source/ui/report/FormattedFieldBeautifier.cxx +++ b/reportdesign/source/ui/report/FormattedFieldBeautifier.cxx @@ -88,11 +88,10 @@ namespace rptui void FormattedFieldBeautifier::setPlaceholderText( const uno::Reference< uno::XInterface >& _rxComponent ) { ::rtl::OUString sDataField; - uno::Reference< report::XReportComponent > xComponent( _rxComponent, uno::UNO_QUERY ); try { - uno::Reference< report::XReportControlModel > xControlModel( xComponent, uno::UNO_QUERY ); + uno::Reference< report::XFormattedField > xControlModel( _rxComponent, uno::UNO_QUERY ); if ( xControlModel.is() ) { sDataField = xControlModel->getDataField(); @@ -119,8 +118,8 @@ namespace rptui } } - if ( xComponent.is() ) - setPlaceholderText( getVclWindowPeer( xComponent ), sDataField ); + if ( xControlModel.is() ) + setPlaceholderText( getVclWindowPeer( xControlModel.get() ), sDataField ); } catch (uno::Exception) { -- cgit v1.2.3 From a035cddf79f291837a2973c7aab81a7f9daa18e0 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 8 Jul 2010 12:21:55 +0200 Subject: dba33g: #i111205# handle filter for key and update and insert row --- dbaccess/source/core/api/KeySet.cxx | 525 ++++++++-------- dbaccess/source/core/api/KeySet.hxx | 26 +- dbaccess/source/core/api/OptimisticSet.cxx | 940 +---------------------------- dbaccess/source/core/api/OptimisticSet.hxx | 99 +-- dbaccess/source/core/api/makefile.mk | 1 + 5 files changed, 282 insertions(+), 1309 deletions(-) diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx index fa8510b3c..a312d05b1 100644 --- a/dbaccess/source/core/api/KeySet.cxx +++ b/dbaccess/source/core/api/KeySet.cxx @@ -53,9 +53,6 @@ #ifndef _COM_SUN_STAR_SDBC_XGENERATEDRESULTSET_HPP_ #include #endif -#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_ -#include -#endif #ifndef _COM_SUN_STAR_SDBC_XCOLUMNLOCATE_HPP_ #include #endif @@ -112,6 +109,7 @@ #endif #include #include +#include "PrivateRow.hxx" using namespace dbaccess; using namespace ::connectivity; @@ -148,134 +146,6 @@ namespace } } } - class OPrivateRow : public ::cppu::WeakImplHelper1 - { - ORowSetValueVector::Vector m_aRow; - sal_Int32 m_nPos; - public: - OPrivateRow(const ORowSetValueVector::Vector& i_aRow) : m_aRow(i_aRow),m_nPos(0) - { - } - virtual ::sal_Bool SAL_CALL wasNull( ) throw (SQLException, RuntimeException); - virtual ::rtl::OUString SAL_CALL getString( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::sal_Bool SAL_CALL getBoolean( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::sal_Int8 SAL_CALL getByte( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::sal_Int16 SAL_CALL getShort( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::sal_Int32 SAL_CALL getInt( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::sal_Int64 SAL_CALL getLong( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual float SAL_CALL getFloat( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual double SAL_CALL getDouble( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Sequence< ::sal_Int8 > SAL_CALL getBytes( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::com::sun::star::util::Date SAL_CALL getDate( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::com::sun::star::util::Time SAL_CALL getTime( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Any SAL_CALL getObject( ::sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw (SQLException, RuntimeException); - virtual Reference< XRef > SAL_CALL getRef( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Reference< XBlob > SAL_CALL getBlob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Reference< XClob > SAL_CALL getClob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - virtual Reference< XArray > SAL_CALL getArray( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException); - }; - ::sal_Bool SAL_CALL OPrivateRow::wasNull( ) throw (SQLException, RuntimeException) - { - return m_aRow[m_nPos].isNull(); - } - ::rtl::OUString SAL_CALL OPrivateRow::getString( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::sal_Bool SAL_CALL OPrivateRow::getBoolean( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::sal_Int8 SAL_CALL OPrivateRow::getByte( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::sal_Int16 SAL_CALL OPrivateRow::getShort( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::sal_Int32 SAL_CALL OPrivateRow::getInt( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::sal_Int64 SAL_CALL OPrivateRow::getLong( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - float SAL_CALL OPrivateRow::getFloat( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - double SAL_CALL OPrivateRow::getDouble( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - Sequence< ::sal_Int8 > SAL_CALL OPrivateRow::getBytes( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::com::sun::star::util::Date SAL_CALL OPrivateRow::getDate( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::com::sun::star::util::Time SAL_CALL OPrivateRow::getTime( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - ::com::sun::star::util::DateTime SAL_CALL OPrivateRow::getTimestamp( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos]; - } - Reference< ::com::sun::star::io::XInputStream > SAL_CALL OPrivateRow::getBinaryStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< ::com::sun::star::io::XInputStream >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } - Reference< ::com::sun::star::io::XInputStream > SAL_CALL OPrivateRow::getCharacterStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< ::com::sun::star::io::XInputStream >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } - Any SAL_CALL OPrivateRow::getObject( ::sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return m_aRow[m_nPos].makeAny(); - } - Reference< XRef > SAL_CALL OPrivateRow::getRef( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< XRef >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } - Reference< XBlob > SAL_CALL OPrivateRow::getBlob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< XBlob >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } - Reference< XClob > SAL_CALL OPrivateRow::getClob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< XClob >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } - Reference< XArray > SAL_CALL OPrivateRow::getArray( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) - { - m_nPos = columnIndex; - return Reference< XArray >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } } DBG_NAME(OKeySet) // ------------------------------------------------------------------------- @@ -315,29 +185,41 @@ OKeySet::~OKeySet() OSL_ENSURE(0,"Unknown Exception occured"); } m_xComposer = NULL; - delete m_pKeyColumnNames; - delete m_pColumnNames; - delete m_pParameterNames; - delete m_pForeignColumnNames; DBG_DTOR(OKeySet,NULL); } -// ----------------------------------------------------------------------------- -void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) +void OKeySet::initColumns() { - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::construct" ); - OCacheSet::construct(_xDriverSet,i_sRowSetFilter); - Reference xMeta = m_xConnection->getMetaData(); bool bCase = (xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers()) ? true : false; - m_pKeyColumnNames = new SelectColumnsMetaData(bCase); - m_pColumnNames = new SelectColumnsMetaData(bCase); - m_pParameterNames = new SelectColumnsMetaData(bCase); - m_pForeignColumnNames = new SelectColumnsMetaData(bCase); + m_pKeyColumnNames.reset( new SelectColumnsMetaData(bCase) ); + m_pColumnNames.reset( new SelectColumnsMetaData(bCase) ); + m_pParameterNames.reset( new SelectColumnsMetaData(bCase) ); + m_pForeignColumnNames.reset( new SelectColumnsMetaData(bCase) ); +} +void OKeySet::findTableColumnsMatching_throw(const Any& i_aTable + ,const Reference& i_xMeta + ,const Reference& i_xQueryColumns) +{ + ::rtl::OUString sCatalog,sSchema,sTable; + Reference xTableProp(i_aTable,UNO_QUERY); + Any aCatalog = xTableProp->getPropertyValue(PROPERTY_CATALOGNAME); + aCatalog >>= sCatalog; + xTableProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema; + xTableProp->getPropertyValue(PROPERTY_NAME) >>= sTable; + + // first ask the database itself for the best columns which can be used + Sequence< ::rtl::OUString> aBestColumnNames; + Reference xKeyColumns = getPrimaryKeyColumns_throw(i_aTable); + if ( xKeyColumns.is() ) + aBestColumnNames = xKeyColumns->getElementNames(); + + const Reference xTblColSup(i_aTable,UNO_QUERY_THROW); + const Reference xTblColumns = xTblColSup->getColumns(); + const ::rtl::OUString sComposedUpdateTableName = dbtools::composeTableName( i_xMeta, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ); + ::dbaccess::getColumnPositions(i_xQueryColumns,aBestColumnNames,sComposedUpdateTableName,(*m_pKeyColumnNames),true); + ::dbaccess::getColumnPositions(i_xQueryColumns,xTblColumns->getElementNames(),sComposedUpdateTableName,(*m_pColumnNames),true); - Reference xKeyColumns = getKeyColumns(); - Reference xSup(m_xComposer,UNO_QUERY); - Reference xSourceColumns = m_xTable->getColumns(); // locate parameter in select columns Reference xParaSup(m_xComposer,UNO_QUERY); Reference xQueryParameters = xParaSup->getParameters(); @@ -347,85 +229,62 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O { Reference xPara(xQueryParameters->getByIndex(i),UNO_QUERY_THROW); xPara->getPropertyValue(PROPERTY_REALNAME) >>= aParameterColumns[i]; - } - - ::rtl::OUString sCatalog,sSchema,sTable; - - Reference xTableProp(m_xTable,UNO_QUERY); - Any aCatalog = xTableProp->getPropertyValue(PROPERTY_CATALOGNAME); - aCatalog >>= sCatalog; - xTableProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema; - xTableProp->getPropertyValue(PROPERTY_NAME) >>= sTable; - - ::std::vector< ::rtl::OUString> aBestRowColumnNames; - /* doesn't work with hsqldb - Reference xBestRes(xMeta->getBestRowIdentifier(aCatalog,sSchema,sTable,0,sal_False)); - Reference xBestRow(xBestRes,uno::UNO_QUERY); - while ( xBestRes->next() ) - { - aBestRowColumnNames.push_back(xBestRow->getString(2)); } - */ - Sequence< ::rtl::OUString> aBestColumnNames; - if ( !aBestRowColumnNames.empty() ) - - { - aBestColumnNames = Sequence< ::rtl::OUString>(&aBestRowColumnNames[0],aBestRowColumnNames.size()); - ::dbaccess::getColumnPositions(xSup->getColumns(),aBestColumnNames,m_sUpdateTableName,(*m_pKeyColumnNames)); - } - - if (m_pKeyColumnNames->empty() && xKeyColumns.is()) - { - aBestColumnNames = xKeyColumns->getElementNames(); - ::dbaccess::getColumnPositions(xSup->getColumns(),aBestColumnNames,m_sUpdateTableName,(*m_pKeyColumnNames)); - } - ::dbaccess::getColumnPositions(xSup->getColumns(),xSourceColumns->getElementNames(),m_sUpdateTableName,(*m_pColumnNames)); - ::dbaccess::getColumnPositions(xSup->getColumns(),aParameterColumns,m_sUpdateTableName,(*m_pParameterNames)); + ::dbaccess::getColumnPositions(i_xQueryColumns,aParameterColumns,sComposedUpdateTableName,(*m_pParameterNames),true); - SelectColumnsMetaData::const_iterator aPosIter = (*m_pKeyColumnNames).begin(); - SelectColumnsMetaData::const_iterator aPosEnd = (*m_pKeyColumnNames).end(); + SelectColumnsMetaData::const_iterator aPosIter = m_pKeyColumnNames->begin(); + SelectColumnsMetaData::const_iterator aPosEnd = m_pKeyColumnNames->end(); for(;aPosIter != aPosEnd;++aPosIter) { - if(xSourceColumns->hasByName(aPosIter->first)) + if ( xTblColumns->hasByName(aPosIter->second.sRealName) ) { - Reference xProp(xSourceColumns->getByName(aPosIter->first),UNO_QUERY); - sal_Bool bAuto = sal_Bool(); + Reference xProp(xTblColumns->getByName(aPosIter->second.sRealName),UNO_QUERY); + sal_Bool bAuto = sal_False; if( (xProp->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAuto) && bAuto) m_aAutoColumns.push_back(aPosIter->first); } } - - // the first row is empty because it's now easier for us to distinguish when we are beforefirst or first - // without extra varaible to be set - m_aKeyMap.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL,::std::pair >(0,NULL)))); - - m_aKeyIter = m_aKeyMap.begin(); - +} +::rtl::OUStringBuffer OKeySet::createKeyFilter() +{ static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); - Reference xMetaData = m_xConnection->getMetaData(); const ::rtl::OUString aQuote = getIdentifierQuoteString(); - m_aSelectComposedTableName = getComposedTableName(sCatalog,sSchema,sTable); - - ::rtl::OUString sComposedName; - sCatalog = sSchema = sTable = ::rtl::OUString(); - ::dbtools::qualifiedNameComponents(xMetaData,m_sUpdateTableName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation); - sComposedName = ::dbtools::composeTableName( xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInDataManipulation ); - ::rtl::OUStringBuffer aFilter; static ::rtl::OUString s_sDot(RTL_CONSTASCII_USTRINGPARAM(".")); static ::rtl::OUString s_sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); // create the where clause - aPosEnd = (*m_pKeyColumnNames).end(); - for(aPosIter = (*m_pKeyColumnNames).begin();aPosIter != aPosEnd;) + SelectColumnsMetaData::iterator aPosEnd = m_pKeyColumnNames->end(); + for(SelectColumnsMetaData::iterator aPosIter = m_pKeyColumnNames->begin();aPosIter != aPosEnd;) { - aFilter.append(sComposedName); + aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sTableName)); aFilter.append(s_sDot); - aFilter.append(::dbtools::quoteName( aQuote,aPosIter->first)); + aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sRealName)); aFilter.append(s_sParam); ++aPosIter; if(aPosIter != aPosEnd) aFilter.append(aAnd); } + return aFilter; +} +// ----------------------------------------------------------------------------- +void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::construct" ); + OCacheSet::construct(_xDriverSet,i_sRowSetFilter); + initColumns(); + + Reference xKeyColumns = getKeyColumns(); + Reference xMeta = m_xConnection->getMetaData(); + Reference xQueryColSup(m_xComposer,UNO_QUERY); + const Reference xQueryColumns = xQueryColSup->getColumns(); + findTableColumnsMatching_throw(makeAny(m_xTable),xMeta,xQueryColumns); + + // the first row is empty because it's now easier for us to distinguish when we are beforefirst or first + // without extra varaible to be set + m_aKeyMap.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL,::std::pair >(0,NULL)))); + m_aKeyIter = m_aKeyMap.begin(); + + ::rtl::OUStringBuffer aFilter = createKeyFilter(); Reference< XSingleSelectQueryComposer> xSourceComposer(m_xComposer,UNO_QUERY); Reference< XMultiServiceFactory > xFactory(m_xConnection, UNO_QUERY_THROW); @@ -436,6 +295,10 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O const Sequence< ::rtl::OUString> aSeq = xSelectTables->getElementNames(); if ( aSeq.getLength() > 1 ) // special handling for join { + static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); + const ::rtl::OUString aQuote = getIdentifierQuoteString(); + static ::rtl::OUString s_sDot(RTL_CONSTASCII_USTRINGPARAM(".")); + static ::rtl::OUString s_sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); const ::rtl::OUString* pIter = aSeq.getConstArray(); const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); for(;pIter != pEnd;++pIter) @@ -444,13 +307,12 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O { connectivity::OSQLTable xSelColSup(xSelectTables->getByName(*pIter),uno::UNO_QUERY); Reference xProp(xSelColSup,uno::UNO_QUERY); - ::rtl::OUString sSelectTableName = ::dbtools::composeTableName( xMetaData, xProp, ::dbtools::eInDataManipulation, false, false, false ); - Reference xSelectColumns = xSup->getColumns(); + ::rtl::OUString sSelectTableName = ::dbtools::composeTableName( xMeta, xProp, ::dbtools::eInDataManipulation, false, false, false ); - ::dbaccess::getColumnPositions(xSelectColumns,xSelColSup->getColumns()->getElementNames(),sSelectTableName,(*m_pForeignColumnNames)); + ::dbaccess::getColumnPositions(xQueryColumns,xSelColSup->getColumns()->getElementNames(),sSelectTableName,(*m_pForeignColumnNames)); - aPosEnd = (*m_pForeignColumnNames).end(); - for(aPosIter = (*m_pForeignColumnNames).begin();aPosIter != aPosEnd;++aPosIter) + SelectColumnsMetaData::iterator aPosEnd = (*m_pForeignColumnNames).end(); + for(SelectColumnsMetaData::iterator aPosIter = (*m_pForeignColumnNames).begin();aPosIter != aPosEnd;++aPosIter) { // look for columns not in the source columns to use them as filter as well // if ( !xSourceColumns->hasByName(aPosIter->first) ) @@ -459,7 +321,7 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O aFilter.append(aAnd); aFilter.append(::dbtools::quoteName( aQuote,sSelectTableName)); aFilter.append(s_sDot); - aFilter.append(::dbtools::quoteName( aQuote,aPosIter->first)); + aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sRealName)); aFilter.append(s_sParam); } } @@ -467,17 +329,40 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::O } } } // if ( aSeq.getLength() > 1 ) // special handling for join - - if ( i_sRowSetFilter.getLength() ) + executeStatement(aFilter,i_sRowSetFilter,xAnalyzer); +} +void OKeySet::executeStatement(::rtl::OUStringBuffer& io_aFilter,const ::rtl::OUString& i_sRowSetFilter,Reference& io_xAnalyzer) +{ + bool bFilterSet = i_sRowSetFilter.getLength() != 0; + if ( bFilterSet ) { FilterCreator aFilterCreator; aFilterCreator.append( i_sRowSetFilter ); - aFilterCreator.append( aFilter.makeStringAndClear() ); - aFilter = aFilterCreator.getComposedAndClear(); + aFilterCreator.append( io_aFilter.makeStringAndClear() ); + io_aFilter = aFilterCreator.getComposedAndClear(); } - xAnalyzer->setFilter(aFilter.makeStringAndClear()); - m_xStatement = m_xConnection->prepareStatement(xAnalyzer->getQueryWithSubstitution()); - ::comphelper::disposeComponent(xAnalyzer); + io_xAnalyzer->setFilter(io_aFilter.makeStringAndClear()); + if ( bFilterSet ) + { + Sequence< Sequence< PropertyValue > > aFilter2 = io_xAnalyzer->getStructuredFilter(); + const Sequence< PropertyValue >* pOr = aFilter2.getConstArray(); + const Sequence< PropertyValue >* pOrEnd = pOr + aFilter2.getLength(); + for(;pOr != pOrEnd;++pOr) + { + const PropertyValue* pAnd = pOr->getConstArray(); + const PropertyValue* pAndEnd = pAnd + pOr->getLength(); + for(;pAnd != pAndEnd;++pAnd) + { + ::rtl::OUString sValue; + if ( !(pAnd->Value >>= sValue) || !(sValue.equalsAscii("?") || sValue.matchAsciiL(":",1,0)) ) + { // we have a criteria which has to be taken into account for updates + m_aFilterColumns.push_back(pAnd->Name); + } + } + } + } + m_xStatement = m_xConnection->prepareStatement(io_xAnalyzer->getQueryWithSubstitution()); + ::comphelper::disposeComponent(io_xAnalyzer); } // ------------------------------------------------------------------------- Any SAL_CALL OKeySet::getBookmark() throw(SQLException, RuntimeException) @@ -560,7 +445,7 @@ Sequence< sal_Int32 > SAL_CALL OKeySet::deleteRows( const Sequence< Any >& rows SelectColumnsMetaData::const_iterator aPosEnd = (*m_pKeyColumnNames).end(); for(;aIter != aPosEnd;++aIter) { - aCondition.append(::dbtools::quoteName( aQuote,aIter->first)); + aCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); aCondition.append(aEqual); aCondition.append(aAnd); } @@ -665,7 +550,7 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow //if(xKeyColumns.is() && xKeyColumns->hasByName(aIter->first)) if ( m_pKeyColumnNames->find(aIter->first) != m_pKeyColumnNames->end() ) { - sKeyCondition.append(::dbtools::quoteName( aQuote,aIter->first)); + sKeyCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); if((_rOrginalRow->get())[aIter->second.nPosition].isNull()) sKeyCondition.append(sIsNull); else @@ -680,7 +565,7 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow { if((*aIndexIter)->hasByName(aIter->first)) { - sIndexCondition.append(::dbtools::quoteName( aQuote,aIter->first)); + sIndexCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); if((_rOrginalRow->get())[aIter->second.nPosition].isNull()) sIndexCondition.append(sIsNull); else @@ -695,7 +580,7 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow } if((_rInsertRow->get())[aIter->second.nPosition].isModified()) { - aSql.append(::dbtools::quoteName( aQuote,aIter->first)); + aSql.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); aSql.append(aPara); } } @@ -729,62 +614,74 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_CONDITION_FOR_PK ), SQL_GENERAL_ERROR, m_xConnection ); // now create end execute the prepared statement - Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(aSql.makeStringAndClear())); + + ::rtl::OUString sEmpty; + executeUpdate(_rInsertRow ,_rOrginalRow,aSql.makeStringAndClear(),sEmpty,aIndexColumnPositions); +} +// ----------------------------------------------------------------------------- +void OKeySet::executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,const ::std::vector& _aIndexColumnPositions) +{ + // now create end execute the prepared statement + Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(i_sSQL)); Reference< XParameters > xParameter(xPrep,UNO_QUERY); - i = 1; - // first the set values bool bRefetch = true; - aIter = m_pColumnNames->begin(); - sal_uInt16 j = 0; Reference xRow; + sal_Int32 i = 1; + // first the set values + SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); + SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); + sal_uInt16 j = 0; for(;aIter != aEnd;++aIter,++j) { - sal_Int32 nPos = aIter->second.nPosition; - if((_rInsertRow->get())[nPos].isModified()) + if ( !i_sTableName.getLength() || aIter->second.sTableName == i_sTableName ) { - if ( bRefetch ) + sal_Int32 nPos = aIter->second.nPosition; + if((_rInsertRow->get())[nPos].isModified()) { - bRefetch = ::std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),aIter->first) == m_aFilterColumns.end(); - if ( !bRefetch ) + if ( bRefetch ) { - xRow = new OPrivateRow(_rInsertRow->get()); + bRefetch = ::std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),aIter->second.sRealName) == m_aFilterColumns.end(); } + impl_convertValue_throw(_rInsertRow,aIter->second); + (_rInsertRow->get())[nPos].setSigned((_rOrginalRow->get())[nPos].isSigned()); + setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); } - - impl_convertValue_throw(_rInsertRow,aIter->second); - (_rInsertRow->get())[nPos].setSigned((_rOrginalRow->get())[nPos].isSigned()); - setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); } } // and then the values of the where condition - aIter = (*m_pKeyColumnNames).begin(); - aEnd = (*m_pKeyColumnNames).end(); + aIter = m_pKeyColumnNames->begin(); + aEnd = m_pKeyColumnNames->end(); j = 0; - for(;aIter != aEnd;++aIter,++i,++j) + for(;aIter != aEnd;++aIter,++j) { - setParameter(i,xParameter,(_rOrginalRow->get())[aIter->second.nPosition],aIter->second.nType,aIter->second.nScale); + if ( !i_sTableName.getLength() || aIter->second.sTableName == i_sTableName ) + { + setParameter(i++,xParameter,(_rOrginalRow->get())[aIter->second.nPosition],aIter->second.nType,aIter->second.nScale); + } } - - // now we have to set the index values - ::std::vector::iterator aIdxColIter = aIndexColumnPositions.begin(); - ::std::vector::iterator aIdxColEnd = aIndexColumnPositions.end(); - j = 0; - aIter = m_pColumnNames->begin(); - for(;aIdxColIter != aIdxColEnd;++aIdxColIter,++i,++j,++aIter) + if ( !_aIndexColumnPositions.empty() ) { - setParameter(i,xParameter,(_rOrginalRow->get())[*aIdxColIter],(_rOrginalRow->get())[*aIdxColIter].getTypeKind(),aIter->second.nScale); + // now we have to set the index values + ::std::vector::const_iterator aIdxColIter = _aIndexColumnPositions.begin(); + ::std::vector::const_iterator aIdxColEnd = _aIndexColumnPositions.end(); + j = 0; + aIter = m_pColumnNames->begin(); + for(;aIdxColIter != aIdxColEnd;++aIdxColIter,++i,++j,++aIter) + { + setParameter(i,xParameter,(_rOrginalRow->get())[*aIdxColIter],(_rOrginalRow->get())[*aIdxColIter].getTypeKind(),aIter->second.nScale); + } } - - m_bUpdated = xPrep->executeUpdate() > 0; + const sal_Int32 nRowsUpdated = xPrep->executeUpdate(); + m_bUpdated = nRowsUpdated > 0; if(m_bUpdated) { const sal_Int32 nBookmark = ::comphelper::getINT32((_rInsertRow->get())[0].getAny()); m_aKeyIter = m_aKeyMap.find(nBookmark); m_aKeyIter->second.second.first = 2; m_aKeyIter->second.second.second = xRow; - copyRowValue(_rInsertRow,m_aKeyIter->second.first,nBookmark); + tryRefetch(_rInsertRow,bRefetch); } } // ------------------------------------------------------------------------- @@ -806,12 +703,17 @@ void SAL_CALL OKeySet::insertRow( const ORowSetRow& _rInsertRow,const connectivi SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); sal_Int32 j = 1; + bool bRefetch = true; sal_Bool bModified = sal_False; for(;aIter != aEnd;++aIter,++j) { if((_rInsertRow->get())[aIter->second.nPosition].isModified()) { - aSql.append(::dbtools::quoteName( aQuote,aIter->first)); + if ( bRefetch ) + { + bRefetch = ::std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),aIter->second.sRealName) == m_aFilterColumns.end(); + } + aSql.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); aSql.append(aComma); aValues.append(aPara); bModified = sal_True; @@ -824,22 +726,33 @@ void SAL_CALL OKeySet::insertRow( const ORowSetRow& _rInsertRow,const connectivi aValues.setCharAt(aValues.getLength()-1,')'); aSql.append(aValues.makeStringAndClear()); // now create,fill and execute the prepared statement - Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(aSql.makeStringAndClear())); + ::rtl::OUString sEmpty; + executeInsert(_rInsertRow,aSql.makeStringAndClear(),sEmpty,bRefetch); +} +// ------------------------------------------------------------------------- +void OKeySet::executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,bool bRefetch ) +{ + // now create,fill and execute the prepared statement + Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(i_sSQL)); Reference< XParameters > xParameter(xPrep,UNO_QUERY); - aIter = m_pColumnNames->begin(); + SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); + SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); for(sal_Int32 i = 1;aIter != aEnd;++aIter) { - const sal_Int32 nPos = aIter->second.nPosition; - if((_rInsertRow->get())[nPos].isModified()) + if ( !i_sTableName.getLength() || aIter->second.sTableName == i_sTableName ) { - if((_rInsertRow->get())[nPos].isNull()) - xParameter->setNull(i++,(_rInsertRow->get())[nPos].getTypeKind()); - else + const sal_Int32 nPos = aIter->second.nPosition; + if((_rInsertRow->get())[nPos].isModified()) { - impl_convertValue_throw(_rInsertRow,aIter->second); - (_rInsertRow->get())[nPos].setSigned(m_aSignedFlags[nPos-1]); - setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); + if((_rInsertRow->get())[nPos].isNull()) + xParameter->setNull(i++,(_rInsertRow->get())[nPos].getTypeKind()); + else + { + impl_convertValue_throw(_rInsertRow,aIter->second); + (_rInsertRow->get())[nPos].setSigned(m_aSignedFlags[nPos-1]); + setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); + } } } } @@ -890,7 +803,7 @@ void SAL_CALL OKeySet::insertRow( const ORowSetRow& _rInsertRow,const connectivi ::comphelper::disposeComponent(xPrep); - if ( !bAutoValuesFetched && m_bInserted ) + if ( !i_sTableName.getLength() && !bAutoValuesFetched && m_bInserted ) { // first check if all key column values were set const ::rtl::OUString sMax(RTL_CONSTASCII_USTRINGPARAM(" MAX(")); @@ -947,13 +860,67 @@ void SAL_CALL OKeySet::insertRow( const ORowSetRow& _rInsertRow,const connectivi { OKeySetMatrix::iterator aKeyIter = m_aKeyMap.end(); --aKeyIter; - ORowSetRow aKeyRow = new connectivity::ORowVector< ORowSetValue >((*m_pKeyColumnNames).size()); + ORowSetRow aKeyRow = new connectivity::ORowVector< ORowSetValue >(m_pKeyColumnNames->size()); copyRowValue(_rInsertRow,aKeyRow,aKeyIter->first + 1); - m_aKeyIter = m_aKeyMap.insert(OKeySetMatrix::value_type(aKeyIter->first + 1,OKeySetValue(aKeyRow,::std::pair >(1,NULL)))).first; // now we set the bookmark for this row (_rInsertRow->get())[0] = makeAny((sal_Int32)m_aKeyIter->first); + tryRefetch(_rInsertRow,bRefetch); + } +} +void OKeySet::tryRefetch(const ORowSetRow& _rInsertRow,bool bRefetch) +{ + if ( bRefetch ) + { + // we just areassign the base members + try + { + Reference< XParameters > xParameter(m_xStatement,UNO_QUERY); + OSL_ENSURE(xParameter.is(),"No Parameter interface!"); + xParameter->clearParameters(); + + sal_Int32 nPos=1; + connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaIter; + connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaEnd; + OUpdatedParameter::iterator aUpdateFind = m_aUpdatedParameter.find(m_aKeyIter->first); + if ( aUpdateFind == m_aUpdatedParameter.end() ) + { + aParaIter = m_aParameterValueForCache.get().begin(); + aParaEnd = m_aParameterValueForCache.get().end(); + } + else + { + aParaIter = aUpdateFind->second.get().begin(); + aParaEnd = aUpdateFind->second.get().end(); + } + + for(++aParaIter;aParaIter != aParaEnd;++aParaIter,++nPos) + { + ::dbtools::setObjectWithInfo( xParameter, nPos, aParaIter->makeAny(), aParaIter->getTypeKind() ); + } + connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aIter2 = m_aKeyIter->second.first->get().begin(); + SelectColumnsMetaData::const_iterator aPosIter = (*m_pKeyColumnNames).begin(); + SelectColumnsMetaData::const_iterator aPosEnd = (*m_pKeyColumnNames).end(); + for(;aPosIter != aPosEnd;++aPosIter,++aIter2,++nPos) + setParameter(nPos,xParameter,*aIter2,aPosIter->second.nType,aPosIter->second.nScale); + aPosIter = (*m_pForeignColumnNames).begin(); + aPosEnd = (*m_pForeignColumnNames).end(); + for(;aPosIter != aPosEnd;++aPosIter,++aIter2,++nPos) + setParameter(nPos,xParameter,*aIter2,aPosIter->second.nType,aPosIter->second.nScale); + + m_xSet = m_xStatement->executeQuery(); + OSL_ENSURE(m_xSet.is(),"No resultset form statement!"); + bRefetch = m_xSet->next(); + } + catch(Exception) + { + bRefetch = false; + } + } + if ( !bRefetch ) + { + m_aKeyIter->second.second.second = new OPrivateRow(_rInsertRow->get()); } } // ----------------------------------------------------------------------------- @@ -992,6 +959,7 @@ void OKeySet::copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sa for(;aPosIter != aPosEnd;++aPosIter,++aIter) { *aIter = (_rInsertRow->get())[aPosIter->second.nPosition]; + impl_convertValue_throw(_rKeyRow,aPosIter->second); aIter->setTypeKind(aPosIter->second.nType); } } @@ -1033,7 +1001,7 @@ void SAL_CALL OKeySet::deleteRow(const ORowSetRow& _rDeleteRow,const connectivit { if ( m_pKeyColumnNames->find(aIter->first) != m_pKeyColumnNames->end() ) { - aSql.append(::dbtools::quoteName( aQuote,aIter->first)); + aSql.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); if((_rDeleteRow->get())[aIter->second.nPosition].isNull()) { OSL_ENSURE(0,"can a primary key be null"); @@ -1051,7 +1019,7 @@ void SAL_CALL OKeySet::deleteRow(const ORowSetRow& _rDeleteRow,const connectivit { if((*aIndexIter)->hasByName(aIter->first)) { - sIndexCondition.append(::dbtools::quoteName( aQuote,aIter->first)); + sIndexCondition.append(::dbtools::quoteName( aQuote,aIter->second.sRealName)); if((_rDeleteRow->get())[aIter->second.nPosition].isNull()) sIndexCondition.append(::rtl::OUString::createFromAscii(" IS NULL")); else @@ -1215,8 +1183,8 @@ void SAL_CALL OKeySet::beforeFirst( ) throw(SQLException, RuntimeException) RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::beforeFirst" ); m_bInserted = m_bUpdated = m_bDeleted = sal_False; m_aKeyIter = m_aKeyMap.begin(); - m_xSet = NULL; - ::comphelper::disposeComponent(m_xRow); + m_xRow = NULL; + ::comphelper::disposeComponent(m_xSet); } // ----------------------------------------------------------------------------- void SAL_CALL OKeySet::afterLast( ) throw(SQLException, RuntimeException) @@ -1225,8 +1193,8 @@ void SAL_CALL OKeySet::afterLast( ) throw(SQLException, RuntimeException) m_bInserted = m_bUpdated = m_bDeleted = sal_False; fillAllRows(); m_aKeyIter = m_aKeyMap.end(); - m_xSet = NULL; - ::comphelper::disposeComponent(m_xRow); + m_xRow = NULL; + ::comphelper::disposeComponent(m_xSet); } // ----------------------------------------------------------------------------- sal_Bool SAL_CALL OKeySet::first( ) throw(SQLException, RuntimeException) @@ -1330,8 +1298,14 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException) if(isBeforeFirst() || isAfterLast() || !m_xStatement.is()) return; - m_xSet = NULL; - ::comphelper::disposeComponent(m_xRow); + m_xRow = NULL; + ::comphelper::disposeComponent(m_xSet); + + if ( m_aKeyIter->second.second.second.is() ) + { + m_xRow = m_aKeyIter->second.second.second; + return; + } // we just areassign the base members Reference< XParameters > xParameter(m_xStatement,UNO_QUERY); OSL_ENSURE(xParameter.is(),"No Parameter interface!"); @@ -1342,8 +1316,7 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException) connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaEnd; OUpdatedParameter::iterator aUpdateFind = m_aUpdatedParameter.find(m_aKeyIter->first); if ( aUpdateFind == m_aUpdatedParameter.end() ) - { - + { aParaIter = m_aParameterValueForCache.get().begin(); aParaEnd = m_aParameterValueForCache.get().end(); } @@ -1357,6 +1330,8 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException) { ::dbtools::setObjectWithInfo( xParameter, nPos, aParaIter->makeAny(), aParaIter->getTypeKind() ); } + + // now set the primary key column values connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aIter = m_aKeyIter->second.first->get().begin(); SelectColumnsMetaData::const_iterator aPosIter = (*m_pKeyColumnNames).begin(); SelectColumnsMetaData::const_iterator aPosEnd = (*m_pKeyColumnNames).end(); diff --git a/dbaccess/source/core/api/KeySet.hxx b/dbaccess/source/core/api/KeySet.hxx index 947f8e161..ccd5cf0e6 100644 --- a/dbaccess/source/core/api/KeySet.hxx +++ b/dbaccess/source/core/api/KeySet.hxx @@ -35,14 +35,14 @@ #ifndef _CPPUHELPER_IMPLBASE1_HXX_ #include #endif +#include #include #ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ #include #endif -#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_ #include -#endif +#include #ifndef _COMPHELPER_STLTYPES_HXX_ #include #endif @@ -93,17 +93,18 @@ namespace dbaccess // is used when the source supports keys class OKeySet : public OCacheSet { + protected: OKeySetMatrix m_aKeyMap; OKeySetMatrix::iterator m_aKeyIter; - + ::std::vector< ::rtl::OUString > m_aAutoColumns; // contains all columns which are autoincrement ones OUpdatedParameter m_aUpdatedParameter; // contains all parameter which have been updated and are needed for refetching ORowSetValueVector m_aParameterValueForCache; - SelectColumnsMetaData* m_pKeyColumnNames; // contains all key column names - SelectColumnsMetaData* m_pColumnNames; // contains all column names - SelectColumnsMetaData* m_pParameterNames; // contains all parameter names - SelectColumnsMetaData* m_pForeignColumnNames; // contains all column names of the rest + ::std::auto_ptr m_pKeyColumnNames; // contains all key column names + ::std::auto_ptr m_pColumnNames; // contains all column names + ::std::auto_ptr m_pParameterNames; // contains all parameter names + ::std::auto_ptr m_pForeignColumnNames; // contains all column names of the rest connectivity::OSQLTable m_xTable; // reference to our table ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> m_xTableKeys; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement> m_xStatement; @@ -141,7 +142,16 @@ namespace dbaccess sal_Bool fetchRow(); void impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData); - protected: + void initColumns(); + void findTableColumnsMatching_throw( const ::com::sun::star::uno::Any& i_aTable + ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& i_xMeta + ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns); + ::rtl::OUStringBuffer createKeyFilter(); + void tryRefetch(const ORowSetRow& _rInsertRow,bool bRefetch); + void executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,const ::std::vector& _aIndexColumnPositions = ::std::vector()); + void executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName = ::rtl::OUString(),bool bRefetch = false); + void executeStatement(::rtl::OUStringBuffer& io_aFilter,const ::rtl::OUString& i_sRowSetFilter,::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer>& io_xAnalyzer); + virtual ~OKeySet(); public: OKeySet(const connectivity::OSQLTable& _xTable, diff --git a/dbaccess/source/core/api/OptimisticSet.cxx b/dbaccess/source/core/api/OptimisticSet.cxx index 3495b2e55..b68910d0f 100644 --- a/dbaccess/source/core/api/OptimisticSet.cxx +++ b/dbaccess/source/core/api/OptimisticSet.cxx @@ -84,23 +84,6 @@ using namespace ::osl; DECLARE_STL_USTRINGACCESS_MAP(::rtl::OUStringBuffer,TSQLStatements); namespace { - void lcl_fillIndexColumns(const Reference& _xIndexes, ::std::vector< Reference >& _rAllIndexColumns) - { - if ( _xIndexes.is() ) - { - Reference xIndexColsSup; - sal_Int32 nCount = _xIndexes->getCount(); - for(sal_Int32 j = 0 ; j < nCount ; ++j) - { - xIndexColsSup.set(_xIndexes->getByIndex(j),UNO_QUERY); - if( xIndexColsSup.is() - && comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISUNIQUE)) - && !comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISPRIMARYKEYINDEX)) - ) - _rAllIndexColumns.push_back(Reference(xIndexColsSup,UNO_QUERY)->getColumns()); - } - } - } void lcl_fillKeyCondition(const ::rtl::OUString& i_sTableName,const ::rtl::OUString& i_sQuotedColumnName,const ORowSetValue& i_aValue,TSQLStatements& io_aKeyConditions) { ::rtl::OUStringBuffer& rKeyCondition = io_aKeyConditions[i_sTableName]; @@ -120,14 +103,9 @@ OptimisticSet::OptimisticSet(const ::comphelper::ComponentContext& _rContext, const Reference< XConnection>& i_xConnection, const Reference< XSingleSelectQueryAnalyzer >& _xComposer, const ORowSetValueVector& _aParameterValueForCache) - :m_aSqlParser( _rContext.getLegacyServiceFactory() ) + :OKeySet(NULL,NULL,::rtl::OUString(),_xComposer,_aParameterValueForCache) + ,m_aSqlParser( _rContext.getLegacyServiceFactory() ) ,m_aSqlIterator( i_xConnection, Reference(_xComposer,UNO_QUERY)->getTables(), m_aSqlParser, NULL ) - ,m_aParameterValueForCache(_aParameterValueForCache) - ,m_pKeyColumnNames(NULL) - ,m_pColumnNames(NULL) - ,m_pParameterNames(NULL) - ,m_xComposer(_xComposer) - ,m_bRowCountFinal(sal_False) ,m_bResultSetChanged(false) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::OptimisticSet" ); @@ -136,20 +114,6 @@ OptimisticSet::OptimisticSet(const ::comphelper::ComponentContext& _rContext, // ----------------------------------------------------------------------------- OptimisticSet::~OptimisticSet() { - try - { - ::comphelper::disposeComponent(m_xStatement); - } - catch(Exception&) - { - m_xStatement.clear(); - } - catch(...) - { - OSL_ENSURE(0,"Unknown Exception occured"); - } - m_xComposer.clear(); - DBG_DTOR(OptimisticSet,NULL); } // ----------------------------------------------------------------------------- @@ -157,14 +121,9 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::construct" ); OCacheSet::construct(_xDriverSet,i_sRowSetFilter); + initColumns(); Reference xMeta = m_xConnection->getMetaData(); - bool bCase = (xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers()) ? true : false; - - m_pKeyColumnNames.reset( new SelectColumnsMetaData(bCase) ); - m_pColumnNames.reset( new SelectColumnsMetaData(bCase) ); - m_pParameterNames.reset( new SelectColumnsMetaData(bCase) ); - Reference xQueryColSup(m_xComposer,UNO_QUERY); const Reference xQueryColumns = xQueryColSup->getColumns(); const Reference xTabSup(m_xComposer,UNO_QUERY); @@ -182,29 +141,13 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: m_aKeyMap.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL,::std::pair >(0,NULL)))); m_aKeyIter = m_aKeyMap.begin(); - static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND "); - const ::rtl::OUString aQuote = getIdentifierQuoteString(); - ::rtl::OUStringBuffer aFilter; - static ::rtl::OUString s_sDot(RTL_CONSTASCII_USTRINGPARAM(".")); - static ::rtl::OUString s_sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); - // create the where clause - SelectColumnsMetaData::iterator aPosEnd = m_pKeyColumnNames->end(); - for(SelectColumnsMetaData::iterator aPosIter = m_pKeyColumnNames->begin();aPosIter != aPosEnd;) - { - aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sTableName)); - aFilter.append(s_sDot); - aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sRealName)); - aFilter.append(s_sParam); - ++aPosIter; - if(aPosIter != aPosEnd) - aFilter.append(aAnd); - } + ::rtl::OUStringBuffer aFilter = createKeyFilter(); + Reference< XSingleSelectQueryComposer> xSourceComposer(m_xComposer,UNO_QUERY); Reference< XMultiServiceFactory > xFactory(m_xConnection, UNO_QUERY_THROW); Reference xAnalyzer(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY); - Reference xComp2(m_xComposer,UNO_QUERY_THROW); - ::rtl::OUString sQuery = xComp2->getQuery(); - xAnalyzer->setQuery(sQuery); + ::rtl::OUString sQuery = xSourceComposer->getQuery(); + xAnalyzer->setElementaryQuery(xSourceComposer->getElementaryQuery()); // check for joins ::rtl::OUString aErrorMsg; ::std::auto_ptr pStatementNode( m_aSqlParser.parseTree( aErrorMsg, sQuery ) ); @@ -227,58 +170,6 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: ::comphelper::disposeComponent(xAnalyzer); } // ------------------------------------------------------------------------- -Any SAL_CALL OptimisticSet::getBookmark() throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getBookmark" ); - OSL_ENSURE(m_aKeyIter != m_aKeyMap.end() && m_aKeyIter != m_aKeyMap.begin(), - "getBookmark is only possible when we stand on a valid row!"); - return makeAny(m_aKeyIter->first); -} - -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::moveToBookmark" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - m_aKeyIter = m_aKeyMap.find(::comphelper::getINT32(bookmark)); - return m_aKeyIter != m_aKeyMap.end(); -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::moveRelativeToBookmark" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - m_aKeyIter = m_aKeyMap.find(::comphelper::getINT32(bookmark)); - if(m_aKeyIter != m_aKeyMap.end()) - { - relative(rows); - } - - return !isBeforeFirst() && !isAfterLast(); -} -// ------------------------------------------------------------------------- -sal_Int32 SAL_CALL OptimisticSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::compareBookmarks" ); - sal_Int32 nFirst = 0, nSecond = 0; - _first >>= nFirst; - _second >>= nSecond; - - return (nFirst != nSecond) ? CompareBookmark::NOT_EQUAL : CompareBookmark::EQUAL; -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::hasOrderedBookmarks" ); - return sal_True; -} -// ------------------------------------------------------------------------- -sal_Int32 SAL_CALL OptimisticSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::hashBookmark" ); - return ::comphelper::getINT32(bookmark); -} -// ------------------------------------------------------------------------- // ::com::sun::star::sdbcx::XDeleteRows Sequence< sal_Int32 > SAL_CALL OptimisticSet::deleteRows( const Sequence< Any >& /*rows*/ ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException) { @@ -485,202 +376,6 @@ void SAL_CALL OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const conn } } // ------------------------------------------------------------------------- -void OptimisticSet::executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName ) -{ - // now create,fill and execute the prepared statement - Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(i_sSQL)); - Reference< XParameters > xParameter(xPrep,UNO_QUERY); - - SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); - SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); - for(sal_Int32 i = 1;aIter != aEnd;++aIter) - { - if ( aIter->second.sTableName == i_sTableName ) - { - const sal_Int32 nPos = aIter->second.nPosition; - if((_rInsertRow->get())[nPos].isModified()) - { - if((_rInsertRow->get())[nPos].isNull()) - xParameter->setNull(i++,(_rInsertRow->get())[nPos].getTypeKind()); - else - { - impl_convertValue_throw(_rInsertRow,aIter->second); - (_rInsertRow->get())[nPos].setSigned(m_aSignedFlags[nPos-1]); - setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); - } - } - } - } - - m_bInserted = xPrep->executeUpdate() > 0; - sal_Bool bAutoValuesFetched = sal_False; - if ( m_bInserted ) - { - // first insert the default values into the insertrow - aIter = m_pColumnNames->begin(); - for(;aIter != aEnd;++aIter) - { - if ( !(_rInsertRow->get())[aIter->second.nPosition].isModified() ) - (_rInsertRow->get())[aIter->second.nPosition] = aIter->second.sDefaultValue; - } - try - { - Reference< XGeneratedResultSet > xGRes(xPrep, UNO_QUERY); - if ( xGRes.is() ) - { - Reference< XResultSet > xRes = xGRes->getGeneratedValues(); - Reference< XRow > xRow(xRes,UNO_QUERY); - if ( xRow.is() && xRes->next() ) - { - Reference< XResultSetMetaDataSupplier > xMdSup(xRes,UNO_QUERY); - Reference< XResultSetMetaData > xMd = xMdSup->getMetaData(); - sal_Int32 nColumnCount = xMd->getColumnCount(); - ::std::vector< ::rtl::OUString >::iterator aAutoIter = m_aAutoColumns.begin(); - ::std::vector< ::rtl::OUString >::iterator aAutoEnd = m_aAutoColumns.end(); - for (sal_Int32 i = 1;aAutoIter != aAutoEnd && i <= nColumnCount; ++aAutoIter,++i) - { -#if OSL_DEBUG_LEVEL > 1 - ::rtl::OUString sColumnName( xMd->getColumnName(i) ); -#endif - SelectColumnsMetaData::iterator aFind = m_pKeyColumnNames->find(*aAutoIter); - if ( aFind != m_pKeyColumnNames->end() ) - (_rInsertRow->get())[aFind->second.nPosition].fill(i,aFind->second.nType,aFind->second.bNullable,xRow); - } - bAutoValuesFetched = sal_True; - } - } - } - catch(Exception&) - { - OSL_ENSURE(0,"Could not execute GeneratedKeys() stmt"); - } - } - - ::comphelper::disposeComponent(xPrep); -/* - if ( !bAutoValuesFetched && m_bInserted ) - { - // first check if all key column values were set - const ::rtl::OUString sMax(RTL_CONSTASCII_USTRINGPARAM(" MAX(")); - const ::rtl::OUString sMaxEnd(RTL_CONSTASCII_USTRINGPARAM("),")); - const ::rtl::OUString sQuote = getIdentifierQuoteString(); - ::rtl::OUString sMaxStmt; - aEnd = m_pKeyColumnNames->end(); - ::std::vector< ::rtl::OUString >::iterator aAutoIter = m_aAutoColumns.begin(); - ::std::vector< ::rtl::OUString >::iterator aAutoEnd = m_aAutoColumns.end(); - for (;aAutoIter != aAutoEnd; ++aAutoIter) - { - // we will only fetch values which are keycolumns - if ( m_pKeyColumnNames->find(*aAutoIter) != aEnd ) - { - sMaxStmt += sMax; - sMaxStmt += ::dbtools::quoteName( sQuote,*aAutoIter); - sMaxStmt += sMaxEnd; - } - } - - if(sMaxStmt.getLength()) - { - sMaxStmt = sMaxStmt.replaceAt(sMaxStmt.getLength()-1,1,::rtl::OUString::createFromAscii(" ")); - ::rtl::OUString sStmt = ::rtl::OUString::createFromAscii("SELECT "); - sStmt += sMaxStmt; - sStmt += ::rtl::OUString::createFromAscii("FROM "); - sStmt += m_aSelectComposedTableName; - try - { - // now fetch the autoincrement values - Reference xStatement = m_xConnection->createStatement(); - Reference xRes = xStatement->executeQuery(sStmt); - Reference xRow(xRes,UNO_QUERY); - if(xRow.is() && xRes->next()) - { - aAutoIter = m_aAutoColumns.begin(); - for (sal_Int32 i=1;aAutoIter != aAutoEnd; ++aAutoIter,++i) - { - // we will only fetch values which are keycolumns - SelectColumnsMetaData::iterator aFind = m_pKeyColumnNames->find(*aAutoIter); - if ( aFind != aEnd ) - (_rInsertRow->get())[aFind->second.nPosition].fill(i,aFind->second.nType,aFind->second.bNullable,xRow); - } - } - ::comphelper::disposeComponent(xStatement); - } - catch(SQLException&) - { - OSL_ENSURE(0,"Could not fetch with MAX() "); - } - } - } - */ - if ( m_bInserted ) - { - OKeySetMatrix::iterator aKeyIter = m_aKeyMap.end(); - --aKeyIter; - ORowSetRow aKeyRow = new connectivity::ORowVector< ORowSetValue >(m_pKeyColumnNames->size()); - copyRowValue(_rInsertRow,aKeyRow,aKeyIter->first + 1); - - m_aKeyIter = m_aKeyMap.insert(OKeySetMatrix::value_type(aKeyIter->first + 1,OKeySetValue(aKeyRow,::std::pair >(1,NULL)))).first; - // now we set the bookmark for this row - (_rInsertRow->get())[0] = makeAny((sal_Int32)m_aKeyIter->first); - } -} -// ----------------------------------------------------------------------------- -void OptimisticSet::copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sal_Int32 i_nBookmark) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::copyRowValue" ); - connectivity::ORowVector< ORowSetValue >::Vector::iterator aIter = _rKeyRow->get().begin(); - - // check the if the parameter values have been changed - OSL_ENSURE((m_aParameterValueForCache.get().size()-1) == m_pParameterNames->size(),"OptimisticSet::copyRowValue: Parameter values and names differ!"); - connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaValuesIter = m_aParameterValueForCache.get().begin() +1; - - bool bChanged = false; - SelectColumnsMetaData::const_iterator aParaIter = (*m_pParameterNames).begin(); - SelectColumnsMetaData::const_iterator aParaEnd = (*m_pParameterNames).end(); - for(sal_Int32 i = 1;aParaIter != aParaEnd;++aParaIter,++aParaValuesIter,++i) - { - ORowSetValue aValue(*aParaValuesIter); - aValue.setSigned(m_aSignedFlags[aParaIter->second.nPosition]); - if ( (_rInsertRow->get())[aParaIter->second.nPosition] != aValue ) - { - ORowSetValueVector aCopy(m_aParameterValueForCache); - (aCopy.get())[i] = (_rInsertRow->get())[aParaIter->second.nPosition]; - m_aUpdatedParameter[i_nBookmark] = aCopy; - bChanged = true; - } - } - if ( !bChanged ) - { - m_aUpdatedParameter.erase(i_nBookmark); - } - - // update the key values - SelectColumnsMetaData::const_iterator aPosIter = m_pKeyColumnNames->begin(); - SelectColumnsMetaData::const_iterator aPosEnd = m_pKeyColumnNames->end(); - for(;aPosIter != aPosEnd;++aPosIter,++aIter) - { - ORowSetValue aValue((_rInsertRow->get())[aPosIter->second.nPosition]); - switch(aPosIter->second.nType) - { - case DataType::DECIMAL: - case DataType::NUMERIC: - { - ::rtl::OUString sValue = aValue.getString(); - sal_Int32 nIndex = sValue.indexOf('.'); - if ( nIndex != -1 ) - { - aValue = sValue.copy(0,nIndex + (aPosIter->second.nScale > 0 ? aPosIter->second.nScale + 1 : 0)); - } - } - break; - default: - break; - } - *aIter = aValue; - aIter->setTypeKind(aPosIter->second.nType); - } -} -// ------------------------------------------------------------------------- void SAL_CALL OptimisticSet::deleteRow(const ORowSetRow& _rDeleteRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) { ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); @@ -754,432 +449,6 @@ void OptimisticSet::executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUS m_bDeleted = sal_True; } } -// ------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::cancelRowUpdates" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; -} -// ------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::moveToInsertRow( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::moveToInsertRow" ); -} -// ------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::moveToCurrentRow" ); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::next( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::next" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - - if(isAfterLast()) - return sal_False; - if(!m_bRowCountFinal) // not yet all records fetched - { - ++m_aKeyIter; // this is possible because we stand on begin() and this is the "beforefirst" row - if(m_aKeyIter == m_aKeyMap.end() && !fetchRow()) - m_aKeyIter = m_aKeyMap.end(); - } - else if(!isAfterLast()) - ++m_aKeyIter; - - refreshRow(); - return !isAfterLast(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::isBeforeFirst( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::isBeforeFirst" ); - return m_aKeyIter == m_aKeyMap.begin(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::isAfterLast( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::isAfterLast" ); - return m_bRowCountFinal && m_aKeyIter == m_aKeyMap.end(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::isFirst( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::isFirst" ); - OKeySetMatrix::iterator aTemp = m_aKeyMap.begin(); - ++aTemp; - return m_aKeyIter == aTemp && m_aKeyIter != m_aKeyMap.end(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::isLast( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::isLast" ); - if(!m_bRowCountFinal) - return sal_False; - - OKeySetMatrix::iterator aTemp = m_aKeyMap.end(); - --aTemp; - return m_aKeyIter == aTemp; -} -// ----------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::beforeFirst( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::beforeFirst" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - m_aKeyIter = m_aKeyMap.begin(); - m_xSet = NULL; - ::comphelper::disposeComponent(m_xRow); -} -// ----------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::afterLast( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::afterLast" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - fillAllRows(); - m_aKeyIter = m_aKeyMap.end(); - m_xSet = NULL; - ::comphelper::disposeComponent(m_xRow); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::first( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::first" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - m_aKeyIter = m_aKeyMap.begin(); - ++m_aKeyIter; - if(m_aKeyIter == m_aKeyMap.end() && !fetchRow()) - m_aKeyIter = m_aKeyMap.end(); - - refreshRow(); - return m_aKeyIter != m_aKeyMap.end() && m_aKeyIter != m_aKeyMap.begin(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::last( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::last" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - fillAllRows(); - - m_aKeyIter = m_aKeyMap.end(); - --m_aKeyIter; - refreshRow(); - return m_aKeyIter != m_aKeyMap.end() && m_aKeyIter != m_aKeyMap.begin(); -} -// ----------------------------------------------------------------------------- -sal_Int32 SAL_CALL OptimisticSet::getRow( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getRow" ); - OSL_ENSURE(!isAfterLast(),"getRow is not allowed when afterlast record!"); - OSL_ENSURE(!isBeforeFirst(),"getRow is not allowed when beforefirst record!"); - - return ::std::distance(m_aKeyMap.begin(),m_aKeyIter); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::absolute" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - OSL_ENSURE(row,"absolute(0) isn't allowed!"); - if(row < 0) - { - if(!m_bRowCountFinal) - fillAllRows(); - - for(;row < 0 && m_aKeyIter != m_aKeyMap.begin();++row) - m_aKeyIter--; - } - else - { - if(row >= (sal_Int32)m_aKeyMap.size()) - { - if(!m_bRowCountFinal) - { - sal_Bool bNext = sal_True; - for(sal_Int32 i=m_aKeyMap.size()-1;i < row && bNext;++i) - bNext = fetchRow(); - } - else - m_aKeyIter = m_aKeyMap.end(); - } - else - { - m_aKeyIter = m_aKeyMap.begin(); - for(;row > 0 && m_aKeyIter != m_aKeyMap.end();--row) - ++m_aKeyIter; - } - } - refreshRow(); - - return m_aKeyIter != m_aKeyMap.end() && m_aKeyIter != m_aKeyMap.begin(); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::relative( sal_Int32 rows ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::relative" ); - if(!rows) - { - refreshRow(); - return sal_True; - } - return absolute(getRow()+rows); -} -// ----------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::previous( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::previous" ); - m_bInserted = m_bUpdated = m_bDeleted = sal_False; - if(m_aKeyIter != m_aKeyMap.begin()) - { - --m_aKeyIter; - refreshRow(); - } - return m_aKeyIter != m_aKeyMap.begin(); -} -// ----------------------------------------------------------------------------- -void SAL_CALL OptimisticSet::refreshRow() throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::refreshRow" ); - if(isBeforeFirst() || isAfterLast() || !m_xStatement.is()) - return; - - m_xSet.clear(); - ::comphelper::disposeComponent(m_xRow); - // we just reassign the base members - Reference< XParameters > xParameter(m_xStatement,UNO_QUERY); - OSL_ENSURE(xParameter.is(),"No Parameter interface!"); - xParameter->clearParameters(); - - sal_Int32 nPos=1; - connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaIter; - connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaEnd; - OUpdatedParameter::iterator aUpdateFind = m_aUpdatedParameter.find(m_aKeyIter->first); - if ( aUpdateFind == m_aUpdatedParameter.end() ) - { - aParaIter = m_aParameterValueForCache.get().begin(); - aParaEnd = m_aParameterValueForCache.get().end(); - } - else - { - aParaIter = aUpdateFind->second.get().begin(); - aParaEnd = aUpdateFind->second.get().end(); - } - - // first put the parameters set by the outer rowset - for(++aParaIter;aParaIter != aParaEnd;++aParaIter,++nPos) - { - ::dbtools::setObjectWithInfo( xParameter, nPos, aParaIter->makeAny(), aParaIter->getTypeKind() ); - } - - // now set the primary key column values - connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aIter = m_aKeyIter->second.first->get().begin(); - SelectColumnsMetaData::const_iterator aPosIter = m_pKeyColumnNames->begin(); - SelectColumnsMetaData::const_iterator aPosEnd = m_pKeyColumnNames->end(); - for(;aPosIter != aPosEnd;++aPosIter,++aIter,++nPos) - setParameter(nPos,xParameter,*aIter,aPosIter->second.nType,aPosIter->second.nScale); - - m_xSet = m_xStatement->executeQuery(); - OSL_ENSURE(m_xSet.is(),"No resultset form statement!"); - sal_Bool bOK = m_xSet->next(); - if ( !bOK ) - m_aKeyIter = m_aKeyMap.end(); - m_xRow.set(m_xSet,UNO_QUERY); - OSL_ENSURE(m_xRow.is(),"No row form statement!"); -} -// ----------------------------------------------------------------------------- -sal_Bool OptimisticSet::fetchRow() -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::fetchRow" ); - // fetch the next row and append on the OptimisticSet - sal_Bool bRet = sal_False; - if ( !m_bRowCountFinal ) - bRet = m_xDriverSet->next(); - if ( bRet ) - { - ORowSetRow aKeyRow = new connectivity::ORowVector< ORowSetValue >(m_pKeyColumnNames->size()); - connectivity::ORowVector< ORowSetValue >::Vector::iterator aIter = aKeyRow->get().begin(); - // first fetch the values needed for the key column - SelectColumnsMetaData::const_iterator aPosIter = m_pKeyColumnNames->begin(); - SelectColumnsMetaData::const_iterator aPosEnd = m_pKeyColumnNames->end(); - for(;aPosIter != aPosEnd;++aPosIter,++aIter) - { - const SelectColumnDescription& rColDesc = aPosIter->second; - aIter->fill(rColDesc.nPosition,rColDesc.nType,rColDesc.bNullable,m_xDriverRow); - } - m_aKeyIter = m_aKeyMap.insert(OKeySetMatrix::value_type(m_aKeyMap.rbegin()->first+1,OKeySetValue(aKeyRow,::std::pair >(0,NULL)))).first; - } - else - m_bRowCountFinal = sal_True; - return bRet; -} -// ------------------------------------------------------------------------- -void OptimisticSet::fillAllRows() -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::fillAllRows" ); - if(!m_bRowCountFinal) - { - while(fetchRow()) - ; - } -} -// XRow -sal_Bool SAL_CALL OptimisticSet::wasNull( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::wasNull" ); - return m_xRow->wasNull(); -} -// ------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OptimisticSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getString" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getString(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getBoolean" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getBoolean(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Int8 SAL_CALL OptimisticSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getByte" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getByte(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Int16 SAL_CALL OptimisticSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getShort" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getShort(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Int32 SAL_CALL OptimisticSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getInt" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getInt(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Int64 SAL_CALL OptimisticSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getLong" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getLong(columnIndex); -} -// ------------------------------------------------------------------------- -float SAL_CALL OptimisticSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getFloat" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getFloat(columnIndex); -} -// ------------------------------------------------------------------------- -double SAL_CALL OptimisticSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getDouble" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getDouble(columnIndex); -} -// ------------------------------------------------------------------------- -Sequence< sal_Int8 > SAL_CALL OptimisticSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getBytes" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getBytes(columnIndex); -} -// ------------------------------------------------------------------------- -::com::sun::star::util::Date SAL_CALL OptimisticSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getDate" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getDate(columnIndex); -} -// ------------------------------------------------------------------------- -::com::sun::star::util::Time SAL_CALL OptimisticSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getTime" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getTime(columnIndex); -} -// ------------------------------------------------------------------------- -::com::sun::star::util::DateTime SAL_CALL OptimisticSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getTimestamp" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getTimestamp(columnIndex); -} -// ------------------------------------------------------------------------- -Reference< ::com::sun::star::io::XInputStream > SAL_CALL OptimisticSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getBinaryStream" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getBinaryStream(columnIndex); -} -// ------------------------------------------------------------------------- -Reference< ::com::sun::star::io::XInputStream > SAL_CALL OptimisticSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getCharacterStream" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getCharacterStream(columnIndex); -} -// ------------------------------------------------------------------------- -Any SAL_CALL OptimisticSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getObject" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getObject(columnIndex,typeMap); -} -// ------------------------------------------------------------------------- -Reference< XRef > SAL_CALL OptimisticSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getRef" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getRef(columnIndex); -} -// ------------------------------------------------------------------------- -Reference< XBlob > SAL_CALL OptimisticSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getBlob" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getBlob(columnIndex); -} -// ------------------------------------------------------------------------- -Reference< XClob > SAL_CALL OptimisticSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getClob" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getClob(columnIndex); -} -// ------------------------------------------------------------------------- -Reference< XArray > SAL_CALL OptimisticSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::getArray" ); - OSL_ENSURE(m_xRow.is(),"m_xRow is null!"); - return m_xRow->getArray(columnIndex); -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::rowUpdated( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::rowUpdated" ); - return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second.first == 2; -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::rowInserted( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::rowInserted" ); - return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second.first == 1; -} -// ------------------------------------------------------------------------- -sal_Bool SAL_CALL OptimisticSet::rowDeleted( ) throw(SQLException, RuntimeException) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::rowDeleted" ); - sal_Bool bDeleted = m_bDeleted; - m_bDeleted = sal_False; - return bDeleted; -} // ----------------------------------------------------------------------------- ::rtl::OUString OptimisticSet::getComposedTableName(const ::rtl::OUString& /*_sCatalog*/, const ::rtl::OUString& /*_sSchema*/, @@ -1215,201 +484,6 @@ sal_Bool SAL_CALL OptimisticSet::rowDeleted( ) throw(SQLException, RuntimeExcep return aComposedName; } // ----------------------------------------------------------------------------- -/* -namespace dbaccess -{ - void getColumnPositions(const Reference& _rxQueryColumns, - const Sequence< ::rtl::OUString>& _aColumnNames, - const ::rtl::OUString& _rsUpdateTableName, - SelectColumnsMetaData& _rColumnNames) - { - // get the real name of the columns - Sequence< ::rtl::OUString> aSelNames(_rxQueryColumns->getElementNames()); - const ::rtl::OUString* pSelBegin = aSelNames.getConstArray(); - const ::rtl::OUString* pSelEnd = pSelBegin + aSelNames.getLength(); - - const ::rtl::OUString* pColumnIter = _aColumnNames.getConstArray(); - const ::rtl::OUString* pColumnEnd = pColumnIter + _aColumnNames.getLength(); - - ::comphelper::UStringMixLess aTmp(_rColumnNames.key_comp()); - ::comphelper::UStringMixEqual bCase(static_cast< ::comphelper::UStringMixLess*>(&aTmp)->isCaseSensitive()); - - for(sal_Int32 nPos = 1;pSelBegin != pSelEnd;++pSelBegin,++nPos) - { - Reference xColumnProp(_rxQueryColumns->getByName(*pSelBegin),UNO_QUERY); - ::rtl::OUString sRealName,sTableName; - OSL_ENSURE(xColumnProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME),"Property REALNAME not available!"); - OSL_ENSURE(xColumnProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_TABLENAME),"Property TABLENAME not available!"); - xColumnProp->getPropertyValue(PROPERTY_REALNAME) >>= sRealName; - xColumnProp->getPropertyValue(PROPERTY_TABLENAME) >>= sTableName; - - for(;pColumnIter != pColumnEnd;++pColumnIter) - { - if(bCase(sRealName,*pColumnIter) && bCase(_rsUpdateTableName,sTableName) && _rColumnNames.find(*pColumnIter) == _rColumnNames.end()) - { - sal_Int32 nType = 0; - xColumnProp->getPropertyValue(PROPERTY_TYPE) >>= nType; - sal_Int32 nScale = 0; - xColumnProp->getPropertyValue(PROPERTY_SCALE) >>= nScale; - ::rtl::OUString sColumnDefault; - if ( xColumnProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_DEFAULTVALUE) ) - xColumnProp->getPropertyValue(PROPERTY_DEFAULTVALUE) >>= sColumnDefault; - - sal_Int32 bNullable = sal_False; - xColumnProp->getPropertyValue(PROPERTY_ISNULLABLE) >>= bNullable; - - - _rColumnNames[sRealName] = SelectColumnDescription( nPos, nType,nScale,bNullable != sdbc::ColumnValue::NO_NULLS, sColumnDefault ); - break; - } - } - pColumnIter = _aColumnNames.getConstArray(); - } - } -} -*/ -// ----------------------------------------------------------------------------- -void OptimisticSet::impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData) -{ - ORowSetValue& aValue((_rInsertRow->get())[i_aMetaData.nPosition]); - switch(i_aMetaData.nType) - { - case DataType::DECIMAL: - case DataType::NUMERIC: - { - ::rtl::OUString sValue = aValue.getString(); - sal_Int32 nIndex = sValue.indexOf('.'); - if ( nIndex != -1 ) - { - aValue = sValue.copy(0,nIndex + (i_aMetaData.nScale > 0 ? i_aMetaData.nScale + 1 : 0)); - } - } - break; - default: - break; - } -} -// ----------------------------------------------------------------------------- -void OptimisticSet::findTableColumnsMatching_throw(const Any& i_aTable - ,const Reference& i_xMeta - ,const Reference& i_xQueryColumns) -{ - ::rtl::OUString sCatalog,sSchema,sTable; - Reference xTableProp(i_aTable,UNO_QUERY); - Any aCatalog = xTableProp->getPropertyValue(PROPERTY_CATALOGNAME); - aCatalog >>= sCatalog; - xTableProp->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema; - xTableProp->getPropertyValue(PROPERTY_NAME) >>= sTable; - - // first ask the database itself for the best columns which can be used - ::std::vector< ::rtl::OUString> aBestRowColumnNames; - /* - Reference xBestRes(i_xMeta->getBestRowIdentifier(aCatalog,sSchema,sTable,0,sal_False)); - Reference xBestRow(xBestRes,uno::UNO_QUERY); - while ( xBestRes->next() ) - { - aBestRowColumnNames.push_back(xBestRow->getString(2)); - } - */ - Sequence< ::rtl::OUString> aBestColumnNames; - if ( aBestRowColumnNames.empty() ) - { - Reference xKeyColumns = getPrimaryKeyColumns_throw(i_aTable); - if ( xKeyColumns.is() ) - aBestColumnNames = xKeyColumns->getElementNames(); - } - else - aBestColumnNames = Sequence< ::rtl::OUString>(&aBestRowColumnNames[0],aBestRowColumnNames.size()); - - const Reference xTblColSup(i_aTable,UNO_QUERY_THROW); - const Reference xTblColumns = xTblColSup->getColumns(); - const ::rtl::OUString sComposedUpdateTableName = dbtools::composeTableName( i_xMeta, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ); - ::dbaccess::getColumnPositions(i_xQueryColumns,aBestColumnNames,sComposedUpdateTableName,(*m_pKeyColumnNames),true); - ::dbaccess::getColumnPositions(i_xQueryColumns,xTblColumns->getElementNames(),sComposedUpdateTableName,(*m_pColumnNames),true); - - // locate parameter in select columns - Reference xParaSup(m_xComposer,UNO_QUERY); - Reference xQueryParameters = xParaSup->getParameters(); - const sal_Int32 nParaCount = xQueryParameters->getCount(); - Sequence< ::rtl::OUString> aParameterColumns(nParaCount); - for(sal_Int32 i = 0; i< nParaCount;++i) - { - Reference xPara(xQueryParameters->getByIndex(i),UNO_QUERY_THROW); - xPara->getPropertyValue(PROPERTY_REALNAME) >>= aParameterColumns[i]; - } - ::dbaccess::getColumnPositions(i_xQueryColumns,aParameterColumns,sComposedUpdateTableName,(*m_pParameterNames),true); - - SelectColumnsMetaData::const_iterator aPosIter = m_pKeyColumnNames->begin(); - SelectColumnsMetaData::const_iterator aPosEnd = m_pKeyColumnNames->end(); - for(;aPosIter != aPosEnd;++aPosIter) - { - if ( xTblColumns->hasByName(aPosIter->second.sRealName) ) - { - Reference xProp(xTblColumns->getByName(aPosIter->second.sRealName),UNO_QUERY); - sal_Bool bAuto = sal_False; - if( (xProp->getPropertyValue(PROPERTY_ISAUTOINCREMENT) >>= bAuto) && bAuto) - m_aAutoColumns.push_back(aPosIter->first); - } - } -} -// ----------------------------------------------------------------------------- -void OptimisticSet::executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName) -{ - // now create end execute the prepared statement - Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(i_sSQL)); - Reference< XParameters > xParameter(xPrep,UNO_QUERY); - - sal_Int32 i = 1; - // first the set values - SelectColumnsMetaData::const_iterator aIter = m_pColumnNames->begin(); - SelectColumnsMetaData::const_iterator aEnd = m_pColumnNames->end(); - sal_uInt16 j = 0; - for(;aIter != aEnd;++aIter,++j) - { - if ( aIter->second.sTableName == i_sTableName ) - { - sal_Int32 nPos = aIter->second.nPosition; - if((_rInsertRow->get())[nPos].isModified()) - { - impl_convertValue_throw(_rInsertRow,aIter->second); - (_rInsertRow->get())[nPos].setSigned((_rOrginalRow->get())[nPos].isSigned()); - setParameter(i++,xParameter,(_rInsertRow->get())[nPos],aIter->second.nType,aIter->second.nScale); - } - } - } - // and then the values of the where condition - aIter = m_pKeyColumnNames->begin(); - aEnd = m_pKeyColumnNames->end(); - j = 0; - for(;aIter != aEnd;++aIter,++j) - { - if ( aIter->second.sTableName == i_sTableName ) - { - setParameter(i++,xParameter,(_rOrginalRow->get())[aIter->second.nPosition],aIter->second.nType,aIter->second.nScale); - } - } -/* - // now we have to set the index values - ::std::vector::iterator aIdxColIter = aIndexColumnPositions.begin(); - ::std::vector::iterator aIdxColEnd = aIndexColumnPositions.end(); - j = 0; - aIter = m_pColumnNames->begin(); - for(;aIdxColIter != aIdxColEnd;++aIdxColIter,++i,++j,++aIter) - { - setParameter(i,xParameter,(_rOrginalRow->get())[*aIdxColIter],(_rOrginalRow->get())[*aIdxColIter].getTypeKind(),aIter->second.nScale); - } -*/ - const sal_Int32 nRowsUpdated = xPrep->executeUpdate(); - m_bUpdated = nRowsUpdated > 0; - if(m_bUpdated) - { - const sal_Int32 nBookmark = ::comphelper::getINT32((_rInsertRow->get())[0].getAny()); - m_aKeyIter = m_aKeyMap.find(nBookmark); - m_aKeyIter->second.second.first = 2; - copyRowValue(_rInsertRow,m_aKeyIter->second.first,nBookmark); - } -} -// ----------------------------------------------------------------------------- void OptimisticSet::fillJoinedColumns_throw(const ::std::vector< TNodePair >& i_aJoinColumns) { ::std::vector< TNodePair >::const_iterator aIter = i_aJoinColumns.begin(); diff --git a/dbaccess/source/core/api/OptimisticSet.hxx b/dbaccess/source/core/api/OptimisticSet.hxx index 1f42bebdf..fd1b304a7 100644 --- a/dbaccess/source/core/api/OptimisticSet.hxx +++ b/dbaccess/source/core/api/OptimisticSet.hxx @@ -31,11 +31,9 @@ #ifndef DBACCESS_CORE_API_OPTIMISTICSET_HXX #define DBACCESS_CORE_API_OPTIMISTICSET_HXX -#include "CacheSet.hxx" #include "KeySet.hxx" #include -#include -#include + #include #include @@ -47,29 +45,15 @@ namespace dbaccess { // is used when the source supports keys - class OptimisticSet : public OCacheSet + class OptimisticSet : public OKeySet { ::connectivity::OSQLParser m_aSqlParser; ::connectivity::OSQLParseTreeIterator m_aSqlIterator; - OKeySetMatrix m_aKeyMap; - OKeySetMatrix::iterator m_aKeyIter; - ::std::vector< ::rtl::OUString > m_aAutoColumns; // contains all columns which are autoincrement ones ::std::map m_aJoinedColumns; - ::std::map m_aJoinedKeyColumns; - - OUpdatedParameter m_aUpdatedParameter; // contains all parameter which have been updated and are needed for refetching - ORowSetValueVector m_aParameterValueForCache; - ::std::auto_ptr m_pKeyColumnNames; // contains all key column names - ::std::auto_ptr m_pColumnNames; // contains all column names - ::std::auto_ptr m_pParameterNames; // contains all parameter names - connectivity::OSQLTable m_xTable; // reference to our table - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement> m_xStatement; - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> m_xSet; - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> m_xRow; - ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer; + ::std::map m_aJoinedKeyColumns; + - sal_Bool m_bRowCountFinal; mutable bool m_bResultSetChanged; /** @@ -83,24 +67,9 @@ namespace dbaccess ::rtl::OUString getComposedTableName( const ::rtl::OUString& _sCatalog, const ::rtl::OUString& _sSchema, const ::rtl::OUString& _sTable); - - /** copies the values from the insert row into the key row - * - * \param _rInsertRow the row which was inserted - * \param _rKeyRow The current key row of the row set. - + \param i_nBookmark The bookmark is used to update the parameter - */ - void copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sal_Int32 i_nBookmark); - - void fillAllRows(); - sal_Bool fetchRow(); - + void impl_convertValue_throw(const ORowSetRow& _rInsertRow,const SelectColumnDescription& i_aMetaData); - void findTableColumnsMatching_throw( const ::com::sun::star::uno::Any& i_aTable - ,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& i_xMeta - ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns); - void executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName); - void executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName); + void executeDelete(const ORowSetRow& _rDeleteRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName); void fillJoinedColumns_throw(const ::std::vector< ::connectivity::TNodePair>& i_aJoinColumns); void fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn); @@ -115,59 +84,6 @@ namespace dbaccess // late ctor which can throw exceptions virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter); - // ::com::sun::star::sdbc::XRow - virtual sal_Bool SAL_CALL wasNull( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - - - virtual sal_Bool SAL_CALL rowUpdated( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL rowInserted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL rowDeleted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ::com::sun::star::sdbc::XResultSet - virtual sal_Bool SAL_CALL next( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isBeforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isAfterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL beforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL afterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL first( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL last( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL getRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL previous( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL refreshRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ::com::sun::star::sdbcx::XRowLocate - virtual ::com::sun::star::uno::Any SAL_CALL getBookmark() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ------------------------------------------------------------------------- - virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ------------------------------------------------------------------------- - virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ------------------------------------------------------------------------- - virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ------------------------------------------------------------------------- - virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - // ------------------------------------------------------------------------- - virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // ------------------------------------------------------------------------- // ::com::sun::star::sdbcx::XDeleteRows virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows ,const connectivity::OSQLTable& _xTable) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); @@ -175,9 +91,6 @@ namespace dbaccess virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // CacheSet virtual bool isResultSetChanged() const; diff --git a/dbaccess/source/core/api/makefile.mk b/dbaccess/source/core/api/makefile.mk index 7af260080..9a4dc9d8e 100644 --- a/dbaccess/source/core/api/makefile.mk +++ b/dbaccess/source/core/api/makefile.mk @@ -73,6 +73,7 @@ SLOFILES= \ $(SLO)$/View.obj \ $(SLO)$/WrappedResultSet.obj \ $(SLO)$/OptimisticSet.obj \ + $(SLO)$/PrivateRow.obj \ $(SLO)$/columnsettings.obj # --- Targets ---------------------------------- -- cgit v1.2.3 From 7711863af2903f7e5410abdeff6f081d7585de1f Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 8 Jul 2010 12:22:36 +0200 Subject: dba33g: #i111205# handle filter for key and update and insert row --- dbaccess/source/core/api/PrivateRow.cxx | 141 ++++++++++++++++++++++++++++++++ dbaccess/source/core/api/PrivateRow.hxx | 69 ++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 dbaccess/source/core/api/PrivateRow.cxx create mode 100644 dbaccess/source/core/api/PrivateRow.hxx diff --git a/dbaccess/source/core/api/PrivateRow.cxx b/dbaccess/source/core/api/PrivateRow.cxx new file mode 100644 index 000000000..3f8e3aa27 --- /dev/null +++ b/dbaccess/source/core/api/PrivateRow.cxx @@ -0,0 +1,141 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle andor its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_dbaccess.hxx" +#include "PrivateRow.hxx" + +using namespace dbaccess; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::util; +using namespace ::com::sun::star; + +::sal_Bool SAL_CALL OPrivateRow::wasNull( ) throw (SQLException, RuntimeException) + { + return m_aRow[m_nPos].isNull(); + } + ::rtl::OUString SAL_CALL OPrivateRow::getString( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::sal_Bool SAL_CALL OPrivateRow::getBoolean( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::sal_Int8 SAL_CALL OPrivateRow::getByte( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::sal_Int16 SAL_CALL OPrivateRow::getShort( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::sal_Int32 SAL_CALL OPrivateRow::getInt( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::sal_Int64 SAL_CALL OPrivateRow::getLong( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + float SAL_CALL OPrivateRow::getFloat( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + double SAL_CALL OPrivateRow::getDouble( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + Sequence< ::sal_Int8 > SAL_CALL OPrivateRow::getBytes( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::com::sun::star::util::Date SAL_CALL OPrivateRow::getDate( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::com::sun::star::util::Time SAL_CALL OPrivateRow::getTime( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + ::com::sun::star::util::DateTime SAL_CALL OPrivateRow::getTimestamp( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos]; + } + Reference< ::com::sun::star::io::XInputStream > SAL_CALL OPrivateRow::getBinaryStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< ::com::sun::star::io::XInputStream >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } + Reference< ::com::sun::star::io::XInputStream > SAL_CALL OPrivateRow::getCharacterStream( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< ::com::sun::star::io::XInputStream >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } + Any SAL_CALL OPrivateRow::getObject( ::sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return m_aRow[m_nPos].makeAny(); + } + Reference< XRef > SAL_CALL OPrivateRow::getRef( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< XRef >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } + Reference< XBlob > SAL_CALL OPrivateRow::getBlob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< XBlob >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } + Reference< XClob > SAL_CALL OPrivateRow::getClob( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< XClob >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } + Reference< XArray > SAL_CALL OPrivateRow::getArray( ::sal_Int32 columnIndex ) throw (SQLException, RuntimeException) + { + m_nPos = columnIndex; + return Reference< XArray >(m_aRow[m_nPos].makeAny(),UNO_QUERY); + } \ No newline at end of file diff --git a/dbaccess/source/core/api/PrivateRow.hxx b/dbaccess/source/core/api/PrivateRow.hxx new file mode 100644 index 000000000..aabcb0d4a --- /dev/null +++ b/dbaccess/source/core/api/PrivateRow.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: OptimisticSet.cxx,v $ + * $Revision: 1.73 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef PRIVATE_ROW_HXX +#define PRIVATE_ROW_HXX + +#include +#include +#include "RowSetRow.hxx" + +namespace dbaccess +{ + class OPrivateRow : public ::cppu::WeakImplHelper1< ::com::sun::star::sdbc::XRow> + { + ORowSetValueVector::Vector m_aRow; + sal_Int32 m_nPos; + public: + OPrivateRow(const ORowSetValueVector::Vector& i_aRow) : m_aRow(i_aRow),m_nPos(0) + { + } + virtual ::sal_Bool SAL_CALL wasNull( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getString( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getBoolean( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int8 SAL_CALL getByte( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL getShort( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getInt( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int64 SAL_CALL getLong( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual float SAL_CALL getFloat( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getDouble( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL getBytes( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::util::Date SAL_CALL getDate( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::util::Time SAL_CALL getTime( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Any SAL_CALL getObject( ::sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( ::sal_Int32 columnIndex ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + }; +} // dbaccess +#endif // PRIVATE_ROW_HXX -- cgit v1.2.3 From f14fd48792162934514527f60a7d0e8e55f9f3e2 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 8 Jul 2010 13:22:49 +0200 Subject: dba33g: #i109528# remove clipboard listener --- reportdesign/source/ui/report/ReportController.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx index 020990af9..051c5b39b 100644 --- a/reportdesign/source/ui/report/ReportController.cxx +++ b/reportdesign/source/ui/report/ReportController.cxx @@ -333,7 +333,7 @@ IMPLEMENT_FORWARD_XINTERFACE2(OReportController,OReportController_BASE,OReportCo void OReportController::disposing() { - if ( getView() && m_pClipbordNotifier ) + if ( m_pClipbordNotifier ) { m_pClipbordNotifier->ClearCallbackLink(); m_pClipbordNotifier->AddRemoveListener( getView(), sal_False ); -- cgit v1.2.3 From 3299b5654699fc7bc460e6683c8598c1686f8d07 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 8 Jul 2010 14:32:56 +0200 Subject: dba33g: #i111142# handle insertrow corrected --- dbaccess/source/ui/inc/TableController.hxx | 2 +- dbaccess/source/ui/tabledesign/TEditControl.cxx | 3 --- dbaccess/source/ui/tabledesign/TableController.cxx | 15 +++++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dbaccess/source/ui/inc/TableController.hxx b/dbaccess/source/ui/inc/TableController.hxx index 19e6a07dd..6aeb1415e 100644 --- a/dbaccess/source/ui/inc/TableController.hxx +++ b/dbaccess/source/ui/inc/TableController.hxx @@ -135,7 +135,7 @@ namespace dbaui inline ::std::vector< ::boost::shared_ptr >* getRows() { return &m_vRowList; } /// returns the postion of the the first empty row - sal_Int32 getFirstEmptyRowPosition() const; + sal_Int32 getFirstEmptyRowPosition(); inline const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo; } diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx index 9169bf643..69fe58bd4 100644 --- a/dbaccess/source/ui/tabledesign/TEditControl.cxx +++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx @@ -134,9 +134,6 @@ DBG_NAME(OTableEditorCtrl) #define HANDLE_ID 0 -// Anzahl Spalten beim Neuanlegen -#define NEWCOLS 128 - // default Spaltenbreiten #define FIELDNAME_WIDTH 100 #define FIELDTYPE_WIDTH 150 diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index 05b72dc89..180019a8e 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -108,6 +108,9 @@ using namespace ::dbtools; using namespace ::dbaui; using namespace ::comphelper; +// Anzahl Spalten beim Neuanlegen +#define NEWCOLS 128 + namespace { void dropTable(const Reference& _rxTable,const ::rtl::OUString& _sTableName) @@ -958,7 +961,7 @@ void OTableController::loadData() OSL_ENSURE(aTypeIter != m_aTypeInfo.end(),"We have no type infomation!"); bool bReadRow = !isAddAllowed(); - for(sal_Int32 i=m_vRowList.size(); i<128; i++ ) + for(sal_Int32 i=m_vRowList.size(); i < NEWCOLS; i++ ) { pTabEdRow.reset(new OTableRow()); pTabEdRow->SetReadOnly(bReadRow); @@ -1579,7 +1582,7 @@ void OTableController::reload() static_cast(getView())->Invalidate(); } // ----------------------------------------------------------------------------- -sal_Int32 OTableController::getFirstEmptyRowPosition() const +sal_Int32 OTableController::getFirstEmptyRowPosition() { sal_Int32 nRet = -1; ::std::vector< ::boost::shared_ptr >::const_iterator aIter = m_vRowList.begin(); @@ -1592,6 +1595,14 @@ sal_Int32 OTableController::getFirstEmptyRowPosition() const break; } } + if ( nRet == -1 ) + { + bool bReadRow = !isAddAllowed(); + ::boost::shared_ptr pTabEdRow(new OTableRow()); + pTabEdRow->SetReadOnly(bReadRow); + nRet = m_vRowList.size(); + m_vRowList.push_back( pTabEdRow); + } return nRet; } // ----------------------------------------------------------------------------- -- cgit v1.2.3 From deeec03ee2f0ad8802543cdebc770d031913ac51 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Fri, 9 Jul 2010 14:49:18 +0200 Subject: dba33g: #i112213# handle chart import for columns --- dbaccess/source/core/api/RowSetCache.cxx | 23 ++++++++++----- dbaccess/source/core/inc/DatabaseDataProvider.hxx | 2 +- dbaccess/source/core/misc/DatabaseDataProvider.cxx | 34 ++++++++++++++++++---- .../source/filter/xml/xmlExportDocumentHandler.cxx | 2 ++ .../source/filter/xml/xmlImportDocumentHandler.cxx | 14 ++++++++- 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index 8716a2132..d42c8d20f 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -158,14 +158,21 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, try { Reference< XResultSetUpdate> xUp(_xRs,UNO_QUERY_THROW); - xUp->moveToInsertRow(); - xUp->cancelRowUpdates(); - _xRs->beforeFirst(); - m_nPrivileges = Privilege::SELECT|Privilege::DELETE|Privilege::INSERT|Privilege::UPDATE; - m_pCacheSet = new WrappedResultSet(); - m_xCacheSet = m_pCacheSet; - m_pCacheSet->construct(_xRs,i_sRowSetFilter); - return; + Reference< XPropertySet> xProp(_xRs,UNO_QUERY); + Reference< XPropertySetInfo > xPropInfo = xProp->getPropertySetInfo(); + sal_Bool bBookmarkable = xPropInfo->hasPropertyByName(PROPERTY_ISBOOKMARKABLE) && + any2bool(xProp->getPropertyValue(PROPERTY_ISBOOKMARKABLE)) && Reference< XRowLocate >(_xRs, UNO_QUERY).is(); + if ( bBookmarkable ) + { + xUp->moveToInsertRow(); + xUp->cancelRowUpdates(); + _xRs->beforeFirst(); + m_nPrivileges = Privilege::SELECT|Privilege::DELETE|Privilege::INSERT|Privilege::UPDATE; + m_pCacheSet = new WrappedResultSet(); + m_xCacheSet = m_pCacheSet; + m_pCacheSet->construct(_xRs,i_sRowSetFilter); + return; + } } catch(const Exception& ex) { diff --git a/dbaccess/source/core/inc/DatabaseDataProvider.hxx b/dbaccess/source/core/inc/DatabaseDataProvider.hxx index c29b487f2..ade231e50 100644 --- a/dbaccess/source/core/inc/DatabaseDataProvider.hxx +++ b/dbaccess/source/core/inc/DatabaseDataProvider.hxx @@ -201,7 +201,7 @@ private: void impl_fillRowSet_throw(); void impl_executeRowSet_throw(::osl::ResettableMutexGuard& _rClearForNotifies); bool impl_fillParameters_nothrow( ::osl::ResettableMutexGuard& _rClearForNotifies); - void impl_fillInternalDataProvider_throw(sal_Bool _bHasCategories); + void impl_fillInternalDataProvider_throw(sal_Bool _bHasCategories,const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > >& i_aColumnNames); void impl_invalidateParameter_nothrow(); ::com::sun::star::uno::Any impl_getNumberFormatKey_nothrow(const ::rtl::OUString & _sRangeRepresentation) const; diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx index ec6f6cbb9..261a4e9ae 100644 --- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx +++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx @@ -204,6 +204,7 @@ uno::Reference< chart2::data::XDataSource > SAL_CALL DatabaseDataProvider::creat if ( createDataSourcePossible(_aArguments) ) { sal_Bool bHasCategories = sal_True; + uno::Sequence< uno::Sequence< ::rtl::OUString > > aColumnNames; const beans::PropertyValue* pArgIter = _aArguments.getConstArray(); const beans::PropertyValue* pArgEnd = pArgIter + _aArguments.getLength(); for(;pArgIter != pArgEnd;++pArgIter) @@ -211,7 +212,11 @@ uno::Reference< chart2::data::XDataSource > SAL_CALL DatabaseDataProvider::creat if ( pArgIter->Name.equalsAscii("HasCategories") ) { pArgIter->Value >>= bHasCategories; - break; + + } + else if ( pArgIter->Name.equalsAscii("ComplexColumnDescriptions") ) + { + pArgIter->Value >>= aColumnNames; } } bool bRet = false; @@ -221,7 +226,7 @@ uno::Reference< chart2::data::XDataSource > SAL_CALL DatabaseDataProvider::creat { impl_fillRowSet_throw(); impl_executeRowSet_throw(aClearForNotifies); - impl_fillInternalDataProvider_throw(bHasCategories); + impl_fillInternalDataProvider_throw(bHasCategories,aColumnNames); bRet = true; } catch(const uno::Exception& /*e*/) @@ -574,7 +579,7 @@ void DatabaseDataProvider::impl_executeRowSet_throw(::osl::ResettableMutexGuard& m_xRowSet->execute(); } // ----------------------------------------------------------------------------- -void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCategories) +void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCategories,const uno::Sequence< uno::Sequence< ::rtl::OUString > >& i_aColumnNames) { // clear the data before fill the new one uno::Reference< chart::XChartDataArray> xChartData(m_xInternal,uno::UNO_QUERY); @@ -586,11 +591,30 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCat m_xInternal->deleteSequence(0); } - uno::Sequence< ::rtl::OUString > aColumns; uno::Reference< sdbcx::XColumnsSupplier> xColSup(m_xRowSet,uno::UNO_QUERY_THROW); uno::Reference< container::XNameAccess > xColumns = xColSup->getColumns(); - if ( xColumns.is() ) + uno::Sequence< ::rtl::OUString > aColumns; + if ( i_aColumnNames.getLength() ) + { + if ( _bHasCategories ) + { + aColumns.realloc(1); + aColumns[0] = xColumns->getElementNames()[0]; + } + for(sal_Int32 i = 0 ; i < i_aColumnNames.getLength();++i) + { + if ( i_aColumnNames[i].getLength() ) + { + sal_Int32 nCount = aColumns.getLength(); + aColumns.realloc(nCount+1); + aColumns[nCount] = i_aColumnNames[i][0]; + } + } + } + else + { aColumns = xColumns->getElementNames(); + } // fill the data uno::Reference< sdbc::XResultSet> xRes(m_xRowSet,uno::UNO_QUERY_THROW); uno::Reference< sdbc::XRow> xRow(m_xRowSet,uno::UNO_QUERY_THROW); diff --git a/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx b/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx index 4132beac1..29f8857df 100644 --- a/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx +++ b/reportdesign/source/filter/xml/xmlExportDocumentHandler.cxx @@ -289,7 +289,9 @@ void SAL_CALL ExportDocumentHandler::endElement(const ::rtl::OUString & _sName) void SAL_CALL ExportDocumentHandler::characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException) { if ( !(m_bTableRowsStarted || m_bFirstRowExported) ) + { m_xDelegatee->characters(aChars); + } else if ( m_bExportChar ) { static const ::rtl::OUString s_sZero(RTL_CONSTASCII_USTRINGPARAM("0")); diff --git a/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx index c7b48b23d..ef79ec3ee 100644 --- a/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx +++ b/reportdesign/source/filter/xml/xmlImportDocumentHandler.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,6 @@ void SAL_CALL ImportDocumentHandler::endDocument() throw (uno::RuntimeException, uno::Reference< chart2::data::XDataReceiver > xReceiver(m_xModel,uno::UNO_QUERY_THROW); if ( xReceiver.is() ) { - xReceiver->attachDataProvider(m_xDatabaseDataProvider.get()); // this fills the chart again uno::Sequence< beans::PropertyValue > aArgs( 4 ); aArgs[0] = beans::PropertyValue( @@ -137,6 +137,18 @@ void SAL_CALL ImportDocumentHandler::endDocument() throw (uno::RuntimeException, aArgs[3] = beans::PropertyValue( ::rtl::OUString::createFromAscii("DataRowSource"), -1, uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE ); + + uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(m_xModel->getDataProvider(),uno::UNO_QUERY); + if ( xDataProvider.is() ) + { + aArgs.realloc(5); + uno::Sequence< uno::Sequence< ::rtl::OUString > > aColumnNames = xDataProvider->getComplexColumnDescriptions(); + aArgs[4] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("ComplexColumnDescriptions"), -1, + uno::makeAny( aColumnNames ), beans::PropertyState_DIRECT_VALUE ); + } + xReceiver->attachDataProvider(m_xDatabaseDataProvider.get()); + xReceiver->setArguments( aArgs ); } } -- cgit v1.2.3 From bc441374d53a5ffcb1d4c17372d9102e08043dd9 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Mon, 12 Jul 2010 11:41:11 +0200 Subject: dba33g: add missing eol --- dbaccess/source/core/api/PrivateRow.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbaccess/source/core/api/PrivateRow.cxx b/dbaccess/source/core/api/PrivateRow.cxx index 3f8e3aa27..2d3baedc4 100644 --- a/dbaccess/source/core/api/PrivateRow.cxx +++ b/dbaccess/source/core/api/PrivateRow.cxx @@ -138,4 +138,5 @@ using namespace ::com::sun::star; { m_nPos = columnIndex; return Reference< XArray >(m_aRow[m_nPos].makeAny(),UNO_QUERY); - } \ No newline at end of file + } + -- cgit v1.2.3 From 9efddbd159431900a65ce80671079b101a70feb3 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Mon, 12 Jul 2010 14:15:15 +0200 Subject: dba33g: #i112213# handle chart import for columns --- dbaccess/source/core/misc/DatabaseDataProvider.cxx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dbaccess/source/core/misc/DatabaseDataProvider.cxx b/dbaccess/source/core/misc/DatabaseDataProvider.cxx index 261a4e9ae..1b4ea8f4d 100644 --- a/dbaccess/source/core/misc/DatabaseDataProvider.cxx +++ b/dbaccess/source/core/misc/DatabaseDataProvider.cxx @@ -596,11 +596,8 @@ void DatabaseDataProvider::impl_fillInternalDataProvider_throw(sal_Bool _bHasCat uno::Sequence< ::rtl::OUString > aColumns; if ( i_aColumnNames.getLength() ) { - if ( _bHasCategories ) - { - aColumns.realloc(1); - aColumns[0] = xColumns->getElementNames()[0]; - } + aColumns.realloc(1); + aColumns[0] = xColumns->getElementNames()[0]; for(sal_Int32 i = 0 ; i < i_aColumnNames.getLength();++i) { if ( i_aColumnNames[i].getLength() ) -- cgit v1.2.3 From d81b33b449c6a23c88a65c21675174dd1b6795e7 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 14 Jul 2010 09:39:49 +0200 Subject: dba33g: handle bookmark corrected after insertrow --- dbaccess/source/core/api/WrappedResultSet.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbaccess/source/core/api/WrappedResultSet.cxx b/dbaccess/source/core/api/WrappedResultSet.cxx index d56765186..0b9c6b6c2 100644 --- a/dbaccess/source/core/api/WrappedResultSet.cxx +++ b/dbaccess/source/core/api/WrappedResultSet.cxx @@ -126,7 +126,7 @@ void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const c updateColumn(i,m_xUpdRow,*aIter); } m_xUpd->insertRow(); - (*_rInsertRow->get().begin()) = m_xDriverSet->getRow(); + (*_rInsertRow->get().begin()) = getBookmark(); } // ------------------------------------------------------------------------- void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) @@ -164,6 +164,7 @@ void SAL_CALL WrappedResultSet::moveToInsertRow( ) throw(SQLException, RuntimeE void SAL_CALL WrappedResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToCurrentRow" ); + m_xUpd->moveToCurrentRow(); } // ------------------------------------------------------------------------- void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition) -- cgit v1.2.3 From b59d086009693935d6ec5e1a3b9660e2abb72fe6 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 14 Jul 2010 14:32:48 +0200 Subject: dba33g: #i112668# add missing word not --- dbaccess/source/core/resource/strings.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbaccess/source/core/resource/strings.src b/dbaccess/source/core/resource/strings.src index bd20da391..a95366b25 100644 --- a/dbaccess/source/core/resource/strings.src +++ b/dbaccess/source/core/resource/strings.src @@ -273,7 +273,7 @@ String RID_STR_ROW_ALREADY_DELETED }; String RID_STR_UPDATE_FAILED { - Text [ en-US ] = "Current row could be updated."; + Text [ en-US ] = "Current row could not be updated."; }; //------------------------------------------------------------------------- String RID_STR_NO_INSERT_PRIVILEGE -- cgit v1.2.3 From 4c44989f24d51d75a942caf1039c71e0aa5cf943 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 14 Jul 2010 15:35:41 +0200 Subject: dba33g: #i112668# reverting --- dbaccess/source/core/resource/strings.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbaccess/source/core/resource/strings.src b/dbaccess/source/core/resource/strings.src index a95366b25..bd20da391 100644 --- a/dbaccess/source/core/resource/strings.src +++ b/dbaccess/source/core/resource/strings.src @@ -273,7 +273,7 @@ String RID_STR_ROW_ALREADY_DELETED }; String RID_STR_UPDATE_FAILED { - Text [ en-US ] = "Current row could not be updated."; + Text [ en-US ] = "Current row could be updated."; }; //------------------------------------------------------------------------- String RID_STR_NO_INSERT_PRIVILEGE -- cgit v1.2.3 From ae3cbff10499ab91c8c0a27889e85a5f5e8c4f69 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 14 Jul 2010 16:14:58 +0200 Subject: dba33g: #i112503# wae fix --- dbaccess/source/ui/misc/TokenWriter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbaccess/source/ui/misc/TokenWriter.cxx b/dbaccess/source/ui/misc/TokenWriter.cxx index b97321980..cd6b84604 100644 --- a/dbaccess/source/ui/misc/TokenWriter.cxx +++ b/dbaccess/source/ui/misc/TokenWriter.cxx @@ -100,7 +100,7 @@ ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor& const Reference< XMultiServiceFactory >& _rM, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF, const String& rExchange) - :m_bBookmarkSelection( NULL ) + :m_bBookmarkSelection( sal_False ) ,m_xFormatter(_rxNumberF) ,m_xFactory(_rM) ,m_nCommandType(CommandType::TABLE) -- cgit v1.2.3 From e32369e92d2ed7cdb3e1f4fe3ff1062822432190 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Tue, 20 Jul 2010 09:24:45 +0200 Subject: dba33g: second version of bBookmarkSelection corrected --- dbaccess/source/ui/misc/TokenWriter.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbaccess/source/ui/misc/TokenWriter.cxx b/dbaccess/source/ui/misc/TokenWriter.cxx index cd6b84604..6de15f1ce 100644 --- a/dbaccess/source/ui/misc/TokenWriter.cxx +++ b/dbaccess/source/ui/misc/TokenWriter.cxx @@ -131,7 +131,7 @@ ODatabaseImportExport::ODatabaseImportExport(const ::svx::ODataAccessDescriptor& // import data ODatabaseImportExport::ODatabaseImportExport( const ::dbtools::SharedConnection& _rxConnection, const Reference< XNumberFormatter >& _rxNumberF, const Reference< XMultiServiceFactory >& _rM ) - :m_bBookmarkSelection( NULL ) + :m_bBookmarkSelection( sal_False ) ,m_xConnection(_rxConnection) ,m_xFormatter(_rxNumberF) ,m_xFactory(_rM) -- cgit v1.2.3 From 046ed77b63f5b317ecce88dfc2213e8e7d6536ca Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Tue, 20 Jul 2010 10:45:17 +0200 Subject: dba33g: #i111205# quote tablename --- dbaccess/source/core/api/KeySet.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx index a312d05b1..3de3133bc 100644 --- a/dbaccess/source/core/api/KeySet.cxx +++ b/dbaccess/source/core/api/KeySet.cxx @@ -253,10 +253,11 @@ void OKeySet::findTableColumnsMatching_throw(const Any& i_aTable static ::rtl::OUString s_sDot(RTL_CONSTASCII_USTRINGPARAM(".")); static ::rtl::OUString s_sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?")); // create the where clause + Reference xMeta = m_xConnection->getMetaData(); SelectColumnsMetaData::iterator aPosEnd = m_pKeyColumnNames->end(); for(SelectColumnsMetaData::iterator aPosIter = m_pKeyColumnNames->begin();aPosIter != aPosEnd;) { - aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sTableName)); + aFilter.append(::dbtools::quoteTableName( xMeta,aPosIter->second.sTableName,::dbtools::eInDataManipulation)); aFilter.append(s_sDot); aFilter.append(::dbtools::quoteName( aQuote,aPosIter->second.sRealName)); aFilter.append(s_sParam); -- cgit v1.2.3