Create the NoteTable table.
| 57 | |
| 58 | //* Create the NoteTable table. |
| 59 | void DataStore::createTable() { |
| 60 | db->lockForWrite(); |
| 61 | QLOG_TRACE() << "Entering DataStore::createTable()"; |
| 62 | |
| 63 | QLOG_DEBUG() << "Creating table DataStore"; |
| 64 | NSqlQuery sql(db); |
| 65 | QString command("Create table DataStore (" + |
| 66 | QString("lid integer,") + |
| 67 | QString("key integer,") + |
| 68 | QString("data blob default null collate nocase)")); |
| 69 | if (!sql.exec(command)) { |
| 70 | QLOG_ERROR() << "Creation of DataStore table failed: " << sql.lastError(); |
| 71 | } |
| 72 | |
| 73 | sql.exec("CREATE INDEX DataStore_Lid on DataStore (lid)"); |
| 74 | sql.exec("CREATE INDEX DataStore_Key on DataStore (key)"); |
| 75 | |
| 76 | sql.prepare("Create view SearchModel as select lid, data as name from DataStore where key=2001"); |
| 77 | if (!sql.exec()) { |
| 78 | QLOG_ERROR() << "Creation of SearchModel table failed: " << sql.lastError(); |
| 79 | } |
| 80 | |
| 81 | sql.prepare("Create View TagModel as select a.lid, (select d.data from DataStore d where d.key=1000 and a.lid = d.lid) as guid, (select data from datastore b1 where b1.lid = (select b.data from DataStore b where b.key=1002 and a.lid = b.lid)) as parent_gid, (select c.data from DataStore c where c.key=1001 and a.lid = c.lid) as name, (select e.data from DataStore e where e.key=1006 and a.lid = e.lid) as account from DataStore a where a.key=1000;"); |
| 82 | if (!sql.exec()) { |
| 83 | QLOG_ERROR() << "Creation of TagModel table failed: " << sql.lastError(); |
| 84 | } |
| 85 | |
| 86 | sql.prepare("Create View NotebookModel as select a.lid, (select b.data from DataStore b where b.key=3002 and a.lid = b.lid) as stack, (select c.data from DataStore c where c.key=3001 and a.lid = c.lid) as name, (select d.data from DataStore d where d.key=3201 and a.lid = d.lid) as username, (select e.data from DataStore e where e.key=3999 and a.lid = e.lid) as isClosed from DataStore a where a.key=3000;"); |
| 87 | if (!sql.exec()) { |
| 88 | QLOG_ERROR() << "Creation of NotebookModel table failed: " << sql.lastError(); |
| 89 | } |
| 90 | |
| 91 | if (!sql.exec("Create virtual table SearchIndex using fts4 (lid int, weight int, source text, content text)")) { |
| 92 | QLOG_ERROR() << "Creation of SearchIndex table failed: " << sql.lastError(); |
| 93 | } |
| 94 | sql.finish(); |
| 95 | db->unlock(); |
| 96 | Notebook notebook; |
| 97 | NotebookTable table(db); |
| 98 | notebook.name = "My Notebook"; |
| 99 | notebook.defaultNotebook = true; |
| 100 | QUuid uuid; |
| 101 | notebook.guid = uuid.createUuid().toString().replace("{","").replace("}",""); |
| 102 | table.add(0,notebook,true,false); |
| 103 | } |
| 104 |