1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir #include "WrappedResultSet.hxx"
27cdf0e10cSrcweir #include "core_resource.hxx"
28cdf0e10cSrcweir #include "core_resource.hrc"
29cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
30cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
31cdf0e10cSrcweir #include <rtl/logfile.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <limits>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace dbaccess;
36cdf0e10cSrcweir using namespace ::connectivity;
37cdf0e10cSrcweir using namespace ::dbtools;
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir using namespace ::com::sun::star::beans;
40cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
41cdf0e10cSrcweir //	using namespace ::com::sun::star::sdb;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
43cdf0e10cSrcweir using namespace ::com::sun::star::container;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir //	using namespace ::cppu;
46cdf0e10cSrcweir using namespace ::osl;
47cdf0e10cSrcweir 
construct(const Reference<XResultSet> & _xDriverSet,const::rtl::OUString & i_sRowSetFilter)48cdf0e10cSrcweir void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::construct" );
51cdf0e10cSrcweir 	OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
52cdf0e10cSrcweir     m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
53cdf0e10cSrcweir 	m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
54cdf0e10cSrcweir     m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
55cdf0e10cSrcweir }
56cdf0e10cSrcweir // -----------------------------------------------------------------------------
getBookmark()57cdf0e10cSrcweir Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::getBookmark" );
60cdf0e10cSrcweir     if ( m_xRowLocate.is() )
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         return m_xRowLocate->getBookmark( );
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 	return makeAny(m_xDriverSet->getRow());
65cdf0e10cSrcweir }
66cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToBookmark(const Any & bookmark)67cdf0e10cSrcweir sal_Bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToBookmark" );
70cdf0e10cSrcweir     return m_xRowLocate->moveToBookmark( bookmark );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -------------------------------------------------------------------------
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)73cdf0e10cSrcweir sal_Bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveRelativeToBookmark" );
76cdf0e10cSrcweir     return m_xRowLocate->moveRelativeToBookmark( bookmark,rows );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir // -------------------------------------------------------------------------
compareBookmarks(const Any & _first,const Any & _second)79cdf0e10cSrcweir sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::compareBookmarks" );
82cdf0e10cSrcweir 	return m_xRowLocate->compareBookmarks( _first,_second );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir // -------------------------------------------------------------------------
hasOrderedBookmarks()85cdf0e10cSrcweir sal_Bool SAL_CALL WrappedResultSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hasOrderedBookmarks" );
88cdf0e10cSrcweir 	return m_xRowLocate->hasOrderedBookmarks();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -------------------------------------------------------------------------
hashBookmark(const Any & bookmark)91cdf0e10cSrcweir sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hashBookmark" );
94cdf0e10cSrcweir     return m_xRowLocate->hashBookmark(bookmark);
95cdf0e10cSrcweir }
96cdf0e10cSrcweir // -------------------------------------------------------------------------
97cdf0e10cSrcweir // ::com::sun::star::sdbcx::XDeleteRows
deleteRows(const Sequence<Any> & rows,const connectivity::OSQLTable &)98cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL WrappedResultSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRows" );
101cdf0e10cSrcweir 	Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
102cdf0e10cSrcweir 	if(xDeleteRow.is())
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		return xDeleteRow->deleteRows(rows);
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 	return Sequence< sal_Int32 >();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir // -------------------------------------------------------------------------
insertRow(const ORowSetRow & _rInsertRow,const connectivity::OSQLTable &)109cdf0e10cSrcweir void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::insertRow" );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	m_xUpd->moveToInsertRow();
114cdf0e10cSrcweir 	sal_Int32 i = 1;
115cdf0e10cSrcweir     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
116cdf0e10cSrcweir 	for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		aIter->setSigned(m_aSignedFlags[i-1]);
119cdf0e10cSrcweir 		updateColumn(i,m_xUpdRow,*aIter);
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir 	m_xUpd->insertRow();
122cdf0e10cSrcweir 	(*_rInsertRow->get().begin()) = getBookmark();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir // -------------------------------------------------------------------------
updateRow(const ORowSetRow & _rInsertRow,const ORowSetRow & _rOrginalRow,const connectivity::OSQLTable &)125cdf0e10cSrcweir void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateRow" );
128cdf0e10cSrcweir 	sal_Int32 i = 1;
129cdf0e10cSrcweir 	connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
130cdf0e10cSrcweir     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
131cdf0e10cSrcweir 	for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		aIter->setSigned(aOrgIter->isSigned());
134cdf0e10cSrcweir 		updateColumn(i,m_xUpdRow,*aIter);
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 	m_xUpd->updateRow();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir // -------------------------------------------------------------------------
deleteRow(const ORowSetRow &,const connectivity::OSQLTable &)139cdf0e10cSrcweir void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRow" );
142cdf0e10cSrcweir 	m_xUpd->deleteRow();
143cdf0e10cSrcweir }
144cdf0e10cSrcweir // -------------------------------------------------------------------------
cancelRowUpdates()145cdf0e10cSrcweir void SAL_CALL WrappedResultSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::cancelRowUpdates" );
148cdf0e10cSrcweir     m_xUpd->cancelRowUpdates();
149cdf0e10cSrcweir }
150cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToInsertRow()151cdf0e10cSrcweir void SAL_CALL WrappedResultSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToInsertRow" );
154cdf0e10cSrcweir 	m_xUpd->moveToInsertRow();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToCurrentRow()157cdf0e10cSrcweir void SAL_CALL WrappedResultSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToCurrentRow" );
160cdf0e10cSrcweir     m_xUpd->moveToCurrentRow();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir // -------------------------------------------------------------------------
fillValueRow(ORowSetRow & _rRow,sal_Int32 _nPosition)163cdf0e10cSrcweir void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::fillValueRow" );
166cdf0e10cSrcweir 	OCacheSet::fillValueRow(_rRow,_nPosition);
167cdf0e10cSrcweir }
168cdf0e10cSrcweir // -------------------------------------------------------------------------
updateColumn(sal_Int32 nPos,Reference<XRowUpdate> _xParameter,const ORowSetValue & _rValue)169cdf0e10cSrcweir void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateColumn" );
172cdf0e10cSrcweir 	if(_rValue.isBound() && _rValue.isModified())
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		if(_rValue.isNull())
175cdf0e10cSrcweir 			_xParameter->updateNull(nPos);
176cdf0e10cSrcweir 		else
177cdf0e10cSrcweir 		{
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 			switch(_rValue.getTypeKind())
180cdf0e10cSrcweir 			{
181cdf0e10cSrcweir                 case DataType::DECIMAL:
182cdf0e10cSrcweir                 case DataType::NUMERIC:
183cdf0e10cSrcweir                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
184cdf0e10cSrcweir                     break;
185cdf0e10cSrcweir 				case DataType::CHAR:
186cdf0e10cSrcweir 				case DataType::VARCHAR:
187cdf0e10cSrcweir 				//case DataType::DECIMAL:
188cdf0e10cSrcweir 				//case DataType::NUMERIC:
189cdf0e10cSrcweir 					_xParameter->updateString(nPos,_rValue);
190cdf0e10cSrcweir 					break;
191cdf0e10cSrcweir 				case DataType::BIGINT:
192cdf0e10cSrcweir 					if ( _rValue.isSigned() )
193cdf0e10cSrcweir 						_xParameter->updateLong(nPos,_rValue);
194cdf0e10cSrcweir 					else
195cdf0e10cSrcweir 						_xParameter->updateString(nPos,_rValue);
196cdf0e10cSrcweir 					break;
197cdf0e10cSrcweir 				case DataType::BIT:
198cdf0e10cSrcweir 				case DataType::BOOLEAN:
199cdf0e10cSrcweir 					_xParameter->updateBoolean(nPos,_rValue);
200cdf0e10cSrcweir 					break;
201cdf0e10cSrcweir 				case DataType::TINYINT:
202cdf0e10cSrcweir 					if ( _rValue.isSigned() )
203cdf0e10cSrcweir 						_xParameter->updateByte(nPos,_rValue);
204cdf0e10cSrcweir 					else
205cdf0e10cSrcweir 						_xParameter->updateShort(nPos,_rValue);
206cdf0e10cSrcweir 					break;
207cdf0e10cSrcweir 				case DataType::SMALLINT:
208cdf0e10cSrcweir 					if ( _rValue.isSigned() )
209cdf0e10cSrcweir 						_xParameter->updateShort(nPos,_rValue);
210cdf0e10cSrcweir 					else
211cdf0e10cSrcweir 						_xParameter->updateInt(nPos,_rValue);
212cdf0e10cSrcweir 					break;
213cdf0e10cSrcweir 				case DataType::INTEGER:
214cdf0e10cSrcweir 					if ( _rValue.isSigned() )
215cdf0e10cSrcweir 						_xParameter->updateInt(nPos,_rValue);
216cdf0e10cSrcweir 					else
217cdf0e10cSrcweir 						_xParameter->updateLong(nPos,_rValue);
218cdf0e10cSrcweir 					break;
219cdf0e10cSrcweir 				case DataType::FLOAT:
220cdf0e10cSrcweir 					_xParameter->updateFloat(nPos,_rValue);
221cdf0e10cSrcweir 					break;
222cdf0e10cSrcweir 				case DataType::DOUBLE:
223cdf0e10cSrcweir 				case DataType::REAL:
224cdf0e10cSrcweir 					_xParameter->updateDouble(nPos,_rValue);
225cdf0e10cSrcweir 					break;
226cdf0e10cSrcweir 				case DataType::DATE:
227cdf0e10cSrcweir 					_xParameter->updateDate(nPos,_rValue);
228cdf0e10cSrcweir 					break;
229cdf0e10cSrcweir 				case DataType::TIME:
230cdf0e10cSrcweir 					_xParameter->updateTime(nPos,_rValue);
231cdf0e10cSrcweir 					break;
232cdf0e10cSrcweir 				case DataType::TIMESTAMP:
233cdf0e10cSrcweir 					_xParameter->updateTimestamp(nPos,_rValue);
234cdf0e10cSrcweir 					break;
235cdf0e10cSrcweir 				case DataType::BINARY:
236cdf0e10cSrcweir 				case DataType::VARBINARY:
237cdf0e10cSrcweir 				case DataType::LONGVARBINARY:
238cdf0e10cSrcweir 					_xParameter->updateBytes(nPos,_rValue);
239cdf0e10cSrcweir 					break;
240cdf0e10cSrcweir 				case DataType::BLOB:
241cdf0e10cSrcweir 				case DataType::CLOB:
242cdf0e10cSrcweir 					_xParameter->updateObject(nPos,_rValue.getAny());
243cdf0e10cSrcweir 					break;
244cdf0e10cSrcweir 			}
245cdf0e10cSrcweir 		}
246cdf0e10cSrcweir 	}
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249