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