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::beans
;
31 using namespace ::com::sun::star::sdbc
;
32 using namespace ::com::sun::star::sdbcx
;
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::osl
;
37 void OBookmarkSet::construct(const Reference
< XResultSet
>& _xDriverSet
,const OUString
& i_sRowSetFilter
)
39 OCacheSet::construct(_xDriverSet
,i_sRowSetFilter
);
40 m_xRowLocate
.set(_xDriverSet
,UNO_QUERY
);
43 void OBookmarkSet::reset(const Reference
< XResultSet
>& _xDriverSet
)
45 construct(_xDriverSet
, m_sRowSetFilter
);
48 Any
OBookmarkSet::getBookmark()
50 return m_xRowLocate
->getBookmark();
53 bool OBookmarkSet::moveToBookmark( const Any
& bookmark
)
55 return m_xRowLocate
->moveToBookmark(bookmark
);
58 sal_Int32
OBookmarkSet::compareBookmarks( const Any
& _first
, const Any
& _second
)
60 return m_xRowLocate
->compareBookmarks(_first
,_second
);
63 bool OBookmarkSet::hasOrderedBookmarks( )
65 return m_xRowLocate
->hasOrderedBookmarks();
68 sal_Int32
OBookmarkSet::hashBookmark( const Any
& bookmark
)
70 return m_xRowLocate
->hashBookmark(bookmark
);
73 void OBookmarkSet::insertRow( const ORowSetRow
& _rInsertRow
,const connectivity::OSQLTable
& /*_xTable*/ )
75 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
77 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
79 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
82 xUpd
->moveToInsertRow();
84 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->end();
85 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->begin()+1;aIter
!= aEnd
;++aIter
,++i
)
87 aIter
->setSigned(m_aSignedFlags
[i
-1]);
88 updateColumn(i
,xUpdRow
,*aIter
);
91 (*_rInsertRow
->begin()) = m_xRowLocate
->getBookmark();
94 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
97 void OBookmarkSet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOriginalRow
,const connectivity::OSQLTable
& /*_xTable*/ )
99 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
101 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
104 connectivity::ORowVector
< ORowSetValue
> ::Vector::const_iterator aOrgIter
= _rOriginalRow
->begin()+1;
105 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->end();
106 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->begin()+1;aIter
!= aEnd
;++aIter
,++i
,++aOrgIter
)
108 aIter
->setSigned(aOrgIter
->isSigned());
109 updateColumn(i
,xUpdRow
,*aIter
);
113 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
117 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE
), StandardSQLState::GENERAL_ERROR
, *this );
120 void OBookmarkSet::deleteRow(const ORowSetRow
& /*_rDeleteRow*/ ,const connectivity::OSQLTable
& /*_xTable*/ )
122 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
127 void OBookmarkSet::updateColumn(sal_Int32 nPos
, const Reference
< XRowUpdate
>& _xParameter
, const ORowSetValue
& _rValue
)
129 if(!(_rValue
.isBound() && _rValue
.isModified()))
133 _xParameter
->updateNull(nPos
);
137 switch(_rValue
.getTypeKind())
139 case DataType::DECIMAL
:
140 case DataType::NUMERIC
:
141 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
144 case DataType::VARCHAR
:
145 _xParameter
->updateString(nPos
,_rValue
);
147 case DataType::BIGINT
:
148 if ( _rValue
.isSigned() )
149 _xParameter
->updateLong(nPos
,_rValue
);
151 _xParameter
->updateString(nPos
,_rValue
);
154 case DataType::BOOLEAN
:
155 _xParameter
->updateBoolean(nPos
,bool(_rValue
));
157 case DataType::TINYINT
:
158 if ( _rValue
.isSigned() )
159 _xParameter
->updateByte(nPos
,_rValue
);
161 _xParameter
->updateShort(nPos
,_rValue
);
163 case DataType::SMALLINT
:
164 if ( _rValue
.isSigned() )
165 _xParameter
->updateShort(nPos
,_rValue
);
167 _xParameter
->updateInt(nPos
,_rValue
);
169 case DataType::INTEGER
:
170 if ( _rValue
.isSigned() )
171 _xParameter
->updateInt(nPos
,_rValue
);
173 _xParameter
->updateLong(nPos
,_rValue
);
175 case DataType::FLOAT
:
176 _xParameter
->updateFloat(nPos
,_rValue
);
178 case DataType::DOUBLE
:
180 _xParameter
->updateDouble(nPos
,_rValue
);
183 _xParameter
->updateDate(nPos
,_rValue
);
186 _xParameter
->updateTime(nPos
,_rValue
);
188 case DataType::TIMESTAMP
:
189 _xParameter
->updateTimestamp(nPos
,_rValue
);
191 case DataType::BINARY
:
192 case DataType::VARBINARY
:
193 case DataType::LONGVARBINARY
:
194 _xParameter
->updateBytes(nPos
,_rValue
);
198 _xParameter
->updateObject(nPos
,_rValue
.getAny());
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */