LibreOffice Module dbaccess (master) 1
WrappedResultSet.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "WrappedResultSet.hxx"
21#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
22
23using namespace dbaccess;
24using namespace ::connectivity;
25using namespace ::com::sun::star::uno;
26using namespace ::com::sun::star::beans;
27using namespace ::com::sun::star::sdbc;
28using namespace ::com::sun::star::sdbcx;
29using namespace ::com::sun::star::container;
30using namespace ::com::sun::star::lang;
31using namespace ::osl;
32
33void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
34{
35 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
36 m_xUpd.set(_xDriverSet,UNO_QUERY_THROW);
37 m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW);
38 m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW);
39}
40
41void WrappedResultSet::reset(const Reference< XResultSet>& _xDriverSet)
42{
43 construct(_xDriverSet, m_sRowSetFilter);
44}
45
47{
48 if ( m_xRowLocate.is() )
49 {
50 return m_xRowLocate->getBookmark( );
51 }
52 return Any(m_xDriverSet->getRow());
53}
54
55bool WrappedResultSet::moveToBookmark( const Any& bookmark )
56{
57 return m_xRowLocate->moveToBookmark( bookmark );
58}
59
60sal_Int32 WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second )
61{
62 return m_xRowLocate->compareBookmarks( _first,_second );
63}
64
66{
67 return m_xRowLocate->hasOrderedBookmarks();
68}
69
70sal_Int32 WrappedResultSet::hashBookmark( const Any& bookmark )
71{
72 return m_xRowLocate->hashBookmark(bookmark);
73}
74
75void WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ )
76{
77 m_xUpd->moveToInsertRow();
78 sal_Int32 i = 1;
79 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aEnd = _rInsertRow->end();
80 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i)
81 {
82 aIter->setSigned(m_aSignedFlags[i-1]);
83 updateColumn(i,m_xUpdRow,*aIter);
84 }
85 m_xUpd->insertRow();
86 (*_rInsertRow->begin()) = getBookmark();
87}
88
89void WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ )
90{
91 sal_Int32 i = 1;
92 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->begin()+1;
93 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
94 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
95 {
96 aIter->setSigned(aOrgIter->isSigned());
97 updateColumn(i,m_xUpdRow,*aIter);
98 }
99 m_xUpd->updateRow();
100}
101
102void WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ )
103{
104 m_xUpd->deleteRow();
105}
106
107void WrappedResultSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _xParameter, const ORowSetValue& _rValue)
108{
109 if(!(_rValue.isBound() && _rValue.isModified()))
110 return;
111
112 if(_rValue.isNull())
113 _xParameter->updateNull(nPos);
114 else
115 {
116
117 switch(_rValue.getTypeKind())
118 {
119 case DataType::DECIMAL:
120 case DataType::NUMERIC:
121 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
122 break;
123 case DataType::CHAR:
124 case DataType::VARCHAR:
125 _xParameter->updateString(nPos,_rValue.getString());
126 break;
127 case DataType::BIGINT:
128 if ( _rValue.isSigned() )
129 _xParameter->updateLong(nPos,_rValue.getLong());
130 else
131 _xParameter->updateString(nPos,_rValue.getString());
132 break;
133 case DataType::BIT:
134 case DataType::BOOLEAN:
135 _xParameter->updateBoolean(nPos,_rValue.getBool());
136 break;
137 case DataType::TINYINT:
138 if ( _rValue.isSigned() )
139 _xParameter->updateByte(nPos,_rValue.getInt8());
140 else
141 _xParameter->updateShort(nPos,_rValue.getInt16());
142 break;
143 case DataType::SMALLINT:
144 if ( _rValue.isSigned() )
145 _xParameter->updateShort(nPos,_rValue.getInt16());
146 else
147 _xParameter->updateInt(nPos,_rValue.getInt32());
148 break;
149 case DataType::INTEGER:
150 if ( _rValue.isSigned() )
151 _xParameter->updateInt(nPos,_rValue.getInt32());
152 else
153 _xParameter->updateLong(nPos,_rValue.getLong());
154 break;
155 case DataType::FLOAT:
156 _xParameter->updateFloat(nPos,_rValue.getFloat());
157 break;
158 case DataType::DOUBLE:
159 case DataType::REAL:
160 _xParameter->updateDouble(nPos,_rValue.getDouble());
161 break;
162 case DataType::DATE:
163 _xParameter->updateDate(nPos,_rValue.getDate());
164 break;
165 case DataType::TIME:
166 _xParameter->updateTime(nPos,_rValue.getTime());
167 break;
168 case DataType::TIMESTAMP:
169 _xParameter->updateTimestamp(nPos,_rValue.getDateTime());
170 break;
171 case DataType::BINARY:
172 case DataType::VARBINARY:
173 case DataType::LONGVARBINARY:
174 _xParameter->updateBytes(nPos,_rValue.getSequence());
175 break;
176 case DataType::BLOB:
177 case DataType::CLOB:
178 _xParameter->updateObject(nPos,_rValue.getAny());
179 break;
180 }
181 }
182}
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::util::Time getTime() const
sal_Int32 getInt32() const
OUString getString() const
css::uno::Any makeAny() const
sal_Int32 getTypeKind() const
sal_Int8 getInt8() const
sal_Int16 getInt16() const
css::util::Date getDate() const
css::util::DateTime getDateTime() const
sal_Int64 getLong() const
const css::uno::Any & getAny() const
css::uno::Sequence< sal_Int8 > getSequence() const
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xSetMetaData
Definition: CacheSet.hxx:40
css::uno::Reference< css::sdbc::XResultSet > m_xDriverSet
Definition: CacheSet.hxx:38
std::vector< bool > m_aSignedFlags
Definition: CacheSet.hxx:44
OUString m_sRowSetFilter
Definition: CacheSet.hxx:51
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter)
Definition: CacheSet.cxx:74
virtual sal_Int32 compareBookmarks(const css::uno::Any &first, const css::uno::Any &second) override
virtual void insertRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
void updateColumn(sal_Int32 nPos, const css::uno::Reference< css::sdbc::XRowUpdate > &_xParameter, const connectivity::ORowSetValue &_rValue)
virtual void updateRow(const ORowSetRow &_rInsertRow, const ORowSetRow &_rOriginalRow, const connectivity::OSQLTable &_xTable) override
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter) override
virtual bool moveToBookmark(const css::uno::Any &bookmark) override
virtual void deleteRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
css::uno::Reference< css::sdbc::XResultSetUpdate > m_xUpd
virtual bool hasOrderedBookmarks() override
virtual void reset(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet) override
virtual sal_Int32 hashBookmark(const css::uno::Any &bookmark) override
virtual css::uno::Any getBookmark() override
css::uno::Reference< css::sdbcx::XRowLocate > m_xRowLocate
css::uno::Reference< css::sdbc::XRowUpdate > m_xUpdRow
sal_uInt16 nPos
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
int i