sl@0
|
1 |
// Copyright (c) 2007-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32test.h>
|
sl@0
|
17 |
#include <e32math.h>
|
sl@0
|
18 |
#include <bautils.h>
|
sl@0
|
19 |
#include <s32buf.h> //MStreamBuf
|
sl@0
|
20 |
#include <sqldb.h>
|
sl@0
|
21 |
#include "SqlResourceProfiler.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
24 |
|
sl@0
|
25 |
RTest TheTest(_L("t_sqlapi2 test"));
|
sl@0
|
26 |
RSqlDatabase TheDb;
|
sl@0
|
27 |
RSqlStatement TheStmt;
|
sl@0
|
28 |
|
sl@0
|
29 |
_LIT(KTestDir, "c:\\test\\");
|
sl@0
|
30 |
_LIT(KTestDbName1, "c:\\test\\t_sqlapi2_1.db");
|
sl@0
|
31 |
_LIT(KTestDbName2, "c:\\private\\1111C1EF\\t_sqlapi2_2.db");//t_sqlapi2 app - private database
|
sl@0
|
32 |
|
sl@0
|
33 |
_LIT(KDbInjectedName1, "DELETE FROM symbian_settings;c:\\test\\A.db");
|
sl@0
|
34 |
_LIT(KDbInjectedName2, "c:\\test\\A.db;DELETE FROM symbian_settings;");
|
sl@0
|
35 |
|
sl@0
|
36 |
const TInt KBufLen = 8192;
|
sl@0
|
37 |
TBuf<KBufLen> TheBuf;
|
sl@0
|
38 |
|
sl@0
|
39 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
40 |
|
sl@0
|
41 |
void DeleteTestFiles()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TheStmt.Close();
|
sl@0
|
44 |
TheDb.Close();
|
sl@0
|
45 |
(void)RSqlDatabase::Delete(KDbInjectedName2);
|
sl@0
|
46 |
(void)RSqlDatabase::Delete(KDbInjectedName1);
|
sl@0
|
47 |
(void)RSqlDatabase::Delete(KTestDbName2);
|
sl@0
|
48 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
52 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
53 |
//Test macros and functions
|
sl@0
|
54 |
void Check(TInt aValue, TInt aLine)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
if(!aValue)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
DeleteTestFiles();
|
sl@0
|
59 |
TheTest(EFalse, aLine);
|
sl@0
|
60 |
}
|
sl@0
|
61 |
}
|
sl@0
|
62 |
void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
if(aValue != aExpected)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
DeleteTestFiles();
|
sl@0
|
67 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
68 |
TheTest(EFalse, aLine);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
}
|
sl@0
|
71 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
72 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
73 |
|
sl@0
|
74 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
75 |
|
sl@0
|
76 |
void CreateTestEnv()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
RFs fs;
|
sl@0
|
79 |
TInt err = fs.Connect();
|
sl@0
|
80 |
TEST2(err, KErrNone);
|
sl@0
|
81 |
|
sl@0
|
82 |
err = fs.MkDir(KTestDir);
|
sl@0
|
83 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
84 |
|
sl@0
|
85 |
err = fs.CreatePrivatePath(EDriveC);
|
sl@0
|
86 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
87 |
|
sl@0
|
88 |
fs.Close();
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
92 |
|
sl@0
|
93 |
/**
|
sl@0
|
94 |
@SYMTestCaseID SYSLIB-SQL-UT-3512
|
sl@0
|
95 |
@SYMTestCaseDesc RSqlStatement::ColumnCount() - SELECT statements test
|
sl@0
|
96 |
The test creates a database with a table and then checks the ColumnCount()
|
sl@0
|
97 |
return result for the following statements:
|
sl@0
|
98 |
- select all columns;
|
sl@0
|
99 |
- select a subset;
|
sl@0
|
100 |
- select an expression;
|
sl@0
|
101 |
- select a constant;
|
sl@0
|
102 |
- multi-table select;
|
sl@0
|
103 |
- select a function;
|
sl@0
|
104 |
- select plus sub-query;
|
sl@0
|
105 |
@SYMTestPriority High
|
sl@0
|
106 |
@SYMTestActions RSqlStatement::ColumnCount() test
|
sl@0
|
107 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
108 |
@SYMREQ REQ8035
|
sl@0
|
109 |
*/
|
sl@0
|
110 |
void ColumnCountTest()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
114 |
TEST2(err, KErrNone);
|
sl@0
|
115 |
//Create table 1
|
sl@0
|
116 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT,Id2 INTEGER,Data BLOB)"));
|
sl@0
|
117 |
TEST(err >= 0);
|
sl@0
|
118 |
|
sl@0
|
119 |
err = TheDb.Exec(_L("INSERT INTO A VALUES(1,'AAA',6234567890,x'11AAFD0C771188')"));
|
sl@0
|
120 |
TEST2(err, 1);
|
sl@0
|
121 |
|
sl@0
|
122 |
//Select all columns (SELECT *)
|
sl@0
|
123 |
err = TheStmt.Prepare(TheDb, _L("SELECT * FROM A"));
|
sl@0
|
124 |
TEST2(err, KErrNone);
|
sl@0
|
125 |
TInt cnt = TheStmt.ColumnCount();
|
sl@0
|
126 |
TEST2(cnt, 4);
|
sl@0
|
127 |
TheStmt.Close();
|
sl@0
|
128 |
//Select all columns (SELECT a,b,c...)
|
sl@0
|
129 |
err = TheStmt.Prepare(TheDb, _L("SELECT Id,Name,Id2,Data FROM A"));
|
sl@0
|
130 |
TEST2(err, KErrNone);
|
sl@0
|
131 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
132 |
TEST2(cnt, 4);
|
sl@0
|
133 |
TheStmt.Close();
|
sl@0
|
134 |
//Select column subset
|
sl@0
|
135 |
err = TheStmt.Prepare(TheDb, _L("SELECT Id,Name,Data FROM A"));
|
sl@0
|
136 |
TEST2(err, KErrNone);
|
sl@0
|
137 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
138 |
TEST2(cnt, 3);
|
sl@0
|
139 |
TheStmt.Close();
|
sl@0
|
140 |
//Select column subset + expression
|
sl@0
|
141 |
err = TheStmt.Prepare(TheDb, _L("SELECT Id,Id+Id2 FROM A"));
|
sl@0
|
142 |
TEST2(err, KErrNone);
|
sl@0
|
143 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
144 |
TEST2(cnt, 2);
|
sl@0
|
145 |
TheStmt.Close();
|
sl@0
|
146 |
//Select column subset + constant
|
sl@0
|
147 |
err = TheStmt.Prepare(TheDb, _L("SELECT Id,Id2,345.78 FROM A"));
|
sl@0
|
148 |
TEST2(err, KErrNone);
|
sl@0
|
149 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
150 |
TEST2(cnt, 3);
|
sl@0
|
151 |
TheStmt.Close();
|
sl@0
|
152 |
//Select SQL function
|
sl@0
|
153 |
err = TheStmt.Prepare(TheDb, _L("SELECT COUNT(*) FROM A"));
|
sl@0
|
154 |
TEST2(err, KErrNone);
|
sl@0
|
155 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
156 |
TEST2(cnt, 1);
|
sl@0
|
157 |
TheStmt.Close();
|
sl@0
|
158 |
//Create table 2
|
sl@0
|
159 |
err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, S INTEGER)"));
|
sl@0
|
160 |
TEST(err >= 0);
|
sl@0
|
161 |
err = TheDb.Exec(_L("INSERT INTO B VALUES(1,25)"));
|
sl@0
|
162 |
TEST2(err, 1);
|
sl@0
|
163 |
//Multitable select
|
sl@0
|
164 |
err = TheStmt.Prepare(TheDb, _L("SELECT A.Id,B.S FROM A,B WHERE A.Id = B.Id"));
|
sl@0
|
165 |
TEST2(err, KErrNone);
|
sl@0
|
166 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
167 |
TEST2(cnt, 2);
|
sl@0
|
168 |
TheStmt.Close();
|
sl@0
|
169 |
//Select + Subquery
|
sl@0
|
170 |
err = TheStmt.Prepare(TheDb, _L("SELECT Id FROM A WHERE (SELECT S FROM B WHERE A.Id = B.Id) > 10"));
|
sl@0
|
171 |
TEST2(err, KErrNone);
|
sl@0
|
172 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
173 |
TEST2(cnt, 1);
|
sl@0
|
174 |
TheStmt.Close();
|
sl@0
|
175 |
//Cleanup
|
sl@0
|
176 |
TheDb.Close();
|
sl@0
|
177 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
/**
|
sl@0
|
181 |
@SYMTestCaseID SYSLIB-SQL-UT-3513
|
sl@0
|
182 |
@SYMTestCaseDesc RSqlStatement::ColumnCount() - DDL and DML statements test
|
sl@0
|
183 |
The test creates a database with a table and then checks the ColumnCount() return result for
|
sl@0
|
184 |
DML statements (INSERT/UPDATE/DELETE) and DDL statements (CREATE TABLE/INDEX, DROP TABLE?INDEX).
|
sl@0
|
185 |
The column count for DML and DDL statements should be 0.
|
sl@0
|
186 |
@SYMTestPriority High
|
sl@0
|
187 |
@SYMTestActions RSqlStatement::ColumnCount() test
|
sl@0
|
188 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
189 |
@SYMREQ REQ8035
|
sl@0
|
190 |
*/
|
sl@0
|
191 |
void ColumnCountTest2()
|
sl@0
|
192 |
{
|
sl@0
|
193 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
194 |
TEST2(err, KErrNone);
|
sl@0
|
195 |
//Create table
|
sl@0
|
196 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Name TEXT,Id2 INTEGER,Data BLOB)"));
|
sl@0
|
197 |
TEST(err >= 0);
|
sl@0
|
198 |
err = TheDb.Exec(_L("INSERT INTO A VALUES(1,'AAA',6234567890,x'11AAFD0C771188')"));
|
sl@0
|
199 |
TEST2(err, 1);
|
sl@0
|
200 |
//INSERT statement
|
sl@0
|
201 |
err = TheStmt.Prepare(TheDb, _L("INSERT INTO A(Id,Id2) VALUES(:P1,:P2)"));
|
sl@0
|
202 |
TEST2(err, KErrNone);
|
sl@0
|
203 |
TInt cnt = TheStmt.ColumnCount();
|
sl@0
|
204 |
TEST2(cnt, 0);
|
sl@0
|
205 |
TheStmt.Close();
|
sl@0
|
206 |
//UPDATE statement
|
sl@0
|
207 |
err = TheStmt.Prepare(TheDb, _L("UPDATE A SET Id2=100 WHERE Id=:P1"));
|
sl@0
|
208 |
TEST2(err, KErrNone);
|
sl@0
|
209 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
210 |
TEST2(cnt, 0);
|
sl@0
|
211 |
TheStmt.Close();
|
sl@0
|
212 |
//DELETE statement
|
sl@0
|
213 |
err = TheStmt.Prepare(TheDb, _L("DELETE FROM A WHERE Id=:P1"));
|
sl@0
|
214 |
TEST2(err, KErrNone);
|
sl@0
|
215 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
216 |
TEST2(cnt, 0);
|
sl@0
|
217 |
TheStmt.Close();
|
sl@0
|
218 |
//CREATE TABLE statement
|
sl@0
|
219 |
err = TheStmt.Prepare(TheDb, _L("CREATE TABLE B AS SELECT * FROM A"));
|
sl@0
|
220 |
TEST2(err, KErrNone);
|
sl@0
|
221 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
222 |
TEST2(cnt, 0);
|
sl@0
|
223 |
TheStmt.Close();
|
sl@0
|
224 |
//DROP TABLE statement
|
sl@0
|
225 |
err = TheStmt.Prepare(TheDb, _L("DROP TABLE A"));
|
sl@0
|
226 |
TEST2(err, KErrNone);
|
sl@0
|
227 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
228 |
TEST2(cnt, 0);
|
sl@0
|
229 |
TheStmt.Close();
|
sl@0
|
230 |
//CREATE INDEX statement
|
sl@0
|
231 |
err = TheStmt.Prepare(TheDb, _L("CREATE INDEX I ON A(Id)"));
|
sl@0
|
232 |
TEST2(err, KErrNone);
|
sl@0
|
233 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
234 |
TEST2(cnt, 0);
|
sl@0
|
235 |
err = TheStmt.Exec();
|
sl@0
|
236 |
TEST(err >= 0);
|
sl@0
|
237 |
TheStmt.Close();
|
sl@0
|
238 |
//DROP INDEX statement
|
sl@0
|
239 |
err = TheStmt.Prepare(TheDb, _L("DROP INDEX I"));
|
sl@0
|
240 |
TEST2(err, KErrNone);
|
sl@0
|
241 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
242 |
TEST2(cnt, 0);
|
sl@0
|
243 |
TheStmt.Close();
|
sl@0
|
244 |
//CREATE TRIGGER statement
|
sl@0
|
245 |
err = TheStmt.Prepare(TheDb,
|
sl@0
|
246 |
_L("CREATE TRIGGER Trg BEFORE DELETE ON A \
|
sl@0
|
247 |
BEGIN \
|
sl@0
|
248 |
SELECT CASE WHEN ((SELECT Id2 FROM A WHERE A.Id = old.Id) > 0) \
|
sl@0
|
249 |
THEN RAISE (ABORT, 'Id2 > 0') \
|
sl@0
|
250 |
END;\
|
sl@0
|
251 |
END;"));
|
sl@0
|
252 |
TEST2(err, KErrNone);
|
sl@0
|
253 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
254 |
TEST2(cnt, 0);
|
sl@0
|
255 |
TheStmt.Close();
|
sl@0
|
256 |
//CREATE VIEW statement
|
sl@0
|
257 |
err = TheStmt.Prepare(TheDb, _L("CREATE VIEW V AS SELECT * FROM A"));
|
sl@0
|
258 |
TEST2(err, KErrNone);
|
sl@0
|
259 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
260 |
TEST2(cnt, 0);
|
sl@0
|
261 |
err = TheStmt.Exec();
|
sl@0
|
262 |
TEST(err >= 0);
|
sl@0
|
263 |
TheStmt.Close();
|
sl@0
|
264 |
//DROP VIEW statement
|
sl@0
|
265 |
err = TheStmt.Prepare(TheDb, _L("DROP VIEW V"));
|
sl@0
|
266 |
TEST2(err, KErrNone);
|
sl@0
|
267 |
cnt = TheStmt.ColumnCount();
|
sl@0
|
268 |
TEST2(cnt, 0);
|
sl@0
|
269 |
TheStmt.Close();
|
sl@0
|
270 |
//Cleanup
|
sl@0
|
271 |
TheDb.Close();
|
sl@0
|
272 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
273 |
}
|
sl@0
|
274 |
|
sl@0
|
275 |
/**
|
sl@0
|
276 |
@SYMTestCaseID SYSLIB-SQL-UT-3514
|
sl@0
|
277 |
@SYMTestCaseDesc RSqlStatement::DeclaredColumnType() test
|
sl@0
|
278 |
The test creates a database with a table and then checks the DeclaredColumnType() return result for:
|
sl@0
|
279 |
- select all column from the table and check their types;
|
sl@0
|
280 |
- multi-table select plus column type checks;
|
sl@0
|
281 |
- select expression - the expected column type is ESqlInt;
|
sl@0
|
282 |
- select constant - the expected column type is ESqlInt;
|
sl@0
|
283 |
@SYMTestPriority High
|
sl@0
|
284 |
@SYMTestActions RSqlStatement::ColumnCount() test
|
sl@0
|
285 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
286 |
@SYMREQ REQ8035
|
sl@0
|
287 |
*/
|
sl@0
|
288 |
void DeclaredColumnTypeTest()
|
sl@0
|
289 |
{
|
sl@0
|
290 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
291 |
TEST2(err, KErrNone);
|
sl@0
|
292 |
const char* KColTypeNames[] =
|
sl@0
|
293 |
{"INTEGER", "LONG INTEGER", "INT", "SHORT INT", "SMALL INT", "TINY INT", "SHORT", "INT64",
|
sl@0
|
294 |
"TEXT", "LONGTEXT", "CLOB", "CHAR", "CHARACTER(20)", "LONG TEXT",
|
sl@0
|
295 |
"BINARY", "LONG BINARY", "LONGBINARY", "BLOB", "LONGBLOB", "LONG BLOB",
|
sl@0
|
296 |
"REAL", "FLOAT", "DOUBLE", "LONG DOUBLE",
|
sl@0
|
297 |
"LONG LONG", "BOO HOO"};
|
sl@0
|
298 |
const TSqlColumnType KColTypes[] =
|
sl@0
|
299 |
{ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,
|
sl@0
|
300 |
ESqlText,ESqlText,ESqlText,ESqlText,ESqlText,ESqlText,
|
sl@0
|
301 |
ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,
|
sl@0
|
302 |
ESqlReal,ESqlReal,ESqlReal,ESqlReal,
|
sl@0
|
303 |
ESqlInt,ESqlInt};
|
sl@0
|
304 |
const TInt KColTypeCnt = sizeof(KColTypes) / sizeof(KColTypes[0]);
|
sl@0
|
305 |
TEST2(sizeof(KColTypeNames) / sizeof(KColTypeNames[0]), KColTypeCnt);
|
sl@0
|
306 |
//Create table 1
|
sl@0
|
307 |
TBuf8<512> sql;
|
sl@0
|
308 |
sql.Copy(_L8("CREATE TABLE T("));
|
sl@0
|
309 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
sql.Append(TChar('A'));
|
sl@0
|
312 |
sql.AppendNum(i + 1);
|
sl@0
|
313 |
sql.Append(TChar(' '));
|
sl@0
|
314 |
sql.Append((TUint8*)KColTypeNames[i], User::StringLength((TUint8*)KColTypeNames[i]));
|
sl@0
|
315 |
sql.Append(TChar(','));
|
sl@0
|
316 |
}
|
sl@0
|
317 |
sql.Replace(sql.Length() - 1, 1, _L8(")"));
|
sl@0
|
318 |
err = TheDb.Exec(sql);
|
sl@0
|
319 |
TEST(err >= 0);
|
sl@0
|
320 |
//Select all columns (SELECT *)
|
sl@0
|
321 |
err = TheStmt.Prepare(TheDb, _L("SELECT * FROM T"));
|
sl@0
|
322 |
TEST2(err, KErrNone);
|
sl@0
|
323 |
TInt cnt = TheStmt.ColumnCount();
|
sl@0
|
324 |
TEST2(cnt, KColTypeCnt);
|
sl@0
|
325 |
TSqlColumnType colType;
|
sl@0
|
326 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
327 |
{
|
sl@0
|
328 |
TInt err = TheStmt.DeclaredColumnType(i, colType);
|
sl@0
|
329 |
TEST2(err, KErrNone);
|
sl@0
|
330 |
TEST2(colType, KColTypes[i]);
|
sl@0
|
331 |
}
|
sl@0
|
332 |
TheStmt.Close();
|
sl@0
|
333 |
//Create table 2
|
sl@0
|
334 |
err = TheDb.Exec(_L8("CREATE TABLE T2(Id INTEGER, DATA BLOB)"));
|
sl@0
|
335 |
TEST(err >= 0);
|
sl@0
|
336 |
//Multi-table select
|
sl@0
|
337 |
err = TheStmt.Prepare(TheDb, _L("SELECT T.A1,T2.Id,T.A9,T2.Data FROM T,T2"));
|
sl@0
|
338 |
TEST2(err, KErrNone);
|
sl@0
|
339 |
err = TheStmt.DeclaredColumnType(0, colType);
|
sl@0
|
340 |
TEST2(err, KErrNone);
|
sl@0
|
341 |
TEST2(colType, ESqlInt);
|
sl@0
|
342 |
err = TheStmt.DeclaredColumnType(1, colType);
|
sl@0
|
343 |
TEST2(err, KErrNone);
|
sl@0
|
344 |
TEST2(colType, ESqlInt);
|
sl@0
|
345 |
err = TheStmt.DeclaredColumnType(2, colType);
|
sl@0
|
346 |
TEST2(err, KErrNone);
|
sl@0
|
347 |
TEST2(colType, ESqlText);
|
sl@0
|
348 |
err = TheStmt.DeclaredColumnType(3, colType);
|
sl@0
|
349 |
TEST2(err, KErrNone);
|
sl@0
|
350 |
TEST2(colType, ESqlBinary);
|
sl@0
|
351 |
TheStmt.Close();
|
sl@0
|
352 |
//Select expression
|
sl@0
|
353 |
err = TheStmt.Prepare(TheDb, _L("SELECT (Id + Data) AS RES FROM t2"));
|
sl@0
|
354 |
TEST2(err, KErrNone);
|
sl@0
|
355 |
err = TheStmt.DeclaredColumnType(0, colType);
|
sl@0
|
356 |
TEST2(err, KErrNone);
|
sl@0
|
357 |
TEST2(colType, ESqlInt);
|
sl@0
|
358 |
TheStmt.Close();
|
sl@0
|
359 |
//Select constant
|
sl@0
|
360 |
err = TheStmt.Prepare(TheDb, _L("SELECT (Id + Data) AS RES, 55.89 FROM t2"));
|
sl@0
|
361 |
TEST2(err, KErrNone);
|
sl@0
|
362 |
err = TheStmt.DeclaredColumnType(1, colType);
|
sl@0
|
363 |
TEST2(err, KErrNone);
|
sl@0
|
364 |
TEST2(colType, ESqlInt);
|
sl@0
|
365 |
TheStmt.Close();
|
sl@0
|
366 |
//Cleanup
|
sl@0
|
367 |
TheDb.Close();
|
sl@0
|
368 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
369 |
}
|
sl@0
|
370 |
|
sl@0
|
371 |
/**
|
sl@0
|
372 |
@SYMTestCaseID SYSLIB-SQL-UT-4017
|
sl@0
|
373 |
@SYMTestCaseDesc RSqlStatement::ColumnName(TInt, TPtrC&) test
|
sl@0
|
374 |
The test creates a database with a table and then checks the ColumnName() return result for:
|
sl@0
|
375 |
- select all column from the table and check their names;
|
sl@0
|
376 |
- multi-table select plus column name checks;
|
sl@0
|
377 |
- select expression - the expected column name is RES
|
sl@0
|
378 |
- select constant - the expected column type is 55.89
|
sl@0
|
379 |
@SYMTestPriority High
|
sl@0
|
380 |
@SYMTestActions RSqlStatement::ColumnName() test
|
sl@0
|
381 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
382 |
@SYMCR RMAD-7B7EV5
|
sl@0
|
383 |
Add SQL Server APIs to retrieve column and parameter names
|
sl@0
|
384 |
*/
|
sl@0
|
385 |
void ColumnNameTest()
|
sl@0
|
386 |
{
|
sl@0
|
387 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
388 |
TEST2(err, KErrNone);
|
sl@0
|
389 |
const char* KColTypeNames[] =
|
sl@0
|
390 |
{"INTEGER", "LONG INTEGER", "INT", "SHORT INT", "SMALL INT", "TINY INT", "SHORT", "INT64",
|
sl@0
|
391 |
"TEXT", "LONGTEXT", "CLOB", "CHAR", "CHARACTER(20)", "LONG TEXT",
|
sl@0
|
392 |
"BINARY", "LONG BINARY", "LONGBINARY", "BLOB", "LONGBLOB", "LONG BLOB",
|
sl@0
|
393 |
"REAL", "FLOAT", "DOUBLE", "LONG DOUBLE",
|
sl@0
|
394 |
"LONG LONG", "BOO HOO"};
|
sl@0
|
395 |
const TSqlColumnType KColTypes[] =
|
sl@0
|
396 |
{ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,ESqlInt,
|
sl@0
|
397 |
ESqlText,ESqlText,ESqlText,ESqlText,ESqlText,ESqlText,
|
sl@0
|
398 |
ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,ESqlBinary,
|
sl@0
|
399 |
ESqlReal,ESqlReal,ESqlReal,ESqlReal,
|
sl@0
|
400 |
ESqlInt,ESqlInt};
|
sl@0
|
401 |
const TInt KColTypeCnt = sizeof(KColTypes) / sizeof(KColTypes[0]);
|
sl@0
|
402 |
TEST2(sizeof(KColTypeNames) / sizeof(KColTypeNames[0]), KColTypeCnt);
|
sl@0
|
403 |
//Create table 1
|
sl@0
|
404 |
TBuf8<512> sql;
|
sl@0
|
405 |
sql.Copy(_L8("CREATE TABLE T("));
|
sl@0
|
406 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
sql.Append(TChar('A'));
|
sl@0
|
409 |
sql.AppendNum(i + 1);
|
sl@0
|
410 |
sql.Append(TChar(' '));
|
sl@0
|
411 |
sql.Append((TUint8*)KColTypeNames[i], User::StringLength((TUint8*)KColTypeNames[i]));
|
sl@0
|
412 |
sql.Append(TChar(','));
|
sl@0
|
413 |
}
|
sl@0
|
414 |
sql.Replace(sql.Length() - 1, 1, _L8(")"));
|
sl@0
|
415 |
err = TheDb.Exec(sql);
|
sl@0
|
416 |
TEST(err >= 0);
|
sl@0
|
417 |
//Select all columns (SELECT *)
|
sl@0
|
418 |
err = TheStmt.Prepare(TheDb, _L("SELECT * FROM T"));
|
sl@0
|
419 |
TEST2(err, KErrNone);
|
sl@0
|
420 |
TInt cnt = TheStmt.ColumnCount();
|
sl@0
|
421 |
TEST2(cnt, KColTypeCnt);
|
sl@0
|
422 |
TPtrC colName;
|
sl@0
|
423 |
TBuf<128> expectedColName;
|
sl@0
|
424 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
expectedColName.Zero();
|
sl@0
|
427 |
expectedColName.Append(TChar('A'));
|
sl@0
|
428 |
expectedColName.AppendNum(i + 1);
|
sl@0
|
429 |
TInt err = TheStmt.ColumnName(i, colName);
|
sl@0
|
430 |
TEST2(err, KErrNone);
|
sl@0
|
431 |
TEST2(colName.Compare(expectedColName), 0);
|
sl@0
|
432 |
TSqlColumnType type;
|
sl@0
|
433 |
err = TheStmt.DeclaredColumnType(i, type);
|
sl@0
|
434 |
TEST2(err, KErrNone);
|
sl@0
|
435 |
TEST2(type, KColTypes[i]);
|
sl@0
|
436 |
}
|
sl@0
|
437 |
TheStmt.Close();
|
sl@0
|
438 |
//Create table 2
|
sl@0
|
439 |
err = TheDb.Exec(_L8("CREATE TABLE T2(Id INTEGER, DATA BLOB)"));
|
sl@0
|
440 |
TEST(err >= 0);
|
sl@0
|
441 |
//Multi-table select
|
sl@0
|
442 |
err = TheStmt.Prepare(TheDb, _L("SELECT T.A1,T2.Id,T.A9,T2.DATA FROM T,T2"));
|
sl@0
|
443 |
TEST2(err, KErrNone);
|
sl@0
|
444 |
err = TheStmt.ColumnName(0, colName);
|
sl@0
|
445 |
TEST2(err, KErrNone);
|
sl@0
|
446 |
TEST2(colName.Compare(_L("A1")), 0);
|
sl@0
|
447 |
err = TheStmt.ColumnName(1, colName);
|
sl@0
|
448 |
TEST2(err, KErrNone);
|
sl@0
|
449 |
TEST2(colName.Compare(_L("Id")), 0);
|
sl@0
|
450 |
err = TheStmt.ColumnName(2, colName);
|
sl@0
|
451 |
TEST2(err, KErrNone);
|
sl@0
|
452 |
TEST2(colName.Compare(_L("A9")), 0);
|
sl@0
|
453 |
err = TheStmt.ColumnName(3, colName);
|
sl@0
|
454 |
TEST2(err, KErrNone);
|
sl@0
|
455 |
TEST2(colName.Compare(_L("DATA")), 0);
|
sl@0
|
456 |
TheStmt.Close();
|
sl@0
|
457 |
//Select expression
|
sl@0
|
458 |
err = TheStmt.Prepare(TheDb, _L("SELECT (Id + Data) AS RES FROM t2"));
|
sl@0
|
459 |
TEST2(err, KErrNone);
|
sl@0
|
460 |
err = TheStmt.ColumnName(0, colName);
|
sl@0
|
461 |
TEST2(err, KErrNone);
|
sl@0
|
462 |
TEST2(colName.Compare(_L("RES")), 0);
|
sl@0
|
463 |
//Too big column index
|
sl@0
|
464 |
err = TheStmt.ColumnName(1323, colName);
|
sl@0
|
465 |
TEST2(err, KErrNotFound);
|
sl@0
|
466 |
//Negative column index
|
sl@0
|
467 |
err = TheStmt.ColumnName(-100, colName);
|
sl@0
|
468 |
TEST2(err, KErrNotFound);
|
sl@0
|
469 |
TheStmt.Close();
|
sl@0
|
470 |
//Select constant
|
sl@0
|
471 |
err = TheStmt.Prepare(TheDb, _L("SELECT (Id + Data) AS RES, 55.89 FROM t2"));
|
sl@0
|
472 |
TEST2(err, KErrNone);
|
sl@0
|
473 |
err = TheStmt.ColumnName(1, colName);
|
sl@0
|
474 |
TEST2(err, KErrNone);
|
sl@0
|
475 |
TEST2(colName.Compare(_L("55.89")), 0);
|
sl@0
|
476 |
TheStmt.Close();
|
sl@0
|
477 |
//Cleanup
|
sl@0
|
478 |
TheDb.Close();
|
sl@0
|
479 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
480 |
}
|
sl@0
|
481 |
|
sl@0
|
482 |
/**
|
sl@0
|
483 |
@SYMTestCaseID SYSLIB-SQL-UT-4018
|
sl@0
|
484 |
@SYMTestCaseDesc RSqlStatement::ParameterName(TInt, TPtrC&) and RSqlStatement::ParamName(TInt, TPtrC&) test
|
sl@0
|
485 |
DML test:
|
sl@0
|
486 |
The test creates a database with a table and prepares an insert query.
|
sl@0
|
487 |
The test then checks the ParameterName() and ParamName() return result for:
|
sl@0
|
488 |
- Named parameters - return the named param
|
sl@0
|
489 |
- Unnamed parameters - return ?<param-index>
|
sl@0
|
490 |
@SYMTestPriority High
|
sl@0
|
491 |
@SYMTestActions RSqlStatement::ParameterName() and RSqlStatement::ParamName() test
|
sl@0
|
492 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
493 |
@SYMCR RMAD-7B7EV5
|
sl@0
|
494 |
Add SQL Server APIs to retrieve column and parameter names
|
sl@0
|
495 |
*/
|
sl@0
|
496 |
void ParamNameTest()
|
sl@0
|
497 |
{
|
sl@0
|
498 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
499 |
TEST2(err, KErrNone);
|
sl@0
|
500 |
const char* KColTypeNames[] =
|
sl@0
|
501 |
{"INTEGER", "TEXT"};
|
sl@0
|
502 |
const TInt KColTypeCnt = sizeof(KColTypeNames) / sizeof(KColTypeNames[0]);
|
sl@0
|
503 |
//Create table 1
|
sl@0
|
504 |
TBuf8<256> sql;
|
sl@0
|
505 |
sql.Copy(_L8("CREATE TABLE T("));
|
sl@0
|
506 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
507 |
{
|
sl@0
|
508 |
sql.Append(TChar('A'));
|
sl@0
|
509 |
sql.AppendNum(i + 1);
|
sl@0
|
510 |
sql.Append(TChar(' '));
|
sl@0
|
511 |
sql.Append((TUint8*)KColTypeNames[i], User::StringLength((TUint8*)KColTypeNames[i]));
|
sl@0
|
512 |
sql.Append(TChar(','));
|
sl@0
|
513 |
}
|
sl@0
|
514 |
sql.Replace(sql.Length() - 1, 1, _L8(")"));
|
sl@0
|
515 |
err = TheDb.Exec(sql);
|
sl@0
|
516 |
TEST(err >= 0);
|
sl@0
|
517 |
TheStmt.Close();
|
sl@0
|
518 |
|
sl@0
|
519 |
// Create insert statement, then check param names
|
sl@0
|
520 |
err = TheStmt.Prepare(TheDb, _L("INSERT INTO T (A1, A2) VALUES (:prm1, :prm2)"));
|
sl@0
|
521 |
TEST2(err, KErrNone);
|
sl@0
|
522 |
TPtrC paramName;
|
sl@0
|
523 |
TBuf<128> expectedParamName;
|
sl@0
|
524 |
for(TInt i=0;i<KColTypeCnt;++i)
|
sl@0
|
525 |
{
|
sl@0
|
526 |
expectedParamName.Zero();
|
sl@0
|
527 |
expectedParamName.Append(_L(":prm"));
|
sl@0
|
528 |
expectedParamName.AppendNum(i + 1);
|
sl@0
|
529 |
TInt paramIndex = TheStmt.ParameterIndex(expectedParamName);
|
sl@0
|
530 |
TEST2(paramIndex, i);
|
sl@0
|
531 |
TInt err = TheStmt.ParameterName(i, paramName);
|
sl@0
|
532 |
TEST2(err, KErrNone);
|
sl@0
|
533 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
534 |
err = TheStmt.ParamName(i, paramName);
|
sl@0
|
535 |
TEST2(err, KErrNone);
|
sl@0
|
536 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
537 |
}
|
sl@0
|
538 |
//Too big parameter index
|
sl@0
|
539 |
err = TheStmt.ParamName(1323, paramName);
|
sl@0
|
540 |
TEST2(err, KErrNotFound);
|
sl@0
|
541 |
//Negative parameter index
|
sl@0
|
542 |
err = TheStmt.ParamName(-100, paramName);
|
sl@0
|
543 |
TEST2(err, KErrNotFound);
|
sl@0
|
544 |
TheStmt.Close();
|
sl@0
|
545 |
|
sl@0
|
546 |
//SQL statement without parameters
|
sl@0
|
547 |
err = TheStmt.Prepare(TheDb, _L("INSERT INTO T (A1, A2) VALUES (1, '1')"));
|
sl@0
|
548 |
TEST2(err, KErrNone);
|
sl@0
|
549 |
err = TheStmt.ParamName(0, paramName);
|
sl@0
|
550 |
TEST2(err, KErrNotFound);
|
sl@0
|
551 |
TheStmt.Close();
|
sl@0
|
552 |
|
sl@0
|
553 |
// Create insert statement, then check param names
|
sl@0
|
554 |
err = TheStmt.Prepare(TheDb, _L("INSERT INTO T (A1, A2) VALUES (:prm1, ?)"));
|
sl@0
|
555 |
TEST2(err, KErrNone);
|
sl@0
|
556 |
|
sl@0
|
557 |
expectedParamName.Zero();
|
sl@0
|
558 |
expectedParamName.Append(_L(":prm1"));
|
sl@0
|
559 |
TInt paramIndex = TheStmt.ParameterIndex(expectedParamName);
|
sl@0
|
560 |
TEST2(paramIndex, 0);
|
sl@0
|
561 |
err = TheStmt.ParameterName(0, paramName);
|
sl@0
|
562 |
TEST2(err, KErrNone);
|
sl@0
|
563 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
564 |
err = TheStmt.ParamName(0, paramName);
|
sl@0
|
565 |
TEST2(err, KErrNone);
|
sl@0
|
566 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
567 |
|
sl@0
|
568 |
expectedParamName.Zero();
|
sl@0
|
569 |
expectedParamName.Append(_L("?1"));
|
sl@0
|
570 |
err = TheStmt.ParameterName(1, paramName);
|
sl@0
|
571 |
TEST2(err, KErrNone);
|
sl@0
|
572 |
paramIndex = TheStmt.ParameterIndex(expectedParamName);
|
sl@0
|
573 |
TEST2(paramIndex, 1);
|
sl@0
|
574 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
575 |
|
sl@0
|
576 |
err = TheStmt.ParamName(1, paramName);
|
sl@0
|
577 |
TEST2(err, KErrNone);
|
sl@0
|
578 |
TEST2(paramName.Compare(expectedParamName), 0);
|
sl@0
|
579 |
|
sl@0
|
580 |
TheStmt.Close();
|
sl@0
|
581 |
|
sl@0
|
582 |
//Cleanup
|
sl@0
|
583 |
TheDb.Close();
|
sl@0
|
584 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
585 |
}
|
sl@0
|
586 |
|
sl@0
|
587 |
|
sl@0
|
588 |
/**
|
sl@0
|
589 |
@SYMTestCaseID SYSLIB-SQL-UT-4006
|
sl@0
|
590 |
@SYMTestCaseDesc Test for DEF115300 - SqlSrv.EXE::!SQL Server when preparing invalid LEFT JOIN sql query.
|
sl@0
|
591 |
The test does the following steps:
|
sl@0
|
592 |
1) Creates a 16-bit database and using 16-bit queries proves that the "GROUP BY GROUP BY" syntax error
|
sl@0
|
593 |
does not cause an assert inside the SQLITE code.
|
sl@0
|
594 |
2) Creates a 8-bit database and using 8-bit queries proves that the "GROUP BY GROUP BY" syntax error
|
sl@0
|
595 |
does not cause an assert inside the SQLITE code.
|
sl@0
|
596 |
@SYMTestPriority Medium
|
sl@0
|
597 |
@SYMTestActions Test for DEF115300 - SqlSrv.EXE::!SQL Server when preparing invalid LEFT JOIN sql query.
|
sl@0
|
598 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
599 |
@SYMDEF DEF115300
|
sl@0
|
600 |
*/
|
sl@0
|
601 |
void DEF115300()
|
sl@0
|
602 |
{
|
sl@0
|
603 |
|
sl@0
|
604 |
//Step 1: 16-bit statements
|
sl@0
|
605 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
606 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
607 |
TEST2(err, KErrNone);
|
sl@0
|
608 |
|
sl@0
|
609 |
err = TheDb.Exec(_L("CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
|
sl@0
|
610 |
TEST2(err, 1);
|
sl@0
|
611 |
err = TheDb.Exec(_L("INSERT INTO MAIN(Id,Id1) VALUES(2,3)"));
|
sl@0
|
612 |
TEST2(err, 1);
|
sl@0
|
613 |
err = TheDb.Exec(_L("INSERT INTO MAIN(Id,Id1) VALUES(3,4)"));
|
sl@0
|
614 |
TEST2(err, 1);
|
sl@0
|
615 |
|
sl@0
|
616 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
|
sl@0
|
617 |
TEST2(err, 1);
|
sl@0
|
618 |
err = TheDb.Exec(_L("INSERT INTO A(Id, Id1) VALUES(2,3)"));
|
sl@0
|
619 |
TEST2(err, 1);
|
sl@0
|
620 |
err = TheDb.Exec(_L("INSERT INTO A(Id, Id1) VALUES(4,4)"));
|
sl@0
|
621 |
TEST2(err, 1);
|
sl@0
|
622 |
|
sl@0
|
623 |
err = TheDb.Exec(_L("CREATE TABLE B(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
|
sl@0
|
624 |
TEST2(err, 1);
|
sl@0
|
625 |
err = TheDb.Exec(_L("INSERT INTO B(Id, Id1) VALUES(2,3)"));
|
sl@0
|
626 |
TEST2(err, 1);
|
sl@0
|
627 |
err = TheDb.Exec(_L("INSERT INTO B(Id, Id1) VALUES(5,4)"));
|
sl@0
|
628 |
TEST2(err, 1);
|
sl@0
|
629 |
err = TheDb.Exec(_L("INSERT INTO B(Id, Id1) VALUES(5,4)"));
|
sl@0
|
630 |
TEST2(err, 1);
|
sl@0
|
631 |
|
sl@0
|
632 |
err = TheDb.Exec(_L("CREATE VIEW v2 AS SELECT Id,Id1,F2 FROM B"));
|
sl@0
|
633 |
TEST2(err, 1);
|
sl@0
|
634 |
err = TheDb.Exec(_L("CREATE VIEW v1 AS SELECT Id,Id1,F2 FROM A"));
|
sl@0
|
635 |
TEST2(err, 1);
|
sl@0
|
636 |
err = TheDb.Exec(_L("CREATE VIEW v3 AS SELECT Id,Id1,F2 FROM B"));
|
sl@0
|
637 |
TEST2(err, 1);
|
sl@0
|
638 |
|
sl@0
|
639 |
RSqlStatement stmt;
|
sl@0
|
640 |
err = stmt.Prepare(TheDb, _L("SELECT * FROM v2 LEFT JOIN MAIN ON v2.Id = MAIN.Id LEFT JOIN A ON MAIN.Id = A.Id GROUP BY GROUP BY MAIN.Id"));
|
sl@0
|
641 |
stmt.Close();
|
sl@0
|
642 |
TEST(err != KErrNone && err != KErrServerTerminated);
|
sl@0
|
643 |
|
sl@0
|
644 |
TheDb.Close();
|
sl@0
|
645 |
err = RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
646 |
TEST2(err, KErrNone);
|
sl@0
|
647 |
|
sl@0
|
648 |
//Step 2: 8-bit statements
|
sl@0
|
649 |
_LIT8(KServerConfigString1, "encoding=\"UTF-8\"");
|
sl@0
|
650 |
err = TheDb.Create(KTestDbName1, &KServerConfigString1);
|
sl@0
|
651 |
TEST2(err, KErrNone);
|
sl@0
|
652 |
|
sl@0
|
653 |
err = TheDb.Exec(_L8("CREATE TABLE MAIN(Id INTEGER, Id1 INTEGER, F2 BLOB)"));
|
sl@0
|
654 |
TEST2(err, 1);
|
sl@0
|
655 |
|
sl@0
|
656 |
err = stmt.Prepare(TheDb, _L8("SELECT * FROM main GROUP BY GROUP BY main.Id"));
|
sl@0
|
657 |
stmt.Close();
|
sl@0
|
658 |
TEST(err != KErrNone && err != KErrServerTerminated);
|
sl@0
|
659 |
|
sl@0
|
660 |
TheDb.Close();
|
sl@0
|
661 |
err = RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
662 |
TEST2(err, KErrNone);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
|
sl@0
|
665 |
/**
|
sl@0
|
666 |
@SYMTestCaseID SYSLIB-SQL-UT-4007
|
sl@0
|
667 |
@SYMTestCaseDesc Test for DEF115331 - SQL, bad code coverage for db reindexing if default collation has changed.
|
sl@0
|
668 |
The test does the following steps, using public shared and private secure database:
|
sl@0
|
669 |
1) Creates a test database with a table and one index using one of the collations.
|
sl@0
|
670 |
2) Updates the symbian_settings table, setting the collation dll name column value
|
sl@0
|
671 |
to be a "bbbababz" string (Simulates that there is no valid collation dll name).
|
sl@0
|
672 |
3) Reopens the database. This operation should cause a database reindexing, since the index uses
|
sl@0
|
673 |
one of the user-defined collation methods.
|
sl@0
|
674 |
The default system collation dll name should be stored in the symbian_settings table.
|
sl@0
|
675 |
4) Verifies that symbian_settings table contains only one record and that the collation dll name
|
sl@0
|
676 |
column value has been updated.
|
sl@0
|
677 |
@SYMTestPriority Medium
|
sl@0
|
678 |
@SYMTestActions Test for DEF115331 - SQL, bad code coverage for db reindexing if default collation has changed.
|
sl@0
|
679 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
680 |
@SYMDEF DEF115331
|
sl@0
|
681 |
*/
|
sl@0
|
682 |
void DEF115331L()
|
sl@0
|
683 |
{
|
sl@0
|
684 |
const TPtrC KDbNames[] = {KTestDbName1(), KTestDbName2()};
|
sl@0
|
685 |
|
sl@0
|
686 |
for(TInt i=0;i<(sizeof(KDbNames)/sizeof(KDbNames[0]));++i)
|
sl@0
|
687 |
{
|
sl@0
|
688 |
//Step 1: Create a test database with a table and one index using one of the collations.
|
sl@0
|
689 |
(void)RSqlDatabase::Delete(KDbNames[i]);
|
sl@0
|
690 |
TInt err = TheDb.Create(KDbNames[i]);
|
sl@0
|
691 |
TEST2(err, KErrNone);
|
sl@0
|
692 |
|
sl@0
|
693 |
err = TheDb.Exec(_L("CREATE TABLE A(C TEXT)"));
|
sl@0
|
694 |
TEST2(err, 1);
|
sl@0
|
695 |
|
sl@0
|
696 |
err = TheDb.Exec(_L("CREATE INDEX I ON A(C COLLATE CompareC1)"));
|
sl@0
|
697 |
TEST2(err, 1);
|
sl@0
|
698 |
|
sl@0
|
699 |
//Step 2: Make sure that the collation dll name is set and unique (not the default collation).
|
sl@0
|
700 |
err = TheDb.Exec(_L("UPDATE symbian_settings SET CollationDllName='bbbababz'"));
|
sl@0
|
701 |
TEST2(err, 1);
|
sl@0
|
702 |
|
sl@0
|
703 |
TheDb.Close();
|
sl@0
|
704 |
|
sl@0
|
705 |
//Step 3: Reopen the database. That step should cause a database reindexing, because the default collation dll
|
sl@0
|
706 |
// name is not the one stored in the table.
|
sl@0
|
707 |
err = TheDb.Open(KDbNames[i]);
|
sl@0
|
708 |
TEST2(err, KErrNone);
|
sl@0
|
709 |
|
sl@0
|
710 |
TSqlScalarFullSelectQuery query(TheDb);
|
sl@0
|
711 |
|
sl@0
|
712 |
//Step 4: Check that the settigns table has only one record.
|
sl@0
|
713 |
TInt cnt = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings"));
|
sl@0
|
714 |
TEST2(cnt, 1);
|
sl@0
|
715 |
|
sl@0
|
716 |
//Step 5: Check that the collation dll name in the settings table has been updated.
|
sl@0
|
717 |
TFileName collationDllName;
|
sl@0
|
718 |
err = query.SelectTextL(_L("SELECT CollationDllName FROM symbian_settings"), collationDllName);
|
sl@0
|
719 |
TEST2(err, KErrNone);
|
sl@0
|
720 |
_LIT(KTestCollationDllName, "bbbababz");//The same as the used in step 2 - above.
|
sl@0
|
721 |
TEST(collationDllName != KTestCollationDllName);
|
sl@0
|
722 |
|
sl@0
|
723 |
TheDb.Close();
|
sl@0
|
724 |
err = RSqlDatabase::Delete(KDbNames[i]);
|
sl@0
|
725 |
TEST2(err, KErrNone);
|
sl@0
|
726 |
}
|
sl@0
|
727 |
}
|
sl@0
|
728 |
|
sl@0
|
729 |
/**
|
sl@0
|
730 |
@SYMTestCaseID SYSLIB-SQL-UT-4079
|
sl@0
|
731 |
@SYMTestCaseDesc RSqlDatabase::Create() and RSqlDatabase::Open() - injection test
|
sl@0
|
732 |
The test attempts to create or open a database which name contains
|
sl@0
|
733 |
"DELETE FROM symbian_settings" statement.If it is possible to open or
|
sl@0
|
734 |
create a database with that name, the "symbian_settings" table content
|
sl@0
|
735 |
should stay unchanged.
|
sl@0
|
736 |
@SYMTestPriority Medium
|
sl@0
|
737 |
@SYMTestActions RSqlDatabase::Create() and RSqlDatabase::Open() - injection test
|
sl@0
|
738 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
739 |
@SYMREQ REQ5792
|
sl@0
|
740 |
*/
|
sl@0
|
741 |
void InjectionTest()
|
sl@0
|
742 |
{
|
sl@0
|
743 |
TInt err = TheDb.Create(KDbInjectedName1);
|
sl@0
|
744 |
TEST(err != KErrNone);
|
sl@0
|
745 |
|
sl@0
|
746 |
err = TheDb.Create(KDbInjectedName2);
|
sl@0
|
747 |
TEST2(err, KErrNone);
|
sl@0
|
748 |
|
sl@0
|
749 |
TSqlScalarFullSelectQuery query(TheDb);
|
sl@0
|
750 |
TInt recCount = 0;
|
sl@0
|
751 |
TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings")));
|
sl@0
|
752 |
TEST2(err, KErrNone);
|
sl@0
|
753 |
TEST2(recCount, 1);
|
sl@0
|
754 |
TheDb.Close();
|
sl@0
|
755 |
|
sl@0
|
756 |
err = TheDb.Open(KDbInjectedName2);
|
sl@0
|
757 |
TEST2(err, KErrNone);
|
sl@0
|
758 |
recCount = 0;
|
sl@0
|
759 |
query.SetDatabase(TheDb);
|
sl@0
|
760 |
TRAP(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings")));
|
sl@0
|
761 |
TEST2(err, KErrNone);
|
sl@0
|
762 |
TEST2(recCount, 1);
|
sl@0
|
763 |
TheDb.Close();
|
sl@0
|
764 |
|
sl@0
|
765 |
(void)RSqlDatabase::Delete(KDbInjectedName2);
|
sl@0
|
766 |
(void)RSqlDatabase::Delete(KDbInjectedName1);
|
sl@0
|
767 |
}
|
sl@0
|
768 |
|
sl@0
|
769 |
/**
|
sl@0
|
770 |
@SYMTestCaseID SYSLIB-SQL-UT-4038
|
sl@0
|
771 |
@SYMTestCaseDesc Background compaction - two connections usability test.
|
sl@0
|
772 |
The test creates a database connection with a background compaction mode. The the test
|
sl@0
|
773 |
locks the database in a transaction. Then the test creates a second connection
|
sl@0
|
774 |
to the same database while the first connection is in a transaction.
|
sl@0
|
775 |
@SYMTestPriority Medium
|
sl@0
|
776 |
@SYMTestActions Background compaction - two connections usability test.
|
sl@0
|
777 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
778 |
@SYMREQ REQ10271
|
sl@0
|
779 |
*/
|
sl@0
|
780 |
void TwoConnectionsTest()
|
sl@0
|
781 |
{
|
sl@0
|
782 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
783 |
RSqlDatabase db1, db2;
|
sl@0
|
784 |
TInt err = db1.Create(KTestDbName1);
|
sl@0
|
785 |
TEST2(err, KErrNone);
|
sl@0
|
786 |
err = db1.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A VALUES(1)"));
|
sl@0
|
787 |
TEST2(err, 1);
|
sl@0
|
788 |
err = db1.Exec(_L("BEGIN TRANSACTION"));
|
sl@0
|
789 |
TEST(err >= 0);
|
sl@0
|
790 |
err = db1.Exec(_L("INSERT INTO A VALUES(2)"));
|
sl@0
|
791 |
TEST2(err, 1);
|
sl@0
|
792 |
err = db2.Open(KTestDbName1);
|
sl@0
|
793 |
TEST2(err, KErrNone);
|
sl@0
|
794 |
err = db1.Exec(_L("COMMIT TRANSACTION"));
|
sl@0
|
795 |
TEST(err >= 0);
|
sl@0
|
796 |
db2.Close();
|
sl@0
|
797 |
db1.Close();
|
sl@0
|
798 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
799 |
}
|
sl@0
|
800 |
|
sl@0
|
801 |
TInt StackOverflowThreadFunc(void* aData)
|
sl@0
|
802 |
{
|
sl@0
|
803 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
804 |
TEST(tc != NULL);
|
sl@0
|
805 |
|
sl@0
|
806 |
User::SetJustInTime(EFalse); // disable debugger panic handling
|
sl@0
|
807 |
|
sl@0
|
808 |
TInt* cntptr = reinterpret_cast<TInt*> (aData);
|
sl@0
|
809 |
TEST(cntptr != NULL);
|
sl@0
|
810 |
TInt cnt = *cntptr;
|
sl@0
|
811 |
|
sl@0
|
812 |
HBufC* buf = HBufC::New(cnt * 12 + 32);//enough for the "SELECT Id FROM A WHERE Id=v1 OR Id=v2 OR ..." string
|
sl@0
|
813 |
if(!buf)
|
sl@0
|
814 |
{
|
sl@0
|
815 |
delete tc;
|
sl@0
|
816 |
return KErrNoMemory;
|
sl@0
|
817 |
}
|
sl@0
|
818 |
TPtr sql = buf->Des();
|
sl@0
|
819 |
|
sl@0
|
820 |
TInt err = TheDb.Open(KTestDbName1);
|
sl@0
|
821 |
if(err != KErrNone)
|
sl@0
|
822 |
{
|
sl@0
|
823 |
delete buf;
|
sl@0
|
824 |
delete tc;
|
sl@0
|
825 |
return err;
|
sl@0
|
826 |
}
|
sl@0
|
827 |
|
sl@0
|
828 |
TTime now;
|
sl@0
|
829 |
now.UniversalTime();
|
sl@0
|
830 |
TInt64 seed = now.Int64();
|
sl@0
|
831 |
|
sl@0
|
832 |
sql.Copy(_L("SELECT Id FROM A WHERE "));
|
sl@0
|
833 |
for(TInt i=0;i<cnt;++i)
|
sl@0
|
834 |
{
|
sl@0
|
835 |
sql.Append(_L("Id="));
|
sl@0
|
836 |
sql.AppendNum(Math::Rand(seed) % cnt);
|
sl@0
|
837 |
sql.Append(_L(" OR "));
|
sl@0
|
838 |
}
|
sl@0
|
839 |
sql.SetLength(sql.Length() - 4);//Remove the last " OR "
|
sl@0
|
840 |
|
sl@0
|
841 |
RSqlStatement stmt;
|
sl@0
|
842 |
err = stmt.Prepare(TheDb, sql);
|
sl@0
|
843 |
stmt.Close();
|
sl@0
|
844 |
|
sl@0
|
845 |
TheDb.Close();
|
sl@0
|
846 |
delete buf;
|
sl@0
|
847 |
delete tc;
|
sl@0
|
848 |
|
sl@0
|
849 |
return err;
|
sl@0
|
850 |
}
|
sl@0
|
851 |
|
sl@0
|
852 |
/**
|
sl@0
|
853 |
@SYMTestCaseID SYSLIB-SQL-UT-4080
|
sl@0
|
854 |
@SYMTestCaseDesc SQL server stack overflow test
|
sl@0
|
855 |
The test creates a database and runs a thread. The thread opens the database
|
sl@0
|
856 |
and attempts to execute a SELECT statement, which format is:
|
sl@0
|
857 |
"SELECT Id FROM A WHERE Id=1 OR Id=2 OR...OR Id=N",
|
sl@0
|
858 |
where N is a number passed as an argument from the main thread, starts from 100000
|
sl@0
|
859 |
and is increased or decreased on each test iteration, depending on the reported result from the thread.
|
sl@0
|
860 |
Finally, the main thread will report the max number of the OR subexpressions that can be included
|
sl@0
|
861 |
in the SELECT statement, without an error to be reported.
|
sl@0
|
862 |
The test should not crash the SQL server, if the server stack size and parsing tree depth has
|
sl@0
|
863 |
been properly configured.
|
sl@0
|
864 |
@SYMTestPriority Medium
|
sl@0
|
865 |
@SYMTestActions SQL server stack overflow test
|
sl@0
|
866 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
867 |
@SYMREQ REQ5792
|
sl@0
|
868 |
*/
|
sl@0
|
869 |
void SqlServerStackOverflowTest()
|
sl@0
|
870 |
{
|
sl@0
|
871 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
872 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
873 |
TEST2(err, KErrNone);
|
sl@0
|
874 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER PRIMARY KEY AUTOINCREMENT)"));
|
sl@0
|
875 |
TEST2(err, 1);
|
sl@0
|
876 |
TheDb.Close();
|
sl@0
|
877 |
|
sl@0
|
878 |
TInt prev = 0, next = 100000;
|
sl@0
|
879 |
while(Abs(next - prev) > 0)
|
sl@0
|
880 |
{
|
sl@0
|
881 |
TInt count = next;
|
sl@0
|
882 |
TheTest.Printf(_L("'OR' expr. count: %d\r\n"), count);
|
sl@0
|
883 |
RThread thread;
|
sl@0
|
884 |
_LIT(KThreadName,"ORThread"); //stack minheap maxheap
|
sl@0
|
885 |
err = thread.Create(KThreadName, &StackOverflowThreadFunc, 0x2000, 0x00100000, 0x02000000, &count);
|
sl@0
|
886 |
TEST2(err, KErrNone);
|
sl@0
|
887 |
|
sl@0
|
888 |
TRequestStatus status;
|
sl@0
|
889 |
thread.Logon(status);
|
sl@0
|
890 |
TEST2(status.Int(), KRequestPending);
|
sl@0
|
891 |
thread.Resume();
|
sl@0
|
892 |
User::WaitForRequest(status);
|
sl@0
|
893 |
User::SetJustInTime(ETrue); // enable debugger panic handling
|
sl@0
|
894 |
|
sl@0
|
895 |
TInt exitType = thread.ExitType();
|
sl@0
|
896 |
const TDesC& exitCategory = thread.ExitCategory();
|
sl@0
|
897 |
TInt exitReason = thread.ExitReason();
|
sl@0
|
898 |
TheTest.Printf(_L("Exit type: %d, exit reason: %d, exit category: %S\r\n"), exitType, exitReason, &exitCategory);
|
sl@0
|
899 |
thread.Close();
|
sl@0
|
900 |
TEST(exitReason != KErrServerTerminated);
|
sl@0
|
901 |
TEST(exitType != EExitPanic);
|
sl@0
|
902 |
|
sl@0
|
903 |
TInt tmp = next;
|
sl@0
|
904 |
if(status.Int() != KErrNone)
|
sl@0
|
905 |
{//The number of the OR subexpressions is too big and cannot be parsed. Decrease the number, repeat the test.
|
sl@0
|
906 |
next -= Abs(next - prev) / 2;
|
sl@0
|
907 |
}
|
sl@0
|
908 |
else
|
sl@0
|
909 |
{//KErrNone: The number of the OR subexpressions has been successfully parsed. Increase the number, repeat the test.
|
sl@0
|
910 |
next += Abs(next - prev) / 2;
|
sl@0
|
911 |
}
|
sl@0
|
912 |
prev = tmp;
|
sl@0
|
913 |
}
|
sl@0
|
914 |
TheTest.Printf(_L("The test has succeeded with an expression with %d ORs\r\n"), prev);
|
sl@0
|
915 |
}
|
sl@0
|
916 |
|
sl@0
|
917 |
void AssertSettingsTable()
|
sl@0
|
918 |
{
|
sl@0
|
919 |
TSqlScalarFullSelectQuery query(TheDb);
|
sl@0
|
920 |
TInt recCount = 0;
|
sl@0
|
921 |
TRAPD(err, recCount = query.SelectIntL(_L("SELECT COUNT(*) FROM symbian_settings")));
|
sl@0
|
922 |
TEST2(err, KErrNone);
|
sl@0
|
923 |
TEST2(recCount, 1);
|
sl@0
|
924 |
}
|
sl@0
|
925 |
|
sl@0
|
926 |
/**
|
sl@0
|
927 |
@SYMTestCaseID SYSLIB-SQL-UT-4086
|
sl@0
|
928 |
@SYMTestCaseDesc RSqlBlobWriteStream::OpenL() and RSqlBlobReadStream::OpenL() - injection test
|
sl@0
|
929 |
The test attempts to open a blob stream with an attached database name containing
|
sl@0
|
930 |
"DELETE FROM symbian_settings" statement. The test should not delete the content of the
|
sl@0
|
931 |
"symbian_settings" table.
|
sl@0
|
932 |
The test also attempts to open a blob stream with a set of very long database/table/column names.
|
sl@0
|
933 |
@SYMTestPriority Medium
|
sl@0
|
934 |
@SYMTestActions RSqlBlobWriteStream::OpenL() and RSqlBlobReadStream::OpenL() - injection test
|
sl@0
|
935 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
936 |
@SYMREQ REQ5792
|
sl@0
|
937 |
REQ10410
|
sl@0
|
938 |
REQ10411
|
sl@0
|
939 |
REQ10418
|
sl@0
|
940 |
*/
|
sl@0
|
941 |
void BlobStreamInjectionTest()
|
sl@0
|
942 |
{
|
sl@0
|
943 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
944 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
945 |
TEST2(err, KErrNone);
|
sl@0
|
946 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER,Data BLOB)"));
|
sl@0
|
947 |
TEST2(err, 1);
|
sl@0
|
948 |
err = TheDb.Exec(_L("INSERT INTO A VALUES(1, x'11223344556677889900')"));
|
sl@0
|
949 |
TEST2(err, 1);
|
sl@0
|
950 |
_LIT(KAttachDb, "AttachDb");
|
sl@0
|
951 |
err = TheDb.Attach(KTestDbName1, KAttachDb);
|
sl@0
|
952 |
TEST2(err, KErrNone);
|
sl@0
|
953 |
//RSqlBlobWriteStream::OpenL() - attached database name injected
|
sl@0
|
954 |
RSqlBlobWriteStream strm1;
|
sl@0
|
955 |
TRAP(err, strm1.OpenL(TheDb, _L("A"), _L("Data"), 1, _L("Id;DELETE FROM symbian_settings;")));
|
sl@0
|
956 |
TEST(err != KErrNone);
|
sl@0
|
957 |
AssertSettingsTable();
|
sl@0
|
958 |
//RSqlBlobReadStream::OpenL() - attached database name injected
|
sl@0
|
959 |
RSqlBlobReadStream strm2;
|
sl@0
|
960 |
TRAP(err, strm2.OpenL(TheDb, _L("A"), _L("Data"), 1, _L("Id;DELETE FROM symbian_settings;")));
|
sl@0
|
961 |
TEST(err != KErrNone);
|
sl@0
|
962 |
AssertSettingsTable();
|
sl@0
|
963 |
//Attempt to open a write blob stream with a set of very long database/table/column names.
|
sl@0
|
964 |
TBuf<KMaxFileName + 10> longName;
|
sl@0
|
965 |
longName.SetLength(longName.MaxLength());
|
sl@0
|
966 |
RSqlBlobWriteStream strm3;
|
sl@0
|
967 |
TRAP(err, strm3.OpenL(TheDb, longName, longName, 1, longName));
|
sl@0
|
968 |
TEST(err != KErrNone);
|
sl@0
|
969 |
//Attempt to open a read blob stream with a set of very long database/table/column names.
|
sl@0
|
970 |
RSqlBlobReadStream strm4;
|
sl@0
|
971 |
TRAP(err, strm4.OpenL(TheDb, longName, longName, 1, longName));
|
sl@0
|
972 |
TEST(err != KErrNone);
|
sl@0
|
973 |
//Attempt to open a write blob stream with a set of KNullDesC database/table/column names.
|
sl@0
|
974 |
RSqlBlobWriteStream strm5;
|
sl@0
|
975 |
TRAP(err, strm5.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
|
sl@0
|
976 |
TEST(err != KErrNone);
|
sl@0
|
977 |
//Attempt to open a read blob stream with a set of KNullDesC database/table/column names.
|
sl@0
|
978 |
RSqlBlobReadStream strm6;
|
sl@0
|
979 |
TRAP(err, strm6.OpenL(TheDb, KNullDesC, KNullDesC, 1, KNullDesC));
|
sl@0
|
980 |
TEST(err != KErrNone);
|
sl@0
|
981 |
//Attempt to open a read blob stream, where the blob column name is invalid and contains non-convertible characters.
|
sl@0
|
982 |
TBuf<3> invName;
|
sl@0
|
983 |
invName.SetLength(3);
|
sl@0
|
984 |
invName[0] = TChar(0xD800);
|
sl@0
|
985 |
invName[1] = TChar(0xFC00);
|
sl@0
|
986 |
invName[2] = TChar(0x0000);
|
sl@0
|
987 |
RSqlBlobReadStream strm7;
|
sl@0
|
988 |
TRAP(err, strm7.OpenL(TheDb, _L("A"), invName, 1, KNullDesC));
|
sl@0
|
989 |
TEST(err != KErrNone);
|
sl@0
|
990 |
//Attempt to open a read blob stream, where the table name is invalid and contains non-convertible characters.
|
sl@0
|
991 |
RSqlBlobReadStream strm8;
|
sl@0
|
992 |
TRAP(err, strm8.OpenL(TheDb, invName, _L("Data"), 1, KNullDesC));
|
sl@0
|
993 |
TEST(err != KErrNone);
|
sl@0
|
994 |
//Attempt to open a read blob stream, where the attached db name is invalid and contains non-convertible characters.
|
sl@0
|
995 |
RSqlBlobReadStream strm9;
|
sl@0
|
996 |
TRAP(err, strm9.OpenL(TheDb, _L("A"), _L("Data"), 1, invName));
|
sl@0
|
997 |
TEST(err != KErrNone);
|
sl@0
|
998 |
//
|
sl@0
|
999 |
err = TheDb.Detach(KAttachDb);
|
sl@0
|
1000 |
TEST2(err, KErrNone);
|
sl@0
|
1001 |
TheDb.Close();
|
sl@0
|
1002 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1003 |
}
|
sl@0
|
1004 |
|
sl@0
|
1005 |
/**
|
sl@0
|
1006 |
@SYMTestCaseID SYSLIB-SQL-UT-4087
|
sl@0
|
1007 |
@SYMTestCaseDesc Bound parameter values test.
|
sl@0
|
1008 |
The test verifies that bound parameters with big text/binary values retain their values after
|
sl@0
|
1009 |
the RSqlStatement::Reset() call. The old bound paramegter values can be used for the next
|
sl@0
|
1010 |
RSqlStatement::Exec() call.
|
sl@0
|
1011 |
@SYMTestActions Bound parameter values test.
|
sl@0
|
1012 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1013 |
@SYMTestPriority High
|
sl@0
|
1014 |
@SYMREQ REQ5792
|
sl@0
|
1015 |
*/
|
sl@0
|
1016 |
void BoundParameterValuesTest()
|
sl@0
|
1017 |
{
|
sl@0
|
1018 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1019 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1020 |
TEST2(err, KErrNone);
|
sl@0
|
1021 |
err = TheDb.Exec(_L("CREATE TABLE A1(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1022 |
TEST2(err, 1);
|
sl@0
|
1023 |
err = TheDb.Exec(_L("CREATE TABLE A2(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1024 |
TEST2(err, 1);
|
sl@0
|
1025 |
|
sl@0
|
1026 |
RSqlStatement stmt1, stmt2;
|
sl@0
|
1027 |
err = stmt1.Prepare(TheDb, _L("INSERT INTO A1 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1028 |
TEST2(err, KErrNone);
|
sl@0
|
1029 |
err = stmt2.Prepare(TheDb, _L("INSERT INTO A2 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1030 |
TEST2(err, KErrNone);
|
sl@0
|
1031 |
//Insert 1 record into table "A1". T2 = "ZZZZ.....".
|
sl@0
|
1032 |
TheBuf.SetLength(KBufLen - 100);
|
sl@0
|
1033 |
TheBuf.Fill(TChar('Z'));
|
sl@0
|
1034 |
err = stmt1.BindText(0, TheBuf);
|
sl@0
|
1035 |
TEST2(err, KErrNone);
|
sl@0
|
1036 |
err = stmt1.BindText(1, TheBuf);
|
sl@0
|
1037 |
TEST2(err, KErrNone);
|
sl@0
|
1038 |
err = stmt1.Exec();
|
sl@0
|
1039 |
TEST2(err, 1);
|
sl@0
|
1040 |
err = stmt1.Reset();
|
sl@0
|
1041 |
TEST2(err, KErrNone);
|
sl@0
|
1042 |
//Insert 1 record into table "A2". T2 = "AAAAAAA.....".
|
sl@0
|
1043 |
TheBuf.SetLength(KBufLen);
|
sl@0
|
1044 |
TheBuf.Fill(TChar('A'));
|
sl@0
|
1045 |
err = stmt2.BindText(0, TheBuf);
|
sl@0
|
1046 |
TEST2(err, KErrNone);
|
sl@0
|
1047 |
err = stmt2.BindText(1, TheBuf);
|
sl@0
|
1048 |
TEST2(err, KErrNone);
|
sl@0
|
1049 |
err = stmt2.Exec();
|
sl@0
|
1050 |
TEST2(err, 1);
|
sl@0
|
1051 |
err = stmt2.Reset();
|
sl@0
|
1052 |
TEST2(err, KErrNone);
|
sl@0
|
1053 |
//Insert 1 record into table "A1". T2 not set. T2 should be initialized with the previous bound value - "ZZZZZZ....".
|
sl@0
|
1054 |
//If the problem is not fixed, the SQLITE will attempt to access an already deleted region of memory.
|
sl@0
|
1055 |
TheBuf.SetLength(KBufLen - 100);
|
sl@0
|
1056 |
TheBuf.Fill(TChar('B'));
|
sl@0
|
1057 |
err = stmt1.BindText(0, TheBuf);
|
sl@0
|
1058 |
TEST2(err, KErrNone);
|
sl@0
|
1059 |
err = stmt1.Exec();
|
sl@0
|
1060 |
TEST2(err, 1);
|
sl@0
|
1061 |
err = stmt1.Reset();
|
sl@0
|
1062 |
TEST2(err, KErrNone);
|
sl@0
|
1063 |
|
sl@0
|
1064 |
stmt2.Close();
|
sl@0
|
1065 |
stmt1.Close();
|
sl@0
|
1066 |
|
sl@0
|
1067 |
//Check the inserted records.
|
sl@0
|
1068 |
TSqlScalarFullSelectQuery q(TheDb);
|
sl@0
|
1069 |
TRAP(err, q.SelectTextL(_L("SELECT T2 FROM A1 WHERE ROWID=1"), TheBuf));
|
sl@0
|
1070 |
TEST2(err, KErrNone);
|
sl@0
|
1071 |
TEST2(TheBuf.Length(), (KBufLen - 100));
|
sl@0
|
1072 |
for(TInt i1=0;i1<(KBufLen - 100);++i1)
|
sl@0
|
1073 |
{
|
sl@0
|
1074 |
TEST2(TheBuf[i1], TChar('Z'));
|
sl@0
|
1075 |
}
|
sl@0
|
1076 |
TRAP(err, q.SelectTextL(_L("SELECT T2 FROM A1 WHERE ROWID=2"), TheBuf));
|
sl@0
|
1077 |
TEST2(err, KErrNone);
|
sl@0
|
1078 |
TEST2(TheBuf.Length(), (KBufLen - 100));
|
sl@0
|
1079 |
for(TInt i2=0;i2<(KBufLen - 100);++i2)
|
sl@0
|
1080 |
{
|
sl@0
|
1081 |
TEST2(TheBuf[i2], TChar('Z'));
|
sl@0
|
1082 |
}
|
sl@0
|
1083 |
|
sl@0
|
1084 |
TheDb.Close();
|
sl@0
|
1085 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1086 |
}
|
sl@0
|
1087 |
|
sl@0
|
1088 |
/**
|
sl@0
|
1089 |
@SYMTestCaseID SYSLIB-SQL-UT-4076
|
sl@0
|
1090 |
@SYMTestCaseDesc Bound parameter values test.
|
sl@0
|
1091 |
The test verifies that when a RSqlParamWriteStream object is used for binding parameter values,
|
sl@0
|
1092 |
it is safe to erverse the order of RSqlParamWriteStream::Close() and RSqlStatement::Close() calls.
|
sl@0
|
1093 |
@SYMTestActions Bound parameter values test.
|
sl@0
|
1094 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1095 |
@SYMTestPriority High
|
sl@0
|
1096 |
@SYMREQ REQ5792
|
sl@0
|
1097 |
*/
|
sl@0
|
1098 |
void BoundParameterValuesTest2()
|
sl@0
|
1099 |
{
|
sl@0
|
1100 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1101 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1102 |
TEST2(err, KErrNone);
|
sl@0
|
1103 |
err = TheDb.Exec(_L("CREATE TABLE A1(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1104 |
TEST2(err, 1);
|
sl@0
|
1105 |
|
sl@0
|
1106 |
RSqlStatement stmt;
|
sl@0
|
1107 |
err = stmt.Prepare(TheDb, _L("INSERT INTO A1 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1108 |
TEST2(err, KErrNone);
|
sl@0
|
1109 |
RSqlParamWriteStream strm;
|
sl@0
|
1110 |
err = strm.BindText(stmt, 0);
|
sl@0
|
1111 |
TEST2(err, KErrNone);
|
sl@0
|
1112 |
err = stmt.Exec();
|
sl@0
|
1113 |
TEST2(err, 1);
|
sl@0
|
1114 |
stmt.Close();
|
sl@0
|
1115 |
strm.Close();
|
sl@0
|
1116 |
|
sl@0
|
1117 |
TheDb.Close();
|
sl@0
|
1118 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1119 |
}
|
sl@0
|
1120 |
|
sl@0
|
1121 |
/**
|
sl@0
|
1122 |
@SYMTestCaseID SYSLIB-SQL-UT-4077
|
sl@0
|
1123 |
@SYMTestCaseDesc Bound parameter values test.
|
sl@0
|
1124 |
The test verifies that when a RSqlParamWriteStream object is used for binding parameter values,
|
sl@0
|
1125 |
it is possible to write the parameter value, then call RSqlParamWriteStream::Close() and finally -
|
sl@0
|
1126 |
RSqlStatement::Exec() to execute the operation (an INSERT statement). The test verifies that the record
|
sl@0
|
1127 |
has really been inserted and the column value is equal to the bound parameter value
|
sl@0
|
1128 |
@SYMTestActions Bound parameter values test.
|
sl@0
|
1129 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1130 |
@SYMTestPriority High
|
sl@0
|
1131 |
@SYMREQ REQ5792
|
sl@0
|
1132 |
*/
|
sl@0
|
1133 |
void BoundParameterValuesTest3()
|
sl@0
|
1134 |
{
|
sl@0
|
1135 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1136 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1137 |
TEST2(err, KErrNone);
|
sl@0
|
1138 |
err = TheDb.Exec(_L("CREATE TABLE A1(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1139 |
TEST2(err, 1);
|
sl@0
|
1140 |
|
sl@0
|
1141 |
RSqlStatement stmt;
|
sl@0
|
1142 |
err = stmt.Prepare(TheDb, _L("INSERT INTO A1 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1143 |
TEST2(err, KErrNone);
|
sl@0
|
1144 |
RSqlParamWriteStream strm;
|
sl@0
|
1145 |
err = strm.BindText(stmt, 0);
|
sl@0
|
1146 |
TEST2(err, KErrNone);
|
sl@0
|
1147 |
_LIT(KText, "AAAA");
|
sl@0
|
1148 |
TRAP(err, strm.WriteL(KText));
|
sl@0
|
1149 |
TEST2(err, KErrNone);
|
sl@0
|
1150 |
TRAP(err, strm.CommitL());
|
sl@0
|
1151 |
TEST2(err, KErrNone);
|
sl@0
|
1152 |
strm.Close();
|
sl@0
|
1153 |
err = stmt.Exec();
|
sl@0
|
1154 |
TEST2(err, 1);
|
sl@0
|
1155 |
stmt.Close();
|
sl@0
|
1156 |
|
sl@0
|
1157 |
TSqlScalarFullSelectQuery q(TheDb);
|
sl@0
|
1158 |
TRAP(err, q.SelectTextL(_L("SELECT T1 FROM A1"), TheBuf));
|
sl@0
|
1159 |
TEST2(err, KErrNone);
|
sl@0
|
1160 |
TEST(KText() == TheBuf);
|
sl@0
|
1161 |
|
sl@0
|
1162 |
TheDb.Close();
|
sl@0
|
1163 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1164 |
}
|
sl@0
|
1165 |
|
sl@0
|
1166 |
/**
|
sl@0
|
1167 |
@SYMTestCaseID SYSLIB-SQL-UT-4083
|
sl@0
|
1168 |
@SYMTestCaseDesc Bound parameter values test.
|
sl@0
|
1169 |
The test prepares an INSERT sql statement and inserts two records using streams to bind the parameter values.
|
sl@0
|
1170 |
For the second INSERT no parameter value is bound to the first parameter. The expectation is that the value
|
sl@0
|
1171 |
that has been bound for the first record will be used for the second record also.
|
sl@0
|
1172 |
@SYMTestActions Bound parameter values test.
|
sl@0
|
1173 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1174 |
@SYMTestPriority High
|
sl@0
|
1175 |
@SYMREQ REQ5792
|
sl@0
|
1176 |
*/
|
sl@0
|
1177 |
void BoundParameterValuesTest4()
|
sl@0
|
1178 |
{
|
sl@0
|
1179 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1180 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1181 |
TEST2(err, KErrNone);
|
sl@0
|
1182 |
err = TheDb.Exec(_L("CREATE TABLE A1(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1183 |
TEST2(err, 1);
|
sl@0
|
1184 |
|
sl@0
|
1185 |
RSqlStatement stmt;
|
sl@0
|
1186 |
err = stmt.Prepare(TheDb, _L("INSERT INTO A1 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1187 |
TEST2(err, KErrNone);
|
sl@0
|
1188 |
|
sl@0
|
1189 |
RSqlParamWriteStream strm;
|
sl@0
|
1190 |
err = strm.BindText(stmt, 0);
|
sl@0
|
1191 |
TEST2(err, KErrNone);
|
sl@0
|
1192 |
_LIT(KText1, "AAAA");
|
sl@0
|
1193 |
TRAP(err, strm.WriteL(KText1));
|
sl@0
|
1194 |
TEST2(err, KErrNone);
|
sl@0
|
1195 |
TRAP(err, strm.CommitL());
|
sl@0
|
1196 |
TEST2(err, KErrNone);
|
sl@0
|
1197 |
strm.Close();
|
sl@0
|
1198 |
|
sl@0
|
1199 |
err = strm.BindText(stmt, 1);
|
sl@0
|
1200 |
TEST2(err, KErrNone);
|
sl@0
|
1201 |
_LIT(KText2, "BBBBBBBBBB");
|
sl@0
|
1202 |
TRAP(err, strm.WriteL(KText2));
|
sl@0
|
1203 |
TEST2(err, KErrNone);
|
sl@0
|
1204 |
TRAP(err, strm.CommitL());
|
sl@0
|
1205 |
TEST2(err, KErrNone);
|
sl@0
|
1206 |
strm.Close();
|
sl@0
|
1207 |
|
sl@0
|
1208 |
err = stmt.Exec();
|
sl@0
|
1209 |
TEST2(err, 1);
|
sl@0
|
1210 |
err = stmt.Reset();
|
sl@0
|
1211 |
TEST2(err, KErrNone);
|
sl@0
|
1212 |
|
sl@0
|
1213 |
err = strm.BindText(stmt, 1);
|
sl@0
|
1214 |
TEST2(err, KErrNone);
|
sl@0
|
1215 |
_LIT(KText3, "CCCCCCCCCCC");
|
sl@0
|
1216 |
TRAP(err, strm.WriteL(KText3));
|
sl@0
|
1217 |
TEST2(err, KErrNone);
|
sl@0
|
1218 |
TRAP(err, strm.CommitL());
|
sl@0
|
1219 |
TEST2(err, KErrNone);
|
sl@0
|
1220 |
strm.Close();
|
sl@0
|
1221 |
|
sl@0
|
1222 |
err = stmt.Exec();
|
sl@0
|
1223 |
TEST2(err, 1);
|
sl@0
|
1224 |
|
sl@0
|
1225 |
stmt.Close();
|
sl@0
|
1226 |
|
sl@0
|
1227 |
TSqlScalarFullSelectQuery q(TheDb);
|
sl@0
|
1228 |
TRAP(err, q.SelectTextL(_L("SELECT T1 FROM A1 WHERE ROWID=1"), TheBuf));
|
sl@0
|
1229 |
TEST2(err, KErrNone);
|
sl@0
|
1230 |
TEST(KText1() == TheBuf);
|
sl@0
|
1231 |
TRAP(err, q.SelectTextL(_L("SELECT T2 FROM A1 WHERE ROWID=1"), TheBuf));
|
sl@0
|
1232 |
TEST2(err, KErrNone);
|
sl@0
|
1233 |
TEST(KText2() == TheBuf);
|
sl@0
|
1234 |
|
sl@0
|
1235 |
TRAP(err, q.SelectTextL(_L("SELECT T1 FROM A1 WHERE ROWID=2"), TheBuf));
|
sl@0
|
1236 |
TEST2(err, KErrNone);
|
sl@0
|
1237 |
TEST(KText1() == TheBuf);
|
sl@0
|
1238 |
TRAP(err, q.SelectTextL(_L("SELECT T2 FROM A1 WHERE ROWID=2"), TheBuf));
|
sl@0
|
1239 |
TEST2(err, KErrNone);
|
sl@0
|
1240 |
TEST(KText3() == TheBuf);
|
sl@0
|
1241 |
|
sl@0
|
1242 |
TheDb.Close();
|
sl@0
|
1243 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1244 |
}
|
sl@0
|
1245 |
|
sl@0
|
1246 |
/**
|
sl@0
|
1247 |
@SYMTestCaseID SYSLIB-SQL-UT-4105
|
sl@0
|
1248 |
@SYMTestCaseDesc Bound parameter values test.
|
sl@0
|
1249 |
BC test. Even though it is correct to execute only one CommitL() on a parameter stream,
|
sl@0
|
1250 |
it should be possible to execute more than one CommitL(). It should be possible also
|
sl@0
|
1251 |
the stream data to be updated after the first commit operation and the expectation is that
|
sl@0
|
1252 |
the updated parameter data should be used for the column value.
|
sl@0
|
1253 |
@SYMTestActions Bound parameter values test.
|
sl@0
|
1254 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1255 |
@SYMTestPriority High
|
sl@0
|
1256 |
@SYMREQ REQ5792
|
sl@0
|
1257 |
*/
|
sl@0
|
1258 |
void BoundParameterValuesTest5()
|
sl@0
|
1259 |
{
|
sl@0
|
1260 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1261 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1262 |
TEST2(err, KErrNone);
|
sl@0
|
1263 |
err = TheDb.Exec(_L("CREATE TABLE A1(T1 TEXT, T2 TEXT)"));
|
sl@0
|
1264 |
TEST2(err, 1);
|
sl@0
|
1265 |
|
sl@0
|
1266 |
RSqlStatement stmt;
|
sl@0
|
1267 |
err = stmt.Prepare(TheDb, _L("INSERT INTO A1 VALUES(:Prm1, :Prm2)"));
|
sl@0
|
1268 |
TEST2(err, KErrNone);
|
sl@0
|
1269 |
|
sl@0
|
1270 |
RSqlParamWriteStream strm;
|
sl@0
|
1271 |
err = strm.BindText(stmt, 0);
|
sl@0
|
1272 |
TEST2(err, KErrNone);
|
sl@0
|
1273 |
_LIT(KText1, "AAAA");
|
sl@0
|
1274 |
TRAP(err, strm.WriteL(KText1));
|
sl@0
|
1275 |
TEST2(err, KErrNone);
|
sl@0
|
1276 |
TRAP(err, strm.CommitL());
|
sl@0
|
1277 |
TEST2(err, KErrNone);
|
sl@0
|
1278 |
TRAP(err, strm.Sink()->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0));
|
sl@0
|
1279 |
TEST2(err, KErrNone);
|
sl@0
|
1280 |
_LIT(KText2, "DTAA");
|
sl@0
|
1281 |
TRAP(err, strm.WriteL(KText2));
|
sl@0
|
1282 |
TEST2(err, KErrNone);
|
sl@0
|
1283 |
TRAP(err, strm.CommitL());
|
sl@0
|
1284 |
TEST2(err, KErrNone);
|
sl@0
|
1285 |
strm.Close();
|
sl@0
|
1286 |
|
sl@0
|
1287 |
err = stmt.Exec();
|
sl@0
|
1288 |
TEST2(err, 1);
|
sl@0
|
1289 |
|
sl@0
|
1290 |
stmt.Close();
|
sl@0
|
1291 |
|
sl@0
|
1292 |
TSqlScalarFullSelectQuery q(TheDb);
|
sl@0
|
1293 |
TRAP(err, q.SelectTextL(_L("SELECT T1 FROM A1 WHERE ROWID=1"), TheBuf));
|
sl@0
|
1294 |
TEST2(err, KErrNone);
|
sl@0
|
1295 |
TEST(KText2() == TheBuf);
|
sl@0
|
1296 |
|
sl@0
|
1297 |
TheDb.Close();
|
sl@0
|
1298 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1299 |
}
|
sl@0
|
1300 |
|
sl@0
|
1301 |
void PrintConfig(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1302 |
{
|
sl@0
|
1303 |
TBuf8<128> config;
|
sl@0
|
1304 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterConfig, config) == KErrNone)
|
sl@0
|
1305 |
{
|
sl@0
|
1306 |
_LIT(KCacheSize, "Cache size: %S pages\r\n");
|
sl@0
|
1307 |
_LIT(KPageSize, "Page size: %S bytes\r\n");
|
sl@0
|
1308 |
_LIT(KEncoding, "Encoding: %S\r\n");
|
sl@0
|
1309 |
_LIT(KDefaultSoftHeapLimit, "Default soft heap limit: %S Kb\r\n");
|
sl@0
|
1310 |
_LIT(KVacuumMode, "Vacuum mode: %S\r\n");
|
sl@0
|
1311 |
|
sl@0
|
1312 |
TPtrC KText[] = {KCacheSize(), KPageSize(), KEncoding(), KDefaultSoftHeapLimit(), KVacuumMode()};
|
sl@0
|
1313 |
|
sl@0
|
1314 |
for(TInt i=0;i<config.Length();++i)
|
sl@0
|
1315 |
{
|
sl@0
|
1316 |
if(config[i] == TChar(';'))
|
sl@0
|
1317 |
{
|
sl@0
|
1318 |
config[i] = TChar(' ');
|
sl@0
|
1319 |
}
|
sl@0
|
1320 |
}
|
sl@0
|
1321 |
TInt idx = 0;
|
sl@0
|
1322 |
TLex8 lex(config);
|
sl@0
|
1323 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1324 |
{
|
sl@0
|
1325 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1326 |
TBuf<20> num;
|
sl@0
|
1327 |
num.Copy(num8);
|
sl@0
|
1328 |
TheTest.Printf(KText[idx], &num);
|
sl@0
|
1329 |
++idx;
|
sl@0
|
1330 |
}
|
sl@0
|
1331 |
}
|
sl@0
|
1332 |
}
|
sl@0
|
1333 |
|
sl@0
|
1334 |
void PrintFileIo(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1335 |
{
|
sl@0
|
1336 |
TBuf8<300> countersValues;
|
sl@0
|
1337 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterFileIO, countersValues) == KErrNone)
|
sl@0
|
1338 |
{
|
sl@0
|
1339 |
TheTest.Printf(_L("=========================\r\n"));
|
sl@0
|
1340 |
_LIT(KFileCreate, "File Create");
|
sl@0
|
1341 |
_LIT(KFileOpen, "File Open");
|
sl@0
|
1342 |
_LIT(KFileClose, "File Close");
|
sl@0
|
1343 |
_LIT(KFileDelete, "File Delete");
|
sl@0
|
1344 |
_LIT(KFileRead, "File Read");
|
sl@0
|
1345 |
_LIT(KFileWrite, "File Write");
|
sl@0
|
1346 |
_LIT(KFileSeek, "File Seek");
|
sl@0
|
1347 |
_LIT(KFileSize, "File Size");
|
sl@0
|
1348 |
_LIT(KFileSetSize, "File SetSize");
|
sl@0
|
1349 |
_LIT(KFileSync, "File Sync");
|
sl@0
|
1350 |
_LIT(KFileDrive, "File Drive");
|
sl@0
|
1351 |
_LIT(KFileAdopt, "File Adopt");
|
sl@0
|
1352 |
_LIT(KFsClose, "Fs Close");
|
sl@0
|
1353 |
_LIT(KFsConnect, "Fs Connect");
|
sl@0
|
1354 |
_LIT(KFsGetSystemDrive, "Fs GetSystemDrive");
|
sl@0
|
1355 |
_LIT(KFsCreatePrivatePath, "Fs CreatePrivatePath");
|
sl@0
|
1356 |
_LIT(KFsPrivatePath, "Fs PrivatePath");
|
sl@0
|
1357 |
_LIT(KFsVolumeIoParam, "Fs VolumeIoParam");
|
sl@0
|
1358 |
_LIT(KFsEntry, "Fs Entry");
|
sl@0
|
1359 |
_LIT(KFsAtt, "Fs Att");
|
sl@0
|
1360 |
_LIT(KFileCreateTemp, "File CreateTemp");
|
sl@0
|
1361 |
_LIT(KFileAttach, "File Attach");
|
sl@0
|
1362 |
_LIT(KBytesWritten, "File Bytes Written");
|
sl@0
|
1363 |
_LIT(KBytesRead, "File Bytes Read");
|
sl@0
|
1364 |
TPtrC KText[] =
|
sl@0
|
1365 |
{
|
sl@0
|
1366 |
KFileCreate(), KFileOpen(), KFileClose(), KFileDelete(), KFileRead(), KFileWrite(), KFileSeek(), KFileSize(),
|
sl@0
|
1367 |
KFileSetSize(), KFileSync(), KFileDrive(), KFileAdopt(), KFsClose(), KFsConnect(), KFsGetSystemDrive(),
|
sl@0
|
1368 |
KFsCreatePrivatePath(), KFsPrivatePath(), KFsVolumeIoParam(), KFsEntry(), KFsAtt(), KFileCreateTemp(),
|
sl@0
|
1369 |
KFileAttach(), KBytesWritten(), KBytesRead()
|
sl@0
|
1370 |
};
|
sl@0
|
1371 |
|
sl@0
|
1372 |
for(TInt i=0;i<countersValues.Length();++i)
|
sl@0
|
1373 |
{
|
sl@0
|
1374 |
if(countersValues[i] == TChar(';'))
|
sl@0
|
1375 |
{
|
sl@0
|
1376 |
countersValues[i] = TChar(' ');
|
sl@0
|
1377 |
}
|
sl@0
|
1378 |
}
|
sl@0
|
1379 |
TInt idx = 0;
|
sl@0
|
1380 |
TLex8 lex(countersValues);
|
sl@0
|
1381 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1382 |
{
|
sl@0
|
1383 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1384 |
TBuf<20> num;
|
sl@0
|
1385 |
num.Copy(num8);
|
sl@0
|
1386 |
TheTest.Printf(_L("==Operation %S, count %S\r\n"), &KText[idx], &num);
|
sl@0
|
1387 |
++idx;
|
sl@0
|
1388 |
}
|
sl@0
|
1389 |
}
|
sl@0
|
1390 |
}
|
sl@0
|
1391 |
|
sl@0
|
1392 |
void PrintOsCall(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1393 |
{
|
sl@0
|
1394 |
TBuf8<300> countersValues;
|
sl@0
|
1395 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterOsCall, countersValues) == KErrNone)
|
sl@0
|
1396 |
{
|
sl@0
|
1397 |
TheTest.Printf(_L("=========================\r\n"));
|
sl@0
|
1398 |
_LIT(KEOsFileClose, "FileClose");
|
sl@0
|
1399 |
_LIT(KEOsFileRead, "FileRead");
|
sl@0
|
1400 |
_LIT(KEOsFileWrite, "FileWrite");
|
sl@0
|
1401 |
_LIT(KEOsFileTruncate, "FileTruncate");
|
sl@0
|
1402 |
_LIT(KEOsFileSync, "FileSync");
|
sl@0
|
1403 |
_LIT(KEOsFileFileSize, "FileSize");
|
sl@0
|
1404 |
_LIT(KEOsFileLock, "FileLock");
|
sl@0
|
1405 |
_LIT(KEOsFileUnlock, "FileUnlock");
|
sl@0
|
1406 |
_LIT(KEOsFileCheckReservedLock, "FileCheckReservedLock");
|
sl@0
|
1407 |
_LIT(KEOsFileFileControl, "FileIoControl");
|
sl@0
|
1408 |
_LIT(KEOsFileSectorSize, "FileSectorSize");
|
sl@0
|
1409 |
_LIT(KEOsFileDeviceCharacteristics, "FileDeviceCharacteristics");
|
sl@0
|
1410 |
_LIT(KEOsVfsOpen, "VfsOpen");
|
sl@0
|
1411 |
_LIT(KEOsVfsDelete, "VfsDelete");
|
sl@0
|
1412 |
_LIT(KEOsVfsAccess, "VfsAccess");
|
sl@0
|
1413 |
_LIT(KEOsVfsFullPathName, "VfsFullPathName");
|
sl@0
|
1414 |
_LIT(KEOsVfsRandomness, "VfsRandomnes");
|
sl@0
|
1415 |
_LIT(KEOsVfsSleep, "VfsSleep");
|
sl@0
|
1416 |
_LIT(KEOsVfsCurrentTime, "VfsCurrentTime");
|
sl@0
|
1417 |
_LIT(KEOsVfsGetLastError, "VfsGetLastError");
|
sl@0
|
1418 |
TPtrC KText[] =
|
sl@0
|
1419 |
{
|
sl@0
|
1420 |
KEOsFileClose(), KEOsFileRead(), KEOsFileWrite(), KEOsFileTruncate(), KEOsFileSync(),
|
sl@0
|
1421 |
KEOsFileFileSize(), KEOsFileLock(), KEOsFileUnlock(), KEOsFileCheckReservedLock(), KEOsFileFileControl(),
|
sl@0
|
1422 |
KEOsFileSectorSize(), KEOsFileDeviceCharacteristics(),
|
sl@0
|
1423 |
KEOsVfsOpen(), KEOsVfsDelete(), KEOsVfsAccess(), KEOsVfsFullPathName(), KEOsVfsRandomness(), KEOsVfsSleep(),
|
sl@0
|
1424 |
KEOsVfsCurrentTime(), KEOsVfsGetLastError()};
|
sl@0
|
1425 |
|
sl@0
|
1426 |
for(TInt i=0;i<countersValues.Length();++i)
|
sl@0
|
1427 |
{
|
sl@0
|
1428 |
if(countersValues[i] == TChar(';'))
|
sl@0
|
1429 |
{
|
sl@0
|
1430 |
countersValues[i] = TChar(' ');
|
sl@0
|
1431 |
}
|
sl@0
|
1432 |
}
|
sl@0
|
1433 |
TInt idx = 0;
|
sl@0
|
1434 |
TLex8 lex(countersValues);
|
sl@0
|
1435 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1436 |
{
|
sl@0
|
1437 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1438 |
TBuf<20> num;
|
sl@0
|
1439 |
num.Copy(num8);
|
sl@0
|
1440 |
TheTest.Printf(_L("==Operation %S, count %S\r\n"), &KText[idx], &num);
|
sl@0
|
1441 |
++idx;
|
sl@0
|
1442 |
}
|
sl@0
|
1443 |
}
|
sl@0
|
1444 |
}
|
sl@0
|
1445 |
|
sl@0
|
1446 |
void PrintOsCallTime(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1447 |
{
|
sl@0
|
1448 |
TBuf8<300> callTimes;
|
sl@0
|
1449 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterOsCallTime, callTimes) == KErrNone)
|
sl@0
|
1450 |
{
|
sl@0
|
1451 |
TheTest.Printf(_L("=========================\r\n"));
|
sl@0
|
1452 |
_LIT(KEOsFileClose, "FileClose");
|
sl@0
|
1453 |
_LIT(KEOsFileRead, "FileRead");
|
sl@0
|
1454 |
_LIT(KEOsFileWrite, "FileWrite");
|
sl@0
|
1455 |
_LIT(KEOsFileTruncate, "FileTruncate");
|
sl@0
|
1456 |
_LIT(KEOsFileSync, "FileSync");
|
sl@0
|
1457 |
_LIT(KEOsFileFileSize, "FileSize");
|
sl@0
|
1458 |
_LIT(KEOsFileLock, "FileLock");
|
sl@0
|
1459 |
_LIT(KEOsFileUnlock, "FileUnlock");
|
sl@0
|
1460 |
_LIT(KEOsFileCheckReservedLock, "FileCheckReservedLock");
|
sl@0
|
1461 |
_LIT(KEOsFileFileControl, "FileIoControl");
|
sl@0
|
1462 |
_LIT(KEOsFileSectorSize, "FileSectorSize");
|
sl@0
|
1463 |
_LIT(KEOsFileDeviceCharacteristics, "FileDeviceCharacteristics");
|
sl@0
|
1464 |
_LIT(KEOsVfsOpen, "VfsOpen");
|
sl@0
|
1465 |
_LIT(KEOsVfsDelete, "VfsDelete");
|
sl@0
|
1466 |
_LIT(KEOsVfsAccess, "VfsAccess");
|
sl@0
|
1467 |
_LIT(KEOsVfsFullPathName, "VfsFullPathName");
|
sl@0
|
1468 |
_LIT(KEOsVfsRandomness, "VfsRandomnes");
|
sl@0
|
1469 |
_LIT(KEOsVfsSleep, "VfsSleep");
|
sl@0
|
1470 |
_LIT(KEOsVfsCurrentTime, "VfsCurrentTime");
|
sl@0
|
1471 |
_LIT(KEOsVfsGetLastError, "VfsGetLastError");
|
sl@0
|
1472 |
TPtrC KText[] =
|
sl@0
|
1473 |
{
|
sl@0
|
1474 |
KEOsFileClose(), KEOsFileRead(), KEOsFileWrite(), KEOsFileTruncate(), KEOsFileSync(),
|
sl@0
|
1475 |
KEOsFileFileSize(), KEOsFileLock(), KEOsFileUnlock(), KEOsFileCheckReservedLock(), KEOsFileFileControl(),
|
sl@0
|
1476 |
KEOsFileSectorSize(), KEOsFileDeviceCharacteristics(),
|
sl@0
|
1477 |
KEOsVfsOpen(), KEOsVfsDelete(), KEOsVfsAccess(), KEOsVfsFullPathName(), KEOsVfsRandomness(), KEOsVfsSleep(),
|
sl@0
|
1478 |
KEOsVfsCurrentTime(), KEOsVfsGetLastError()};
|
sl@0
|
1479 |
|
sl@0
|
1480 |
for(TInt i=0;i<callTimes.Length();++i)
|
sl@0
|
1481 |
{
|
sl@0
|
1482 |
if(callTimes[i] == TChar(';'))
|
sl@0
|
1483 |
{
|
sl@0
|
1484 |
callTimes[i] = TChar(' ');
|
sl@0
|
1485 |
}
|
sl@0
|
1486 |
}
|
sl@0
|
1487 |
TInt idx = 0;
|
sl@0
|
1488 |
TLex8 lex(callTimes);
|
sl@0
|
1489 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1490 |
{
|
sl@0
|
1491 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1492 |
TBuf<20> num;
|
sl@0
|
1493 |
num.Copy(num8);
|
sl@0
|
1494 |
TheTest.Printf(_L("==Operation %S, time %S us\r\n"), &KText[idx], &num);
|
sl@0
|
1495 |
++idx;
|
sl@0
|
1496 |
}
|
sl@0
|
1497 |
}
|
sl@0
|
1498 |
}
|
sl@0
|
1499 |
|
sl@0
|
1500 |
void PrintIpc(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1501 |
{
|
sl@0
|
1502 |
TBuf8<300> countersValues;
|
sl@0
|
1503 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterIpc, countersValues) == KErrNone)
|
sl@0
|
1504 |
{
|
sl@0
|
1505 |
TheTest.Printf(_L("=========================\r\n"));
|
sl@0
|
1506 |
_LIT(KIpcRq, "IPC requests");
|
sl@0
|
1507 |
_LIT(KIpcRead, "IPC read");
|
sl@0
|
1508 |
_LIT(KIpcWrite, "IPC write");
|
sl@0
|
1509 |
_LIT(KIpcReadBytes, "IPC read bytes");
|
sl@0
|
1510 |
_LIT(KIpcWriteBytes, "IPC write bytes");
|
sl@0
|
1511 |
TPtrC KText[] =
|
sl@0
|
1512 |
{
|
sl@0
|
1513 |
KIpcRq(), KIpcRead(), KIpcWrite(), KIpcReadBytes(), KIpcWriteBytes()
|
sl@0
|
1514 |
};
|
sl@0
|
1515 |
|
sl@0
|
1516 |
for(TInt i=0;i<countersValues.Length();++i)
|
sl@0
|
1517 |
{
|
sl@0
|
1518 |
if(countersValues[i] == TChar(';'))
|
sl@0
|
1519 |
{
|
sl@0
|
1520 |
countersValues[i] = TChar(' ');
|
sl@0
|
1521 |
}
|
sl@0
|
1522 |
}
|
sl@0
|
1523 |
TInt idx = 0;
|
sl@0
|
1524 |
TLex8 lex(countersValues);
|
sl@0
|
1525 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1526 |
{
|
sl@0
|
1527 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1528 |
TBuf<20> num;
|
sl@0
|
1529 |
num.Copy(num8);
|
sl@0
|
1530 |
TheTest.Printf(_L("==Operation %S, count %S\r\n"), &KText[idx], &num);
|
sl@0
|
1531 |
++idx;
|
sl@0
|
1532 |
}
|
sl@0
|
1533 |
}
|
sl@0
|
1534 |
}
|
sl@0
|
1535 |
|
sl@0
|
1536 |
void PrintMemory(TSqlResourceProfiler& aProfiler)
|
sl@0
|
1537 |
{
|
sl@0
|
1538 |
TBuf8<300> countersValues;
|
sl@0
|
1539 |
if(aProfiler.Query(TSqlResourceProfiler::ESqlCounterMemory, countersValues) == KErrNone)
|
sl@0
|
1540 |
{
|
sl@0
|
1541 |
TheTest.Printf(_L("=========================\r\n"));
|
sl@0
|
1542 |
_LIT(KMemorySrvAllocatedCnt, "Server allocated cnt");
|
sl@0
|
1543 |
_LIT(KMemorySrvAllocatedSize, "Server allocated size");
|
sl@0
|
1544 |
_LIT(KMemorySrvFreeSpace, "Server free space");
|
sl@0
|
1545 |
_LIT(KMemorySrvLargestBlockSize, "Server larges block size");
|
sl@0
|
1546 |
_LIT(KMemorySQLiteAllocatedCnt, "SQLite allocated cnt");
|
sl@0
|
1547 |
_LIT(KMemorySQLiteReallocatedCnt, "SQLite reallocated cnt");
|
sl@0
|
1548 |
_LIT(KMemorySQLiteFreedCnt, "SQLite freed cnt");
|
sl@0
|
1549 |
_LIT(KMemorySQLiteAllocatedBytes, "SQLite allocated bytes");
|
sl@0
|
1550 |
_LIT(KMemorySQLiteFreedBytes, "SQLite freed bytes");
|
sl@0
|
1551 |
_LIT(KMemorySQLiteAllocTime, "SQLite alloc, us");
|
sl@0
|
1552 |
_LIT(KMemorySQLiteReallocTime, "SQLite realloc, us");
|
sl@0
|
1553 |
_LIT(KMemorySQLiteFreeTime, "SQLite free, us");
|
sl@0
|
1554 |
TPtrC KText[] =
|
sl@0
|
1555 |
{
|
sl@0
|
1556 |
KMemorySrvAllocatedCnt(), KMemorySrvAllocatedSize(), KMemorySrvFreeSpace(), KMemorySrvLargestBlockSize(),
|
sl@0
|
1557 |
KMemorySQLiteAllocatedCnt(), KMemorySQLiteReallocatedCnt(), KMemorySQLiteFreedCnt(),
|
sl@0
|
1558 |
KMemorySQLiteAllocatedBytes(), KMemorySQLiteFreedBytes(),
|
sl@0
|
1559 |
KMemorySQLiteAllocTime(), KMemorySQLiteReallocTime(), KMemorySQLiteFreeTime()
|
sl@0
|
1560 |
};
|
sl@0
|
1561 |
|
sl@0
|
1562 |
for(TInt i=0;i<countersValues.Length();++i)
|
sl@0
|
1563 |
{
|
sl@0
|
1564 |
if(countersValues[i] == TChar(';'))
|
sl@0
|
1565 |
{
|
sl@0
|
1566 |
countersValues[i] = TChar(' ');
|
sl@0
|
1567 |
}
|
sl@0
|
1568 |
}
|
sl@0
|
1569 |
TInt idx = 0;
|
sl@0
|
1570 |
TLex8 lex(countersValues);
|
sl@0
|
1571 |
while (!lex.Eos() && idx < (sizeof(KText)/sizeof(KText[0])))
|
sl@0
|
1572 |
{
|
sl@0
|
1573 |
TPtrC8 num8 = lex.NextToken();
|
sl@0
|
1574 |
TBuf<20> num;
|
sl@0
|
1575 |
num.Copy(num8);
|
sl@0
|
1576 |
TheTest.Printf(_L("==%S=%S\r\n"), &KText[idx], &num);
|
sl@0
|
1577 |
++idx;
|
sl@0
|
1578 |
}
|
sl@0
|
1579 |
}
|
sl@0
|
1580 |
}
|
sl@0
|
1581 |
|
sl@0
|
1582 |
/**
|
sl@0
|
1583 |
@SYMTestCaseID SYSLIB-SQL-UT-4088
|
sl@0
|
1584 |
@SYMTestCaseDesc TSqlResouceProfiler - file I/O and configuration test.
|
sl@0
|
1585 |
The test enables the file I/O profiling and then executes a simple INSERT statement
|
sl@0
|
1586 |
and prints out the profiling results. The test also prints the current database configuration.
|
sl@0
|
1587 |
@SYMTestActions TSqlResouceProfiler - file I/O and configuration test.
|
sl@0
|
1588 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1589 |
@SYMTestPriority Medium
|
sl@0
|
1590 |
@SYMREQ REQ5792
|
sl@0
|
1591 |
*/
|
sl@0
|
1592 |
void ProfilerTest()
|
sl@0
|
1593 |
{
|
sl@0
|
1594 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1595 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1596 |
TEST2(err, KErrNone);
|
sl@0
|
1597 |
err = TheDb.Exec(_L("CREATE TABLE A(Id INTEGER, T TEXT)"));
|
sl@0
|
1598 |
TEST2(err, 1);
|
sl@0
|
1599 |
|
sl@0
|
1600 |
TSqlResourceProfiler profiler(TheDb);
|
sl@0
|
1601 |
|
sl@0
|
1602 |
PrintConfig(profiler);
|
sl@0
|
1603 |
|
sl@0
|
1604 |
(void)profiler.Start(TSqlResourceProfiler::ESqlCounterFileIO);
|
sl@0
|
1605 |
(void)profiler.Start(TSqlResourceProfiler::ESqlCounterOsCall);
|
sl@0
|
1606 |
(void)profiler.Start(TSqlResourceProfiler::ESqlCounterOsCallTime);
|
sl@0
|
1607 |
(void)profiler.Start(TSqlResourceProfiler::ESqlCounterIpc);
|
sl@0
|
1608 |
(void)profiler.Start(TSqlResourceProfiler::ESqlCounterMemory);
|
sl@0
|
1609 |
|
sl@0
|
1610 |
(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterFileIO);
|
sl@0
|
1611 |
(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterOsCall);
|
sl@0
|
1612 |
(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterOsCallTime);
|
sl@0
|
1613 |
(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterIpc);
|
sl@0
|
1614 |
(void)profiler.Reset(TSqlResourceProfiler::ESqlCounterMemory);
|
sl@0
|
1615 |
|
sl@0
|
1616 |
err = TheDb.Exec(_L("INSERT INTO A VALUES(1, 'ABCDEEFGH')"));
|
sl@0
|
1617 |
TEST2(err, 1);
|
sl@0
|
1618 |
|
sl@0
|
1619 |
PrintFileIo(profiler);
|
sl@0
|
1620 |
PrintOsCall(profiler);
|
sl@0
|
1621 |
PrintOsCallTime(profiler);
|
sl@0
|
1622 |
PrintIpc(profiler);
|
sl@0
|
1623 |
PrintMemory(profiler);
|
sl@0
|
1624 |
|
sl@0
|
1625 |
(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterIpc);
|
sl@0
|
1626 |
(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterOsCallTime);
|
sl@0
|
1627 |
(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterOsCall);
|
sl@0
|
1628 |
(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterFileIO);
|
sl@0
|
1629 |
(void)profiler.Stop(TSqlResourceProfiler::ESqlCounterMemory);
|
sl@0
|
1630 |
|
sl@0
|
1631 |
TheDb.Close();
|
sl@0
|
1632 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1633 |
}
|
sl@0
|
1634 |
|
sl@0
|
1635 |
TInt CompoundSelectStackOverflowThreadFunc(void* aData)
|
sl@0
|
1636 |
{
|
sl@0
|
1637 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
1638 |
TEST(tc != NULL);
|
sl@0
|
1639 |
|
sl@0
|
1640 |
User::SetJustInTime(EFalse); // disable debugger panic handling
|
sl@0
|
1641 |
|
sl@0
|
1642 |
TInt* cntptr = reinterpret_cast<TInt*> (aData);
|
sl@0
|
1643 |
TEST(cntptr != NULL);
|
sl@0
|
1644 |
const TInt KSelectStmtCnt = *cntptr;
|
sl@0
|
1645 |
|
sl@0
|
1646 |
HBufC* buf = HBufC::New(KSelectStmtCnt * 25 + 32);//enough for the "SELECT I FROM A UNION SELECT I FROM A..." string
|
sl@0
|
1647 |
if(!buf)
|
sl@0
|
1648 |
{
|
sl@0
|
1649 |
delete tc;
|
sl@0
|
1650 |
return KErrNoMemory;
|
sl@0
|
1651 |
}
|
sl@0
|
1652 |
TPtr sql = buf->Des();
|
sl@0
|
1653 |
|
sl@0
|
1654 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1655 |
RSqlDatabase db;
|
sl@0
|
1656 |
TInt err = db.Create(KTestDbName1);
|
sl@0
|
1657 |
if(err != KErrNone)
|
sl@0
|
1658 |
{
|
sl@0
|
1659 |
delete buf;
|
sl@0
|
1660 |
return err;
|
sl@0
|
1661 |
}
|
sl@0
|
1662 |
err = db.Exec(_L("CREATE TABLE A(I INTEGER);INSERT INTO A VALUES(1);"));
|
sl@0
|
1663 |
if(err < 1)
|
sl@0
|
1664 |
{
|
sl@0
|
1665 |
delete buf;
|
sl@0
|
1666 |
return err;
|
sl@0
|
1667 |
}
|
sl@0
|
1668 |
|
sl@0
|
1669 |
for(TInt i=0;i<KSelectStmtCnt;i++)
|
sl@0
|
1670 |
{
|
sl@0
|
1671 |
sql.Append(_L("SELECT I FROM A UNION "));
|
sl@0
|
1672 |
}
|
sl@0
|
1673 |
sql.SetLength(sql.Length() - 7);
|
sl@0
|
1674 |
RSqlStatement stmt;
|
sl@0
|
1675 |
err = stmt.Prepare(db, sql);//This call can crash the server with "stack overflow"
|
sl@0
|
1676 |
stmt.Close();
|
sl@0
|
1677 |
|
sl@0
|
1678 |
db.Close();
|
sl@0
|
1679 |
delete buf;
|
sl@0
|
1680 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1681 |
return err;
|
sl@0
|
1682 |
}
|
sl@0
|
1683 |
|
sl@0
|
1684 |
void CompoundSelectStackOverflowTest()
|
sl@0
|
1685 |
{
|
sl@0
|
1686 |
const TInt KMaxSelectStmtCnt = 64;
|
sl@0
|
1687 |
for(TInt cnt=KMaxSelectStmtCnt;cnt>0;--cnt)
|
sl@0
|
1688 |
{
|
sl@0
|
1689 |
TheTest.Printf(_L("SELECT statement count: %d\r\n"), cnt);
|
sl@0
|
1690 |
RThread thread;
|
sl@0
|
1691 |
_LIT(KThreadName,"S2Thread"); //stack minheap maxheap
|
sl@0
|
1692 |
TInt err = thread.Create(KThreadName, &CompoundSelectStackOverflowThreadFunc, 0x2000, 0x00100000, 0x02000000, &cnt);
|
sl@0
|
1693 |
TEST2(err, KErrNone);
|
sl@0
|
1694 |
|
sl@0
|
1695 |
TRequestStatus status;
|
sl@0
|
1696 |
thread.Logon(status);
|
sl@0
|
1697 |
TEST2(status.Int(), KRequestPending);
|
sl@0
|
1698 |
thread.Resume();
|
sl@0
|
1699 |
User::WaitForRequest(status);
|
sl@0
|
1700 |
User::SetJustInTime(ETrue); // enable debugger panic handling
|
sl@0
|
1701 |
|
sl@0
|
1702 |
TInt exitType = thread.ExitType();
|
sl@0
|
1703 |
const TDesC& exitCategory = thread.ExitCategory();
|
sl@0
|
1704 |
TInt exitReason = thread.ExitReason();
|
sl@0
|
1705 |
TheTest.Printf(_L("Exit type: %d, exit reason: %d, exit category: %S\r\n"), exitType, exitReason, &exitCategory);
|
sl@0
|
1706 |
thread.Close();
|
sl@0
|
1707 |
if(exitReason == KErrServerTerminated) //SQL server --> stack overflow
|
sl@0
|
1708 |
{
|
sl@0
|
1709 |
continue;
|
sl@0
|
1710 |
}
|
sl@0
|
1711 |
TEST2(exitReason, KErrNone);
|
sl@0
|
1712 |
TheTest.Printf(_L(" The test has succeeded with SELECT statement count=%d\r\n"), cnt);
|
sl@0
|
1713 |
break;
|
sl@0
|
1714 |
}
|
sl@0
|
1715 |
}
|
sl@0
|
1716 |
|
sl@0
|
1717 |
/**
|
sl@0
|
1718 |
@SYMTestCaseID PDS-SQL-CT-4198
|
sl@0
|
1719 |
@SYMTestCaseDesc Expired SQL statements test.
|
sl@0
|
1720 |
The test creates a database and opens 2 connections to that database.
|
sl@0
|
1721 |
Connection 2 prepares couple of SELECT and INSERT statements (8-bit and 16-bit).
|
sl@0
|
1722 |
Then connection 1 renames the table used in the already prepared statements.
|
sl@0
|
1723 |
Connection 2 attempts to execute the prepared statements. The execution should fail
|
sl@0
|
1724 |
because the database schema has changed after they were prepared.
|
sl@0
|
1725 |
@SYMTestActions Expired SQL statements test.
|
sl@0
|
1726 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
1727 |
@SYMTestPriority High
|
sl@0
|
1728 |
@SYMDEF DEF145236
|
sl@0
|
1729 |
*/
|
sl@0
|
1730 |
void ExpiredStmtTest()
|
sl@0
|
1731 |
{
|
sl@0
|
1732 |
(void)RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1733 |
//Create a database and create db connection 1.
|
sl@0
|
1734 |
TInt err = TheDb.Create(KTestDbName1);
|
sl@0
|
1735 |
TEST2(err, KErrNone);
|
sl@0
|
1736 |
err = TheDb.Exec(_L("CREATE TABLE A(C1 INTEGER)"));
|
sl@0
|
1737 |
TEST(err >= 0);
|
sl@0
|
1738 |
err = TheDb.Exec(_L("INSERT INTO A(C1) VALUES(1)"));
|
sl@0
|
1739 |
TEST2(err, 1);
|
sl@0
|
1740 |
|
sl@0
|
1741 |
//Create db connection 2 to the same database, as db connection 1.
|
sl@0
|
1742 |
RSqlDatabase db2;
|
sl@0
|
1743 |
err = db2.Open(KTestDbName1);
|
sl@0
|
1744 |
TEST2(err, KErrNone);
|
sl@0
|
1745 |
|
sl@0
|
1746 |
//Db connection 2. Prepare SELECT and INSERT, 8-bit and 16-bit statements.
|
sl@0
|
1747 |
RSqlStatement stmt1, stmt2, stmt3, stmt4;
|
sl@0
|
1748 |
err = stmt1.Prepare(db2, _L("SELECT * FROM A"));
|
sl@0
|
1749 |
TEST2(err, KErrNone);
|
sl@0
|
1750 |
err = stmt2.Prepare(db2, _L8("SELECT * FROM A"));
|
sl@0
|
1751 |
TEST2(err, KErrNone);
|
sl@0
|
1752 |
err = stmt3.Prepare(db2, _L("INSERT INTO A(C1) VALUES(2)"));
|
sl@0
|
1753 |
TEST2(err, KErrNone);
|
sl@0
|
1754 |
err = stmt4.Prepare(db2, _L8("INSERT INTO A(C1) VALUES(3)"));
|
sl@0
|
1755 |
TEST2(err, KErrNone);
|
sl@0
|
1756 |
|
sl@0
|
1757 |
//Modify the A table structure from the other connection
|
sl@0
|
1758 |
//err = TheDb.Exec(_L("ALTER TABLE A ADD C2 INTEGER"));
|
sl@0
|
1759 |
err = TheDb.Exec(_L("ALTER TABLE A RENAME TO B"));
|
sl@0
|
1760 |
TEST(err >= 0);
|
sl@0
|
1761 |
|
sl@0
|
1762 |
//Try to execute the already prepared statements.
|
sl@0
|
1763 |
err = stmt1.Next();
|
sl@0
|
1764 |
TEST2(err, KSqlErrSchema);
|
sl@0
|
1765 |
err = stmt1.Next();
|
sl@0
|
1766 |
TEST(err != KSqlAtRow);
|
sl@0
|
1767 |
err = stmt2.Next();
|
sl@0
|
1768 |
TEST(err != KSqlAtRow);
|
sl@0
|
1769 |
err = stmt3.Exec();
|
sl@0
|
1770 |
TEST(err < 0);
|
sl@0
|
1771 |
err = stmt4.Exec();
|
sl@0
|
1772 |
TEST(err < 0);
|
sl@0
|
1773 |
//
|
sl@0
|
1774 |
stmt4.Close();
|
sl@0
|
1775 |
stmt3.Close();
|
sl@0
|
1776 |
stmt2.Close();
|
sl@0
|
1777 |
stmt1.Close();
|
sl@0
|
1778 |
db2.Close();
|
sl@0
|
1779 |
TheDb.Close();
|
sl@0
|
1780 |
err = RSqlDatabase::Delete(KTestDbName1);
|
sl@0
|
1781 |
TEST2(err, KErrNone);
|
sl@0
|
1782 |
}
|
sl@0
|
1783 |
|
sl@0
|
1784 |
void DoTestsL()
|
sl@0
|
1785 |
{
|
sl@0
|
1786 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3512 RSqlStatement::ColumnCount() tests "));
|
sl@0
|
1787 |
ColumnCountTest();
|
sl@0
|
1788 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3513 RSqlStatement::ColumnCount(), non-SELECT tests "));
|
sl@0
|
1789 |
ColumnCountTest2();
|
sl@0
|
1790 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-3514 RSqlStatement::DeclaredColumnType() tests "));
|
sl@0
|
1791 |
DeclaredColumnTypeTest();
|
sl@0
|
1792 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4017 RSqlStatement::ColumnName() tests"));
|
sl@0
|
1793 |
ColumnNameTest();
|
sl@0
|
1794 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4018 RSqlStatement::ParameterName() and RSqlStatement::ParamName() tests"));
|
sl@0
|
1795 |
ParamNameTest();
|
sl@0
|
1796 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4006 DEF115300 - SqlSrv.EXE::!SQL Server when preparing invalid LEFT JOIN sql query "));
|
sl@0
|
1797 |
DEF115300();
|
sl@0
|
1798 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4007 DEF115331 - SQL, bad code coverage for db reindexing if default collation has changed "));
|
sl@0
|
1799 |
DEF115331L();
|
sl@0
|
1800 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4079 RSqlDatabase::Create() and RSqlDatabase::Open() - injection tests"));
|
sl@0
|
1801 |
InjectionTest();
|
sl@0
|
1802 |
TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-UT-4038 Two connections test"));
|
sl@0
|
1803 |
TwoConnectionsTest();
|
sl@0
|
1804 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4080 SQL server stack overflow test"));
|
sl@0
|
1805 |
SqlServerStackOverflowTest();
|
sl@0
|
1806 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4086 RSqlBlobWriteStream/RSqlBlobReadStream injection test"));
|
sl@0
|
1807 |
BlobStreamInjectionTest();
|
sl@0
|
1808 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4087 Bound parameter values test 1"));
|
sl@0
|
1809 |
BoundParameterValuesTest();
|
sl@0
|
1810 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4076 Bound parameter values test 2"));
|
sl@0
|
1811 |
BoundParameterValuesTest2();
|
sl@0
|
1812 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4077 Bound parameter values test 3"));
|
sl@0
|
1813 |
BoundParameterValuesTest3();
|
sl@0
|
1814 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4083 Bound parameter values test 4"));
|
sl@0
|
1815 |
BoundParameterValuesTest4();
|
sl@0
|
1816 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4105 Bound parameter values test 5"));
|
sl@0
|
1817 |
BoundParameterValuesTest5();
|
sl@0
|
1818 |
TheTest.Next( _L(" @SYMTestCaseID:SYSLIB-SQL-UT-4088 TSqlResourceProfiler - file I/O and configuration test"));
|
sl@0
|
1819 |
ProfilerTest();
|
sl@0
|
1820 |
TheTest.Next( _L(" Compound SELECT, stack overflow test"));
|
sl@0
|
1821 |
CompoundSelectStackOverflowTest();
|
sl@0
|
1822 |
TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4198 Expired statements test"));
|
sl@0
|
1823 |
ExpiredStmtTest();
|
sl@0
|
1824 |
}
|
sl@0
|
1825 |
|
sl@0
|
1826 |
TInt E32Main()
|
sl@0
|
1827 |
{
|
sl@0
|
1828 |
TheTest.Title();
|
sl@0
|
1829 |
|
sl@0
|
1830 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
1831 |
|
sl@0
|
1832 |
__UHEAP_MARK;
|
sl@0
|
1833 |
|
sl@0
|
1834 |
CreateTestEnv();
|
sl@0
|
1835 |
DeleteTestFiles();
|
sl@0
|
1836 |
TRAPD(err, DoTestsL());
|
sl@0
|
1837 |
DeleteTestFiles();
|
sl@0
|
1838 |
TEST2(err, KErrNone);
|
sl@0
|
1839 |
|
sl@0
|
1840 |
__UHEAP_MARKEND;
|
sl@0
|
1841 |
|
sl@0
|
1842 |
TheTest.End();
|
sl@0
|
1843 |
TheTest.Close();
|
sl@0
|
1844 |
|
sl@0
|
1845 |
delete tc;
|
sl@0
|
1846 |
|
sl@0
|
1847 |
User::Heap().Check();
|
sl@0
|
1848 |
return KErrNone;
|
sl@0
|
1849 |
}
|