1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
40 // used for the config test |
40 // used for the config test |
41 _LIT8(KServerConfigString1, " ; cache_size = 1024 ; page_size =1024 ;encoding = \"UTF-8\" "); |
41 _LIT8(KServerConfigString1, " ; cache_size = 1024 ; page_size =1024 ;encoding = \"UTF-8\" "); |
42 _LIT8(KServerConfigString2, " badconfigstring "); |
42 _LIT8(KServerConfigString2, " badconfigstring "); |
43 _LIT8(KServerConfigString3, " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
43 _LIT8(KServerConfigString3, " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
44 _LIT8(KServerConfigString4, ""); |
44 _LIT8(KServerConfigString4, ""); |
|
45 _LIT8(KServerConfigString5, "dfgdfrgdkfjgjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj43w3wk4jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); |
45 |
46 |
46 const TUid KSecureUid = {0x1111CCCC};//The same as the UID in the MMP file |
47 const TUid KSecureUid = {0x1111CCCC};//The same as the UID in the MMP file |
47 |
48 |
48 _LIT(KCreateDbScript, "z:\\test\\contacts_schema_to_vendors.sql"); |
49 _LIT(KCreateDbScript, "z:\\test\\contacts_schema_to_vendors.sql"); |
49 _LIT(KFillDbScript, "z:\\test\\add_simple_contacts.sql"); |
50 _LIT(KFillDbScript, "z:\\test\\add_simple_contacts.sql"); |
242 rc = db.Create(KTestCfgDbName,&KServerConfigString4); |
243 rc = db.Create(KTestCfgDbName,&KServerConfigString4); |
243 TEST2(rc, KErrNone); |
244 TEST2(rc, KErrNone); |
244 db.Close(); |
245 db.Close(); |
245 rc2 = RSqlDatabase::Delete(KTestCfgDbName); |
246 rc2 = RSqlDatabase::Delete(KTestCfgDbName); |
246 TEST2(rc2, KErrNone); |
247 TEST2(rc2, KErrNone); |
247 |
248 |
|
249 // create database with very long config specified |
|
250 rc = db.Create(KTestCfgDbName, &KServerConfigString5); |
|
251 TEST2(rc, KErrArgument); |
|
252 db.Close(); |
|
253 |
248 //Secure shared database file on an existing drive (C:). |
254 //Secure shared database file on an existing drive (C:). |
249 //Very long database file name (> 90 characters) but still a valid name. |
255 //Very long database file name (> 90 characters) but still a valid name. |
250 rc = db.Create(KTestDbName4, securityPolicy); |
256 rc = db.Create(KTestDbName4, securityPolicy); |
251 db.Close(); |
257 db.Close(); |
252 rc2 = RSqlDatabase::Delete(KTestDbName4); |
258 rc2 = RSqlDatabase::Delete(KTestDbName4); |
1108 } |
1114 } |
1109 |
1115 |
1110 //Read row 2 using ColumnText(TInt aColumnIndex, TDes& aDest). |
1116 //Read row 2 using ColumnText(TInt aColumnIndex, TDes& aDest). |
1111 rc = stmt.ColumnText(1, colData); |
1117 rc = stmt.ColumnText(1, colData); |
1112 TEST2(rc, KErrNone); |
1118 TEST2(rc, KErrNone); |
|
1119 //Too small target buffer |
|
1120 TBuf<3> buf1; |
|
1121 rc = stmt.ColumnText(1, buf1); |
|
1122 TEST2(rc, KErrOverflow); |
1113 |
1123 |
1114 //Check the column value |
1124 //Check the column value |
1115 for(i=0;i<KTextLen;++i) |
1125 for(i=0;i<KTextLen;++i) |
1116 { |
1126 { |
1117 TEST(colData[i] == (TUint8)KChar2); |
1127 TEST(colData[i] == (TUint8)KChar2); |
1222 sql.Append(_L8("')")); |
1232 sql.Append(_L8("')")); |
1223 |
1233 |
1224 rc = db.Exec(sql); |
1234 rc = db.Exec(sql); |
1225 TEST2(rc, 1); |
1235 TEST2(rc, 1); |
1226 |
1236 |
|
1237 //Insert row 3: the binary column length is just 2 bytes |
|
1238 rc = db.Exec(_L("INSERT INTO A VALUES(3, x'A5D3')")); |
|
1239 TEST2(rc, 1); |
|
1240 |
1227 //Prepare SELECT SQL statement |
1241 //Prepare SELECT SQL statement |
1228 _LIT8(KSqlStmt3, "SELECT * FROM A"); |
1242 _LIT8(KSqlStmt3, "SELECT * FROM A"); |
1229 RSqlStatement stmt = PrepareSqlStmt<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt3, KErrNone); |
1243 RSqlStatement stmt = PrepareSqlStmt<TDesC8, TBuf8<KSqlBufSize> >(db, KSqlStmt3, KErrNone); |
1230 |
1244 |
1231 //Move on row 1 |
1245 //Move on row 1 |
1312 for(i=0;i<KBufMaxLen;++i) |
1326 for(i=0;i<KBufMaxLen;++i) |
1313 { |
1327 { |
1314 TUint8 val = colBuf[i]; |
1328 TUint8 val = colBuf[i]; |
1315 TEST(val = KHexVal2); |
1329 TEST(val = KHexVal2); |
1316 } |
1330 } |
|
1331 |
|
1332 //Move on row 3. The binary column value length is just 2 bytes. |
|
1333 rc = stmt.Next(); |
|
1334 TEST2(rc, KSqlAtRow); |
|
1335 rc = stmt.Next(); |
|
1336 TEST2(rc, KSqlAtRow); |
|
1337 TBuf8<2> buf1; |
|
1338 rc = stmt.ColumnBinary(1, buf1); |
|
1339 TEST2(rc, KErrNone); |
|
1340 TEST2(buf1.Length(), 2); |
|
1341 TBuf8<1> buf2; |
|
1342 rc = stmt.ColumnBinary(1, buf2); |
|
1343 TEST2(rc, KErrOverflow); |
1317 |
1344 |
1318 stmt.Close(); |
1345 stmt.Close(); |
1319 |
1346 |
1320 //Deallocate buf |
1347 //Deallocate buf |
1321 delete buf; |
1348 delete buf; |
1532 |
1559 |
1533 //Open the parameter stream |
1560 //Open the parameter stream |
1534 RSqlParamWriteStream paramStream; |
1561 RSqlParamWriteStream paramStream; |
1535 rc = paramStream.BindBinary(stmt, 0); |
1562 rc = paramStream.BindBinary(stmt, 0); |
1536 TEST2(rc, KErrNone); |
1563 TEST2(rc, KErrNone); |
|
1564 paramStream.Close(); |
|
1565 //Open the parameter stream with BindBinaryL() |
|
1566 TRAP(rc, paramStream.BindBinaryL(stmt, 0)); |
|
1567 TEST2(rc, KErrNone); |
1537 |
1568 |
1538 //Prepare and set the parameter value (NULL parameter value) |
1569 //Prepare and set the parameter value (NULL parameter value) |
1539 TPtr8 prmVal = buf->Des(); |
1570 TPtr8 prmVal = buf->Des(); |
1540 prmVal.SetLength(0); |
1571 prmVal.SetLength(0); |
1541 |
1572 |
2057 err = db.Size(size1, _L("TheDbDoesNotExist")); |
2088 err = db.Size(size1, _L("TheDbDoesNotExist")); |
2058 TEST2(err, KSqlErrGeneral); |
2089 TEST2(err, KSqlErrGeneral); |
2059 TPtrC msg = db.LastErrorMessage(); |
2090 TPtrC msg = db.LastErrorMessage(); |
2060 TheTest.Printf(_L("Non-existing attached database, error message: %S\r\n"), &msg); |
2091 TheTest.Printf(_L("Non-existing attached database, error message: %S\r\n"), &msg); |
2061 |
2092 |
|
2093 //An attempt to get the size when the attached database name contains "bad" unicode characters (cannot be converted to UTF8) |
|
2094 TBuf<2> dbName3; |
|
2095 dbName3.SetLength(2); |
|
2096 dbName3[0] = TChar(0xD800); |
|
2097 dbName3[1] = TChar(0xFC00); |
|
2098 err = db.Size(size1, dbName3); |
|
2099 TEST2(err, KErrGeneral); |
|
2100 |
2062 err = db.Detach(KAttachDbName); |
2101 err = db.Detach(KAttachDbName); |
2063 TEST2(err, KErrNone); |
2102 TEST2(err, KErrNone); |
2064 db.Close(); |
2103 db.Close(); |
2065 (void)RSqlDatabase::Delete(KTestDbName8); |
2104 (void)RSqlDatabase::Delete(KTestDbName8); |
2066 (void)RSqlDatabase::Delete(KTestDbName1); |
2105 (void)RSqlDatabase::Delete(KTestDbName1); |