Reads all nodes from a database and builds the tree; returns `true` on success
| 55 | |
| 56 | /// Reads all nodes from a database and builds the tree; returns `true` on success |
| 57 | static bool read_nodes(QSqlDatabase *db, Execution &ex) |
| 58 | { |
| 59 | const auto query = "select * from Nodes;"; |
| 60 | |
| 61 | QSqlQuery select_stmt (*db); |
| 62 | select_stmt.prepare(query); |
| 63 | |
| 64 | auto &tree = ex.tree(); |
| 65 | |
| 66 | const auto total_nodes = count_nodes(db); |
| 67 | print("We have {} nodes", total_nodes); |
| 68 | |
| 69 | tree.db_initialize(total_nodes); |
| 70 | |
| 71 | bool success = select_stmt.exec(); |
| 72 | |
| 73 | if(!success) return false; |
| 74 | |
| 75 | while (select_stmt.next()) |
| 76 | { |
| 77 | const auto nid = NodeID(select_stmt.value(0).toInt()); |
| 78 | const auto pid = NodeID(select_stmt.value(1).toInt()); |
| 79 | const auto alt = select_stmt.value(2).toInt(); |
| 80 | const auto kids = select_stmt.value(3).toInt(); |
| 81 | const auto status = tree::NodeStatus(select_stmt.value(4).toInt()); |
| 82 | const auto label = select_stmt.value(5).toString().toStdString(); |
| 83 | |
| 84 | if (pid == NodeID::NoNode) |
| 85 | { |
| 86 | tree.db_createRoot(nid, label); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | tree.db_addChild(nid, pid, alt, status, label); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return success; |
| 95 | } |
| 96 | |
| 97 | /// Read all bookmarks from the database |
| 98 | static bool read_bookmarks(QSqlDatabase *db, Execution &ex) |
no test coverage detected