persistentstorage/sql/SRC/Client/SqlStmtSession.h
changeset 0 08ec8eefde2f
child 11 211563e4b919
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __SQLSTMTSESSION_H__
       
    17 #define __SQLSTMTSESSION_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 #include "SqlDbSession.h"		//RSqlDbSession
       
    21 #include "SqlBufFlat.h"			//RSqlBufFlat
       
    22 #include "IPCBuf.h"				//HIpcBuf
       
    23 
       
    24 /**
       
    25 RSqlStatementSession class is used for "prepare once execute many times" supplied to PrepareL() SQL 
       
    26 statement.
       
    27 RSqlStatementSession::PrepareL() must be called for preparing the SQL statement.
       
    28 If the SQL statement contains parameters, Bind() must be called before calling Next() or Exec() 
       
    29 to bind the parameter values.
       
    30 RSqlStatementSession class shall not be used for executing a set of SQL statements, separated with ";".
       
    31 PrepareL() will report this as a KErrArgument error.
       
    32 
       
    33 RSqlStatementSession class hides all details about the communication with the database server.
       
    34 No database specific header files should be seen or used outside the session class.
       
    35 
       
    36 Usage patterns:
       
    37 
       
    38 1) SQL statement which does not return a record set.
       
    39 
       
    40 @code
       
    41 	RSqlStatementSession sess;
       
    42 	TInt err = sess.Prepare(...);
       
    43 	...
       
    44 	RSqlBufFlat paramBuf;
       
    45 	<Initialize "paramBuf" object>;
       
    46 begin:
       
    47 	err = sess.Bind(paramBuf);
       
    48 	err = sess.Exec();
       
    49 	err = sess.Reset();
       
    50 	<Now a new set of parameter values can be prepared and the statement can be executed again - from the "begin" label>;
       
    51 	
       
    52 	sess.Close();
       
    53 @endcode
       
    54 
       
    55 2) SQL statement which returns a record set.
       
    56 
       
    57 @code
       
    58 	RSqlStatementSession sess;
       
    59 	TInt err = sess.Prepare(...);
       
    60 	...
       
    61 	RSqlBufFlat paramBuf;
       
    62 	<Initialize "paramBuf" object>;
       
    63 	RSqlBufFlat columnBuf;
       
    64 	<Initialize "columnBuf" object. The element count must match the columns count>;
       
    65 begin:
       
    66 	err = sess.Bind(paramBuf);
       
    67 	while(sess.Next(columnBuf) == KSqlAtRow)
       
    68 		{
       
    69 		<process the record data - "columnBuf" set>;
       
    70 		}
       
    71 	err = sess.Reset();
       
    72 	<Now a new set of parameter values can be prepared and the statement can be executed again - from the "begin" label>;
       
    73 	
       
    74 	sess.Close();
       
    75 @endcode
       
    76 
       
    77 @internalComponent
       
    78 */
       
    79 NONSHARABLE_CLASS(RSqlStatementSession)
       
    80 	{
       
    81 public:	
       
    82 	inline RSqlStatementSession();
       
    83 	inline TInt Prepare(RSqlDbSession& aDbSession, const TDesC& aSqlStmt, TInt& aColumnCount, TInt& aParamCount);
       
    84 	inline TInt Prepare(RSqlDbSession& aDbSession, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount);
       
    85 	void Close();
       
    86 	
       
    87 	inline TInt Reset();
       
    88 	inline TInt Exec();
       
    89 	inline void Exec(TRequestStatus& aStatus);
       
    90 	inline TInt BindExec(const RSqlBufFlat& aParamBuf);
       
    91 	inline void BindExec(const RSqlBufFlat& aParamBuf, TRequestStatus& aStatus);
       
    92 	inline TInt Next(RSqlBufFlat& aColumnBuf);
       
    93 	TInt BindNext(const RSqlBufFlat& aParamBuf, RSqlBufFlat& aColumnBuf);
       
    94 	TInt GetNames(TSqlSrvFunction aFunction, RSqlBufFlat& aNameBuf);
       
    95 	inline TInt ReadColumnValue(TInt aColumnIndex, TDes8& aBuf);
       
    96 	
       
    97 	inline MStreamBuf* ColumnSourceL(TInt aColumnIndex);
       
    98 	inline MStreamBuf* ParamSinkL(TSqlSrvFunction aFunction, TInt aParamIndex);
       
    99 
       
   100 	HBufC* GetDeclColumnTypesL(TInt aColumnCount);
       
   101 		
       
   102 private:
       
   103 	TInt DoBindNext(TSqlSrvFunction aFunction, TIpcArgs& aIpcArgs, RSqlBufFlat& aColumnBuf);
       
   104 	TInt Retry(RSqlBufFlat& aBufFlat, TInt aSize, TSqlBufFlatType aWhat);
       
   105 	inline RSqlDbSession& DbSession() const;
       
   106 
       
   107 private:
       
   108 	TInt			iHandle;
       
   109 	RSqlDbSession*	iDbSession;
       
   110 
       
   111 	};
       
   112 
       
   113 #include "SqlStmtSession.inl"
       
   114 
       
   115 #endif//__SQLSTMTSESSION_H__