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 <com/sun/star/sdbc/XResultSetUpdate.hpp>
23 using namespace dbaccess
;
24 using namespace ::connectivity
;
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::beans
;
27 using namespace ::com::sun::star::sdbc
;
28 using namespace ::com::sun::star::sdbcx
;
29 using namespace ::com::sun::star::container
;
30 using namespace ::com::sun::star::lang
;
31 using namespace ::osl
;
33 void WrappedResultSet::construct(const Reference
< XResultSet
>& _xDriverSet
,const OUString
& i_sRowSetFilter
)
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
);
41 void WrappedResultSet::reset(const Reference
< XResultSet
>& _xDriverSet
)
43 construct(_xDriverSet
, m_sRowSetFilter
);
46 Any
WrappedResultSet::getBookmark()
48 if ( m_xRowLocate
.is() )
50 return m_xRowLocate
->getBookmark( );
52 return Any(m_xDriverSet
->getRow());
55 bool WrappedResultSet::moveToBookmark( const Any
& bookmark
)
57 return m_xRowLocate
->moveToBookmark( bookmark
);
60 sal_Int32
WrappedResultSet::compareBookmarks( const Any
& _first
, const Any
& _second
)
62 return m_xRowLocate
->compareBookmarks( _first
,_second
);
65 bool WrappedResultSet::hasOrderedBookmarks( )
67 return m_xRowLocate
->hasOrderedBookmarks();
70 sal_Int32
WrappedResultSet::hashBookmark( const Any
& bookmark
)
72 return m_xRowLocate
->hashBookmark(bookmark
);
75 void WrappedResultSet::insertRow( const ORowSetRow
& _rInsertRow
,const connectivity::OSQLTable
& /*_xTable*/ )
77 m_xUpd
->moveToInsertRow();
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
)
82 aIter
->setSigned(m_aSignedFlags
[i
-1]);
83 updateColumn(i
,m_xUpdRow
,*aIter
);
86 (*_rInsertRow
->begin()) = getBookmark();
89 void WrappedResultSet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOriginalRow
,const connectivity::OSQLTable
& /*_xTable*/ )
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
)
96 aIter
->setSigned(aOrgIter
->isSigned());
97 updateColumn(i
,m_xUpdRow
,*aIter
);
102 void WrappedResultSet::deleteRow(const ORowSetRow
& /*_rDeleteRow*/ ,const connectivity::OSQLTable
& /*_xTable*/ )
107 void WrappedResultSet::updateColumn(sal_Int32 nPos
, const Reference
< XRowUpdate
>& _xParameter
, const ORowSetValue
& _rValue
)
109 if(!(_rValue
.isBound() && _rValue
.isModified()))
113 _xParameter
->updateNull(nPos
);
117 switch(_rValue
.getTypeKind())
119 case DataType::DECIMAL
:
120 case DataType::NUMERIC
:
121 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
124 case DataType::VARCHAR
:
125 _xParameter
->updateString(nPos
,_rValue
.getString());
127 case DataType::BIGINT
:
128 if ( _rValue
.isSigned() )
129 _xParameter
->updateLong(nPos
,_rValue
.getLong());
131 _xParameter
->updateString(nPos
,_rValue
.getString());
134 case DataType::BOOLEAN
:
135 _xParameter
->updateBoolean(nPos
,_rValue
.getBool());
137 case DataType::TINYINT
:
138 if ( _rValue
.isSigned() )
139 _xParameter
->updateByte(nPos
,_rValue
.getInt8());
141 _xParameter
->updateShort(nPos
,_rValue
.getInt16());
143 case DataType::SMALLINT
:
144 if ( _rValue
.isSigned() )
145 _xParameter
->updateShort(nPos
,_rValue
.getInt16());
147 _xParameter
->updateInt(nPos
,_rValue
.getInt32());
149 case DataType::INTEGER
:
150 if ( _rValue
.isSigned() )
151 _xParameter
->updateInt(nPos
,_rValue
.getInt32());
153 _xParameter
->updateLong(nPos
,_rValue
.getLong());
155 case DataType::FLOAT
:
156 _xParameter
->updateFloat(nPos
,_rValue
.getFloat());
158 case DataType::DOUBLE
:
160 _xParameter
->updateDouble(nPos
,_rValue
.getDouble());
163 _xParameter
->updateDate(nPos
,_rValue
.getDate());
166 _xParameter
->updateTime(nPos
,_rValue
.getTime());
168 case DataType::TIMESTAMP
:
169 _xParameter
->updateTimestamp(nPos
,_rValue
.getDateTime());
171 case DataType::BINARY
:
172 case DataType::VARBINARY
:
173 case DataType::LONGVARBINARY
:
174 _xParameter
->updateBytes(nPos
,_rValue
.getSequence());
178 _xParameter
->updateObject(nPos
,_rValue
.getAny());
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */