persistentstorage/sql/SRC/Server/SqlSrvSession.h
changeset 0 08ec8eefde2f
child 10 fa9941cf3867
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 __SQLSRVSESSION_H__
       
    17 #define __SQLSRVSESSION_H__
       
    18 
       
    19 #include <e32base.h>				//CSession2
       
    20 #include "IPCStream.h"				//HIpcStream
       
    21 #include "SqlUtil.h"				//TSqlSrvFunction
       
    22 #include "SqlSrvObjContainer.h"		//RDbObjContainer
       
    23 #include "SqlSrvDatabase.h"			//CSqlSrvDatabase
       
    24 #include "SqlSrvResourceProfiler.h"
       
    25 
       
    26 //Forward declarations
       
    27 class CSqlServer;
       
    28 class CSqlSrvStatement;
       
    29 class MStreamBuf;
       
    30 class RMessage2;
       
    31 class CSqlSecurityPolicy;
       
    32 
       
    33 /**
       
    34 SQL server side session class.
       
    35 
       
    36 All client side requests come through a CSqlSrvSession instance which unpacks the client data,
       
    37 performs the requested operation invoking the appropriate server side objects and functions and
       
    38 packs and returns back to the client the results from the performed operation.
       
    39 
       
    40 CSqlSrvSession class owns the following set of data:
       
    41 - A CSqlSrvDatabase instance - one per session;
       
    42 - A RDbObjContainer instance - container for statement handles (CSqlSrvStatement class);
       
    43 - A RDbObjContainer instance - container for IPC stream hadles (large data block transfer operations)
       
    44                                (HIpcStream class);
       
    45                   
       
    46 CSqlSrvSession instances shall never be created via a direct call of CSqlSrvSession::NewL().
       
    47 It is always the server, which creates a new session instance as a responce to the creation of a client side
       
    48 session instance (CSqlServer::NewSessionL() function).
       
    49 
       
    50 @see CSqlSrvDatabase
       
    51 @see CSqlSrvStatement
       
    52 @see RDbObjContainer
       
    53 @see HIpcStream
       
    54 @see CSqlServer
       
    55 @see CSqlServer::NewSessionL()
       
    56 @see CSession2
       
    57 
       
    58 @internalComponent
       
    59 */
       
    60 NONSHARABLE_CLASS(CSqlSrvSession) : public CSession2
       
    61 	{
       
    62 public:
       
    63 	static CSqlSrvSession* NewL();
       
    64 	virtual ~CSqlSrvSession();
       
    65 	inline CSqlServer& Server();
       
    66 	
       
    67 private:	
       
    68 	inline CSqlSrvSession();
       
    69 	inline void ConstructL();
       
    70 	//CSession2::ServiceL() implementation and overriden CSession2::ServiceError().
       
    71 	virtual void ServiceL(const RMessage2& aMessage);
       
    72 	virtual void ServiceError(const RMessage2& aMessage, TInt aError);
       
    73 	//Profiler operations
       
    74 	void ProfilerQueryL(const RMessage2& aMessage);
       
    75 	//Database operations
       
    76 	void DbCreateObjectL(const RMessage2& aMessage, TSqlSrvFunction aFunction);
       
    77 	void DbCreateObjectFromHandleL(const RMessage2& aMessage);
       
    78 	void DbAttachL(const RMessage2& aMessage);
       
    79 	void DbAttachFromHandleL(const RMessage2& aMessage);
       
    80 	void DbDetachL(const RMessage2& aMessage);
       
    81 	inline void DbDestroyObject();
       
    82 	void DbCopyFileL(const RMessage2& aMessage);
       
    83 	void DbDeleteFileL(const RMessage2& aMessage);
       
    84 	TInt DbLastErrorMessageL(const RMessage2& aMessage);
       
    85 	void DbLastInsertedRowIdL(const RMessage2& aMessage);
       
    86 	inline TInt DbExecSql8L(const RMessage2& aMessage);
       
    87 	inline TInt DbExecSql16L(const RMessage2& aMessage);
       
    88 	inline void DbSetIsolationLevelL(const RMessage2& aMessage);
       
    89 	TInt DbGetSecurityPolicyL(const RMessage2& aMessage);
       
    90 	TInt DbScalarFullSelectL(const RMessage2& aMessage, TBool aIsText16);
       
    91 	TInt DbBlobSourceL(const RMessage2& aMessage);
       
    92 	TBool DbInTransaction(const RMessage2& aMessage);
       
    93 	TInt DbSizeL(const RMessage2& aMessage);
       
    94 	void DbSize2L(const RMessage2& aMessage);
       
    95 	TInt DbCompactL(const RMessage2& aMessage);
       
    96 	void DbReserveDriveSpaceL();
       
    97 	void DbFreeReservedSpace();
       
    98 	void DbGetReserveAccessL();
       
    99 	void DbReleaseReserveAccess();
       
   100 	//Statement operations
       
   101 	TInt StmtPrepareL(const RMessage2& aMessage, TBool aIsText16);
       
   102 	TInt StmtExecL(const RMessage2& aMessage, TInt aStmtHandle, TSqlSrvFunction aFunction);
       
   103 	TInt StmtNextL(const RMessage2& aMessage, TInt aStmtHandle, TSqlSrvFunction aFunction);
       
   104 	TInt StmtNamesL(const RMessage2& aMessage, TInt aStmtHandle, TSqlSrvFunction aFunction);
       
   105 	TInt StmtColumnSourceL(const RMessage2& aMessage, TInt aStmtHandle);
       
   106 	TInt StmtParamSinkL(const RMessage2& aMessage, TInt aStmtHandle, TSqlSrvFunction aFunction);
       
   107 	void StmtGetBufFlatL(const RMessage2& aMessage, TInt aStmtHandle);
       
   108 	void StmtColumnValueL(const RMessage2& aMessage, TInt aStmtHandle);
       
   109 	void DoStmtBindL(const RMessage2& aMessage, CSqlSrvStatement& aStmt);
       
   110 	void StmtDeclColumnTypesL(const RMessage2& aMessage, TInt aStmtHandle);
       
   111 	//Helper methods
       
   112 	TInt NewOutputStreamL(const RMessage2& aMessage, MStreamBuf* aStreamBuf);
       
   113 	TDes8& ReadString8ZL(const RMessage2& aMessage, TInt aArgNum, TInt aByteLen);
       
   114 	TDes16& ReadString16ZL(const RMessage2& aMessage, TInt aArgNum, TInt aCharLen);
       
   115 	TDes16& ReadString16L(const RMessage2& aMessage, TInt aArgNum, TInt aCharLen);
       
   116 	CSqlSecurityPolicy* InternalizeSecurityPolicyL(const RMessage2& aMessage);
       
   117 	virtual TInt CountResources();
       
   118 	void Extract(const RMessage2& aMessage, TSqlSrvFunction& aFunction, TInt& aHandle);
       
   119 	TInt GetColumnValueL(const RMessage2& aMessage, CSqlSrvStatement& aStmt, TSqlColumnType aColType);
       
   120 	void ExtractNameL(RDesReadStream& aStrm, TDes8& aNameOut, const TDesC& aEmptyNameSubstitute = KNullDesC);
       
   121 	//Resource allocation testing related
       
   122 	inline TBool ActivateDbTestMode(TInt aHeapFailureMode, TInt aFailedAllocNumber);
       
   123 	inline void StopDbTestMode();
       
   124 	inline void DbResourceMark();
       
   125 	inline void DbResourceEnd(const RMessage2& aMessage);
       
   126 	inline void DbSetAllocFail(TInt aHeapFailureMode, TInt aFailedAllocNumber);
       
   127 	inline void DbSetDelayedAllocFail();
       
   128 private:
       
   129 	CSqlSrvDatabase*					iDatabase;				//The database object (one per session)
       
   130 	RDbObjContainer<CSqlSrvStatement>	iStatements;			//Container for SQL statement handles
       
   131 	RDbObjContainer<HIpcStream>			iIpcStreams;			//Container for IPC stream hansdles
       
   132 	TInt								iDbResourceTestMode;	//Non-zero if this session is in test mode (memory leaks simulation/detection)
       
   133 	TInt								iFailedAllocNumber;		//The failing allocation number - If iDbResourceTestMode is OR-ed with 0x1000
       
   134 	TBool								iDriveSpaceReserved;	//True if this session reserved drive space
       
   135 	TBool								iDriveSpaceInUse;		//True if the client has been given an access to the reserved drive space
       
   136 	TDriveNumber 						iDrive;					//the drive number, where the database file is
       
   137 #ifdef _SQLPROFILER
       
   138 	TUint                               iIpcCounter;                                   
       
   139     TSqlSrvIpcTraceData                 iIpcTraceData[KIpcTraceTypeCount];
       
   140 #endif
       
   141 	};
       
   142 
       
   143 #include "SqlSrvSession.inl"
       
   144 
       
   145 #endif//__SQLSRVSESSION_H__