diff options
author | sb <sb@openoffice.org> | 2010-04-21 22:01:20 +0200 |
---|---|---|
committer | sb <sb@openoffice.org> | 2010-04-21 22:01:20 +0200 |
commit | 5d861c007999bbcc85ede771424a9fb8bd1e3e27 (patch) | |
tree | 802fe3347cbaa38459b998aef6bcb5fc1791df9e /dbaccess | |
parent | fa2c17c251f6448ddaf05470aface20f78cdf2cd (diff) | |
parent | f09e3e9714d6b3dd29f90dc8412702a6157edbf4 (diff) |
sb120: merged in DEV300_m77
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/qa/complex/dbaccess/RowSet.java | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/BookmarkSet.cxx | 4 | ||||
-rw-r--r-- | dbaccess/source/core/api/BookmarkSet.hxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/CacheSet.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/CacheSet.hxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/KeySet.cxx | 264 | ||||
-rw-r--r-- | dbaccess/source/core/api/KeySet.hxx | 15 | ||||
-rw-r--r-- | dbaccess/source/core/api/RowSet.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/RowSetCache.cxx | 14 | ||||
-rw-r--r-- | dbaccess/source/core/api/RowSetCache.hxx | 3 | ||||
-rw-r--r-- | dbaccess/source/core/api/SingleSelectQueryComposer.cxx | 28 | ||||
-rw-r--r-- | dbaccess/source/ui/control/tabletree.cxx | 56 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/WCopyTable.cxx | 3 |
13 files changed, 314 insertions, 83 deletions
diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index d03abe90d59c..5a13f6724d1f 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -977,7 +977,7 @@ public class RowSet extends ComplexTestCase } catch (Exception e) { - assure("could not text the relationship between XParameters and XParametersSupplier" + e.getMessage(), false); + assure("could not test the relationship between XParameters and XParametersSupplier" + e.getMessage(), false); } } diff --git a/dbaccess/source/core/api/BookmarkSet.cxx b/dbaccess/source/core/api/BookmarkSet.cxx index e71a5187db64..b5b9ec0ec787 100644 --- a/dbaccess/source/core/api/BookmarkSet.cxx +++ b/dbaccess/source/core/api/BookmarkSet.cxx @@ -59,10 +59,10 @@ using namespace ::com::sun::star::lang; // using namespace ::cppu; using namespace ::osl; -void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet) +void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" ); - OCacheSet::construct(_xDriverSet); + OCacheSet::construct(_xDriverSet,i_sRowSetFilter); m_xRowLocate.set(_xDriverSet,UNO_QUERY); } // ----------------------------------------------------------------------------- diff --git a/dbaccess/source/core/api/BookmarkSet.hxx b/dbaccess/source/core/api/BookmarkSet.hxx index c7beff64dbde..36d3c90c7969 100644 --- a/dbaccess/source/core/api/BookmarkSet.hxx +++ b/dbaccess/source/core/api/BookmarkSet.hxx @@ -51,7 +51,7 @@ namespace dbaccess m_xRowLocate = NULL; } - virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet); + virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter); virtual void fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition); // ::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); diff --git a/dbaccess/source/core/api/CacheSet.cxx b/dbaccess/source/core/api/CacheSet.cxx index b541bb7fd6fa..bedd873adc83 100644 --- a/dbaccess/source/core/api/CacheSet.cxx +++ b/dbaccess/source/core/api/CacheSet.cxx @@ -126,7 +126,7 @@ OCacheSet::OCacheSet() return sQuote; } // ------------------------------------------------------------------------- -void OCacheSet::construct( const Reference< XResultSet>& _xDriverSet) +void OCacheSet::construct( const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& /*i_sRowSetFilter*/) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::construct" ); OSL_ENSURE(_xDriverSet.is(),"Invalid resultSet"); diff --git a/dbaccess/source/core/api/CacheSet.hxx b/dbaccess/source/core/api/CacheSet.hxx index 63aa508478b2..658e2c9871bf 100644 --- a/dbaccess/source/core/api/CacheSet.hxx +++ b/dbaccess/source/core/api/CacheSet.hxx @@ -107,7 +107,7 @@ namespace dbaccess public: // late constructor - virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet); + virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter); virtual void fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition); // ::com::sun::star::sdbc::XRow diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx index f804c1c1cb34..04bef19278b1 100644 --- a/dbaccess/source/core/api/KeySet.cxx +++ b/dbaccess/source/core/api/KeySet.cxx @@ -148,6 +148,134 @@ namespace } } } + class OPrivateRow : public ::cppu::WeakImplHelper1<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 (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) // ------------------------------------------------------------------------- @@ -159,6 +287,7 @@ OKeySet::OKeySet(const connectivity::OSQLTable& _xTable, :m_aParameterValueForCache(_aParameterValueForCache) ,m_pKeyColumnNames(NULL) ,m_pColumnNames(NULL) + ,m_pParameterNames(NULL) ,m_pForeignColumnNames(NULL) ,m_xTable(_xTable) ,m_xTableKeys(_xTableKeys) @@ -188,25 +317,38 @@ OKeySet::~OKeySet() 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) +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); + OCacheSet::construct(_xDriverSet,i_sRowSetFilter); Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); bool bCase = (xMeta.is() && xMeta->storesMixedCaseQuotedIdentifiers()) ? true : false; - m_pKeyColumnNames = new SelectColumnsMetaData(bCase); - m_pColumnNames = new SelectColumnsMetaData(bCase); - m_pForeignColumnNames = new SelectColumnsMetaData(bCase); + m_pKeyColumnNames = new SelectColumnsMetaData(bCase); + m_pColumnNames = new SelectColumnsMetaData(bCase); + m_pParameterNames = new SelectColumnsMetaData(bCase); + m_pForeignColumnNames = new SelectColumnsMetaData(bCase); Reference<XNameAccess> xKeyColumns = getKeyColumns(); Reference<XColumnsSupplier> xSup(m_xComposer,UNO_QUERY); Reference<XNameAccess> xSourceColumns = m_xTable->getColumns(); + // locate parameter in select columns + Reference<XParametersSupplier> xParaSup(m_xComposer,UNO_QUERY); + Reference<XIndexAccess> xQueryParameters = xParaSup->getParameters(); + const sal_Int32 nParaCount = xQueryParameters->getCount(); + Sequence< ::rtl::OUString> aParameterColumns(nParaCount); + for(sal_Int32 i = 0; i< nParaCount;++i) + { + Reference<XPropertySet> xPara(xQueryParameters->getByIndex(i),UNO_QUERY_THROW); + xPara->getPropertyValue(PROPERTY_REALNAME) >>= aParameterColumns[i]; + } + ::rtl::OUString sCatalog,sSchema,sTable; @@ -235,6 +377,7 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet) ::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)); SelectColumnsMetaData::const_iterator aPosIter = (*m_pKeyColumnNames).begin(); SelectColumnsMetaData::const_iterator aPosEnd = (*m_pKeyColumnNames).end(); @@ -251,7 +394,7 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet) // 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,0))); + m_aKeyMap.insert(OKeySetMatrix::value_type(0,OKeySetValue(NULL,::std::pair<sal_Int32,Reference<XRow> >(0,NULL)))); m_aKeyIter = m_aKeyMap.begin(); @@ -281,9 +424,10 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet) aFilter.append(aAnd); } + Reference< XSingleSelectQueryComposer> xSourceComposer(m_xComposer,UNO_QUERY); Reference< XMultiServiceFactory > xFactory(m_xConnection, UNO_QUERY_THROW); Reference<XSingleSelectQueryComposer> xAnalyzer(xFactory->createInstance(SERVICE_NAME_SINGLESELECTQUERYCOMPOSER),UNO_QUERY); - xAnalyzer->setQuery(m_xComposer->getQuery()); + xAnalyzer->setElementaryQuery(xSourceComposer->getElementaryQuery()); Reference<XTablesSupplier> xTabSup(xAnalyzer,uno::UNO_QUERY); Reference<XNameAccess> xSelectTables(xTabSup->getTables(),uno::UNO_QUERY); const Sequence< ::rtl::OUString> aSeq = xSelectTables->getElementNames(); @@ -320,11 +464,10 @@ void OKeySet::construct(const Reference< XResultSet>& _xDriverSet) } } } // if ( aSeq.getLength() > 1 ) // special handling for join - const ::rtl::OUString sOldFilter = xAnalyzer->getFilter(); - if ( sOldFilter.getLength() ) + if ( i_sRowSetFilter.getLength() ) { FilterCreator aFilterCreator; - aFilterCreator.append( sOldFilter ); + aFilterCreator.append( i_sRowSetFilter ); aFilterCreator.append( aFilter.makeStringAndClear() ); aFilter = aFilterCreator.getComposedAndClear(); } @@ -587,13 +730,24 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow i = 1; // first the set values + bool bRefetch = true; aIter = m_pColumnNames->begin(); sal_uInt16 j = 0; + Reference<XRow> xRow; for(;aIter != aEnd;++aIter,++j) { sal_Int32 nPos = aIter->second.nPosition; if((_rInsertRow->get())[nPos].isModified()) { + if ( bRefetch ) + { + bRefetch = ::std::find(m_aFilterColumns.begin(),m_aFilterColumns.end(),aIter->first) == m_aFilterColumns.end(); + if ( !bRefetch ) + { + xRow = new OPrivateRow(_rInsertRow->get()); + } + } + 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); @@ -621,10 +775,11 @@ void SAL_CALL OKeySet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow m_bUpdated = xPrep->executeUpdate() > 0; if(m_bUpdated) { - m_aKeyIter = m_aKeyMap.find(::comphelper::getINT32((_rInsertRow->get())[0].getAny())); - OSL_ENSURE(m_aKeyIter != m_aKeyMap.end(),"New inserted row not found!"); - m_aKeyIter->second.second = 2; - copyRowValue(_rInsertRow,m_aKeyIter->second.first); + 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); } } // ------------------------------------------------------------------------- @@ -785,21 +940,47 @@ void SAL_CALL OKeySet::insertRow( const ORowSetRow& _rInsertRow,const connectivi } if ( m_bInserted ) { - ORowSetRow aKeyRow = new connectivity::ORowVector< ORowSetValue >((*m_pKeyColumnNames).size()); - copyRowValue(_rInsertRow,aKeyRow); - OKeySetMatrix::iterator aKeyIter = m_aKeyMap.end(); --aKeyIter; - m_aKeyIter = m_aKeyMap.insert(OKeySetMatrix::value_type(aKeyIter->first + 1,OKeySetValue(aKeyRow,1))).first; + 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<sal_Int32,Reference<XRow> >(1,NULL)))).first; // now we set the bookmark for this row (_rInsertRow->get())[0] = makeAny((sal_Int32)m_aKeyIter->first); } } // ----------------------------------------------------------------------------- -void OKeySet::copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow) +void OKeySet::copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sal_Int32 i_nBookmark) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::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(),"OKeySet::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) @@ -1149,9 +1330,23 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException) 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 = m_aParameterValueForCache.get().begin(); - connectivity::ORowVector< ORowSetValue >::Vector::const_iterator aParaEnd = m_aParameterValueForCache.get().end(); + 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() ); @@ -1202,7 +1397,7 @@ sal_Bool OKeySet::fetchRow() 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,0))).first; + m_aKeyIter = m_aKeyMap.insert(OKeySetMatrix::value_type(m_aKeyMap.rbegin()->first+1,OKeySetValue(aKeyRow,::std::pair<sal_Int32,Reference<XRow> >(0,NULL)))).first; } else m_bRowCountFinal = sal_True; @@ -1361,13 +1556,13 @@ Reference< XArray > SAL_CALL OKeySet::getArray( sal_Int32 columnIndex ) throw(SQ sal_Bool SAL_CALL OKeySet::rowUpdated( ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::rowUpdated" ); - return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second == 2; + return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second.first == 2; } // ------------------------------------------------------------------------- sal_Bool SAL_CALL OKeySet::rowInserted( ) throw(SQLException, RuntimeException) { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::rowInserted" ); - return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second == 1; + return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second.first == 1; } // ------------------------------------------------------------------------- sal_Bool SAL_CALL OKeySet::rowDeleted( ) throw(SQLException, RuntimeException) @@ -1413,20 +1608,22 @@ sal_Bool SAL_CALL OKeySet::rowDeleted( ) throw(SQLException, RuntimeException) // ----------------------------------------------------------------------------- namespace dbaccess { - void getColumnPositions(const Reference<XNameAccess>& _rxQueryColumns, - const Sequence< ::rtl::OUString>& _aColumnNames, + +void getColumnPositions(const Reference<XNameAccess>& _rxQueryColumns, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rColumnNames, const ::rtl::OUString& _rsUpdateTableName, - SelectColumnsMetaData& _rColumnNames) + SelectColumnsMetaData& _rColumnAssignments) + { // 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(); + const ::rtl::OUString* pColumnIter = _rColumnNames.getConstArray(); + const ::rtl::OUString* pColumnEnd = pColumnIter + _rColumnNames.getLength(); - ::comphelper::UStringMixLess aTmp(_rColumnNames.key_comp()); + ::comphelper::UStringMixLess aTmp(_rColumnAssignments.key_comp()); ::comphelper::UStringMixEqual bCase(static_cast< ::comphelper::UStringMixLess*>(&aTmp)->isCaseSensitive()); for(sal_Int32 nPos = 1;pSelBegin != pSelEnd;++pSelBegin,++nPos) @@ -1440,7 +1637,7 @@ namespace dbaccess for(;pColumnIter != pColumnEnd;++pColumnIter) { - if(bCase(sRealName,*pColumnIter) && bCase(_rsUpdateTableName,sTableName) && _rColumnNames.find(*pColumnIter) == _rColumnNames.end()) + if(bCase(sRealName,*pColumnIter) && bCase(_rsUpdateTableName,sTableName) && _rColumnAssignments.find(*pColumnIter) == _rColumnAssignments.end()) { sal_Int32 nType = 0; xColumnProp->getPropertyValue(PROPERTY_TYPE) >>= nType; @@ -1454,11 +1651,11 @@ namespace dbaccess xColumnProp->getPropertyValue(PROPERTY_ISNULLABLE) >>= bNullable; - _rColumnNames[sRealName] = SelectColumnDescription( nPos, nType,nScale,bNullable != sdbc::ColumnValue::NO_NULLS, sColumnDefault ); + _rColumnAssignments[sRealName] = SelectColumnDescription( nPos, nType,nScale,bNullable != sdbc::ColumnValue::NO_NULLS, sColumnDefault ); break; } } - pColumnIter = _aColumnNames.getConstArray(); + pColumnIter = _rColumnNames.getConstArray(); } } } @@ -1484,3 +1681,4 @@ void OKeySet::impl_convertValue_throw(const ORowSetRow& _rInsertRow,const Select } } // ----------------------------------------------------------------------------- + diff --git a/dbaccess/source/core/api/KeySet.hxx b/dbaccess/source/core/api/KeySet.hxx index 5f92d8f4fa5b..169d8d4f65a6 100644 --- a/dbaccess/source/core/api/KeySet.hxx +++ b/dbaccess/source/core/api/KeySet.hxx @@ -80,12 +80,13 @@ namespace dbaccess // the elements of _rxQueryColumns must have the properties PROPERTY_REALNAME and PROPERTY_TABLENAME void getColumnPositions(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxQueryColumns, - const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _aColumnNames, + const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rColumnNames, const ::rtl::OUString& _rsUpdateTableName, - SelectColumnsMetaData& _rColumnNames /* out */); + SelectColumnsMetaData& _rColumnAssignments /* out */); - typedef ::std::pair<ORowSetRow,sal_Int32> OKeySetValue; + typedef ::std::pair<ORowSetRow,::std::pair<sal_Int32,::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> > > OKeySetValue; typedef ::std::map<sal_Int32,OKeySetValue > OKeySetMatrix; + typedef ::std::map<sal_Int32,ORowSetValueVector > OUpdatedParameter; // is used when the source supports keys class OKeySet : public OCacheSet { @@ -94,9 +95,11 @@ namespace dbaccess ::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 connectivity::OSQLTable m_xTable; // reference to our table ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> m_xTableKeys; @@ -106,6 +109,7 @@ namespace dbaccess ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer; ::rtl::OUString m_sUpdateTableName; ::rtl::OUString m_aSelectComposedTableName; + ::std::vector< ::rtl::OUString > m_aFilterColumns; sal_Bool m_bRowCountFinal; @@ -125,8 +129,9 @@ namespace dbaccess * * \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); + void copyRowValue(const ORowSetRow& _rInsertRow,ORowSetRow& _rKeyRow,sal_Int32 i_nBookmark); ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getKeyColumns() const; void fillAllRows(); @@ -143,7 +148,7 @@ namespace dbaccess const ORowSetValueVector& _aParameterValueForCache); // late ctor which can throw exceptions - virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet); + 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); diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 2d7bda3f29b4..156a3e21037b 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -1775,7 +1775,7 @@ void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotifi { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn: creating cache" ); - m_pCache = new ORowSetCache( xResultSet, m_xComposer.get(), m_aContext, aComposedUpdateTableName, m_bModified, m_bNew,m_aParameterValueForCache ); + m_pCache = new ORowSetCache( xResultSet, m_xComposer.get(), m_aContext, aComposedUpdateTableName, m_bModified, m_bNew,m_aParameterValueForCache,m_aFilter ); if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY ) { m_nPrivileges = Privilege::SELECT; diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index 94e6cf62e235..bd9de512e311 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -135,7 +135,8 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, const ::rtl::OUString& _rUpdateTableName, sal_Bool& _bModified, sal_Bool& _bNew, - const ORowSetValueVector& _aParameterValueForCache) + const ORowSetValueVector& _aParameterValueForCache, + const ::rtl::OUString& i_sRowSetFilter) :m_xSet(_xRs) ,m_xMetaData(Reference< XResultSetMetaDataSupplier >(_xRs,UNO_QUERY)->getMetaData()) ,m_aContext( _rContext ) @@ -257,7 +258,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, { m_pCacheSet = new OBookmarkSet(); m_xCacheSet = m_pCacheSet; - m_pCacheSet->construct(_xRs); + m_pCacheSet->construct(_xRs,i_sRowSetFilter); // check privileges m_nPrivileges = Privilege::SELECT; @@ -291,7 +292,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, { m_pCacheSet = new OStaticSet(); m_xCacheSet = m_pCacheSet; - m_pCacheSet->construct(_xRs); + m_pCacheSet->construct(_xRs,i_sRowSetFilter); m_nPrivileges = Privilege::SELECT; } else @@ -332,7 +333,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, { m_pCacheSet = pKeySet; m_xCacheSet = m_pCacheSet; - pKeySet->construct(_xRs); + pKeySet->construct(_xRs,i_sRowSetFilter); if(Reference<XResultSetUpdate>(_xRs,UNO_QUERY).is()) // this interface is optional so we have to check it { @@ -356,7 +357,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, m_xCacheSet = NULL; m_pCacheSet = new OStaticSet(); m_xCacheSet = m_pCacheSet; - m_pCacheSet->construct(_xRs); + m_pCacheSet->construct(_xRs,i_sRowSetFilter); m_nPrivileges = Privilege::SELECT; } } @@ -1281,8 +1282,7 @@ void ORowSetCache::updateRow( ORowSetMatrix::iterator& _rUpdateRow ) // refetch the whole row (*m_aMatrixIter) = NULL; - if ( !moveToBookmark(aBookmark) ) - m_aMatrixIter = m_pMatrix->end(); + moveToBookmark(aBookmark); // moveToBookmark((*(*m_aInsertRow))[0].makeAny()); // if(m_pCacheSet->rowUpdated()) diff --git a/dbaccess/source/core/api/RowSetCache.hxx b/dbaccess/source/core/api/RowSetCache.hxx index 812cc3007e64..2153d84740bb 100644 --- a/dbaccess/source/core/api/RowSetCache.hxx +++ b/dbaccess/source/core/api/RowSetCache.hxx @@ -192,7 +192,8 @@ namespace dbaccess const ::rtl::OUString& _rUpdateTableName, sal_Bool& _bModified, sal_Bool& _bNew, - const ORowSetValueVector& _aParameterValueForCache); + const ORowSetValueVector& _aParameterValueForCache, + const ::rtl::OUString& i_sRowSetFilter); ~ORowSetCache(); diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index b14b4440275a..8bc9a665bc9d 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -47,6 +47,7 @@ #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/XResultSetMetaData.hpp> #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> +#include <com/sun/star/sdbc/XParameters.hpp> #include <com/sun/star/uno/XAggregation.hpp> #include <com/sun/star/util/XNumberFormatter.hpp> /** === end UNO includes === **/ @@ -708,13 +709,28 @@ Reference< XNameAccess > SAL_CALL OSingleSelectQueryComposer::getColumns( ) thr } catch( const Exception& ) { } - if ( !xResultSetMeta.is() ) + try + { + if ( !xResultSetMeta.is() ) + { + xStatement.reset( Reference< XStatement >( m_xConnection->createStatement(), UNO_QUERY_THROW ) ); + Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); + try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( sal_False ) ); } + catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } + xResMetaDataSup.set( xStatement->executeQuery( sSQL ), UNO_QUERY_THROW ); + xResultSetMeta.set( xResMetaDataSup->getMetaData(), UNO_QUERY_THROW ); + } + } + catch( const Exception& ) { - xStatement.reset( Reference< XStatement >( m_xConnection->createStatement(), UNO_QUERY_THROW ) ); - Reference< XPropertySet > xStatementProps( xStatement, UNO_QUERY_THROW ); - try { xStatementProps->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, makeAny( sal_False ) ); } - catch ( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } - xResMetaDataSup.set( xStatement->executeQuery( sSQL ), UNO_QUERY_THROW ); + //@see issue http://qa.openoffice.org/issues/show_bug.cgi?id=110111 + // access returns a different order of column names when executing select * from + // and asking the columns from the metadata. + Reference< XParameters > xParameters( xPreparedStatement, UNO_QUERY_THROW ); + Reference< XIndexAccess > xPara = getParameters(); + for(sal_Int32 i = 1;i <= xPara->getCount();++i) + xParameters->setNull(i,DataType::VARCHAR); + xResMetaDataSup.set(xPreparedStatement->executeQuery(), UNO_QUERY_THROW ); xResultSetMeta.set( xResMetaDataSup->getMetaData(), UNO_QUERY_THROW ); } diff --git a/dbaccess/source/ui/control/tabletree.cxx b/dbaccess/source/ui/control/tabletree.cxx index 5dc8fe2ecba6..72db2ee129df 100644 --- a/dbaccess/source/ui/control/tabletree.cxx +++ b/dbaccess/source/ui/control/tabletree.cxx @@ -638,37 +638,45 @@ String OTableTreeListBox::getQualifiedTableName( SvLBoxEntry* _pEntry ) const { OSL_PRECOND( !isFolderEntry( _pEntry ), "OTableTreeListBox::getQualifiedTableName: folder entries not allowed here!" ); - Reference< XDatabaseMetaData > xMeta; - if ( !impl_getAndAssertMetaData( xMeta ) ) - return String(); + try + { + Reference< XDatabaseMetaData > xMeta; + if ( !impl_getAndAssertMetaData( xMeta ) ) + return String(); - ::rtl::OUString sCatalog; - ::rtl::OUString sSchema; - ::rtl::OUString sTable; + ::rtl::OUString sCatalog; + ::rtl::OUString sSchema; + ::rtl::OUString sTable; - SvLBoxEntry* pSchema = GetParent( _pEntry ); - if ( pSchema ) - { - SvLBoxEntry* pCatalog = GetParent( pSchema ); - if ( pCatalog - || ( xMeta->supportsCatalogsInDataManipulation() - && !xMeta->supportsSchemasInDataManipulation() - ) // here we support catalog but no schema - ) + SvLBoxEntry* pSchema = GetParent( _pEntry ); + if ( pSchema ) { - if ( pCatalog == NULL ) + SvLBoxEntry* pCatalog = GetParent( pSchema ); + if ( pCatalog + || ( xMeta->supportsCatalogsInDataManipulation() + && !xMeta->supportsSchemasInDataManipulation() + ) // here we support catalog but no schema + ) { - pCatalog = pSchema; - pSchema = NULL; + if ( pCatalog == NULL ) + { + pCatalog = pSchema; + pSchema = NULL; + } + sCatalog = GetEntryText( pCatalog ); } - sCatalog = GetEntryText( pCatalog ); + if ( pSchema ) + sSchema = GetEntryText(pSchema); } - if ( pSchema ) - sSchema = GetEntryText(pSchema); - } - sTable = GetEntryText( _pEntry ); + sTable = GetEntryText( _pEntry ); - return ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ); + return ::dbtools::composeTableName( xMeta, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return String(); } //------------------------------------------------------------------------ diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index 5670ff86b60e..f7c3daeb6543 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -1101,6 +1101,7 @@ void OCopyTableWizard::insertColumn(sal_Int32 _nPos,OFieldDescription* _pField) m_aDestVec.insert(m_aDestVec.begin() + _nPos, m_vDestColumns.insert(ODatabaseExport::TColumns::value_type(_pField->GetName(),_pField)).first); + m_mNameMapping[_pField->GetName()] = _pField->GetName(); } } // ----------------------------------------------------------------------------- @@ -1191,6 +1192,8 @@ void OCopyTableWizard::clearDestColumns() { RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::clearDestColumns" ); clearColumns(m_vDestColumns,m_aDestVec); + m_bAddPKFirstTime = sal_True; + m_mNameMapping.clear(); } // ----------------------------------------------------------------------------- |