Files
libreoffice/dbaccess/source/core/api/BookmarkSet.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

205 lines
7.4 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-14 17:39:53 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 23:16:46 +00:00
#include "BookmarkSet.hxx"
#include <core_resource.hxx>
#include <strings.hrc>
2000-09-18 23:16:46 +00:00
#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
#include <connectivity/dbexception.hxx>
2000-09-18 23:16:46 +00:00
using namespace dbaccess;
using namespace ::connectivity;
using namespace ::dbtools;
2000-09-18 23:16:46 +00:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::osl;
void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
2001-10-30 13:22:10 +00:00
{
OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
m_xRowLocate.set(_xDriverSet,UNO_QUERY);
2001-10-30 13:22:10 +00:00
}
void OBookmarkSet::reset(const Reference< XResultSet>& _xDriverSet)
{
construct(_xDriverSet, m_sRowSetFilter);
}
Any OBookmarkSet::getBookmark()
2001-10-30 13:22:10 +00:00
{
return m_xRowLocate->getBookmark();
}
bool OBookmarkSet::moveToBookmark( const Any& bookmark )
2001-10-30 13:22:10 +00:00
{
return m_xRowLocate->moveToBookmark(bookmark);
}
sal_Int32 OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second )
2001-10-30 13:22:10 +00:00
{
return m_xRowLocate->compareBookmarks(_first,_second);
2001-10-30 13:22:10 +00:00
}
bool OBookmarkSet::hasOrderedBookmarks( )
2001-10-30 13:22:10 +00:00
{
return m_xRowLocate->hasOrderedBookmarks();
}
sal_Int32 OBookmarkSet::hashBookmark( const Any& bookmark )
2001-10-30 13:22:10 +00:00
{
return m_xRowLocate->hashBookmark(bookmark);
}
void OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ )
2000-09-18 23:16:46 +00:00
{
Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
if(!xUpdRow.is())
::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
2000-09-18 23:16:46 +00:00
Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
if(xUpd.is())
2000-09-29 14:23:36 +00:00
{
xUpd->moveToInsertRow();
sal_Int32 i = 1;
connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i)
{
aIter->setSigned(m_aSignedFlags[i-1]);
2000-09-29 14:23:36 +00:00
updateColumn(i,xUpdRow,*aIter);
}
2000-09-18 23:16:46 +00:00
xUpd->insertRow();
(*_rInsertRow->begin()) = m_xRowLocate->getBookmark();
2000-09-29 14:23:36 +00:00
}
2000-09-18 23:16:46 +00:00
else
::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
2000-09-18 23:16:46 +00:00
}
void OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ )
2000-09-18 23:16:46 +00:00
{
Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
if(!xUpdRow.is())
::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
2000-09-18 23:16:46 +00:00
sal_Int32 i = 1;
connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->begin()+1;
connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
2000-09-29 14:23:36 +00:00
{
aIter->setSigned(aOrgIter->isSigned());
2000-09-18 23:16:46 +00:00
updateColumn(i,xUpdRow,*aIter);
2000-09-29 14:23:36 +00:00
}
2000-09-18 23:16:46 +00:00
Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
if(xUpd.is())
xUpd->updateRow();
else
::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
2000-09-18 23:16:46 +00:00
}
void OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ )
2000-09-18 23:16:46 +00:00
{
2000-09-29 14:23:36 +00:00
Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
xUpd->deleteRow();
2000-09-18 23:16:46 +00:00
}
void OBookmarkSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _xParameter, const ORowSetValue& _rValue)
2000-09-18 23:16:46 +00:00
{
if(!(_rValue.isBound() && _rValue.isModified()))
return;
if(_rValue.isNull())
_xParameter->updateNull(nPos);
else
2000-09-18 23:16:46 +00:00
{
switch(_rValue.getTypeKind())
{
case DataType::DECIMAL:
case DataType::NUMERIC:
_xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
break;
case DataType::CHAR:
case DataType::VARCHAR:
_xParameter->updateString(nPos,_rValue.getString());
break;
case DataType::BIGINT:
if ( _rValue.isSigned() )
_xParameter->updateLong(nPos,_rValue.getLong());
else
_xParameter->updateString(nPos,_rValue.getString());
break;
case DataType::BIT:
case DataType::BOOLEAN:
_xParameter->updateBoolean(nPos,_rValue.getBool());
break;
case DataType::TINYINT:
if ( _rValue.isSigned() )
_xParameter->updateByte(nPos,_rValue.getInt8());
else
_xParameter->updateShort(nPos,_rValue.getInt16());
break;
case DataType::SMALLINT:
if ( _rValue.isSigned() )
_xParameter->updateShort(nPos,_rValue.getInt16());
else
_xParameter->updateInt(nPos,_rValue.getInt32());
break;
case DataType::INTEGER:
if ( _rValue.isSigned() )
_xParameter->updateInt(nPos,_rValue.getInt32());
else
_xParameter->updateLong(nPos,_rValue.getLong());
break;
case DataType::FLOAT:
_xParameter->updateFloat(nPos,_rValue.getFloat());
break;
case DataType::DOUBLE:
case DataType::REAL:
_xParameter->updateDouble(nPos,_rValue.getDouble());
break;
case DataType::DATE:
_xParameter->updateDate(nPos,_rValue.getDate());
break;
case DataType::TIME:
_xParameter->updateTime(nPos,_rValue.getTime());
break;
case DataType::TIMESTAMP:
_xParameter->updateTimestamp(nPos,_rValue.getDateTime());
break;
case DataType::BINARY:
case DataType::VARBINARY:
case DataType::LONGVARBINARY:
_xParameter->updateBytes(nPos,_rValue.getSequence());
break;
case DataType::BLOB:
case DataType::CLOB:
_xParameter->updateObject(nPos,_rValue.getAny());
break;
2000-09-18 23:16:46 +00:00
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */