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 <com/sun/star/sdbc/DataType.hpp>
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <comphelper/property.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <cppuhelper/typeprovider.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <comphelper/extract.hxx>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/sdbc/ResultSetType.hpp>
29 #include <com/sun/star/sdbc/FetchDirection.hpp>
30 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
31 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
32 #include <comphelper/types.hxx>
33 #include <connectivity/dbexception.hxx>
34 #include <connectivity/dbtools.hxx>
36 #include <TSortIndex.hxx>
37 #include <rtl/string.hxx>
40 #include "MResultSet.hxx"
41 #include "MResultSetMetaData.hxx"
42 #include "FDatabaseMetaDataResultSet.hxx"
43 #include "resource/mozab_res.hrc"
44 #include "resource/common_res.hrc"
45 #include "sqlbison.hxx"
47 #if OSL_DEBUG_LEVEL > 0
48 # define OUtoCStr( x ) ( OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
49 #else /* OSL_DEBUG_LEVEL */
50 # define OUtoCStr( x ) ("dummy")
51 #endif /* OSL_DEBUG_LEVEL */
53 using namespace ::comphelper
;
54 using namespace connectivity
;
55 using namespace connectivity::mozab
;
56 using namespace ::cppu
;
57 using namespace com::sun::star::uno
;
58 using namespace com::sun::star::lang
;
59 using namespace com::sun::star::beans
;
60 using namespace com::sun::star::sdbc
;
61 using namespace com::sun::star::sdbcx
;
62 using namespace com::sun::star::container
;
63 using namespace com::sun::star::io
;
64 using namespace com::sun::star::util
;
67 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
68 OUString SAL_CALL
OResultSet::getImplementationName( ) throw ( RuntimeException
) \
70 return OUString("com.sun.star.sdbcx.mozab.ResultSet");
73 Sequence
< OUString
> SAL_CALL
OResultSet::getSupportedServiceNames( ) throw( RuntimeException
)
75 ::com::sun::star::uno::Sequence
< OUString
> aSupported(2);
76 aSupported
[0] = "com.sun.star.sdbc.ResultSet";
77 aSupported
[1] = "com.sun.star.sdbcx.ResultSet";
81 sal_Bool SAL_CALL
OResultSet::supportsService( const OUString
& _rServiceName
) throw( RuntimeException
)
83 return cppu::supportsService(this, _rServiceName
);
87 OResultSet::OResultSet(OCommonStatement
* pStmt
, const ::boost::shared_ptr
< connectivity::OSQLParseTreeIterator
>& _pSQLIterator
)
88 : OResultSet_BASE(m_aMutex
)
89 ,OPropertySetHelper(OResultSet_BASE::rBHelper
)
96 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE
)
97 ,m_nFetchDirection(FetchDirection::FORWARD
)
98 ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE
)
99 ,m_pSQLIterator( _pSQLIterator
)
100 ,m_pParseTree( _pSQLIterator
->getParseTree() )
101 ,m_aQuery( pStmt
->getOwnConnection()->getColumnAlias() )
103 ,m_CurrentRowCount(0)
105 ,m_bIsAlwaysFalseQuery(sal_False
)
113 m_aQuery
.setMaxNrOfReturns(pStmt
->getOwnConnection()->getMaxResultRecords());
116 OResultSet::~OResultSet()
121 void OResultSet::disposing()
123 OPropertySetHelper::disposing();
125 ::osl::MutexGuard
aGuard(m_aMutex
);
127 m_xStatement
.clear();
131 m_xParamColumns
= NULL
;
140 Any SAL_CALL
OResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
)
142 Any aRet
= OPropertySetHelper::queryInterface(rType
);
144 aRet
= OResultSet_BASE::queryInterface(rType
);
148 Sequence
< Type
> SAL_CALL
OResultSet::getTypes( ) throw( RuntimeException
)
150 OTypeCollection
aTypes( cppu::UnoType
<com::sun::star::beans::XMultiPropertySet
>::get(),
151 cppu::UnoType
<com::sun::star::beans::XFastPropertySet
>::get(),
152 cppu::UnoType
<com::sun::star::beans::XPropertySet
>::get());
154 return ::comphelper::concatSequences(aTypes
.getTypes(),OResultSet_BASE::getTypes());
157 void OResultSet::methodEntry()
159 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
162 OSL_FAIL( "OResultSet::methodEntry: looks like we're disposed, but how is this possible?" );
163 throw DisposedException( OUString(), *this );
168 sal_Int32 SAL_CALL
OResultSet::findColumn( const OUString
& columnName
) throw(SQLException
, RuntimeException
)
170 ResultSetEntryGuard
aGuard( *this );
172 // find the first column with the name columnName
173 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
174 sal_Int32 nLen
= xMeta
->getColumnCount();
178 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
179 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
183 ::dbtools::throwInvalidColumnException( columnName
, *this );
185 return 0; // Never reached
188 Reference
< XInputStream
> SAL_CALL
OResultSet::getBinaryStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
193 Reference
< XInputStream
> SAL_CALL
OResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
199 sal_Bool SAL_CALL
OResultSet::getBoolean( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
201 ResultSetEntryGuard
aGuard( *this );
202 m_bWasNull
= sal_True
;
207 sal_Int8 SAL_CALL
OResultSet::getByte( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
209 ResultSetEntryGuard
aGuard( *this );
214 Sequence
< sal_Int8
> SAL_CALL
OResultSet::getBytes( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
216 ResultSetEntryGuard
aGuard( *this );
217 return Sequence
< sal_Int8
>();
221 Date SAL_CALL
OResultSet::getDate( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
223 ResultSetEntryGuard
aGuard( *this );
228 double SAL_CALL
OResultSet::getDouble( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
230 ResultSetEntryGuard
aGuard( *this );
235 float SAL_CALL
OResultSet::getFloat( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
237 ResultSetEntryGuard
aGuard( *this );
242 sal_Int32 SAL_CALL
OResultSet::getInt( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
244 ResultSetEntryGuard
aGuard( *this );
249 sal_Int32 SAL_CALL
OResultSet::getRow( ) throw(SQLException
, RuntimeException
)
251 ResultSetEntryGuard
aGuard( *this );
253 OSL_TRACE("In/Out: OResultSet::getRow, return = %u", m_nRowPos
);
258 sal_Int64 SAL_CALL
OResultSet::getLong( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
260 ResultSetEntryGuard
aGuard( *this );
265 Reference
< XResultSetMetaData
> SAL_CALL
OResultSet::getMetaData( ) throw(SQLException
, RuntimeException
)
267 ResultSetEntryGuard
aGuard( *this );
269 if(!m_xMetaData
.is())
270 m_xMetaData
= new OResultSetMetaData(
271 m_pSQLIterator
->getSelectColumns(), m_pSQLIterator
->getTables().begin()->first
,m_pTable
,determineReadOnly());
275 Reference
< XArray
> SAL_CALL
OResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
282 Reference
< XClob
> SAL_CALL
OResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
287 Reference
< XBlob
> SAL_CALL
OResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
293 Reference
< XRef
> SAL_CALL
OResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
299 Any SAL_CALL
OResultSet::getObject( sal_Int32
/*columnIndex*/, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
)
305 sal_Int16 SAL_CALL
OResultSet::getShort( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
311 void OResultSet::checkIndex(sal_Int32 columnIndex
) throw(::com::sun::star::sdbc::SQLException
)
313 if(columnIndex
<= 0 || columnIndex
> (sal_Int32
)m_xColumns
->get().size())
314 ::dbtools::throwInvalidIndexException(*this);
317 sal_uInt32
OResultSet::currentRowCount()
319 if ( m_bIsAlwaysFalseQuery
)
321 return m_aQuery
.getRealRowCount() - deletedCount();
326 sal_Bool
OResultSet::fetchCurrentRow( ) throw(SQLException
, RuntimeException
)
328 OSL_TRACE("fetchCurrentRow, m_nRowPos = %u", m_nRowPos
);
329 return fetchRow(getCurrentCardNumber());
333 sal_Bool
OResultSet::pushCard(sal_uInt32 cardNumber
) throw(SQLException
, RuntimeException
)
337 // Check whether we are storing the updated row
338 if ( (m_aRow
->get())[0].isNull() || (sal_Int32
)(m_aRow
->get())[0] != (sal_Int32
)cardNumber
)
341 sal_Int32 nCount
= m_aColumnNames
.getLength();
342 m_aQuery
.setRowStates(cardNumber
,m_RowStates
);
343 for( sal_Int32 i
= 1; i
<= nCount
; i
++ )
345 if ( (m_aRow
->get())[i
].isBound() )
348 // Everything in the addressbook is a string!
350 if ( !m_aQuery
.setRowValue( (m_aRow
->get())[i
], cardNumber
, m_aColumnNames
[i
-1], DataType::VARCHAR
))
352 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
360 sal_Bool
OResultSet::fetchRow(sal_Int32 cardNumber
,sal_Bool bForceReload
) throw(SQLException
, RuntimeException
)
362 OSL_TRACE("fetchRow, cardNumber = %u", cardNumber
);
365 // Check whether we've already fetched the row...
366 if ( !(m_aRow
->get())[0].isNull() && (sal_Int32
)(m_aRow
->get())[0] == (sal_Int32
)cardNumber
)
368 //Check whether the old row has been changed
369 if (cardNumber
== m_nUpdatedRow
)
371 //write back the changes first
372 if (!pushCard(cardNumber
)) //error write back the changes
373 throw SQLException();
377 m_aQuery
.resyncRow(cardNumber
);
379 if ( validRow( cardNumber
) == sal_False
)
382 (m_aRow
->get())[0] = (sal_Int32
)cardNumber
;
383 sal_Int32 nCount
= m_aColumnNames
.getLength();
384 m_RowStates
= m_aQuery
.getRowStates(cardNumber
);
385 for( sal_Int32 i
= 1; i
<= nCount
; i
++ )
387 if ( (m_aRow
->get())[i
].isBound() )
390 // Everything in the addressbook is a string!
392 if ( !m_aQuery
.getRowValue( (m_aRow
->get())[i
], cardNumber
, m_aColumnNames
[i
-1], DataType::VARCHAR
))
394 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
402 const ORowSetValue
& OResultSet::getValue(sal_Int32 cardNumber
, sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
404 if ( fetchRow( cardNumber
) == sal_False
)
406 OSL_FAIL("fetchRow() returned False" );
407 m_bWasNull
= sal_True
;
408 return *ODatabaseMetaDataResultSet::getEmptyValue();
411 m_bWasNull
= (m_aRow
->get())[columnIndex
].isNull();
412 return (m_aRow
->get())[columnIndex
];
418 OUString SAL_CALL
OResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
420 ResultSetEntryGuard
aGuard( *this );
422 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
423 OSL_ENSURE(columnIndex
<= (sal_Int32
)m_xColumns
->get().size(), "Trying to access invalid columns number");
424 checkIndex( columnIndex
);
426 // If this query was sorted then we should have a valid KeySet, so use it
427 return getValue(getCurrentCardNumber(), mapColumn( columnIndex
) );
432 Time SAL_CALL
OResultSet::getTime( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
434 ResultSetEntryGuard
aGuard( *this );
440 DateTime SAL_CALL
OResultSet::getTimestamp( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
442 ResultSetEntryGuard
aGuard( *this );
447 sal_Bool SAL_CALL
OResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
)
449 ResultSetEntryGuard
aGuard( *this );
451 // here you have to implement your movements
452 // return true means there is no data
453 OSL_TRACE("In/Out: OResultSet::isBeforeFirst" );
454 return( m_nRowPos
< 1 );
457 sal_Bool SAL_CALL
OResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
)
459 ResultSetEntryGuard
aGuard( *this );
461 OSL_TRACE("In/Out: OResultSet::isAfterLast" );
462 return m_nRowPos
> currentRowCount() && m_aQuery
.queryComplete();
465 sal_Bool SAL_CALL
OResultSet::isFirst( ) throw(SQLException
, RuntimeException
)
467 ResultSetEntryGuard
aGuard( *this );
469 OSL_TRACE("In/Out: OResultSet::isFirst" );
470 return m_nRowPos
== 1;
473 sal_Bool SAL_CALL
OResultSet::isLast( ) throw(SQLException
, RuntimeException
)
475 ResultSetEntryGuard
aGuard( *this );
477 OSL_TRACE("In/Out: OResultSet::isLast" );
478 return m_nRowPos
== currentRowCount() && m_aQuery
.queryComplete();
481 void SAL_CALL
OResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
)
483 ResultSetEntryGuard
aGuard( *this );
485 // move before the first row so that isBeforeFirst returns false
486 OSL_TRACE("In/Out: OResultSet::beforeFirst" );
491 void SAL_CALL
OResultSet::afterLast( ) throw(SQLException
, RuntimeException
)
493 ResultSetEntryGuard
aGuard( *this );
494 OSL_TRACE("In/Out: OResultSet::afterLast" );
501 void SAL_CALL
OResultSet::close( ) throw(SQLException
, RuntimeException
)
503 ResultSetEntryGuard
aGuard( *this );
504 OSL_TRACE("In/Out: OResultSet::close" );
509 sal_Bool SAL_CALL
OResultSet::first( ) throw(SQLException
, RuntimeException
)
511 OSL_TRACE("In/Out: OResultSet::first" );
512 return seekRow( FIRST_POS
);
516 sal_Bool SAL_CALL
OResultSet::last( ) throw(SQLException
, RuntimeException
)
518 OSL_TRACE("In/Out: OResultSet::last" );
519 return seekRow( LAST_POS
);
522 sal_Bool SAL_CALL
OResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
)
524 OSL_TRACE("In/Out: OResultSet::absolute" );
525 return seekRow( ABSOLUTE_POS
, row
);
528 sal_Bool SAL_CALL
OResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
)
530 OSL_TRACE("In/Out: OResultSet::relative" );
531 return seekRow( RELATIVE_POS
, row
);
534 sal_Bool SAL_CALL
OResultSet::previous( ) throw(SQLException
, RuntimeException
)
536 ResultSetEntryGuard
aGuard( *this );
537 OSL_TRACE("In/Out: OResultSet::previous" );
538 return seekRow( PRIOR_POS
);
541 Reference
< XInterface
> SAL_CALL
OResultSet::getStatement( ) throw(SQLException
, RuntimeException
)
543 ResultSetEntryGuard
aGuard( *this );
545 OSL_TRACE("In/Out: OResultSet::getStatement" );
550 sal_Bool SAL_CALL
OResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
)
552 ResultSetEntryGuard
aGuard( *this );
553 OSL_TRACE("In/Out: OResultSet::rowDeleted, m_RowStates=%u",m_RowStates
);
554 return ((m_RowStates
& RowStates_Deleted
) == RowStates_Deleted
) ;
557 sal_Bool SAL_CALL
OResultSet::rowInserted( ) throw(SQLException
, RuntimeException
)
559 ResultSetEntryGuard
aGuard( *this );
560 OSL_TRACE("In/Out: OResultSet::rowInserted,m_RowStates=%u",m_RowStates
);
561 return ((m_RowStates
& RowStates_Inserted
) == RowStates_Inserted
);
564 sal_Bool SAL_CALL
OResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
)
566 ResultSetEntryGuard
aGuard( *this );
567 OSL_TRACE("In/Out: OResultSet::rowUpdated,m_RowStates=%u",m_RowStates
);
568 return ((m_RowStates
& RowStates_Updated
) == RowStates_Updated
) ;
572 sal_Bool SAL_CALL
OResultSet::next( ) throw(SQLException
, RuntimeException
)
574 return seekRow( NEXT_POS
);
578 sal_Bool SAL_CALL
OResultSet::wasNull( ) throw(SQLException
, RuntimeException
)
580 ResultSetEntryGuard
aGuard( *this );
586 void SAL_CALL
OResultSet::cancel( ) throw(RuntimeException
)
588 ResultSetEntryGuard
aGuard( *this );
589 OSL_TRACE("In/Out: OResultSet::cancel" );
593 void SAL_CALL
OResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
)
595 OSL_TRACE("In/Out: OResultSet::clearWarnings" );
598 Any SAL_CALL
OResultSet::getWarnings( ) throw(SQLException
, RuntimeException
)
600 OSL_TRACE("In/Out: OResultSet::getWarnings" );
604 void SAL_CALL
OResultSet::refreshRow( ) throw(SQLException
, RuntimeException
)
606 OSL_TRACE("In/Out: OResultSet::refreshRow" );
607 if (fetchRow(getCurrentCardNumber(),sal_True
)) //force fetch current row will cause we lose all change to the current row
608 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_REFRESH_ROW
, *this );
611 IPropertyArrayHelper
* OResultSet::createArrayHelper( ) const
613 Sequence
< Property
> aProps(5);
614 Property
* pProperties
= aProps
.getArray();
616 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
617 PROPERTY_ID_FETCHDIRECTION
, cppu::UnoType
<sal_Int32
>::get(), 0);
619 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
620 PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
622 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE
),
623 PROPERTY_ID_ISBOOKMARKABLE
, cppu::UnoType
<bool>::get(), PropertyAttribute::READONLY
);
625 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
626 PROPERTY_ID_RESULTSETCONCURRENCY
, cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
628 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
629 PROPERTY_ID_RESULTSETTYPE
, cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
631 return new OPropertyArrayHelper(aProps
);
634 IPropertyArrayHelper
& OResultSet::getInfoHelper()
636 return *const_cast<OResultSet
*>(this)->getArrayHelper();
639 sal_Bool
OResultSet::convertFastPropertyValue(
640 Any
& /*rConvertedValue*/,
643 const Any
& /*rValue*/ )
644 throw (::com::sun::star::lang::IllegalArgumentException
)
646 OSL_FAIL( "OResultSet::convertFastPropertyValue: not implemented!" );
649 case PROPERTY_ID_ISBOOKMARKABLE
:
650 case PROPERTY_ID_RESULTSETCONCURRENCY
:
651 case PROPERTY_ID_RESULTSETTYPE
:
652 throw ::com::sun::star::lang::IllegalArgumentException();
653 case PROPERTY_ID_FETCHDIRECTION
:
654 case PROPERTY_ID_FETCHSIZE
:
661 void OResultSet::setFastPropertyValue_NoBroadcast(
663 const Any
& /*rValue*/
667 OSL_FAIL( "OResultSet::setFastPropertyValue_NoBroadcast: not implemented!" );
670 case PROPERTY_ID_ISBOOKMARKABLE
:
671 case PROPERTY_ID_RESULTSETCONCURRENCY
:
672 case PROPERTY_ID_RESULTSETTYPE
:
674 case PROPERTY_ID_FETCHDIRECTION
:
676 case PROPERTY_ID_FETCHSIZE
:
683 void OResultSet::getFastPropertyValue(
690 case PROPERTY_ID_RESULTSETCONCURRENCY
:
691 rValue
<<= (sal_Int32
)m_nResultSetConcurrency
;
693 case PROPERTY_ID_RESULTSETTYPE
:
694 rValue
<<= m_nResultSetType
;
696 case PROPERTY_ID_FETCHDIRECTION
:
697 rValue
<<= m_nFetchDirection
;
699 case PROPERTY_ID_FETCHSIZE
:
700 rValue
<<= m_nFetchSize
;
702 case PROPERTY_ID_ISBOOKMARKABLE
:
703 const_cast< OResultSet
* >( this )->determineReadOnly();
704 rValue
<<= !m_bIsReadOnly
;
709 void SAL_CALL
OResultSet::acquire() throw()
711 OResultSet_BASE::acquire();
714 void SAL_CALL
OResultSet::release() throw()
716 OResultSet_BASE::release();
719 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
721 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
725 void OResultSet::parseParameter( const OSQLParseNode
* pNode
, OUString
& rMatchString
)
727 OSL_ENSURE(pNode
->count() > 0,"Error parsing parameter in Parse Tree");
728 OSQLParseNode
*pMark
= pNode
->getChild(0);
730 // Initialize to empty string
733 OUString aParameterName
;
734 if (SQL_ISPUNCTUATION(pMark
,"?")) {
735 aParameterName
= "?";
737 else if (SQL_ISPUNCTUATION(pMark
,":")) {
738 aParameterName
= pNode
->getChild(1)->getTokenValue();
740 // XXX - Now we know name, what's value????
742 OSL_TRACE("Parameter name [%d]: %s", m_nParamIndex
,OUtoCStr(aParameterName
) );
744 if ( m_aParameterRow
.is() ) {
745 OSL_ENSURE( m_nParamIndex
< (sal_Int32
)m_aParameterRow
->get().size() + 1, "More parameters than values found" );
746 rMatchString
= (m_aParameterRow
->get())[(sal_uInt16
)m_nParamIndex
];
747 #if OSL_DEBUG_LEVEL > 0
748 OSL_TRACE("Prop Value : %s", OUtoCStr( rMatchString
) );
751 #if OSL_DEBUG_LEVEL > 0
753 OSL_TRACE("Prop Value : Invalid ParameterRow!" );
759 #define ALT_WILDCARD "*"
760 static const sal_Unicode MATCHCHAR
= '_';
762 void OResultSet::analyseWhereClause( const OSQLParseNode
* parseTree
,
763 MQueryExpression
&queryExpression
)
766 MQueryOp::cond_type
op( MQueryOp::Is
);
767 OUString matchString
;
769 if ( parseTree
== NULL
)
772 if ( m_pSQLIterator
->getParseTree() != NULL
) {
773 ::rtl::Reference
<OSQLColumns
> xColumns
= m_pSQLIterator
->getParameters();
776 OUString aColName
, aParameterValue
;
777 OSQLColumns::Vector::iterator aIter
= xColumns
->get().begin();
779 for(;aIter
!= xColumns
->get().end();++aIter
)
781 (*aIter
)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
)) >>= aColName
;
782 OSL_TRACE("Prop Column Name : %s", OUtoCStr( aColName
) );
783 if ( m_aParameterRow
.is() ) {
784 aParameterValue
= (m_aParameterRow
->get())[(sal_uInt16
)i
];
785 #if OSL_DEBUG_LEVEL > 0
786 OSL_TRACE("Prop Value : %s", OUtoCStr( aParameterValue
) );
789 #if OSL_DEBUG_LEVEL > 0
791 OSL_TRACE("Prop Value : Invalid ParameterRow!" );
800 if ( SQL_ISRULE(parseTree
,where_clause
) )
802 OSL_TRACE("analyseSQL : Got WHERE clause");
803 // Reset Parameter Counter
805 analyseWhereClause( parseTree
->getChild( 1 ), queryExpression
);
807 else if ( parseTree
->count() == 3 && // Handle ()'s
808 SQL_ISPUNCTUATION(parseTree
->getChild(0),"(") &&
809 SQL_ISPUNCTUATION(parseTree
->getChild(2),")"))
812 OSL_TRACE("analyseSQL : Got Punctuation ()");
813 MQueryExpression
*subExpression
= new MQueryExpression();
814 analyseWhereClause( parseTree
->getChild( 1 ), *subExpression
);
815 queryExpression
.getExpressions().push_back( subExpression
);
817 else if ((SQL_ISRULE(parseTree
,search_condition
) || (SQL_ISRULE(parseTree
,boolean_term
)))
818 && parseTree
->count() == 3) // Handle AND/OR
821 OSL_TRACE("analyseSQL : Got AND/OR clause");
823 // TODO - Need to take care or AND, for now match is always OR
824 analyseWhereClause( parseTree
->getChild( 0 ), queryExpression
);
825 analyseWhereClause( parseTree
->getChild( 2 ), queryExpression
);
827 if (SQL_ISTOKEN(parseTree
->getChild(1),OR
)) { // OR-Operator
828 queryExpression
.setExpressionCondition( MQueryExpression::OR
);
830 else if (SQL_ISTOKEN(parseTree
->getChild(1),AND
)) { // AND-Operator
831 queryExpression
.setExpressionCondition( MQueryExpression::AND
);
834 OSL_FAIL("analyseSQL: Error in Parse Tree");
837 else if (SQL_ISRULE(parseTree
,comparison_predicate
))
839 OSL_ENSURE(parseTree
->count() == 3, "Error parsing COMPARE predicate");
840 if (!(SQL_ISRULE(parseTree
->getChild(0),column_ref
) ||
841 parseTree
->getChild(2)->getNodeType() == SQL_NODE_STRING
||
842 parseTree
->getChild(2)->getNodeType() == SQL_NODE_INTNUM
||
843 parseTree
->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM
||
844 SQL_ISTOKEN(parseTree
->getChild(2),TRUE
) ||
845 SQL_ISTOKEN(parseTree
->getChild(2),FALSE
) ||
846 SQL_ISRULE(parseTree
->getChild(2),parameter
) ||
848 (SQL_ISRULE(parseTree
->getChild(2),set_fct_spec
) && SQL_ISPUNCTUATION(parseTree
->getChild(2)->getChild(0),"{"))))
850 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
853 OSQLParseNode
*pPrec
= parseTree
->getChild(1);
854 if (pPrec
->getNodeType() == SQL_NODE_EQUAL
)
856 else if (pPrec
->getNodeType() == SQL_NODE_NOTEQUAL
)
857 op
= MQueryOp::IsNot
;
859 OUString sTableRange
;
860 if(SQL_ISRULE(parseTree
->getChild(0),column_ref
))
861 m_pSQLIterator
->getColumnRange(parseTree
->getChild(0),columnName
,sTableRange
);
862 else if(parseTree
->getChild(0)->isToken())
863 columnName
= parseTree
->getChild(0)->getTokenValue();
865 if ( SQL_ISRULE(parseTree
->getChild(2),parameter
) ) {
866 parseParameter( parseTree
->getChild(2), matchString
);
869 matchString
= parseTree
->getChild(2)->getTokenValue();
872 if ( columnName
.equalsAscii("0") && op
== MQueryOp::Is
&&
873 matchString
.equalsAscii("1") ) {
874 OSL_TRACE("Query always evaluates to FALSE");
875 m_bIsAlwaysFalseQuery
= sal_True
;
877 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
, matchString
));
879 else if (SQL_ISRULE(parseTree
,like_predicate
))
881 OSL_ENSURE(parseTree
->count() == 2, "Error parsing LIKE predicate");
883 OSL_TRACE("analyseSQL : Got LIKE rule");
885 if ( !(SQL_ISRULE(parseTree
->getChild(0), column_ref
)) )
887 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_COLUMN
, *this );
891 OSQLParseNode
*pColumn
;
892 OSQLParseNode
*pAtom
;
893 OSQLParseNode
*pOptEscape
;
894 const OSQLParseNode
* pPart2
= parseTree
->getChild(1);
895 pColumn
= parseTree
->getChild(0); // Match Item
896 pAtom
= pPart2
->getChild(static_cast<sal_uInt32
>(pPart2
->count()-2)); // Match String
897 pOptEscape
= pPart2
->getChild(static_cast<sal_uInt32
>(pPart2
->count()-1)); // Opt Escape Rule
899 const bool bNot
= SQL_ISTOKEN(pPart2
->getChild(0), NOT
);
901 if (!(pAtom
->getNodeType() == SQL_NODE_STRING
||
902 pAtom
->getNodeType() == SQL_NODE_NAME
||
903 SQL_ISRULE(pAtom
,parameter
) ||
904 ( pAtom
->getChild(0) && pAtom
->getChild(0)->getNodeType() == SQL_NODE_NAME
) ||
905 ( pAtom
->getChild(0) && pAtom
->getChild(0)->getNodeType() == SQL_NODE_STRING
)
908 OSL_TRACE("analyseSQL : pAtom->count() = %d", pAtom
->count() );
910 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING
, *this );
913 OUString sTableRange
;
914 if(SQL_ISRULE(pColumn
,column_ref
))
915 m_pSQLIterator
->getColumnRange(pColumn
,columnName
,sTableRange
);
917 OSL_TRACE("ColumnName = %s", OUtoCStr( columnName
) );
919 if ( SQL_ISRULE(pAtom
,parameter
) ) {
920 parseParameter( pAtom
, matchString
);
921 // Replace all '*' with '%' : UI Usually does this but not with
922 // Parameters for some reason.
923 matchString
= matchString
.replaceAll( ALT_WILDCARD
, WILDCARD
);
927 matchString
= pAtom
->getTokenValue();
930 // Determine where '%' character is...
932 if ( matchString
.equals( WILDCARD
) )
934 // String containing only a '%' and nothing else
935 op
= MQueryOp::Exists
;
936 // Will be ignored for Exists case, but clear anyway.
939 else if ( matchString
.indexOf ( WILDCARD
) == -1 &&
940 matchString
.indexOf ( MATCHCHAR
) == -1 )
942 // Simple string , eg. "to match"
944 op
= MQueryOp::DoesNotContain
;
946 op
= MQueryOp::Contains
;
948 else if ( matchString
.startsWith( WILDCARD
)
949 && matchString
.endsWith( WILDCARD
)
950 && matchString
.indexOf ( WILDCARD
, 1 ) == matchString
.lastIndexOf ( WILDCARD
)
951 && matchString
.indexOf( MATCHCHAR
) == -1
954 // Relatively simple "%string%" - ie, contains...
955 // Cut '%' from front and rear
956 matchString
= matchString
.replaceAt( 0, 1, OUString() );
957 matchString
= matchString
.replaceAt( matchString
.getLength() -1 , 1, OUString() );
960 op
= MQueryOp::DoesNotContain
;
962 op
= MQueryOp::Contains
;
966 // We currently can't handle a 'NOT LIKE' when there are '%' or
967 // '_' dispersed throughout
968 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_NOT_LIKE_TOO_COMPLEX
, *this );
972 if ( (matchString
.indexOf ( WILDCARD
) == matchString
.lastIndexOf ( WILDCARD
))
973 && matchString
.indexOf( MATCHCHAR
) == -1
976 // One occurrence of '%' - no '_' matches...
977 if ( matchString
.startsWith( WILDCARD
) )
979 op
= MQueryOp::EndsWith
;
980 matchString
= matchString
.replaceAt( 0, 1, OUString());
982 else if ( matchString
.endsWith( WILDCARD
) )
984 op
= MQueryOp::BeginsWith
;
985 matchString
= matchString
.replaceAt( matchString
.getLength() -1, 1, OUString() );
989 sal_Int32 pos
= matchString
.indexOf ( WILDCARD
);
990 matchString
= matchString
.replaceAt( pos
, 1, ".*" );
991 op
= MQueryOp::RegExp
;
997 // Most Complex, need to use an RE
999 while ( (pos
= matchString
.indexOf ( WILDCARD
)) != -1 )
1001 matchString
= matchString
.replaceAt( pos
, 1, ".*" );
1004 while ( (pos
= matchString
.indexOf( MATCHCHAR
)) != -1 )
1006 matchString
= matchString
.replaceAt( pos
, 1, "." );
1009 op
= MQueryOp::RegExp
;
1013 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
, matchString
));
1015 else if (SQL_ISRULE(parseTree
,test_for_null
))
1017 OSL_ENSURE(parseTree
->count() == 2,"Error in ParseTree");
1018 const OSQLParseNode
* pPart2
= parseTree
->getChild(1);
1019 OSL_ENSURE(SQL_ISTOKEN(pPart2
->getChild(0),IS
),"Error in ParseTree");
1021 if (!SQL_ISRULE(parseTree
->getChild(0),column_ref
))
1023 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_IS_NULL_COLUMN
, *this );
1026 if (SQL_ISTOKEN(pPart2
->getChild(1),NOT
))
1028 op
= MQueryOp::Exists
;
1031 op
= MQueryOp::DoesNotExist
;
1033 OUString sTableRange
;
1034 m_pSQLIterator
->getColumnRange(parseTree
->getChild(0),columnName
,sTableRange
);
1036 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
));
1040 OSL_TRACE( "Unexpected statement!!!" );
1042 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
1049 void OResultSet::fillRowData()
1050 throw( ::com::sun::star::sdbc::SQLException
)
1052 OSL_ENSURE( m_pStatement
, "Require a statement" );
1054 MQueryExpression queryExpression
;
1056 OConnection
* xConnection
= static_cast<OConnection
*>(m_pStatement
->getConnection().get());
1057 m_xColumns
= m_pSQLIterator
->getSelectColumns();
1059 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
1061 OSQLColumns::Vector::const_iterator aIter
= m_xColumns
->get().begin();
1062 const OUString sProprtyName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
);
1064 m_aAttributeStrings
.clear();
1065 m_aAttributeStrings
.reserve(m_xColumns
->get().size());
1066 for (sal_Int32 i
= 1; aIter
!= m_xColumns
->get().end();++aIter
, i
++)
1068 (*aIter
)->getPropertyValue(sProprtyName
) >>= sName
;
1069 #if OSL_DEBUG_LEVEL > 0
1070 OSL_TRACE("Query Columns : (%d) %s", i
, OUtoCStr(sName
) );
1072 m_aAttributeStrings
.push_back( sName
);
1076 // Generate Match Conditions for Query
1077 const OSQLParseNode
* pParseTree
= m_pSQLIterator
->getWhereTree();
1079 // const OSQLParseNode* pParseTree = NULL;
1081 m_bIsAlwaysFalseQuery
= sal_False
;
1082 if ( pParseTree
!= NULL
)
1084 // Extract required info
1086 OSL_TRACE("\tHave a Where Clause");
1088 analyseWhereClause( pParseTree
, queryExpression
);
1092 OSL_TRACE("\tDon't have a Where Clause");
1094 MQueryExpression::ExprVector eVector
;
1096 // LDAP does not allow a query without restriction, so we add a dummy
1098 // For other types we stick to the old behaviour of using
1100 OSL_ENSURE(m_pStatement
, "Cannot determine Parent Statement");
1102 if (xConnection
->isLDAP())
1103 aStr
= "PrimaryEmail";
1105 aStr
= "card:nsIAbCard";
1106 eVector
.push_back( new MQueryExpressionString(aStr
, MQueryOp::Exists
) );
1108 queryExpression
.setExpressions( eVector
);
1111 // If the query is a 0=1 then set Row count to 0 and return
1112 if ( m_bIsAlwaysFalseQuery
)
1118 m_aQuery
.setExpression( queryExpression
);
1120 OUString
aStr( m_pTable
->getName() );
1121 m_aQuery
.setAddressbook( aStr
);
1123 sal_Int32 rv
= m_aQuery
.executeQuery(xConnection
);
1125 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERR_EXECUTING_QUERY
, *this );
1127 //determine whether the address book is readonly
1128 determineReadOnly();
1130 #if OSL_DEBUG_LEVEL > 0
1131 OSL_TRACE( "executeQuery returned %d", rv
);
1133 OSL_TRACE( "\tOUT OResultSet::fillRowData()" );
1138 static sal_Bool
matchRow( OValueRow
& row1
, OValueRow
& row2
)
1140 OValueVector::Vector::iterator row1Iter
= row1
->get().begin();
1141 OValueVector::Vector::iterator row2Iter
= row2
->get().begin();
1142 for ( ++row1Iter
,++row2Iter
; // the first column is the bookmark column
1143 row1Iter
!= row1
->get().end(); ++row1Iter
,++row2Iter
)
1145 if ( row1Iter
->isBound())
1147 // Compare values, if at anytime there's a mismatch return false
1148 if ( !( (*row1Iter
) == (*row2Iter
) ) )
1153 // If we get to here the rows match
1156 sal_Int32
OResultSet::getRowForCardNumber(sal_Int32 nCardNum
)
1158 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, nCardNum = %u", nCardNum
);
1160 if ( m_pKeySet
.is() )
1163 for(nPos
=0;nPos
< (sal_Int32
)m_pKeySet
->get().size();nPos
++)
1165 if (nCardNum
== (m_pKeySet
->get())[nPos
])
1167 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, return = %u", nPos
+1 );
1173 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK
, *this );
1178 void SAL_CALL
OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLException
,
1179 ::com::sun::star::uno::RuntimeException
)
1181 ResultSetEntryGuard
aGuard( *this );
1183 OSL_ENSURE( m_pTable
, "Need a Table object");
1186 const OSQLTables
& xTabs
= m_pSQLIterator
->getTables();
1187 if ((xTabs
.begin() == xTabs
.end()) || !xTabs
.begin()->second
.is())
1188 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
1190 m_pTable
= static_cast< OTable
* > ((xTabs
.begin()->second
).get());
1198 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
1200 switch( m_pSQLIterator
->getStatementType() )
1202 case SQL_STATEMENT_SELECT
:
1204 if(m_bIsAlwaysFalseQuery
) {
1209 m_pStatement
->getOwnConnection()->throwSQLException( STR_NO_COUNT_SUPPORT
, *this );
1213 sal_Bool bDistinct
= sal_False
;
1214 OSQLParseNode
*pDistinct
= m_pParseTree
->getChild(1);
1215 if (pDistinct
&& pDistinct
->getTokenID() == SQL_TOKEN_DISTINCT
)
1219 m_aOrderbyColumnNumber
.push_back(m_aColMapping
[1]);
1220 m_aOrderbyAscending
.push_back(SQL_DESC
);
1222 bDistinct
= sal_True
;
1225 OSortIndex::TKeyTypeVector
eKeyType(m_aOrderbyColumnNumber
.size());
1226 ::std::vector
<sal_Int32
>::iterator aOrderByIter
= m_aOrderbyColumnNumber
.begin();
1227 for ( ::std::vector
<sal_Int16
>::size_type i
= 0; aOrderByIter
!= m_aOrderbyColumnNumber
.end(); ++aOrderByIter
,++i
)
1229 OSL_ENSURE((sal_Int32
)m_aRow
->get().size() > *aOrderByIter
,"Invalid Index");
1230 switch ((m_aRow
->get().begin()+*aOrderByIter
)->getTypeKind())
1232 case DataType::CHAR
:
1233 case DataType::VARCHAR
:
1234 eKeyType
[i
] = SQL_ORDERBYKEY_STRING
;
1237 case DataType::OTHER
:
1238 case DataType::TINYINT
:
1239 case DataType::SMALLINT
:
1240 case DataType::INTEGER
:
1241 case DataType::DECIMAL
:
1242 case DataType::NUMERIC
:
1243 case DataType::REAL
:
1244 case DataType::DOUBLE
:
1245 case DataType::DATE
:
1246 case DataType::TIME
:
1247 case DataType::TIMESTAMP
:
1249 eKeyType
[i
] = SQL_ORDERBYKEY_DOUBLE
;
1252 // Other types aren't implemented (so they are always FALSE)
1254 eKeyType
[i
] = SQL_ORDERBYKEY_NONE
;
1255 OSL_FAIL("MResultSet::executeQuery: Order By Data Type not implemented");
1262 // Implement Sorting
1264 // So that we can sort we need to wait until the executed
1265 // query to the mozilla addressbooks has returned all
1268 OSL_TRACE("Query is to be sorted");
1269 if( ! m_aQuery
.queryComplete() )
1270 if ( !m_aQuery
.waitForQueryComplete() )
1272 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1275 OSL_ENSURE( m_aQuery
.queryComplete(), "Query not complete!!");
1277 m_pSortIndex
= new OSortIndex(eKeyType
,m_aOrderbyAscending
);
1279 OSL_TRACE("OrderbyColumnNumber->size() = %d",m_aOrderbyColumnNumber
.size());
1280 #if OSL_DEBUG_LEVEL > 0
1281 for ( ::std::vector
<sal_Int32
>::size_type i
= 0; i
< m_aColMapping
.size(); i
++ )
1282 OSL_TRACE("Mapped: %d -> %d", i
, m_aColMapping
[i
] );
1284 for ( sal_Int32 nRow
= 1; nRow
<= m_aQuery
.getRowCount(); nRow
++ ) {
1286 OKeyValue
* pKeyValue
= OKeyValue::createKeyValue((nRow
));
1288 ::std::vector
<sal_Int32
>::iterator aIter
= m_aOrderbyColumnNumber
.begin();
1289 for (;aIter
!= m_aOrderbyColumnNumber
.end(); ++aIter
)
1291 const ORowSetValue
& value
= getValue(nRow
, *aIter
);
1293 OSL_TRACE( "Adding Value: (%d,%d) : %s", nRow
, *aIter
,OUtoCStr( value
));
1295 pKeyValue
->pushKey(new ORowSetValueDecorator(value
));
1298 m_pSortIndex
->AddKeyValue( pKeyValue
);
1301 m_pKeySet
= m_pSortIndex
->CreateKeySet();
1302 m_CurrentRowCount
= static_cast<sal_Int32
>(m_pKeySet
->get().size());
1303 #if OSL_DEBUG_LEVEL > 0
1304 for( OKeySet::Vector::size_type i
= 0; i
< m_pKeySet
->get().size(); i
++ )
1305 OSL_TRACE("Sorted: %d -> %d", i
, (m_pKeySet
->get())[i
] );
1308 m_pSortIndex
= NULL
;
1309 beforeFirst(); // Go back to start
1311 else //we always need m_pKeySet now
1312 m_pKeySet
= new OKeySet();
1314 // Handle the DISTINCT case
1315 if ( bDistinct
&& m_pKeySet
.is() )
1317 OValueRow aSearchRow
= new OValueVector( m_aRow
->get().size() );
1319 for( OKeySet::Vector::size_type i
= 0; i
< m_pKeySet
->get().size(); i
++ )
1321 fetchRow( (m_pKeySet
->get())[i
] ); // Fills m_aRow
1322 if ( matchRow( m_aRow
, aSearchRow
) )
1324 (m_pKeySet
->get())[i
] = 0; // Marker for later to be removed
1328 // They don't match, so it's not a duplicate.
1329 // Use the current Row as the next one to match against
1330 *aSearchRow
= *m_aRow
;
1333 // Now remove any keys marked with a 0
1334 m_pKeySet
->get().erase(::std::remove_if(m_pKeySet
->get().begin(),m_pKeySet
->get().end()
1335 ,::std::bind2nd(::std::equal_to
<sal_Int32
>(),0))
1336 ,m_pKeySet
->get().end());
1342 case SQL_STATEMENT_UPDATE
:
1343 case SQL_STATEMENT_DELETE
:
1344 case SQL_STATEMENT_INSERT
:
1347 m_pStatement
->getOwnConnection()->throwSQLException( STR_STMT_TYPE_NOT_SUPPORTED
, *this );
1354 void OResultSet::setBoundedColumns(const OValueRow
& _rRow
,
1355 const ::rtl::Reference
<connectivity::OSQLColumns
>& _rxColumns
,
1356 const Reference
<XIndexAccess
>& _xNames
,
1357 sal_Bool _bSetColumnMapping
,
1358 const Reference
<XDatabaseMetaData
>& _xMetaData
,
1359 ::std::vector
<sal_Int32
>& _rColMapping
)
1361 ::comphelper::UStringMixEqual
aCase(_xMetaData
->supportsMixedCaseQuotedIdentifiers());
1363 Reference
<XPropertySet
> xTableColumn
;
1364 OUString sTableColumnName
, sSelectColumnRealName
;
1366 const OUString sName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
);
1367 const OUString sRealName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME
);
1369 ::std::vector
< OUString
> aColumnNames
;
1370 aColumnNames
.reserve(_rxColumns
->get().size());
1371 OValueVector::Vector::iterator aRowIter
= _rRow
->get().begin()+1;
1372 for (sal_Int32 i
=0; // the first column is the bookmark column
1373 aRowIter
!= _rRow
->get().end();
1379 // get the table column and its name
1380 _xNames
->getByIndex(i
) >>= xTableColumn
;
1381 OSL_ENSURE(xTableColumn
.is(), "OResultSet::setBoundedColumns: invalid table column!");
1382 if (xTableColumn
.is())
1383 xTableColumn
->getPropertyValue(sName
) >>= sTableColumnName
;
1385 sTableColumnName
= "";
1387 // look if we have such a select column
1388 // TODO: would like to have a O(log n) search here ...
1389 sal_Int32 nColumnPos
= 0;
1390 for ( OSQLColumns::Vector::iterator aIter
= _rxColumns
->get().begin();
1391 aIter
!= _rxColumns
->get().end();
1392 ++aIter
,++nColumnPos
1395 if ( nColumnPos
< (sal_Int32
)aColumnNames
.size() )
1396 sSelectColumnRealName
= aColumnNames
[nColumnPos
];
1399 if((*aIter
)->getPropertySetInfo()->hasPropertyByName(sRealName
))
1400 (*aIter
)->getPropertyValue(sRealName
) >>= sSelectColumnRealName
;
1402 (*aIter
)->getPropertyValue(sName
) >>= sSelectColumnRealName
;
1403 aColumnNames
.push_back(sSelectColumnRealName
);
1406 if (aCase(sTableColumnName
, sSelectColumnRealName
))
1408 if(_bSetColumnMapping
)
1410 sal_Int32 nSelectColumnPos
= static_cast<sal_Int32
>(aIter
- _rxColumns
->get().begin() + 1);
1411 // the getXXX methods are 1-based ...
1412 sal_Int32 nTableColumnPos
= i
+ 1;
1413 // get first table column is the bookmark column
1415 #if OSL_DEBUG_LEVEL > 0
1416 OSL_TRACE("Set Col Mapping: %d -> %d", nSelectColumnPos
, nTableColumnPos
);
1418 _rColMapping
[nSelectColumnPos
] = nTableColumnPos
;
1421 aRowIter
->setBound(sal_True
);
1422 aRowIter
->setTypeKind(DataType::VARCHAR
);
1428 OSL_FAIL("OResultSet::setBoundedColumns: caught an Exception!");
1435 sal_Bool
OResultSet::isCount() const
1437 return (m_pParseTree
&&
1438 m_pParseTree
->count() > 2 &&
1439 SQL_ISRULE(m_pParseTree
->getChild(2),scalar_exp_commalist
) &&
1440 SQL_ISRULE(m_pParseTree
->getChild(2)->getChild(0),derived_column
) &&
1441 SQL_ISRULE(m_pParseTree
->getChild(2)->getChild(0)->getChild(0),general_set_fct
) &&
1442 m_pParseTree
->getChild(2)->getChild(0)->getChild(0)->count() == 4
1448 // Check for valid row in m_aQuery
1450 sal_Bool
OResultSet::validRow( sal_uInt32 nRow
)
1452 sal_Int32 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1454 while ( nRow
> (sal_uInt32
)nNumberOfRecords
&& !m_aQuery
.queryComplete() ) {
1455 #if OSL_DEBUG_LEVEL > 0
1456 OSL_TRACE("validRow: waiting...");
1458 m_aQuery
.checkRowAvailable( nRow
);
1459 if ( m_aQuery
.hadError() )
1461 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1463 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1466 if (( nRow
== 0 ) ||
1467 ( nRow
> (sal_uInt32
)nNumberOfRecords
&& m_aQuery
.queryComplete()) ){
1468 OSL_TRACE("validRow(%u): return False", nRow
);
1471 #if OSL_DEBUG_LEVEL > 0
1472 OSL_TRACE("validRow(%u): return True", nRow
);
1476 sal_Bool
OResultSet::fillKeySet(sal_Int32 nMaxCardNumber
)
1478 impl_ensureKeySet();
1479 if (m_CurrentRowCount
< nMaxCardNumber
)
1481 sal_Int32 nKeyValue
;
1482 if ( (sal_Int32
)m_pKeySet
->get().capacity() < nMaxCardNumber
)
1483 m_pKeySet
->get().reserve(nMaxCardNumber
+ 20 );
1485 for (nKeyValue
= m_CurrentRowCount
+1; nKeyValue
<= nMaxCardNumber
; nKeyValue
++)
1486 m_pKeySet
->get().push_back( nKeyValue
);
1487 m_CurrentRowCount
= nMaxCardNumber
;
1492 sal_Int32
OResultSet::deletedCount()
1494 impl_ensureKeySet();
1495 return m_CurrentRowCount
- static_cast<sal_Int32
>(m_pKeySet
->get().size());
1499 sal_Bool
OResultSet::seekRow( eRowPosition pos
, sal_Int32 nOffset
)
1501 ResultSetEntryGuard
aGuard( *this );
1502 if ( !m_pKeySet
.is() )
1503 m_pStatement
->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT
, *this );
1505 sal_Int32 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1506 sal_Int32 nRetrievedRows
= currentRowCount();
1507 sal_Int32 nCurPos
= m_nRowPos
;
1509 OSL_TRACE("seekRow: nCurPos = %d", nCurPos
);
1512 OSL_TRACE("seekRow: NEXT");
1516 OSL_TRACE("seekRow: PRIOR");
1522 OSL_TRACE("seekRow: FIRST");
1527 OSL_TRACE("seekRow: LAST");
1528 nCurPos
= nRetrievedRows
;
1531 OSL_TRACE("seekRow: ABSOLUTE : %d", nOffset
);
1535 OSL_TRACE("seekRow: RELATIVE : %d", nOffset
);
1536 nCurPos
+= sal_uInt32( nOffset
);
1540 if ( nCurPos
<= 0 ) {
1542 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos
);
1545 sal_Int32 nCurCard
= nCurPos
;
1546 if ( nCurPos
< (sal_Int32
)m_pKeySet
->get().size() ) //The requested row is exist in m_pKeySet, so we just use it
1548 nCurCard
= (m_pKeySet
->get())[nCurPos
-1];
1550 else //The requested row has not been retrieved until now. We should get the right card for it.
1551 nCurCard
= nCurPos
+ deletedCount();
1553 while ( nCurCard
> nNumberOfRecords
&& !m_aQuery
.queryComplete() ) {
1554 m_aQuery
.checkRowAvailable( nCurCard
);
1555 if ( m_aQuery
.hadError() )
1557 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1559 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1562 if ( nCurCard
> nNumberOfRecords
&& m_aQuery
.queryComplete()) {
1563 fillKeySet(nNumberOfRecords
);
1564 m_nRowPos
= static_cast<sal_uInt32
>(m_pKeySet
->get().size() + 1);
1565 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos
);
1568 //Insert new retrieved items for later use
1569 fillKeySet(nNumberOfRecords
);
1570 m_nRowPos
= (sal_uInt32
)nCurPos
;
1571 OSL_TRACE("seekRow: return True, m_nRowPos = %u", m_nRowPos
);
1576 void OResultSet::setColumnMapping(const ::std::vector
<sal_Int32
>& _aColumnMapping
)
1578 m_aColMapping
= _aColumnMapping
;
1579 #if OSL_DEBUG_LEVEL > 0
1580 for ( sal_uInt32 i
= 0; i
< m_aColMapping
.size(); i
++ )
1581 OSL_TRACE("Set Mapped: %d -> %d", i
, m_aColMapping
[i
] );
1586 ::com::sun::star::uno::Any
OResultSet::getBookmark( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1588 OSL_TRACE("getBookmark, m_nRowPos = %u", m_nRowPos
);
1589 ResultSetEntryGuard
aGuard( *this );
1590 if ( fetchCurrentRow() == sal_False
)
1591 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1593 OSL_ENSURE((!m_aRow
->isDeleted()),"getBookmark called for deleted row");
1594 return makeAny((sal_Int32
)(m_aRow
->get())[0]);
1596 sal_Bool
OResultSet::moveToBookmark( const ::com::sun::star::uno::Any
& bookmark
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1598 ResultSetEntryGuard
aGuard( *this );
1599 OSL_TRACE("moveToBookmark, bookmark = %u", comphelper::getINT32(bookmark
) );
1600 sal_Int32 nCardNum
= comphelper::getINT32(bookmark
);
1601 m_nRowPos
= getRowForCardNumber(nCardNum
);
1605 sal_Bool
OResultSet::moveRelativeToBookmark( const ::com::sun::star::uno::Any
& bookmark
, sal_Int32 rows
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1607 ResultSetEntryGuard
aGuard( *this );
1608 OSL_TRACE("moveRelativeToBookmark, bookmark = %u rows= %u", comphelper::getINT32(bookmark
),rows
);
1609 sal_Int32 nCardNum
= comphelper::getINT32(bookmark
);
1610 m_nRowPos
= getRowForCardNumber(nCardNum
);
1611 return seekRow(RELATIVE_POS
,rows
);
1613 sal_Int32
OResultSet::compareBookmarks( const ::com::sun::star::uno::Any
& lhs
, const ::com::sun::star::uno::Any
& rhs
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1615 ResultSetEntryGuard
aGuard( *this );
1616 OSL_TRACE("compareBookmarks, m_nRowPos = %u", m_nRowPos
);
1618 sal_Int32 nSecond
=0;
1619 sal_Int32 nResult
=0;
1621 if ( !( lhs
>>= nFirst
) || !( rhs
>>= nSecond
) )
1622 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK
, *this );
1624 if(nFirst
< nSecond
)
1625 nResult
= CompareBookmark::LESS
;
1626 else if(nFirst
> nSecond
)
1627 nResult
= CompareBookmark::GREATER
;
1629 nResult
= CompareBookmark::EQUAL
;
1633 sal_Bool
OResultSet::hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1635 ResultSetEntryGuard
aGuard( *this );
1636 OSL_TRACE("hasOrderedBookmarks, m_nRowPos = %u", m_nRowPos
);
1639 sal_Int32
OResultSet::hashBookmark( const ::com::sun::star::uno::Any
& bookmark
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1641 ResultSetEntryGuard
aGuard( *this );
1642 OSL_TRACE("hashBookmark, m_nRowPos = %u", m_nRowPos
);
1643 return comphelper::getINT32(bookmark
);
1646 sal_Int32
OResultSet::getCurrentCardNumber()
1648 if ( ( m_nRowPos
== 0 ) || !m_pKeySet
.is() )
1650 if (m_pKeySet
->get().size() < m_nRowPos
)
1652 return (m_pKeySet
->get())[m_nRowPos
-1];
1654 void OResultSet::checkPendingUpdate() throw(SQLException
, RuntimeException
)
1656 OSL_TRACE("checkPendingUpdate, m_nRowPos = %u", m_nRowPos
);
1657 const sal_Int32 nCurrentRow
= getCurrentCardNumber();
1659 if ((m_nNewRow
&& nCurrentRow
!= m_nNewRow
)
1660 || ( m_nUpdatedRow
&& m_nUpdatedRow
!= nCurrentRow
))
1662 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1664 "$position$", OUString::number(nCurrentRow
)
1666 ::dbtools::throwGenericSQLException(sError
,*this);
1670 void OResultSet::updateValue(sal_Int32 columnIndex
,const ORowSetValue
& x
) throw(SQLException
, RuntimeException
)
1672 OSL_TRACE("updateValue, m_nRowPos = %u", m_nRowPos
);
1673 ResultSetEntryGuard
aGuard( *this );
1674 if ( fetchCurrentRow() == sal_False
)
1675 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1678 checkPendingUpdate();
1680 checkIndex(columnIndex
);
1681 columnIndex
= mapColumn(columnIndex
);
1683 (m_aRow
->get())[columnIndex
].setBound(sal_True
);
1684 (m_aRow
->get())[columnIndex
] = x
;
1685 m_nUpdatedRow
= getCurrentCardNumber();
1686 m_RowStates
= m_RowStates
| RowStates_Updated
;
1690 void SAL_CALL
OResultSet::updateNull( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1692 OSL_TRACE("updateNull, m_nRowPos = %u", m_nRowPos
);
1693 ResultSetEntryGuard
aGuard( *this );
1694 if ( fetchCurrentRow() == sal_False
)
1695 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1697 checkPendingUpdate();
1698 checkIndex(columnIndex
);
1699 columnIndex
= mapColumn(columnIndex
);
1701 (m_aRow
->get())[columnIndex
].setBound(sal_True
);
1702 (m_aRow
->get())[columnIndex
].setNull();
1703 m_nUpdatedRow
= getCurrentCardNumber();
1704 m_RowStates
= m_RowStates
| RowStates_Updated
;
1708 void SAL_CALL
OResultSet::updateBoolean( sal_Int32 columnIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
1710 updateValue(columnIndex
, static_cast<bool>(x
));
1713 void SAL_CALL
OResultSet::updateByte( sal_Int32 columnIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
1715 updateValue(columnIndex
,x
);
1719 void SAL_CALL
OResultSet::updateShort( sal_Int32 columnIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
1721 updateValue(columnIndex
,x
);
1724 void SAL_CALL
OResultSet::updateInt( sal_Int32 columnIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
1726 updateValue(columnIndex
,x
);
1729 void SAL_CALL
OResultSet::updateLong( sal_Int32
/*columnIndex*/, sal_Int64
/*x*/ ) throw(SQLException
, RuntimeException
)
1731 ::dbtools::throwFeatureNotImplementedSQLException( "XRowUpdate::updateLong", *this );
1734 void SAL_CALL
OResultSet::updateFloat( sal_Int32 columnIndex
, float x
) throw(SQLException
, RuntimeException
)
1736 updateValue(columnIndex
,x
);
1740 void SAL_CALL
OResultSet::updateDouble( sal_Int32 columnIndex
, double x
) throw(SQLException
, RuntimeException
)
1742 updateValue(columnIndex
,x
);
1745 void SAL_CALL
OResultSet::updateString( sal_Int32 columnIndex
, const OUString
& x
) throw(SQLException
, RuntimeException
)
1747 updateValue(columnIndex
,x
);
1750 void SAL_CALL
OResultSet::updateBytes( sal_Int32 columnIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
1752 updateValue(columnIndex
,x
);
1755 void SAL_CALL
OResultSet::updateDate( sal_Int32 columnIndex
, const ::com::sun::star::util::Date
& x
) throw(SQLException
, RuntimeException
)
1757 updateValue(columnIndex
,x
);
1761 void SAL_CALL
OResultSet::updateTime( sal_Int32 columnIndex
, const ::com::sun::star::util::Time
& x
) throw(SQLException
, RuntimeException
)
1763 updateValue(columnIndex
,x
);
1767 void SAL_CALL
OResultSet::updateTimestamp( sal_Int32 columnIndex
, const ::com::sun::star::util::DateTime
& x
) throw(SQLException
, RuntimeException
)
1769 updateValue(columnIndex
,x
);
1773 void SAL_CALL
OResultSet::updateBinaryStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
1775 ResultSetEntryGuard
aGuard( *this );
1778 ::dbtools::throwFunctionSequenceException(*this);
1780 Sequence
<sal_Int8
> aSeq
;
1781 x
->readBytes(aSeq
,length
);
1782 updateValue(columnIndex
,aSeq
);
1785 void SAL_CALL
OResultSet::updateCharacterStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
1787 updateBinaryStream(columnIndex
,x
,length
);
1790 void SAL_CALL
OResultSet::updateObject( sal_Int32 columnIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
1792 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
1794 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1795 STR_COLUMN_NOT_UPDATEABLE
,
1796 "$position$", OUString::number(columnIndex
)
1798 ::dbtools::throwGenericSQLException(sError
,*this);
1799 } // if (!::dbtools::implUpdateObject(this, columnIndex, x))
1803 void SAL_CALL
OResultSet::updateNumericObject( sal_Int32 columnIndex
, const Any
& x
, sal_Int32
/*scale*/ ) throw(SQLException
, RuntimeException
)
1805 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
1807 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1808 STR_COLUMN_NOT_UPDATEABLE
,
1809 "$position$", OUString::number(columnIndex
)
1811 ::dbtools::throwGenericSQLException(sError
,*this);
1817 void SAL_CALL
OResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1819 ResultSetEntryGuard
aGuard( *this );
1820 OSL_TRACE("insertRow in, m_nRowPos = %u", m_nRowPos
);
1821 m_RowStates
= RowStates_Inserted
;
1825 m_aQuery
.setRowStates(getCurrentCardNumber(),m_RowStates
);
1826 OSL_TRACE("insertRow out, m_nRowPos = %u", m_nRowPos
);
1829 void SAL_CALL
OResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1831 OSL_TRACE("updateRow in, m_nRowPos = %u", m_nRowPos
);
1832 ResultSetEntryGuard
aGuard( *this );
1833 impl_ensureKeySet();
1835 if (!m_nRowPos
|| m_pKeySet
->get().size() < m_nRowPos
)
1836 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_ROW_UPDATE
, *this );
1838 const sal_Int32 nCurrentCard
= getCurrentCardNumber();
1840 if (!pushCard(nCurrentCard
))
1842 m_RowStates
= RowStates_Error
;
1843 m_pStatement
->getOwnConnection()->throwSQLException( STR_ROW_CAN_NOT_SAVE
, *this );
1846 if (!m_aQuery
.commitRow(nCurrentCard
))
1848 m_RowStates
= RowStates_Error
;
1850 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1855 OSL_TRACE("updateRow out, m_nRowPos = %u", m_nRowPos
);
1858 void SAL_CALL
OResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1860 OSL_TRACE("deleteRow, m_nRowPos = %u", m_nRowPos
);
1861 ResultSetEntryGuard
aGuard( *this );
1863 m_pStatement
->getOwnConnection()->throwSQLException( STR_ROW_ALREADY_DELETED
, *this );
1865 const sal_Int32 nCurrentRow
= getCurrentCardNumber();
1866 //fetchRow(nCurrentRow);
1868 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1870 sal_Bool m_bRowDeleted
= ( m_aQuery
.deleteRow( nCurrentRow
) > 0 );
1872 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1874 m_aQuery
.setRowStates(nCurrentRow
,RowStates_Deleted
);
1875 m_pKeySet
->get().erase(m_pKeySet
->get().begin() + m_nRowPos
-1);
1876 m_RowStates
= RowStates_Deleted
;
1877 OSL_TRACE("deleteRow out, m_nRowPos = %u", m_nRowPos
);
1880 void SAL_CALL
OResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1882 ResultSetEntryGuard
aGuard( *this );
1883 OSL_TRACE("cancelRowUpdates, m_nRowPos = %u", m_nRowPos
);
1884 if (fetchRow(getCurrentCardNumber(),sal_True
)) //force fetch current row will cause we lose all change to the current row
1885 m_pStatement
->getOwnConnection()->throwSQLException( STR_CAN_NOT_CANCEL_ROW_UPDATE
, *this );
1888 void SAL_CALL
OResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1890 OSL_TRACE("moveToInsertRow in, m_nRowPos = %u", m_nRowPos
);
1891 ResultSetEntryGuard
aGuard( *this );
1892 m_nOldRowPos
= m_nRowPos
;
1894 if (!m_nNewRow
) //no new row now, insert one
1896 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
1897 checkPendingUpdate();
1900 if (m_nRowPos
&& !pushCard(getCurrentCardNumber()))
1901 throw SQLException();
1903 m_nNewRow
= m_aQuery
.createNewCard();
1905 m_pStatement
->getOwnConnection()->throwSQLException( STR_CAN_NOT_CREATE_ROW
, *this );
1907 m_RowStates
= RowStates_Normal
;
1908 fillKeySet(m_nNewRow
);
1913 m_nRowPos
= static_cast<sal_uInt32
>(m_pKeySet
->get().size());
1915 OSL_TRACE("moveToInsertRow out, m_nRowPos = %u", m_nRowPos
);
1918 void SAL_CALL
OResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1920 ResultSetEntryGuard
aGuard( *this );
1921 OSL_TRACE("moveToCurrentRow, m_nRowPos = %u", m_nRowPos
);
1924 m_nRowPos
= m_nOldRowPos
;
1929 sal_Bool
OResultSet::determineReadOnly()
1931 if (m_bIsReadOnly
== -1)
1933 OConnection
* xConnection
= static_cast<OConnection
*>(m_pStatement
->getConnection().get());
1934 m_bIsReadOnly
= !m_aQuery
.isWritable(xConnection
) || m_bIsAlwaysFalseQuery
;
1937 return m_bIsReadOnly
!= 0;
1940 void OResultSet::setTable(OTable
* _rTable
)
1942 OSL_TRACE("In : setTable");
1944 m_pTable
->acquire();
1945 m_xTableColumns
= m_pTable
->getColumns();
1946 if(m_xTableColumns
.is())
1947 m_aColumnNames
= m_xTableColumns
->getElementNames();
1948 OSL_TRACE("Out : setTable");
1951 void OResultSet::setOrderByColumns(const ::std::vector
<sal_Int32
>& _aColumnOrderBy
)
1953 m_aOrderbyColumnNumber
= _aColumnOrderBy
;
1956 void OResultSet::setOrderByAscending(const ::std::vector
<TAscendingOrder
>& _aOrderbyAsc
)
1958 m_aOrderbyAscending
= _aOrderbyAsc
;
1960 Sequence
< sal_Int32
> SAL_CALL
OResultSet::deleteRows( const Sequence
< Any
>& /*rows*/ ) throw(SQLException
, RuntimeException
)
1962 ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this );
1963 return Sequence
< sal_Int32
>();
1966 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */