Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / api / WrappedResultSet.cxx
blob354ab1c7ab3548d9f9002ea65bba9ae60d6761a5
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 "WrappedResultSet.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 WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
41 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
42 m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
43 m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
44 m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
47 void WrappedResultSet::reset(const Reference< XResultSet>& _xDriverSet)
49 construct(_xDriverSet, m_sRowSetFilter);
52 Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException)
54 if ( m_xRowLocate.is() )
56 return m_xRowLocate->getBookmark( );
58 return makeAny(m_xDriverSet->getRow());
61 bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
63 return m_xRowLocate->moveToBookmark( bookmark );
66 bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
68 return m_xRowLocate->moveRelativeToBookmark( bookmark,rows );
71 sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
73 return m_xRowLocate->compareBookmarks( _first,_second );
76 bool SAL_CALL WrappedResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
78 return m_xRowLocate->hasOrderedBookmarks();
81 sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
83 return m_xRowLocate->hashBookmark(bookmark);
86 // ::com::sun::star::sdbcx::XDeleteRows
87 Sequence< sal_Int32 > SAL_CALL WrappedResultSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
89 Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
90 if(xDeleteRow.is())
92 return xDeleteRow->deleteRows(rows);
94 return Sequence< sal_Int32 >();
97 void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
99 m_xUpd->moveToInsertRow();
100 sal_Int32 i = 1;
101 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
102 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
104 aIter->setSigned(m_aSignedFlags[i-1]);
105 updateColumn(i,m_xUpdRow,*aIter);
107 m_xUpd->insertRow();
108 (*_rInsertRow->get().begin()) = getBookmark();
111 void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
113 sal_Int32 i = 1;
114 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->get().begin()+1;
115 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
116 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
118 aIter->setSigned(aOrgIter->isSigned());
119 updateColumn(i,m_xUpdRow,*aIter);
121 m_xUpd->updateRow();
124 void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
126 m_xUpd->deleteRow();
129 void SAL_CALL WrappedResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
131 m_xUpd->cancelRowUpdates();
134 void SAL_CALL WrappedResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
136 m_xUpd->moveToInsertRow();
139 void SAL_CALL WrappedResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
141 m_xUpd->moveToCurrentRow();
144 void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
146 OCacheSet::fillValueRow(_rRow,_nPosition);
149 void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
151 if(_rValue.isBound() && _rValue.isModified())
153 if(_rValue.isNull())
154 _xParameter->updateNull(nPos);
155 else
158 switch(_rValue.getTypeKind())
160 case DataType::DECIMAL:
161 case DataType::NUMERIC:
162 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
163 break;
164 case DataType::CHAR:
165 case DataType::VARCHAR:
166 _xParameter->updateString(nPos,_rValue);
167 break;
168 case DataType::BIGINT:
169 if ( _rValue.isSigned() )
170 _xParameter->updateLong(nPos,_rValue);
171 else
172 _xParameter->updateString(nPos,_rValue);
173 break;
174 case DataType::BIT:
175 case DataType::BOOLEAN:
176 _xParameter->updateBoolean(nPos,static_cast<bool>(_rValue));
177 break;
178 case DataType::TINYINT:
179 if ( _rValue.isSigned() )
180 _xParameter->updateByte(nPos,_rValue);
181 else
182 _xParameter->updateShort(nPos,_rValue);
183 break;
184 case DataType::SMALLINT:
185 if ( _rValue.isSigned() )
186 _xParameter->updateShort(nPos,_rValue);
187 else
188 _xParameter->updateInt(nPos,_rValue);
189 break;
190 case DataType::INTEGER:
191 if ( _rValue.isSigned() )
192 _xParameter->updateInt(nPos,_rValue);
193 else
194 _xParameter->updateLong(nPos,_rValue);
195 break;
196 case DataType::FLOAT:
197 _xParameter->updateFloat(nPos,_rValue);
198 break;
199 case DataType::DOUBLE:
200 case DataType::REAL:
201 _xParameter->updateDouble(nPos,_rValue);
202 break;
203 case DataType::DATE:
204 _xParameter->updateDate(nPos,_rValue);
205 break;
206 case DataType::TIME:
207 _xParameter->updateTime(nPos,_rValue);
208 break;
209 case DataType::TIMESTAMP:
210 _xParameter->updateTimestamp(nPos,_rValue);
211 break;
212 case DataType::BINARY:
213 case DataType::VARBINARY:
214 case DataType::LONGVARBINARY:
215 _xParameter->updateBytes(nPos,_rValue);
216 break;
217 case DataType::BLOB:
218 case DataType::CLOB:
219 _xParameter->updateObject(nPos,_rValue.getAny());
220 break;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */