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 "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
);
73 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
75 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
78 xUpd
->moveToInsertRow();
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
);
87 (*_rInsertRow
->begin()) = m_xRowLocate
->getBookmark();
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
);
97 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
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
);
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
);
123 void OBookmarkSet::updateColumn(sal_Int32 nPos
, const Reference
< XRowUpdate
>& _xParameter
, const ORowSetValue
& _rValue
)
125 if(!(_rValue
.isBound() && _rValue
.isModified()))
129 _xParameter
->updateNull(nPos
);
133 switch(_rValue
.getTypeKind())
135 case DataType::DECIMAL
:
136 case DataType::NUMERIC
:
137 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
140 case DataType::VARCHAR
:
141 _xParameter
->updateString(nPos
,_rValue
.getString());
143 case DataType::BIGINT
:
144 if ( _rValue
.isSigned() )
145 _xParameter
->updateLong(nPos
,_rValue
.getLong());
147 _xParameter
->updateString(nPos
,_rValue
.getString());
150 case DataType::BOOLEAN
:
151 _xParameter
->updateBoolean(nPos
,_rValue
.getBool());
153 case DataType::TINYINT
:
154 if ( _rValue
.isSigned() )
155 _xParameter
->updateByte(nPos
,_rValue
.getInt8());
157 _xParameter
->updateShort(nPos
,_rValue
.getInt16());
159 case DataType::SMALLINT
:
160 if ( _rValue
.isSigned() )
161 _xParameter
->updateShort(nPos
,_rValue
.getInt16());
163 _xParameter
->updateInt(nPos
,_rValue
.getInt32());
165 case DataType::INTEGER
:
166 if ( _rValue
.isSigned() )
167 _xParameter
->updateInt(nPos
,_rValue
.getInt32());
169 _xParameter
->updateLong(nPos
,_rValue
.getLong());
171 case DataType::FLOAT
:
172 _xParameter
->updateFloat(nPos
,_rValue
.getFloat());
174 case DataType::DOUBLE
:
176 _xParameter
->updateDouble(nPos
,_rValue
.getDouble());
179 _xParameter
->updateDate(nPos
,_rValue
.getDate());
182 _xParameter
->updateTime(nPos
,_rValue
.getTime());
184 case DataType::TIMESTAMP
:
185 _xParameter
->updateTimestamp(nPos
,_rValue
.getDateTime());
187 case DataType::BINARY
:
188 case DataType::VARBINARY
:
189 case DataType::LONGVARBINARY
:
190 _xParameter
->updateBytes(nPos
,_rValue
.getSequence());
194 _xParameter
->updateObject(nPos
,_rValue
.getAny());
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */