sl@0
|
1 |
// Copyright (c) 2005-2010 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 |
// NTT DOCOMO, INC - Fix for Bug 1915 "SQL server panics when using long column type strings"
|
sl@0
|
13 |
//
|
sl@0
|
14 |
// Description:
|
sl@0
|
15 |
//
|
sl@0
|
16 |
|
sl@0
|
17 |
#ifndef __SQLSTMTSESSION_H__
|
sl@0
|
18 |
#define __SQLSTMTSESSION_H__
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <e32std.h>
|
sl@0
|
21 |
#include "SqlDbSession.h" //RSqlDbSession
|
sl@0
|
22 |
#include "SqlBufFlat.h" //RSqlBufFlat
|
sl@0
|
23 |
#include "IPCBuf.h" //HIpcBuf
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
RSqlStatementSession class is used for "prepare once execute many times" supplied to PrepareL() SQL
|
sl@0
|
27 |
statement.
|
sl@0
|
28 |
RSqlStatementSession::PrepareL() must be called for preparing the SQL statement.
|
sl@0
|
29 |
If the SQL statement contains parameters, Bind() must be called before calling Next() or Exec()
|
sl@0
|
30 |
to bind the parameter values.
|
sl@0
|
31 |
RSqlStatementSession class shall not be used for executing a set of SQL statements, separated with ";".
|
sl@0
|
32 |
PrepareL() will report this as a KErrArgument error.
|
sl@0
|
33 |
|
sl@0
|
34 |
RSqlStatementSession class hides all details about the communication with the database server.
|
sl@0
|
35 |
No database specific header files should be seen or used outside the session class.
|
sl@0
|
36 |
|
sl@0
|
37 |
Usage patterns:
|
sl@0
|
38 |
|
sl@0
|
39 |
1) SQL statement which does not return a record set.
|
sl@0
|
40 |
|
sl@0
|
41 |
@code
|
sl@0
|
42 |
RSqlStatementSession sess;
|
sl@0
|
43 |
TInt err = sess.Prepare(...);
|
sl@0
|
44 |
...
|
sl@0
|
45 |
RSqlBufFlat paramBuf;
|
sl@0
|
46 |
<Initialize "paramBuf" object>;
|
sl@0
|
47 |
begin:
|
sl@0
|
48 |
err = sess.Bind(paramBuf);
|
sl@0
|
49 |
err = sess.Exec();
|
sl@0
|
50 |
err = sess.Reset();
|
sl@0
|
51 |
<Now a new set of parameter values can be prepared and the statement can be executed again - from the "begin" label>;
|
sl@0
|
52 |
|
sl@0
|
53 |
sess.Close();
|
sl@0
|
54 |
@endcode
|
sl@0
|
55 |
|
sl@0
|
56 |
2) SQL statement which returns a record set.
|
sl@0
|
57 |
|
sl@0
|
58 |
@code
|
sl@0
|
59 |
RSqlStatementSession sess;
|
sl@0
|
60 |
TInt err = sess.Prepare(...);
|
sl@0
|
61 |
...
|
sl@0
|
62 |
RSqlBufFlat paramBuf;
|
sl@0
|
63 |
<Initialize "paramBuf" object>;
|
sl@0
|
64 |
RSqlBufFlat columnBuf;
|
sl@0
|
65 |
<Initialize "columnBuf" object. The element count must match the columns count>;
|
sl@0
|
66 |
begin:
|
sl@0
|
67 |
err = sess.Bind(paramBuf);
|
sl@0
|
68 |
while(sess.Next(columnBuf) == KSqlAtRow)
|
sl@0
|
69 |
{
|
sl@0
|
70 |
<process the record data - "columnBuf" set>;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
err = sess.Reset();
|
sl@0
|
73 |
<Now a new set of parameter values can be prepared and the statement can be executed again - from the "begin" label>;
|
sl@0
|
74 |
|
sl@0
|
75 |
sess.Close();
|
sl@0
|
76 |
@endcode
|
sl@0
|
77 |
|
sl@0
|
78 |
@internalComponent
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
NONSHARABLE_CLASS(RSqlStatementSession)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
public:
|
sl@0
|
83 |
inline RSqlStatementSession();
|
sl@0
|
84 |
TInt Prepare(RSqlDbSession& aDbSession, const TDesC& aSqlStmt, TInt& aColumnCount, TInt& aParamCount);
|
sl@0
|
85 |
TInt Prepare(RSqlDbSession& aDbSession, const TDesC8& aSqlStmt, TInt& aColumnCount, TInt& aParamCount);
|
sl@0
|
86 |
void Close();
|
sl@0
|
87 |
|
sl@0
|
88 |
inline TInt Reset();
|
sl@0
|
89 |
inline TInt Exec();
|
sl@0
|
90 |
inline void Exec(TRequestStatus& aStatus);
|
sl@0
|
91 |
inline TInt BindExec(const RSqlBufFlat& aParamBuf);
|
sl@0
|
92 |
inline void BindExec(const RSqlBufFlat& aParamBuf, TRequestStatus& aStatus);
|
sl@0
|
93 |
inline TInt Next(RSqlBufFlat& aColumnBuf);
|
sl@0
|
94 |
TInt BindNext(const RSqlBufFlat& aParamBuf, RSqlBufFlat& aColumnBuf);
|
sl@0
|
95 |
TInt GetNames(TSqlSrvFunction aFunction, RSqlBufFlat& aNameBuf);
|
sl@0
|
96 |
inline TInt ReadColumnValue(TInt aColumnIndex, TDes8& aBuf);
|
sl@0
|
97 |
|
sl@0
|
98 |
inline MStreamBuf* ColumnSourceL(TInt aColumnIndex);
|
sl@0
|
99 |
inline MStreamBuf* ParamSinkL(TSqlSrvFunction aFunction, TInt aParamIndex);
|
sl@0
|
100 |
|
sl@0
|
101 |
TInt GetDeclColumnTypes(RSqlBufFlat& aDeclColumnTypeBuf);
|
sl@0
|
102 |
|
sl@0
|
103 |
private:
|
sl@0
|
104 |
TInt DoBindNext(TSqlSrvFunction aFunction, TIpcArgs& aIpcArgs, RSqlBufFlat& aColumnBuf);
|
sl@0
|
105 |
TInt Retry(RSqlBufFlat& aBufFlat, TInt aSize, TSqlBufFlatType aWhat);
|
sl@0
|
106 |
inline RSqlDbSession& DbSession() const;
|
sl@0
|
107 |
|
sl@0
|
108 |
private:
|
sl@0
|
109 |
TInt iHandle;
|
sl@0
|
110 |
RSqlDbSession* iDbSession;
|
sl@0
|
111 |
|
sl@0
|
112 |
};
|
sl@0
|
113 |
|
sl@0
|
114 |
#include "SqlStmtSession.inl"
|
sl@0
|
115 |
|
sl@0
|
116 |
#endif//__SQLSTMTSESSION_H__
|