williamr@2: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #if !defined(__D32DBMS_H__) williamr@2: #define __D32DBMS_H__ williamr@2: williamr@2: #ifndef __S32STD_H__ williamr@2: #include williamr@2: #endif williamr@2: #ifndef __F32FILE_H__ williamr@2: #include williamr@2: #endif williamr@2: williamr@2: // other classes referenced williamr@2: class RFs; williamr@2: class CDbObject; williamr@2: class CDbRowConstraint; williamr@2: class CDbCursor; williamr@2: class CDbDatabase; williamr@2: class CDbIncremental; williamr@2: class CDbNotifier; williamr@2: class TDbColumn; williamr@2: class TDbColumnC; williamr@2: williamr@2: // classes defined williamr@2: class TDbCol; williamr@2: class CDbColSet; williamr@2: class TDbColSetIter; williamr@2: class TDbKeyCol; williamr@2: class CDbKey; williamr@2: class TDbBookmark; williamr@2: class TDbQuery; williamr@2: class RDbHandleBase; williamr@2: template class RDbHandle; williamr@2: class RDbRowConstraint; williamr@2: class RDbRowSet; williamr@2: class RDbColReadStream; williamr@2: class RDbColWriteStream; williamr@2: class TDbWindow; williamr@2: class RDbView; williamr@2: template class TUnion; williamr@2: class TDbLookupKey; williamr@2: class TDbSeekKey; williamr@2: template class TDbSeekMultiKey; williamr@2: class RDbTable; williamr@2: class CDbNames; williamr@2: class RDbDatabase; williamr@2: class RDbIncremental; williamr@2: class RDbUpdate; williamr@2: class RDbNotifier; williamr@2: class RDbs; williamr@2: class RDbNamedDatabase; williamr@2: class RDbStoreDatabase; williamr@2: williamr@2: /** williamr@2: The maximum length for a DBMS name: 64 characters. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbMaxName=0x40; williamr@2: williamr@2: /** williamr@2: The maximum length for a DBMS column name: 64 characters. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbMaxColName=KDbMaxName; williamr@2: williamr@2: /** williamr@2: Represents a writable DBMS name. It maps to a modifiable buffer descriptor williamr@2: with maximum size KDbMaxName. williamr@2: williamr@2: Notes: williamr@2: williamr@2: A DBMS name must begin with an alphabetic character, after which any alphabetic, williamr@2: numeric or the _ (underscore) character may be used. DBMS names are also limited williamr@2: to 64 characters in length. williamr@2: williamr@2: Table names must be unique within a database, and columns and indexes must williamr@2: have unique names within the table to which they belong. For the purposes williamr@2: of uniqueness and identification, the names are folded before comparison, williamr@2: so two columns named column_one and Column_ONE are considered to have the williamr@2: same name. williamr@2: williamr@2: @see TBuf williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TBuf TDbName; williamr@2: williamr@2: /** Represents a non-writeable DBMS name. It maps to a non modifiable buffer descriptor williamr@2: with maximum size KDbMaxName. williamr@2: williamr@2: Notes: williamr@2: williamr@2: A DBMS name must begin with an alphabetic character, after which any alphabetic, williamr@2: numeric or the _ (underscore) character may be used. DBMS names are also limited williamr@2: to 64 characters in length. williamr@2: williamr@2: Table names must be unique within a database, and columns and indexes must williamr@2: have unique names within the table to which they belong. For the purposes williamr@2: of uniqueness and identification, the names are folded before comparison, williamr@2: so two columns named column_one and Column_ONE are considered to have the williamr@2: same name. williamr@2: williamr@2: @see TBufC williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TBufC TDbNameC; williamr@2: williamr@2: /** Represents a writable DBMS column name. It maps to a modifiable buffer descriptor williamr@2: with maximum size KDbMaxColName. williamr@2: williamr@2: Notes: williamr@2: williamr@2: A DBMS name must begin with an alphabetic character, after which any alphabetic, williamr@2: numeric or the _ (underscore) character may be used. DBMS names are also limited williamr@2: to 64 characters in length. williamr@2: williamr@2: Table names must be unique within a database, and columns and indexes must williamr@2: have unique names within the table to which they belong. For the purposes williamr@2: of uniqueness and identification, the names are folded before comparison, williamr@2: so two columns named column_one and Column_ONE are considered to have the williamr@2: same name. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TBuf TDbColName; williamr@2: williamr@2: /** Represents a non-writable DBMS column name. It maps to a non-modifiable buffer williamr@2: descriptor with maximum size KDbMaxColName. williamr@2: williamr@2: Notes: williamr@2: williamr@2: A DBMS name must begin with an alphabetic character, after which any alphabetic, williamr@2: numeric or the _ (underscore) character may be used. DBMS names are also limited williamr@2: to 64 characters in length. williamr@2: williamr@2: Table names must be unique within a database, and columns and indexes must williamr@2: have unique names within the table to which they belong. For the purposes williamr@2: of uniqueness and identification, the names are folded before comparison, williamr@2: so two columns named column_one and Column_ONE are considered to have the williamr@2: same name. williamr@2: williamr@2: @see TBufC williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TBufC TDbColNameC; williamr@2: williamr@2: /** Specifies when DBMS objects require a column ordinal to identify a column in williamr@2: a column set or in a rowset. williamr@2: williamr@2: Note that KDbNullColNo is a special value of TDbColNo used to indicate that williamr@2: no such column exists. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TInt TDbColNo; williamr@2: williamr@2: /** williamr@2: Indicates that a specified column does not exist. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TDbColNo KDbNullColNo=0; williamr@2: williamr@2: /** williamr@2: A value returned by RDbRowSet::Count() when the number of rows cannot be determined. williamr@2: williamr@2: @see RDbRowSet williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbUndefinedCount=-1; williamr@2: williamr@2: /** williamr@2: The length of a column is undefined. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbUndefinedLength=-1; williamr@2: williamr@2: /** williamr@2: The default text column length. This is equal to 50. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbDefaultTextColLength=50; williamr@2: williamr@2: /** williamr@2: Represents every supported column type. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: enum TDbColType williamr@2: { williamr@2: /** The column stores a single bit. williamr@2: williamr@2: Representation range: 0 to 1 williamr@2: williamr@2: Storage: 1 bit williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColBit, williamr@2: williamr@2: /** The column stores an 8-bit signed integer. williamr@2: williamr@2: Representation range: -2^7 to 2^7 - 1 williamr@2: williamr@2: Storage: 1 byte williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColInt8, williamr@2: williamr@2: /** The column stores an 8-bit unsigned integer. williamr@2: williamr@2: Representation range: 0 to 2^8-1 williamr@2: williamr@2: Storage: 1 byte williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColUint8, williamr@2: williamr@2: /** The column stores a 16-bit signed integer. williamr@2: williamr@2: Representation range: -2^15 to 2^15 - 1 williamr@2: williamr@2: Storage: 2 bytes williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColInt16, williamr@2: williamr@2: /** The column stores a 16-bit unsigned integer. williamr@2: williamr@2: Representation range: 0 to 2^16-1 williamr@2: williamr@2: Storage: 2 bytes williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColUint16, williamr@2: williamr@2: /** The column stores a 32-bit signed integer. williamr@2: williamr@2: Representation range: -2^31 to 2^31 - 1 williamr@2: williamr@2: Storage: 4 bytes williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColInt32, williamr@2: williamr@2: /** The column stores a 32-bit unsigned integer. williamr@2: williamr@2: Representation range: 0 to 2^32-1 williamr@2: williamr@2: Storage: 4 bytes williamr@2: williamr@2: Auto-increment: Yes williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColUint32, williamr@2: williamr@2: /** The column stores a 64-bit signed integer. williamr@2: williamr@2: Representation range: -2^63 to 2^63 - 1 williamr@2: williamr@2: Storage: 8 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColInt64, williamr@2: williamr@2: /** The column stores a 32-bit floating point value. williamr@2: williamr@2: Representation range: 1.4 X 10^-45 to 3.40282 X 10^38 williamr@2: williamr@2: Storage: 4 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColReal32, williamr@2: williamr@2: /** The column stores a 64-bit floating point value. williamr@2: williamr@2: Representation range: 2.2 X 10^-308 to 1.79769 X 10^308 williamr@2: williamr@2: Storage: 8 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColReal64, williamr@2: williamr@2: /** The column stores a date/time value. williamr@2: williamr@2: Representation range: 1/1/0 to 31/12/9999 williamr@2: williamr@2: Storage: 8 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColDateTime, williamr@2: williamr@2: /** The column stores a (short) variable length of non-Unicode text data. williamr@2: williamr@2: Representation range: 0 to 256 characters williamr@2: williamr@2: Storage: 0 to 256 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColText8, williamr@2: williamr@2: /** The column stores a (short) variable length of Unicode text data. williamr@2: williamr@2: Representation range: 0 to 256 characters williamr@2: williamr@2: Storage: 0 to 512 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Yes */ williamr@2: EDbColText16, williamr@2: williamr@2: /** The column stores a (short) variable length of untyped data. williamr@2: williamr@2: Representation range: 0 to 255 bytes williamr@2: williamr@2: Storage: 0 to 256 bytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: No */ williamr@2: EDbColBinary, williamr@2: williamr@2: /** The column stores a potentially large amount of non-Unicode text data. williamr@2: williamr@2: Representation range: 0 to 2^31 characters williamr@2: williamr@2: Storage: 0 to 2 Gbytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Truncated */ williamr@2: EDbColLongText8, williamr@2: williamr@2: /** The column stores a potentially large amount of Unicode text data. williamr@2: williamr@2: Representation range: 0 to 2^30 characters williamr@2: williamr@2: Storage: 0 to 2 Gbytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: Truncated */ williamr@2: EDbColLongText16, williamr@2: williamr@2: /** The column stores a potentially large amount of untyped data. williamr@2: williamr@2: Representation range: 0 to 2^31 bytes williamr@2: williamr@2: Storage: 0 to 2 Gbytes williamr@2: williamr@2: Auto-increment: No williamr@2: williamr@2: Index key: No */ williamr@2: EDbColLongBinary, williamr@2: williamr@2: /** This is equivalent to EDbColText8 if the build is narrow, and williamr@2: EDbColText16 if the build is Unicode. */ williamr@2: EDbColText=EDbColText16, williamr@2: williamr@2: /** This is equivalent to EDbColLongText8 if the build is narrow, and williamr@2: EDbColLongText16 if the build is Unicode. */ williamr@2: EDbColLongText=EDbColLongText16 williamr@2: }; williamr@2: williamr@2: /** williamr@2: Represents different ways of comparing Text and LongText columns. williamr@2: williamr@2: This affects the ordering of indexes (see CDbKey), the evaluation of SQL williamr@2: queries and matching row constraints (see TDbQuery). williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: enum TDbTextComparison williamr@2: { williamr@2: /** Use standard text comparison and ordering. */ williamr@2: EDbCompareNormal, williamr@2: /** Use folded text for comparison and ordering. */ williamr@2: EDbCompareFolded, williamr@2: /** Use collation for comparison and ordering. */ williamr@2: EDbCompareCollated williamr@2: }; williamr@2: williamr@2: /** williamr@2: Defines a column in a table or rowset. williamr@2: williamr@2: The data members are public because this is really a structure to group the williamr@2: attributes of the column together. williamr@2: williamr@2: Three non-default constructors are provided for convenience. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbCol williamr@2: { williamr@2: friend class CDbColSet; williamr@2: public: williamr@2: enum {ENotNull=0x01,EAutoIncrement=0x02}; williamr@2: public: williamr@2: /** Constructs an uninitialised TDbCol. It is necessary because there are williamr@2: also non-default constructors in this class. */ williamr@2: inline TDbCol() {} williamr@2: inline TDbCol(const TDbCol&); williamr@2: inline TDbCol& operator=(const TDbCol&); williamr@2: IMPORT_C TDbCol(const TDesC& aName,TDbColType aType); williamr@2: IMPORT_C TDbCol(const TDesC& aName,TDbColType aType,TInt aMaxLength); williamr@2: static inline TBool IsLong(TDbColType aType); williamr@2: private: williamr@2: inline TDbCol(const TDesC& aName); williamr@2: public: williamr@2: /** The column type. */ williamr@2: TDbColType iType; williamr@2: /** The maximum length of data that can be stored in a Text or Binary williamr@2: column. */ williamr@2: TInt iMaxLength; williamr@2: /** A set of flags describing other column attributes. This must be one williamr@2: of the anonymous enum values ENotNull or EAutoIncrement. */ williamr@2: TUint iAttributes; williamr@2: /** The column name. */ williamr@2: TDbColNameC iName; williamr@2: }; williamr@2: williamr@2: /** Manages a set of column definitions which describe a table or rowset williamr@2: structure. Column definitions can be added and removed. The set can be williamr@2: iterated over, and ordinals for a column can be looked up. williamr@2: williamr@2: The class is not intended for user derivation. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CDbColSet : public CBase williamr@2: { williamr@2: friend class TDbColSetIter; williamr@2: public: williamr@2: IMPORT_C CDbColSet(); williamr@2: IMPORT_C static CDbColSet* NewL(); williamr@2: IMPORT_C static CDbColSet* NewLC(); williamr@2: IMPORT_C ~CDbColSet(); williamr@2: inline const TDbCol& operator[](TDbColNo aCol) const; williamr@2: IMPORT_C const TDbCol* Col(const TDesC& aColName) const; williamr@2: IMPORT_C TDbColNo ColNo(const TDesC& aColName) const; williamr@2: inline TInt Count() const; williamr@2: inline void Clear(); williamr@2: IMPORT_C CDbColSet& AddL(const TDbCol& aCol); williamr@2: IMPORT_C void Remove(const TDesC& aColName); williamr@2: private: williamr@2: CArrayPakFlat iColumns; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides a useful way to iterate over the contents of a column set. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbColSetIter williamr@2: { williamr@2: public: williamr@2: IMPORT_C TDbColSetIter(const CDbColSet& aColSet); williamr@2: inline operator TAny* () const; williamr@2: inline const TDbCol& operator*() const; williamr@2: inline const TDbCol* operator->() const; williamr@2: IMPORT_C TDbColSetIter& operator++(); williamr@2: inline TDbColSetIter operator++(TInt); williamr@2: inline TDbColNo Col() const; williamr@2: private: williamr@2: const TDbCol* iColumn; williamr@2: TInt iIndex; williamr@2: const CArrayPakFlat* iArray; williamr@2: }; williamr@2: williamr@2: /** Defines a key column in an index. williamr@2: williamr@2: The data members are public as this is really a structure to group the williamr@2: attributes of the key column together. Two non-default constructors are williamr@2: provided for convenience. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbKeyCol williamr@2: { williamr@2: public: williamr@2: /** Specifies whether a key column in an index should be sorted in williamr@2: ascending or descending order. */ williamr@2: enum TOrder williamr@2: { williamr@2: /** Use ascending order. */ williamr@2: EAsc, williamr@2: /** Use descending order. */ williamr@2: EDesc williamr@2: }; williamr@2: public: williamr@2: /** Constructs an uninitialised object. Default constructor. It is necessary williamr@2: because there are also non-default constructors in this class. */ williamr@2: inline TDbKeyCol() {} williamr@2: inline TDbKeyCol(const TDbKeyCol&); williamr@2: inline TDbKeyCol& operator=(const TDbKeyCol&); williamr@2: IMPORT_C TDbKeyCol(const TDesC& aName,TOrder anOrder=EAsc); williamr@2: IMPORT_C TDbKeyCol(const TDesC& aName,TInt aLength,TOrder anOrder=EAsc); williamr@2: public: williamr@2: /** The ordering of the key. */ williamr@2: TOrder iOrder; williamr@2: /** The maximum number of characters used to index Text or LongText williamr@2: columns. If equal to KDbUndefinedLength (the default), all the characters williamr@2: in the defined column will be used. */ williamr@2: TInt iLength; williamr@2: /** The column name for the key. */ williamr@2: TDbColNameC iName; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Represents the definition of an index. The key may be unique or primary, it williamr@2: can specify the sort of comparison which is made for Text columns, and it williamr@2: has a list of columns which make up the key. The class is used to construct williamr@2: and interrogate index keys. williamr@2: williamr@2: This class is not intended for user derivation. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CDbKey : public CBase williamr@2: { williamr@2: public: williamr@2: enum {EUnique=0x01,EPrimary=0x02}; williamr@2: public: williamr@2: IMPORT_C CDbKey(); williamr@2: IMPORT_C static CDbKey* NewL(); williamr@2: IMPORT_C static CDbKey* NewLC(); williamr@2: IMPORT_C ~CDbKey(); williamr@2: IMPORT_C CDbKey& AddL(const TDbKeyCol& aKeyCol); williamr@2: IMPORT_C void Remove(const TDesC& aColName); williamr@2: IMPORT_C void Clear(); williamr@2: inline TInt Count() const; williamr@2: inline const TDbKeyCol& operator[](TInt aCol) const; williamr@2: inline void MakeUnique(); williamr@2: inline TBool IsUnique() const; williamr@2: inline void SetComparison(TDbTextComparison aComparison); williamr@2: inline TDbTextComparison Comparison() const; williamr@2: inline void MakePrimary(); williamr@2: inline TBool IsPrimary() const; williamr@2: private: williamr@2: CArrayPakFlat iKeys; williamr@2: TDbTextComparison iComparison; williamr@2: TInt iAttributes; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Saves the current location of a rowset, enabling rapid navigation back to a williamr@2: previously visited row or position in the set. williamr@2: williamr@2: Instances of this class are returned by RDbRowSet::Bookmark(), which can later williamr@2: be passed to RDbRowSet::GotoL() to return to the row which was current at williamr@2: the call to Bookmark(). williamr@2: williamr@2: @see RDbRowSet::Bookmark() williamr@2: @see RDbRowSet::GotoL() williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbBookmark williamr@2: { williamr@2: friend class RDbRowSet; williamr@2: public: williamr@2: struct TMark williamr@2: /** Stores a database bookmark. */ williamr@2: { williamr@2: enum {ESize=8}; williamr@2: TUint32 iMark[ESize]; williamr@2: }; williamr@2: private: williamr@2: TMark iMark; williamr@2: }; williamr@2: williamr@2: /** williamr@2: A wrapper for an SQL string combined with a text comparison mode. williamr@2: williamr@2: An instance of the class is used as a parameter to RDbView::Prepare(), williamr@2: RDbRowSet::FindL() and RDbRowConstraint::Open(). williamr@2: williamr@2: The evaluation of SQL queries or constraints depends on how Text columns are williamr@2: compared so every SQL string is accompanied by a member of the TDbTextComparison williamr@2: enumeration to indicate how comparison is done. williamr@2: williamr@2: If the SQL string contains a LIKE clause with * (asterisks) wildcard then the williamr@2: characters between them must be no longer than length 255. williamr@2: If only one * exists then the length is taken from the start and to the end of williamr@2: the clause. However, if the clause contains a ? (question mark) wildcard williamr@2: within it then the characters between must be no longer than length 253. williamr@2: williamr@2: @see TDbTextComparison williamr@2: @see RDbView::Prepare() williamr@2: @see RDbRowSet::FindL() williamr@2: @see RDbRowConstraint::Open() williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbQuery williamr@2: { williamr@2: public: williamr@2: inline TDbQuery(const TDesC& aQuery,TDbTextComparison aComparison=EDbCompareNormal); williamr@2: inline const TDesC& Query() const; williamr@2: inline TDbTextComparison Comparison() const; williamr@2: private: williamr@2: const TDesC& iQuery; williamr@2: TDbTextComparison iComparison; williamr@2: }; williamr@2: williamr@2: /** williamr@2: This class is internal and is not intended for use williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbHandleBase williamr@2: { williamr@2: public: williamr@2: inline RDbHandleBase(); williamr@2: void Close(); williamr@2: protected: williamr@2: inline void Set(CDbObject* aObject); williamr@2: CDbObject& Object() const; williamr@2: protected: williamr@2: CDbObject* iObject; williamr@2: }; williamr@2: williamr@2: /** williamr@2: This class is internal and is not intended for use. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: template williamr@2: class RDbHandle : public RDbHandleBase williamr@2: { williamr@2: public: williamr@2: inline T* operator=(T* aT); williamr@2: inline T* operator->() const; williamr@2: inline T& operator*() const; williamr@2: inline T* operator()() const; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Represents a pre-compiled SQL search-condition, which can be used to williamr@2: test against the current row in a rowset. williamr@2: williamr@2: The constraint is compiled against a specific rowset, and can only be matched williamr@2: against the same rowset using the RDbRowSet::MatchL() function. williamr@2: williamr@2: @see RDbRowSet williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbRowConstraint williamr@2: { williamr@2: friend class RDbRowSet; williamr@2: public: williamr@2: IMPORT_C TInt Open(const RDbRowSet& aView,TDbQuery aCriteria); williamr@2: IMPORT_C void Close(); williamr@2: private: williamr@2: RDbHandle iConstraint; williamr@2: }; williamr@2: williamr@2: /** williamr@2: An abstract base class that provides functionality which is shared between williamr@2: SQL view objects and Table objects. This functionality includes most of the williamr@2: cursor navigation, row retrieval and update behaviour of rowsets. williamr@2: williamr@2: Rowset objects do not provide the data for the rowset on which they operate. williamr@2: It is the responsibility of the derived classes RDbView and RDbTable to specify williamr@2: the data source. williamr@2: williamr@2: This class is not intended for user derivation. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbRowSet williamr@2: { williamr@2: friend class RDbRowConstraint; williamr@2: friend class RDbColReadStream; williamr@2: friend class RDbColWriteStream; williamr@2: public: williamr@2: /** Specifies where the rowset should navigate to in the GotoL() function. williamr@2: Their use is encapsulated by the respective member functions FirstL(), williamr@2: NextL() etc. */ williamr@2: enum TPosition williamr@2: { williamr@2: /** Move to the first row in the rowset. */ williamr@2: EFirst, williamr@2: /** Move to the next row in the rowset. */ williamr@2: ENext, williamr@2: /** Move to the previous row in the rowset. */ williamr@2: EPrevious, williamr@2: /** Move to the last row in the rowset. */ williamr@2: ELast, williamr@2: /** Move to the position before the first row in the rowset. */ williamr@2: EBeginning, williamr@2: /** Move to the position after the last row in the rowset. */ williamr@2: EEnd williamr@2: }; williamr@2: williamr@2: /** Specifies which operations can be performed on a rowset. */ williamr@2: enum TAccess williamr@2: { williamr@2: /** All operations can be performed on the rowset. */ williamr@2: EUpdatable, williamr@2: /** Row navigation and reading are permitted. */ williamr@2: EReadOnly, williamr@2: /** Inserting new rows is the only valid operation on the rowset. */ williamr@2: EInsertOnly williamr@2: }; williamr@2: williamr@2: /** Specifies the direction to search through the rowset when using the williamr@2: FindL() function. */ williamr@2: enum TDirection williamr@2: { williamr@2: /** Search from the current row forwards through the set. */ williamr@2: EForwards, williamr@2: /** Search from the current row backwards through the set. */ williamr@2: EBackwards williamr@2: }; williamr@2: williamr@2: /** Specifies whether the CountL() function should ensure that it returns williamr@2: the exact value which may be a non-trivial task. */ williamr@2: enum TAccuracy williamr@2: { williamr@2: /** Take the time, if necessary, to return the exact value. */ williamr@2: EEnsure, williamr@2: /** Return any immediately available value. */ williamr@2: EQuick williamr@2: }; williamr@2: public: williamr@2: IMPORT_C void Close(); williamr@2: IMPORT_C void Reset(); williamr@2: // williamr@2: IMPORT_C CDbColSet* ColSetL() const; williamr@2: IMPORT_C TInt ColCount() const; williamr@2: IMPORT_C TDbColType ColType(TDbColNo aCol) const; williamr@2: IMPORT_C TDbCol ColDef(TDbColNo aCol) const; williamr@2: // williamr@2: IMPORT_C TBool AtRow() const; williamr@2: IMPORT_C TBool AtBeginning() const; williamr@2: IMPORT_C TBool AtEnd() const; williamr@2: // williamr@2: IMPORT_C TInt CountL(TAccuracy anAccuracy=EEnsure) const; williamr@2: IMPORT_C TBool IsEmptyL() const; williamr@2: // williamr@2: IMPORT_C TBool GotoL(TPosition aPosition); williamr@2: inline void BeginningL(); williamr@2: inline void EndL(); williamr@2: inline TBool FirstL(); williamr@2: inline TBool LastL(); williamr@2: inline TBool NextL(); williamr@2: inline TBool PreviousL(); williamr@2: // williamr@2: IMPORT_C TDbBookmark Bookmark() const; williamr@2: IMPORT_C void GotoL(const TDbBookmark& aMark); williamr@2: // williamr@2: IMPORT_C TBool MatchL(const RDbRowConstraint& aConstraint); williamr@2: IMPORT_C TInt FindL(TDirection aDirection,TDbQuery aCriteria); williamr@2: // williamr@2: IMPORT_C void GetL(); williamr@2: IMPORT_C void InsertL(); williamr@2: IMPORT_C void InsertCopyL(); williamr@2: IMPORT_C void UpdateL(); williamr@2: IMPORT_C void PutL(); williamr@2: IMPORT_C void Cancel(); williamr@2: IMPORT_C void DeleteL(); williamr@2: // williamr@2: inline TBool IsColNull(TDbColNo aCol) const; williamr@2: IMPORT_C TInt ColSize(TDbColNo aCol) const; williamr@2: IMPORT_C TInt ColLength(TDbColNo aCol) const; williamr@2: // williamr@2: IMPORT_C TInt8 ColInt8(TDbColNo aCol) const; williamr@2: IMPORT_C TInt16 ColInt16(TDbColNo aCol) const; williamr@2: IMPORT_C TInt32 ColInt32(TDbColNo aCol) const; williamr@2: IMPORT_C TInt64 ColInt64(TDbColNo aCol) const; williamr@2: inline TInt ColInt(TDbColNo aCol) const; williamr@2: IMPORT_C TUint8 ColUint8(TDbColNo aCol) const; williamr@2: IMPORT_C TUint16 ColUint16(TDbColNo aCol) const; williamr@2: IMPORT_C TUint32 ColUint32(TDbColNo aCol) const; williamr@2: inline TUint ColUint(TDbColNo aCol) const; williamr@2: IMPORT_C TReal32 ColReal32(TDbColNo aCol) const __SOFTFP; williamr@2: IMPORT_C TReal64 ColReal64(TDbColNo aCol) const __SOFTFP; williamr@2: inline TReal ColReal(TDbColNo aCol) const; williamr@2: IMPORT_C TTime ColTime(TDbColNo aCol) const; williamr@2: IMPORT_C TPtrC8 ColDes8(TDbColNo aCol) const; williamr@2: IMPORT_C TPtrC16 ColDes16(TDbColNo aCol) const; williamr@2: IMPORT_C TPtrC ColDes(TDbColNo aCol) const; williamr@2: // williamr@2: IMPORT_C void SetColNullL(TDbColNo aCol); williamr@2: inline void SetColL(TDbColNo aCol,TInt aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TInt32 aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TInt64 aValue); williamr@2: inline void SetColL(TDbColNo aCol,TUint aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TUint32 aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TReal32 aValue) __SOFTFP; williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TReal64 aValue) __SOFTFP; williamr@2: IMPORT_C void SetColL(TDbColNo aCol,TTime aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,const TDesC8& aValue); williamr@2: IMPORT_C void SetColL(TDbColNo aCol,const TDesC16& aValue); williamr@2: private: williamr@2: inline MStreamBuf* ColSourceL(TDbColNo aCol) const; williamr@2: inline MStreamBuf* ColSinkL(TDbColNo aCol); williamr@2: CDbCursor& CheckCol(TDbColNo aCol) const; williamr@2: TDbColumnC ColumnC(TDbColNo aCol,TDbColType aType) const; williamr@2: TDbColumn Column(TDbColNo aCol,TDbColType aType); williamr@2: protected: williamr@2: RDbHandle iCursor; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Allows any column value to be read as stream data. williamr@2: williamr@2: Note that this is the only way to extract the contents of a Long column from williamr@2: a rowset. williamr@2: williamr@2: Only one column in a rowset object can be opened for reading as a stream at williamr@2: a time, and while it is open no column in the same rowset object may be set williamr@2: using RDbColWriteStream. williamr@2: williamr@2: Null columns result in a read stream with no data. Small numeric columns are williamr@2: maintained in memory as 32-bit values; hence reading a Uint8 column as a stream williamr@2: results in 4 bytes of stream data, not 1. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbColReadStream : public RReadStream williamr@2: { williamr@2: public: williamr@2: IMPORT_C void OpenL(const RDbRowSet& aView,TDbColNo aCol); williamr@2: IMPORT_C void OpenLC(const RDbRowSet& aView,TDbColNo aCol); williamr@2: }; williamr@2: williamr@2: /** williamr@2: Writes Long columns when inserting or updating rows in a rowset. williamr@2: williamr@2: Only one column in a rowset object can be opened for writing as a stream at williamr@2: a time. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbColWriteStream : public RWriteStream williamr@2: { williamr@2: public: williamr@2: /** Constructs this object by invoking the default constructor for williamr@2: RWriteStream. */ williamr@2: inline RDbColWriteStream() {} williamr@2: inline RDbColWriteStream(const MExternalizer &anExternalizer); williamr@2: IMPORT_C void OpenL(RDbRowSet& aView,TDbColNo aCol); williamr@2: IMPORT_C void OpenLC(RDbRowSet& aView,TDbColNo aCol); williamr@2: }; williamr@2: williamr@2: /** williamr@2: Describes the desired shape of a view's pre-evaluation window. williamr@2: williamr@2: An instance of this class is passed to the RDbView object as part of the williamr@2: Prepare() function. The different constructors for TDbWindow can specify a view: williamr@2: williamr@2: without pre-evaluation williamr@2: williamr@2: with full pre-evaluation williamr@2: williamr@2: with limited pre-evaluation. williamr@2: williamr@2: @see RDbView williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbWindow williamr@2: { williamr@2: public: williamr@2: /** Denotes a full pre-evaluation window. */ williamr@2: enum TUnlimited williamr@2: { williamr@2: /** No limit on how many rows may be in the window. */ williamr@2: EUnlimited=KMaxTInt williamr@2: }; williamr@2: enum {ENone=0}; williamr@2: public: williamr@2: inline TDbWindow(); williamr@2: inline TDbWindow(TUnlimited); williamr@2: IMPORT_C TDbWindow(TInt aForeSlots,TInt aRearSlots); williamr@2: inline TInt Size() const; williamr@2: inline TInt PreferredPos() const; williamr@2: private: williamr@2: TInt iSize; williamr@2: TInt iPreferredPos; williamr@2: }; williamr@2: #if defined(__NO_CLASS_CONSTS__) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: #define KDbUnlimitedWindow TDbWindow(TDbWindow::EUnlimited) williamr@2: #else williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TDbWindow KDbUnlimitedWindow=TDbWindow(TDbWindow::EUnlimited); williamr@2: #endif williamr@2: williamr@2: /** williamr@2: Generates rowsets from an SQL query. The query is prepared and evaluated williamr@2: using the interface to this class, while the rowset is manipulated using the williamr@2: RDbRowset base class. williamr@2: williamr@2: There are no special rules to consider when deriving from this class. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbView : public RDbRowSet williamr@2: { williamr@2: public: williamr@2: IMPORT_C TInt Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,TAccess anAccess=EUpdatable); williamr@2: IMPORT_C TInt Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,const TDbWindow& aWindow); williamr@2: IMPORT_C TInt Prepare(RDbDatabase& aDatabase,const TDbQuery& aQuery,const TDbWindow& aWindow,TAccess anAccess); williamr@2: IMPORT_C TInt EvaluateAll(); williamr@2: IMPORT_C TInt Evaluate(); williamr@2: IMPORT_C void Evaluate(TRequestStatus& aStatus); williamr@2: IMPORT_C TBool Unevaluated() const; williamr@2: }; williamr@2: williamr@2: /** williamr@2: This class is internal and is not intended for use. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: template williamr@2: class TUnion williamr@2: { williamr@2: public: williamr@2: inline operator const T&() const; williamr@2: inline const T& operator()() const; williamr@2: inline T& operator()(); williamr@2: inline void Set(const T& aT); williamr@2: private: williamr@2: TUint8 iRep[sizeof(T)]; williamr@2: }; williamr@2: williamr@2: /** williamr@2: This class is internal and is not intended for use. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbLookupKey williamr@2: { williamr@2: public: williamr@2: struct SColumn williamr@2: { williamr@2: union williamr@2: { williamr@2: TInt32 iInt32; williamr@2: TUint32 iUint32; williamr@2: TUnion iInt64; williamr@2: TReal32 iReal32; williamr@2: TReal64 iReal64; williamr@2: TUnion iTime; williamr@2: struct {const TText8* iPtr;TInt iLength;} iDes8; williamr@2: struct {const TText16* iPtr;TInt iLength;} iDes16; williamr@2: }; williamr@2: TDbColType iType; williamr@2: }; williamr@2: public: williamr@2: inline TDbLookupKey(); williamr@2: inline TInt Count() const; williamr@2: inline const SColumn* First() const; williamr@2: void Add(TInt aKey); williamr@2: void Add(TUint aKey); williamr@2: void Add(TInt64 aKey); williamr@2: void Add(TReal32 aKey) __SOFTFP; williamr@2: void Add(TReal64 aKey) __SOFTFP; williamr@2: void Add(TTime aKey); williamr@2: void Add(const TDesC8& aKey); williamr@2: void Add(const TDesC16& aKey); williamr@2: private: williamr@2: SColumn& NextKey(); williamr@2: private: williamr@2: TInt iCount; williamr@2: SColumn iKey[1]; // at least one williamr@2: }; williamr@2: williamr@2: /** williamr@2: Database key value. williamr@2: williamr@2: The class encapsulates a key value which is passed to RDbTable::SeekL(), for williamr@2: lookup in the currently active index on that rowset. williamr@2: williamr@2: An instance of this class can store a key value of any type. williamr@2: williamr@2: Note that the class can only hold a single-column key. Use TDbSeekMultiKey williamr@2: for multi-column keys. williamr@2: williamr@2: @see TDbSeekMultiKey williamr@2: @see RDbTable williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class TDbSeekKey williamr@2: { williamr@2: friend class RDbTable; williamr@2: public: williamr@2: inline TDbSeekKey(); williamr@2: inline TDbSeekKey(TInt aKey); williamr@2: inline TDbSeekKey(TUint aKey); williamr@2: inline TDbSeekKey(TInt64 aKey); williamr@2: inline TDbSeekKey(TReal32 aKey); williamr@2: inline TDbSeekKey(TReal64 aKey); williamr@2: inline TDbSeekKey(TTime aKey); williamr@2: inline TDbSeekKey(const TDesC8& aKey); williamr@2: inline TDbSeekKey(const TDesC16& aKey); williamr@2: IMPORT_C TDbSeekKey& Add(TInt aKey); williamr@2: IMPORT_C TDbSeekKey& Add(TUint aKey); williamr@2: IMPORT_C TDbSeekKey& Add(TInt64 aKey); williamr@2: IMPORT_C TDbSeekKey& Add(TReal32 aKey) __SOFTFP; williamr@2: IMPORT_C TDbSeekKey& Add(TReal64 aKey) __SOFTFP; williamr@2: IMPORT_C TDbSeekKey& Add(TTime aKey); williamr@2: IMPORT_C TDbSeekKey& Add(const TDesC8& aKey); williamr@2: IMPORT_C TDbSeekKey& Add(const TDesC16& aKey); williamr@2: private: williamr@2: TDbLookupKey& Check(); williamr@2: protected: williamr@2: inline TDbSeekKey(TInt aKeys,TInt); williamr@2: private: williamr@2: TInt iMaxKeys; williamr@2: TDbLookupKey iKey; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Database multi-column key value. williamr@2: williamr@2: The class extends the behaviour of TDbSeekKey by allowing multi-column indexes williamr@2: to be searched using multi-column key values. williamr@2: williamr@2: The template parameter S specifies the maximum number of column values that williamr@2: can be added to the key value. williamr@2: williamr@2: Use the TDbSeekKey::Add() members to append the values for each column in williamr@2: the key value. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: template williamr@2: class TDbSeekMultiKey : public TDbSeekKey williamr@2: { williamr@2: public: williamr@2: inline TDbSeekMultiKey(); williamr@2: private: williamr@2: TDbLookupKey::SColumn iExtraKeys[S-1]; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides access to table data as a rowset, allowing manipulation of a named williamr@2: table in the database. Additionally, a named index can be used to order the williamr@2: rowset, and to provide fast key-based row retrieval from the table. williamr@2: williamr@2: There are no special rules to consider when deriving from this class. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbTable : public RDbRowSet williamr@2: { williamr@2: public: williamr@2: /** Database table seek comparison types. */ williamr@2: enum TComparison williamr@2: { williamr@2: /** Retrieve the last row which is strictly less than the key value. */ williamr@2: ELessThan, williamr@2: /** Retrieve the last row which is equal to or less than the key williamr@2: value. */ williamr@2: ELessEqual, williamr@2: /** Retrieve the first row which is equal to the key value. */ williamr@2: EEqualTo, williamr@2: /** Retrieve the first row which is equal to or greater than the key williamr@2: value. */ williamr@2: EGreaterEqual, williamr@2: /** Retrieve the first row which is strictly greater than the key williamr@2: value. */ williamr@2: EGreaterThan williamr@2: }; williamr@2: public: williamr@2: IMPORT_C TInt Open(RDbDatabase& aDatabase,const TDesC& aName,TAccess anAccess=EUpdatable); williamr@2: inline TInt SetIndex(const TDesC& anIndex); williamr@2: inline TInt SetNoIndex(); williamr@2: IMPORT_C TBool SeekL(const TDbSeekKey& aKey,TComparison aComparison=EEqualTo); williamr@2: private: williamr@2: IMPORT_C TInt SetIndex(const TDesC* anIndex); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CDbNames : public CBase williamr@2: { williamr@2: private: williamr@2: inline CDbNames(); williamr@2: public: williamr@2: static CDbNames* NewLC(); williamr@2: ~CDbNames(); williamr@2: inline TInt Count() const; williamr@2: inline const TDesC& operator[](TInt anIndex) const; williamr@2: IMPORT_C void AddL(const TDesC& aName); williamr@2: private: williamr@2: CArrayPakFlat iList; williamr@2: }; williamr@2: /** williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef CDbNames CDbTableNames,CDbIndexNames,CDbDatabaseNames; williamr@2: williamr@2: /** williamr@2: The maximum length for a generic DBMS string, which might be transferred from DBMS server williamr@2: to the DBMS client using IPC. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: const TInt KDbMaxStrLen = 256; williamr@2: williamr@2: /** williamr@2: Represents a generic read-only DBMS string. It maps to a non-modifiable buffer descriptor williamr@2: with maximum size KDbMaxStrLen. williamr@2: williamr@2: @see TBufC williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef TBufC TDbStringC; williamr@2: williamr@2: /** williamr@2: CDbStrings encapsulates functionality used for transferring an array of strings from williamr@2: DBMS server to the DBMS client. The maximal length of each element of the array is williamr@2: KDbMaxStrLen characters. williamr@2: The typical usage pattern of CDbStrings class is: williamr@2: @code williamr@2: CDbStrings* strings = ; williamr@2: TInt cnt = strings.Count(); williamr@2: for(TInt i=0;i; williamr@2: } williamr@2: delete strings; williamr@2: @endcode williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class CDbStrings : public CBase williamr@2: { williamr@2: private: williamr@2: inline CDbStrings(); williamr@2: public: williamr@2: static CDbStrings* NewLC(); williamr@2: virtual ~CDbStrings(); williamr@2: inline TInt Count() const; williamr@2: inline const TDesC& operator[](TInt aIndex) const; williamr@2: void AddL(const TDesC& aStr); williamr@2: private: williamr@2: CArrayPakFlat iList; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Abstract class providing the functionality of a database. williamr@2: williamr@2: The source of the database and the implementation characteristics of a particular williamr@2: database are provided by a class derived from RDbDatabase. williamr@2: williamr@2: DBMS has one such implementation: the store database. williamr@2: williamr@2: This class is not intended for user derivation. williamr@2: williamr@2: Note: For functions (i.e. Execute) that take an Sql string, if the string williamr@2: contains a LIKE clause with * (asterisks) wildcard then the williamr@2: characters between them must be no longer than length 255. williamr@2: If only one * exists then the length is taken from the start and to the end of williamr@2: the clause. However, if the clause contains a ? (question mark) wildcard williamr@2: within it then the characters between must be no longer than length 253. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbDatabase williamr@2: { williamr@2: friend class RDbView; williamr@2: friend class RDbTable; williamr@2: friend class RDbIncremental; williamr@2: friend class RDbUpdate; williamr@2: friend class RDbNotifier; williamr@2: public: williamr@2: struct TSize {TInt iSize;TInt iUsage;}; williamr@2: public: williamr@2: IMPORT_C void Close(); williamr@2: IMPORT_C TInt Destroy(); williamr@2: // williamr@2: IMPORT_C TBool IsDamaged() const; williamr@2: IMPORT_C TInt Recover(); williamr@2: // williamr@2: IMPORT_C TInt UpdateStats(); williamr@2: IMPORT_C TSize Size() const; williamr@2: IMPORT_C TInt Compact(); williamr@2: IMPORT_C TInt Begin(); williamr@2: IMPORT_C TInt Commit(); williamr@2: IMPORT_C void Rollback(); williamr@2: IMPORT_C TBool InTransaction() const; williamr@2: // williamr@2: inline TInt CreateTable(const TDesC& aName,const CDbColSet& aDef); williamr@2: inline TInt CreateTable(const TDesC& aName,const CDbColSet& aDef,const CDbKey& aPrimaryKey); williamr@2: IMPORT_C TInt DropTable(const TDesC& aName); williamr@2: IMPORT_C TInt AlterTable(const TDesC& aName,const CDbColSet& aNewDef); williamr@2: IMPORT_C TInt CreateIndex(const TDesC& aName,const TDesC& aTable,const CDbKey& aKey); williamr@2: IMPORT_C TInt DropIndex(const TDesC& aName,const TDesC& aTable); williamr@2: // williamr@2: IMPORT_C TInt Execute(const TDesC& aSql,TDbTextComparison aComparison=EDbCompareNormal); williamr@2: // williamr@2: IMPORT_C CDbTableNames* TableNamesL() const; williamr@2: IMPORT_C CDbColSet* ColSetL(const TDesC& aName) const; williamr@2: IMPORT_C CDbIndexNames* IndexNamesL(const TDesC& aTable) const; williamr@2: IMPORT_C CDbKey* KeyL(const TDesC& aName,const TDesC& aTable) const; williamr@2: private: williamr@2: IMPORT_C TInt CreateTable(const TDesC& aName,const CDbColSet& aColSet,const CDbKey* aPrimaryKey); williamr@2: protected: williamr@2: RDbHandle iDatabase; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides the interface for performing long-running database operations in williamr@2: incremental steps, allowing application programs to remain responsive to other williamr@2: events. williamr@2: williamr@2: After an operation has begun, a standard interface is used to continue and williamr@2: complete all incremental operations. On successful return from one of the williamr@2: initiating functions, a step value is also returned. This gives the progress williamr@2: indication and is, initially, positive. This value should be passed into williamr@2: subsequent steps in the operation, each of which may decrement the value by williamr@2: some amount, although they are allowed to leave it unchanged. The value williamr@2: reaches zero, if, and only if the operation completes. williamr@2: williamr@2: While an incremental operation is in progress, the database cannot be used williamr@2: for any other operations such as opening tables or preparing views. williamr@2: williamr@2: Starting an incremental operation also requires that no rowsets are open on williamr@2: the database and that no commit is pending for data manipulation transactions. williamr@2: williamr@2: If no explicit transaction has been started by the database, then an automatic williamr@2: transaction is begun when any incremental operation is started and is committed williamr@2: when complete or rolled back if the operation either fails or is abandoned williamr@2: prior to completion. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbIncremental williamr@2: { williamr@2: public: williamr@2: IMPORT_C void Close(); williamr@2: IMPORT_C TInt Next(TInt& aStep); williamr@2: IMPORT_C void Next(TPckgBuf& aStep,TRequestStatus& aStatus); williamr@2: // williamr@2: IMPORT_C TInt Recover(RDbDatabase& aDatabase,TInt& aStep); williamr@2: IMPORT_C TInt Compact(RDbDatabase& aDatabase,TInt& aStep); williamr@2: IMPORT_C TInt DropTable(RDbDatabase& aDatabase,const TDesC& aTable,TInt& aStep); williamr@2: IMPORT_C TInt AlterTable(RDbDatabase& aDatabase,const TDesC& aTable,const CDbColSet& aNewDef,TInt& aStep); williamr@2: IMPORT_C TInt CreateIndex(RDbDatabase& aDatabase,const TDesC& aName,const TDesC& aTable,const CDbKey& aKey,TInt& aStep); williamr@2: IMPORT_C TInt DropIndex(RDbDatabase& aDatabase,const TDesC& aName,const TDesC& aTable,TInt& aStep); williamr@2: inline TInt Execute(RDbDatabase& aDatabase,const TDesC& aSql,TInt& aStep); williamr@2: IMPORT_C TInt Execute(RDbDatabase& aDatabase,const TDesC& aSql,TDbTextComparison aComparison,TInt& aStep); williamr@2: IMPORT_C TInt UpdateStats(RDbDatabase& aDatabase,TInt& aStep); williamr@2: private: williamr@2: RDbHandle iState; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides an interface to allow incremental execution of a DML (SQL data williamr@2: update) statement. williamr@2: williamr@2: This class offers similar behaviour to the RDbIncremental class, in that it williamr@2: allows an application to perform long running operations while remaining williamr@2: responsive to events. However, unlike that class, RDbUpdate is restricted to williamr@2: executing DML statements. williamr@2: williamr@2: @see RDbIncremental williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbUpdate williamr@2: { williamr@2: public: williamr@2: IMPORT_C TInt Execute(RDbDatabase& aDatabase,const TDesC& aSql,TDbTextComparison aComparison=EDbCompareNormal); williamr@2: IMPORT_C void Close(); williamr@2: // williamr@2: IMPORT_C TInt Next(); williamr@2: IMPORT_C void Next(TRequestStatus& aStatus); williamr@2: IMPORT_C TInt RowCount() const; williamr@2: private: williamr@2: RDbHandle iUpdate; williamr@2: TPckgBuf iRows; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Provides notification of database changes to clients. williamr@2: williamr@2: This is useful for shared databases. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbNotifier williamr@2: { williamr@2: public: williamr@2: /** Defines the events which may be reported by a DBMS change notifier williamr@2: through this RDbNotifier object. williamr@2: williamr@2: Each enumerator corresponds to a distinct event type. williamr@2: williamr@2: The changes are reported through a TRequestStatus object when an williamr@2: outstanding notification request completes. williamr@2: williamr@2: Notes williamr@2: williamr@2: If further database events occur while a client is handling the completion williamr@2: of a previous event, the notifier remembers the most significant event. The williamr@2: order of importance is: williamr@2: williamr@2: ERecover > ERollback > ECommit williamr@2: williamr@2: where the symbol > means "is more important than" */ williamr@2: enum TEvent williamr@2: { williamr@2: /** The database has been closed. */ williamr@2: EClose, williamr@2: /** All read locks have been removed. */ williamr@2: EUnlock, williamr@2: /** A transaction has been committed. */ williamr@2: ECommit, williamr@2: /** A transaction has been rolled back */ williamr@2: ERollback, williamr@2: /** The database has been recovered */ williamr@2: ERecover williamr@2: }; williamr@2: public: williamr@2: IMPORT_C TInt Open(RDbDatabase& aDatabase); williamr@2: IMPORT_C void Close(); williamr@2: // williamr@2: IMPORT_C void NotifyUnlock(TRequestStatus& aStatus); williamr@2: IMPORT_C void NotifyChange(TRequestStatus& aStatus); williamr@2: IMPORT_C void Cancel(); williamr@2: private: williamr@2: RDbHandle iNotifier; williamr@2: }; williamr@2: williamr@2: /** williamr@2: Client-server databases williamr@2: williamr@2: Represents a session with the DBMS server. A thread uses this class to set williamr@2: up a DBMS server session and this provides the basis for sharing databases williamr@2: with other threads. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbs : public RSessionBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: This enum is used in GetDatabasePolicy/GetTablePolicy/GetTablePolicies calls and specifies williamr@2: requested security policy type: read/write/schema. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: typedef enum {EReadPolicy, EWritePolicy, ESchemaPolicy} TPolicyType; williamr@2: williamr@2: public: williamr@2: IMPORT_C static TVersion Version(); williamr@2: IMPORT_C TInt Connect(); williamr@2: IMPORT_C CDbDatabaseNames* DatabaseNamesL(TDriveNumber aDrive, TUid aPolicyUid); williamr@2: IMPORT_C TInt CopyDatabase(const TDesC& aSrcDbName, const TDesC& aDestDbName, TUid aPolicyUid); williamr@2: IMPORT_C TInt DeleteDatabase(const TDesC& aDbName, TUid aPolicyUid); williamr@2: IMPORT_C TInt GetDatabasePolicy(TUid aPolicyUid, TPolicyType aPolicyType, williamr@2: TSecurityPolicy& aDbPolicy); williamr@2: IMPORT_C TInt GetTablePolicy(TUid aPolicyUid, const TDesC& aTableName, williamr@2: TPolicyType aPolicyType, TSecurityPolicy& aTablePolicy); williamr@2: IMPORT_C TInt GetTablePolicies(TUid aPolicyUid, const TDesC& aTableName, williamr@2: TPolicyType aPolicyType, williamr@2: TSecurityPolicy& aDbPolicy, TSecurityPolicy& aTablePolicy); williamr@2: // williamr@2: IMPORT_C void ResourceMark(); williamr@2: IMPORT_C void ResourceCheck(); williamr@2: IMPORT_C TInt ResourceCount(); williamr@2: IMPORT_C void SetHeapFailure(TInt aTAllocFail,TInt aRate); williamr@2: williamr@2: IMPORT_C TInt ReserveDriveSpace(TInt aDriveNo, TInt aSpace); williamr@2: IMPORT_C void FreeReservedSpace(TInt aDriveNo); williamr@2: IMPORT_C TInt GetReserveAccess(TInt aDriveNo); williamr@2: IMPORT_C TInt ReleaseReserveAccess(TInt aDriveNo); williamr@2: williamr@2: IMPORT_C TInt GetBackupPath(TSecureId aRequesterSid, const TDesC& aDbName, williamr@2: TUid aDbPolicyUid, TDes& aBackupPath); williamr@2: IMPORT_C CDbStrings* BackupPathsL(TSecureId aRequesterSid, TUid aDbPolicyUid); williamr@2: williamr@2: private: williamr@2: TInt DoConnect(); williamr@2: TInt SessionMessage(TInt aFunction); williamr@2: TInt GetPolicy(TUid aPolicyUid, const TDesC& aTableName, williamr@2: TUint aMask, TSecurityPolicy& aPolicy); williamr@2: }; williamr@2: williamr@2: /** williamr@2: Generic database implementation williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbNamedDatabase : public RDbDatabase williamr@2: { williamr@2: public: williamr@2: /** Specifies which operations can be performed on a rowset. */ williamr@2: enum TAccess williamr@2: { williamr@2: EReadWrite, williamr@2: /** Row navigation and reading are permitted. */ williamr@2: EReadOnly williamr@2: }; williamr@2: public: williamr@2: IMPORT_C TInt Create(RDbs& aDbs, const TDesC& aDatabase, const TDesC& aFormat); williamr@2: IMPORT_C TInt Create(RFs& aFs,const TDesC& aDatabase,const TDesC& aFormat=TPtrC()); williamr@2: IMPORT_C TInt Replace(RFs& aFs,const TDesC& aDatabase,const TDesC& aFormat=TPtrC()); williamr@2: IMPORT_C TInt Open(RFs& aFs,const TDesC& aDatabase,const TDesC& aFormat=TPtrC(),TAccess aMode=EReadWrite); williamr@2: IMPORT_C TInt Open(RDbs& aDbs,const TDesC& aDatabase,const TDesC& aFormat=TPtrC()); williamr@2: }; williamr@2: williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: const TInt KDbStoreMaxColumnLength=255; williamr@2: williamr@2: /** williamr@2: DBMS Store database implementation williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: class RDbStoreDatabase : public RDbDatabase williamr@2: { williamr@2: public: williamr@2: IMPORT_C TStreamId CreateL(CStreamStore* aStore); williamr@2: IMPORT_C void OpenL(CStreamStore* aStore,TStreamId anId); williamr@2: IMPORT_C static void CompressL(CStreamStore& aStore,TStreamId aId); williamr@2: IMPORT_C static void DecompressL(CStreamStore& aStore,TStreamId aId); williamr@2: }; williamr@2: williamr@2: #include williamr@2: #endif