sl@0: // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings" sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __SQLSTMTSESSION_H__ sl@0: #define __SQLSTMTSESSION_H__ sl@0: sl@0: #include sl@0: #include "SqlDbSession.h" //RSqlDbSession sl@0: #include "SqlBufFlat.h" //RSqlBufFlat sl@0: #include "IPCBuf.h" //HIpcBuf sl@0: sl@0: /** sl@0: RSqlStatementSession class is used for "prepare once execute many times" supplied to PrepareL() SQL sl@0: statement. sl@0: RSqlStatementSession::PrepareL() must be called for preparing the SQL statement. sl@0: If the SQL statement contains parameters, Bind() must be called before calling Next() or Exec() sl@0: to bind the parameter values. sl@0: RSqlStatementSession class shall not be used for executing a set of SQL statements, separated with ";". sl@0: PrepareL() will report this as a KErrArgument error. sl@0: sl@0: RSqlStatementSession class hides all details about the communication with the database server. sl@0: No database specific header files should be seen or used outside the session class. sl@0: sl@0: Usage patterns: sl@0: sl@0: 1) SQL statement which does not return a record set. sl@0: sl@0: @code sl@0: RSqlStatementSession sess; sl@0: TInt err = sess.Prepare(...); sl@0: ... sl@0: RSqlBufFlat paramBuf; sl@0: ; sl@0: begin: sl@0: err = sess.Bind(paramBuf); sl@0: err = sess.Exec(); sl@0: err = sess.Reset(); sl@0: ; sl@0: sl@0: sess.Close(); sl@0: @endcode sl@0: sl@0: 2) SQL statement which returns a record set. sl@0: sl@0: @code sl@0: RSqlStatementSession sess; sl@0: TInt err = sess.Prepare(...); sl@0: ... sl@0: RSqlBufFlat paramBuf; sl@0: ; sl@0: RSqlBufFlat columnBuf; sl@0: ; sl@0: begin: sl@0: err = sess.Bind(paramBuf); sl@0: while(sess.Next(columnBuf) == KSqlAtRow) sl@0: { sl@0: ; sl@0: } sl@0: err = sess.Reset(); sl@0: ; sl@0: sl@0: sess.Close(); sl@0: @endcode sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(RSqlStatementSession) sl@0: { sl@0: public: sl@0: inline RSqlStatementSession(); sl@0: TInt Prepare(RSqlDbSession& aDbSession, const TDesC& aSqlStmt, TInt& aColumnCount, TInt& aParamCount); sl@0: TInt Prepare(RSqlDbSession& aDbSession, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount); sl@0: void Close(); sl@0: sl@0: inline TInt Reset(); sl@0: inline TInt Exec(); sl@0: inline void Exec(TRequestStatus& aStatus); sl@0: inline TInt BindExec(const RSqlBufFlat& aParamBuf); sl@0: inline void BindExec(const RSqlBufFlat& aParamBuf, TRequestStatus& aStatus); sl@0: inline TInt Next(RSqlBufFlat& aColumnBuf); sl@0: TInt BindNext(const RSqlBufFlat& aParamBuf, RSqlBufFlat& aColumnBuf); sl@0: TInt GetNames(TSqlSrvFunction aFunction, RSqlBufFlat& aNameBuf); sl@0: inline TInt ReadColumnValue(TInt aColumnIndex, TDes8& aBuf); sl@0: sl@0: inline MStreamBuf* ColumnSourceL(TInt aColumnIndex); sl@0: inline MStreamBuf* ParamSinkL(TSqlSrvFunction aFunction, TInt aParamIndex); sl@0: sl@0: TInt GetDeclColumnTypes(RSqlBufFlat& aDeclColumnTypeBuf); sl@0: sl@0: private: sl@0: TInt DoBindNext(TSqlSrvFunction aFunction, TIpcArgs& aIpcArgs, RSqlBufFlat& aColumnBuf); sl@0: TInt Retry(RSqlBufFlat& aBufFlat, TInt aSize, TSqlBufFlatType aWhat); sl@0: inline RSqlDbSession& DbSession() const; sl@0: sl@0: private: sl@0: TInt iHandle; sl@0: RSqlDbSession* iDbSession; sl@0: sl@0: }; sl@0: sl@0: #include "SqlStmtSession.inl" sl@0: sl@0: #endif//__SQLSTMTSESSION_H__