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 "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 OBookmarkSet::construct(const Reference
< XResultSet
>& _xDriverSet
,const OUString
& i_sRowSetFilter
)
41 OCacheSet::construct(_xDriverSet
,i_sRowSetFilter
);
42 m_xRowLocate
.set(_xDriverSet
,UNO_QUERY
);
45 void OBookmarkSet::reset(const Reference
< XResultSet
>& _xDriverSet
)
47 construct(_xDriverSet
, m_sRowSetFilter
);
50 Any SAL_CALL
OBookmarkSet::getBookmark() throw(SQLException
, RuntimeException
)
52 return m_xRowLocate
->getBookmark();
55 bool SAL_CALL
OBookmarkSet::moveToBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
57 return m_xRowLocate
->moveToBookmark(bookmark
);
60 bool SAL_CALL
OBookmarkSet::moveRelativeToBookmark( const Any
& bookmark
, sal_Int32 rows
) throw(SQLException
, RuntimeException
)
62 return m_xRowLocate
->moveRelativeToBookmark(bookmark
,rows
);
65 sal_Int32 SAL_CALL
OBookmarkSet::compareBookmarks( const Any
& _first
, const Any
& _second
) throw(SQLException
, RuntimeException
)
67 return m_xRowLocate
->compareBookmarks(_first
,_second
);
70 bool SAL_CALL
OBookmarkSet::hasOrderedBookmarks( ) throw(SQLException
, RuntimeException
)
72 return m_xRowLocate
->hasOrderedBookmarks();
75 sal_Int32 SAL_CALL
OBookmarkSet::hashBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
77 return m_xRowLocate
->hashBookmark(bookmark
);
80 // ::com::sun::star::sdbcx::XDeleteRows
81 Sequence
< sal_Int32
> SAL_CALL
OBookmarkSet::deleteRows( const Sequence
< Any
>& rows
,const connectivity::OSQLTable
& /*_xTable*/) throw(SQLException
, RuntimeException
)
83 Reference
< ::com::sun::star::sdbcx::XDeleteRows
> xDeleteRow(m_xRowLocate
,UNO_QUERY
);
86 return xDeleteRow
->deleteRows(rows
);
88 return Sequence
< sal_Int32
>();
91 void SAL_CALL
OBookmarkSet::insertRow( const ORowSetRow
& _rInsertRow
,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
93 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
95 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE
), SQL_GENERAL_ERROR
, *this );
97 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
100 xUpd
->moveToInsertRow();
102 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->get().end();
103 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->get().begin()+1;aIter
!= aEnd
;++aIter
,++i
)
105 aIter
->setSigned(m_aSignedFlags
[i
-1]);
106 updateColumn(i
,xUpdRow
,*aIter
);
109 (*_rInsertRow
->get().begin()) = m_xRowLocate
->getBookmark();
112 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE
), SQL_GENERAL_ERROR
, *this );
115 void SAL_CALL
OBookmarkSet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOriginalRow
,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
117 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
119 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE
), SQL_GENERAL_ERROR
, *this );
122 connectivity::ORowVector
< ORowSetValue
> ::Vector::const_iterator aOrgIter
= _rOriginalRow
->get().begin()+1;
123 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->get().end();
124 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->get().begin()+1;aIter
!= aEnd
;++aIter
,++i
,++aOrgIter
)
126 aIter
->setSigned(aOrgIter
->isSigned());
127 updateColumn(i
,xUpdRow
,*aIter
);
131 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
135 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE
), SQL_GENERAL_ERROR
, *this );
138 void SAL_CALL
OBookmarkSet::deleteRow(const ORowSetRow
& /*_rDeleteRow*/ ,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
140 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
145 void SAL_CALL
OBookmarkSet::cancelRowUpdates( ) throw(SQLException
, RuntimeException
)
149 void SAL_CALL
OBookmarkSet::moveToInsertRow( ) throw(SQLException
, RuntimeException
)
151 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
153 xUpd
->moveToInsertRow();
156 void SAL_CALL
OBookmarkSet::moveToCurrentRow( ) throw(SQLException
, RuntimeException
)
160 void OBookmarkSet::fillValueRow(ORowSetRow
& _rRow
,sal_Int32 _nPosition
)
162 OCacheSet::fillValueRow(_rRow
,_nPosition
);
165 void OBookmarkSet::updateColumn(sal_Int32 nPos
,Reference
< XRowUpdate
> _xParameter
,const ORowSetValue
& _rValue
)
167 if(_rValue
.isBound() && _rValue
.isModified())
170 _xParameter
->updateNull(nPos
);
174 switch(_rValue
.getTypeKind())
176 case DataType::DECIMAL
:
177 case DataType::NUMERIC
:
178 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
181 case DataType::VARCHAR
:
182 _xParameter
->updateString(nPos
,_rValue
);
184 case DataType::BIGINT
:
185 if ( _rValue
.isSigned() )
186 _xParameter
->updateLong(nPos
,_rValue
);
188 _xParameter
->updateString(nPos
,_rValue
);
191 case DataType::BOOLEAN
:
192 _xParameter
->updateBoolean(nPos
,_rValue
);
194 case DataType::TINYINT
:
195 if ( _rValue
.isSigned() )
196 _xParameter
->updateByte(nPos
,_rValue
);
198 _xParameter
->updateShort(nPos
,_rValue
);
200 case DataType::SMALLINT
:
201 if ( _rValue
.isSigned() )
202 _xParameter
->updateShort(nPos
,_rValue
);
204 _xParameter
->updateInt(nPos
,_rValue
);
206 case DataType::INTEGER
:
207 if ( _rValue
.isSigned() )
208 _xParameter
->updateInt(nPos
,_rValue
);
210 _xParameter
->updateLong(nPos
,_rValue
);
212 case DataType::FLOAT
:
213 _xParameter
->updateFloat(nPos
,_rValue
);
215 case DataType::DOUBLE
:
217 _xParameter
->updateDouble(nPos
,_rValue
);
220 _xParameter
->updateDate(nPos
,_rValue
);
223 _xParameter
->updateTime(nPos
,_rValue
);
225 case DataType::TIMESTAMP
:
226 _xParameter
->updateTimestamp(nPos
,_rValue
);
228 case DataType::BINARY
:
229 case DataType::VARBINARY
:
230 case DataType::LONGVARBINARY
:
231 _xParameter
->updateBytes(nPos
,_rValue
);
235 _xParameter
->updateObject(nPos
,_rValue
.getAny());
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */