sl@0
|
1 |
// Copyright (c) 2006-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 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// SqlDbSession.inl
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@panic SqlDb 2 In _DEBUG mode if the statement handle is 0 or the database session is NULL,
|
sl@0
|
20 |
i.e. Prepare() has not yet been called on this RSqlStatementSession object.
|
sl@0
|
21 |
|
sl@0
|
22 |
@return A reference to the RSqlDbSession instance.
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
inline RSqlDbSession& RSqlStatementSession::DbSession() const
|
sl@0
|
25 |
{
|
sl@0
|
26 |
__ASSERT_DEBUG(iHandle > 0 && iDbSession != NULL, __SQLPANIC(ESqlPanicInvalidObj));
|
sl@0
|
27 |
return *iDbSession;
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
/**
|
sl@0
|
31 |
Creates unitialized RSqlStatementSession object.
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
inline RSqlStatementSession::RSqlStatementSession() :
|
sl@0
|
34 |
iHandle(-1),
|
sl@0
|
35 |
iDbSession(NULL)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Sends a request to the SQL server to reset the prepared SQL statement.
|
sl@0
|
41 |
|
sl@0
|
42 |
@return KErrNone The method completed successfully, system-wide error code otherwise.
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
inline TInt RSqlStatementSession::Reset()
|
sl@0
|
45 |
{
|
sl@0
|
46 |
return DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtReset, ESqlSrvStatementHandle, iHandle));
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
Sends a request to the SQL server to execute the prepared SQL statement.
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
@return >=0, The operation has completed successfully. The number of database rows that were
|
sl@0
|
54 |
changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
|
sl@0
|
55 |
Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0
|
sl@0
|
56 |
if the operation has completed successfully (disregarding the number of the deleted rows);
|
sl@0
|
57 |
KSqlErrStmtExpired, statement has expired (if new functions or collating sequences are
|
sl@0
|
58 |
registered or if an authorizer function is added or changed);
|
sl@0
|
59 |
KErrNoMemory, an out of memory condition has occurred.
|
sl@0
|
60 |
Note that database specific errors categorised as ESqlDbError, and
|
sl@0
|
61 |
other system-wide error codes may also be returned.
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
inline TInt RSqlStatementSession::Exec()
|
sl@0
|
64 |
{
|
sl@0
|
65 |
return DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtExec, ESqlSrvStatementHandle, iHandle));
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
Sends a request asynchronously to the SQL server to execute the prepared SQL statement.
|
sl@0
|
70 |
|
sl@0
|
71 |
@param aStatus Completion status of asynchronous request, one of the following:
|
sl@0
|
72 |
@code
|
sl@0
|
73 |
- >=0, The operation has completed successfully. The number of database rows that were
|
sl@0
|
74 |
changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
|
sl@0
|
75 |
Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0
|
sl@0
|
76 |
if the operation has completed successfully (disregarding the number of the deleted rows);
|
sl@0
|
77 |
- KSqlErrStmtExpired, the SQL statement has expired (if new functions or
|
sl@0
|
78 |
collating sequences have been registered or if an
|
sl@0
|
79 |
authorizer function has been added or changed);
|
sl@0
|
80 |
- KErrNoMemory, an out of memory condition has occurred - the statement
|
sl@0
|
81 |
will be reset.
|
sl@0
|
82 |
Note that aStatus may be set with database specific errors categorised as ESqlDbError,
|
sl@0
|
83 |
and other system-wide error codes.
|
sl@0
|
84 |
@endcode
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
inline void RSqlStatementSession::Exec(TRequestStatus& aStatus)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtAsyncExec, ESqlSrvStatementHandle, iHandle), aStatus);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
Sends a request to the SQL server to execute the prepared SQL statement.
|
sl@0
|
93 |
|
sl@0
|
94 |
Usage of the IPC call arguments:
|
sl@0
|
95 |
Arg 0: [out] parameter buffer length in bytes
|
sl@0
|
96 |
Arg 1: [out] parameter buffer
|
sl@0
|
97 |
|
sl@0
|
98 |
@param aParamBuf A buffer with the parameter values
|
sl@0
|
99 |
|
sl@0
|
100 |
@return >=0, The operation has completed successfully. The number of database rows that were
|
sl@0
|
101 |
changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
|
sl@0
|
102 |
Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0
|
sl@0
|
103 |
if the operation has completed successfully (disregarding the number of the deleted rows);
|
sl@0
|
104 |
KSqlErrStmtExpired, statement has expired (if new functions or collating sequences are
|
sl@0
|
105 |
registered or if an authorizer function is added or changed);
|
sl@0
|
106 |
KErrNoMemory, an out of memory condition has occurred.
|
sl@0
|
107 |
Note that database specific errors categorised as ESqlDbError, and
|
sl@0
|
108 |
other system-wide error codes may also be returned.
|
sl@0
|
109 |
*/
|
sl@0
|
110 |
inline TInt RSqlStatementSession::BindExec(const RSqlBufFlat& aParamBuf)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TPtrC8 prmData(aParamBuf.BufDes());
|
sl@0
|
113 |
return DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtBindExec, ESqlSrvStatementHandle, iHandle), TIpcArgs(prmData.Length(), &prmData));
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
/**
|
sl@0
|
117 |
Sends a request asynchronously to the SQL server to execute the prepared SQL statement.
|
sl@0
|
118 |
|
sl@0
|
119 |
Usage of the IPC call arguments:
|
sl@0
|
120 |
Arg 0: [out] parameter buffer length in bytes
|
sl@0
|
121 |
Arg 1: [out] parameter buffer
|
sl@0
|
122 |
|
sl@0
|
123 |
@param aParamBuf A buffer with the parameter values
|
sl@0
|
124 |
@param aStatus Completion status of asynchronous request, one of the following:
|
sl@0
|
125 |
@code
|
sl@0
|
126 |
- >=0, The operation has completed successfully. The number of database rows that were
|
sl@0
|
127 |
changed/inserted/deleted by the most recently completed INSERT/UPDATE/DELETE sql statement.
|
sl@0
|
128 |
Exception: If the executed statement is "DELETE FROM <table>", then the function returns 0
|
sl@0
|
129 |
if the operation has completed successfully (disregarding the number of the deleted rows);
|
sl@0
|
130 |
- KSqlErrStmtExpired, the SQL statement has expired (if new functions or
|
sl@0
|
131 |
collating sequences have been registered or if an
|
sl@0
|
132 |
authorizer function has been added or changed);
|
sl@0
|
133 |
- KErrNoMemory, an out of memory condition has occurred - the statement
|
sl@0
|
134 |
will be reset.
|
sl@0
|
135 |
Note that aStatus may be set with database specific errors categorised as ESqlDbError,
|
sl@0
|
136 |
and other system-wide error codes.
|
sl@0
|
137 |
@endcode
|
sl@0
|
138 |
*/
|
sl@0
|
139 |
inline void RSqlStatementSession::BindExec(const RSqlBufFlat& aParamBuf, TRequestStatus& aStatus)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
const TDesC8& bufDes = aParamBuf.BufDes();
|
sl@0
|
142 |
DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtAsyncBindExec, ESqlSrvStatementHandle, iHandle), TIpcArgs(bufDes.Length(), &bufDes), aStatus);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
/**
|
sl@0
|
146 |
Sends a request to the SQL server to move to the next record which satisfies the
|
sl@0
|
147 |
condition of the prepared SQL statement.
|
sl@0
|
148 |
If there is a valid next record, the method transfers the column values from the server.
|
sl@0
|
149 |
|
sl@0
|
150 |
@param aColumnBuf It references RSqlBufFlat object where the column values will be stored.
|
sl@0
|
151 |
|
sl@0
|
152 |
@return KSqlAtRow, the record data is ready for processing by the caller;
|
sl@0
|
153 |
KSqlAtEnd, there is no more record data;
|
sl@0
|
154 |
KSqlErrBusy, the database file is locked;
|
sl@0
|
155 |
KErrNoMemory, an out of memory condition has occurred - the statement
|
sl@0
|
156 |
will be reset;
|
sl@0
|
157 |
KSqlErrGeneral, a run-time error has occured - this function must not
|
sl@0
|
158 |
be called again;
|
sl@0
|
159 |
KSqlErrMisuse, this function has been called after a previous call
|
sl@0
|
160 |
returned KSqlAtEnd or KSqlErrGeneral.
|
sl@0
|
161 |
KSqlErrStmtExpired, the SQL statement has expired (if new functions or
|
sl@0
|
162 |
collating sequences have been registered or if an
|
sl@0
|
163 |
authorizer function has been added or changed);
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
inline TInt RSqlStatementSession::Next(RSqlBufFlat& aColumnBuf)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
TIpcArgs ipcArgs;
|
sl@0
|
168 |
return DoBindNext(ESqlSrvStmtNext, ipcArgs, aColumnBuf);
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
/**
|
sl@0
|
172 |
Sends a command to the server for retrieving a column data.
|
sl@0
|
173 |
|
sl@0
|
174 |
Usage of the IPC call arguments:
|
sl@0
|
175 |
Arg 0: [out] column index
|
sl@0
|
176 |
Arg 1: [out] column data buffer length in bytes
|
sl@0
|
177 |
Arg 2: [in/out] column data buffer
|
sl@0
|
178 |
*/
|
sl@0
|
179 |
inline TInt RSqlStatementSession::ReadColumnValue(TInt aColumnIndex, TDes8& aBuf)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
return DbSession().SendReceive(::MakeMsgCode(ESqlSrvStmtColumnValue, ESqlSrvStatementHandle, iHandle), TIpcArgs(aColumnIndex, aBuf.MaxLength(), &aBuf));
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
/**
|
sl@0
|
185 |
The method creates a read-only MStreamBuf derived object which allows the column with aColumnIndex index
|
sl@0
|
186 |
to be accessed as a stream of bytes (if the column is a binary column) or characters
|
sl@0
|
187 |
(if the column is a text column) and returns it to the caller.
|
sl@0
|
188 |
|
sl@0
|
189 |
Usage of the IPC call arguments:
|
sl@0
|
190 |
Arg 0: [out] column index (0 based)
|
sl@0
|
191 |
Arg 2: [in] ipc buffer, column source
|
sl@0
|
192 |
|
sl@0
|
193 |
The caller is responsible for the destroying of the read-only MStreamBuf derived object.
|
sl@0
|
194 |
|
sl@0
|
195 |
@param aColumnIndex Column index (starting from 0)
|
sl@0
|
196 |
@return A pointer to the created read-only memory MStreamBuf derived object.
|
sl@0
|
197 |
|
sl@0
|
198 |
@leave KErrNoMemory, an out of memory condition has occured;
|
sl@0
|
199 |
*/
|
sl@0
|
200 |
inline MStreamBuf* RSqlStatementSession::ColumnSourceL(TInt aColumnIndex)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
TIpcArgs args(aColumnIndex);
|
sl@0
|
203 |
HIpcBuf* columnSource = HIpcBuf::NewL(DbSession(), ::MakeMsgCode(ESqlSrvStmtColumnSource, ESqlSrvStatementHandle, iHandle), args);
|
sl@0
|
204 |
return columnSource;
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
/**
|
sl@0
|
208 |
The method creates an IPC object with buffering capabilities, allowing to stream out the data of the
|
sl@0
|
209 |
parameter with aParameterIndex index and returns this MStreamBuf derived object to the caller.
|
sl@0
|
210 |
|
sl@0
|
211 |
The caller is responsible for the destroying of the MStreamBuf derived object.
|
sl@0
|
212 |
|
sl@0
|
213 |
Arg 0: [out] parameter index (0 based)
|
sl@0
|
214 |
Arg 2: [in] ipc buffer, parameter source
|
sl@0
|
215 |
|
sl@0
|
216 |
@param aParameterIndex Parameter index (starting from 0)
|
sl@0
|
217 |
|
sl@0
|
218 |
@return A pointer to the created MStreamBuf derived object.
|
sl@0
|
219 |
|
sl@0
|
220 |
@leave KErrNoMemory, an out of memory condition has occured;
|
sl@0
|
221 |
*/
|
sl@0
|
222 |
inline MStreamBuf* RSqlStatementSession::ParamSinkL(TSqlSrvFunction aFunction, TInt aParamIndex)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
TIpcArgs args(aParamIndex);
|
sl@0
|
225 |
HIpcBuf* paramSink = HIpcBuf::NewL(DbSession(), ::MakeMsgCode(aFunction, ESqlSrvStatementHandle, iHandle), args);
|
sl@0
|
226 |
return paramSink;
|
sl@0
|
227 |
}
|