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 "BookmarkSet.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 OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
51cdf0e10cSrcweir 	OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
52cdf0e10cSrcweir 	m_xRowLocate.set(_xDriverSet,UNO_QUERY);
53cdf0e10cSrcweir }
54cdf0e10cSrcweir // -----------------------------------------------------------------------------
getBookmark()55cdf0e10cSrcweir Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
58cdf0e10cSrcweir 	return m_xRowLocate->getBookmark();
59cdf0e10cSrcweir }
60cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToBookmark(const Any & bookmark)61cdf0e10cSrcweir sal_Bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
64cdf0e10cSrcweir 	return m_xRowLocate->moveToBookmark(bookmark);
65cdf0e10cSrcweir }
66cdf0e10cSrcweir // -------------------------------------------------------------------------
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)67cdf0e10cSrcweir sal_Bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
70cdf0e10cSrcweir 	return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -------------------------------------------------------------------------
compareBookmarks(const Any & _first,const Any & _second)73cdf0e10cSrcweir sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
76cdf0e10cSrcweir 	return m_xRowLocate->compareBookmarks(_first,_second);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir // -------------------------------------------------------------------------
hasOrderedBookmarks()79cdf0e10cSrcweir sal_Bool SAL_CALL OBookmarkSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
82cdf0e10cSrcweir 	return m_xRowLocate->hasOrderedBookmarks();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir // -------------------------------------------------------------------------
hashBookmark(const Any & bookmark)85cdf0e10cSrcweir sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
88cdf0e10cSrcweir 	return m_xRowLocate->hashBookmark(bookmark);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -------------------------------------------------------------------------
91cdf0e10cSrcweir // ::com::sun::star::sdbcx::XDeleteRows
deleteRows(const Sequence<Any> & rows,const connectivity::OSQLTable &)92cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
95cdf0e10cSrcweir 	Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
96cdf0e10cSrcweir 	if(xDeleteRow.is())
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		return xDeleteRow->deleteRows(rows);
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir 	return Sequence< sal_Int32 >();
101cdf0e10cSrcweir }
102cdf0e10cSrcweir // -------------------------------------------------------------------------
insertRow(const ORowSetRow & _rInsertRow,const connectivity::OSQLTable &)103cdf0e10cSrcweir void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
106cdf0e10cSrcweir 	Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
107cdf0e10cSrcweir 	if(!xUpdRow.is())
108cdf0e10cSrcweir         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
111cdf0e10cSrcweir 	if(xUpd.is())
112cdf0e10cSrcweir 	{
113cdf0e10cSrcweir 		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,xUpdRow,*aIter);
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 		xUpd->insertRow();
122cdf0e10cSrcweir 		(*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 	else
125cdf0e10cSrcweir         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir // -------------------------------------------------------------------------
updateRow(const ORowSetRow & _rInsertRow,const ORowSetRow & _rOrginalRow,const connectivity::OSQLTable &)128cdf0e10cSrcweir void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
131cdf0e10cSrcweir 	//	OCacheSet::updateRow( _rInsertRow,_rOrginalRow,_xTable);
132cdf0e10cSrcweir 	Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
133cdf0e10cSrcweir 	if(!xUpdRow.is())
134cdf0e10cSrcweir         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	sal_Int32 i = 1;
137cdf0e10cSrcweir 	connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
138cdf0e10cSrcweir     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
139cdf0e10cSrcweir 	for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		aIter->setSigned(aOrgIter->isSigned());
142cdf0e10cSrcweir 		updateColumn(i,xUpdRow,*aIter);
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
147cdf0e10cSrcweir 	if(xUpd.is())
148cdf0e10cSrcweir 		xUpd->updateRow();
149cdf0e10cSrcweir 	else
150cdf0e10cSrcweir         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
151cdf0e10cSrcweir }
152cdf0e10cSrcweir // -------------------------------------------------------------------------
deleteRow(const ORowSetRow &,const connectivity::OSQLTable &)153cdf0e10cSrcweir void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
156cdf0e10cSrcweir 	Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	xUpd->deleteRow();
159cdf0e10cSrcweir }
160cdf0e10cSrcweir // -------------------------------------------------------------------------
cancelRowUpdates()161cdf0e10cSrcweir void SAL_CALL OBookmarkSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToInsertRow()166cdf0e10cSrcweir void SAL_CALL OBookmarkSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
169cdf0e10cSrcweir 	Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
170cdf0e10cSrcweir 	if(xUpd.is())
171cdf0e10cSrcweir 		xUpd->moveToInsertRow();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir // -------------------------------------------------------------------------
moveToCurrentRow()174cdf0e10cSrcweir void SAL_CALL OBookmarkSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir // -------------------------------------------------------------------------
fillValueRow(ORowSetRow & _rRow,sal_Int32 _nPosition)179cdf0e10cSrcweir void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
182cdf0e10cSrcweir 	OCacheSet::fillValueRow(_rRow,_nPosition);
183cdf0e10cSrcweir }
184cdf0e10cSrcweir // -------------------------------------------------------------------------
updateColumn(sal_Int32 nPos,Reference<XRowUpdate> _xParameter,const ORowSetValue & _rValue)185cdf0e10cSrcweir void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
188cdf0e10cSrcweir 	if(_rValue.isBound() && _rValue.isModified())
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		if(_rValue.isNull())
191cdf0e10cSrcweir 			_xParameter->updateNull(nPos);
192cdf0e10cSrcweir 		else
193cdf0e10cSrcweir 		{
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 			switch(_rValue.getTypeKind())
196cdf0e10cSrcweir 			{
197cdf0e10cSrcweir                 case DataType::DECIMAL:
198cdf0e10cSrcweir                 case DataType::NUMERIC:
199cdf0e10cSrcweir                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
200cdf0e10cSrcweir                     break;
201cdf0e10cSrcweir 				case DataType::CHAR:
202cdf0e10cSrcweir 				case DataType::VARCHAR:
203cdf0e10cSrcweir 				//case DataType::DECIMAL:
204cdf0e10cSrcweir 				//case DataType::NUMERIC:
205cdf0e10cSrcweir 					_xParameter->updateString(nPos,_rValue);
206cdf0e10cSrcweir 					break;
207cdf0e10cSrcweir 				case DataType::BIGINT:
208cdf0e10cSrcweir 					if ( _rValue.isSigned() )
209cdf0e10cSrcweir 						_xParameter->updateLong(nPos,_rValue);
210cdf0e10cSrcweir 					else
211cdf0e10cSrcweir 						_xParameter->updateString(nPos,_rValue);
212cdf0e10cSrcweir 					break;
213cdf0e10cSrcweir 				case DataType::BIT:
214cdf0e10cSrcweir 				case DataType::BOOLEAN:
215cdf0e10cSrcweir 					_xParameter->updateBoolean(nPos,_rValue);
216cdf0e10cSrcweir 					break;
217cdf0e10cSrcweir 				case DataType::TINYINT:
218cdf0e10cSrcweir 					if ( _rValue.isSigned() )
219cdf0e10cSrcweir 						_xParameter->updateByte(nPos,_rValue);
220cdf0e10cSrcweir 					else
221cdf0e10cSrcweir 						_xParameter->updateShort(nPos,_rValue);
222cdf0e10cSrcweir 					break;
223cdf0e10cSrcweir 				case DataType::SMALLINT:
224cdf0e10cSrcweir 					if ( _rValue.isSigned() )
225cdf0e10cSrcweir 						_xParameter->updateShort(nPos,_rValue);
226cdf0e10cSrcweir 					else
227cdf0e10cSrcweir 						_xParameter->updateInt(nPos,_rValue);
228cdf0e10cSrcweir 					break;
229cdf0e10cSrcweir 				case DataType::INTEGER:
230cdf0e10cSrcweir 					if ( _rValue.isSigned() )
231cdf0e10cSrcweir 						_xParameter->updateInt(nPos,_rValue);
232cdf0e10cSrcweir 					else
233cdf0e10cSrcweir 						_xParameter->updateLong(nPos,_rValue);
234cdf0e10cSrcweir 					break;
235cdf0e10cSrcweir 				case DataType::FLOAT:
236cdf0e10cSrcweir 					_xParameter->updateFloat(nPos,_rValue);
237cdf0e10cSrcweir 					break;
238cdf0e10cSrcweir 				case DataType::DOUBLE:
239cdf0e10cSrcweir 				case DataType::REAL:
240cdf0e10cSrcweir 					_xParameter->updateDouble(nPos,_rValue);
241cdf0e10cSrcweir 					break;
242cdf0e10cSrcweir 				case DataType::DATE:
243cdf0e10cSrcweir 					_xParameter->updateDate(nPos,_rValue);
244cdf0e10cSrcweir 					break;
245cdf0e10cSrcweir 				case DataType::TIME:
246cdf0e10cSrcweir 					_xParameter->updateTime(nPos,_rValue);
247cdf0e10cSrcweir 					break;
248cdf0e10cSrcweir 				case DataType::TIMESTAMP:
249cdf0e10cSrcweir 					_xParameter->updateTimestamp(nPos,_rValue);
250cdf0e10cSrcweir 					break;
251cdf0e10cSrcweir 				case DataType::BINARY:
252cdf0e10cSrcweir 				case DataType::VARBINARY:
253cdf0e10cSrcweir 				case DataType::LONGVARBINARY:
254cdf0e10cSrcweir 					_xParameter->updateBytes(nPos,_rValue);
255cdf0e10cSrcweir 					break;
256cdf0e10cSrcweir 				case DataType::BLOB:
257cdf0e10cSrcweir 				case DataType::CLOB:
258cdf0e10cSrcweir 					_xParameter->updateObject(nPos,_rValue.getAny());
259cdf0e10cSrcweir 					break;
260cdf0e10cSrcweir 			}
261cdf0e10cSrcweir 		}
262cdf0e10cSrcweir 	}
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265