update dev300-m58
[ooovba.git] / dbaccess / source / core / api / CacheSet.cxx
blob796cf39f40e530912b38d20987eab732272264fd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CacheSet.cxx,v $
10 * $Revision: 1.46 $
12 * This file is part of OpenOffice.org.
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.
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).
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBACCESS_CORE_API_CACHESET_HXX
34 #include "CacheSet.hxx"
35 #endif
36 #ifndef _DBA_CORE_RESOURCE_HXX_
37 #include "core_resource.hxx"
38 #endif
39 #ifndef _DBA_CORE_RESOURCE_HRC_
40 #include "core_resource.hrc"
41 #endif
42 #ifndef _COM_SUN_STAR_SDBCX_COMPAREBOOKMARK_HPP_
43 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETMETADATASUPPLIER_HPP_
46 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
49 #include <com/sun/star/beans/XPropertySet.hpp>
50 #endif
51 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
52 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_SDBC_XPREPAREDSTATEMENT_HPP_
55 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
56 #endif
57 #include <com/sun/star/sdbc/ColumnValue.hpp>
58 #ifndef _COM_SUN_STAR_SDBC_XPARAMETERS_HPP_
59 #include <com/sun/star/sdbc/XParameters.hpp>
60 #endif
61 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
62 #include "dbastrings.hrc"
63 #endif
64 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
65 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_SDBCX_XINDEXESSUPPLIER_HPP_
68 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
69 #endif
71 #include <limits>
73 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
74 #include <connectivity/dbtools.hxx>
75 #endif
76 #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
77 #include <com/sun/star/sdbcx/KeyType.hpp>
78 #endif
79 #ifndef _COMPHELPER_EXTRACT_HXX_
80 #include <comphelper/extract.hxx>
81 #endif
82 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_
83 #include <com/sun/star/io/XInputStream.hpp>
84 #endif
85 #ifndef _COMPHELPER_TYPES_HXX_
86 #include <comphelper/types.hxx>
87 #endif
88 #ifndef _TOOLS_DEBUG_HXX
89 #include <tools/debug.hxx>
90 #endif
91 #include <rtl/ustrbuf.hxx>
92 #include <rtl/logfile.hxx>
94 using namespace comphelper;
96 using namespace dbaccess;
97 using namespace dbtools;
98 using namespace connectivity;
99 using namespace ::com::sun::star::uno;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::sdbc;
102 // using namespace ::com::sun::star::sdb;
103 using namespace ::com::sun::star::sdbcx;
104 using namespace ::com::sun::star::container;
105 using namespace ::com::sun::star::lang;
106 using namespace ::com::sun::star::io;
107 // using namespace ::cppu;
108 using namespace ::osl;
110 DBG_NAME(OCacheSet)
111 // -------------------------------------------------------------------------
112 OCacheSet::OCacheSet()
113 :m_bInserted(sal_False)
114 ,m_bUpdated(sal_False)
115 ,m_bDeleted(sal_False)
117 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::OCacheSet" );
118 DBG_CTOR(OCacheSet,NULL);
121 // -------------------------------------------------------------------------
122 ::rtl::OUString OCacheSet::getIdentifierQuoteString() const
124 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getIdentifierQuoteString" );
125 ::rtl::OUString sQuote;
126 Reference<XDatabaseMetaData> xMeta;
127 if ( m_xConnection.is() && (xMeta = m_xConnection->getMetaData()).is() )
128 sQuote = xMeta->getIdentifierQuoteString();
129 return sQuote;
131 // -------------------------------------------------------------------------
132 void OCacheSet::construct( const Reference< XResultSet>& _xDriverSet)
134 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::construct" );
135 OSL_ENSURE(_xDriverSet.is(),"Invalid resultSet");
136 if(_xDriverSet.is())
138 m_xDriverSet = _xDriverSet;
139 m_xDriverRow.set(_xDriverSet,UNO_QUERY);
140 m_xSetMetaData = Reference<XResultSetMetaDataSupplier>(_xDriverSet,UNO_QUERY)->getMetaData();
141 if ( m_xSetMetaData.is() )
143 const sal_Int32 nCount = m_xSetMetaData->getColumnCount();
144 m_aNullable.realloc(nCount);
145 m_aSignedFlags.realloc(nCount);
146 m_aColumnTypes.realloc(nCount);
147 sal_Bool* pNullableIter = m_aNullable.getArray();
148 sal_Bool* pSignedIter = m_aSignedFlags.getArray();
149 sal_Int32* pColumnIter = m_aColumnTypes.getArray();
150 for (sal_Int32 i=1; i <= nCount; ++i,++pSignedIter,++pColumnIter,++pNullableIter)
152 *pNullableIter = m_xSetMetaData->isNullable(i) != ColumnValue::NO_NULLS;
153 *pSignedIter = m_xSetMetaData->isSigned(i);
154 *pColumnIter = m_xSetMetaData->getColumnType(i);
157 Reference< XStatement> xStmt(m_xDriverSet->getStatement(),UNO_QUERY);
158 if(xStmt.is())
159 m_xConnection = xStmt->getConnection();
160 else
162 Reference< XPreparedStatement> xPrepStmt(m_xDriverSet->getStatement(),UNO_QUERY);
163 if ( xPrepStmt.is() )
164 m_xConnection = xPrepStmt->getConnection();
168 // -------------------------------------------------------------------------
169 OCacheSet::~OCacheSet()
173 m_xDriverSet = NULL;
174 m_xDriverRow = NULL;
175 m_xSetMetaData = NULL;
176 m_xConnection = NULL;
178 catch(Exception&)
180 OSL_ENSURE(0,"Exception occured");
182 catch(...)
184 OSL_ENSURE(0,"Unknown Exception occured");
187 DBG_DTOR(OCacheSet,NULL);
189 // -----------------------------------------------------------------------------
190 void OCacheSet::fillTableName(const Reference<XPropertySet>& _xTable) throw(SQLException, RuntimeException)
192 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::fillTableName" );
193 OSL_ENSURE(_xTable.is(),"OCacheSet::fillTableName: PropertySet is empty!");
194 if(!m_aComposedTableName.getLength() && _xTable.is() )
196 Reference<XDatabaseMetaData> xMeta(m_xConnection->getMetaData());
197 m_aComposedTableName = composeTableName(xMeta
198 ,comphelper::getString(_xTable->getPropertyValue(PROPERTY_CATALOGNAME))
199 ,comphelper::getString(_xTable->getPropertyValue(PROPERTY_SCHEMANAME))
200 ,comphelper::getString(_xTable->getPropertyValue(PROPERTY_NAME))
201 ,sal_True
202 ,::dbtools::eInDataManipulation);
205 // -------------------------------------------------------------------------
206 void SAL_CALL OCacheSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(SQLException, RuntimeException)
208 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::insertRow" );
209 ::rtl::OUStringBuffer aSql(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INSERT INTO ")));
210 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
211 fillTableName(xSet);
213 aSql.append(m_aComposedTableName);
214 aSql.append(::rtl::OUString::createFromAscii(" ( "));
215 // set values and column names
216 ::rtl::OUStringBuffer aValues = ::rtl::OUString::createFromAscii(" VALUES ( ");
217 static ::rtl::OUString aPara(RTL_CONSTASCII_USTRINGPARAM("?,"));
218 ::rtl::OUString aQuote = getIdentifierQuoteString();
219 static ::rtl::OUString aComma(RTL_CONSTASCII_USTRINGPARAM(","));
220 sal_Int32 i = 1;
221 ORowVector< ORowSetValue >::Vector::const_iterator aIter = _rInsertRow->get().begin()+1;
222 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
223 for(; aIter != aEnd;++aIter)
225 aSql.append(::dbtools::quoteName( aQuote,m_xSetMetaData->getColumnName(i++)));
226 aSql.append(aComma);
227 aValues.append(aPara);
230 aSql.setCharAt(aSql.getLength()-1,')');
231 aValues.setCharAt(aValues.getLength()-1,')');
233 aSql.append(aValues.makeStringAndClear());
234 // now create end execute the prepared statement
236 Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(aSql.makeStringAndClear()));
237 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
238 i = 1;
239 for(aIter = _rInsertRow->get().begin()+1; aIter != aEnd;++aIter,++i)
241 if(aIter->isNull())
242 xParameter->setNull(i,aIter->getTypeKind());
243 else
244 setParameter(i,xParameter,*aIter,m_xSetMetaData->getColumnType(i),m_xSetMetaData->getScale(i));
247 m_bInserted = xPrep->executeUpdate() > 0;
250 // ::rtl::OUString aCountSql = ::rtl::OUString::createFromAscii("SELECT COUNT(*) FROM ");
251 // aCountSql += m_aComposedTableName;
252 // try
253 // {
254 // Reference< XStatement > xStmt(m_xConnection->createStatement());
255 // Reference<XResultSet> xRes(xStmt->executeQuery(aCountSql));
256 // if(xRes.is() && xRes->next())
257 // {
258 // Reference<XRow> xRow(xRes,UNO_QUERY);
259 // }
260 // }
261 // catch(SQLException&)
262 // {
263 // }
265 // TODO set the bookmark in the insert row
267 // -------------------------------------------------------------------------
268 void OCacheSet::fillParameters( const ORowSetRow& _rRow
269 ,const connectivity::OSQLTable& _xTable
270 ,::rtl::OUStringBuffer& _sCondition
271 ,::rtl::OUStringBuffer& _sParameter
272 ,::std::list< sal_Int32>& _rOrgValues)
274 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::fillParameters" );
275 // use keys and indexes for excat postioning
276 // first the keys
277 Reference<XKeysSupplier> xKeySup(_xTable,UNO_QUERY);
278 Reference<XIndexAccess> xKeys;
279 if(xKeySup.is())
280 xKeys = xKeySup->getKeys();
282 Reference<XColumnsSupplier> xKeyColsSup;
283 Reference<XNameAccess> xKeyColumns;
284 if(xKeys.is() && xKeys->getCount())
286 Reference<XPropertySet> xProp;
287 Reference<XColumnsSupplier> xColumnsSupplier;
288 // search the one and only primary key
289 for(sal_Int32 i=0;i< xKeys->getCount();++i)
291 ::cppu::extractInterface(xProp,xKeys->getByIndex(i));
292 sal_Int32 nKeyType = 0;
293 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
294 if(KeyType::PRIMARY == nKeyType)
296 xKeyColsSup.set(xProp,UNO_QUERY);
297 break;
300 if(xKeyColsSup.is())
301 xKeyColumns = xKeyColsSup->getColumns();
303 // second the indexes
304 Reference<XIndexesSupplier> xIndexSup(_xTable,UNO_QUERY);
305 Reference<XIndexAccess> xIndexes;
306 if(xIndexSup.is())
307 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
309 // Reference<XColumnsSupplier>
310 Reference<XPropertySet> xIndexColsSup;
311 Reference<XNameAccess> xIndexColumns;
312 ::std::vector< Reference<XNameAccess> > aAllIndexColumns;
313 if(xIndexes.is())
315 for(sal_Int32 j=0;j<xIndexes->getCount();++j)
317 ::cppu::extractInterface(xIndexColsSup,xIndexes->getByIndex(j));
318 if( xIndexColsSup.is()
319 && comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISUNIQUE))
320 && !comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISPRIMARYKEYINDEX))
322 aAllIndexColumns.push_back(Reference<XColumnsSupplier>(xIndexColsSup,UNO_QUERY)->getColumns());
326 ::rtl::OUString aColumnName;
328 static ::rtl::OUString aPara = ::rtl::OUString::createFromAscii("?,");
329 static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND ");
331 ::rtl::OUString aQuote = getIdentifierQuoteString();
333 sal_Int32 nCheckCount = 1; // index for the orginal values
334 sal_Int32 i = 1;
336 ::rtl::OUString sIsNull(RTL_CONSTASCII_USTRINGPARAM(" IS NULL"));
337 ::rtl::OUString sParam(RTL_CONSTASCII_USTRINGPARAM(" = ?"));
338 ORowVector< ORowSetValue >::Vector::const_iterator aIter = _rRow->get().begin()+1;
339 ORowVector< ORowSetValue >::Vector::const_iterator aEnd = _rRow->get().end()+1;
340 for(; aIter != aEnd;++aIter,++nCheckCount,++i)
342 aColumnName = m_xSetMetaData->getColumnName(i);
343 if(xKeyColumns.is() && xKeyColumns->hasByName(aColumnName))
345 _sCondition.append(::dbtools::quoteName( aQuote,aColumnName));
346 if(aIter->isNull())
347 _sCondition.append(sIsNull);
348 else
349 _sCondition.append(sParam);
350 _sCondition.append(aAnd);
351 _rOrgValues.push_back(nCheckCount);
353 } // if(xKeyColumns.is() && xKeyColumns->hasByName(aColumnName))
354 ::std::vector< Reference<XNameAccess> >::const_iterator aIndexEnd = aAllIndexColumns.end();
355 for( ::std::vector< Reference<XNameAccess> >::const_iterator aIndexIter = aAllIndexColumns.begin();
356 aIndexIter != aIndexEnd;++aIndexIter)
358 if((*aIndexIter)->hasByName(aColumnName))
360 _sCondition.append(::dbtools::quoteName( aQuote,aColumnName));
361 if(aIter->isNull())
362 _sCondition.append(sIsNull);
363 else
364 _sCondition.append(sParam);
365 _sCondition.append(aAnd);
366 _rOrgValues.push_back(nCheckCount);
367 break;
370 if(aIter->isModified())
372 _sParameter.append(::dbtools::quoteName( aQuote,aColumnName));
373 _sParameter.append(aPara);
377 // -------------------------------------------------------------------------
378 void SAL_CALL OCacheSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable ) throw(SQLException, RuntimeException)
380 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::updateRow" );
381 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
382 fillTableName(xSet);
384 ::rtl::OUStringBuffer aSql = ::rtl::OUString::createFromAscii("UPDATE ");
385 aSql.append(m_aComposedTableName);
386 aSql.append(::rtl::OUString::createFromAscii(" SET "));
387 // list all cloumns that should be set
389 ::rtl::OUStringBuffer aCondition;
390 ::std::list< sal_Int32> aOrgValues;
391 fillParameters(_rInsertRow,_xTable,aCondition,aSql,aOrgValues);
392 aSql.setCharAt(aSql.getLength()-1,' ');
393 if ( aCondition.getLength() )
395 aCondition.setLength(aCondition.getLength()-5);
397 aSql.append(::rtl::OUString::createFromAscii(" WHERE "));
398 aSql.append(aCondition.makeStringAndClear());
400 else
401 ::dbtools::throwSQLException(
402 DBACORE_RESSTRING( RID_STR_NO_UPDATE_MISSING_CONDITION ), SQL_GENERAL_ERROR, *this );
404 // now create end execute the prepared statement
405 Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(aSql.makeStringAndClear()));
406 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
407 sal_Int32 i = 1;
408 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
409 for(ORowVector< ORowSetValue >::Vector::const_iterator aIter = _rInsertRow->get().begin()+1; aIter != aEnd;++aIter)
411 if(aIter->isModified())
413 setParameter(i,xParameter,*aIter,m_xSetMetaData->getColumnType(i),m_xSetMetaData->getScale(i));
414 ++i;
416 } // for(ORowVector< ORowSetValue >::Vector::const_iterator aIter = _rInsertRow->get().begin()+1; aIter != aEnd;++aIter)
417 ::std::list< sal_Int32>::const_iterator aOrgValueEnd = aOrgValues.end();
418 for(::std::list< sal_Int32>::const_iterator aOrgValue = aOrgValues.begin(); aOrgValue != aOrgValueEnd;++aOrgValue,++i)
420 setParameter(i,xParameter,(_rOrginalRow->get())[*aOrgValue],m_xSetMetaData->getColumnType(i),m_xSetMetaData->getScale(i));
423 m_bUpdated = xPrep->executeUpdate() > 0;
425 // -------------------------------------------------------------------------
426 void SAL_CALL OCacheSet::deleteRow(const ORowSetRow& _rDeleteRow ,const connectivity::OSQLTable& _xTable ) throw(SQLException, RuntimeException)
428 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::deleteRow" );
429 Reference<XPropertySet> xSet(_xTable,UNO_QUERY);
430 fillTableName(xSet);
432 ::rtl::OUStringBuffer aSql = ::rtl::OUString::createFromAscii("DELETE FROM ");
433 aSql.append(m_aComposedTableName);
434 aSql.append(::rtl::OUString::createFromAscii(" WHERE "));
436 // list all cloumns that should be set
437 ::rtl::OUString aQuote = getIdentifierQuoteString();
438 static ::rtl::OUString aAnd = ::rtl::OUString::createFromAscii(" AND ");
440 // use keys and indexes for excat postioning
441 // first the keys
442 Reference<XKeysSupplier> xKeySup(_xTable,UNO_QUERY);
443 Reference<XIndexAccess> xKeys;
444 if(xKeySup.is())
445 xKeys = xKeySup->getKeys();
447 Reference<XColumnsSupplier> xKeyColsSup;
448 Reference<XNameAccess> xKeyColumns;
449 if(xKeys.is() && xKeys->getCount())
451 Reference<XPropertySet> xProp;
452 Reference<XColumnsSupplier> xColumnsSupplier;
453 // search the one and only primary key
454 for(sal_Int32 i=0;i< xKeys->getCount();++i)
456 ::cppu::extractInterface(xProp,xKeys->getByIndex(i));
457 sal_Int32 nKeyType = 0;
458 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
459 if(KeyType::PRIMARY == nKeyType)
461 xKeyColsSup.set(xProp,UNO_QUERY);
462 break;
465 if(xKeyColsSup.is())
466 xKeyColumns = xKeyColsSup->getColumns();
468 // second the indexes
469 Reference<XIndexesSupplier> xIndexSup(_xTable,UNO_QUERY);
470 Reference<XIndexAccess> xIndexes;
471 if(xIndexSup.is())
472 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
474 // Reference<XColumnsSupplier>
475 Reference<XPropertySet> xIndexColsSup;
476 Reference<XNameAccess> xIndexColumns;
477 ::std::vector< Reference<XNameAccess> > aAllIndexColumns;
478 if(xIndexes.is())
480 for(sal_Int32 j=0;j<xIndexes->getCount();++j)
482 xIndexColsSup.set(xIndexes->getByIndex(j),UNO_QUERY);
483 if( xIndexColsSup.is()
484 && comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISUNIQUE))
485 && !comphelper::getBOOL(xIndexColsSup->getPropertyValue(PROPERTY_ISPRIMARYKEYINDEX))
487 aAllIndexColumns.push_back(Reference<XColumnsSupplier>(xIndexColsSup,UNO_QUERY)->getColumns());
491 ::rtl::OUStringBuffer aColumnName;
492 ::std::list< sal_Int32> aOrgValues;
493 fillParameters(_rDeleteRow,_xTable,aSql,aColumnName,aOrgValues);
495 aSql.setLength(aSql.getLength()-5);
497 // now create end execute the prepared statement
498 Reference< XPreparedStatement > xPrep(m_xConnection->prepareStatement(aSql.makeStringAndClear()));
499 Reference< XParameters > xParameter(xPrep,UNO_QUERY);
500 sal_Int32 i = 1;
501 ::std::list< sal_Int32>::const_iterator aOrgValueEnd = aOrgValues.end();
502 for(::std::list< sal_Int32>::const_iterator j = aOrgValues.begin(); j != aOrgValueEnd;++j,++i)
504 setParameter(i,xParameter,(_rDeleteRow->get())[*j],m_xSetMetaData->getColumnType(i),m_xSetMetaData->getScale(i));
507 m_bDeleted = xPrep->executeUpdate() > 0;
509 // -------------------------------------------------------------------------
510 void OCacheSet::setParameter(sal_Int32 nPos
511 ,const Reference< XParameters >& _xParameter
512 ,const ORowSetValue& _rValue
513 ,sal_Int32 _nType
514 ,sal_Int32 _nScale)
516 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::setParameter" );
517 sal_Int32 nType = ( _nType != DataType::OTHER ) ? _nType : _rValue.getTypeKind();
518 if(!_rValue.isNull())
521 switch(nType)
523 case DataType::DECIMAL:
524 case DataType::NUMERIC:
525 _xParameter->setObjectWithInfo(nPos,_rValue.makeAny(),nType,_nScale);
526 break;
527 case DataType::CHAR:
528 case DataType::VARCHAR:
529 case DataType::LONGVARCHAR:
530 _xParameter->setString(nPos,_rValue);
531 break;
532 case DataType::BIGINT:
533 if ( _rValue.isSigned() )
534 _xParameter->setLong(nPos,_rValue);
535 else
536 _xParameter->setString(nPos,_rValue);
537 break;
538 case DataType::BIT:
539 case DataType::BOOLEAN:
540 _xParameter->setBoolean(nPos,_rValue);
541 break;
542 case DataType::TINYINT:
543 if ( _rValue.isSigned() )
544 _xParameter->setByte(nPos,_rValue);
545 else
546 _xParameter->setShort(nPos,_rValue);
547 break;
548 case DataType::SMALLINT:
549 if ( _rValue.isSigned() )
550 _xParameter->setShort(nPos,_rValue);
551 else
552 _xParameter->setInt(nPos,_rValue);
553 break;
554 case DataType::INTEGER:
555 if ( _rValue.isSigned() )
556 _xParameter->setInt(nPos,_rValue);
557 else
558 _xParameter->setLong(nPos,_rValue);
559 break;
560 case DataType::FLOAT:
561 _xParameter->setFloat(nPos,_rValue);
562 break;
563 case DataType::DOUBLE:
564 case DataType::REAL:
565 _xParameter->setDouble(nPos,_rValue);
566 break;
567 case DataType::DATE:
568 _xParameter->setDate(nPos,_rValue);
569 break;
570 case DataType::TIME:
571 _xParameter->setTime(nPos,_rValue);
572 break;
573 case DataType::TIMESTAMP:
574 _xParameter->setTimestamp(nPos,_rValue);
575 break;
576 case DataType::BINARY:
577 case DataType::VARBINARY:
578 case DataType::LONGVARBINARY:
579 _xParameter->setBytes(nPos,_rValue);
580 break;
581 case DataType::CLOB:
583 Reference<XInputStream> xStream(_rValue.getAny(),UNO_QUERY);
584 _xParameter->setCharacterStream(nPos,xStream,xStream.is() ? xStream->available() : sal_Int32(0));
586 break;
587 case DataType::BLOB:
589 Reference<XInputStream> xStream(_rValue.getAny(),UNO_QUERY);
590 _xParameter->setBinaryStream(nPos,xStream,xStream.is() ? xStream->available() : sal_Int32(0));
592 break;
593 case DataType::SQLNULL:
594 _xParameter->setNull(nPos,nType);
595 break;
598 else
599 _xParameter->setNull(nPos,nType);
601 // -------------------------------------------------------------------------
602 void OCacheSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
604 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::fillValueRow" );
605 Any aBookmark = getBookmark();
606 if(!aBookmark.hasValue())
607 aBookmark = makeAny(_nPosition);
609 connectivity::ORowVector< ORowSetValue >::Vector::iterator aIter = _rRow->get().begin();
610 connectivity::ORowVector< ORowSetValue >::Vector::iterator aEnd = _rRow->get().end();
611 (*aIter) = aBookmark;
612 ++aIter;
613 for(sal_Int32 i=1;aIter != aEnd;++aIter,++i)
615 aIter->setSigned(m_aSignedFlags[i-1]);
616 aIter->fill(i,m_aColumnTypes[i-1],m_aNullable[i-1],this);
619 // -----------------------------------------------------------------------------
620 sal_Bool SAL_CALL OCacheSet::wasNull( ) throw(SQLException, RuntimeException)
622 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::wasNull" );
623 return m_xDriverRow->wasNull();
625 // -------------------------------------------------------------------------
626 ::rtl::OUString SAL_CALL OCacheSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
628 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getString" );
629 return m_xDriverRow->getString(columnIndex);
631 // -------------------------------------------------------------------------
632 sal_Bool SAL_CALL OCacheSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
634 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getBoolean" );
635 return m_xDriverRow->getBoolean(columnIndex);
637 // -------------------------------------------------------------------------
638 sal_Int8 SAL_CALL OCacheSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
640 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getByte" );
641 return m_xDriverRow->getByte(columnIndex);
643 // -------------------------------------------------------------------------
644 sal_Int16 SAL_CALL OCacheSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
646 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getShort" );
647 return m_xDriverRow->getShort(columnIndex);
649 // -------------------------------------------------------------------------
650 sal_Int32 SAL_CALL OCacheSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
652 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getInt" );
653 return m_xDriverRow->getInt(columnIndex);
655 // -------------------------------------------------------------------------
656 sal_Int64 SAL_CALL OCacheSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
658 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getLong" );
659 return m_xDriverRow->getLong(columnIndex);
661 // -------------------------------------------------------------------------
662 float SAL_CALL OCacheSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
664 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getFloat" );
665 return m_xDriverRow->getFloat(columnIndex);
667 // -------------------------------------------------------------------------
668 double SAL_CALL OCacheSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
670 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getDouble" );
671 return m_xDriverRow->getDouble(columnIndex);
673 // -------------------------------------------------------------------------
674 Sequence< sal_Int8 > SAL_CALL OCacheSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
676 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getBytes" );
677 return m_xDriverRow->getBytes(columnIndex);
679 // -------------------------------------------------------------------------
680 ::com::sun::star::util::Date SAL_CALL OCacheSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
682 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getDate" );
683 return m_xDriverRow->getDate(columnIndex);
685 // -------------------------------------------------------------------------
686 ::com::sun::star::util::Time SAL_CALL OCacheSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
688 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getTime" );
689 return m_xDriverRow->getTime(columnIndex);
691 // -------------------------------------------------------------------------
692 ::com::sun::star::util::DateTime SAL_CALL OCacheSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
694 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getTimestamp" );
695 return m_xDriverRow->getTimestamp(columnIndex);
697 // -------------------------------------------------------------------------
698 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCacheSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
700 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getBinaryStream" );
701 return m_xDriverRow->getBinaryStream(columnIndex);
703 // -------------------------------------------------------------------------
704 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OCacheSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
706 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getCharacterStream" );
707 return m_xDriverRow->getCharacterStream(columnIndex);
709 // -------------------------------------------------------------------------
710 Any SAL_CALL OCacheSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(SQLException, RuntimeException)
712 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getObject" );
713 return m_xDriverRow->getObject(columnIndex,typeMap);
715 // -------------------------------------------------------------------------
716 Reference< XRef > SAL_CALL OCacheSet::getRef( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
718 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getRef" );
719 return m_xDriverRow->getRef(columnIndex);
721 // -------------------------------------------------------------------------
722 Reference< XBlob > SAL_CALL OCacheSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
724 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getBlob" );
725 return m_xDriverRow->getBlob(columnIndex);
727 // -------------------------------------------------------------------------
728 Reference< XClob > SAL_CALL OCacheSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
730 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getClob" );
731 return m_xDriverRow->getClob(columnIndex);
733 // -------------------------------------------------------------------------
734 Reference< XArray > SAL_CALL OCacheSet::getArray( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
736 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getArray" );
737 return m_xDriverRow->getArray(columnIndex);
739 // -------------------------------------------------------------------------
740 // XResultSet
741 sal_Bool SAL_CALL OCacheSet::next( ) throw(SQLException, RuntimeException)
743 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::next" );
744 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
745 return m_xDriverSet->next();
747 // -------------------------------------------------------------------------
748 sal_Bool SAL_CALL OCacheSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
750 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::isBeforeFirst" );
751 return m_xDriverSet->isBeforeFirst();
753 // -------------------------------------------------------------------------
754 sal_Bool SAL_CALL OCacheSet::isAfterLast( ) throw(SQLException, RuntimeException)
756 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::isAfterLast" );
757 return m_xDriverSet->isAfterLast();
759 // -------------------------------------------------------------------------
760 sal_Bool SAL_CALL OCacheSet::isFirst( ) throw(SQLException, RuntimeException)
762 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::isFirst" );
763 return m_xDriverSet->isFirst();
765 // -------------------------------------------------------------------------
766 sal_Bool SAL_CALL OCacheSet::isLast( ) throw(SQLException, RuntimeException)
768 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::isLast" );
769 return m_xDriverSet->isLast();
771 // -------------------------------------------------------------------------
772 void SAL_CALL OCacheSet::beforeFirst( ) throw(SQLException, RuntimeException)
774 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::beforeFirst" );
775 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
776 m_xDriverSet->beforeFirst();
778 // -------------------------------------------------------------------------
779 void SAL_CALL OCacheSet::afterLast( ) throw(SQLException, RuntimeException)
781 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::afterLast" );
782 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
783 m_xDriverSet->afterLast();
785 // -------------------------------------------------------------------------
786 sal_Bool SAL_CALL OCacheSet::first( ) throw(SQLException, RuntimeException)
788 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::first" );
789 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
790 return m_xDriverSet->first();
792 // -------------------------------------------------------------------------
793 sal_Bool SAL_CALL OCacheSet::last( ) throw(SQLException, RuntimeException)
795 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::last" );
796 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
797 return m_xDriverSet->last();
799 // -------------------------------------------------------------------------
800 sal_Int32 SAL_CALL OCacheSet::getRow( ) throw(SQLException, RuntimeException)
802 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getRow" );
803 return m_xDriverSet->getRow();
805 // -------------------------------------------------------------------------
806 sal_Bool SAL_CALL OCacheSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
808 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::absolute" );
809 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
810 return m_xDriverSet->absolute(row);
812 // -------------------------------------------------------------------------
813 sal_Bool SAL_CALL OCacheSet::relative( sal_Int32 rows ) throw(SQLException, RuntimeException)
815 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::relative" );
816 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
817 return m_xDriverSet->relative(rows);
819 // -------------------------------------------------------------------------
820 sal_Bool SAL_CALL OCacheSet::previous( ) throw(SQLException, RuntimeException)
822 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::previous" );
823 m_bInserted = m_bUpdated = m_bDeleted = sal_False;
824 return m_xDriverSet->previous();
826 // -------------------------------------------------------------------------
827 void SAL_CALL OCacheSet::refreshRow( ) throw(SQLException, RuntimeException)
829 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::refreshRow" );
830 m_xDriverSet->refreshRow();
832 // -------------------------------------------------------------------------
833 sal_Bool SAL_CALL OCacheSet::rowUpdated( ) throw(SQLException, RuntimeException)
835 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::rowUpdated" );
836 return m_xDriverSet->rowUpdated();
838 // -------------------------------------------------------------------------
839 sal_Bool SAL_CALL OCacheSet::rowInserted( ) throw(SQLException, RuntimeException)
841 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::rowInserted" );
842 return m_xDriverSet->rowInserted();
844 // -------------------------------------------------------------------------
845 sal_Bool SAL_CALL OCacheSet::rowDeleted( ) throw(SQLException, RuntimeException)
847 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::rowDeleted" );
848 return m_xDriverSet->rowDeleted();
850 // -------------------------------------------------------------------------
851 Reference< XInterface > SAL_CALL OCacheSet::getStatement( ) throw(SQLException, RuntimeException)
853 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OCacheSet::getStatement" );
854 return m_xDriverSet->getStatement();
856 // -----------------------------------------------------------------------------