persistentstorage/sql/TEST/t_sqlapi.cpp
branchRCL_3
changeset 10 31a8f755b7fe
parent 8 fa9941cf3867
child 11 211563e4b919
equal deleted inserted replaced
9:667e88a979d7 10:31a8f755b7fe
  1339     TEST2(rc, KErrNone);
  1339     TEST2(rc, KErrNone);
  1340     TEST2(buf1.Length(), 2);
  1340     TEST2(buf1.Length(), 2);
  1341     TBuf8<1> buf2;
  1341     TBuf8<1> buf2;
  1342     rc = stmt.ColumnBinary(1, buf2); 
  1342     rc = stmt.ColumnBinary(1, buf2); 
  1343     TEST2(rc, KErrOverflow);
  1343     TEST2(rc, KErrOverflow);
  1344 	
  1344     
  1345 	stmt.Close();
  1345 	stmt.Close();
  1346 	
  1346 	
  1347 	//Deallocate buf
  1347 	//Deallocate buf
  1348 	delete buf; 
  1348 	delete buf; 
  1349 	buf = NULL;
  1349 	buf = NULL;
  1351 	db.Close();
  1351 	db.Close();
  1352 
  1352 
  1353 	rc = RSqlDatabase::Delete(KTestDbName1);
  1353 	rc = RSqlDatabase::Delete(KTestDbName1);
  1354 	TEST2(rc, KErrNone);
  1354 	TEST2(rc, KErrNone);
  1355 	}
  1355 	}
       
  1356 
       
  1357 /**
       
  1358 @SYMTestCaseID          PDS-SQL-CT-4174
       
  1359 @SYMTestCaseDesc        Test for DEF144937: SQL, SQL server, the code coverage can be improved in some areas.
       
  1360 @SYMTestPriority        High
       
  1361 @SYMTestActions         The test creates a test database with a table with 3 records.
       
  1362                         The first record has a BLOB column with 0 length.
       
  1363                         The second record has a BLOB column with length less than KSqlMaxDesLen
       
  1364                         (in debug mode) in which case no IPC call is needed to be made in order 
       
  1365                         to access the column value via stream.
       
  1366                         The third record has a BLOB column with length exactly KSqlMaxDesLen 
       
  1367                         in which case an IPC call will be made in order to retrieve the column value,
       
  1368                         but the column value will be copied directly to the client - no stream object is created. 
       
  1369 @SYMTestExpectedResults Test must not fail
       
  1370 @SYMDEF                 DEF144937
       
  1371 */  
       
  1372 void ColumnBinaryStreamTest2()
       
  1373     {
       
  1374     RSqlDatabase db;    
       
  1375     TInt rc = db.Create(KTestDbName1);
       
  1376     TEST2(rc, KErrNone);
       
  1377 
       
  1378     enum {KSqlBufSize = 128};
       
  1379     
       
  1380     //Create a table
       
  1381     _LIT8(KSqlStmt1, "CREATE TABLE A(Fld1 INTEGER, Fld2 BLOB);");
       
  1382     ExecSqlStmtOnDb<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt1(), KErrNone);
       
  1383     
       
  1384     //Insert one record where the BLOB length is 0. 
       
  1385     //Insert second record where the BLOB length is smaller than the max inline column length - KSqlMaxDesLen.
       
  1386     //Insert third record where the BLOB length is exactly the max inline column length - KSqlMaxDesLen.
       
  1387     _LIT8(KSqlStmt2, "INSERT INTO A VALUES(1, '');INSERT INTO A VALUES(2, x'0102030405');INSERT INTO A VALUES(3, x'0102030405060708');");
       
  1388     ExecSqlStmtOnDb<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt2(), KErrNone);
       
  1389     
       
  1390     RSqlStatement stmt;
       
  1391     rc = stmt.Prepare(db, _L("SELECT Fld2 FROM A"));
       
  1392     TEST2(rc, KErrNone);
       
  1393 
       
  1394     TBuf8<16> databuf;
       
  1395     
       
  1396     rc = stmt.Next();
       
  1397     TEST2(rc, KSqlAtRow);
       
  1398     //ColumnBinary() does not make an IPC call because the BLOB length is 0.
       
  1399     RSqlColumnReadStream strm;
       
  1400     rc = strm.ColumnBinary(stmt, 0);
       
  1401     TEST2(rc, KErrNone);
       
  1402     TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0)));
       
  1403     strm.Close();
       
  1404     TEST2(rc, KErrNone);
       
  1405     TEST2(databuf.Length(), 0);
       
  1406 
       
  1407     rc = stmt.Next();
       
  1408     TEST2(rc, KSqlAtRow);
       
  1409     //ColumnBinary() does not make an IPC call because the BLOB length is less than the max inline 
       
  1410     //column length - KSqlMaxDesLen.
       
  1411     rc = strm.ColumnBinary(stmt, 0);
       
  1412     TEST2(rc, KErrNone);
       
  1413     TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0)));
       
  1414     strm.Close();
       
  1415     TEST2(rc, KErrNone);
       
  1416     TEST(databuf == _L8("\x1\x2\x3\x4\x5"));
       
  1417 
       
  1418     rc = stmt.Next();
       
  1419     TEST2(rc, KSqlAtRow);
       
  1420     //ColumnBinary() makes an IPC call  (in _DEBUG mode) because:
       
  1421     // - the column length is exactly KSqlMaxDesLen.  
       
  1422     // - but at the same time the column length is equal to KIpcBufSize (in debug mode).
       
  1423     rc = strm.ColumnBinary(stmt, 0);
       
  1424     TEST2(rc, KErrNone);
       
  1425     TRAP(rc, strm.ReadL(databuf, stmt.ColumnSize(0)));
       
  1426     strm.Close();
       
  1427     TEST2(rc, KErrNone);
       
  1428     TEST(databuf == _L8("\x1\x2\x3\x4\x5\x6\x7\x8"));
       
  1429     
       
  1430     stmt.Close();
       
  1431     db.Close();
       
  1432 
       
  1433     rc = RSqlDatabase::Delete(KTestDbName1);
       
  1434     TEST2(rc, KErrNone);
       
  1435     }
  1356 
  1436 
  1357 /**
  1437 /**
  1358 @SYMTestCaseID			SYSLIB-SQL-CT-1608
  1438 @SYMTestCaseID			SYSLIB-SQL-CT-1608
  1359 @SYMTestCaseDesc		Setting long text parameter values test.
  1439 @SYMTestCaseDesc		Setting long text parameter values test.
  1360 @SYMTestPriority		High
  1440 @SYMTestPriority		High
  2192 	ColumnTextStreamTest();
  2272 	ColumnTextStreamTest();
  2193 
  2273 
  2194 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1621 RSqlColumnReadStream test. Long binary column "));
  2274 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1621 RSqlColumnReadStream test. Long binary column "));
  2195 	ColumnBinaryStreamTest();
  2275 	ColumnBinaryStreamTest();
  2196 
  2276 
       
  2277     TheTest.Next (_L(" @SYMTestCaseID:PDS-SQL-CT-4174 CSqlSrvSession::NewOutputStreamL() coverage test"));
       
  2278 	ColumnBinaryStreamTest2();
       
  2279 	
  2197 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1608 RSqlParamWriteStream test. Long text parameter "));
  2280 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1608 RSqlParamWriteStream test. Long text parameter "));
  2198 	TextParameterStreamTest();
  2281 	TextParameterStreamTest();
  2199 
  2282 
  2200 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1622 RSqlParamWriteStream test. Long binary parameter "));
  2283 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1622 RSqlParamWriteStream test. Long binary parameter "));
  2201 	BinaryParameterStreamTest();
  2284 	BinaryParameterStreamTest();