| 289 | } |
| 290 | |
| 291 | bool CDatabaseNode::DeleteNode( |
| 292 | int id, std::function<bool (int)> cbDeleteLeaf, bool checkReturn) |
| 293 | { |
| 294 | bool bRet = false; |
| 295 | // 删除子目录 |
| 296 | auto folders = GetSubNodes(id); |
| 297 | foreach(auto f, folders) { |
| 298 | bRet = DeleteNode(f.GetId(), cbDeleteLeaf, checkReturn); |
| 299 | if(checkReturn && !bRet) |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | // 删除其下面的所有条目 |
| 304 | if(cbDeleteLeaf) { |
| 305 | bRet = cbDeleteLeaf(id); |
| 306 | if(checkReturn && !bRet) { |
| 307 | SetError("Failed to call cbDeleteLeaf"); |
| 308 | qCritical(log) << GetError(); |
| 309 | return false; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | bRet = OnDeleteLeafs(id); |
| 314 | if(checkReturn && !bRet) { |
| 315 | SetError("Failed to call OnDeleteLeafs"); |
| 316 | qCritical(log) << GetError(); |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | // 删除文件夹 |
| 321 | QSqlQuery query(GetDatabase()); |
| 322 | query.prepare("DELETE FROM `" + m_szTableName + "` WHERE `id` = :id"); |
| 323 | query.bindValue(":id", id); |
| 324 | bRet = query.exec(); |
| 325 | if (bRet) |
| 326 | emit sigChanged(); |
| 327 | else { |
| 328 | SetError("Failed to delete folders: " + query.lastError().text() |
| 329 | + "; Sql: " + query.executedQuery()); |
| 330 | qCritical(log) << GetError(); |
| 331 | } |
| 332 | |
| 333 | return bRet; |
| 334 | } |
| 335 | |
| 336 | bool CDatabaseNode::OnDeleteLeafs(int id) |
| 337 | { |
no outgoing calls
no test coverage detected