Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



Location: D32DBMS.H
Link against: edbms.lib

Class RDbDatabase

class RDbDatabase;

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.

Members

Defined in RDbDatabase:
AlterTable(), Begin(), Close(), ColSetL(), Commit(), Compact(), CreateIndex(), CreateTable(), CreateTable(), Destroy(), DropIndex(), DropTable(), Execute(), InTransaction(), IndexNamesL(), IsDamaged(), KeyL(), Recover(), Rollback(), Size(), TSize, TableNamesL(), UpdateStats(), iDatabase


Member functions


Close()

IMPORT_C void Close();

Description

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


Destroy()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

IMPORT_C TInt Destroy();

Description

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

Return value

TInt

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.


IsDamaged()

IMPORT_C TBool IsDamaged() const;

Description

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

Return value

TBool

True if the database is damaged, false otherwise.


Recover()

Capability: Security policy note: For a secure shared database, the caller must satisfy the write access policy for the database.

IMPORT_C TInt Recover();

Description

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

Return value

TInt

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.


UpdateStats()

Capability: Security policy note: For a secure shared database, the caller must satisfy the write access policy for the database.

IMPORT_C TInt UpdateStats();

Description

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().

Return value

TInt

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.

See also:


Size()

IMPORT_C TSize Size() const;

Description

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.

Return value

TSize

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


Compact()

Capability: Security policy note: For a secure shared database, the caller must satisfy the write access policy for the database.

IMPORT_C TInt Compact();

Description

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.

Return value

TInt

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.

See also:


Begin()

Capability: Security policy note: For a secure shared database, the caller must satisfy either the read or the write access policy for the database.

IMPORT_C TInt Begin();

Description

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:

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.

Return value

TInt

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.


Commit()

Capability: Security policy note: For a secure shared database, the caller must satisfy either the read or the write access policy for the database.

IMPORT_C TInt Commit();

Description

Commits the current transaction.

Return value

TInt

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.


Rollback()

Capability: Security policy note: For a secure shared database, the caller must satisfy either the read or the write access policy for the database.

IMPORT_C void Rollback();

Description

Rollbacks the current transaction.


InTransaction()

IMPORT_C TBool InTransaction() const;

Description

Return value

TBool

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


CreateTable()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

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

Description

Creates a table on the database.

Parameters

const TDesC &aName

Table name.

const CDbColSet &aDef

A set of column definitions which describe the table structure.

Return value

TInt

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()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

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

Description

Creates a table on the database.

Parameters

const TDesC &aName

Table name.

const CDbColSet &aDef

A set of column definitions which describe the table structure.

const CDbKey &aPrimaryKey

Primary key definition.

Return value

TInt

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.


DropTable()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

IMPORT_C TInt DropTable(const TDesC &aName);

Description

Drops a table synchronously.

Parameters

const TDesC &aName

Table name.

Return value

TInt

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.


AlterTable()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

IMPORT_C TInt AlterTable(const TDesC &aName, const CDbColSet &aNewDef);

Description

Alters a table synchronously.

Parameters

const TDesC &aName

Table name.

const CDbColSet &aNewDef

A new set of column definitions which describe the table structure.

Return value

TInt

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.


CreateIndex()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

IMPORT_C TInt CreateIndex(const TDesC &aName, const TDesC &aTable, const CDbKey &aKey);

Description

Creates an index synchronously.

Parameters

const TDesC &aName

Index name.

const TDesC &aTable

Table name.

const CDbKey &aKey

Index definition

Return value

TInt

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.


DropIndex()

Capability: Security policy note: For a secure shared database, the caller must satisfy the schema access policy for the database.

IMPORT_C TInt DropIndex(const TDesC &aName, const TDesC &aTable);

Description

Drops an index synchronously.

Parameters

const TDesC &aName

Index name.

const TDesC &aTable

Table name.

Return value

TInt

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.


Execute()

Capability: Security policy note: For a secure shared database, the caller must satisfy:

IMPORT_C TInt Execute(const TDesC &aSql, TDbTextComparison aComparison=EDbCompareNormal);

Description

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:

Parameters

const TDesC &aSql

A string of 16-bit wide characters containing one SQL statement.

TDbTextComparison aComparison

Tells the DBMS how to compare text and long text columns.

Return value

TInt

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.


TableNamesL()

IMPORT_C CDbTableNames *TableNamesL() const;

Description

Lists the tables on the database.

Return value

CDbTableNames *

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

Leave codes

KErrNoMemory,

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


ColSetL()

IMPORT_C CDbColSet *ColSetL(const TDesC &aName) const;

Description

Returns the table definition.

Parameters

const TDesC &aName

Table name.

Return value

CDbColSet *

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

Leave codes

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.


IndexNamesL()

IMPORT_C CDbIndexNames *IndexNamesL(const TDesC &aTable) const;

Description

Lists the indexes on a table.

Parameters

const TDesC &aTable

Table name.

Return value

CDbIndexNames *

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

Leave codes

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.


KeyL()

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

Description

Returns the index key.

Parameters

const TDesC &aName

Index name.

const TDesC &aTable

Table name.

Return value

CDbKey *

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

Leave codes

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.

[Top]


Member structures


Struct TSize

struct TSize;

Description

Members

Defined in RDbDatabase::TSize:
iSize, iUsage

Member data


iSize

TInt iSize;

Description


iUsage

TInt iUsage;

Description

[Top]


Member data


iDatabase

protected: RDbHandle< CDbDatabase > iDatabase;

Description