sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "UD_STD.H"
sl@0: 
sl@0: // Class RDbRowSet
sl@0: 
sl@0: /** Resets the rowset.
sl@0: 
sl@0: For a Table, this just sets the rowset cursor to the beginning position.
sl@0: 
sl@0: For an SQL view, this discards any evaluated rows and returns the cursor to 
sl@0: the beginning. The view then requires reevaluation.
sl@0: 
sl@0: The Store Database implementation requires this function to be called in order 
sl@0: to recover an open rowset object after the database has been rolled back. 
sl@0: The rowset does not need to be closed in this situation.
sl@0: 
sl@0: If a rowset object requires a reset, then all row functions return or leave 
sl@0: with KErrNotReady. */
sl@0: EXPORT_C void RDbRowSet::Reset()
sl@0: 	{
sl@0: 	iCursor->Reset();
sl@0: 	}
sl@0: 
sl@0: /** Closes the rowset and releases any owned resources. It is safe to close a rowset 
sl@0: object which is not open. */
sl@0: EXPORT_C void RDbRowSet::Close()
sl@0: 	{
sl@0: 	iCursor.Close();
sl@0: 	}
sl@0: 
sl@0: /** Returns the number of rows available in a rowset.
sl@0: 	
sl@0: This can take some time to complete, and a parameter can be passed to request 
sl@0: a quick but not always thorough count of the rows.
sl@0: 
sl@0: For SQL views, the value returned depends on the evaluation window being used 
sl@0: by the view. If there is an evaluation window this function will always return 
sl@0: the number of rows available in the window, not the total number which could 
sl@0: be returned by the query.
sl@0: 
sl@0: @param anAccuracy This specifies whether to ensure that an accurate count 
sl@0: is returned, or to give up if this value is not readily available. The default 
sl@0: is to ensure an accurate count.
sl@0: @return The number of rows available in the rowset, or KDbUndefinedCount if 
sl@0: EQuick was specified and the count was not available. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy either the read
sl@0:             or the write access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbRowSet::CountL(TAccuracy aAccuracy) const
sl@0: 	{
sl@0: 	return iCursor->CountL(aAccuracy);
sl@0: 	}
sl@0: 
sl@0: /** Tests whether there are any rows in the rowset. This is often faster than testing 
sl@0: whether CountL()==0.
sl@0: 
sl@0: @return ETrue if there are no rows available in the rowset, EFalse if there 
sl@0: are one or more. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TBool RDbRowSet::IsEmptyL() const
sl@0: 	{
sl@0: 	if (AtRow())
sl@0: 		return EFalse;
sl@0: 	TInt count=CountL(EQuick);
sl@0: 	if (count!=KDbUndefinedCount)
sl@0: 		return count==0;
sl@0: 	TDbBookmark mark=Bookmark();
sl@0: 	CDbCursor& cursor=*iCursor;
sl@0: 	TBool hasRow=cursor.GotoL(EFirst);
sl@0: 	cursor.GotoL(mark.iMark);
sl@0: 	return !hasRow;
sl@0: 	}
sl@0: 
sl@0: /** Returns the entire column set for the rowset. This can be used to discover 
sl@0: column ordinals for named columns in this rowset.
sl@0: 
sl@0: The function leaves with KErrNoMemory if there is not enough memory to carry 
sl@0: out the operation. 
sl@0: 
sl@0: @return The column set object which describes this rowset structure. The caller 
sl@0: should delete it when it is no longer required. */
sl@0: EXPORT_C CDbColSet* RDbRowSet::ColSetL() const
sl@0: 	{
sl@0: 	CDbColSet* cs=CDbColSet::NewLC();
sl@0: 	iCursor->ColumnsL(*cs);
sl@0: 	CleanupStack::Pop();
sl@0: 	return cs;
sl@0: 	}
sl@0: 
sl@0: /** Returns the number of columns which are defined in this rowset.
sl@0: 
sl@0: @return The number of columns which are defined in this rowset. */
sl@0: EXPORT_C TInt RDbRowSet::ColCount() const
sl@0: 	{
sl@0: 	return iCursor->ColumnCount();
sl@0: 	}
sl@0: 
sl@0: /** Returns the type of a column in the rowset.
sl@0: 	
sl@0: @param aCol The column ordinal for which the column type is required. Column 
sl@0: ordinals range from 1 to ColCount().
sl@0: @return The type of the column aCol. */
sl@0: EXPORT_C TDbColType RDbRowSet::ColType(TDbColNo aColNo) const
sl@0: 	{
sl@0: 	return iCursor->ColumnType(aColNo);
sl@0: 	}
sl@0: 
sl@0: /** Returns the definition of a column in the rowset.
sl@0: 	
sl@0: @param aCol The column ordinal for which the column definition is required. 
sl@0: Column ordinals range from 1 to ColCount().
sl@0: @return The definition of the column aCol. */
sl@0: EXPORT_C TDbCol RDbRowSet::ColDef(TDbColNo aColNo) const
sl@0: 	{
sl@0: 	TDbCol col;
sl@0: 	iCursor->ColumnDef(col,aColNo);
sl@0: 	return col;
sl@0: 	}
sl@0: 
sl@0: /** Tests whether the cursor is on a row.
sl@0: 
sl@0: One of the following is true:
sl@0: 
sl@0: the rowset is currently updating a row
sl@0: 
sl@0: the rowset is currently inserting a row
sl@0: 
sl@0: GetL() can be called to retrieve the row
sl@0: 
sl@0: @return ETrue if the cursor is on a valid row; EFalse, otherwise. */
sl@0: EXPORT_C TBool RDbRowSet::AtRow() const
sl@0: 	{
sl@0: 	return iCursor->AtRow();
sl@0: 	}
sl@0: 
sl@0: /** Tests whether the cursor is at the beginning of the rowset.
sl@0: 
sl@0: @return ETrue if the cursor is at the beginning, otherwise EFalse. */
sl@0: EXPORT_C TBool RDbRowSet::AtBeginning() const
sl@0: 	{
sl@0: 	return iCursor->AtBeginning();
sl@0: 	}
sl@0: 
sl@0: /** Tests whether the cursor is at the end of the rowset.
sl@0: 
sl@0: @return ETrue if the cursor is at the end, otherwise EFalse. */
sl@0: EXPORT_C TBool RDbRowSet::AtEnd() const
sl@0: 	{
sl@0: 	return iCursor->AtEnd();
sl@0: 	}
sl@0: 
sl@0: /** Moves the cursor to a specified position.
sl@0: 
sl@0: This is invoked by Beginning(), End(), FirstL(), LastL(), NextL() and PreviousL() 
sl@0: to navigate the cursor. See those functions for descriptions of how the cursor 
sl@0: behaves given different position specifications.
sl@0: 
sl@0: @param aPosition Specifies the position to move the cursor to.
sl@0: @return ETrue if the cursor is now at a row, EFalse if it is at the beginning 
sl@0: or end. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TBool RDbRowSet::GotoL(TPosition aPosition)
sl@0: 	{
sl@0: 	return iCursor->GotoL(aPosition);
sl@0: 	}
sl@0: 
sl@0: /** Gets the bookmark for the current cursor position. Bookmarks cannot be extracted 
sl@0: when the rowset is updating or inserting a row.
sl@0: 
sl@0: The Store Database implementation allows bookmarks to be extracted for any 
sl@0: cursor position including the beginning and end.
sl@0: 
sl@0: @return A bookmark which can be used to return to the current position using 
sl@0: the GotoL() function. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TDbBookmark RDbRowSet::Bookmark() const
sl@0: 	{
sl@0: 	TDbBookmark mark;
sl@0: 	iCursor->Bookmark(mark.iMark);
sl@0: 	return mark;
sl@0: 	}
sl@0: 
sl@0: /** Goes to a previously bookmarked position in a rowset.
sl@0: 
sl@0: The Store Database implements bookmarks which are valid in any rowset based 
sl@0: on the same table or generated by the same query, and which persist across 
sl@0: transaction boundaries.
sl@0: 
sl@0: @param aMark The bookmark to return to. This should have been returned by 
sl@0: a previous call to Bookmark() on this or an equivalent rowset object. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::GotoL(const TDbBookmark& aMark)
sl@0: 	{
sl@0: 	iCursor->GotoL(aMark.iMark);
sl@0: 	}
sl@0: 
sl@0: /** Gets the current row data for access using the column extractor functions. 
sl@0: The cursor must be positioned at a valid row. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::GetL()
sl@0: 	{
sl@0: 	iCursor->GetL();
sl@0: 	}
sl@0: 
sl@0: /** Inserts a new row into the rowset. All auto-increment columns will be initialised 
sl@0: with their new values, all other columns will be initialised to NULL values. 
sl@0: If no client-begun transaction is in progress, this function begins an automatic 
sl@0: transaction, which is committed by PutL().
sl@0: 
sl@0: After the column values have been set using the SetColL() functions, the row 
sl@0: can be written to the database using PutL(). 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::InsertL()
sl@0: 	{
sl@0: 	iCursor->InsertL(CDbCursor::EClear);
sl@0: 	}
sl@0: 
sl@0: /** Inserts a copy of the current row into the rowset. All auto-increment columns 
sl@0: will be given a new value (as for InsertL()), the other columns will copy 
sl@0: their values from the cursor's current row. If no client-begun transaction 
sl@0: is in progress, this function begins an automatic transaction, which is committed 
sl@0: by PutL().
sl@0: 
sl@0: After the column values have been modified using the SetColL() functions, 
sl@0: the row can be written to the database using PutL(). 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::InsertCopyL()
sl@0: 	{
sl@0: 	iCursor->InsertL(CDbCursor::ECopy);
sl@0: 	}
sl@0: 
sl@0: /** Prepares the current row for update. If no client-begun transaction is in progress, 
sl@0: this function begins an automatic transaction, which is committed by PutL().
sl@0: 
sl@0: After the column values have been modified using the SetColL() functions, 
sl@0: the row can be written back to the database using PutL(). 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::UpdateL()
sl@0: 	{
sl@0: 	iCursor->UpdateL();
sl@0: 	}
sl@0: 
sl@0: /** Completes the update or insertion of a row.
sl@0: 
sl@0: First the new row data is validated:
sl@0: 
sl@0: not-null columns are checked to be not NULL
sl@0: 
sl@0: numerical columns are checked to be in range for their type
sl@0: 
sl@0: variable length columns are checked to not exceed their maximum length
sl@0: 
sl@0: unique index keys are checked to ensure uniqueness is not violated
sl@0: 
sl@0: Note that modifying auto-increment columns is not prevented by DBMS.
sl@0: 
sl@0: Following validation the data is written to the database and any affected 
sl@0: indexes are updated. On successful completion of the write, PutL() will then 
sl@0: commit any automatic transaction.
sl@0: 
sl@0: The cursor is left positioned on the updated or inserted row — where this 
sl@0: lies in the rowset is not always well defined. To return to the row which 
sl@0: was current prior to the update or insertion, a bookmark can be used.
sl@0: 
sl@0: In the Store Database implementation the written row is located in the rowset 
sl@0: as follows:
sl@0: 
sl@0: Tables without an active index will leave updated rows in the same location 
sl@0: and append new rows to the end of the rowset.
sl@0: 
sl@0: Tables with an active index place the row according to the active index ordering.
sl@0: 
sl@0: SQL views without an evaluation window will place it according to the rowset 
sl@0: ordering. The row may subsequently disappear if it does not match the WHERE 
sl@0: clause of the SQL query.
sl@0: 
sl@0: SQL views with a full evaluation window will leave updated rows in the same 
sl@0: location and append new rows to the end of the rowset. Re-evaluation may cause 
sl@0: the row to disappear if it does not match the WHERE clause of the SQL query.
sl@0: 
sl@0: SQL views with a partial evaluation window will leave updated rows in the 
sl@0: same location, new rows are not added to the window and navigation from the 
sl@0: new row is undefined. Further navigation and evaluation of the partial window 
sl@0: will place the rows in the correct location according to the query. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::PutL()
sl@0: 	{
sl@0: 	iCursor->PutL();
sl@0: 	}
sl@0: 
sl@0: /** Deletes the current row in a rowset. The rowset must not currently be updating 
sl@0: or inserting the row.
sl@0: 
sl@0: The rowset cursor is left positioned at the "hole" left by the deletion of 
sl@0: the current row. Navigation to the next or previous row will have the same 
sl@0: effect as if this row had not been deleted. Once the cursor has been moved 
sl@0: from the "hole" it will disappear from the rowset.
sl@0: 
sl@0: If the client has not begun a transaction, this function will use an automatic 
sl@0: transaction to update the rowset. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::DeleteL()
sl@0: 	{
sl@0: 	iCursor->DeleteL();
sl@0: 	}
sl@0: 
sl@0: /** Cancels the update or insertion of a row, or recovers the rowset if PutL() 
sl@0: fails. The cursor will return to the location prior to starting the update 
sl@0: or insertion. It is also safe to call this function when the rowset object 
sl@0: is not updating or inserting a row, in which case it does nothing.
sl@0: 
sl@0: In the Store database implementation, if this is called to abort a row update 
sl@0: or insertion before PutL() is called or during row validation in PutL(), all 
sl@0: the changes are discarded without requiring a transaction rollback and the 
sl@0: rowset to be Reset(). */
sl@0: EXPORT_C void RDbRowSet::Cancel()
sl@0: 	{
sl@0: 	iCursor->Cancel();
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Checks for valid Cursor and column ID
sl@0: //
sl@0: CDbCursor& RDbRowSet::CheckCol(TDbColNo aCol) const
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	__ASSERT_ALWAYS(aCol>0&&aCol<=cr.ColumnCount(),Panic(EDbInvalidColumn));
sl@0: 	return cr;
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Checks for valid Cursor, column ID and type
sl@0: //
sl@0: TDbColumnC RDbRowSet::ColumnC(TDbColNo aCol,TDbColType aType) const
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	TDbColType cType=cr.ColumnType(aCol);
sl@0: 	if (cType!=aType)
sl@0: 		{	// not an exact match
sl@0: 		if (cType>aType)
sl@0: 			Panic(EDbWrongType);		// extraction type is narrower
sl@0: 		else if (!IsIntegral(cType))
sl@0: 			Panic(EDbWrongType);		// type is non-integral
sl@0: 		else if (IsSigned(cType) && IsUnsigned(aType))
sl@0: 			Panic(EDbWrongType);		// cannot get signed column as unsigned
sl@0: 		}
sl@0: 	return cr.ColumnC(aCol);
sl@0: 	}
sl@0: 
sl@0: TDbColumn RDbRowSet::Column(TDbColNo aCol,TDbColType aType)
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	__ASSERT_ALWAYS(cr.ColumnType(aCol)==aType,Panic(EDbWrongType));
sl@0: 	return cr.Column(aCol);
sl@0: 	}
sl@0: 
sl@0: /** Gets the size in bytes of a column value. This can be used for all column types, 
sl@0: including Long columns. NULL columns return a size of 0.
sl@0: 
sl@0: Note:
sl@0: 
sl@0: This may yield unexpected results for small numerical column types as they 
sl@0: are stored in memory as 32-bit values.
sl@0: 
sl@0: @param aCol The column ordinal of the column to check.
sl@0: @return The length in bytes of column aCol's value. */
sl@0: EXPORT_C TInt RDbRowSet::ColSize(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return iCursor->ColumnSize(aCol);
sl@0: 	}
sl@0: 
sl@0: /** Gets the length of a column value. As compared with ColSize(), this returns 
sl@0: the number of "units" in the column:
sl@0: 
sl@0: NULL columns have a length of 0
sl@0: 
sl@0: non-NULL numerical and date-time columns have a length of 1
sl@0: 
sl@0: for Text columns the length is the character count
sl@0: 
sl@0: for Binary columns the length is the byte count
sl@0: 
sl@0: @param aCol The column ordinal of the column to check.
sl@0: @return The length in "units" of column aCol's value. */
sl@0: EXPORT_C TInt RDbRowSet::ColLength(TDbColNo aCol) const
sl@0: 	{
sl@0: 	TInt size=ColSize(aCol);
sl@0: 	switch (iCursor()->ColumnType(aCol))
sl@0: 		{
sl@0: 	case EDbColText8:
sl@0: 	case EDbColLongText8:
sl@0: 	case EDbColBinary:
sl@0: 	case EDbColLongBinary:
sl@0: 		break;
sl@0: 	case EDbColText16:
sl@0: 	case EDbColLongText16:
sl@0: 		if (size>0)
sl@0: 			size>>=1;
sl@0: 		break;
sl@0: 	default:
sl@0: 		if (size)
sl@0: 			size=1;
sl@0: 		break;
sl@0: 		}
sl@0: 	return size;
sl@0: 	}
sl@0: 
sl@0: /** Extracts a TInt8 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TInt8 RDbRowSet::ColInt8(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColInt8).Int8();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TInt16 or TInt8 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TInt16 RDbRowSet::ColInt16(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColInt16).Int16();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TInt32, TInt16 or TInt8 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TInt32 RDbRowSet::ColInt32(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColInt32).Int32();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TInt64 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TInt64 RDbRowSet::ColInt64(TDbColNo aCol) const
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	TDbColumnC c=cr.ColumnC(aCol);
sl@0: 	TDbColType t=cr.ColumnType(aCol);
sl@0: 	if (t==EDbColInt64)
sl@0: 		return c.Int64();
sl@0: 	if (t>EDbColInt64)
sl@0: 		Panic(EDbWrongType);
sl@0: 	if (IsSigned(t))
sl@0: 		return TInt(c.Int32());
sl@0: 	return TUint(c.Uint32());
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a Uint8 or Bit column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TUint8 RDbRowSet::ColUint8(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColUint8).Uint8();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a Uint16, Uint8 or Bit column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TUint16 RDbRowSet::ColUint16(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColUint16).Uint16();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a Uint32, Uint16, Uint8 or Bit column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TUint32 RDbRowSet::ColUint32(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColUint32).Uint32();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TReal32 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TReal32 RDbRowSet::ColReal32(TDbColNo aCol) const __SOFTFP
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColReal32).Real32();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TReal64 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. */
sl@0: EXPORT_C TReal64 RDbRowSet::ColReal64(TDbColNo aCol) const __SOFTFP
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColReal64).Real64();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a TTime column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return The value of column aCol. TTime may be either local time or universal time. 
sl@0: DBMS doesn't interpret the value of TTime, it is left up to the user to know which has been used.*/
sl@0: EXPORT_C TTime RDbRowSet::ColTime(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColDateTime).Time();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts any column type, except Long columns, as binary data.
sl@0: Can handle any type of non-long column
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return A descriptor of column aCol's value. */
sl@0: EXPORT_C TPtrC8 RDbRowSet::ColDes8(TDbColNo aCol) const
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	__ASSERT_ALWAYS(!IsLong(cr.ColumnType(aCol)),Panic(EDbWrongType));
sl@0: 	return cr.ColumnC(aCol).PtrC8();
sl@0: 	} 
sl@0: 
sl@0: /** Extracts a column as Unicode text.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract
sl@0: @return A descriptor of column aCol's value. */
sl@0: EXPORT_C TPtrC16 RDbRowSet::ColDes16(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColumnC(aCol,EDbColText16).PtrC16();
sl@0: 	}
sl@0: 
sl@0: /** Extracts a Text column value. The column type must match the default descriptor 
sl@0: type to use this extractor, ie. it must be equal to EDbColText.
sl@0: 
sl@0: @param aCol The column ordinal of the column to extract.
sl@0: @return A descriptor of column aCol's value. */
sl@0: EXPORT_C TPtrC RDbRowSet::ColDes(TDbColNo aCol) const
sl@0: 	{
sl@0: 	return ColDes16(aCol);
sl@0: 	}
sl@0: 
sl@0: /** Use this function to set the value of a column to NULL.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set to NULL. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbRowSet::SetColNullL(TDbColNo aCol)
sl@0: 	{
sl@0: 	iCursor->SetNullL(aCol);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TInt32, TInt16 or TInt8 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TInt32 aValue)
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	TDbColType t=cr.ColumnType(aCol);
sl@0: 	if (t<EDbColInt64)
sl@0: 		{	// set any <= 32-bit integral type
sl@0: 		if (IsSigned(t))
sl@0: 			{
sl@0: 			cr.Column(aCol).SetL(aValue);
sl@0: 			return;
sl@0: 			}
sl@0: 		if (aValue>=0)
sl@0: 			{	// check the domain for unsigned columns
sl@0: 			cr.Column(aCol).SetL(aValue);
sl@0: 			return;
sl@0: 			}
sl@0: 		}
sl@0: 	Panic(EDbWrongType);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TInt64 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TInt64 aValue)
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	TDbColumn c=cr.Column(aCol);
sl@0: 	TDbColType t=cr.ColumnType(aCol);
sl@0: 	if (t==EDbColInt64)
sl@0: 		{		// exact match
sl@0: 		c.SetL(aValue);
sl@0: 		return;
sl@0: 		}
sl@0: 	if (t<EDbColInt64)
sl@0: 		{
sl@0: 		TInt32 l = I64LOW(aValue);
sl@0: 		TInt32 h = I64HIGH(aValue);
sl@0: 		if (IsSigned(t))
sl@0: 			{	// check the domain for signed 32-bit 
sl@0: 			if (h==l>>31)		// sign-extend l gives aValue
sl@0: 				{
sl@0: 				c.SetL(l);
sl@0: 				return;
sl@0: 				}
sl@0: 			}	// invalid type, drop through to panic
sl@0: 		else
sl@0: 			{	// check the domain for unsigned 32-bit 
sl@0: 			if (h==0)
sl@0: 				{				// zero extend l gives aValue
sl@0: 				c.SetL(l);	// in unsigned 32 bit range
sl@0: 				return;
sl@0: 				}
sl@0: 			}	// invalid type, drop through to panic
sl@0: 		}
sl@0: 	Panic(EDbWrongType);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TUint32, TUint16, TUint8 or Bit column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TUint32 aValue)
sl@0: 	{
sl@0: 	CDbCursor& cr=*iCursor;
sl@0: 	TDbColType t=cr.ColumnType(aCol);
sl@0: 	if (t<EDbColInt64)
sl@0: 		{	// set any <= 32-bit integral type
sl@0: 		if (IsUnsigned(t))
sl@0: 			{
sl@0: 			cr.Column(aCol).SetL(aValue);
sl@0: 			return;
sl@0: 			}
sl@0: 		if (aValue<=TUint32(KMaxTInt))
sl@0: 			{	// check the domain for signed columns
sl@0: 			cr.Column(aCol).SetL(aValue);
sl@0: 			return;
sl@0: 			}
sl@0: 		}
sl@0: 	Panic(EDbWrongType);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TReal32 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TReal32 aValue) __SOFTFP
sl@0: 	{
sl@0: 	Column(aCol,EDbColReal32).SetL(aValue);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TReal64 column value.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TReal64 aValue) __SOFTFP
sl@0: 	{
sl@0: 	Column(aCol,EDbColReal64).SetL(aValue);
sl@0: 	}
sl@0: 
sl@0: /** Sets a TTime column value.
sl@0: 
sl@0: TTime could be either local time or universal time. 
sl@0: DBMS doesn't interpret the value of TTime, it is left up to the user to decide which should be used.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,TTime aValue)
sl@0: 	{
sl@0: 	Column(aCol,EDbColDateTime).SetL(aValue);
sl@0: 	}
sl@0: 
sl@0: /** Sets a column value from an 8 bit descriptor. This function can also set the 
sl@0: value of Long columns.
sl@0: 
sl@0: Usually this is used to set a Text8 or LongText8 column from a non-Unicode 
sl@0: text descriptor, but can be used for any column type: the data content is 
sl@0: validated when the row is PutL().
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,const TDesC8 &aValue)
sl@0: 	{
sl@0: 	CDbCursor& c=*iCursor;
sl@0: 	if (IsLong(c.ColumnType(aCol)))
sl@0: 		{
sl@0: 		RDbColWriteStream strm;
sl@0: 		strm.OpenLC(*this,aCol);
sl@0: 		strm.WriteL(aValue);
sl@0: 		strm.CommitL();
sl@0: 		CleanupStack::PopAndDestroy();
sl@0: 		}
sl@0: 	else
sl@0: 		c.Column(aCol).SetL(aValue);
sl@0: 	}
sl@0: 
sl@0: /** Set a column value from Unicode text.
sl@0: 
sl@0: @param aCol The column ordinal of the column to set.
sl@0: @param aValue The new column value. */
sl@0: EXPORT_C void RDbRowSet::SetColL(TDbColNo aCol,const TDesC16 &aValue)
sl@0: 	{
sl@0: 	CDbCursor& c=*iCursor;
sl@0: 	if (c.ColumnType(aCol)==EDbColLongText16)
sl@0: 		{
sl@0: 		RDbColWriteStream strm;
sl@0: 		strm.OpenLC(*this,aCol);
sl@0: 		strm.WriteL(aValue);
sl@0: 		strm.CommitL();
sl@0: 		CleanupStack::PopAndDestroy();
sl@0: 		}
sl@0: 	else
sl@0: 		Column(aCol,EDbColText16).SetL(aValue);
sl@0: 	}
sl@0: 
sl@0: /** Searches through a rowset for a row which fulfils an SQL search-condition. 
sl@0: The search begins from the current position (which must be a valid row) and 
sl@0: proceeds forwards or backwards through the available rows until it finds a 
sl@0: match or runs out of rows.
sl@0: 
sl@0: The cursor is positioned to the matching row (or beginning/end of set) on 
sl@0: return.
sl@0: 
sl@0: This is a brute-force approach to finding a row using an index for key-based 
sl@0: retrieval on a Table rowset is a much faster but less flexible way of finding 
sl@0: rows.
sl@0: 
sl@0: @param aDirection Specifies which direction to search after testing the current 
sl@0: row.
sl@0: @param aCriteria A query object containing an SQL search-condition to match 
sl@0: against.
sl@0: @return If no match is found KErrNotFound is returned. Otherwise the number 
sl@0: of rows navigated while finding a match, which may be 0 if the current row 
sl@0: matches. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbRowSet::FindL(TDirection aDirection,TDbQuery aCriteria)
sl@0: 	{
sl@0: 	return iCursor->FindL(aDirection,aCriteria);
sl@0: 	}
sl@0: 
sl@0: /** Tests whether the current row in the rowset matches a previously compiled row 
sl@0: constraint. The rowset must not currently be updating or inserting a row.
sl@0: 
sl@0: @param aConstraint A row constraint object which must have been previously 
sl@0: opened on this rowset object.
sl@0: @return ETrue if the current row fulfils the constraint, otherwise EFalse. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TBool RDbRowSet::MatchL(const RDbRowConstraint& aConstraint)
sl@0: 	{
sl@0: 	return iCursor->MatchL(*aConstraint.iConstraint);
sl@0: 	}
sl@0: 
sl@0: // Class RDbRowConstraint
sl@0: 
sl@0: /** Compiles the specified SQL search-condition for matching against rows in the 
sl@0: specified rowset. The text comparison supplied in aCriteria is used for all 
sl@0: text columns in the constraint.
sl@0: 
sl@0: @param aView The rowset to which the constraint will apply.
sl@0: @param aCriteria The SQL string and the text comparison mode for the constraint.
sl@0: @return KErrNone, if successful, otherwise one of the system-wide error codes. 
sl@0: Specifically:KErrNotFound if a column name in the SQL query does not exist.KErrArgument 
sl@0: if Invalid or unrecognised SQL syntax was used.KErrGeneral for a column type 
sl@0: mismatch in a predicate in the SQL query or if a date-literal in the SQL query 
sl@0: was invalid.KErrOverflow if a number-literal in the SQL query for an integral 
sl@0: column was too large (did not fit in a 32-bit integral representation). This 
sl@0: can also be one of the DBMS database error codes. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbRowConstraint::Open(const RDbRowSet& aView,TDbQuery aCriteria)
sl@0: 	{
sl@0: 	TRAPD(r,iConstraint=aView.iCursor->ConstraintL(aCriteria));
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: /** Releases the resources used by the constraint before discarding the constraint 
sl@0: object. */
sl@0: EXPORT_C void RDbRowConstraint::Close()
sl@0: 	{
sl@0: 	iConstraint.Close();
sl@0: 	}
sl@0: 
sl@0: // Class RDbColReadStream
sl@0: 
sl@0: /** Opens the column with the specified ordinal in the specified current row in 
sl@0: the rowset. The row must have previously been read into the rowset using RDbRowSet::GetL().
sl@0: 
sl@0: @param aView The rowset which has the row and column to be read.
sl@0: @param aCol The column ordinal of the column to be read 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbColReadStream::OpenL(const RDbRowSet& aView,TDbColNo aCol)
sl@0: 	{
sl@0: 	Attach(aView.ColSourceL(aCol));
sl@0: 	}
sl@0: 
sl@0: /** Opens the column with the specified ordinal in the specified current row in 
sl@0: the rowset and puts a pointer to the column on the cleanup stack.
sl@0: 
sl@0: The row must have previously been read into the rowset using RDbRowSet::GetL().
sl@0: 
sl@0: @param aView The rowset which has the row and column to be read.
sl@0: @param aCol The column ordinal of the column to be read. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbColReadStream::OpenLC(const RDbRowSet& aView,TDbColNo aCol)
sl@0: 	{
sl@0: 	OpenL(aView,aCol);
sl@0: 	PushL();
sl@0: 	}
sl@0: 
sl@0: // Class RDbColWriteStream
sl@0: 
sl@0: /** Opens the column with the specified ordinal in the current row, and in the 
sl@0: specified rowset, and prepares the column for being written or replaced. The 
sl@0: rowset must be updating or inserting a row.
sl@0: 
sl@0: @param aView The rowset which has the row and column to be written.
sl@0: @param aCol The column ordinal of the column to be written. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbColWriteStream::OpenL(RDbRowSet& aView,TDbColNo aCol)
sl@0: 	{
sl@0: 	Attach(aView.ColSinkL(aCol));
sl@0: 	}
sl@0: 
sl@0: /** Opens the column with the specified ordinal in the current row, and in the 
sl@0: specified rowset, and prepares the column for being written or replaced, putting 
sl@0: a cleanup item for this object onto the cleanup stack. The rowset must be 
sl@0: updating or inserting a row. 
sl@0: 
sl@0: Placing the cleanup object on the cleanup stack allows allocated resources 
sl@0: to be cleaned up if a subsequent leave occurs.
sl@0: 
sl@0: @param aView The rowset which has the row and column to be written.
sl@0: @param aCol The column ordinal of the column to be written. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the write
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C void RDbColWriteStream::OpenLC(RDbRowSet& aView,TDbColNo aCol)
sl@0: 	{
sl@0: 	OpenL(aView,aCol);
sl@0: 	PushL();
sl@0: 	}
sl@0: 
sl@0: // Class TDbWindow
sl@0: 
sl@0: /** Constructs this object with the preferred shape. When fully evaluated, the 
sl@0: view will try to have aForeSlots rows immediately available for navigation 
sl@0: forwards, and aRearSlots rows immediately available for navigation backwards.
sl@0: 
sl@0: @param aForeSlots The number of rows to evaluate ahead of the current row.
sl@0: @param aRearSlots The number of rows to evaluate behind the current row. */
sl@0: EXPORT_C TDbWindow::TDbWindow(TInt aForeSlots,TInt aRearSlots)
sl@0: 	: iSize(aForeSlots+aRearSlots+1), iPreferredPos(aRearSlots)
sl@0: 	{
sl@0: 	__ASSERT_ALWAYS(aForeSlots>=0 && aRearSlots>=0,Panic(EDbInvalidViewWindowParameters));
sl@0: 	}
sl@0: 
sl@0: // Class RDbView
sl@0: 
sl@0: /** Prepares the view object for evaluating an SQL select-statement.
sl@0: 
sl@0: Following preparation, the rowset object can always provide schema information, 
sl@0: but the view may first require evaluation to generate the rowset for navigation.
sl@0: 
sl@0: @param aDatabase The database on which to execute the query.
sl@0: @param aQuery The SQL query and the text comparison mode for the constraint.
sl@0: @param anAccess The access specification for the rowset. By default, updatable 
sl@0: access is given.
sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error 
sl@0: codes. Specifically: KErrNotFound if The table does not exist in the database 
sl@0: or a column name in the SQL query does not exist.KErrNotSupported if a sort-specification 
sl@0: in the SQL query cannot be provided by an index.KErrArgument if an invalid 
sl@0: or unrecognised SQL syntax was used.KErrGeneral if there is a column type 
sl@0: mismatch in a predicate in the SQL query or if a date-literal in the SQL query 
sl@0: was invalid.KErrOverflow if a number-literal in the SQL query for an integral 
sl@0: column was too large (did not fit in a 32-bit integral representation). This 
sl@0: can also be one of the DBMS database error codes.. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbView::Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,TAccess anAccess)
sl@0: 	{
sl@0: 	return Prepare(aDatabase,aQuery,TDbWindow(),anAccess);
sl@0: 	}
sl@0: 
sl@0: /** Prepares the view object for evaluating an SQL select-statement and specifies 
sl@0: the evaluation window shape for the rowset.
sl@0: 
sl@0: The function does not specify the access specification for the rowset
sl@0: updatable access is given.
sl@0: 
sl@0: Following preparation, the rowset object can always provide schema information, 
sl@0: but the view may first require evaluation to generate the rowset for navigation.
sl@0: 
sl@0: @param aDatabase The database on which to execute the query.
sl@0: @param aQuery The SQL query and the text comparison mode for the constraint.
sl@0: @param aWindow The desired evaluation window shape for the rowset. If this 
sl@0: parameter is omitted, an alternative overload is called e.g. no pre-evaluation 
sl@0: window is requested.
sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error 
sl@0: codes. Specifically: KErrNotFound if The table does not exist in the database 
sl@0: or a column name in the SQL query does not exist.KErrNotSupported if a sort-specification 
sl@0: in the SQL query cannot be provided by an index.KErrArgument if an invalid 
sl@0: or unrecognised SQL syntax was used.KErrGeneral if there is a column type 
sl@0: mismatch in a predicate in the SQL query or if a date-literal in the SQL query 
sl@0: was invalid.KErrOverflow if a number-literal in the SQL query for an integral 
sl@0: column was too large (did not fit in a 32-bit integral representation). This 
sl@0: can also be one of the DBMS database error codes. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbView::Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,const TDbWindow& aWindow)
sl@0: 	{
sl@0: 	return Prepare(aDatabase,aQuery,aWindow,EUpdatable);
sl@0: 	}
sl@0: 
sl@0: /** Prepares the view object for evaluating an SQL select-statement, specifies 
sl@0: the evaluation window shape for the rowset, and sets the access specification 
sl@0: for the rowset.
sl@0: 
sl@0: Following preparation, the rowset object can always provide schema information, 
sl@0: but the view may first require evaluation to generate the rowset for navigation.
sl@0: 
sl@0: @param aDatabase The database on which to execute the query.
sl@0: @param aQuery The SQL query and the text comparison mode for the constraint.
sl@0: @param aWindow The desired evaluation window shape for the rowset. If this 
sl@0: parameter is omitted, an alternative overload is called e.g. no pre-evaluation 
sl@0: window is requested.
sl@0: @param anAccess The access specification for the rowset. If omitted, updatable 
sl@0: access is given.
sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error 
sl@0: codes. Specifically:KErrNotFound if The table does not exist in the database 
sl@0: or a column name in the SQL query does not exist.KErrNotSupported if a sort-specification 
sl@0: in the SQL query cannot be provided by an index.KErrArgument if an invalid 
sl@0: or unrecognised SQL syntax was used.KErrGeneral if there is a column type 
sl@0: mismatch in a predicate in the SQL query or if a date-literal in the SQL query 
sl@0: was invalid.KErrOverflow if a number-literal in the SQL query for an integral 
sl@0: column was too large (did not fit in a 32-bit integral representation). This 
sl@0: can also be one of the DBMS database error codes. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbView::Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,const TDbWindow& aWindow,TAccess anAccess)
sl@0: 	{
sl@0: 	TRAPD(r,iCursor=aDatabase.iDatabase->ViewL(aQuery,aWindow,anAccess));
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: /** Use this function to fully evaluate the view. It is equivalent to:
sl@0: 
sl@0: while (Unevaluated()) { Evaluate(); }
sl@0: 
sl@0: @return KErrNone, if successful, otherwise one of the system wide error codes. */
sl@0: EXPORT_C TInt RDbView::EvaluateAll()
sl@0: 	{
sl@0: 	TInt r;
sl@0: 	do r=Evaluate(); while (r>0);
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: /** Performs a single step of the view evaluation, and returns when the step is 
sl@0: complete. To completely evaluate a view in one go, EvaluateAll() should be 
sl@0: used.
sl@0: 
sl@0: @return 0, evaluation is complete.> 0, more evaluation can be done. < 0, an 
sl@0: error code, see the class overview for more information. */
sl@0: EXPORT_C TInt RDbView::Evaluate()
sl@0: 	{
sl@0: 	return iCursor->Evaluate();
sl@0: 	}
sl@0: 
sl@0: ///** Performs a single step of the view evaluation, returning immediately and signalling 
sl@0: //when the step is complete.
sl@0: //
sl@0: //This function is most effectively used when the view evaluation is carried 
sl@0: //out from an active object. 
sl@0: //
sl@0: //@param aStatus The request status used to contain completion information for 
sl@0: //the function. On completion, the status value should be interpreted as follows: 
sl@0: //0, evaluation is complete.> 0, more evaluation can be done. < 0, an error 
sl@0: //code, see the class overview for more information. */
sl@0: //EXPORT_C void RDbView::Evaluate(TRequestStatus& aStatus)
sl@0: //	{
sl@0: //	iCursor->Evaluate(aStatus);
sl@0: //	}
sl@0: 
sl@0: /** Tests whether any more evaluation can be done to a view.
sl@0: 
sl@0: @return ETrue, if the view can be further evaluated; EFalse, if evaluation will 
sl@0: have no effect. */
sl@0: EXPORT_C TBool RDbView::Unevaluated() const
sl@0: 	{
sl@0: 	return iCursor->Unevaluated();
sl@0: 	}
sl@0: 
sl@0: // Class RDbTable
sl@0: 
sl@0: /** Opens the named table object on a database with the specified access.
sl@0: 
sl@0: If successful, the rowset is positioned to the beginning.
sl@0: 
sl@0: @param aDatabase The database on which to open the table.
sl@0: @param aName The name of the table to open.
sl@0: @param anAccess The access specification for the rowset, the default is updatable 
sl@0: access.
sl@0: @return KErrNone, if successful, otherwise one of the system-wide error codes. 
sl@0: Specifically:KErrNotFound if the table does not exist in the database.KErrAccessDenied 
sl@0: if an incremental operation is in progress. This can also be one of the DBMS 
sl@0: database error codes. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy either the read
sl@0:             or the write access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbTable::Open(RDbDatabase &aDatabase,const TDesC &aName,TAccess anAccess)
sl@0: 	{
sl@0: 	TRAPD(r,iCursor=aDatabase.iDatabase->TableL(aName,anAccess));
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: /** Sets the specified index as the active index for this table. The rows will 
sl@0: be presented in index order, and this index key will be used for lookup by 
sl@0: the SeekL() function.
sl@0: 
sl@0: If successful, the rowset is reset to the beginning.
sl@0: 
sl@0: @param anIndex The name of the index to activate.
sl@0: @return KErrNone, if successful, otherwise one of the system-wide error codes. 
sl@0: Specifically:KErrWrite if the table was created with insert-only access.KErrNotFound 
sl@0: if the index does not exist on the table. This can also be one of the DBMS 
sl@0: database error codes. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TInt RDbTable::SetIndex(const TDesC* anIndex)
sl@0: 	{
sl@0: 	TRAPD(r,iCursor->SetIndexL(anIndex));
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: /** Finds a row in a table based on a key in the active index.
sl@0: 
sl@0: This function cannot be called while the rowset is currently updating or inserting 
sl@0: a row. The currently active index on the table must have a key definition 
sl@0: which matches the types in the key value.
sl@0: 
sl@0: Less columns can be added to the key than are present in the index definition: 
sl@0: the keys will only be compared up to the columns present further columns 
sl@0: in the index are not considered.
sl@0: 
sl@0: If successful the cursor is positioned to the row which was found, otherwise 
sl@0: the cursor is left on an invalid row.
sl@0: 
sl@0: The underlying Store database can leave with KErrWrite, if the table was created 
sl@0: with insert-only access.
sl@0: 
sl@0: The function can also leave with one of the DBMS database error codes.
sl@0: 
sl@0: @param aKey The key value to lookup in the index.
sl@0: @param aComparison The comparison operation for the lookup, the default is 
sl@0: to look for an exact match (EEqualTo).
sl@0: @return ETrue if a row which compares correctly with the key exists, EFalse if 
sl@0: not. 
sl@0: 
sl@0: @capability Note For a secure shared database, the caller must satisfy the read
sl@0:             access policy for the table.
sl@0: */
sl@0: EXPORT_C TBool RDbTable::SeekL(const TDbSeekKey& aKey,TComparison aComparison)
sl@0: 	{
sl@0: 	__ASSERT_ALWAYS(aKey.iKey.Count()>0,Panic(EDbNoColumnsInSeekKey));
sl@0: 	return iCursor->SeekL(aKey.iKey,aComparison);
sl@0: 	}
sl@0: 
sl@0: // Class CDbCursor
sl@0: 
sl@0: //
sl@0: // Default implementation in terms of ColumnDef. Might be inefficient
sl@0: //
sl@0: EXPORT_C void CDbCursor::ColumnsL(CDbColSet& aColSet)
sl@0: 	{
sl@0: 	TDbCol col;
sl@0: 	TDbColNo max=ColumnCount();
sl@0: 	for (TDbColNo ii=0;++ii<=max;)
sl@0: 		{
sl@0: 		ColumnDef(col,ii);
sl@0: 		aColSet.AddL(col);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Default implementation in terms of navigation
sl@0: // Faster counting may be possible
sl@0: //
sl@0: EXPORT_C TInt CDbCursor::CountL(RDbRowSet::TAccuracy)
sl@0: 	{
sl@0: 	TDbBookmark::TMark mark;
sl@0: 	Bookmark(mark);
sl@0: 	GotoL(RDbRowSet::EBeginning);
sl@0: 	TInt count=0;
sl@0: 	while (GotoL(RDbRowSet::ENext))
sl@0: 		++count;
sl@0: 	GotoL(mark);
sl@0: 	return count;
sl@0: 	}
sl@0: 
sl@0: //
sl@0: //  Default implementation in terms of constraints
sl@0: //
sl@0: EXPORT_C TInt CDbCursor::FindL(RDbRowSet::TDirection aDirection,const TDbQuery& aCriteria)
sl@0: 	{
sl@0: 	CDbRowConstraint* constraint=ConstraintL(aCriteria);
sl@0: 	constraint->PushL();
sl@0: 	RDbRowSet::TPosition next=aDirection==RDbRowSet::EForwards ? RDbRowSet::ENext : RDbRowSet::EPrevious;
sl@0: 	TInt skip=0;
sl@0: 	do
sl@0: 		{
sl@0: 		if (MatchL(*constraint))
sl@0: 			{
sl@0: 			CleanupStack::PopAndDestroy();	// constraint
sl@0: 			return skip;
sl@0: 			}
sl@0: 		++skip;
sl@0: 		} while (GotoL(next));
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 	return KErrNotFound;
sl@0: 	}
sl@0: 
sl@0: TInt CDbCursor::Evaluate()
sl@0: 	{
sl@0: 	TRAPD(r,r=EvaluateL());
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: CDbRowConstraint* CDbCursor::ConstraintL(const TDbQuery& aQuery)
sl@0: 	{
sl@0: 	return AttachContext(this,OpenConstraintL(aQuery));
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Reserved for future development
sl@0: //
sl@0: EXPORT_C void CDbCursor::Reserved_1()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Reserved for future development
sl@0: //
sl@0: EXPORT_C void CDbCursor::Reserved_2()
sl@0: 	{
sl@0: 	}