Пример #1
0
// Synchronize a new notebook with what is in the database.  We basically
// just delete the old one & give it a new entry
qint32 LinkedNotebookTable::sync(qint32 lid, LinkedNotebook &notebook) {
    qint32 lastUSN = 0;
    NotebookTable ntable(db);
    SharedNotebookTable stable(db);

    if (lid == 0 && notebook.shareKey.isSet()) {
        lid = stable.findByShareKey(notebook.shareKey);
    }
    if (lid == 0 && notebook.uri.isSet()) {
        lid = ntable.findByUri(notebook.uri);
    }


    if (lid > 0) {
        lastUSN = getLastUpdateSequenceNumber(lid);
        // Delete the old record
        NSqlQuery query(*db);
        query.prepare("Delete from DataStore where lid=:lid and key>=3200 and key<3300");
        query.bindValue(":lid", lid);
        query.exec();
        query.finish();
    }

    if (lid == 0) {
        lid = ntable.getLid(notebook.guid);
        if (lid == 0) {
            ConfigStore cs(db);
            lid = cs.incrementLidCounter();
            NotebookTable ntable(db);

            // Build the dummy notebook entry
            Notebook book;
            book.guid = notebook.guid;
            book.name = notebook.shareName;
            book.updateSequenceNum = notebook.updateSequenceNum;
            book.published = true;
            Publishing publishing;
            publishing.uri = notebook.uri;
            book.publishing = publishing;

            if (notebook.stack.isSet()) {
                book.stack = notebook.stack;
            }

            ntable.sync(lid, book);
        }
    }

    add(lid, notebook, false);
    if (lastUSN > 0) {
        setLastUpdateSequenceNumber(lid, lastUSN);
    }

    return lid;
}
Пример #2
0
// Synchronize a new notebook with what is in the database.  We basically
// just delete the old one & give it a new entry
qint32 LinkedNotebookTable::sync(qint32 lid, LinkedNotebook &notebook) {
    qint32 lastUSN = 0;
    if (lid > 0) {
        lastUSN = getLastUpdateSequenceNumber(lid);

        // Delete the old record
        QSqlQuery query;
        query.prepare("Delete from DataStore where lid=:lid and key>=3200 and key<3300");
        query.bindValue(":lid", lid);
        query.exec();
    } else {
        ConfigStore cs;
        lid = cs.incrementLidCounter();
    }

    add(lid, notebook, false);
    if (lastUSN > 0) {
        setLastUpdateSequenceNumber(lid, lastUSN);
    }

    return lid;
}