278 |
278 |
279 RFs fs; |
279 RFs fs; |
280 TEST2(fs.Connect(), KErrNone); |
280 TEST2(fs.Connect(), KErrNone); |
281 TFileName privatePath; |
281 TFileName privatePath; |
282 TEST2(fs.PrivatePath(privatePath), KErrNone); |
282 TEST2(fs.PrivatePath(privatePath), KErrNone); |
283 fs.Close(); |
|
284 |
283 |
285 //Private shared database file on an existing drive (C:). |
284 //Private shared database file on an existing drive (C:). |
286 //Very long database file name. |
285 //Very long database file name. |
287 const TInt KMaxFileName2 = KMaxFileName - 40;//"-40" because the SQLITE engine creates a journal file if begins |
286 TBuf<50>filesysname; |
288 //a transaction. The name of the journal file is |
287 fs.FileSystemName(filesysname,(TInt) EDriveC); |
289 //"<dbFileName>-journal.<ext>". It is obvious that if the |
288 fs.Close(); |
290 //database file name is too long but still valid and its creation |
289 |
291 //succeeds, the journal file creation may fail because the journal |
290 RDebug::Print(_L("file system name = %S"), &filesysname); |
292 //file name becomes too long |
291 TInt maxFileName = KMaxFileName -40;//"-40" because the SQLITE engine creates a journal file if begins |
293 TBuf<KMaxFileName2> dbPath; |
292 //a transaction. The name of the journal file is |
|
293 //"<dbFileName>-journal.<ext>". It is obvious that if the |
|
294 //database file name is too long but still valid and its creation |
|
295 //succeeds, the journal file creation may fail because the journal |
|
296 //file name becomes too long |
|
297 |
|
298 if(filesysname.CompareF(_L("HVFS")) == 0) |
|
299 { |
|
300 maxFileName = KMaxFileName -150;//The test will panic in PlatSim when the file name is too long. This line should be removed when platsim team fixes the file system defect. |
|
301 } |
|
302 HBufC* dbPath = HBufC::NewLC(maxFileName); |
294 _LIT(KExt, ".DB"); |
303 _LIT(KExt, ".DB"); |
295 dbPath.Copy(_L("C:")); |
304 dbPath->Des().Copy(_L("C:")); |
296 dbPath.Append(KSecureUid.Name()); |
305 dbPath->Des().Append(KSecureUid.Name()); |
297 TInt len = KMaxFileName2 + 1 - (dbPath.Length() + KExt().Length() + privatePath.Length()); |
306 TInt len = maxFileName + 1 - (dbPath->Length() + KExt().Length() + privatePath.Length()); |
|
307 |
298 while(--len) |
308 while(--len) |
299 { |
309 { |
300 dbPath.Append(TChar('A')); |
310 dbPath->Des().Append(TChar('A')); |
301 } |
311 } |
302 dbPath.Append(KExt); |
312 dbPath->Des().Append(KExt); |
303 TEST(dbPath.Length() == (KMaxFileName2 - privatePath.Length())); |
313 TEST(dbPath->Length() == (maxFileName - privatePath.Length())); |
304 rc = db.Create(dbPath, securityPolicy); |
314 rc = db.Create(dbPath->Des(), securityPolicy); |
305 db.Close(); |
315 TEST2(rc, KErrNone); |
306 rc2 = RSqlDatabase::Delete(dbPath); |
316 db.Close(); |
307 TEST2(rc, KErrNone); |
317 rc2 = RSqlDatabase::Delete(dbPath->Des()); |
308 TEST2(rc2, KErrNone); |
318 TEST2(rc2, KErrNone); |
309 |
319 |
310 // Private database with config |
320 // Private database with config |
311 TBuf<KMaxFileName> cfgPath; |
321 TBuf<KMaxFileName> cfgPath; |
312 cfgPath.Copy(_L("C:")); |
322 cfgPath.Copy(_L("C:")); |
1351 db.Close(); |
1363 db.Close(); |
1352 |
1364 |
1353 rc = RSqlDatabase::Delete(KTestDbName1); |
1365 rc = RSqlDatabase::Delete(KTestDbName1); |
1354 TEST2(rc, KErrNone); |
1366 TEST2(rc, KErrNone); |
1355 } |
1367 } |
|
1368 |
|
1369 /** |
|
1370 @SYMTestCaseID PDS-SQL-CT-4191 |
|
1371 @SYMTestCaseDesc The test creates a test database and inserts one record using a stream. |
|
1372 MStreamBuf::SeekL() is used to modify the parameter data at specific positions. |
|
1373 Then the test executes a SELECT statement to read the just written record. |
|
1374 MStreamBuf::SeekL() is used to read the column content at specific positions |
|
1375 (the same positions used during the record write operation). The read byte values must |
|
1376 match the written byte values. |
|
1377 @SYMTestPriority High |
|
1378 @SYMTestActions RSqlColumnReadStream::ColumnBinary() and RSqlParamWriteStream::BindBinary() - MStreamBuf::SeekL() test. |
|
1379 @SYMTestExpectedResults Test must not fail |
|
1380 @SYMDEF DEF145125 |
|
1381 */ |
|
1382 void StreamSeekTestL() |
|
1383 { |
|
1384 RSqlDatabase db; |
|
1385 CleanupClosePushL(db); |
|
1386 TInt rc = db.Create(KTestDbName1); |
|
1387 TEST2(rc, KErrNone); |
|
1388 rc = db.Exec(_L("CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB)")); |
|
1389 TEST(rc >= 0); |
|
1390 //Write a record to the database using a stream. MStreamBuf::SeekL() is used to modify the content at a specific position. |
|
1391 RSqlStatement stmt; |
|
1392 CleanupClosePushL(stmt); |
|
1393 rc = stmt.Prepare(db, _L("INSERT INTO A(Fld1, Fld2) VALUES(1, ?)")); |
|
1394 TEST2(rc, KErrNone); |
|
1395 |
|
1396 RSqlParamWriteStream strm1; |
|
1397 CleanupClosePushL(strm1); |
|
1398 rc = strm1.BindBinary(stmt, 0); |
|
1399 TEST2(rc, KErrNone); |
|
1400 |
|
1401 for(TInt i=0;i<256;++i) |
|
1402 { |
|
1403 strm1 << (TUint8)i; |
|
1404 } |
|
1405 |
|
1406 const TInt KStreamOffset = 10; |
|
1407 const TUint8 KByte = 'z'; |
|
1408 _LIT8(KData, "QWERTYUIOPASDFG"); |
|
1409 |
|
1410 MStreamBuf* strm1buf = strm1.Sink(); |
|
1411 TEST(strm1buf != NULL); |
|
1412 |
|
1413 strm1buf->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0); |
|
1414 strm1buf->WriteL(&KByte, 1); |
|
1415 |
|
1416 strm1buf->SeekL(MStreamBuf::EWrite, EStreamMark, KStreamOffset); |
|
1417 strm1buf->WriteL(&KByte, 1); |
|
1418 |
|
1419 strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, 0); |
|
1420 strm1buf->WriteL(KData().Ptr(), KData().Length()); |
|
1421 |
|
1422 strm1buf->SeekL(MStreamBuf::EWrite, EStreamEnd, -4 * KStreamOffset); |
|
1423 strm1buf->WriteL(&KByte, 1); |
|
1424 |
|
1425 strm1.CommitL(); |
|
1426 CleanupStack::PopAndDestroy(&strm1); |
|
1427 |
|
1428 rc = stmt.Exec(); |
|
1429 TEST2(rc, 1); |
|
1430 CleanupStack::PopAndDestroy(&stmt); |
|
1431 |
|
1432 //Read the record using a stream. MStreamBuf::SeekL() is used to read the content at a specific position. |
|
1433 CleanupClosePushL(stmt); |
|
1434 rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A WHERE Fld1 = 1")); |
|
1435 TEST2(rc, KErrNone); |
|
1436 rc = stmt.Next(); |
|
1437 TEST2(rc, KSqlAtRow); |
|
1438 |
|
1439 RSqlColumnReadStream strm2; |
|
1440 CleanupClosePushL(strm2); |
|
1441 rc = strm2.ColumnBinary(stmt, 0); |
|
1442 TEST2(rc, KErrNone); |
|
1443 |
|
1444 TUint8 byte = 0; |
|
1445 MStreamBuf* strm2buf = strm2.Source(); |
|
1446 TEST(strm1buf != NULL); |
|
1447 |
|
1448 strm2buf->SeekL(MStreamBuf::ERead, EStreamBeginning, 0); |
|
1449 rc = strm2buf->ReadL(&byte, 1); |
|
1450 TEST2(rc, 1); |
|
1451 TEST2(byte, KByte); |
|
1452 |
|
1453 strm2buf->SeekL(MStreamBuf::ERead, EStreamMark, KStreamOffset); |
|
1454 rc = strm2buf->ReadL(&byte, 1); |
|
1455 TEST2(rc, 1); |
|
1456 TEST2(byte, KByte); |
|
1457 |
|
1458 strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -KData().Length()); |
|
1459 TUint8 buf[20]; |
|
1460 rc = strm2buf->ReadL(buf, KData().Length()); |
|
1461 TEST2(rc, KData().Length()); |
|
1462 TPtrC8 bufptr(buf, rc); |
|
1463 TEST(bufptr == KData); |
|
1464 |
|
1465 strm2buf->SeekL(MStreamBuf::ERead, EStreamEnd, -4 * KStreamOffset); |
|
1466 rc = strm2buf->ReadL(&byte, 1); |
|
1467 TEST2(rc, 1); |
|
1468 TEST2(byte, KByte); |
|
1469 |
|
1470 CleanupStack::PopAndDestroy(&strm2); |
|
1471 CleanupStack::PopAndDestroy(&stmt); |
|
1472 |
|
1473 CleanupStack::PopAndDestroy(&db); |
|
1474 rc = RSqlDatabase::Delete(KTestDbName1); |
|
1475 TEST2(rc, KErrNone); |
|
1476 } |
|
1477 |
|
1478 /** |
|
1479 @SYMTestCaseID PDS-SQL-CT-4174 |
|
1480 @SYMTestCaseDesc Test for DEF144937: SQL, SQL server, the code coverage can be improved in some areas. |
|
1481 @SYMTestPriority High |
|
1482 @SYMTestActions The test creates a test database with a table with 3 records. |
|
1483 The first record has a BLOB column with 0 length. |
|
1484 The second record has a BLOB column with length less than KSqlMaxDesLen |
|
1485 (in debug mode) in which case no IPC call is needed to be made in order |
|
1486 to access the column value via stream. |
|
1487 The third record has a BLOB column with length exactly KSqlMaxDesLen |
|
1488 in which case an IPC call will be made in order to retrieve the column value, |
|
1489 but the column value will be copied directly to the client - no stream object is created. |
|
1490 @SYMTestExpectedResults Test must not fail |
|
1491 @SYMDEF DEF144937 |
|
1492 */ |
|
1493 void ColumnBinaryStreamTest2() |
|
1494 { |
|
1495 RSqlDatabase db; |
|
1496 TInt rc = db.Create(KTestDbName1); |
|
1497 TEST2(rc, KErrNone); |
|
1498 |
|
1499 enum {KSqlBufSize = 128}; |
|
1500 |
|
1501 //Create a table |
|
1502 _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB);"); |
|
1503 ExecSqlStmtOnDb<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt1(), KErrNone); |
|
1504 |
|
1505 //Insert one record where the BLOB length is 0. |
|
1506 //Insert second record where the BLOB length is smaller than the max inline column length - KSqlMaxDesLen. |
|
1507 //Insert third record where the BLOB length is exactly the max inline column length - KSqlMaxDesLen. |
|
1508 _LIT8(KSqlStmt2, "INSERT INTO A VALUES(1, '');INSERT INTO A VALUES(2, x'0102030405');INSERT INTO A VALUES(3, x'0102030405060708');"); |
|
1509 ExecSqlStmtOnDb<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt2(), KErrNone); |
|
1510 |
|
1511 RSqlStatement stmt; |
|
1512 rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A")); |
|
1513 TEST2(rc, KErrNone); |
|
1514 |
|
1515 TBuf8<16> databuf; |
|
1516 |
|
1517 rc = stmt.Next(); |
|
1518 TEST2(rc, KSqlAtRow); |
|
1519 //ColumnBinary() does not make an IPC call because the BLOB length is 0. |
|
1520 RSqlColumnReadStream strm; |
|
1521 rc = strm.ColumnBinary(stmt, 0); |
|
1522 TEST2(rc, KErrNone); |
|
1523 TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); |
|
1524 strm.Close(); |
|
1525 TEST2(rc, KErrNone); |
|
1526 TEST2(databuf.Length(), 0); |
|
1527 |
|
1528 rc = stmt.Next(); |
|
1529 TEST2(rc, KSqlAtRow); |
|
1530 //ColumnBinary() does not make an IPC call because the BLOB length is less than the max inline |
|
1531 //column length - KSqlMaxDesLen. |
|
1532 rc = strm.ColumnBinary(stmt, 0); |
|
1533 TEST2(rc, KErrNone); |
|
1534 TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); |
|
1535 strm.Close(); |
|
1536 TEST2(rc, KErrNone); |
|
1537 TEST(databuf == _L8("\x1\x2\x3\x4\x5")); |
|
1538 |
|
1539 rc = stmt.Next(); |
|
1540 TEST2(rc, KSqlAtRow); |
|
1541 //ColumnBinary() makes an IPC call (in _DEBUG mode) because: |
|
1542 // - the column length is exactly KSqlMaxDesLen. |
|
1543 // - but at the same time the column length is equal to KIpcBufSize (in debug mode). |
|
1544 rc = strm.ColumnBinary(stmt, 0); |
|
1545 TEST2(rc, KErrNone); |
|
1546 TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0))); |
|
1547 strm.Close(); |
|
1548 TEST2(rc, KErrNone); |
|
1549 TEST(databuf == _L8("\x1\x2\x3\x4\x5\x6\x7\x8")); |
|
1550 |
|
1551 stmt.Close(); |
|
1552 db.Close(); |
|
1553 |
|
1554 rc = RSqlDatabase::Delete(KTestDbName1); |
|
1555 TEST2(rc, KErrNone); |
|
1556 } |
1356 |
1557 |
1357 /** |
1558 /** |
1358 @SYMTestCaseID SYSLIB-SQL-CT-1608 |
1559 @SYMTestCaseID SYSLIB-SQL-CT-1608 |
1359 @SYMTestCaseDesc Setting long text parameter values test. |
1560 @SYMTestCaseDesc Setting long text parameter values test. |
1360 @SYMTestPriority High |
1561 @SYMTestPriority High |