MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / deleteNotebook

Method deleteNotebook

sql/notebooktable.cpp:639–679  ·  view source on GitHub ↗

Delete this notebook

Source from the content-addressed store, hash-verified

637
638// Delete this notebook
639void 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

Callers 1

deleteRequestedMethod · 0.80

Calls 9

findNotesByNotebookMethod · 0.80
lockForWriteMethod · 0.80
bindValueMethod · 0.80
updateNotebookMethod · 0.45
deleteNoteMethod · 0.45
isSetMethod · 0.45
prepareMethod · 0.45
execMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected