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 <comphelper/types.hxx>
32 #include <connectivity/dbexception.hxx>
33 #include <connectivity/dbtools.hxx>
35 #include <TSortIndex.hxx>
36 #include <rtl/string.hxx>
39 #include "MResultSet.hxx"
40 #include "MResultSetMetaData.hxx"
41 #include "FDatabaseMetaDataResultSet.hxx"
42 #include "resource/mozab_res.hrc"
43 #include "resource/common_res.hrc"
45 #if OSL_DEBUG_LEVEL > 0
46 # define OUtoCStr( x ) ( OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
47 #else /* OSL_DEBUG_LEVEL */
48 # define OUtoCStr( x ) ("dummy")
49 #endif /* OSL_DEBUG_LEVEL */
51 using namespace ::comphelper
;
52 using namespace connectivity
;
53 using namespace connectivity::mozab
;
54 using namespace ::cppu
;
55 using namespace com::sun::star::uno
;
56 using namespace com::sun::star::lang
;
57 using namespace com::sun::star::beans
;
58 using namespace com::sun::star::sdbc
;
59 using namespace com::sun::star::container
;
60 using namespace com::sun::star::io
;
61 using namespace com::sun::star::util
;
64 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
65 OUString SAL_CALL
OResultSet::getImplementationName( ) throw ( RuntimeException
) \
67 return OUString("com.sun.star.sdbcx.mozab.ResultSet");
70 Sequence
< OUString
> SAL_CALL
OResultSet::getSupportedServiceNames( ) throw( RuntimeException
)
72 ::com::sun::star::uno::Sequence
< OUString
> aSupported(2);
73 aSupported
[0] = "com.sun.star.sdbc.ResultSet";
74 aSupported
[1] = "com.sun.star.sdbcx.ResultSet";
78 sal_Bool SAL_CALL
OResultSet::supportsService( const OUString
& _rServiceName
) throw( RuntimeException
)
80 return cppu::supportsService(this, _rServiceName
);
84 OResultSet::OResultSet(OCommonStatement
* pStmt
, const ::boost::shared_ptr
< connectivity::OSQLParseTreeIterator
>& _pSQLIterator
)
85 : OResultSet_BASE(m_aMutex
)
86 ,OPropertySetHelper(OResultSet_BASE::rBHelper
)
93 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE
)
94 ,m_nFetchDirection(FetchDirection::FORWARD
)
95 ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE
)
96 ,m_pSQLIterator( _pSQLIterator
)
97 ,m_pParseTree( _pSQLIterator
->getParseTree() )
98 ,m_aQuery( pStmt
->getOwnConnection()->getColumnAlias() )
100 ,m_CurrentRowCount(0)
102 ,m_bIsAlwaysFalseQuery(sal_False
)
110 m_aQuery
.setMaxNrOfReturns(pStmt
->getOwnConnection()->getMaxResultRecords());
113 OResultSet::~OResultSet()
118 void OResultSet::disposing(void)
120 OPropertySetHelper::disposing();
122 ::osl::MutexGuard
aGuard(m_aMutex
);
124 m_xStatement
.clear();
128 m_xParamColumns
= NULL
;
137 Any SAL_CALL
OResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
)
139 Any aRet
= OPropertySetHelper::queryInterface(rType
);
141 aRet
= OResultSet_BASE::queryInterface(rType
);
145 Sequence
< Type
> SAL_CALL
OResultSet::getTypes( ) throw( RuntimeException
)
147 OTypeCollection
aTypes( ::getCppuType( (const Reference
< ::com::sun::star::beans::XMultiPropertySet
> *)0 ),
148 ::getCppuType( (const Reference
< ::com::sun::star::beans::XFastPropertySet
> *)0 ),
149 ::getCppuType( (const Reference
< ::com::sun::star::beans::XPropertySet
> *)0 ));
151 return ::comphelper::concatSequences(aTypes
.getTypes(),OResultSet_BASE::getTypes());
154 void OResultSet::methodEntry()
156 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
159 OSL_FAIL( "OResultSet::methodEntry: looks like we're disposed, but how is this possible?" );
160 throw DisposedException( OUString(), *this );
165 sal_Int32 SAL_CALL
OResultSet::findColumn( const OUString
& columnName
) throw(SQLException
, RuntimeException
)
167 ResultSetEntryGuard
aGuard( *this );
169 // find the first column with the name columnName
170 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
171 sal_Int32 nLen
= xMeta
->getColumnCount();
175 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
176 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
180 ::dbtools::throwInvalidColumnException( columnName
, *this );
182 return 0; // Never reached
185 Reference
< XInputStream
> SAL_CALL
OResultSet::getBinaryStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
190 Reference
< XInputStream
> SAL_CALL
OResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
196 sal_Bool SAL_CALL
OResultSet::getBoolean( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
198 ResultSetEntryGuard
aGuard( *this );
199 m_bWasNull
= sal_True
;
204 sal_Int8 SAL_CALL
OResultSet::getByte( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
206 ResultSetEntryGuard
aGuard( *this );
211 Sequence
< sal_Int8
> SAL_CALL
OResultSet::getBytes( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
213 ResultSetEntryGuard
aGuard( *this );
214 return Sequence
< sal_Int8
>();
218 Date SAL_CALL
OResultSet::getDate( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
220 ResultSetEntryGuard
aGuard( *this );
225 double SAL_CALL
OResultSet::getDouble( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
227 ResultSetEntryGuard
aGuard( *this );
232 float SAL_CALL
OResultSet::getFloat( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
234 ResultSetEntryGuard
aGuard( *this );
239 sal_Int32 SAL_CALL
OResultSet::getInt( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
241 ResultSetEntryGuard
aGuard( *this );
246 sal_Int32 SAL_CALL
OResultSet::getRow( ) throw(SQLException
, RuntimeException
)
248 ResultSetEntryGuard
aGuard( *this );
250 OSL_TRACE("In/Out: OResultSet::getRow, return = %u", m_nRowPos
);
255 sal_Int64 SAL_CALL
OResultSet::getLong( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
257 ResultSetEntryGuard
aGuard( *this );
262 Reference
< XResultSetMetaData
> SAL_CALL
OResultSet::getMetaData( ) throw(SQLException
, RuntimeException
)
264 ResultSetEntryGuard
aGuard( *this );
266 if(!m_xMetaData
.is())
267 m_xMetaData
= new OResultSetMetaData(
268 m_pSQLIterator
->getSelectColumns(), m_pSQLIterator
->getTables().begin()->first
,m_pTable
,determineReadOnly());
272 Reference
< XArray
> SAL_CALL
OResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
279 Reference
< XClob
> SAL_CALL
OResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
284 Reference
< XBlob
> SAL_CALL
OResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
290 Reference
< XRef
> SAL_CALL
OResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
296 Any SAL_CALL
OResultSet::getObject( sal_Int32
/*columnIndex*/, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
)
302 sal_Int16 SAL_CALL
OResultSet::getShort( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
308 void OResultSet::checkIndex(sal_Int32 columnIndex
) throw(::com::sun::star::sdbc::SQLException
)
310 if(columnIndex
<= 0 || columnIndex
> (sal_Int32
)m_xColumns
->get().size())
311 ::dbtools::throwInvalidIndexException(*this);
314 sal_uInt32
OResultSet::currentRowCount()
316 if ( m_bIsAlwaysFalseQuery
)
318 return m_aQuery
.getRealRowCount() - deletedCount();
323 sal_Bool
OResultSet::fetchCurrentRow( ) throw(SQLException
, RuntimeException
)
325 OSL_TRACE("fetchCurrentRow, m_nRowPos = %u", m_nRowPos
);
326 return fetchRow(getCurrentCardNumber());
330 sal_Bool
OResultSet::pushCard(sal_uInt32 cardNumber
) throw(SQLException
, RuntimeException
)
334 // Check whether we are storing the updated row
335 if ( (m_aRow
->get())[0].isNull() || (sal_Int32
)(m_aRow
->get())[0] != (sal_Int32
)cardNumber
)
338 sal_Int32 nCount
= m_aColumnNames
.getLength();
339 m_aQuery
.setRowStates(cardNumber
,m_RowStates
);
340 for( sal_Int32 i
= 1; i
<= nCount
; i
++ )
342 if ( (m_aRow
->get())[i
].isBound() )
345 // Everything in the addressbook is a string!
347 if ( !m_aQuery
.setRowValue( (m_aRow
->get())[i
], cardNumber
, m_aColumnNames
[i
-1], DataType::VARCHAR
))
349 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
357 sal_Bool
OResultSet::fetchRow(sal_Int32 cardNumber
,sal_Bool bForceReload
) throw(SQLException
, RuntimeException
)
359 OSL_TRACE("fetchRow, cardNumber = %u", cardNumber
);
362 // Check whether we've already fetched the row...
363 if ( !(m_aRow
->get())[0].isNull() && (sal_Int32
)(m_aRow
->get())[0] == (sal_Int32
)cardNumber
)
365 //Check whether the old row has been changed
366 if (cardNumber
== m_nUpdatedRow
)
368 //write back the changes first
369 if (!pushCard(cardNumber
)) //error write back the changes
370 throw SQLException();
374 m_aQuery
.resyncRow(cardNumber
);
376 if ( validRow( cardNumber
) == sal_False
)
379 (m_aRow
->get())[0] = (sal_Int32
)cardNumber
;
380 sal_Int32 nCount
= m_aColumnNames
.getLength();
381 m_RowStates
= m_aQuery
.getRowStates(cardNumber
);
382 for( sal_Int32 i
= 1; i
<= nCount
; i
++ )
384 if ( (m_aRow
->get())[i
].isBound() )
387 // Everything in the addressbook is a string!
389 if ( !m_aQuery
.getRowValue( (m_aRow
->get())[i
], cardNumber
, m_aColumnNames
[i
-1], DataType::VARCHAR
))
391 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
399 const ORowSetValue
& OResultSet::getValue(sal_Int32 cardNumber
, sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
401 if ( fetchRow( cardNumber
) == sal_False
)
403 OSL_FAIL("fetchRow() returned False" );
404 m_bWasNull
= sal_True
;
405 return *ODatabaseMetaDataResultSet::getEmptyValue();
408 m_bWasNull
= (m_aRow
->get())[columnIndex
].isNull();
409 return (m_aRow
->get())[columnIndex
];
415 OUString SAL_CALL
OResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
417 ResultSetEntryGuard
aGuard( *this );
419 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
420 OSL_ENSURE(columnIndex
<= (sal_Int32
)m_xColumns
->get().size(), "Trying to access invalid columns number");
421 checkIndex( columnIndex
);
423 // If this query was sorted then we should have a valid KeySet, so use it
424 return getValue(getCurrentCardNumber(), mapColumn( columnIndex
) );
429 Time SAL_CALL
OResultSet::getTime( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
431 ResultSetEntryGuard
aGuard( *this );
437 DateTime SAL_CALL
OResultSet::getTimestamp( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
439 ResultSetEntryGuard
aGuard( *this );
444 sal_Bool SAL_CALL
OResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
)
446 ResultSetEntryGuard
aGuard( *this );
448 // here you have to implement your movements
449 // return true means there is no data
450 OSL_TRACE("In/Out: OResultSet::isBeforeFirst" );
451 return( m_nRowPos
< 1 );
454 sal_Bool SAL_CALL
OResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
)
456 ResultSetEntryGuard
aGuard( *this );
458 OSL_TRACE("In/Out: OResultSet::isAfterLast" );
459 return m_nRowPos
> currentRowCount() && m_aQuery
.queryComplete();
462 sal_Bool SAL_CALL
OResultSet::isFirst( ) throw(SQLException
, RuntimeException
)
464 ResultSetEntryGuard
aGuard( *this );
466 OSL_TRACE("In/Out: OResultSet::isFirst" );
467 return m_nRowPos
== 1;
470 sal_Bool SAL_CALL
OResultSet::isLast( ) throw(SQLException
, RuntimeException
)
472 ResultSetEntryGuard
aGuard( *this );
474 OSL_TRACE("In/Out: OResultSet::isLast" );
475 return m_nRowPos
== currentRowCount() && m_aQuery
.queryComplete();
478 void SAL_CALL
OResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
)
480 ResultSetEntryGuard
aGuard( *this );
482 // move before the first row so that isBeforeFirst returns false
483 OSL_TRACE("In/Out: OResultSet::beforeFirst" );
488 void SAL_CALL
OResultSet::afterLast( ) throw(SQLException
, RuntimeException
)
490 ResultSetEntryGuard
aGuard( *this );
491 OSL_TRACE("In/Out: OResultSet::afterLast" );
498 void SAL_CALL
OResultSet::close( ) throw(SQLException
, RuntimeException
)
500 ResultSetEntryGuard
aGuard( *this );
501 OSL_TRACE("In/Out: OResultSet::close" );
506 sal_Bool SAL_CALL
OResultSet::first( ) throw(SQLException
, RuntimeException
)
508 OSL_TRACE("In/Out: OResultSet::first" );
509 return seekRow( FIRST_POS
);
513 sal_Bool SAL_CALL
OResultSet::last( ) throw(SQLException
, RuntimeException
)
515 OSL_TRACE("In/Out: OResultSet::last" );
516 return seekRow( LAST_POS
);
519 sal_Bool SAL_CALL
OResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
)
521 OSL_TRACE("In/Out: OResultSet::absolute" );
522 return seekRow( ABSOLUTE_POS
, row
);
525 sal_Bool SAL_CALL
OResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
)
527 OSL_TRACE("In/Out: OResultSet::relative" );
528 return seekRow( RELATIVE_POS
, row
);
531 sal_Bool SAL_CALL
OResultSet::previous( ) throw(SQLException
, RuntimeException
)
533 ResultSetEntryGuard
aGuard( *this );
534 OSL_TRACE("In/Out: OResultSet::previous" );
535 return seekRow( PRIOR_POS
);
538 Reference
< XInterface
> SAL_CALL
OResultSet::getStatement( ) throw(SQLException
, RuntimeException
)
540 ResultSetEntryGuard
aGuard( *this );
542 OSL_TRACE("In/Out: OResultSet::getStatement" );
547 sal_Bool SAL_CALL
OResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
)
549 ResultSetEntryGuard
aGuard( *this );
550 OSL_TRACE("In/Out: OResultSet::rowDeleted, m_RowStates=%u",m_RowStates
);
551 return ((m_RowStates
& RowStates_Deleted
) == RowStates_Deleted
) ;
554 sal_Bool SAL_CALL
OResultSet::rowInserted( ) throw(SQLException
, RuntimeException
)
556 ResultSetEntryGuard
aGuard( *this );
557 OSL_TRACE("In/Out: OResultSet::rowInserted,m_RowStates=%u",m_RowStates
);
558 return ((m_RowStates
& RowStates_Inserted
) == RowStates_Inserted
);
561 sal_Bool SAL_CALL
OResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
)
563 ResultSetEntryGuard
aGuard( *this );
564 OSL_TRACE("In/Out: OResultSet::rowUpdated,m_RowStates=%u",m_RowStates
);
565 return ((m_RowStates
& RowStates_Updated
) == RowStates_Updated
) ;
569 sal_Bool SAL_CALL
OResultSet::next( ) throw(SQLException
, RuntimeException
)
571 return seekRow( NEXT_POS
);
575 sal_Bool SAL_CALL
OResultSet::wasNull( ) throw(SQLException
, RuntimeException
)
577 ResultSetEntryGuard
aGuard( *this );
583 void SAL_CALL
OResultSet::cancel( ) throw(RuntimeException
)
585 ResultSetEntryGuard
aGuard( *this );
586 OSL_TRACE("In/Out: OResultSet::cancel" );
590 void SAL_CALL
OResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
)
592 OSL_TRACE("In/Out: OResultSet::clearWarnings" );
595 Any SAL_CALL
OResultSet::getWarnings( ) throw(SQLException
, RuntimeException
)
597 OSL_TRACE("In/Out: OResultSet::getWarnings" );
601 void SAL_CALL
OResultSet::refreshRow( ) throw(SQLException
, RuntimeException
)
603 OSL_TRACE("In/Out: OResultSet::refreshRow" );
604 if (fetchRow(getCurrentCardNumber(),sal_True
)) //force fetch current row will cause we lose all change to the current row
605 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_REFRESH_ROW
, *this );
608 IPropertyArrayHelper
* OResultSet::createArrayHelper( ) const
610 Sequence
< Property
> aProps(5);
611 Property
* pProperties
= aProps
.getArray();
613 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION
),
614 PROPERTY_ID_FETCHDIRECTION
, cppu::UnoType
<sal_Int32
>::get(), 0);
616 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE
),
617 PROPERTY_ID_FETCHSIZE
, cppu::UnoType
<sal_Int32
>::get(), 0);
619 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE
),
620 PROPERTY_ID_ISBOOKMARKABLE
, ::getBooleanCppuType(), PropertyAttribute::READONLY
);
622 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY
),
623 PROPERTY_ID_RESULTSETCONCURRENCY
, cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
625 pProperties
[nPos
++] = ::com::sun::star::beans::Property(::connectivity::OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE
),
626 PROPERTY_ID_RESULTSETTYPE
, cppu::UnoType
<sal_Int32
>::get(), PropertyAttribute::READONLY
);
628 return new OPropertyArrayHelper(aProps
);
631 IPropertyArrayHelper
& OResultSet::getInfoHelper()
633 return *const_cast<OResultSet
*>(this)->getArrayHelper();
636 sal_Bool
OResultSet::convertFastPropertyValue(
637 Any
& /*rConvertedValue*/,
640 const Any
& /*rValue*/ )
641 throw (::com::sun::star::lang::IllegalArgumentException
)
643 OSL_FAIL( "OResultSet::convertFastPropertyValue: not implemented!" );
646 case PROPERTY_ID_ISBOOKMARKABLE
:
647 case PROPERTY_ID_RESULTSETCONCURRENCY
:
648 case PROPERTY_ID_RESULTSETTYPE
:
649 throw ::com::sun::star::lang::IllegalArgumentException();
650 case PROPERTY_ID_FETCHDIRECTION
:
651 case PROPERTY_ID_FETCHSIZE
:
658 void OResultSet::setFastPropertyValue_NoBroadcast(
660 const Any
& /*rValue*/
664 OSL_FAIL( "OResultSet::setFastPropertyValue_NoBroadcast: not implemented!" );
667 case PROPERTY_ID_ISBOOKMARKABLE
:
668 case PROPERTY_ID_RESULTSETCONCURRENCY
:
669 case PROPERTY_ID_RESULTSETTYPE
:
671 case PROPERTY_ID_FETCHDIRECTION
:
673 case PROPERTY_ID_FETCHSIZE
:
680 void OResultSet::getFastPropertyValue(
687 case PROPERTY_ID_RESULTSETCONCURRENCY
:
688 rValue
<<= (sal_Int32
)m_nResultSetConcurrency
;
690 case PROPERTY_ID_RESULTSETTYPE
:
691 rValue
<<= m_nResultSetType
;
693 case PROPERTY_ID_FETCHDIRECTION
:
694 rValue
<<= m_nFetchDirection
;
696 case PROPERTY_ID_FETCHSIZE
:
697 rValue
<<= m_nFetchSize
;
699 case PROPERTY_ID_ISBOOKMARKABLE
:
700 const_cast< OResultSet
* >( this )->determineReadOnly();
701 rValue
<<= !m_bIsReadOnly
;
706 void SAL_CALL
OResultSet::acquire() throw()
708 OResultSet_BASE::acquire();
711 void SAL_CALL
OResultSet::release() throw()
713 OResultSet_BASE::release();
716 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
718 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
722 void OResultSet::parseParameter( const OSQLParseNode
* pNode
, OUString
& rMatchString
)
724 OSL_ENSURE(pNode
->count() > 0,"Error parsing parameter in Parse Tree");
725 OSQLParseNode
*pMark
= pNode
->getChild(0);
727 // Initialize to empty string
730 OUString aParameterName
;
731 if (SQL_ISPUNCTUATION(pMark
,"?")) {
732 aParameterName
= "?";
734 else if (SQL_ISPUNCTUATION(pMark
,":")) {
735 aParameterName
= pNode
->getChild(1)->getTokenValue();
737 // XXX - Now we know name, what's value????
739 OSL_TRACE("Parameter name [%d]: %s", m_nParamIndex
,OUtoCStr(aParameterName
) );
741 if ( m_aParameterRow
.is() ) {
742 OSL_ENSURE( m_nParamIndex
< (sal_Int32
)m_aParameterRow
->get().size() + 1, "More parameters than values found" );
743 rMatchString
= (m_aParameterRow
->get())[(sal_uInt16
)m_nParamIndex
];
744 #if OSL_DEBUG_LEVEL > 0
745 OSL_TRACE("Prop Value : %s", OUtoCStr( rMatchString
) );
748 #if OSL_DEBUG_LEVEL > 0
750 OSL_TRACE("Prop Value : Invalid ParameterRow!" );
756 #define ALT_WILDCARD "*"
757 static const sal_Unicode MATCHCHAR
= '_';
759 void OResultSet::analyseWhereClause( const OSQLParseNode
* parseTree
,
760 MQueryExpression
&queryExpression
)
763 MQueryOp::cond_type
op( MQueryOp::Is
);
764 OUString matchString
;
766 if ( parseTree
== NULL
)
769 if ( m_pSQLIterator
->getParseTree() != NULL
) {
770 ::rtl::Reference
<OSQLColumns
> xColumns
= m_pSQLIterator
->getParameters();
773 OUString aColName
, aParameterValue
;
774 OSQLColumns::Vector::iterator aIter
= xColumns
->get().begin();
776 for(;aIter
!= xColumns
->get().end();++aIter
)
778 (*aIter
)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
)) >>= aColName
;
779 OSL_TRACE("Prop Column Name : %s", OUtoCStr( aColName
) );
780 if ( m_aParameterRow
.is() ) {
781 aParameterValue
= (m_aParameterRow
->get())[(sal_uInt16
)i
];
782 #if OSL_DEBUG_LEVEL > 0
783 OSL_TRACE("Prop Value : %s", OUtoCStr( aParameterValue
) );
786 #if OSL_DEBUG_LEVEL > 0
788 OSL_TRACE("Prop Value : Invalid ParameterRow!" );
797 if ( SQL_ISRULE(parseTree
,where_clause
) )
799 OSL_TRACE("analyseSQL : Got WHERE clause");
800 // Reset Parameter Counter
802 analyseWhereClause( parseTree
->getChild( 1 ), queryExpression
);
804 else if ( parseTree
->count() == 3 && // Handle ()'s
805 SQL_ISPUNCTUATION(parseTree
->getChild(0),"(") &&
806 SQL_ISPUNCTUATION(parseTree
->getChild(2),")"))
809 OSL_TRACE("analyseSQL : Got Punctuation ()");
810 MQueryExpression
*subExpression
= new MQueryExpression();
811 analyseWhereClause( parseTree
->getChild( 1 ), *subExpression
);
812 queryExpression
.getExpressions().push_back( subExpression
);
814 else if ((SQL_ISRULE(parseTree
,search_condition
) || (SQL_ISRULE(parseTree
,boolean_term
)))
815 && parseTree
->count() == 3) // Handle AND/OR
818 OSL_TRACE("analyseSQL : Got AND/OR clause");
820 // TODO - Need to take care or AND, for now match is always OR
821 analyseWhereClause( parseTree
->getChild( 0 ), queryExpression
);
822 analyseWhereClause( parseTree
->getChild( 2 ), queryExpression
);
824 if (SQL_ISTOKEN(parseTree
->getChild(1),OR
)) { // OR-Operator
825 queryExpression
.setExpressionCondition( MQueryExpression::OR
);
827 else if (SQL_ISTOKEN(parseTree
->getChild(1),AND
)) { // AND-Operator
828 queryExpression
.setExpressionCondition( MQueryExpression::AND
);
831 OSL_FAIL("analyseSQL: Error in Parse Tree");
834 else if (SQL_ISRULE(parseTree
,comparison_predicate
))
836 OSL_ENSURE(parseTree
->count() == 3, "Error parsing COMPARE predicate");
837 if (!(SQL_ISRULE(parseTree
->getChild(0),column_ref
) ||
838 parseTree
->getChild(2)->getNodeType() == SQL_NODE_STRING
||
839 parseTree
->getChild(2)->getNodeType() == SQL_NODE_INTNUM
||
840 parseTree
->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM
||
841 SQL_ISTOKEN(parseTree
->getChild(2),TRUE
) ||
842 SQL_ISTOKEN(parseTree
->getChild(2),FALSE
) ||
843 SQL_ISRULE(parseTree
->getChild(2),parameter
) ||
845 (SQL_ISRULE(parseTree
->getChild(2),set_fct_spec
) && SQL_ISPUNCTUATION(parseTree
->getChild(2)->getChild(0),"{"))))
847 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
850 OSQLParseNode
*pPrec
= parseTree
->getChild(1);
851 if (pPrec
->getNodeType() == SQL_NODE_EQUAL
)
853 else if (pPrec
->getNodeType() == SQL_NODE_NOTEQUAL
)
854 op
= MQueryOp::IsNot
;
856 OUString sTableRange
;
857 if(SQL_ISRULE(parseTree
->getChild(0),column_ref
))
858 m_pSQLIterator
->getColumnRange(parseTree
->getChild(0),columnName
,sTableRange
);
859 else if(parseTree
->getChild(0)->isToken())
860 columnName
= parseTree
->getChild(0)->getTokenValue();
862 if ( SQL_ISRULE(parseTree
->getChild(2),parameter
) ) {
863 parseParameter( parseTree
->getChild(2), matchString
);
866 matchString
= parseTree
->getChild(2)->getTokenValue();
869 if ( columnName
.equalsAscii("0") && op
== MQueryOp::Is
&&
870 matchString
.equalsAscii("1") ) {
871 OSL_TRACE("Query always evaluates to FALSE");
872 m_bIsAlwaysFalseQuery
= sal_True
;
874 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
, matchString
));
876 else if (SQL_ISRULE(parseTree
,like_predicate
))
878 OSL_ENSURE(parseTree
->count() == 2, "Error parsing LIKE predicate");
880 OSL_TRACE("analyseSQL : Got LIKE rule");
882 if ( !(SQL_ISRULE(parseTree
->getChild(0), column_ref
)) )
884 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_COLUMN
, *this );
888 OSQLParseNode
*pColumn
;
889 OSQLParseNode
*pAtom
;
890 OSQLParseNode
*pOptEscape
;
891 const OSQLParseNode
* pPart2
= parseTree
->getChild(1);
892 pColumn
= parseTree
->getChild(0); // Match Item
893 pAtom
= pPart2
->getChild(static_cast<sal_uInt32
>(pPart2
->count()-2)); // Match String
894 pOptEscape
= pPart2
->getChild(static_cast<sal_uInt32
>(pPart2
->count()-1)); // Opt Escape Rule
896 const bool bNot
= SQL_ISTOKEN(pPart2
->getChild(0), NOT
);
898 if (!(pAtom
->getNodeType() == SQL_NODE_STRING
||
899 pAtom
->getNodeType() == SQL_NODE_NAME
||
900 SQL_ISRULE(pAtom
,parameter
) ||
901 ( pAtom
->getChild(0) && pAtom
->getChild(0)->getNodeType() == SQL_NODE_NAME
) ||
902 ( pAtom
->getChild(0) && pAtom
->getChild(0)->getNodeType() == SQL_NODE_STRING
)
905 OSL_TRACE("analyseSQL : pAtom->count() = %d", pAtom
->count() );
907 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING
, *this );
910 OUString sTableRange
;
911 if(SQL_ISRULE(pColumn
,column_ref
))
912 m_pSQLIterator
->getColumnRange(pColumn
,columnName
,sTableRange
);
914 OSL_TRACE("ColumnName = %s", OUtoCStr( columnName
) );
916 if ( SQL_ISRULE(pAtom
,parameter
) ) {
917 parseParameter( pAtom
, matchString
);
918 // Replace all '*' with '%' : UI Usually does this but not with
919 // Parameters for some reason.
920 matchString
= matchString
.replaceAll( ALT_WILDCARD
, WILDCARD
);
924 matchString
= pAtom
->getTokenValue();
927 // Determine where '%' character is...
929 if ( matchString
.equals( WILDCARD
) )
931 // String containing only a '%' and nothing else
932 op
= MQueryOp::Exists
;
933 // Will be ignored for Exists case, but clear anyway.
936 else if ( matchString
.indexOf ( WILDCARD
) == -1 &&
937 matchString
.indexOf ( MATCHCHAR
) == -1 )
939 // Simple string , eg. "to match"
941 op
= MQueryOp::DoesNotContain
;
943 op
= MQueryOp::Contains
;
945 else if ( matchString
.startsWith( WILDCARD
)
946 && matchString
.endsWith( WILDCARD
)
947 && matchString
.indexOf ( WILDCARD
, 1 ) == matchString
.lastIndexOf ( WILDCARD
)
948 && matchString
.indexOf( MATCHCHAR
) == -1
951 // Relatively simple "%string%" - ie, contains...
952 // Cut '%' from front and rear
953 matchString
= matchString
.replaceAt( 0, 1, OUString() );
954 matchString
= matchString
.replaceAt( matchString
.getLength() -1 , 1, OUString() );
957 op
= MQueryOp::DoesNotContain
;
959 op
= MQueryOp::Contains
;
963 // We currently can't handle a 'NOT LIKE' when there are '%' or
964 // '_' dispersed throughout
965 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_NOT_LIKE_TOO_COMPLEX
, *this );
969 if ( (matchString
.indexOf ( WILDCARD
) == matchString
.lastIndexOf ( WILDCARD
))
970 && matchString
.indexOf( MATCHCHAR
) == -1
973 // One occurrence of '%' - no '_' matches...
974 if ( matchString
.startsWith( WILDCARD
) )
976 op
= MQueryOp::EndsWith
;
977 matchString
= matchString
.replaceAt( 0, 1, OUString());
979 else if ( matchString
.endsWith( WILDCARD
) )
981 op
= MQueryOp::BeginsWith
;
982 matchString
= matchString
.replaceAt( matchString
.getLength() -1, 1, OUString() );
986 sal_Int32 pos
= matchString
.indexOf ( WILDCARD
);
987 matchString
= matchString
.replaceAt( pos
, 1, ".*" );
988 op
= MQueryOp::RegExp
;
994 // Most Complex, need to use an RE
996 while ( (pos
= matchString
.indexOf ( WILDCARD
)) != -1 )
998 matchString
= matchString
.replaceAt( pos
, 1, ".*" );
1001 while ( (pos
= matchString
.indexOf( MATCHCHAR
)) != -1 )
1003 matchString
= matchString
.replaceAt( pos
, 1, "." );
1006 op
= MQueryOp::RegExp
;
1010 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
, matchString
));
1012 else if (SQL_ISRULE(parseTree
,test_for_null
))
1014 OSL_ENSURE(parseTree
->count() == 2,"Error in ParseTree");
1015 const OSQLParseNode
* pPart2
= parseTree
->getChild(1);
1016 OSL_ENSURE(SQL_ISTOKEN(pPart2
->getChild(0),IS
),"Error in ParseTree");
1018 if (!SQL_ISRULE(parseTree
->getChild(0),column_ref
))
1020 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_IS_NULL_COLUMN
, *this );
1023 if (SQL_ISTOKEN(pPart2
->getChild(1),NOT
))
1025 op
= MQueryOp::Exists
;
1028 op
= MQueryOp::DoesNotExist
;
1030 OUString sTableRange
;
1031 m_pSQLIterator
->getColumnRange(parseTree
->getChild(0),columnName
,sTableRange
);
1033 queryExpression
.getExpressions().push_back( new MQueryExpressionString( columnName
, op
));
1037 OSL_TRACE( "Unexpected statement!!!" );
1039 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
1046 void OResultSet::fillRowData()
1047 throw( ::com::sun::star::sdbc::SQLException
)
1049 OSL_ENSURE( m_pStatement
, "Require a statement" );
1051 MQueryExpression queryExpression
;
1053 OConnection
* xConnection
= static_cast<OConnection
*>(m_pStatement
->getConnection().get());
1054 m_xColumns
= m_pSQLIterator
->getSelectColumns();
1056 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
1058 OSQLColumns::Vector::const_iterator aIter
= m_xColumns
->get().begin();
1059 const OUString sProprtyName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
);
1061 m_aAttributeStrings
.clear();
1062 m_aAttributeStrings
.reserve(m_xColumns
->get().size());
1063 for (sal_Int32 i
= 1; aIter
!= m_xColumns
->get().end();++aIter
, i
++)
1065 (*aIter
)->getPropertyValue(sProprtyName
) >>= sName
;
1066 #if OSL_DEBUG_LEVEL > 0
1067 OSL_TRACE("Query Columns : (%d) %s", i
, OUtoCStr(sName
) );
1069 m_aAttributeStrings
.push_back( sName
);
1073 // Generate Match Conditions for Query
1074 const OSQLParseNode
* pParseTree
= m_pSQLIterator
->getWhereTree();
1076 // const OSQLParseNode* pParseTree = NULL;
1078 m_bIsAlwaysFalseQuery
= sal_False
;
1079 if ( pParseTree
!= NULL
)
1081 // Extract required info
1083 OSL_TRACE("\tHave a Where Clause");
1085 analyseWhereClause( pParseTree
, queryExpression
);
1089 OSL_TRACE("\tDon't have a Where Clause");
1091 MQueryExpression::ExprVector eVector
;
1093 // LDAP does not allow a query without restriction, so we add a dummy
1095 // For other types we stick to the old behaviour of using
1097 OSL_ENSURE(m_pStatement
, "Cannot determine Parent Statement");
1099 if (xConnection
->isLDAP())
1100 aStr
= "PrimaryEmail";
1102 aStr
= "card:nsIAbCard";
1103 eVector
.push_back( new MQueryExpressionString(aStr
, MQueryOp::Exists
) );
1105 queryExpression
.setExpressions( eVector
);
1108 // If the query is a 0=1 then set Row count to 0 and return
1109 if ( m_bIsAlwaysFalseQuery
)
1115 m_aQuery
.setExpression( queryExpression
);
1117 OUString
aStr( m_pTable
->getName() );
1118 m_aQuery
.setAddressbook( aStr
);
1120 sal_Int32 rv
= m_aQuery
.executeQuery(xConnection
);
1122 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERR_EXECUTING_QUERY
, *this );
1124 //determine whether the address book is readonly
1125 determineReadOnly();
1127 #if OSL_DEBUG_LEVEL > 0
1128 OSL_TRACE( "executeQuery returned %d", rv
);
1130 OSL_TRACE( "\tOUT OResultSet::fillRowData()" );
1135 static sal_Bool
matchRow( OValueRow
& row1
, OValueRow
& row2
)
1137 OValueVector::Vector::iterator row1Iter
= row1
->get().begin();
1138 OValueVector::Vector::iterator row2Iter
= row2
->get().begin();
1139 for ( ++row1Iter
,++row2Iter
; // the first column is the bookmark column
1140 row1Iter
!= row1
->get().end(); ++row1Iter
,++row2Iter
)
1142 if ( row1Iter
->isBound())
1144 // Compare values, if at anytime there's a mismatch return false
1145 if ( !( (*row1Iter
) == (*row2Iter
) ) )
1150 // If we get to here the rows match
1153 sal_Int32
OResultSet::getRowForCardNumber(sal_Int32 nCardNum
)
1155 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, nCardNum = %u", nCardNum
);
1157 if ( m_pKeySet
.is() )
1160 for(nPos
=0;nPos
< (sal_Int32
)m_pKeySet
->get().size();nPos
++)
1162 if (nCardNum
== (m_pKeySet
->get())[nPos
])
1164 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, return = %u", nPos
+1 );
1170 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK
, *this );
1175 void SAL_CALL
OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLException
,
1176 ::com::sun::star::uno::RuntimeException
)
1178 ResultSetEntryGuard
aGuard( *this );
1180 OSL_ENSURE( m_pTable
, "Need a Table object");
1183 const OSQLTables
& xTabs
= m_pSQLIterator
->getTables();
1184 if ((xTabs
.begin() == xTabs
.end()) || !xTabs
.begin()->second
.is())
1185 m_pStatement
->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX
, *this );
1187 m_pTable
= static_cast< OTable
* > ((xTabs
.begin()->second
).get());
1195 OSL_ENSURE(m_xColumns
.is(), "Need the Columns!!");
1197 switch( m_pSQLIterator
->getStatementType() )
1199 case SQL_STATEMENT_SELECT
:
1201 if(m_bIsAlwaysFalseQuery
) {
1206 m_pStatement
->getOwnConnection()->throwSQLException( STR_NO_COUNT_SUPPORT
, *this );
1210 sal_Bool bDistinct
= sal_False
;
1211 OSQLParseNode
*pDistinct
= m_pParseTree
->getChild(1);
1212 if (pDistinct
&& pDistinct
->getTokenID() == SQL_TOKEN_DISTINCT
)
1216 m_aOrderbyColumnNumber
.push_back(m_aColMapping
[1]);
1217 m_aOrderbyAscending
.push_back(SQL_DESC
);
1219 bDistinct
= sal_True
;
1222 OSortIndex::TKeyTypeVector
eKeyType(m_aOrderbyColumnNumber
.size());
1223 ::std::vector
<sal_Int32
>::iterator aOrderByIter
= m_aOrderbyColumnNumber
.begin();
1224 for ( ::std::vector
<sal_Int16
>::size_type i
= 0; aOrderByIter
!= m_aOrderbyColumnNumber
.end(); ++aOrderByIter
,++i
)
1226 OSL_ENSURE((sal_Int32
)m_aRow
->get().size() > *aOrderByIter
,"Invalid Index");
1227 switch ((m_aRow
->get().begin()+*aOrderByIter
)->getTypeKind())
1229 case DataType::CHAR
:
1230 case DataType::VARCHAR
:
1231 eKeyType
[i
] = SQL_ORDERBYKEY_STRING
;
1234 case DataType::OTHER
:
1235 case DataType::TINYINT
:
1236 case DataType::SMALLINT
:
1237 case DataType::INTEGER
:
1238 case DataType::DECIMAL
:
1239 case DataType::NUMERIC
:
1240 case DataType::REAL
:
1241 case DataType::DOUBLE
:
1242 case DataType::DATE
:
1243 case DataType::TIME
:
1244 case DataType::TIMESTAMP
:
1246 eKeyType
[i
] = SQL_ORDERBYKEY_DOUBLE
;
1249 // Other types aren't implemented (so they are always FALSE)
1251 eKeyType
[i
] = SQL_ORDERBYKEY_NONE
;
1252 OSL_FAIL("MResultSet::executeQuery: Order By Data Type not implemented");
1259 // Implement Sorting
1261 // So that we can sort we need to wait until the executed
1262 // query to the mozilla addressbooks has returned all
1265 OSL_TRACE("Query is to be sorted");
1266 if( ! m_aQuery
.queryComplete() )
1267 if ( !m_aQuery
.waitForQueryComplete() )
1269 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1272 OSL_ENSURE( m_aQuery
.queryComplete(), "Query not complete!!");
1274 m_pSortIndex
= new OSortIndex(eKeyType
,m_aOrderbyAscending
);
1276 OSL_TRACE("OrderbyColumnNumber->size() = %d",m_aOrderbyColumnNumber
.size());
1277 #if OSL_DEBUG_LEVEL > 0
1278 for ( ::std::vector
<sal_Int32
>::size_type i
= 0; i
< m_aColMapping
.size(); i
++ )
1279 OSL_TRACE("Mapped: %d -> %d", i
, m_aColMapping
[i
] );
1281 for ( sal_Int32 nRow
= 1; nRow
<= m_aQuery
.getRowCount(); nRow
++ ) {
1283 OKeyValue
* pKeyValue
= OKeyValue::createKeyValue((nRow
));
1285 ::std::vector
<sal_Int32
>::iterator aIter
= m_aOrderbyColumnNumber
.begin();
1286 for (;aIter
!= m_aOrderbyColumnNumber
.end(); ++aIter
)
1288 const ORowSetValue
& value
= getValue(nRow
, *aIter
);
1290 OSL_TRACE( "Adding Value: (%d,%d) : %s", nRow
, *aIter
,OUtoCStr( value
));
1292 pKeyValue
->pushKey(new ORowSetValueDecorator(value
));
1295 m_pSortIndex
->AddKeyValue( pKeyValue
);
1298 m_pKeySet
= m_pSortIndex
->CreateKeySet();
1299 m_CurrentRowCount
= static_cast<sal_Int32
>(m_pKeySet
->get().size());
1300 #if OSL_DEBUG_LEVEL > 0
1301 for( OKeySet::Vector::size_type i
= 0; i
< m_pKeySet
->get().size(); i
++ )
1302 OSL_TRACE("Sorted: %d -> %d", i
, (m_pKeySet
->get())[i
] );
1305 m_pSortIndex
= NULL
;
1306 beforeFirst(); // Go back to start
1308 else //we always need m_pKeySet now
1309 m_pKeySet
= new OKeySet();
1311 // Handle the DISTINCT case
1312 if ( bDistinct
&& m_pKeySet
.is() )
1314 OValueRow aSearchRow
= new OValueVector( m_aRow
->get().size() );
1316 for( OKeySet::Vector::size_type i
= 0; i
< m_pKeySet
->get().size(); i
++ )
1318 fetchRow( (m_pKeySet
->get())[i
] ); // Fills m_aRow
1319 if ( matchRow( m_aRow
, aSearchRow
) )
1321 (m_pKeySet
->get())[i
] = 0; // Marker for later to be removed
1325 // They don't match, so it's not a duplicate.
1326 // Use the current Row as the next one to match against
1327 *aSearchRow
= *m_aRow
;
1330 // Now remove any keys marked with a 0
1331 m_pKeySet
->get().erase(::std::remove_if(m_pKeySet
->get().begin(),m_pKeySet
->get().end()
1332 ,::std::bind2nd(::std::equal_to
<sal_Int32
>(),0))
1333 ,m_pKeySet
->get().end());
1339 case SQL_STATEMENT_UPDATE
:
1340 case SQL_STATEMENT_DELETE
:
1341 case SQL_STATEMENT_INSERT
:
1344 m_pStatement
->getOwnConnection()->throwSQLException( STR_STMT_TYPE_NOT_SUPPORTED
, *this );
1351 void OResultSet::setBoundedColumns(const OValueRow
& _rRow
,
1352 const ::rtl::Reference
<connectivity::OSQLColumns
>& _rxColumns
,
1353 const Reference
<XIndexAccess
>& _xNames
,
1354 sal_Bool _bSetColumnMapping
,
1355 const Reference
<XDatabaseMetaData
>& _xMetaData
,
1356 ::std::vector
<sal_Int32
>& _rColMapping
)
1358 ::comphelper::UStringMixEqual
aCase(_xMetaData
->supportsMixedCaseQuotedIdentifiers());
1360 Reference
<XPropertySet
> xTableColumn
;
1361 OUString sTableColumnName
, sSelectColumnRealName
;
1363 const OUString sName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
);
1364 const OUString sRealName
= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME
);
1366 ::std::vector
< OUString
> aColumnNames
;
1367 aColumnNames
.reserve(_rxColumns
->get().size());
1368 OValueVector::Vector::iterator aRowIter
= _rRow
->get().begin()+1;
1369 for (sal_Int32 i
=0; // the first column is the bookmark column
1370 aRowIter
!= _rRow
->get().end();
1376 // get the table column and its name
1377 _xNames
->getByIndex(i
) >>= xTableColumn
;
1378 OSL_ENSURE(xTableColumn
.is(), "OResultSet::setBoundedColumns: invalid table column!");
1379 if (xTableColumn
.is())
1380 xTableColumn
->getPropertyValue(sName
) >>= sTableColumnName
;
1382 sTableColumnName
= "";
1384 // look if we have such a select column
1385 // TODO: would like to have a O(log n) search here ...
1386 sal_Int32 nColumnPos
= 0;
1387 for ( OSQLColumns::Vector::iterator aIter
= _rxColumns
->get().begin();
1388 aIter
!= _rxColumns
->get().end();
1389 ++aIter
,++nColumnPos
1392 if ( nColumnPos
< (sal_Int32
)aColumnNames
.size() )
1393 sSelectColumnRealName
= aColumnNames
[nColumnPos
];
1396 if((*aIter
)->getPropertySetInfo()->hasPropertyByName(sRealName
))
1397 (*aIter
)->getPropertyValue(sRealName
) >>= sSelectColumnRealName
;
1399 (*aIter
)->getPropertyValue(sName
) >>= sSelectColumnRealName
;
1400 aColumnNames
.push_back(sSelectColumnRealName
);
1403 if (aCase(sTableColumnName
, sSelectColumnRealName
))
1405 if(_bSetColumnMapping
)
1407 sal_Int32 nSelectColumnPos
= static_cast<sal_Int32
>(aIter
- _rxColumns
->get().begin() + 1);
1408 // the getXXX methods are 1-based ...
1409 sal_Int32 nTableColumnPos
= i
+ 1;
1410 // get first table column is the bookmark column
1412 #if OSL_DEBUG_LEVEL > 0
1413 OSL_TRACE("Set Col Mapping: %d -> %d", nSelectColumnPos
, nTableColumnPos
);
1415 _rColMapping
[nSelectColumnPos
] = nTableColumnPos
;
1418 aRowIter
->setBound(sal_True
);
1419 aRowIter
->setTypeKind(DataType::VARCHAR
);
1425 OSL_FAIL("OResultSet::setBoundedColumns: caught an Exception!");
1432 sal_Bool
OResultSet::isCount() const
1434 return (m_pParseTree
&&
1435 m_pParseTree
->count() > 2 &&
1436 SQL_ISRULE(m_pParseTree
->getChild(2),scalar_exp_commalist
) &&
1437 SQL_ISRULE(m_pParseTree
->getChild(2)->getChild(0),derived_column
) &&
1438 SQL_ISRULE(m_pParseTree
->getChild(2)->getChild(0)->getChild(0),general_set_fct
) &&
1439 m_pParseTree
->getChild(2)->getChild(0)->getChild(0)->count() == 4
1445 // Check for valid row in m_aQuery
1447 sal_Bool
OResultSet::validRow( sal_uInt32 nRow
)
1449 sal_Int32 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1451 while ( nRow
> (sal_uInt32
)nNumberOfRecords
&& !m_aQuery
.queryComplete() ) {
1452 #if OSL_DEBUG_LEVEL > 0
1453 OSL_TRACE("validRow: waiting...");
1455 m_aQuery
.checkRowAvailable( nRow
);
1456 if ( m_aQuery
.hadError() )
1458 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1460 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1463 if (( nRow
== 0 ) ||
1464 ( nRow
> (sal_uInt32
)nNumberOfRecords
&& m_aQuery
.queryComplete()) ){
1465 OSL_TRACE("validRow(%u): return False", nRow
);
1468 #if OSL_DEBUG_LEVEL > 0
1469 OSL_TRACE("validRow(%u): return True", nRow
);
1473 sal_Bool
OResultSet::fillKeySet(sal_Int32 nMaxCardNumber
)
1475 impl_ensureKeySet();
1476 if (m_CurrentRowCount
< nMaxCardNumber
)
1478 sal_Int32 nKeyValue
;
1479 if ( (sal_Int32
)m_pKeySet
->get().capacity() < nMaxCardNumber
)
1480 m_pKeySet
->get().reserve(nMaxCardNumber
+ 20 );
1482 for (nKeyValue
= m_CurrentRowCount
+1; nKeyValue
<= nMaxCardNumber
; nKeyValue
++)
1483 m_pKeySet
->get().push_back( nKeyValue
);
1484 m_CurrentRowCount
= nMaxCardNumber
;
1489 sal_Int32
OResultSet::deletedCount()
1491 impl_ensureKeySet();
1492 return m_CurrentRowCount
- static_cast<sal_Int32
>(m_pKeySet
->get().size());
1496 sal_Bool
OResultSet::seekRow( eRowPosition pos
, sal_Int32 nOffset
)
1498 ResultSetEntryGuard
aGuard( *this );
1499 if ( !m_pKeySet
.is() )
1500 m_pStatement
->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT
, *this );
1502 sal_Int32 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1503 sal_Int32 nRetrievedRows
= currentRowCount();
1504 sal_Int32 nCurPos
= m_nRowPos
;
1506 OSL_TRACE("seekRow: nCurPos = %d", nCurPos
);
1509 OSL_TRACE("seekRow: NEXT");
1513 OSL_TRACE("seekRow: PRIOR");
1519 OSL_TRACE("seekRow: FIRST");
1524 OSL_TRACE("seekRow: LAST");
1525 nCurPos
= nRetrievedRows
;
1528 OSL_TRACE("seekRow: ABSOLUTE : %d", nOffset
);
1532 OSL_TRACE("seekRow: RELATIVE : %d", nOffset
);
1533 nCurPos
+= sal_uInt32( nOffset
);
1537 if ( nCurPos
<= 0 ) {
1539 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos
);
1542 sal_Int32 nCurCard
= nCurPos
;
1543 if ( nCurPos
< (sal_Int32
)m_pKeySet
->get().size() ) //The requested row is exist in m_pKeySet, so we just use it
1545 nCurCard
= (m_pKeySet
->get())[nCurPos
-1];
1547 else //The requested row has not been retrieved until now. We should get the right card for it.
1548 nCurCard
= nCurPos
+ deletedCount();
1550 while ( nCurCard
> nNumberOfRecords
&& !m_aQuery
.queryComplete() ) {
1551 m_aQuery
.checkRowAvailable( nCurCard
);
1552 if ( m_aQuery
.hadError() )
1554 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1556 nNumberOfRecords
= m_aQuery
.getRealRowCount();
1559 if ( nCurCard
> nNumberOfRecords
&& m_aQuery
.queryComplete()) {
1560 fillKeySet(nNumberOfRecords
);
1561 m_nRowPos
= static_cast<sal_uInt32
>(m_pKeySet
->get().size() + 1);
1562 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos
);
1565 //Insert new retrieved items for later use
1566 fillKeySet(nNumberOfRecords
);
1567 m_nRowPos
= (sal_uInt32
)nCurPos
;
1568 OSL_TRACE("seekRow: return True, m_nRowPos = %u", m_nRowPos
);
1573 void OResultSet::setColumnMapping(const ::std::vector
<sal_Int32
>& _aColumnMapping
)
1575 m_aColMapping
= _aColumnMapping
;
1576 #if OSL_DEBUG_LEVEL > 0
1577 for ( sal_uInt32 i
= 0; i
< m_aColMapping
.size(); i
++ )
1578 OSL_TRACE("Set Mapped: %d -> %d", i
, m_aColMapping
[i
] );
1583 ::com::sun::star::uno::Any
OResultSet::getBookmark( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1585 OSL_TRACE("getBookmark, m_nRowPos = %u", m_nRowPos
);
1586 ResultSetEntryGuard
aGuard( *this );
1587 if ( fetchCurrentRow() == sal_False
)
1588 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1590 OSL_ENSURE((!m_aRow
->isDeleted()),"getBookmark called for deleted row");
1591 return makeAny((sal_Int32
)(m_aRow
->get())[0]);
1593 sal_Bool
OResultSet::moveToBookmark( const ::com::sun::star::uno::Any
& bookmark
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1595 ResultSetEntryGuard
aGuard( *this );
1596 OSL_TRACE("moveToBookmark, bookmark = %u", comphelper::getINT32(bookmark
) );
1597 sal_Int32 nCardNum
= comphelper::getINT32(bookmark
);
1598 m_nRowPos
= getRowForCardNumber(nCardNum
);
1602 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
)
1604 ResultSetEntryGuard
aGuard( *this );
1605 OSL_TRACE("moveRelativeToBookmark, bookmark = %u rows= %u", comphelper::getINT32(bookmark
),rows
);
1606 sal_Int32 nCardNum
= comphelper::getINT32(bookmark
);
1607 m_nRowPos
= getRowForCardNumber(nCardNum
);
1608 return seekRow(RELATIVE_POS
,rows
);
1610 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
)
1612 ResultSetEntryGuard
aGuard( *this );
1613 OSL_TRACE("compareBookmarks, m_nRowPos = %u", m_nRowPos
);
1615 sal_Int32 nSecond
=0;
1616 sal_Int32 nResult
=0;
1618 if ( !( lhs
>>= nFirst
) || !( rhs
>>= nSecond
) )
1619 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK
, *this );
1621 if(nFirst
< nSecond
)
1623 else if(nFirst
> nSecond
)
1630 sal_Bool
OResultSet::hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1632 ResultSetEntryGuard
aGuard( *this );
1633 OSL_TRACE("hasOrderedBookmarks, m_nRowPos = %u", m_nRowPos
);
1636 sal_Int32
OResultSet::hashBookmark( const ::com::sun::star::uno::Any
& bookmark
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1638 ResultSetEntryGuard
aGuard( *this );
1639 OSL_TRACE("hashBookmark, m_nRowPos = %u", m_nRowPos
);
1640 return comphelper::getINT32(bookmark
);
1643 sal_Int32
OResultSet::getCurrentCardNumber()
1645 if ( ( m_nRowPos
== 0 ) || !m_pKeySet
.is() )
1647 if (m_pKeySet
->get().size() < m_nRowPos
)
1649 return (m_pKeySet
->get())[m_nRowPos
-1];
1651 void OResultSet::checkPendingUpdate() throw(SQLException
, RuntimeException
)
1653 OSL_TRACE("checkPendingUpdate, m_nRowPos = %u", m_nRowPos
);
1654 const sal_Int32 nCurrentRow
= getCurrentCardNumber();
1656 if ((m_nNewRow
&& nCurrentRow
!= m_nNewRow
)
1657 || ( m_nUpdatedRow
&& m_nUpdatedRow
!= nCurrentRow
))
1659 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1661 "$position$", OUString::number(nCurrentRow
)
1663 ::dbtools::throwGenericSQLException(sError
,*this);
1667 void OResultSet::updateValue(sal_Int32 columnIndex
,const ORowSetValue
& x
) throw(SQLException
, RuntimeException
)
1669 OSL_TRACE("updateValue, m_nRowPos = %u", m_nRowPos
);
1670 ResultSetEntryGuard
aGuard( *this );
1671 if ( fetchCurrentRow() == sal_False
)
1672 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1675 checkPendingUpdate();
1677 checkIndex(columnIndex
);
1678 columnIndex
= mapColumn(columnIndex
);
1680 (m_aRow
->get())[columnIndex
].setBound(sal_True
);
1681 (m_aRow
->get())[columnIndex
] = x
;
1682 m_nUpdatedRow
= getCurrentCardNumber();
1683 m_RowStates
= m_RowStates
| RowStates_Updated
;
1687 void SAL_CALL
OResultSet::updateNull( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
1689 OSL_TRACE("updateNull, m_nRowPos = %u", m_nRowPos
);
1690 ResultSetEntryGuard
aGuard( *this );
1691 if ( fetchCurrentRow() == sal_False
)
1692 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1694 checkPendingUpdate();
1695 checkIndex(columnIndex
);
1696 columnIndex
= mapColumn(columnIndex
);
1698 (m_aRow
->get())[columnIndex
].setBound(sal_True
);
1699 (m_aRow
->get())[columnIndex
].setNull();
1700 m_nUpdatedRow
= getCurrentCardNumber();
1701 m_RowStates
= m_RowStates
| RowStates_Updated
;
1705 void SAL_CALL
OResultSet::updateBoolean( sal_Int32 columnIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
1707 updateValue(columnIndex
, static_cast<bool>(x
));
1710 void SAL_CALL
OResultSet::updateByte( sal_Int32 columnIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
1712 updateValue(columnIndex
,x
);
1716 void SAL_CALL
OResultSet::updateShort( sal_Int32 columnIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
1718 updateValue(columnIndex
,x
);
1721 void SAL_CALL
OResultSet::updateInt( sal_Int32 columnIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
1723 updateValue(columnIndex
,x
);
1726 void SAL_CALL
OResultSet::updateLong( sal_Int32
/*columnIndex*/, sal_Int64
/*x*/ ) throw(SQLException
, RuntimeException
)
1728 ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateLong", *this );
1731 void SAL_CALL
OResultSet::updateFloat( sal_Int32 columnIndex
, float x
) throw(SQLException
, RuntimeException
)
1733 updateValue(columnIndex
,x
);
1737 void SAL_CALL
OResultSet::updateDouble( sal_Int32 columnIndex
, double x
) throw(SQLException
, RuntimeException
)
1739 updateValue(columnIndex
,x
);
1742 void SAL_CALL
OResultSet::updateString( sal_Int32 columnIndex
, const OUString
& x
) throw(SQLException
, RuntimeException
)
1744 updateValue(columnIndex
,x
);
1747 void SAL_CALL
OResultSet::updateBytes( sal_Int32 columnIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
1749 updateValue(columnIndex
,x
);
1752 void SAL_CALL
OResultSet::updateDate( sal_Int32 columnIndex
, const ::com::sun::star::util::Date
& x
) throw(SQLException
, RuntimeException
)
1754 updateValue(columnIndex
,x
);
1758 void SAL_CALL
OResultSet::updateTime( sal_Int32 columnIndex
, const ::com::sun::star::util::Time
& x
) throw(SQLException
, RuntimeException
)
1760 updateValue(columnIndex
,x
);
1764 void SAL_CALL
OResultSet::updateTimestamp( sal_Int32 columnIndex
, const ::com::sun::star::util::DateTime
& x
) throw(SQLException
, RuntimeException
)
1766 updateValue(columnIndex
,x
);
1770 void SAL_CALL
OResultSet::updateBinaryStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
1772 ResultSetEntryGuard
aGuard( *this );
1775 ::dbtools::throwFunctionSequenceException(*this);
1777 Sequence
<sal_Int8
> aSeq
;
1778 x
->readBytes(aSeq
,length
);
1779 updateValue(columnIndex
,aSeq
);
1782 void SAL_CALL
OResultSet::updateCharacterStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
1784 updateBinaryStream(columnIndex
,x
,length
);
1787 void SAL_CALL
OResultSet::updateObject( sal_Int32 columnIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
1789 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
1791 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1792 STR_COLUMN_NOT_UPDATEABLE
,
1793 "$position$", OUString::number(columnIndex
)
1795 ::dbtools::throwGenericSQLException(sError
,*this);
1796 } // if (!::dbtools::implUpdateObject(this, columnIndex, x))
1800 void SAL_CALL
OResultSet::updateNumericObject( sal_Int32 columnIndex
, const Any
& x
, sal_Int32
/*scale*/ ) throw(SQLException
, RuntimeException
)
1802 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
1804 const OUString
sError( m_pStatement
->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1805 STR_COLUMN_NOT_UPDATEABLE
,
1806 "$position$", OUString::number(columnIndex
)
1808 ::dbtools::throwGenericSQLException(sError
,*this);
1814 void SAL_CALL
OResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1816 ResultSetEntryGuard
aGuard( *this );
1817 OSL_TRACE("insertRow in, m_nRowPos = %u", m_nRowPos
);
1818 m_RowStates
= RowStates_Inserted
;
1822 m_aQuery
.setRowStates(getCurrentCardNumber(),m_RowStates
);
1823 OSL_TRACE("insertRow out, m_nRowPos = %u", m_nRowPos
);
1826 void SAL_CALL
OResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1828 OSL_TRACE("updateRow in, m_nRowPos = %u", m_nRowPos
);
1829 ResultSetEntryGuard
aGuard( *this );
1830 impl_ensureKeySet();
1832 if (!m_nRowPos
|| m_pKeySet
->get().size() < m_nRowPos
)
1833 m_pStatement
->getOwnConnection()->throwSQLException( STR_INVALID_ROW_UPDATE
, *this );
1835 const sal_Int32 nCurrentCard
= getCurrentCardNumber();
1837 if (!pushCard(nCurrentCard
))
1839 m_RowStates
= RowStates_Error
;
1840 m_pStatement
->getOwnConnection()->throwSQLException( STR_ROW_CAN_NOT_SAVE
, *this );
1843 if (!m_aQuery
.commitRow(nCurrentCard
))
1845 m_RowStates
= RowStates_Error
;
1847 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1852 OSL_TRACE("updateRow out, m_nRowPos = %u", m_nRowPos
);
1855 void SAL_CALL
OResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1857 OSL_TRACE("deleteRow, m_nRowPos = %u", m_nRowPos
);
1858 ResultSetEntryGuard
aGuard( *this );
1860 m_pStatement
->getOwnConnection()->throwSQLException( STR_ROW_ALREADY_DELETED
, *this );
1862 const sal_Int32 nCurrentRow
= getCurrentCardNumber();
1863 //fetchRow(nCurrentRow);
1865 m_pStatement
->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW
, *this );
1867 sal_Bool m_bRowDeleted
= ( m_aQuery
.deleteRow( nCurrentRow
) > 0 );
1869 m_pStatement
->getOwnConnection()->throwSQLException( m_aQuery
.getError(), *this );
1871 m_aQuery
.setRowStates(nCurrentRow
,RowStates_Deleted
);
1872 m_pKeySet
->get().erase(m_pKeySet
->get().begin() + m_nRowPos
-1);
1873 m_RowStates
= RowStates_Deleted
;
1874 OSL_TRACE("deleteRow out, m_nRowPos = %u", m_nRowPos
);
1877 void SAL_CALL
OResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1879 ResultSetEntryGuard
aGuard( *this );
1880 OSL_TRACE("cancelRowUpdates, m_nRowPos = %u", m_nRowPos
);
1881 if (fetchRow(getCurrentCardNumber(),sal_True
)) //force fetch current row will cause we lose all change to the current row
1882 m_pStatement
->getOwnConnection()->throwSQLException( STR_CAN_NOT_CANCEL_ROW_UPDATE
, *this );
1885 void SAL_CALL
OResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1887 OSL_TRACE("moveToInsertRow in, m_nRowPos = %u", m_nRowPos
);
1888 ResultSetEntryGuard
aGuard( *this );
1889 m_nOldRowPos
= m_nRowPos
;
1891 if (!m_nNewRow
) //no new row now, insert one
1893 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
1894 checkPendingUpdate();
1897 if (m_nRowPos
&& !pushCard(getCurrentCardNumber()))
1898 throw SQLException();
1900 m_nNewRow
= m_aQuery
.createNewCard();
1902 m_pStatement
->getOwnConnection()->throwSQLException( STR_CAN_NOT_CREATE_ROW
, *this );
1904 m_RowStates
= RowStates_Normal
;
1905 fillKeySet(m_nNewRow
);
1910 m_nRowPos
= static_cast<sal_uInt32
>(m_pKeySet
->get().size());
1912 OSL_TRACE("moveToInsertRow out, m_nRowPos = %u", m_nRowPos
);
1915 void SAL_CALL
OResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1917 ResultSetEntryGuard
aGuard( *this );
1918 OSL_TRACE("moveToCurrentRow, m_nRowPos = %u", m_nRowPos
);
1921 m_nRowPos
= m_nOldRowPos
;
1926 sal_Bool
OResultSet::determineReadOnly()
1928 if (m_bIsReadOnly
== -1)
1930 OConnection
* xConnection
= static_cast<OConnection
*>(m_pStatement
->getConnection().get());
1931 m_bIsReadOnly
= !m_aQuery
.isWritable(xConnection
) || m_bIsAlwaysFalseQuery
;
1934 return m_bIsReadOnly
!= 0;
1937 void OResultSet::setTable(OTable
* _rTable
)
1939 OSL_TRACE("In : setTable");
1941 m_pTable
->acquire();
1942 m_xTableColumns
= m_pTable
->getColumns();
1943 if(m_xTableColumns
.is())
1944 m_aColumnNames
= m_xTableColumns
->getElementNames();
1945 OSL_TRACE("Out : setTable");
1948 void OResultSet::setOrderByColumns(const ::std::vector
<sal_Int32
>& _aColumnOrderBy
)
1950 m_aOrderbyColumnNumber
= _aColumnOrderBy
;
1953 void OResultSet::setOrderByAscending(const ::std::vector
<TAscendingOrder
>& _aOrderbyAsc
)
1955 m_aOrderbyAscending
= _aOrderbyAsc
;
1957 Sequence
< sal_Int32
> SAL_CALL
OResultSet::deleteRows( const Sequence
< Any
>& /*rows*/ ) throw(SQLException
, RuntimeException
)
1959 ::dbtools::throwFeatureNotImplementedException( "XDeleteRows::deleteRows", *this );
1960 return Sequence
< sal_Int32
>();
1963 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */