Пример #1
0
bool DbNote::existNote(Note & note)
{
    sqlite3_stmt *statement;
    string stmnt = "select count(*) from NoteTable where NoteKey = ?";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing select-Statement failed");
        return false;
    }
    req = sqlite3_bind_int(statement, 1, note.getNoteKey());

    if (req != SQLITE_OK)
    {
        throw SQLError("Binding Date into select statement failed");
        return false;
    }
    req = sqlite3_step(statement);

    int noteCount = static_cast<int>(sqlite3_column_int(statement, 0));

    sqlite3_finalize(statement);
    sqlite3_close(db);
    if (noteCount > 0)
        return true;
    return false;
}
Пример #2
0
bool DbNote::saveEntry(Note & note, save_t sav)
{
    Category cat;
    cat.setKatKey(note.getKatKey());

    if (! existCategory(cat))
    {
        cout << "Category doesn't exists" << endl;
        return false;
    }
    if (note.getNoteRef() != 0)
    {
        Note ref_note;
        ref_note.setNoteKey(note.getNoteRef());
        if( ! existNote(ref_note) )
        {
            std::cout << "Can't find given note reference" << std::endl;
            return false;
        }
    }
    if (sav == append_entr)
    {
        if (note.getNoteKey() != 0)
        {
            cout << "Note entry exists" << endl;
            return false;
        }
        if (!insertTable(note))
        {
            cerr << "Insert notice failed" << endl;
            return false;
        }
    }
    else if (sav == write_entr)
    {
        if ( ! existNote(note) )
        {
            cout << "Can't override notice cause of the notice doesn't exists"
                 << endl;
            return false;
        }
        if (!updateRow( note))
        {
            cerr << "Update the notice failed" << endl;
            return false;
        }
    }
    return true;
}
Пример #3
0
bool DbNote::updateRow(Note & note)
{
    sqlite3_stmt *statement;
    string stmnt =
        "update NoteTable SET date=?,NoteText=?,NoteTitle=?,NoteRef=?,KatKey=? where NoteKey=?;";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Update-Statement failed");
        return false;
    }
    req = sqlite3_bind_text(statement, 1,
                            (note.getDate().getDateString()).c_str(),
                            (note.getDate().getDateString()).length(), SQLITE_TRANSIENT);

    if (req != SQLITE_OK)
    {
        throw SQLError("Binding Date into update statement failed");
        return false;
    }
    req = sqlite3_bind_text(statement, 2, (note.getNoteText()).c_str(),
                            (note.getNoteText()).length(), SQLITE_TRANSIENT);
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding note text into update statement failed");
        return false;
    }
    req = sqlite3_bind_text(statement, 3, (note.getNotetitle()).c_str(),
                            (note.getNotetitle()).length(), SQLITE_TRANSIENT);
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding note title into update statement failed");
        return false;
    }
    req = sqlite3_bind_int(statement, 4, note.getNoteRef());
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding note ref into update statement failed");
        return false;
    }
    req = sqlite3_bind_int(statement, 5, note.getKatKey());
    if (req != SQLITE_OK)
    {
        throw SQLError(
            "Binding note category key into update statement failed");
        return false;
    }
    req = sqlite3_bind_int(statement, 6, note.getNoteKey());
    if (req != SQLITE_OK)
    {
        throw SQLError("Binding note key into update statement failed");
        return false;
    }
    req = sqlite3_step(statement);
    if (req != SQLITE_DONE)
    {
        throw SQLError("execute of insert statement failed");
        return false;
    }
    sqlite3_finalize(statement);
    sqlite3_close(db);
    return true;
}