| 708 | } |
| 709 | |
| 710 | bool CDatabaseTree::Delete(int id, bool delKey) |
| 711 | { |
| 712 | // 如果是最后的一个,则从 key 相关表中删除 key |
| 713 | if(delKey) { |
| 714 | auto leaf = GetLeaf(id); |
| 715 | if(leaf.GetKey() > 0) { |
| 716 | auto leaves = GetLeavesByKey(leaf.GetKey()); |
| 717 | if(leaves.count() == 1) { |
| 718 | bool ok = OnDeleteKey(leaf.GetKey()); |
| 719 | if(!ok) |
| 720 | return ok; |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | QSqlQuery query(GetDatabase()); |
| 725 | query.prepare("DELETE FROM `" + m_szTableName + "` WHERE `id` = :id"); |
| 726 | query.bindValue(":id", id); |
| 727 | bool bRet = query.exec(); |
| 728 | if (!bRet) { |
| 729 | SetError("Failed to delete item: " + query.lastError().text() |
| 730 | + "; Sql: " + query.executedQuery() |
| 731 | + "; table: " + m_szTableName |
| 732 | + "; id: " + QString::number(id)); |
| 733 | qCritical(log) << GetError(); |
| 734 | } |
| 735 | return bRet; |
| 736 | } |
| 737 | |
| 738 | bool CDatabaseTree::Delete(QList<int> items, bool delKey) |
| 739 | { |
no test coverage detected