|
1 // Copyright (c) 2006-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 #include "SqlPanic.h" //ESqlPanicInvalidObj, ESqlPanicObjExists |
|
17 #include "SqlDatabaseImpl.h" //CSqlDatabaseImpl |
|
18 |
|
19 /** |
|
20 Returns a reference to the implementation object of RSqlDatabase - CSqlDatabaseImpl. |
|
21 |
|
22 @panic SqlDb 2 Create() or Open() has not previously been called on this RSqlDatabase object. |
|
23 |
|
24 @internalComponent |
|
25 */ |
|
26 inline CSqlDatabaseImpl& TSqlScalarFullSelectQuery::Impl() const |
|
27 { |
|
28 __SQLASSERT_ALWAYS(iDatabaseImpl != NULL, ESqlPanicInvalidObj); |
|
29 return *iDatabaseImpl; |
|
30 } |
|
31 |
|
32 /** |
|
33 Initializes TSqlScalarFullSelectQuery data members with default values. |
|
34 */ |
|
35 EXPORT_C TSqlScalarFullSelectQuery::TSqlScalarFullSelectQuery() : |
|
36 iDatabaseImpl(NULL) |
|
37 { |
|
38 } |
|
39 |
|
40 /** |
|
41 Initializes TSqlScalarFullSelectQuery object. |
|
42 |
|
43 @param aDatabase A reference to the RSqlDatabase object that represents |
|
44 the database on which scalar fullselect queries will be executed. |
|
45 */ |
|
46 EXPORT_C TSqlScalarFullSelectQuery::TSqlScalarFullSelectQuery(RSqlDatabase& aDatabase) : |
|
47 iDatabaseImpl(&aDatabase.Impl()) |
|
48 { |
|
49 } |
|
50 |
|
51 /** |
|
52 Initializes/reinitializes TSqlScalarFullSelectQuery object. |
|
53 |
|
54 @param aDatabase A reference to the RSqlDatabase object that represents |
|
55 the database on which scalar fullselect queries will be executed. |
|
56 */ |
|
57 EXPORT_C void TSqlScalarFullSelectQuery::SetDatabase(RSqlDatabase& aDatabase) |
|
58 { |
|
59 SQLUTRACE_PROFILER(this); |
|
60 iDatabaseImpl = &aDatabase.Impl(); |
|
61 } |
|
62 |
|
63 /** |
|
64 Executes a SELECT query which is expected to return a single row consisting of |
|
65 a single 32-bit integer value and returns that value. |
|
66 |
|
67 @param aSqlStmt 16-bit SELECT sql query |
|
68 |
|
69 @return 32-bit integer column value. |
|
70 |
|
71 @leave KErrNotFound, If there is no record, |
|
72 The function may leave with database specific errors categorised as ESqlDbError and |
|
73 other system-wide error codes. |
|
74 */ |
|
75 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectIntL(const TDesC& aSqlStmt) |
|
76 { |
|
77 SQLUTRACE_PROFILER(this); |
|
78 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aSqlStmt)); |
|
79 |
|
80 TInt res; |
|
81 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
82 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlInt, ptr); |
|
83 return res; |
|
84 } |
|
85 |
|
86 /** |
|
87 Executes a SELECT query which is expected to return a single row consisting of |
|
88 a single 64-bit integer value and returns that value. |
|
89 |
|
90 @param aSqlStmt 16-bit SELECT sql query |
|
91 |
|
92 @return 64-bit integer column value. |
|
93 |
|
94 @leave KErrNotFound, If there is no record, |
|
95 The function may leave with database specific errors categorised as ESqlDbError and |
|
96 other system-wide error codes. |
|
97 */ |
|
98 EXPORT_C TInt64 TSqlScalarFullSelectQuery::SelectInt64L(const TDesC& aSqlStmt) |
|
99 { |
|
100 SQLUTRACE_PROFILER(this); |
|
101 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aSqlStmt)); |
|
102 |
|
103 TInt64 res; |
|
104 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
105 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlInt64, ptr); |
|
106 return res; |
|
107 } |
|
108 |
|
109 /** |
|
110 Executes a SELECT query which is expected to return a single row consisting of |
|
111 a single real value and returns that value. |
|
112 |
|
113 @param aSqlStmt 16-bit SELECT sql query |
|
114 |
|
115 @return Real column value. |
|
116 |
|
117 @leave KErrNotFound, If there is no record, |
|
118 The function may leave with database specific errors categorised as ESqlDbError and |
|
119 other system-wide error codes. |
|
120 */ |
|
121 EXPORT_C TReal TSqlScalarFullSelectQuery::SelectRealL(const TDesC& aSqlStmt) |
|
122 { |
|
123 SQLUTRACE_PROFILER(this); |
|
124 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aSqlStmt)); |
|
125 |
|
126 TReal res; |
|
127 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
128 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlReal, ptr); |
|
129 return res; |
|
130 } |
|
131 |
|
132 /** |
|
133 Executes a SELECT query which is expected to return a single row consisting of |
|
134 a single text value and copies that value to the place refered by aDest parameter. |
|
135 |
|
136 If the destination buffer is not big enough, the function will copy as much data as |
|
137 possible and will return positive value - the character length of the text column. |
|
138 |
|
139 @param aSqlStmt 16-bit SELECT sql query |
|
140 @param aDest Refers to the place where the column data will be copied |
|
141 |
|
142 @return KErrNone, if the function completes successfully, |
|
143 Positive value, The text column value length in characters, in case if the receiving buffer |
|
144 is not big enough. |
|
145 |
|
146 @leave KErrNotFound, If there is no record, |
|
147 The function may leave with database specific errors categorised as ESqlDbError and |
|
148 other system-wide error codes. |
|
149 */ |
|
150 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectTextL(const TDesC& aSqlStmt, TDes& aDest) |
|
151 { |
|
152 SQLUTRACE_PROFILER(this); |
|
153 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aSqlStmt)); |
|
154 |
|
155 TPtr8 ptr(reinterpret_cast <TUint8*> (const_cast <TUint16*> (aDest.Ptr())), aDest.MaxLength() * sizeof(TUint16)); |
|
156 TInt err = Impl().ExecScalarFullSelectL(aSqlStmt, ESqlText, ptr); |
|
157 aDest.SetLength(ptr.Length() / sizeof(TUint16)); |
|
158 return err; |
|
159 } |
|
160 |
|
161 /** |
|
162 Executes a SELECT query which is expected to return a single row consisting of |
|
163 a single binary value and copies that value to the place refered by aDest parameter. |
|
164 |
|
165 If the destination buffer is not big enough, the function will copy as much data as |
|
166 possible and will return positive value - the byte length of the binary column. |
|
167 |
|
168 @param aSqlStmt 16-bit SELECT sql query |
|
169 @param aDest Refers to the place where the column data will be copied |
|
170 |
|
171 @return KErrNone, if the function completes successfully, |
|
172 Positive value, The binary column value length in bytes, in case if the receiving buffer |
|
173 is not big enough. |
|
174 |
|
175 @leave KErrNotFound, If there is no record, |
|
176 The function may leave with database specific errors categorised as ESqlDbError and |
|
177 other system-wide error codes. |
|
178 */ |
|
179 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectBinaryL(const TDesC& aSqlStmt, TDes8& aDest) |
|
180 { |
|
181 SQLUTRACE_PROFILER(this); |
|
182 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam16, 1, &aSqlStmt)); |
|
183 |
|
184 return Impl().ExecScalarFullSelectL(aSqlStmt, ESqlBinary, aDest); |
|
185 } |
|
186 |
|
187 /** |
|
188 Executes a SELECT query which is expected to return a single row consisting of |
|
189 a single 32-bit integer value and returns that value. |
|
190 |
|
191 @param aSqlStmt 8-bit SELECT sql query |
|
192 |
|
193 @return 32-bit integer column value. |
|
194 |
|
195 @leave KErrNotFound, If there is no record, |
|
196 The function may leave with database specific errors categorised as ESqlDbError and |
|
197 other system-wide error codes. |
|
198 */ |
|
199 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectIntL(const TDesC8& aSqlStmt) |
|
200 { |
|
201 SQLUTRACE_PROFILER(this); |
|
202 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam, 1, &aSqlStmt)); |
|
203 |
|
204 TInt res; |
|
205 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
206 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlInt, ptr); |
|
207 return res; |
|
208 } |
|
209 |
|
210 /** |
|
211 Executes a SELECT query which is expected to return a single row consisting of |
|
212 a single 64-bit integer value and returns that value. |
|
213 |
|
214 @param aSqlStmt 8-bit SELECT sql query |
|
215 |
|
216 @return 64-bit integer column value. |
|
217 |
|
218 @leave KErrNotFound, If there is no record, |
|
219 The function may leave with database specific errors categorised as ESqlDbError and |
|
220 other system-wide error codes. |
|
221 */ |
|
222 EXPORT_C TInt64 TSqlScalarFullSelectQuery::SelectInt64L(const TDesC8& aSqlStmt) |
|
223 { |
|
224 SQLUTRACE_PROFILER(this); |
|
225 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam, 1, &aSqlStmt)); |
|
226 |
|
227 TInt64 res; |
|
228 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
229 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlInt64, ptr); |
|
230 return res; |
|
231 } |
|
232 |
|
233 /** |
|
234 Executes a SELECT query which is expected to return a single row consisting of |
|
235 a single real value and returns that value. |
|
236 |
|
237 @param aSqlStmt 8-bit SELECT sql query |
|
238 |
|
239 @return Real column value. |
|
240 |
|
241 @leave KErrNotFound, If there is no record, |
|
242 The function may leave with database specific errors categorised as ESqlDbError and |
|
243 other system-wide error codes. |
|
244 */ |
|
245 EXPORT_C TReal TSqlScalarFullSelectQuery::SelectRealL(const TDesC8& aSqlStmt) |
|
246 { |
|
247 SQLUTRACE_PROFILER(this); |
|
248 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam, 1, &aSqlStmt)); |
|
249 |
|
250 TReal res; |
|
251 TPtr8 ptr(reinterpret_cast <TUint8*> (&res), sizeof(res)); |
|
252 (void)Impl().ExecScalarFullSelectL(aSqlStmt, ESqlReal, ptr); |
|
253 return res; |
|
254 } |
|
255 |
|
256 /** |
|
257 Executes a SELECT query which is expected to return a single row consisting of |
|
258 a single text value and copies that value to the place refered by aDest parameter. |
|
259 |
|
260 If the destination buffer is not big enough, the function will copy as much data as |
|
261 possible and will return positive value - the character length of the text column. |
|
262 |
|
263 @param aSqlStmt 8-bit SELECT sql query |
|
264 @param aDest Refers to the place where the column data will be copied |
|
265 |
|
266 @return KErrNone, if the function completes successfully, |
|
267 Positive value, The text column value length in characters, in case if the receiving buffer |
|
268 is not big enough. |
|
269 |
|
270 @leave KErrNotFound, If there is no record, |
|
271 The function may leave with database specific errors categorised as ESqlDbError and |
|
272 other system-wide error codes. |
|
273 */ |
|
274 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectTextL(const TDesC8& aSqlStmt, TDes& aDest) |
|
275 { |
|
276 SQLUTRACE_PROFILER(this); |
|
277 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam, 1, &aSqlStmt)); |
|
278 |
|
279 TPtr8 ptr(reinterpret_cast <TUint8*> (const_cast <TUint16*> (aDest.Ptr())), aDest.MaxLength() * sizeof(TUint16)); |
|
280 TInt err = Impl().ExecScalarFullSelectL(aSqlStmt, ESqlText, ptr); |
|
281 aDest.SetLength(ptr.Length() / sizeof(TUint16)); |
|
282 return err; |
|
283 } |
|
284 |
|
285 /** |
|
286 Executes a SELECT query which is expected to return a single row consisting of |
|
287 a single binary value and copies that value to the place refered by aDest parameter. |
|
288 |
|
289 If the destination buffer is not big enough, the function will copy as much data as |
|
290 possible and will return positive value - the character length of the text column. |
|
291 |
|
292 @param aSqlStmt 8-bit SELECT sql query |
|
293 @param aDest Refers to the place where the column data will be copied |
|
294 |
|
295 @return KErrNone, if the function completes successfully, |
|
296 Positive value, The binary column value length in bytes, in case if the receiving buffer |
|
297 is not big enough. |
|
298 |
|
299 @leave KErrNotFound, If there is no record, |
|
300 The function may leave with database specific errors categorised as ESqlDbError and |
|
301 other system-wide error codes. |
|
302 */ |
|
303 EXPORT_C TInt TSqlScalarFullSelectQuery::SelectBinaryL(const TDesC8& aSqlStmt, TDes8& aDest) |
|
304 { |
|
305 SQLUTRACE_PROFILER(this); |
|
306 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KStrParam, 1, &aSqlStmt)); |
|
307 |
|
308 return Impl().ExecScalarFullSelectL(aSqlStmt, ESqlBinary, aDest); |
|
309 } |