nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / source / core / api / BookmarkSet.cxx
blobb21d7cbbb6666393e6eee01fb1c542ed37ae510d
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 <strings.hrc>
23 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
24 #include <connectivity/dbexception.hxx>
26 using namespace dbaccess;
27 using namespace ::connectivity;
28 using namespace ::dbtools;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::sdbc;
32 using namespace ::com::sun::star::sdbcx;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::lang;
35 using namespace ::osl;
37 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
39 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
40 m_xRowLocate.set(_xDriverSet,UNO_QUERY);
43 void OBookmarkSet::reset(const Reference< XResultSet>& _xDriverSet)
45 construct(_xDriverSet, m_sRowSetFilter);
48 Any OBookmarkSet::getBookmark()
50 return m_xRowLocate->getBookmark();
53 bool OBookmarkSet::moveToBookmark( const Any& bookmark )
55 return m_xRowLocate->moveToBookmark(bookmark);
58 sal_Int32 OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second )
60 return m_xRowLocate->compareBookmarks(_first,_second);
63 bool OBookmarkSet::hasOrderedBookmarks( )
65 return m_xRowLocate->hasOrderedBookmarks();
68 sal_Int32 OBookmarkSet::hashBookmark( const Any& bookmark )
70 return m_xRowLocate->hashBookmark(bookmark);
73 void OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ )
75 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
76 if(!xUpdRow.is())
77 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
79 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
80 if(xUpd.is())
82 xUpd->moveToInsertRow();
83 sal_Int32 i = 1;
84 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
85 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i)
87 aIter->setSigned(m_aSignedFlags[i-1]);
88 updateColumn(i,xUpdRow,*aIter);
90 xUpd->insertRow();
91 (*_rInsertRow->begin()) = m_xRowLocate->getBookmark();
93 else
94 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
97 void OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ )
99 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
100 if(!xUpdRow.is())
101 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
103 sal_Int32 i = 1;
104 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->begin()+1;
105 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
106 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
108 aIter->setSigned(aOrgIter->isSigned());
109 updateColumn(i,xUpdRow,*aIter);
113 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
114 if(xUpd.is())
115 xUpd->updateRow();
116 else
117 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
120 void OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ )
122 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
124 xUpd->deleteRow();
127 void OBookmarkSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _xParameter, const ORowSetValue& _rValue)
129 if(!(_rValue.isBound() && _rValue.isModified()))
130 return;
132 if(_rValue.isNull())
133 _xParameter->updateNull(nPos);
134 else
137 switch(_rValue.getTypeKind())
139 case DataType::DECIMAL:
140 case DataType::NUMERIC:
141 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
142 break;
143 case DataType::CHAR:
144 case DataType::VARCHAR:
145 _xParameter->updateString(nPos,_rValue);
146 break;
147 case DataType::BIGINT:
148 if ( _rValue.isSigned() )
149 _xParameter->updateLong(nPos,_rValue);
150 else
151 _xParameter->updateString(nPos,_rValue);
152 break;
153 case DataType::BIT:
154 case DataType::BOOLEAN:
155 _xParameter->updateBoolean(nPos,bool(_rValue));
156 break;
157 case DataType::TINYINT:
158 if ( _rValue.isSigned() )
159 _xParameter->updateByte(nPos,_rValue);
160 else
161 _xParameter->updateShort(nPos,_rValue);
162 break;
163 case DataType::SMALLINT:
164 if ( _rValue.isSigned() )
165 _xParameter->updateShort(nPos,_rValue);
166 else
167 _xParameter->updateInt(nPos,_rValue);
168 break;
169 case DataType::INTEGER:
170 if ( _rValue.isSigned() )
171 _xParameter->updateInt(nPos,_rValue);
172 else
173 _xParameter->updateLong(nPos,_rValue);
174 break;
175 case DataType::FLOAT:
176 _xParameter->updateFloat(nPos,_rValue);
177 break;
178 case DataType::DOUBLE:
179 case DataType::REAL:
180 _xParameter->updateDouble(nPos,_rValue);
181 break;
182 case DataType::DATE:
183 _xParameter->updateDate(nPos,_rValue);
184 break;
185 case DataType::TIME:
186 _xParameter->updateTime(nPos,_rValue);
187 break;
188 case DataType::TIMESTAMP:
189 _xParameter->updateTimestamp(nPos,_rValue);
190 break;
191 case DataType::BINARY:
192 case DataType::VARBINARY:
193 case DataType::LONGVARBINARY:
194 _xParameter->updateBytes(nPos,_rValue);
195 break;
196 case DataType::BLOB:
197 case DataType::CLOB:
198 _xParameter->updateObject(nPos,_rValue.getAny());
199 break;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */