1002 sqlite3_stmt *st; |
1002 sqlite3_stmt *st; |
1003 |
1003 |
1004 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
1004 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
1005 &st, (const void**) NULL); |
1005 &st, (const void**) NULL); |
1006 |
1006 |
|
1007 if (rc == SQLITE_OK) |
|
1008 { |
|
1009 Cleanup_sqlite3_finalize_PushL(st); |
|
1010 rc = sqlite3_step(st); |
|
1011 if (rc != SQLITE_DONE) |
|
1012 { |
|
1013 User::Leave(KErrUnknown); |
|
1014 } |
|
1015 CleanupStack::PopAndDestroy(); // st |
|
1016 } |
|
1017 else |
|
1018 { |
|
1019 User::Leave(KErrCorrupt); |
|
1020 } |
|
1021 } |
|
1022 |
|
1023 void CShowEngine::DBSwapDownloadsL(TDownload aFirstDL, TDownload aSecondDL) |
|
1024 { |
|
1025 DP("CShowEngine::DBSwapDownloadsL"); |
|
1026 _LIT(KSqlStatement, "update downloads set uid=%u where dl_index=%d"); |
|
1027 |
|
1028 iSqlBuffer.Format(KSqlStatement, aFirstDL.iUid, aSecondDL.iIndex); |
|
1029 sqlite3_stmt *st; |
|
1030 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1031 &st, (const void**) NULL); |
|
1032 |
|
1033 if (rc == SQLITE_OK) |
|
1034 { |
|
1035 Cleanup_sqlite3_finalize_PushL(st); |
|
1036 rc = sqlite3_step(st); |
|
1037 if (rc != SQLITE_DONE) |
|
1038 { |
|
1039 User::Leave(KErrUnknown); |
|
1040 } |
|
1041 CleanupStack::PopAndDestroy(); // st |
|
1042 } |
|
1043 else |
|
1044 { |
|
1045 User::Leave(KErrCorrupt); |
|
1046 } |
|
1047 |
|
1048 iSqlBuffer.Format(KSqlStatement, aSecondDL.iUid, aFirstDL.iIndex); |
|
1049 |
|
1050 rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1051 &st, (const void**) NULL); |
|
1052 |
1007 if (rc == SQLITE_OK) |
1053 if (rc == SQLITE_OK) |
1008 { |
1054 { |
1009 Cleanup_sqlite3_finalize_PushL(st); |
1055 Cleanup_sqlite3_finalize_PushL(st); |
1010 rc = sqlite3_step(st); |
1056 rc = sqlite3_step(st); |
1011 if (rc != SQLITE_DONE) |
1057 if (rc != SQLITE_DONE) |
1380 } |
1426 } |
1381 } |
1427 } |
1382 } |
1428 } |
1383 } |
1429 } |
1384 |
1430 |
|
1431 EXPORT_C void CShowEngine::MoveDownloadUpL(TUint aUid) |
|
1432 { |
|
1433 DP("CShowEngine::MoveDownLoadUpL"); |
|
1434 _LIT(KSqlStatement, "select * from downloads"); |
|
1435 iSqlBuffer.Format(KSqlStatement); |
|
1436 |
|
1437 sqlite3_stmt *st; |
|
1438 |
|
1439 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1440 &st, (const void**) NULL); |
|
1441 |
|
1442 if (rc == SQLITE_OK) |
|
1443 { |
|
1444 RArray<TDownload> downloads; |
|
1445 CleanupClosePushL(downloads); |
|
1446 |
|
1447 rc = sqlite3_step(st); |
|
1448 Cleanup_sqlite3_finalize_PushL(st); |
|
1449 |
|
1450 TInt selectedIdx = -1; |
|
1451 while (rc == SQLITE_ROW && selectedIdx == -1) |
|
1452 { |
|
1453 TDownload download; |
|
1454 |
|
1455 download.iIndex = sqlite3_column_int(st, 0); |
|
1456 download.iUid = sqlite3_column_int(st, 1); |
|
1457 |
|
1458 downloads.Append(download); |
|
1459 |
|
1460 if (download.iUid == aUid) |
|
1461 { |
|
1462 selectedIdx = downloads.Count()-1; |
|
1463 } |
|
1464 |
|
1465 rc = sqlite3_step(st); |
|
1466 } |
|
1467 CleanupStack::PopAndDestroy();//st, downloads |
|
1468 |
|
1469 // If the selected download was found in the database |
|
1470 if (selectedIdx != -1) |
|
1471 { |
|
1472 // Swap the specified download with the one above it |
|
1473 TDownload selectedDownload = downloads[selectedIdx]; |
|
1474 TDownload previousDownload = downloads[selectedIdx - 1]; |
|
1475 |
|
1476 // SQL - Update index (with index of selected download) where uid is of previous download |
|
1477 // and update index (with index of previous download) where uid if of selected download |
|
1478 DBSwapDownloadsL(selectedDownload, previousDownload); |
|
1479 } |
|
1480 else |
|
1481 { |
|
1482 User::Leave(KErrNotFound); |
|
1483 } |
|
1484 |
|
1485 CleanupStack::PopAndDestroy(); // downloads |
|
1486 } |
|
1487 else |
|
1488 { |
|
1489 User::Leave(KErrCorrupt); |
|
1490 } |
|
1491 } |
|
1492 |
|
1493 EXPORT_C void CShowEngine::MoveDownloadDownL(TUint aUid) |
|
1494 { |
|
1495 DP("CShowEngine::MoveDownLoadDownL"); |
|
1496 |
|
1497 // An upside-down list will result in the download moving down |
|
1498 _LIT(KSqlStatement, "select * from downloads order by dl_index desc"); |
|
1499 iSqlBuffer.Format(KSqlStatement); |
|
1500 |
|
1501 sqlite3_stmt *st; |
|
1502 |
|
1503 int rc = sqlite3_prepare16_v2(&iDB, (const void*) iSqlBuffer.PtrZ(), -1, |
|
1504 &st, (const void**) NULL); |
|
1505 |
|
1506 if (rc == SQLITE_OK) |
|
1507 { |
|
1508 RArray<TDownload> downloads; |
|
1509 CleanupClosePushL(downloads); |
|
1510 |
|
1511 rc = sqlite3_step(st); |
|
1512 Cleanup_sqlite3_finalize_PushL(st); |
|
1513 |
|
1514 TInt selectedIdx = -1; |
|
1515 while (rc == SQLITE_ROW && selectedIdx == -1) |
|
1516 { |
|
1517 TDownload download; |
|
1518 |
|
1519 download.iIndex = sqlite3_column_int(st, 0); |
|
1520 download.iUid = sqlite3_column_int(st, 1); |
|
1521 |
|
1522 downloads.Append(download); |
|
1523 |
|
1524 if (download.iUid == aUid) |
|
1525 { |
|
1526 selectedIdx = downloads.Count()-1; |
|
1527 } |
|
1528 |
|
1529 rc = sqlite3_step(st); |
|
1530 } |
|
1531 CleanupStack::PopAndDestroy();//st, downloads |
|
1532 |
|
1533 // If the selected download was found in the database |
|
1534 if (selectedIdx != -1) |
|
1535 { |
|
1536 // Swap the specified download with the one above it |
|
1537 TDownload selectedDownload = downloads[selectedIdx]; |
|
1538 TDownload previousDownload = downloads[selectedIdx - 1]; |
|
1539 |
|
1540 // SQL - Update index (with index of selected download) where uid is of previous download |
|
1541 // and update index (with index of previous download) where uid if of selected download |
|
1542 DBSwapDownloadsL(selectedDownload, previousDownload); |
|
1543 } |
|
1544 else |
|
1545 { |
|
1546 User::Leave(KErrNotFound); |
|
1547 } |
|
1548 |
|
1549 CleanupStack::PopAndDestroy(); // downloads |
|
1550 } |
|
1551 else |
|
1552 { |
|
1553 User::Leave(KErrCorrupt); |
|
1554 } |
|
1555 } |