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