1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
);
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();
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
);
108 (*_rInsertRow
->get().begin()) = getBookmark();
111 void SAL_CALL
WrappedResultSet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOriginalRow
,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
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
);
124 void SAL_CALL
WrappedResultSet::deleteRow(const ORowSetRow
& /*_rDeleteRow*/ ,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
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())
154 _xParameter
->updateNull(nPos
);
158 switch(_rValue
.getTypeKind())
160 case DataType::DECIMAL
:
161 case DataType::NUMERIC
:
162 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
165 case DataType::VARCHAR
:
166 _xParameter
->updateString(nPos
,_rValue
);
168 case DataType::BIGINT
:
169 if ( _rValue
.isSigned() )
170 _xParameter
->updateLong(nPos
,_rValue
);
172 _xParameter
->updateString(nPos
,_rValue
);
175 case DataType::BOOLEAN
:
176 _xParameter
->updateBoolean(nPos
,static_cast<bool>(_rValue
));
178 case DataType::TINYINT
:
179 if ( _rValue
.isSigned() )
180 _xParameter
->updateByte(nPos
,_rValue
);
182 _xParameter
->updateShort(nPos
,_rValue
);
184 case DataType::SMALLINT
:
185 if ( _rValue
.isSigned() )
186 _xParameter
->updateShort(nPos
,_rValue
);
188 _xParameter
->updateInt(nPos
,_rValue
);
190 case DataType::INTEGER
:
191 if ( _rValue
.isSigned() )
192 _xParameter
->updateInt(nPos
,_rValue
);
194 _xParameter
->updateLong(nPos
,_rValue
);
196 case DataType::FLOAT
:
197 _xParameter
->updateFloat(nPos
,_rValue
);
199 case DataType::DOUBLE
:
201 _xParameter
->updateDouble(nPos
,_rValue
);
204 _xParameter
->updateDate(nPos
,_rValue
);
207 _xParameter
->updateTime(nPos
,_rValue
);
209 case DataType::TIMESTAMP
:
210 _xParameter
->updateTimestamp(nPos
,_rValue
);
212 case DataType::BINARY
:
213 case DataType::VARBINARY
:
214 case DataType::LONGVARBINARY
:
215 _xParameter
->updateBytes(nPos
,_rValue
);
219 _xParameter
->updateObject(nPos
,_rValue
.getAny());
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */