RDbDatabase Class Reference

#include <d32dbms.h>

Link against: edbms.lib

class RDbDatabase

Nested Classes and Structures

Protected Attributes
RDbHandle< CDbDatabase >iDatabase
Public Member Functions
IMPORT_C TIntAlterTable(const TDesC &, const CDbColSet &)
IMPORT_C TIntBegin()
IMPORT_C voidClose()
IMPORT_C CDbColSet *ColSetL(const TDesC &)
IMPORT_C TIntCommit()
IMPORT_C TIntCompact()
IMPORT_C TIntCreateIndex(const TDesC &, const TDesC &, const CDbKey &)
TInt CreateTable(const TDesC &, const CDbColSet &)
TInt CreateTable(const TDesC &, const CDbColSet &, const CDbKey &)
IMPORT_C TIntDestroy()
IMPORT_C TIntDropIndex(const TDesC &, const TDesC &)
IMPORT_C TIntDropTable(const TDesC &)
IMPORT_C TIntExecute(const TDesC &, TDbTextComparison)
IMPORT_C TBoolInTransaction()
IMPORT_C CDbIndexNames *IndexNamesL(const TDesC &)
IMPORT_C TBoolIsDamaged()
IMPORT_C CDbKey *KeyL(const TDesC &, const TDesC &)
IMPORT_C TIntRecover()
IMPORT_C voidRollback()
IMPORT_C TSizeSize()
IMPORT_C CDbTableNames *TableNamesL()
IMPORT_C TIntUpdateStats()

Detailed Description

Abstract class providing the functionality of a database.

The source of the database and the implementation characteristics of a particular database are provided by a class derived from RDbDatabase.

DBMS has one such implementation: the store database.

This class is not intended for user derivation.

Note: For functions (i.e. Execute) that take an Sql string, if the string contains a LIKE clause with * (asterisks) wildcard then the characters between them must be no longer than length 255. If only one * exists then the length is taken from the start and to the end of the clause. However, if the clause contains a ? (question mark) wildcard within it then the characters between must be no longer than length 253.

Member Attribute Documentation

iDatabase

RDbHandle< CDbDatabase >iDatabase[protected]

Member Function Documentation

AlterTable ( const TDesC &, const CDbColSet & )

IMPORT_C TIntAlterTable(const TDesC &aName,
const CDbColSet &aNewDef
)

Alters a table synchronously.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameTable name.
aNewDefA new set of column definitions which describe the table structure.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrArgument, empty column set, duplicated column name, invalid column length; KErrNotFound, there is no table with the supplied name; KErrNotSupported, unknown column type, unknown column attributes; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Begin ( )

IMPORT_C TIntBegin()

Begins a transaction.

DBMS server only supports one 'granularity' of transaction lock: the whole database. Beginning a transaction locks the database, and this can fail if another client has already got a lock which excludes this client. If the same client has already locked the database it will be panic'd. The function is guaranteed to return KErrNone for client-side access.

DBMS transactions do not provide any form of isolation between the clients: while one client is updating a table within a transaction, other clients will be able to see the changes as they are made. As a result, if a client retrieves two separate rows from a database there is no automatic guarantee that the data being retrieved has not been changed between the reads - this can lead to an 'inconsistent read'. A client can prevent an update while retrieving related rows by enclosing the individual reads within a transaction. Such a transaction will not modify the database and only operates as a read-lock: releasing such a lock using Commit() or Rollback() will not affect the database in any way.

How RDbDatabase::Begin() works:
  • on a shared database Begin() will attempt to get a shared read-lock on the database, and will fail with KErrLocked if anyone has an exclusive write-lock. Other clients with read-locks will not cause this operation to fail.

  • any operation which will modify the database attempts to gain an exclusive write-lock on the database, and will fail with KErrLocked if anyone else has any lock on the database. If the current client already has a read-lock as a result of calling Begin(), then it will be upgraded to an exclusive write-lock.

  • Commit() or Rollback() after a read-lock has been acquired (but not a write-lock) will release that client's lock. The database will only be considered to be unlocked when all such locks are removed by all clients, when it will report a EUnlock event to any notifiers.

  • Commit() or Rollback() after a write-lock has been acquired will release the lock, and report the ECommit or ERollback event to any notifiers.

  • automatic transactions will be used as at present if updates are made outside of explicit transactions, and such updates will also be able to fail with KErrLocked if an exclusive lock cannot be acquired.

Allowing read-locks to be shared enables greater concurrency at the same time as providing some safe guard against inconsistent reads. It does, however, lead to the possibility of deadlock: two clients wanting to update the database can reach deadlock if they both Begin() a transaction before either of them starts an update, then one client's read-lock will prevent the other from upgrading to a write lock and vice versa. The only way out of this is to code the clients in such a way as to back out of such a deadlock situation, rather than retry forever without releasing the locks.

A client will be able to change the database schema while other clients are using the database, as long as the other clients have no locks on it. As described above, other clients may find that their rowsets are then invalidated asynchronously as a result of this.

capability
Note For a secure shared database, the caller must satisfy either the read, write or the schema access policy for the database.

Returns: KErrNone The operation has completed successfully; KErrLocked, the database is locked by another client; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Close ( )

IMPORT_C voidClose()

Closes a database. Commits any pending transaction. Frees the allocated resources.

ColSetL ( const TDesC & )

IMPORT_C CDbColSet *ColSetL(const TDesC &aName)const

Returns the table definition.

leave
KErrNoMemory, an out of memory condition has occurred; KErrNotFound, no table with that name exists; Note that the function may leave with other system-wide error codes.
ParameterDescription
aNameTable name.

Returns: A pointer to a CDbColSet container with column definitions . The caller is responsible for destroying the returned CDbColSet instance.

Commit ( )

IMPORT_C TIntCommit()

Commits the current transaction.

capability
Note For a secure shared database, the caller must satisfy either the read, write or the schema access policy for the database.

Returns: KErrNone The operation has completed successfully; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Compact ( )

IMPORT_C TIntCompact()

Synchronous database compaction. Compacts the database and returns when complete. Note that this can take an extended time to complete, so an incremental form is also provided. There is a complementary interface to calculate and report database size and usage information, which can be used by the clients to determine when it may be appropriate to compact the database.

See also: RDbIncremental::Compact() RDbDatabase::UpdateStats() RDbDatabase::Size()

capability
Note For a secure shared database, the caller must satisfy the write access policy for the database.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

CreateIndex ( const TDesC &, const TDesC &, const CDbKey & )

IMPORT_C TIntCreateIndex(const TDesC &aName,
const TDesC &aTable,
const CDbKey &aKey
)

Creates an index synchronously.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameIndex name.
aTableTable name.
aKeyIndex definition

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrBadName, invalid index name (containing spaces for example); KErrAlreadyExists, an index with that name already exists; KErrNotFound, there is no table with that name; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

CreateTable ( const TDesC &, const CDbColSet & )

TInt CreateTable(const TDesC &aName,
const CDbColSet &aDef
)[inline]

Creates a table on the database.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameTable name.
aDefA set of column definitions which describe the table structure.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrAlreadyExists, a table with that name already exists; KErrArgument, empty column set, duplicated column name, invalid column length; KErrBadName, invalid table name, invalid column name (containing spaces for example); KErrNotSupported, unknown column type, unknown column attributes; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

CreateTable ( const TDesC &, const CDbColSet &, const CDbKey & )

TInt CreateTable(const TDesC &aName,
const CDbColSet &aDef,
const CDbKey &aPrimaryKey
)[inline]

Creates a table on the database.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameTable name.
aDefA set of column definitions which describe the table structure.
aPrimaryKeyPrimary key definition.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrAlreadyExists, a table with that name already exists; KErrArgument, empty column set, duplicated column name, invalid column length; KErrBadName, invalid table name, invalid column name (containing spaces for example); KErrNotSupported, unknown column type, unknown column attributes; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Destroy ( )

IMPORT_C TIntDestroy()

Drops the tables and destroys the database. This handle is closed on successful destruction.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

DropIndex ( const TDesC &, const TDesC & )

IMPORT_C TIntDropIndex(const TDesC &aName,
const TDesC &aTable
)

Drops an index synchronously.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameIndex name.
aTableTable name.

Returns: KErrNone The operation has completed successfully; KErrNotFound, there is no table or index with that name; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

DropTable ( const TDesC & )

IMPORT_C TIntDropTable(const TDesC &aName)

Drops a table synchronously.

capability
Note For a secure shared database, the caller must satisfy the schema access policy for the database.
ParameterDescription
aNameTable name.

Returns: KErrNone The operation has completed successfully; KErrNotFound, there is no table with the supplied name; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Execute ( const TDesC &, TDbTextComparison )

IMPORT_C TIntExecute(const TDesC &aSql,
TDbTextComparisonaComparison = EDbCompareNormal
)
Executes a SQL statement on the database, and returns when it is complete. The aComp parameter is used in the execution of some SQL statements:
  • in CREATE INDEX statements it specifies the comparison operation used for text columns in the index key;

  • in UPDATE and DELETE statements it specifies the comparison operation used to evaluate the WHERE clause; Other statements ignore the value of aComp. A negative return value indicates an error. A successful DDL operation always returns KErrNone (zero), a successful DML operation returns the number of rows that were inserted, updated or deleted by the operation.

capability
Note For a secure shared database, the caller must satisfy:
  • the schema access policy for the database, if the SQL statement is CREATE/DROP/ALTER;

  • the write access policy for the table in the SQL, if the SQL statement is INSERT/UPDATE/DELETE;

ParameterDescription
aSqlA string of 16-bit wide characters containing one SQL statement.
aComparisonTells the DBMS how to compare text and long text columns.

Returns: Zero or positive value, the number of rows that were inserted, updated or deleted by the operation; KErrLocked, the database is locked by another client; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

InTransaction ( )

IMPORT_C TBoolInTransaction()const

Returns: True if the database is in a transaction, false otherwise.

IndexNamesL ( const TDesC & )

IMPORT_C CDbIndexNames *IndexNamesL(const TDesC &aTable)const

Lists the indexes on a table.

leave
KErrNoMemory, an out of memory condition has occurred; KErrNotFound, no table with that name exists; Note that the function may leave with other system-wide error codes.
ParameterDescription
aTableTable name.

Returns: A pointer to a CDbIndexNames container with column definitions . The caller is responsible for destroying the returned CDbIndexNames instance.

IsDamaged ( )

IMPORT_C TBoolIsDamaged()const

Reports the damage status of the database. The function checks database indexes and returs true if some of them are broken.

Returns: True if the database is damaged, false otherwise.

KeyL ( const TDesC &, const TDesC & )

IMPORT_C CDbKey *KeyL(const TDesC &aName,
const TDesC &aTable
)const

Returns the index key.

leave
KErrNoMemory, an out of memory condition has occurred; KErrNotFound, no index or table with that name exists; Note that the function may leave with other system-wide error codes.
ParameterDescription
aNameIndex name.
aTableTable name.

Returns: A pointer to a CDbKey object containing the index definition. The caller is responsible for destroying the returned CDbKey instance.

Recover ( )

IMPORT_C TIntRecover()

Synchronous database recovery. Recover() will try to rebuild database indexes if they are broken. If the database data is corrupted, it cannot be recovered.

capability
Note For a secure shared database, the caller must satisfy the write access policy for the database.

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.

Rollback ( )

IMPORT_C voidRollback()

Rollbacks the current transaction.

capability
Note For a secure shared database, the caller must satisfy either the read, write or the schema access policy for the database.

Size ( )

IMPORT_C TSizeSize()const

Returns the currently available size information for the database. This comprises a size in bytes for the database objects and a percentage used value which indicates how much of that size is live data-the remainder may be available for compaction. Some types of database may not be able to report this information, e.g. a RDbStoreDatabase, and others may need to have UpdateStats() in order to provide valid data. In these cases, the values in the RDbDatabase::TSize structure will contain an error value to indicate this.

Returns: RDbDatabase::TSize object, containing the database size and the percentage used value.

TableNamesL ( )

IMPORT_C CDbTableNames *TableNamesL()const

Lists the tables on the database.

leave
KErrNoMemory, an out of memory condition has occurred; Note that the function may leave with other system-wide error codes.

Returns: A pointer to a CDbTableNames container with table names. The caller is responsible for destroying the returned CDbTableNames instance.

UpdateStats ( )

IMPORT_C TIntUpdateStats()

Update any calculated statistics for the database. Note that this can take an extended time to complete, so an incremental form is also provided - RDbIncremental::UpdateStats().

capability
Note For a secure shared database, the caller must satisfy the write access policy for the database.

See also: RDbIncremental::UpdateStats()

Returns: KErrNone The operation has completed successfully; KErrNoMemory, an out of memory condition has occurred; KErrPermissionDenied, the caller does not satisfy the relevant database security policies. Note that other system-wide error codes may also be returned.