Kaydet (Commit) 3fc48998 authored tarafından Ocke Janssen's avatar Ocke Janssen

change for insert , delete and update rows

üst d29d890f
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: KeySet.hxx,v $ * $RCSfile: KeySet.hxx,v $
* *
* $Revision: 1.6 $ * $Revision: 1.7 $
* *
* last change: $Author: oj $ $Date: 2001-01-30 14:27:47 $ * last change: $Author: oj $ $Date: 2001-02-01 14:23:57 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -78,33 +78,48 @@ ...@@ -78,33 +78,48 @@
#ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_ #ifndef _COM_SUN_STAR_SDB_XSQLQUERYCOMPOSER_HPP_
#include <com/sun/star/sdb/XSQLQueryComposer.hpp> #include <com/sun/star/sdb/XSQLQueryComposer.hpp>
#endif #endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif
namespace dbaccess namespace dbaccess
{ {
typedef ::std::map<sal_Int32,ORowSetRow> OKeySetMatrix; DECLARE_STL_MAP(::rtl::OUString,sal_Int32,::comphelper::UStringMixLess,OColumnNamePos);
// 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::Reference< ::com::sun::star::container::XNameAccess >& _rxColumns,
const ::rtl::OUString& _rsUpdateTableName,
OColumnNamePos& _rColumnNames /* out */);
typedef ::std::pair<ORowSetRow,sal_Int32> OKeySetValue;
typedef ::std::map<sal_Int32,OKeySetValue > OKeySetMatrix;
// is used when the source supports keys // is used when the source supports keys
class OKeySet : public OCacheSet class OKeySet : public OCacheSet
{ {
OKeySetMatrix m_aKeyMap; OKeySetMatrix m_aKeyMap;
OKeySetMatrix::iterator m_aKeyIter; OKeySetMatrix::iterator m_aKeyIter;
::std::vector< sal_Int32> m_aColumnPos; OColumnNamePos m_aKeyColumnNames; // contains all key column names
::std::vector< ::rtl::OUString> m_aColumnNames; OColumnNamePos m_aColumnNames; // contains all column names
connectivity::OSQLTable m_xTable; // reference to our table 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::XPreparedStatement> m_xStatement;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> m_xSet; ::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::sdbc::XRow> m_xRow;
::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer > m_xComposer;
::rtl::OUString m_sUpdateTableName;
// ::std::vector< OKeySetMatrix::iterator> m_aKeyPosition; // ::std::vector< OKeySetMatrix::iterator> m_aKeyPosition;
// ::std::vector< OKeySetMatrix::iterator>::iterator m_aKeyIter; // ::std::vector< OKeySetMatrix::iterator>::iterator m_aKeyIter;
sal_Bool m_bRowCountFinal; sal_Bool m_bRowCountFinal;
::std::vector< ::rtl::OUString> getColumnNames(); ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getKeyColumns() const;
void fillAllRows(); void fillAllRows();
sal_Bool fetchRow(); sal_Bool fetchRow();
public: public:
OKeySet(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet, OKeySet(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,
const connectivity::OSQLTable& _xTable, const connectivity::OSQLTable& _xTable,
const ::rtl::OUString& _rUpdateTableName,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer >& _xComposer); const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSQLQueryComposer >& _xComposer);
~OKeySet(); ~OKeySet();
...@@ -230,17 +245,17 @@ namespace dbaccess ...@@ -230,17 +245,17 @@ namespace dbaccess
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
virtual sal_Bool SAL_CALL rowUpdated( ) 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)
{ {
return m_bUpdated; return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second == 2;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
virtual sal_Bool SAL_CALL rowInserted( ) 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)
{ {
return m_bInserted; return m_aKeyIter != m_aKeyMap.begin() && m_aKeyIter != m_aKeyMap.end() && m_aKeyIter->second.second == 1;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
virtual sal_Bool SAL_CALL rowDeleted( ) 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)
{ {
return m_bDeleted; return sal_False;
} }
// ::com::sun::star::sdbc::XResultSet // ::com::sun::star::sdbc::XResultSet
...@@ -286,6 +301,9 @@ namespace dbaccess ...@@ -286,6 +301,9 @@ namespace dbaccess
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.6 2001/01/30 14:27:47 oj
new member which holds the column names
Revision 1.5 2001/01/24 09:50:49 oj Revision 1.5 2001/01/24 09:50:49 oj
#82628# rowset modifications #82628# rowset modifications
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: RowSetCache.cxx,v $ * $RCSfile: RowSetCache.cxx,v $
* *
* $Revision: 1.23 $ * $Revision: 1.24 $
* *
* last change: $Author: oj $ $Date: 2001-01-26 15:18:17 $ * last change: $Author: oj $ $Date: 2001-02-01 14:23:57 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -95,6 +95,9 @@ ...@@ -95,6 +95,9 @@
#ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_ #ifndef _COM_SUN_STAR_SDBC_RESULTSETCONCURRENCY_HPP_
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
#endif #endif
#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
#include <com/sun/star/sdbc/ColumnValue.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_ #ifndef _COM_SUN_STAR_SDBCX_PRIVILEGE_HPP_
#include <com/sun/star/sdbcx/Privilege.hpp> #include <com/sun/star/sdbcx/Privilege.hpp>
#endif #endif
...@@ -156,16 +159,22 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, ...@@ -156,16 +159,22 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
// check if all keys of the updateable table are fetched // check if all keys of the updateable table are fetched
sal_Bool bAllKeysFound = sal_False; sal_Bool bAllKeysFound = sal_False;
::rtl::OUString aUpdateTableName = _rUpdateTableName;
Reference< XConnection> xConnection;
if(_xComposer.is()) if(_xComposer.is())
{ {
Reference<XTablesSupplier> xTabSup(_xComposer,UNO_QUERY); Reference<XTablesSupplier> xTabSup(_xComposer,UNO_QUERY);
OSL_ENSURE(xTabSup.is(),"ORowSet::execute composer isn't a tablesupplier!"); OSL_ENSURE(xTabSup.is(),"ORowSet::execute composer isn't a tablesupplier!");
Reference<XNameAccess> xTables = xTabSup->getTables(); Reference<XNameAccess> xTables = xTabSup->getTables();
if(_rUpdateTableName.getLength())
if(_rUpdateTableName.getLength() && xTables->hasByName(_rUpdateTableName))
xTables->getByName(_rUpdateTableName) >>= m_aUpdateTable; xTables->getByName(_rUpdateTableName) >>= m_aUpdateTable;
else else
xTables->getByName(xTables->getElementNames()[0]) >>= m_aUpdateTable; {
aUpdateTableName = xTables->getElementNames()[0];
xTables->getByName(aUpdateTableName) >>= m_aUpdateTable;
}
if(m_aUpdateTable.is()) if(m_aUpdateTable.is())
{ {
...@@ -190,19 +199,24 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, ...@@ -190,19 +199,24 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
if(xColumnsSupplier.is()) if(xColumnsSupplier.is())
{ {
Reference<XNameAccess> xColumns = xColumnsSupplier->getColumns(); // first we need a connection
Reference< XStatement> xStmt(_xRs->getStatement(),UNO_QUERY);
Sequence< ::rtl::OUString> aNames(xColumns->getElementNames()); if(xStmt.is())
const ::rtl::OUString* pBegin = aNames.getConstArray(); xConnection = xStmt->getConnection();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength(); else
{
Reference< XPreparedStatement> xPrepStmt(_xRs->getStatement(),UNO_QUERY);
xConnection = xPrepStmt->getConnection();
}
OSL_ENSURE(xConnection.is(),"No connection!");
Reference<XNameAccess> xColumns = xColumnsSupplier->getColumns();
Reference<XColumnsSupplier> xColSup(_xComposer,UNO_QUERY); Reference<XColumnsSupplier> xColSup(_xComposer,UNO_QUERY);
Reference<XNameAccess> xSelColumns = xColSup->getColumns(); Reference<XNameAccess> xSelColumns = xColSup->getColumns();
for(;pBegin != pEnd ;++pBegin)
{ OColumnNamePos aColumnNames(xConnection->getMetaData()->storesMixedCaseQuotedIdentifiers());
if(!(bAllKeysFound = xSelColumns->hasByName(*pBegin))) // found a column which is not refetched ::dbaccess::getColumnPositions(xSelColumns,xColumns,aUpdateTableName,aColumnNames);
break; bAllKeysFound = aColumnNames.size() == xColumns->getElementNames().getLength();
}
} }
} }
} }
...@@ -242,9 +256,38 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, ...@@ -242,9 +256,38 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
} }
else else
{ {
m_pCacheSet = new OKeySet(_xRs,m_aUpdateTable,_xComposer); OColumnNamePos aColumnNames(xConnection->getMetaData()->storesMixedCaseQuotedIdentifiers());
Reference<XColumnsSupplier> xColSup(_xComposer,UNO_QUERY);
Reference<XNameAccess> xSelColumns = xColSup->getColumns();
Reference<XNameAccess> xColumns = m_aUpdateTable->getColumns();
::dbaccess::getColumnPositions(xSelColumns,xColumns,aUpdateTableName,aColumnNames);
// check privileges // check privileges
m_nPrivileges = Privilege::SELECT; m_nPrivileges = Privilege::SELECT;
sal_Bool bNoInsert = sal_False;
Sequence< ::rtl::OUString> aNames(xColumns->getElementNames());
const ::rtl::OUString* pBegin = aNames.getConstArray();
const ::rtl::OUString* pEnd = pBegin + aNames.getLength();
for(;pBegin != pEnd;++pBegin)
{
Reference<XPropertySet> xColumn;
xColumns->getByName(*pBegin) >>= xColumn;
OSL_ENSURE(xColumn.is(),"Column in table is null!");
if(xColumn.is())
{
sal_Int32 nNullable = 0;
xColumn->getPropertyValue(PROPERTY_ISNULLABLE) >>= nNullable;
if(nNullable == ColumnValue::NO_NULLS && aColumnNames.find(*pBegin) == aColumnNames.end())
{ // we found a column where null is not allowed so we can't insert new values
bNoInsert = sal_True;
break; // one column is enough
}
}
}
m_pCacheSet = new OKeySet(_xRs,m_aUpdateTable,aUpdateTableName ,_xComposer);
if(Reference<XResultSetUpdate>(_xRs,UNO_QUERY).is()) // this interface is optional so we have to check it if(Reference<XResultSetUpdate>(_xRs,UNO_QUERY).is()) // this interface is optional so we have to check it
{ {
Reference<XPropertySet> xTable(m_aUpdateTable,UNO_QUERY); Reference<XPropertySet> xTable(m_aUpdateTable,UNO_QUERY);
...@@ -256,6 +299,8 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, ...@@ -256,6 +299,8 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
m_nPrivileges = Privilege::SELECT; m_nPrivileges = Privilege::SELECT;
} }
} }
if(bNoInsert)
m_nPrivileges |= ~Privilege::INSERT; // remove the insert privilege
} }
} }
...@@ -282,7 +327,7 @@ ORowSetCache::~ORowSetCache() ...@@ -282,7 +327,7 @@ ORowSetCache::~ORowSetCache()
delete m_pInsertMatrix; delete m_pInsertMatrix;
} }
m_xStatement = NULL; m_xStatement = NULL;
m_xSet = ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>(); m_xSet = WeakReference< XResultSet>();
m_xMetaData = NULL; m_xMetaData = NULL;
m_aUpdateTable = NULL; m_aUpdateTable = NULL;
} }
...@@ -1714,9 +1759,13 @@ void ORowSetCache::setUpdateIterator(const ORowSetMatrix::iterator& _rOriginalRo ...@@ -1714,9 +1759,13 @@ void ORowSetCache::setUpdateIterator(const ORowSetMatrix::iterator& _rOriginalRo
for(;aIter != (*m_aInsertRow)->end();++aIter) for(;aIter != (*m_aInsertRow)->end();++aIter)
aIter->setModified(sal_False); aIter->setModified(sal_False);
} }
// -----------------------------------------------------------------------------
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.23 2001/01/26 15:18:17 oj
#83216# check if we stands after the last row after a next
Revision 1.22 2001/01/24 09:52:19 oj Revision 1.22 2001/01/24 09:52:19 oj
#82628# rowset modifications #82628# rowset modifications
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: RowSetCache.hxx,v $ * $RCSfile: RowSetCache.hxx,v $
* *
* $Revision: 1.6 $ * $Revision: 1.7 $
* *
* last change: $Author: oj $ $Date: 2001-01-22 07:38:24 $ * last change: $Author: oj $ $Date: 2001-02-01 14:23:57 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -364,6 +364,9 @@ namespace dbaccess ...@@ -364,6 +364,9 @@ namespace dbaccess
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.6 2001/01/22 07:38:24 oj
#82632# change member
Revision 1.5 2000/10/17 10:18:12 oj Revision 1.5 2000/10/17 10:18:12 oj
some changes for the rowset some changes for the rowset
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment