Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / api / BookmarkSet.cxx
blob8cb6a4e2760a6ae374c1daf12d9ff0d4c9b797bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "BookmarkSet.hxx"
21 #include "core_resource.hxx"
22 #include "core_resource.hrc"
23 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
24 #include <connectivity/dbexception.hxx>
26 #include <limits>
28 using namespace dbaccess;
29 using namespace ::connectivity;
30 using namespace ::dbtools;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::sdbc;
34 using namespace ::com::sun::star::sdbcx;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::lang;
37 using namespace ::osl;
39 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
41 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
42 m_xRowLocate.set(_xDriverSet,UNO_QUERY);
45 void OBookmarkSet::reset(const Reference< XResultSet>& _xDriverSet)
47 construct(_xDriverSet, m_sRowSetFilter);
50 Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
52 return m_xRowLocate->getBookmark();
55 bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
57 return m_xRowLocate->moveToBookmark(bookmark);
60 bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
62 return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
65 sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
67 return m_xRowLocate->compareBookmarks(_first,_second);
70 bool SAL_CALL OBookmarkSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
72 return m_xRowLocate->hasOrderedBookmarks();
75 sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
77 return m_xRowLocate->hashBookmark(bookmark);
80 // ::com::sun::star::sdbcx::XDeleteRows
81 Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
83 Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
84 if(xDeleteRow.is())
86 return xDeleteRow->deleteRows(rows);
88 return Sequence< sal_Int32 >();
91 void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
93 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
94 if(!xUpdRow.is())
95 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
97 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
98 if(xUpd.is())
100 xUpd->moveToInsertRow();
101 sal_Int32 i = 1;
102 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
103 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
105 aIter->setSigned(m_aSignedFlags[i-1]);
106 updateColumn(i,xUpdRow,*aIter);
108 xUpd->insertRow();
109 (*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
111 else
112 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
115 void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
117 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
118 if(!xUpdRow.is())
119 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
121 sal_Int32 i = 1;
122 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->get().begin()+1;
123 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
124 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
126 aIter->setSigned(aOrgIter->isSigned());
127 updateColumn(i,xUpdRow,*aIter);
131 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
132 if(xUpd.is())
133 xUpd->updateRow();
134 else
135 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
138 void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
140 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
142 xUpd->deleteRow();
145 void SAL_CALL OBookmarkSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
149 void SAL_CALL OBookmarkSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
151 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
152 if(xUpd.is())
153 xUpd->moveToInsertRow();
156 void SAL_CALL OBookmarkSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
160 void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
162 OCacheSet::fillValueRow(_rRow,_nPosition);
165 void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
167 if(_rValue.isBound() && _rValue.isModified())
169 if(_rValue.isNull())
170 _xParameter->updateNull(nPos);
171 else
174 switch(_rValue.getTypeKind())
176 case DataType::DECIMAL:
177 case DataType::NUMERIC:
178 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
179 break;
180 case DataType::CHAR:
181 case DataType::VARCHAR:
182 _xParameter->updateString(nPos,_rValue);
183 break;
184 case DataType::BIGINT:
185 if ( _rValue.isSigned() )
186 _xParameter->updateLong(nPos,_rValue);
187 else
188 _xParameter->updateString(nPos,_rValue);
189 break;
190 case DataType::BIT:
191 case DataType::BOOLEAN:
192 _xParameter->updateBoolean(nPos,_rValue);
193 break;
194 case DataType::TINYINT:
195 if ( _rValue.isSigned() )
196 _xParameter->updateByte(nPos,_rValue);
197 else
198 _xParameter->updateShort(nPos,_rValue);
199 break;
200 case DataType::SMALLINT:
201 if ( _rValue.isSigned() )
202 _xParameter->updateShort(nPos,_rValue);
203 else
204 _xParameter->updateInt(nPos,_rValue);
205 break;
206 case DataType::INTEGER:
207 if ( _rValue.isSigned() )
208 _xParameter->updateInt(nPos,_rValue);
209 else
210 _xParameter->updateLong(nPos,_rValue);
211 break;
212 case DataType::FLOAT:
213 _xParameter->updateFloat(nPos,_rValue);
214 break;
215 case DataType::DOUBLE:
216 case DataType::REAL:
217 _xParameter->updateDouble(nPos,_rValue);
218 break;
219 case DataType::DATE:
220 _xParameter->updateDate(nPos,_rValue);
221 break;
222 case DataType::TIME:
223 _xParameter->updateTime(nPos,_rValue);
224 break;
225 case DataType::TIMESTAMP:
226 _xParameter->updateTimestamp(nPos,_rValue);
227 break;
228 case DataType::BINARY:
229 case DataType::VARBINARY:
230 case DataType::LONGVARBINARY:
231 _xParameter->updateBytes(nPos,_rValue);
232 break;
233 case DataType::BLOB:
234 case DataType::CLOB:
235 _xParameter->updateObject(nPos,_rValue.getAny());
236 break;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */