Use COMReference to handle COM pointers in CreateShortcut
[LibreOffice.git] / dbaccess / source / core / api / BookmarkSet.cxx
blob75b369885e3b99758659e2e476c1e50b0347c59a
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::sdbc;
31 using namespace ::com::sun::star::sdbcx;
33 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
35 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
36 m_xRowLocate.set(_xDriverSet,UNO_QUERY);
39 void OBookmarkSet::reset(const Reference< XResultSet>& _xDriverSet)
41 construct(_xDriverSet, m_sRowSetFilter);
44 Any OBookmarkSet::getBookmark()
46 return m_xRowLocate->getBookmark();
49 bool OBookmarkSet::moveToBookmark( const Any& bookmark )
51 return m_xRowLocate->moveToBookmark(bookmark);
54 sal_Int32 OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second )
56 return m_xRowLocate->compareBookmarks(_first,_second);
59 bool OBookmarkSet::hasOrderedBookmarks( )
61 return m_xRowLocate->hasOrderedBookmarks();
64 sal_Int32 OBookmarkSet::hashBookmark( const Any& bookmark )
66 return m_xRowLocate->hashBookmark(bookmark);
69 void OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ )
71 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
72 if(!xUpdRow.is())
73 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
75 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
76 if(xUpd.is())
78 xUpd->moveToInsertRow();
79 sal_Int32 i = 1;
80 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
81 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i)
83 aIter->setSigned(m_aSignedFlags[i-1]);
84 updateColumn(i,xUpdRow,*aIter);
86 xUpd->insertRow();
87 (*_rInsertRow->begin()) = m_xRowLocate->getBookmark();
89 else
90 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
93 void OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ )
95 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
96 if(!xUpdRow.is())
97 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
99 sal_Int32 i = 1;
100 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->begin()+1;
101 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
102 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
104 aIter->setSigned(aOrgIter->isSigned());
105 updateColumn(i,xUpdRow,*aIter);
109 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
110 if(xUpd.is())
111 xUpd->updateRow();
112 else
113 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
116 void OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ )
118 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
120 xUpd->deleteRow();
123 void OBookmarkSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _xParameter, const ORowSetValue& _rValue)
125 if(!(_rValue.isBound() && _rValue.isModified()))
126 return;
128 if(_rValue.isNull())
129 _xParameter->updateNull(nPos);
130 else
133 switch(_rValue.getTypeKind())
135 case DataType::DECIMAL:
136 case DataType::NUMERIC:
137 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
138 break;
139 case DataType::CHAR:
140 case DataType::VARCHAR:
141 _xParameter->updateString(nPos,_rValue.getString());
142 break;
143 case DataType::BIGINT:
144 if ( _rValue.isSigned() )
145 _xParameter->updateLong(nPos,_rValue.getLong());
146 else
147 _xParameter->updateString(nPos,_rValue.getString());
148 break;
149 case DataType::BIT:
150 case DataType::BOOLEAN:
151 _xParameter->updateBoolean(nPos,_rValue.getBool());
152 break;
153 case DataType::TINYINT:
154 if ( _rValue.isSigned() )
155 _xParameter->updateByte(nPos,_rValue.getInt8());
156 else
157 _xParameter->updateShort(nPos,_rValue.getInt16());
158 break;
159 case DataType::SMALLINT:
160 if ( _rValue.isSigned() )
161 _xParameter->updateShort(nPos,_rValue.getInt16());
162 else
163 _xParameter->updateInt(nPos,_rValue.getInt32());
164 break;
165 case DataType::INTEGER:
166 if ( _rValue.isSigned() )
167 _xParameter->updateInt(nPos,_rValue.getInt32());
168 else
169 _xParameter->updateLong(nPos,_rValue.getLong());
170 break;
171 case DataType::FLOAT:
172 _xParameter->updateFloat(nPos,_rValue.getFloat());
173 break;
174 case DataType::DOUBLE:
175 case DataType::REAL:
176 _xParameter->updateDouble(nPos,_rValue.getDouble());
177 break;
178 case DataType::DATE:
179 _xParameter->updateDate(nPos,_rValue.getDate());
180 break;
181 case DataType::TIME:
182 _xParameter->updateTime(nPos,_rValue.getTime());
183 break;
184 case DataType::TIMESTAMP:
185 _xParameter->updateTimestamp(nPos,_rValue.getDateTime());
186 break;
187 case DataType::BINARY:
188 case DataType::VARBINARY:
189 case DataType::LONGVARBINARY:
190 _xParameter->updateBytes(nPos,_rValue.getSequence());
191 break;
192 case DataType::BLOB:
193 case DataType::CLOB:
194 _xParameter->updateObject(nPos,_rValue.getAny());
195 break;
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */