Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / WrappedResultSet.cxx
blobd4d600559cf779d28525286a1c363d6ebcacf083
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>
25 #include <rtl/logfile.hxx>
27 #include <limits>
29 using namespace dbaccess;
30 using namespace ::connectivity;
31 using namespace ::dbtools;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
38 using namespace ::osl;
40 void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
42 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::construct" );
43 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
44 m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
45 m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
46 m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
49 Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException)
51 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::getBookmark" );
52 if ( m_xRowLocate.is() )
54 return m_xRowLocate->getBookmark( );
56 return makeAny(m_xDriverSet->getRow());
59 sal_Bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
61 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToBookmark" );
62 return m_xRowLocate->moveToBookmark( bookmark );
65 sal_Bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
67 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveRelativeToBookmark" );
68 return m_xRowLocate->moveRelativeToBookmark( bookmark,rows );
71 sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
73 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::compareBookmarks" );
74 return m_xRowLocate->compareBookmarks( _first,_second );
77 sal_Bool SAL_CALL WrappedResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
79 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hasOrderedBookmarks" );
80 return m_xRowLocate->hasOrderedBookmarks();
83 sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
85 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hashBookmark" );
86 return m_xRowLocate->hashBookmark(bookmark);
89 // ::com::sun::star::sdbcx::XDeleteRows
90 Sequence< sal_Int32 > SAL_CALL WrappedResultSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
92 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRows" );
93 Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
94 if(xDeleteRow.is())
96 return xDeleteRow->deleteRows(rows);
98 return Sequence< sal_Int32 >();
101 void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
103 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::insertRow" );
105 m_xUpd->moveToInsertRow();
106 sal_Int32 i = 1;
107 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
108 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
110 aIter->setSigned(m_aSignedFlags[i-1]);
111 updateColumn(i,m_xUpdRow,*aIter);
113 m_xUpd->insertRow();
114 (*_rInsertRow->get().begin()) = getBookmark();
117 void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
119 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateRow" );
120 sal_Int32 i = 1;
121 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
122 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
123 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
125 aIter->setSigned(aOrgIter->isSigned());
126 updateColumn(i,m_xUpdRow,*aIter);
128 m_xUpd->updateRow();
131 void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
133 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRow" );
134 m_xUpd->deleteRow();
137 void SAL_CALL WrappedResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
139 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::cancelRowUpdates" );
140 m_xUpd->cancelRowUpdates();
143 void SAL_CALL WrappedResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
145 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToInsertRow" );
146 m_xUpd->moveToInsertRow();
149 void SAL_CALL WrappedResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
151 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToCurrentRow" );
152 m_xUpd->moveToCurrentRow();
155 void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
157 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::fillValueRow" );
158 OCacheSet::fillValueRow(_rRow,_nPosition);
161 void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
163 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateColumn" );
164 if(_rValue.isBound() && _rValue.isModified())
166 if(_rValue.isNull())
167 _xParameter->updateNull(nPos);
168 else
171 switch(_rValue.getTypeKind())
173 case DataType::DECIMAL:
174 case DataType::NUMERIC:
175 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
176 break;
177 case DataType::CHAR:
178 case DataType::VARCHAR:
179 _xParameter->updateString(nPos,_rValue);
180 break;
181 case DataType::BIGINT:
182 if ( _rValue.isSigned() )
183 _xParameter->updateLong(nPos,_rValue);
184 else
185 _xParameter->updateString(nPos,_rValue);
186 break;
187 case DataType::BIT:
188 case DataType::BOOLEAN:
189 _xParameter->updateBoolean(nPos,_rValue);
190 break;
191 case DataType::TINYINT:
192 if ( _rValue.isSigned() )
193 _xParameter->updateByte(nPos,_rValue);
194 else
195 _xParameter->updateShort(nPos,_rValue);
196 break;
197 case DataType::SMALLINT:
198 if ( _rValue.isSigned() )
199 _xParameter->updateShort(nPos,_rValue);
200 else
201 _xParameter->updateInt(nPos,_rValue);
202 break;
203 case DataType::INTEGER:
204 if ( _rValue.isSigned() )
205 _xParameter->updateInt(nPos,_rValue);
206 else
207 _xParameter->updateLong(nPos,_rValue);
208 break;
209 case DataType::FLOAT:
210 _xParameter->updateFloat(nPos,_rValue);
211 break;
212 case DataType::DOUBLE:
213 case DataType::REAL:
214 _xParameter->updateDouble(nPos,_rValue);
215 break;
216 case DataType::DATE:
217 _xParameter->updateDate(nPos,_rValue);
218 break;
219 case DataType::TIME:
220 _xParameter->updateTime(nPos,_rValue);
221 break;
222 case DataType::TIMESTAMP:
223 _xParameter->updateTimestamp(nPos,_rValue);
224 break;
225 case DataType::BINARY:
226 case DataType::VARBINARY:
227 case DataType::LONGVARBINARY:
228 _xParameter->updateBytes(nPos,_rValue);
229 break;
230 case DataType::BLOB:
231 case DataType::CLOB:
232 _xParameter->updateObject(nPos,_rValue.getAny());
233 break;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */