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.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __SQLDBSESSION_H__
sl@0
    17
#define __SQLDBSESSION_H__
sl@0
    18
sl@0
    19
#include <sqldb.h>			//RSqlDatabase::TIsolationLevel
sl@0
    20
#include "SqlUtil.h"		//TSqlSrvFunction
sl@0
    21
sl@0
    22
//Forward declarations
sl@0
    23
struct sqlite3;
sl@0
    24
class RSqlStatementSession;
sl@0
    25
class TSqlResourceTestData;
sl@0
    26
class CSqlSecurityPolicy;
sl@0
    27
class RSqlBufFlat;
sl@0
    28
class TSqlFhCmdFunctor;
sl@0
    29
sl@0
    30
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
    31
//////////////////////                RSqlDbSession           /////////////////////////////////////////////////
sl@0
    32
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
    33
sl@0
    34
/**
sl@0
    35
RSqlDbSession class is used for establishing a connection with the database server.
sl@0
    36
It can be used also for: 
sl@0
    37
 - executing SQL statements or a set of SQL statements, separated with ";";
sl@0
    38
 - attaching/detaching databases;
sl@0
    39
 - copying databases;
sl@0
    40
 - deleting databases;
sl@0
    41
 - retrieving last error messages;
sl@0
    42
 
sl@0
    43
@internalComponent
sl@0
    44
*/
sl@0
    45
NONSHARABLE_CLASS(RSqlDbSession) : public RSessionBase
sl@0
    46
	{
sl@0
    47
	//RSqlDbSession class hides all details about the communication with the database server.
sl@0
    48
	//No database specific header files should be seen or used outside the session class.
sl@0
    49
	
sl@0
    50
	friend class RSqlStatementSession;
sl@0
    51
	friend class TSqlResourceTestData;
sl@0
    52
	
sl@0
    53
public:	
sl@0
    54
	inline RSqlDbSession();
sl@0
    55
	TInt Connect(TSqlSrvFunction aFunction, const TDesC& aDbFileName, const TDesC8& aSecurityPolicyData, const TDesC8* aConfig);
sl@0
    56
	TInt Attach(const TDesC& aDbFileName, const TDesC& aDbName);
sl@0
    57
	inline TInt Detach(const TDesC& aDbName);
sl@0
    58
	static TInt CopyDatabase(const TDesC& aSrcDbFileName, const TDesC& aDestDbFileName);
sl@0
    59
	static TInt DeleteDatabase(const TDesC& aDbFileName);
sl@0
    60
	TPtrC LastErrorMessage();
sl@0
    61
	TInt64 LastInsertedRowId(); 
sl@0
    62
	inline TInt Exec(const TDesC& aSqlStmt);
sl@0
    63
	inline TInt Exec(const TDesC8& aSqlStmt);
sl@0
    64
	inline void Exec(const TDesC& aSqlStmt, TRequestStatus& aStatus);
sl@0
    65
	inline void Exec(const TDesC8& aSqlStmt, TRequestStatus& aStatus);
sl@0
    66
	inline TInt SetIsolationLevel(RSqlDatabase::TIsolationLevel aIsolationLevel);
sl@0
    67
	TInt GetSecurityPolicy(RSqlBufFlat& aSecurityPolicyBuf);
sl@0
    68
	inline TInt ExecScalarFullSelect(const TDesC& aSqlStmt, TSqlColumnType aType, TDes8& aRes);
sl@0
    69
	inline TInt ExecScalarFullSelect(const TDesC8& aSqlStmt, TSqlColumnType aType, TDes8& aRes);
sl@0
    70
	void Close();
sl@0
    71
sl@0
    72
	inline TInt SendReceive(TInt aFunction);
sl@0
    73
	inline void SendReceive(TInt aFunction, TRequestStatus& aStatus);
sl@0
    74
	inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs);
sl@0
    75
	inline void SendReceive(TInt aFunction,const TIpcArgs& aArgs, TRequestStatus& aStatus);
sl@0
    76
sl@0
    77
private:
sl@0
    78
	enum TDbfAction {EDbfCreate, EDbfOpen};
sl@0
    79
	TInt DoCreateSession();
sl@0
    80
	TInt InitResourceTestData();
sl@0
    81
	TInt CreateAndSendFileHandle(TSqlFhCmdFunctor& aFhCmdSender, TDbfAction aDbfAction);
sl@0
    82
	TInt DoConnect(TSqlSrvFunction aFunction, const TDesC& aDbFileName, const TDesC8& aSecurityPolicyData, const TDesC8* aConfig);
sl@0
    83
	
sl@0
    84
private:
sl@0
    85
	HBufC*	iLastErrorMessage;
sl@0
    86
sl@0
    87
	};
sl@0
    88
sl@0
    89
#include "SqlDbSession.inl"
sl@0
    90
sl@0
    91
#endif //__SQLDBSESSION_H__