os/persistentdata/persistentstorage/sql/SRC/Client/SqlDbSession.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 __SQLDBSESSION_H__
    17 #define __SQLDBSESSION_H__
    18 
    19 #include <sqldb.h>			//RSqlDatabase::TIsolationLevel
    20 #include "SqlUtil.h"		//TSqlSrvFunction
    21 
    22 //Forward declarations
    23 struct sqlite3;
    24 class RSqlStatementSession;
    25 class TSqlResourceTestData;
    26 class CSqlSecurityPolicy;
    27 class RSqlBufFlat;
    28 class TSqlFhCmdFunctor;
    29 
    30 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    31 //////////////////////                RSqlDbSession           /////////////////////////////////////////////////
    32 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    33 
    34 /**
    35 RSqlDbSession class is used for establishing a connection with the database server.
    36 It can be used also for: 
    37  - executing SQL statements or a set of SQL statements, separated with ";";
    38  - attaching/detaching databases;
    39  - copying databases;
    40  - deleting databases;
    41  - retrieving last error messages;
    42  
    43 @internalComponent
    44 */
    45 NONSHARABLE_CLASS(RSqlDbSession) : public RSessionBase
    46 	{
    47 	//RSqlDbSession class hides all details about the communication with the database server.
    48 	//No database specific header files should be seen or used outside the session class.
    49 	
    50 	friend class RSqlStatementSession;
    51 	friend class TSqlResourceTestData;
    52 	
    53 public:	
    54 	inline RSqlDbSession();
    55 	TInt Connect(TSqlSrvFunction aFunction, const TDesC& aDbFileName, const TDesC8& aSecurityPolicyData, const TDesC8* aConfig);
    56 	TInt Attach(const TDesC& aDbFileName, const TDesC& aDbName);
    57 	inline TInt Detach(const TDesC& aDbName);
    58 	static TInt CopyDatabase(const TDesC& aSrcDbFileName, const TDesC& aDestDbFileName);
    59 	static TInt DeleteDatabase(const TDesC& aDbFileName);
    60 	TPtrC LastErrorMessage();
    61 	TInt64 LastInsertedRowId(); 
    62 	inline TInt Exec(const TDesC& aSqlStmt);
    63 	inline TInt Exec(const TDesC8& aSqlStmt);
    64 	inline void Exec(const TDesC& aSqlStmt, TRequestStatus& aStatus);
    65 	inline void Exec(const TDesC8& aSqlStmt, TRequestStatus& aStatus);
    66 	inline TInt SetIsolationLevel(RSqlDatabase::TIsolationLevel aIsolationLevel);
    67 	TInt GetSecurityPolicy(RSqlBufFlat& aSecurityPolicyBuf);
    68 	inline TInt ExecScalarFullSelect(const TDesC& aSqlStmt, TSqlColumnType aType, TDes8& aRes);
    69 	inline TInt ExecScalarFullSelect(const TDesC8& aSqlStmt, TSqlColumnType aType, TDes8& aRes);
    70 	void Close();
    71 
    72 	inline TInt SendReceive(TInt aFunction);
    73 	inline void SendReceive(TInt aFunction, TRequestStatus& aStatus);
    74 	inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs);
    75 	inline void SendReceive(TInt aFunction,const TIpcArgs& aArgs, TRequestStatus& aStatus);
    76 
    77 private:
    78 	enum TDbfAction {EDbfCreate, EDbfOpen};
    79 	TInt DoCreateSession();
    80 	TInt InitResourceTestData();
    81 	TInt CreateAndSendFileHandle(TSqlFhCmdFunctor& aFhCmdSender, TDbfAction aDbfAction);
    82 	TInt DoConnect(TSqlSrvFunction aFunction, const TDesC& aDbFileName, const TDesC8& aSecurityPolicyData, const TDesC8* aConfig);
    83 	
    84 private:
    85 	HBufC*	iLastErrorMessage;
    86 
    87 	};
    88 
    89 #include "SqlDbSession.inl"
    90 
    91 #endif //__SQLDBSESSION_H__