Delete this notebook
| 637 | |
| 638 | // Delete this notebook |
| 639 | void NotebookTable::deleteNotebook(qint32 lid) { |
| 640 | if (!exists(lid)) |
| 641 | return; |
| 642 | |
| 643 | // First delete all the notes for this notebook and |
| 644 | // move them to the default notebook |
| 645 | QList<qint32> notes; |
| 646 | NoteTable noteTable(db); |
| 647 | QString guid; |
| 648 | getGuid(guid, lid); |
| 649 | qint32 defaultNotebookLid = getDefaultNotebookLid(); |
| 650 | noteTable.findNotesByNotebook(notes, guid); |
| 651 | for (qint32 i=0; i<notes.size(); i++) { |
| 652 | noteTable.updateNotebook(notes[i], defaultNotebookLid, true); |
| 653 | noteTable.deleteNote(notes[i], true); |
| 654 | } |
| 655 | |
| 656 | // Now delete the actual notebook |
| 657 | Notebook notebook; |
| 658 | get(notebook, lid); |
| 659 | if (notebook.updateSequenceNum.isSet() && notebook.updateSequenceNum > 0) { |
| 660 | NSqlQuery query(db); |
| 661 | db->lockForWrite(); |
| 662 | query.prepare("delete from datastore where lid=:lid and key=:key"); |
| 663 | query.bindValue(":lid", lid); |
| 664 | query.bindValue(":key", NOTEBOOK_IS_DELETED); |
| 665 | query.exec(); |
| 666 | |
| 667 | query.prepare("insert into DataStore (lid, key, data) values (:lid, :key, :data)"); |
| 668 | query.bindValue(":lid", lid); |
| 669 | query.bindValue(":key", NOTEBOOK_IS_DELETED); |
| 670 | query.bindValue(":data", true); |
| 671 | query.exec(); |
| 672 | query.finish(); |
| 673 | db->unlock(); |
| 674 | |
| 675 | setDirty(lid, true); |
| 676 | } else { |
| 677 | expunge(lid); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | |
| 682 |
no test coverage detected