| 671 | } |
| 672 | |
| 673 | bool CDatabaseTree::Update(const TreeItem &item) |
| 674 | { |
| 675 | // Check if it is a leaf |
| 676 | if(item.IsNode()) { |
| 677 | qCritical(log) << "The item is not leaf"; |
| 678 | return false; |
| 679 | } |
| 680 | |
| 681 | QSqlQuery query(GetDatabase()); |
| 682 | query.prepare( |
| 683 | "UPDATE `" + m_szTableName + "` SET " |
| 684 | "`name` = :name, " |
| 685 | "`key` = :key, " |
| 686 | "`created_time` = :created_time, " |
| 687 | "`modified_time` = :modified_time, " |
| 688 | "`last_visit_time` = :last_visit_time, " |
| 689 | "`parent_id` = :parent_id " |
| 690 | "WHERE `id` = :id" |
| 691 | ); |
| 692 | query.bindValue(":name", item.GetName()); |
| 693 | query.bindValue(":key", item.GetKey()); |
| 694 | query.bindValue(":created_time", item.GetCreateTime()); |
| 695 | query.bindValue(":modified_time", QDateTime::currentDateTime()); |
| 696 | query.bindValue(":last_visit_time", item.GetLastVisitTime()); |
| 697 | query.bindValue(":parent_id", item.GetParentId()); |
| 698 | query.bindValue(":id", item.GetId()); |
| 699 | qDebug(log) << "Sql:" << query.executedQuery(); |
| 700 | qDebug(log) << "Bound value:" << query.boundValues(); |
| 701 | bool bRet = query.exec(); |
| 702 | if (!bRet) { |
| 703 | SetError("Failed to update tree item: " + query.lastError().text() |
| 704 | + "; Sql: " + query.executedQuery()); |
| 705 | qCritical(log) << GetError(); |
| 706 | } |
| 707 | return bRet; |
| 708 | } |
| 709 | |
| 710 | bool CDatabaseTree::Delete(int id, bool delKey) |
| 711 | { |
no test coverage detected