1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2008 by Sun Microsystems, Inc. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * $RCSfile: BookmarkSet.cxx,v $ 10 * $Revision: 1.21 $ 11 * 12 * This file is part of OpenOffice.org. 13 * 14 * OpenOffice.org is free software: you can redistribute it and/or modify 15 * it under the terms of the GNU Lesser General Public License version 3 16 * only, as published by the Free Software Foundation. 17 * 18 * OpenOffice.org is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU Lesser General Public License version 3 for more details 22 * (a copy is included in the LICENSE file that accompanied this code). 23 * 24 * You should have received a copy of the GNU Lesser General Public License 25 * version 3 along with OpenOffice.org. If not, see 26 * <http://www.openoffice.org/license.html> 27 * for a copy of the LGPLv3 License. 28 * 29 ************************************************************************/ 30 31 // MARKER(update_precomp.py): autogen include statement, do not remove 32 #include "precompiled_dbaccess.hxx" 33 #include "WrappedResultSet.hxx" 34 #include "core_resource.hxx" 35 #include "core_resource.hrc" 36 #include <com/sun/star/sdbc/XResultSetUpdate.hpp> 37 #include <connectivity/dbexception.hxx> 38 #include <rtl/logfile.hxx> 39 40 #include <limits> 41 42 using namespace dbaccess; 43 using namespace ::connectivity; 44 using namespace ::dbtools; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::beans; 47 using namespace ::com::sun::star::sdbc; 48 // using namespace ::com::sun::star::sdb; 49 using namespace ::com::sun::star::sdbcx; 50 using namespace ::com::sun::star::container; 51 using namespace ::com::sun::star::lang; 52 // using namespace ::cppu; 53 using namespace ::osl; 54 55 void WrappedResultSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) 56 { 57 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::construct" ); 58 OCacheSet::construct(_xDriverSet,i_sRowSetFilter); 59 m_xUpd.set(_xDriverSet,UNO_QUERY_THROW); 60 m_xRowLocate.set(_xDriverSet,UNO_QUERY_THROW); 61 m_xUpdRow.set(_xDriverSet,UNO_QUERY_THROW); 62 } 63 // ----------------------------------------------------------------------------- 64 Any SAL_CALL WrappedResultSet::getBookmark() throw(SQLException, RuntimeException) 65 { 66 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::getBookmark" ); 67 if ( m_xRowLocate.is() ) 68 { 69 return m_xRowLocate->getBookmark( ); 70 } 71 return makeAny(m_xDriverSet->getRow()); 72 } 73 // ------------------------------------------------------------------------- 74 sal_Bool SAL_CALL WrappedResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) 75 { 76 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToBookmark" ); 77 return m_xRowLocate->moveToBookmark( bookmark ); 78 } 79 // ------------------------------------------------------------------------- 80 sal_Bool SAL_CALL WrappedResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException) 81 { 82 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveRelativeToBookmark" ); 83 return m_xRowLocate->moveRelativeToBookmark( bookmark,rows ); 84 } 85 // ------------------------------------------------------------------------- 86 sal_Int32 SAL_CALL WrappedResultSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException) 87 { 88 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::compareBookmarks" ); 89 return m_xRowLocate->compareBookmarks( _first,_second ); 90 } 91 // ------------------------------------------------------------------------- 92 sal_Bool SAL_CALL WrappedResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException) 93 { 94 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hasOrderedBookmarks" ); 95 return m_xRowLocate->hasOrderedBookmarks(); 96 } 97 // ------------------------------------------------------------------------- 98 sal_Int32 SAL_CALL WrappedResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException) 99 { 100 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::hashBookmark" ); 101 return m_xRowLocate->hashBookmark(bookmark); 102 } 103 // ------------------------------------------------------------------------- 104 // ::com::sun::star::sdbcx::XDeleteRows 105 Sequence< sal_Int32 > SAL_CALL WrappedResultSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException) 106 { 107 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRows" ); 108 Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY); 109 if(xDeleteRow.is()) 110 { 111 return xDeleteRow->deleteRows(rows); 112 } 113 return Sequence< sal_Int32 >(); 114 } 115 // ------------------------------------------------------------------------- 116 void SAL_CALL WrappedResultSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) 117 { 118 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::insertRow" ); 119 120 m_xUpd->moveToInsertRow(); 121 sal_Int32 i = 1; 122 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end(); 123 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i) 124 { 125 aIter->setSigned(m_aSignedFlags[i-1]); 126 updateColumn(i,m_xUpdRow,*aIter); 127 } 128 m_xUpd->insertRow(); 129 (*_rInsertRow->get().begin()) = getBookmark(); 130 } 131 // ------------------------------------------------------------------------- 132 void SAL_CALL WrappedResultSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) 133 { 134 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateRow" ); 135 sal_Int32 i = 1; 136 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1; 137 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end(); 138 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter) 139 { 140 aIter->setSigned(aOrgIter->isSigned()); 141 updateColumn(i,m_xUpdRow,*aIter); 142 } 143 m_xUpd->updateRow(); 144 } 145 // ------------------------------------------------------------------------- 146 void SAL_CALL WrappedResultSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException) 147 { 148 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::deleteRow" ); 149 m_xUpd->deleteRow(); 150 } 151 // ------------------------------------------------------------------------- 152 void SAL_CALL WrappedResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException) 153 { 154 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::cancelRowUpdates" ); 155 m_xUpd->cancelRowUpdates(); 156 } 157 // ------------------------------------------------------------------------- 158 void SAL_CALL WrappedResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException) 159 { 160 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToInsertRow" ); 161 m_xUpd->moveToInsertRow(); 162 } 163 // ------------------------------------------------------------------------- 164 void SAL_CALL WrappedResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException) 165 { 166 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::moveToCurrentRow" ); 167 m_xUpd->moveToCurrentRow(); 168 } 169 // ------------------------------------------------------------------------- 170 void WrappedResultSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition) 171 { 172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::fillValueRow" ); 173 OCacheSet::fillValueRow(_rRow,_nPosition); 174 } 175 // ------------------------------------------------------------------------- 176 void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue) 177 { 178 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "WrappedResultSet::updateColumn" ); 179 if(_rValue.isBound() && _rValue.isModified()) 180 { 181 if(_rValue.isNull()) 182 _xParameter->updateNull(nPos); 183 else 184 { 185 186 switch(_rValue.getTypeKind()) 187 { 188 case DataType::DECIMAL: 189 case DataType::NUMERIC: 190 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos)); 191 break; 192 case DataType::CHAR: 193 case DataType::VARCHAR: 194 //case DataType::DECIMAL: 195 //case DataType::NUMERIC: 196 _xParameter->updateString(nPos,_rValue); 197 break; 198 case DataType::BIGINT: 199 if ( _rValue.isSigned() ) 200 _xParameter->updateLong(nPos,_rValue); 201 else 202 _xParameter->updateString(nPos,_rValue); 203 break; 204 case DataType::BIT: 205 case DataType::BOOLEAN: 206 _xParameter->updateBoolean(nPos,_rValue); 207 break; 208 case DataType::TINYINT: 209 if ( _rValue.isSigned() ) 210 _xParameter->updateByte(nPos,_rValue); 211 else 212 _xParameter->updateShort(nPos,_rValue); 213 break; 214 case DataType::SMALLINT: 215 if ( _rValue.isSigned() ) 216 _xParameter->updateShort(nPos,_rValue); 217 else 218 _xParameter->updateInt(nPos,_rValue); 219 break; 220 case DataType::INTEGER: 221 if ( _rValue.isSigned() ) 222 _xParameter->updateInt(nPos,_rValue); 223 else 224 _xParameter->updateLong(nPos,_rValue); 225 break; 226 case DataType::FLOAT: 227 _xParameter->updateFloat(nPos,_rValue); 228 break; 229 case DataType::DOUBLE: 230 case DataType::REAL: 231 _xParameter->updateDouble(nPos,_rValue); 232 break; 233 case DataType::DATE: 234 _xParameter->updateDate(nPos,_rValue); 235 break; 236 case DataType::TIME: 237 _xParameter->updateTime(nPos,_rValue); 238 break; 239 case DataType::TIMESTAMP: 240 _xParameter->updateTimestamp(nPos,_rValue); 241 break; 242 case DataType::BINARY: 243 case DataType::VARBINARY: 244 case DataType::LONGVARBINARY: 245 _xParameter->updateBytes(nPos,_rValue); 246 break; 247 case DataType::BLOB: 248 case DataType::CLOB: 249 _xParameter->updateObject(nPos,_rValue.getAny()); 250 break; 251 } 252 } 253 } 254 } 255 256