Beispiel #1
0
void SqlppDatabase::newNote(Note &note)
{
    using namespace std::chrono;
    auto reminder = system_clock::from_time_t(pt::to_time_t(note.reminder()));

    auto stmt = insert_into(notes_).set(
        notes_.title = note.title(), notes_.content = note.content(),
        notes_.notebook = note.notebook(), notes_.reminder = reminder);

    note.id(conn()(stmt));
}
Beispiel #2
0
void SqlppDatabase::updateNote(const Note &note)
{
    using namespace std::chrono;
    auto reminder = system_clock::from_time_t(pt::to_time_t(note.reminder()));
    auto stmt =
        update(notes_)
            .set(notes_.title = note.title(), notes_.content = note.content(),
                 notes_.notebook = note.notebook(), notes_.reminder = reminder)
            .where(notes_.id == note.id());
    conn()(stmt);
}
Beispiel #3
0
void Sqlite3Database::updateNote(const Note &note)
{
    auto date_str = pt::to_iso_string(note.reminder());

    clearStatement();
    stmt_cache_ << "UPDATE notes SET title=?1,content=?2,"
                << "notebook=?3,last_change=datetime('now','localtime'),"
                << "reminder=?4 where (id=?5)";

    auto result = prepareStatement(stmt_cache_.str());

    bindString(result, 1, note.title());
    bindString(result, 2, note.content());
    bindInt(result, 3, note.notebook());
    bindString(result, 4, date_str);
    bindInt(result, 5, note.id());
    if (isError(executeStep(result)))
        throw DatabaseException("updating note " + note.title() + " failed");
}
Beispiel #4
0
// DEMO : sqlite3 example with prepared statement parameters
void Sqlite3Database::newNote(Note &note)
{
    auto date_str = pt::to_iso_string(note.reminder());

    clearStatement();
    stmt_cache_ << "INSERT INTO notes(title,content,notebook,reminder) VALUES("
                << "?1, ?2, ?3, ?4"
                << ")";

    auto result = prepareStatement(stmt_cache_.str());

    bindString(result, 1, note.title());
    bindString(result, 2, note.content());
    bindInt(result, 3, note.notebook());
    bindString(result, 4, date_str);
    if (isError(executeStep(result)))
        throw DatabaseException("inserting note " + note.title() + " failed");

    // get the generated ID
    note.id(getLastInsertId());
}