epoc32/include/sqldb.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // 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
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    13 // Description:
    13 // Description:
    14 // SQL Client side API header
    14 // SQL Client side API header
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 
       
    19 
       
    20 /**
    18 /**
    21  @file
    19  @file
    22  @publishedAll
    20  @publishedAll
    23  @released
    21  @released
    24 */
    22 */
    25 #ifndef __SQLDB_H__
    23 #ifndef __SQLDB_H__
    26 #define __SQLDB_H__
    24 #define __SQLDB_H__
    27 
    25 
    28 #ifndef __S32STD_H__
    26 #ifndef __S32STD_H__
    29 #include <s32std.h>	//RReadStream, RWriteStream
    27 #include <s32std.h>	//RReadStream, RWriteStream
       
    28 #endif
       
    29 
       
    30 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS 
       
    31 	#include <sqlresourcetester.h>
    30 #endif
    32 #endif
    31 
    33 
    32 //Forward declarations
    34 //Forward declarations
    33 class CSqlSecurityPolicy;
    35 class CSqlSecurityPolicy;
    34 class RSqlDatabase;
    36 class RSqlDatabase;
    36 class RSqlStatement;
    38 class RSqlStatement;
    37 class CSqlStatementImpl;
    39 class CSqlStatementImpl;
    38 class RSqlColumnReadStream;
    40 class RSqlColumnReadStream;
    39 class RSqlParamWriteStream;
    41 class RSqlParamWriteStream;
    40 class TSqlScalarFullSelectQuery;
    42 class TSqlScalarFullSelectQuery;
       
    43 class RSqlBlob;
       
    44 class RSqlBlobReadStream;
       
    45 class RSqlBlobWriteStream;
       
    46 class TSqlResourceProfiler;
       
    47 
       
    48 /**
       
    49 Used to specify that the ROWID of the most recently inserted record
       
    50 from the specified database connection should be used as the ROWID 
       
    51 in a call to directly access a blob.
       
    52 
       
    53 @see RSqlBlobReadStream
       
    54 @see RSqlBlobWriteStream
       
    55 @see TSqlBlob
       
    56 
       
    57 @publishedAll
       
    58 @released
       
    59 */
       
    60 const TInt KSqlLastInsertedRowId = -1;
    41 
    61 
    42 /**
    62 /**
    43 A container for the security policies for a shared SQL database.
    63 A container for the security policies for a shared SQL database.
    44 
    64 
    45 The container can contain:
    65 The container can contain:
   226 - copy a SQL database by calling RSqlDatabase::Copy().
   246 - copy a SQL database by calling RSqlDatabase::Copy().
   227 - delete a SQL database by calling RSqlDatabase::Delete().
   247 - delete a SQL database by calling RSqlDatabase::Delete().
   228 - attach a SQL database to current database connection by calling RSqlDatabase::Attach().
   248 - attach a SQL database to current database connection by calling RSqlDatabase::Attach().
   229 - detach a SQL database from current database connection by calling RSqlDatabase::Detach().
   249 - detach a SQL database from current database connection by calling RSqlDatabase::Detach().
   230 
   250 
       
   251 The RSqlDatabase handles are not thread-safe.
       
   252 
   231 A client can create either a non-secure database or a secure database,
   253 A client can create either a non-secure database or a secure database,
   232 depending on the variant of RSqlDatabase::Create() that is used.
   254 depending on the variant of RSqlDatabase::Create() that is used.
   233 - a non-secure database is created if the RSqlDatabase::Create(const TDesC&) variant is used.
   255 - a non-secure database is created if the RSqlDatabase::Create(const TDesC&) variant is used.
   234 - a secure database is created if the RSqlDatabase::Create(const TDesC&, const RSqlSecurityPolicy&)
   256 - a secure database is created if the RSqlDatabase::Create(const TDesC&, const RSqlSecurityPolicy&)
   235 variant is used. In this case, a container containing a collection of security
   257 variant is used. In this case, a container containing a collection of security
   279 */
   301 */
   280 class RSqlDatabase
   302 class RSqlDatabase
   281 	{
   303 	{
   282 	friend class RSqlStatement;
   304 	friend class RSqlStatement;
   283 	friend class TSqlScalarFullSelectQuery;
   305 	friend class TSqlScalarFullSelectQuery;
       
   306 	friend class RSqlBlob;
       
   307 	friend class RSqlBlobReadStream;
       
   308 	friend class RSqlBlobWriteStream;
       
   309 	friend class TSqlResourceProfiler;
   284 	
   310 	
   285 public:
   311 public:
   286 	/**
   312 	/**
   287 	Defines a set of values that represents the transaction isolation level.
   313 	Defines a set of values that represents the transaction isolation level.
   288 	
   314 	
   375 		@see TIsolationLevel
   401 		@see TIsolationLevel
   376 		@see RSqlDatabase::SetIsolationLevel()
   402 		@see RSqlDatabase::SetIsolationLevel()
   377 		*/
   403 		*/
   378 		ESerializable
   404 		ESerializable
   379 		};
   405 		};
       
   406 	/**
       
   407 	This structure is used for retrieving the database size and database free space.
       
   408 	@see RSqlDatabase::Size(TSize&)
       
   409 	*/
       
   410 	struct TSize
       
   411 		{
       
   412 		/** The database size in bytes*/
       
   413 		TInt64	iSize;
       
   414 		/** The database free space in bytes*/
       
   415 		TInt64	iFree;
       
   416 		};
       
   417 
       
   418 	/** If this value is used as an argument of RSqlDatabase::Compact() (aSize argument), then all free space will be removed */
       
   419 	enum {EMaxCompaction = -1};
   380 		
   420 		
   381 	IMPORT_C RSqlDatabase();
   421 	IMPORT_C RSqlDatabase();
   382 	
   422 	
   383 	IMPORT_C TInt Create(const TDesC& aDbFileName, const TDesC8* aConfig=NULL);
   423 	IMPORT_C TInt Create(const TDesC& aDbFileName, const TDesC8* aConfig=NULL);
   384 	IMPORT_C TInt Create(const TDesC& aDbFileName,
   424 	IMPORT_C TInt Create(const TDesC& aDbFileName,
   407 	
   447 	
   408 	IMPORT_C void Exec(const TDesC& aSqlStmt, TRequestStatus& aStatus);
   448 	IMPORT_C void Exec(const TDesC& aSqlStmt, TRequestStatus& aStatus);
   409 	IMPORT_C void Exec(const TDesC8& aSqlStmt, TRequestStatus& aStatus);
   449 	IMPORT_C void Exec(const TDesC8& aSqlStmt, TRequestStatus& aStatus);
   410 	
   450 	
   411 	IMPORT_C TPtrC LastErrorMessage() const;
   451 	IMPORT_C TPtrC LastErrorMessage() const;
       
   452 	IMPORT_C TInt64 LastInsertedRowId() const; 
   412 	
   453 	
   413 	IMPORT_C TBool InTransaction() const;
   454 	IMPORT_C TBool InTransaction() const;
   414 	IMPORT_C TInt Size() const;
   455 	IMPORT_C TInt Size() const;
       
   456 	IMPORT_C TInt Size(TSize& aSize, const TDesC& aDbName = KNullDesC) const;
       
   457 
       
   458 	IMPORT_C TInt Compact(TInt64 aSize, const TDesC& aDbName = KNullDesC);
       
   459 	IMPORT_C void Compact(TInt64 aSize, TRequestStatus& aStatus, const TDesC& aDbName = KNullDesC);
   415 	
   460 	
   416 	IMPORT_C TInt ReserveDriveSpace(TInt aSize);
   461 	IMPORT_C TInt ReserveDriveSpace(TInt aSize);
   417 	IMPORT_C void FreeReservedSpace();
   462 	IMPORT_C void FreeReservedSpace();
   418 	IMPORT_C TInt GetReserveAccess();
   463 	IMPORT_C TInt GetReserveAccess();
   419 	IMPORT_C void ReleaseReserveAccess();
   464 	IMPORT_C void ReleaseReserveAccess();
   539 	ESqlText, 
   584 	ESqlText, 
   540 	
   585 	
   541 	/**
   586 	/**
   542 	Binary data, a sequence of bytes.
   587 	Binary data, a sequence of bytes.
   543 	*/
   588 	*/
   544 	ESqlBinary 
   589 	ESqlBinary
   545 	};
   590 	};
   546 
   591 
   547 /**
   592 /**
   548 Represents an SQL statement.
   593 Represents an SQL statement.
   549 
   594 
   759 represented by the type returned by the accessor function.
   804 represented by the type returned by the accessor function.
   760 - "round": the floating point value will be rounded up to the nearest integer.
   805 - "round": the floating point value will be rounded up to the nearest integer.
   761 If the result is outside the range that can be represented by the type returned
   806 If the result is outside the range that can be represented by the type returned
   762 by the accessor function, then it will be clamped.
   807 by the accessor function, then it will be clamped.
   763 
   808 
       
   809 Note that when handling blob and text data over 2Mb in size it is recommended that the 
       
   810 RSqlBlobReadStream and RSqlBlobWriteStream classes or the TSqlBlob class is used instead. 
       
   811 These classes provide a more RAM-efficient way of reading and writing large amounts of 
       
   812 blob or text data from a database.
       
   813 
   764 @see KMinTInt
   814 @see KMinTInt
   765 @see KMaxTInt
   815 @see KMaxTInt
   766 @see KNullDesC
   816 @see KNullDesC
   767 @see KNullDesC8
   817 @see KNullDesC8
       
   818 @see RSqlBlobReadStream
       
   819 @see RSqlBlobWriteStream
       
   820 @see TSqlBlob
   768 
   821 
   769 @publishedAll
   822 @publishedAll
   770 @released
   823 @released
   771 */
   824 */
   772 class RSqlStatement
   825 class RSqlStatement
   798 	IMPORT_C TInt BindInt(TInt aParameterIndex, TInt aParameterValue);
   851 	IMPORT_C TInt BindInt(TInt aParameterIndex, TInt aParameterValue);
   799 	IMPORT_C TInt BindInt64(TInt aParameterIndex, TInt64 aParameterValue);
   852 	IMPORT_C TInt BindInt64(TInt aParameterIndex, TInt64 aParameterValue);
   800 	IMPORT_C TInt BindReal(TInt aParameterIndex, TReal aParameterValue);
   853 	IMPORT_C TInt BindReal(TInt aParameterIndex, TReal aParameterValue);
   801 	IMPORT_C TInt BindText(TInt aParameterIndex, const TDesC& aParameterText);
   854 	IMPORT_C TInt BindText(TInt aParameterIndex, const TDesC& aParameterText);
   802 	IMPORT_C TInt BindBinary(TInt aParameterIndex, const TDesC8& aParameterData);
   855 	IMPORT_C TInt BindBinary(TInt aParameterIndex, const TDesC8& aParameterData);
       
   856 	IMPORT_C TInt BindZeroBlob(TInt aParameterIndex, TInt aBlobSize);
   803 	
   857 	
   804 	IMPORT_C TBool IsNull(TInt aColumnIndex) const;
   858 	IMPORT_C TBool IsNull(TInt aColumnIndex) const;
   805 	IMPORT_C TInt ColumnInt(TInt aColumnIndex) const;
   859 	IMPORT_C TInt ColumnInt(TInt aColumnIndex) const;
   806 	IMPORT_C TInt64 ColumnInt64(TInt aColumnIndex) const;
   860 	IMPORT_C TInt64 ColumnInt64(TInt aColumnIndex) const;
   807 	IMPORT_C TReal ColumnReal(TInt aColumnIndex) const;
   861 	IMPORT_C TReal ColumnReal(TInt aColumnIndex) const;
   812 	
   866 	
   813 	IMPORT_C TPtrC8 ColumnBinaryL(TInt aColumnIndex) const;
   867 	IMPORT_C TPtrC8 ColumnBinaryL(TInt aColumnIndex) const;
   814 	IMPORT_C TInt ColumnBinary(TInt aColumnIndex, TPtrC8& aPtr) const;
   868 	IMPORT_C TInt ColumnBinary(TInt aColumnIndex, TPtrC8& aPtr) const;
   815 	IMPORT_C TInt ColumnBinary(TInt aColumnIndex, TDes8& aDest) const;
   869 	IMPORT_C TInt ColumnBinary(TInt aColumnIndex, TDes8& aDest) const;
   816 	
   870 	
       
   871 	IMPORT_C TInt ColumnName(TInt aColumnIndex, TPtrC& aNameDest);
       
   872 	IMPORT_C TInt ParameterName(TInt aParameterIndex, TPtrC& aNameDest);
       
   873 	IMPORT_C TInt ParamName(TInt aParameterIndex, TPtrC& aNameDest);
   817 private:
   874 private:
   818 	CSqlStatementImpl& Impl() const;
   875 	CSqlStatementImpl& Impl() const;
   819 	
   876 	
   820 private:
   877 private:
   821 	CSqlStatementImpl* 	iImpl;
   878 	CSqlStatementImpl* 	iImpl;
   823 	};
   880 	};
   824 
   881 
   825 /**
   882 /**
   826 The read stream interface.
   883 The read stream interface.
   827 
   884 
   828 The class is used for reading the content of a column containing a large
   885 The class is used for reading the content of a column containing either 
   829 amount of either binary data or text data.
   886 binary data or text data.
   830 
   887 
   831 The class derives from RReadStream, which means that all RReadStream public
   888 The class derives from RReadStream, which means that all RReadStream public
   832 member functions and predefined stream operators \>\> can be used to deal
   889 member functions and predefined stream operators \>\> can be used to deal
   833 with column data.
   890 with column data.
       
   891 
       
   892 If the blob or text data is over 2Mb in size then it is recommended that the 
       
   893 RSqlBlobReadStream or TSqlBlob class is used instead. These classes provide 
       
   894 a more RAM-efficient way of reading large amounts of blob or text data from
       
   895 a database.
   834 
   896 
   835 The following two cases are typical:
   897 The following two cases are typical:
   836 
   898 
   837 CASE 1 - processing large binary column data.
   899 CASE 1 - processing large binary column data.
   838 
   900 
   884 	{
   946 	{
   885 	...
   947 	...
   886 	}
   948 	}
   887 @endcode
   949 @endcode
   888 
   950 
       
   951 @see RSqlBlobReadStream
       
   952 @see TSqlBlob
       
   953 
   889 @publishedAll
   954 @publishedAll
   890 @released
   955 @released
   891 */
   956 */
   892 class RSqlColumnReadStream : public RReadStream
   957 class RSqlColumnReadStream : public RReadStream
   893 	{
   958 	{
   900 	};
   965 	};
   901 
   966 
   902 /**
   967 /**
   903 The write stream interface.
   968 The write stream interface.
   904 
   969 
   905 The class is used to set a large amount of either binary data or text data
   970 The class is used to set binary data or text data into a parameter. 
   906 into a parameter. This is a also known as binding a parameter.
   971 This is a also known as binding a parameter.
   907 
   972 
   908 The class derives from RWriteStream, which means that all RWriteStream public
   973 The class derives from RWriteStream, which means that all RWriteStream public
   909 member functions and predefined stream operators \<\< can be used to deal with
   974 member functions and predefined stream operators \<\< can be used to deal with
   910 the parameter data.
   975 the parameter data.
       
   976 
       
   977 If the blob or text data is over 2Mb in size then it is recommended that the 
       
   978 RSqlBlobWriteStream or TSqlBlob class is used instead. These classes provide 
       
   979 a more RAM-efficient way of writing large amounts of blob or text data to
       
   980 a database.
   911 
   981 
   912 The following two cases are typical:
   982 The following two cases are typical:
   913 
   983 
   914 CASE 1 - binding a large binary parameter.
   984 CASE 1 - binding a large binary parameter.
   915 
   985 
   953 TInt rc = stmt.Next();//rc = stmt.Exec()
  1023 TInt rc = stmt.Next();//rc = stmt.Exec()
   954 //Close the stream
  1024 //Close the stream
   955 CleanupStack::PopAndDestroy(&paramStream);
  1025 CleanupStack::PopAndDestroy(&paramStream);
   956 @endcode
  1026 @endcode
   957 
  1027 
       
  1028 @see RSqlBlobWriteStream
       
  1029 @see TSqlBlob
       
  1030 
   958 @publishedAll
  1031 @publishedAll
   959 @released
  1032 @released
   960 */
  1033 */
   961 class RSqlParamWriteStream : public RWriteStream
  1034 class RSqlParamWriteStream : public RWriteStream
   962 	{
  1035 	{
   967 	IMPORT_C void BindBinaryL(RSqlStatement& aStmt, TInt aParameterIndex);
  1040 	IMPORT_C void BindBinaryL(RSqlStatement& aStmt, TInt aParameterIndex);
   968 
  1041 
   969 	};
  1042 	};
   970 
  1043 
   971 /**
  1044 /**
   972 TSqlResourceTester class is used internally by the SQL server out of memory and resource leaking
  1045 A direct handle to a blob, used for reading the content of the blob via a streaming interface.
   973 tests. 
  1046 
   974 It provides methods for heap allocation failure simulation and resource checking and counting.
  1047 The target blob is identified using the relevant database connection, table name, 
   975 
  1048 column name and ROWID of the record to which the blob belongs (also the attached
   976 @internalAll
  1049 database name if the blob is contained in an attached database).
   977 @released
  1050 
   978 */
  1051 A blob in this context refers to the content of a BLOB or TEXT column, 
   979 class TSqlResourceTester
  1052 and a read handle can be opened on both types of column.
   980 	{
  1053 For TEXT columns it is important to note that no conversions are performed on 
   981 public:	
  1054 data retrieved using this class - the data is returned as a stream of bytes.
   982 	IMPORT_C static void Mark();
  1055 
   983 	IMPORT_C static void Check();
  1056 The class derives from RReadStream and provides all of its streaming methods.
   984 	IMPORT_C static TInt Count();
  1057 The SizeL() method can be used to check the total size of the blob, in bytes.
   985 	IMPORT_C static void SetDbHeapFailure(TInt aAllocFailType,TInt aRate);
  1058 
   986 	IMPORT_C static void SetHeapFailure(TInt aAllocFailType,TInt aRate);
  1059 It is strongly recommended to use this class for reading the content of large blobs 
   987 
  1060 because it significantly reduces the amount of RAM that is used when compared to using the 
       
  1061 RSqlColumnReadStream, RSqlStatement::ColumnBinary(L) or RSqlStatement::ColumnText(L) APIs.
       
  1062 
       
  1063 Specifically, it is recommended to use this class for blobs over 2Mb in size.
       
  1064 Indeed, in some circumstances where very large blobs are in use it may be impossible
       
  1065 to read the blob content using the legacy APIs (due to the server's finite RAM capacity), 
       
  1066 and this class may provide the only way to access the data.
       
  1067 
       
  1068 The following code illustrates typical use cases of this class:
       
  1069 
       
  1070 CASE 1 - reading large blob data from the last inserted record.
       
  1071 
       
  1072 @code
       
  1073 RSqlDatabase db;
       
  1074 CleanupClosePushL(db);
       
  1075 <open/create "db" object>;
       
  1076 RSqlBlobReadStream rdStrm;
       
  1077 CleanupClosePushL(rdStrm);
       
  1078 rdStrm.OpenL(db, <table_name>, <column_name>);
       
  1079 HBufC8* buffer = HBufC8::NewLC(KBlockSize);
       
  1080 TPtr8 bufPtr(buffer->Des());
       
  1081 TInt size = rdStrm.SizeL();
       
  1082 while(size)
       
  1083 	{
       
  1084 	TInt bytesToRead = (size >= KBlockSize) ? KBlockSize : size ;
       
  1085 	rdStrm.ReadL(bufPtr, bytesToRead); // read the next block of data		
       
  1086 	<do something with the block of data>
       
  1087 	size =- bytesToRead;
       
  1088 	}
       
  1089 CleanupStack::PopAndDestroy(3); // buffer, rdStrm, db
       
  1090 @endcode
       
  1091 
       
  1092 CASE 2 - reading large blob data from a selection of records.
       
  1093 
       
  1094 @code
       
  1095 RSqlDatabase db;
       
  1096 CleanupClosePushL(db);
       
  1097 <open/create "db" object>;
       
  1098 RSqlStatement stmt;
       
  1099 CleanupClosePushL(stmt);
       
  1100 <prepare "stmt" object to SELECT the ROWIDs of a collection of blob objects>;
       
  1101 TInt rc = 0;
       
  1102 while((rc = stmt.Next()) == KSqlAtRow)
       
  1103 	{
       
  1104 	TInt64 rowid = stmt.ColumnInt64(0);	
       
  1105 	RSqlBlobReadStream rdStrm;
       
  1106 	CleanupClosePushL(rdStrm);
       
  1107 	rdStrm.OpenL(db, <table_name>, <column_name>, rowid);
       
  1108 	
       
  1109 	HBufC8* buffer = HBufC8::NewLC(KBlockSize);
       
  1110 	TPtr8 bufPtr(buffer->Des());
       
  1111 	TInt size = rdStrm.SizeL();
       
  1112 	while(size)
       
  1113 		{
       
  1114 		TInt bytesToRead = (size >= KBlockSize) ? KBlockSize : size ;
       
  1115 		rdStrm.ReadL(bufPtr, bytesToRead); // read the next block of data		
       
  1116 		<do something with the block of data>
       
  1117 		size =- bytesToRead;
       
  1118 		}
       
  1119 	CleanupStack::PopAndDestroy(2); // buffer, rdStrm
       
  1120 	}
       
  1121 CleanupStack::PopAndDestroy(2); // stmt, db
       
  1122 @endcode
       
  1123 
       
  1124 @see RSqlBlobWriteStream
       
  1125 @see RSqlDatabase::LastInsertedRowId()
       
  1126 
       
  1127 @publishedAll
       
  1128 @released
       
  1129 */
       
  1130 class RSqlBlobReadStream : public RReadStream
       
  1131 	{
       
  1132 public:						
       
  1133 	IMPORT_C void OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
       
  1134 						TInt64 aRowId = KSqlLastInsertedRowId, const TDesC& aDbName = KNullDesC);
       
  1135 	IMPORT_C TInt SizeL();
       
  1136 	};
       
  1137 
       
  1138 /**
       
  1139 A direct handle to a blob, used for writing the content of the blob via a streaming interface.
       
  1140 
       
  1141 The target blob is identified using the relevant database connection, table name, 
       
  1142 column name and ROWID of the record to which the blob belongs (also the attached
       
  1143 database name if the blob is contained in an attached database).
       
  1144 
       
  1145 A blob in this context refers to the content of a BLOB or TEXT column, 
       
  1146 and a write handle can be opened on both types of column, except if the
       
  1147 column is indexed, in which case the open call will fail with KSqlErrGeneral.
       
  1148 For TEXT columns it is important to note that no conversions are performed on data 
       
  1149 that is stored using this class - the data is simply stored as a stream of bytes.
       
  1150 
       
  1151 The class derives from RWriteStream and provides all of its streaming methods.
       
  1152 The SizeL() method can be used to check the total size of the blob, in bytes.
       
  1153 Note that this class cannot be used to increase the size of a blob, only to modify 
       
  1154 the existing contents of a blob. An attempt to write beyond the end of a blob will
       
  1155 fail with KErrEof.
       
  1156 
       
  1157 It is strongly recommended to use this class for writing the content of large blobs 
       
  1158 because it significantly reduces the amount of RAM that is used when compared to using 
       
  1159 the RSqlParamWriteStream, RSqlStatement::BindBinary or RSqlStatement::BindText APIs.
       
  1160 
       
  1161 Specifically, it is recommended to use this class for blobs over 2Mb in size.
       
  1162 Indeed, in some circumstances where very large blobs are required it may be impossible
       
  1163 to create a blob or update its content using the legacy APIs (due to the server's finite 
       
  1164 RAM capacity), and this class may provide the only way to achieve this.
       
  1165 
       
  1166 Using this class in combination with zeroblobs it is possible to create and manipulate 
       
  1167 blobs that are gigabytes in size. A zeroblob acts as a place-holder for a blob whose 
       
  1168 content is later written using this class and one can be created using an INSERT 
       
  1169 statement that either contains the SQLite 'zeroblob()' function or on which 
       
  1170 RSqlStatement::BindZeroBlob() has been executed.
       
  1171 Note that a zeroblob should be created in a column after which there are no columns 
       
  1172 that contain anything other than zeroblobs or NULLs, otherwise the zeroblob must be 
       
  1173 allocated in full in RAM.
       
  1174 
       
  1175 When creating a zeroblob it is recommended, where possible, to create the zeroblob and
       
  1176 then write the blob content within the same transaction. Otherwise the zeroblob will 
       
  1177 have to be journalled before being written to.
       
  1178 
       
  1179 It is also strongly recommended to execute calls to WriteL() within a transaction. 
       
  1180 If a leave occurs during a call to WriteL() then the current state of the blob object is
       
  1181 undefined and a ROLLBACK should be executed to return the blob object to its previous state.
       
  1182 Note that in order for a ROLLBACK to execute successfully all open RSqlBlobReadStream 
       
  1183 and RSqlBlobWriteStream handles and all open RSqlStatement objects must be closed 
       
  1184 before the ROLLBACK is executed.
       
  1185 
       
  1186 The following code illustrates typical use cases of this class:
       
  1187 
       
  1188 CASE 1 - creating a 5Mb blob.
       
  1189 
       
  1190 @code
       
  1191 RSqlDatabase db;
       
  1192 CleanupClosePushL(db);
       
  1193 <open/create "db" object>;
       
  1194 CleanupStack::PushL(TCleanupItem(&DoRollback, &db)); // rollback function
       
  1195 TInt err = db.Exec(_L("BEGIN"));
       
  1196 <check err>
       
  1197 err = db.Exec(_L("INSERT INTO table1 VALUES(35, zeroblob(5242880))"));
       
  1198 <check err>
       
  1199 RSqlBlobWriteStream wrStrm;
       
  1200 CleanupClosePushL(wrStrm);
       
  1201 wrStrm.OpenL(db, <table_name>, <column_name>);
       
  1202 TInt size = wrStrm.SizeL();
       
  1203 while(size)
       
  1204 	{
       
  1205 	TInt bytesToWrite = (size >= KBlockSize) ? KBlockSize : size ;
       
  1206 	<fill a buffer 'buf' with this amount of the blob data>
       
  1207 	wrStrm.WriteL(buf); // write the next block of data		
       
  1208 	size =- bytesToWrite;
       
  1209 	}
       
  1210 CleanupStack::PopAndDestroy(&wrStrm);
       
  1211 CleanupStack::Pop(); // TCleanupItem
       
  1212 err = db.Exec(_L("COMMIT")); // blob data committed to disk
       
  1213 <check err>
       
  1214 CleanupStack::PopAndDestroy(&db);
       
  1215 @endcode
       
  1216 
       
  1217 CASE 2 - updating a large blob in the last inserted record.
       
  1218 
       
  1219 @code
       
  1220 RSqlDatabase db;
       
  1221 CleanupClosePushL(db);
       
  1222 <open/create "db" object>;
       
  1223 CleanupStack::PushL(TCleanupItem(&DoRollback, &db)); // rollback function
       
  1224 TInt err = db.Exec(_L("BEGIN"));
       
  1225 <check err>
       
  1226 RSqlBlobWriteStream wrStrm;
       
  1227 CleanupClosePushL(wrStrm);
       
  1228 wrStrm.OpenL(db, <table_name>, <column_name>);
       
  1229 <fill a buffer 'buf' with the changed blob data>
       
  1230 wrStrm.WriteL(buf); // update the blob
       
  1231 CleanupStack::PopAndDestroy(&wrStrm);
       
  1232 CleanupStack::Pop(); // TCleanupItem
       
  1233 err = db.Exec(_L("COMMIT")); // blob data committed to disk
       
  1234 <check err>
       
  1235 CleanupStack::PopAndDestroy(&db);
       
  1236 @endcode
       
  1237 
       
  1238 @see RSqlBlobReadStream
       
  1239 @see RSqlDatabase::LastInsertedRowId()
       
  1240 @see RSqlStatement::BindZeroBlob()
       
  1241 
       
  1242 @publishedAll
       
  1243 @released
       
  1244 */
       
  1245 class RSqlBlobWriteStream : public RWriteStream
       
  1246 	{
       
  1247 public:
       
  1248 	IMPORT_C void OpenL(RSqlDatabase& aDb, const TDesC& aTableName, const TDesC& aColumnName, 
       
  1249 						TInt64 aRowId = KSqlLastInsertedRowId, const TDesC& aDbName = KNullDesC);
       
  1250 	IMPORT_C TInt SizeL();
       
  1251 	};
       
  1252 
       
  1253 /**
       
  1254 Utility class that provides methods for reading and writing the entire content of 
       
  1255 a blob in a single call.
       
  1256 
       
  1257 The target blob is identified using the relevant database connection, table name, 
       
  1258 column name and ROWID of the record to which the blob belongs (also the attached
       
  1259 database name if the blob is contained in an attached database).
       
  1260 
       
  1261 The behaviour of the RSqlBlobReadStream class and the recommendations for using
       
  1262 it exist for the Get() and GetLC() methods of this class. Similarly, the behaviour 
       
  1263 of the RSqlBlobWriteStream class and the recommendations for using it exist for the 
       
  1264 SetL() method of this class.
       
  1265 
       
  1266 In particular, it is strongly recommended to use this class or the RSqlBlobReadStream
       
  1267 and RSqlBlobWriteStream classes for reading and writing the content of large blobs 
       
  1268 because it significantly reduces the amount of RAM that is used when compared to using 
       
  1269 the legacy streaming and RSqlStatement APIs.
       
  1270 
       
  1271 Specifically, it is recommended to use this class for blobs over 2Mb in size.
       
  1272 Indeed, in some circumstances where very large blobs are in use it may be impossible
       
  1273 to read or write to a blob using the legacy APIs (due to the server's finite 
       
  1274 RAM capacity), and this class or the RSqlBlobReadStream and RSqlBlobWriteStream classes 
       
  1275 may provide the only way to achieve this.
       
  1276 
       
  1277 It is strongly recommended to execute calls to the SetL() method within a transaction. 
       
  1278 If a leave occurs during a call to SetL() then the current state of the blob object is 
       
  1279 undefined and a ROLLBACK should be executed to return the blob object to its previous state.
       
  1280 Note that in order for a ROLLBACK to execute successfully all open RSqlBlobReadStream 
       
  1281 and RSqlBlobWriteStream handles and all open RSqlStatement objects must be closed 
       
  1282 before the ROLLBACK is executed.
       
  1283 
       
  1284 When using SetL() to update the content of a zeroblob it is recommended, where possible, 
       
  1285 to create the zeroblob and then call SetL() within the same transaction. 
       
  1286 Otherwise the zeroblob will have to be journalled before being written to.
       
  1287 
       
  1288 The following code illustrates typical use cases of this class:
       
  1289 
       
  1290 CASE 1 - retrieving the entire content of a large blob.
       
  1291 
       
  1292 @code
       
  1293 RSqlDatabase db;
       
  1294 CleanupClosePushL(db);
       
  1295 <open/create "db" object>;
       
  1296 HBufC8* wholeBlob = TSqlBlob::GetLC(db, <table_name>, <column_name>, <rowid>);
       
  1297 <do something with the blob data>
       
  1298 CleanupStack::PopAndDestroy(2); // wholeBlob, db
       
  1299 @endcode
       
  1300 
       
  1301 
       
  1302 CASE 2 - creating a 4Mb blob.
       
  1303 
       
  1304 @code
       
  1305 RSqlDatabase db;
       
  1306 CleanupClosePushL(db);
       
  1307 <open/create "db" object>;
       
  1308 CleanupStack::PushL(TCleanupItem(&DoRollback, &db)); // rollback function
       
  1309 TInt err = db.Exec(_L("BEGIN"));
       
  1310 <check err>
       
  1311 err = db.Exec(_L("INSERT INTO table1 VALUES(99, zeroblob(4194304))"));
       
  1312 <check err>
       
  1313 <fill a buffer 'buf' with 4Mb of blob data>
       
  1314 TSqlBlob::SetL(db, <table_name>, <column_name>, buf);
       
  1315 CleanupStack::Pop(); // TCleanupItem
       
  1316 err = db.Exec(_L("COMMIT")); // blob data committed to disk
       
  1317 <check err>
       
  1318 CleanupStack::PopAndDestroy(&db);
       
  1319 @endcode
       
  1320 
       
  1321 @see RSqlBlobReadStream
       
  1322 @see RSqlBlobWriteStream
       
  1323 @see RSqlDatabase::LastInsertedRowId()
       
  1324 @see RSqlStatement::BindZeroBlob()
       
  1325 
       
  1326 @publishedAll
       
  1327 @released
       
  1328 */
       
  1329 class TSqlBlob
       
  1330 	{
       
  1331 public:					  		  	  
       
  1332 	IMPORT_C static HBufC8* GetLC(RSqlDatabase& aDb, 	
       
  1333 					     		  const TDesC& aTableName, 
       
  1334 					     		  const TDesC& aColumnName, 	
       
  1335 					     		  TInt64 aRowId = KSqlLastInsertedRowId,
       
  1336 					     		  const TDesC& aDbName = KNullDesC);
       
  1337 								  		  	  
       
  1338 	IMPORT_C static TInt Get(RSqlDatabase& aDb, 	
       
  1339 					 		 const TDesC& aTableName, 
       
  1340 					 		 const TDesC& aColumnName, 	
       
  1341 					 		 TDes8& aBuffer,
       
  1342 					 		 TInt64 aRowId = KSqlLastInsertedRowId,
       
  1343 					 		 const TDesC& aDbName = KNullDesC);			 		 
       
  1344 
       
  1345 	IMPORT_C static void SetL(RSqlDatabase& aDb, 	
       
  1346 					  		  const TDesC& aTableName, 
       
  1347 					  		  const TDesC& aColumnName,
       
  1348 					  		  const TDesC8& aData,	
       
  1349 					  		  TInt64 aRowId = KSqlLastInsertedRowId,
       
  1350 					  		  const TDesC& aDbName = KNullDesC);				  
   988 	};
  1351 	};
   989 
  1352 
   990 /**
  1353 /**
   991 Defines a set of categories for the values returned by the SQL API.
  1354 Defines a set of categories for the values returned by the SQL API.
   992 
  1355