Beispiel #1
0
// implementation of NotebookDatabase interface
std::vector<Notebook> Sqlite3Database::listNotebooks()
{
    auto result = prepareStatement("SELECT * FROM notebooks");
    int status = executeStep(result);
    if (isError(status))
        throw DatabaseException("listing notebooks failed, invalid result");

    std::vector<Notebook> result_vec;
    while (status != SQLITE_DONE) {
        result_vec.emplace_back(getInt(result, 0), getString(result, 1));
        status = executeStep(result);
    }
    return result_vec;
}
Beispiel #2
0
// create database structure
void Sqlite3Database::setupDb()
{
    auto result = prepareStatement("DROP TABLE IF EXISTS tags_nm;");
    if (isError(executeStep(result)))
        throw DatabaseException("dropping table notebooks failed");

    result = prepareStatement("DROP TABLE IF EXISTS notes;");
    if (isError(executeStep(result)))
        throw DatabaseException("dropping table notebooks failed");

    result = prepareStatement("DROP TABLE IF EXISTS tags;");
    if (isError(executeStep(result)))
        throw DatabaseException("dropping table tags failed");

    result = prepareStatement("DROP TABLE IF EXISTS notebooks;");
    if (isError(executeStep(result)))
        throw DatabaseException("dropping table tags failed");

    result =
        prepareStatement("CREATE TABLE notebooks ("
                         "id		integer primary key autoincrement,"
                         "title	varchar(255)"
                         ")");

    if (isError(executeStep(result)))
        throw DatabaseException("creating table notebooks failed");

    result =
        prepareStatement("CREATE TABLE tags ("
                         "id	 	integer primary key autoincrement,"
                         "title	varchar(255)"
                         ")");

    if (isError(executeStep(result)))
        throw DatabaseException("creating table tags failed");

    result = prepareStatement(
        "CREATE TABLE notes ("
        "id      	    integer primary key autoincrement,"
        "title   	    varchar(255),"
        "content	    text,"
        "notebook 	    integer references notebooks(id) ON DELETE CASCADE,"
        "last_change    timestamp DEFAULT (datetime('now','localtime')),"
        "reminder	    timestamp"
        ")");

    if (isError(executeStep(result)))
        throw DatabaseException("creating table notes failed");

    result = prepareStatement("CREATE TABLE tags_nm ("
                              "tag_id	integer references tags(id)"
                              " ON DELETE CASCADE,"
                              "note_id	integer references notes(id)"
                              " ON DELETE CASCADE"
                              ")");

    if (isError(executeStep(result)))
        throw DatabaseException("creating table tags_nm failed");
}
Beispiel #3
0
std::vector<Note> Sqlite3Database::searchNotes(const std::string &term)
{
    clearStatement();
    stmt_cache_
        << "SELECT notes.id, notes.title, notes.content, notes.notebook,"
           "notes.last_change, notes.reminder FROM notes left join tags_nm ON "
           "(notes.id=tags_nm.note_id)"
           " left join tags ON (tags_nm.tag_id=tags.id) WHERE ("
           " notes.title like '%" << term << "%' or notes.content like '%"
        << term << "%' or tags.title like '%" << term << "%')";
    auto result = prepareStatement(stmt_cache_.str());
    int state = SQLITE_OK;

    std::vector<Note> result_vec;
    do {
        state = executeStep(result);
        if (isError(state))
            throw DatabaseException("Searching for notes failed with ec=" +
                                    std::to_string(state));
        if (state == SQLITE_DONE)
            break;

        result_vec.emplace_back(getInt(result, 0), getString(result, 1),
                                getString(result, 2), getInt(result, 3),
                                getTimestamp(result, 4),
                                getTimestamp(result, 5));
    } while (state != SQLITE_DONE);
    return result_vec;
}
Beispiel #4
0
std::vector<Note> Sqlite3Database::loadNotesForTag(const bigint_t tag_id)
{
    clearStatement();
    stmt_cache_ << "SELECT notes.id, notes.title, notes.content, "
                   "notes.notebook, notes.last_change, "
                << "notes.reminder FROM notes join tags_nm ON "
                   "(notes.id=tags_nm.note_id)"
                << " WHERE (tag_id = " << std::to_string(tag_id) << ")";
    auto result = prepareStatement(stmt_cache_.str());
    int state = SQLITE_OK;

    std::vector<Note> result_vec;
    do {
        state = executeStep(result);
        if (isError(state))
            throw DatabaseException("listing notes failed, invalid result");
        if (state == SQLITE_DONE)
            break;

        result_vec.emplace_back(getInt(result, 0), getString(result, 1),
                                getString(result, 2), getInt(result, 3),
                                getTimestamp(result, 4),
                                getTimestamp(result, 5));
    } while (state != SQLITE_DONE);
    return result_vec;
}
Beispiel #5
0
uint32_t MoveEvent::fireStepEvent(Creature* creature, Item* item, const Position& pos)
{
	if (m_scripted) {
		return executeStep(creature, item, pos);
	} else {
		return stepFunction(creature, item, pos);
	}
}
Beispiel #6
0
void MiniStepper::step(long steps)
{
	long absSteps = abs(steps);
	byte stepDirection = (steps<0 ? -1 : 1);
	for (long i=0; i<absSteps; i+=stepDirection) {
		incrementStep(stepDirection);
		executeStep();
	}
}
TVerdict CCommDbTest005_03::doTestStepL( )
	{
	INFO_PRINTF1(_L("Step 005.03 called "));

	SetTestStepResult(EFail);	
	if ( executeStep() == KErrNotFound )
		SetTestStepResult(EPass);
	return TestStepResult();
	}
Beispiel #8
0
void Sqlite3Database::deleteTag(const bigint_t tag_id)
{
    clearStatement();
    stmt_cache_ << "DELETE FROM tags WHERE id=" << std::to_string(tag_id);
    auto result = prepareStatement(stmt_cache_.str());
    if (isError(executeStep(result)))
        throw DatabaseException("deleting tag " + std::to_string(tag_id) +
                                " failed");
}
Beispiel #9
0
void Emulator::execute()
{
	while (!resourcesStream.empty())
	{
		LOG("timestamp: " << timestamp);
		executeStep();
		collectStatistics();
		++ timestamp;
	}
}
Beispiel #10
0
bigint_t Sqlite3Database::newTag(const std::string &title)
{
    clearStatement();
    stmt_cache_ << "INSERT INTO tags(title) VALUES('" << title << "')";
    auto result = prepareStatement(stmt_cache_.str());
    if (isError(executeStep(result)))
        throw DatabaseException("inserting tag " + title + " failed");

    return getLastInsertId();
}
Beispiel #11
0
void Sqlite3Database::addTag(const bigint_t note_id, const bigint_t tag_id)
{

    clearStatement();
    stmt_cache_ << "INSERT INTO tags_nm VALUES(" << std::to_string(tag_id)
                << ", " << std::to_string(note_id) << ")";
    auto result = prepareStatement(stmt_cache_.str());
    if (isError(executeStep(result)))
        throw DatabaseException("adding tag " + std::to_string(tag_id) +
                                " to " + std::to_string(note_id) + " failed");
}
Beispiel #12
0
void Sqlite3Database::renameNotebook(const bigint_t notebook_id,
                                     const std::string &new_title)
{
    clearStatement();
    stmt_cache_ << "UPDATE notebooks SET title='" << new_title
                << "' WHERE id=" << notebook_id;
    auto result = prepareStatement(stmt_cache_.str());

    if (isError(executeStep(result)))
        throw DatabaseException("updating notebook title for notebook " +
                                new_title);
}
Beispiel #13
0
void Sqlite3Database::deleteNotebook(const bigint_t notebook_id)
{
    clearStatement();
    stmt_cache_ << "DELETE FROM notebooks WHERE id="
                << std::to_string(notebook_id);

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

    if (isError(executeStep(result)))
        throw DatabaseException("deleting notebook failed: " +
                                std::to_string(notebook_id));
}
TVerdict CCommDbTest005_01::doTestStepL( )
	{
	INFO_PRINTF1(_L("Step 005.01 called "));
	
	if ( executeStep() )
		{
		SetTestStepResult(EFail);		}
	else
		{
		SetTestStepResult(EPass);		}
		
	return TestStepResult();
	}
Beispiel #15
0
Notebook Sqlite3Database::loadNotebook(const bigint_t notebook_id)
{
    clearStatement();
    stmt_cache_ << "SELECT * FROM notebooks WHERE id="
                << std::to_string(notebook_id);

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

    if (isError(executeStep(result)))
        throw DatabaseException("loading notebook id " +
                                std::to_string(notebook_id) +
                                " failed, invalid result");

    Notebook nb(getInt(result, 0), getString(result, 1));

    return nb;
}
Beispiel #16
0
Note Sqlite3Database::loadNote(const bigint_t note_id)
{
    clearStatement();
    stmt_cache_ << "SELECT title,content,notebook,last_change,reminder"
                   " FROM notes WHERE (id=" << std::to_string(note_id) << ")";
    auto result = prepareStatement(stmt_cache_.str());

    if (isError(executeStep(result))) {
        throw DatabaseException("loading note id " + std::to_string(note_id) +
                                " failed, invalid result");
    }
    return Note(note_id, getString(result, 0), // title
                getString(result, 1),          // content
                getInt(result, 2),             // notebook
                getTimestamp(result, 3),       // last change
                getTimestamp(result, 4)        // reminder
                );
}
Beispiel #17
0
std::vector<Tag> db::Sqlite3Database::listTags()
{
    clearStatement();
    stmt_cache_ << "SELECT * FROM tags";
    auto result = prepareStatement(stmt_cache_.str());
    int state = SQLITE_OK;

    std::vector<Tag> result_vec;
    do {
        state = executeStep(result);
        if (isError(state))
            throw DatabaseException("listing tags failed, invalid result");
        if (state == SQLITE_DONE)
            break;

        result_vec.emplace_back(getInt(result, 0), getString(result, 1));
    } while (!isError(state) && state != SQLITE_DONE);
    return result_vec;
}
Beispiel #18
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 #19
0
void Sqlite3Database::removeTag(const bigint_t note_id, const bigint_t tag_id)
{

    clearStatement();
    if (note_id < 0) {
        stmt_cache_ << "DELETE FROM tags_nm WHERE (tag_id="
                    << std::to_string(tag_id) << ")";
    } else if (tag_id < 0) {
        stmt_cache_ << "DELETE FROM tags_nm WHERE (note_id="
                    << std::to_string(note_id) << ")";
    } else {
        stmt_cache_ << "DELETE FROM tags_nm WHERE (note_id="
                    << std::to_string(note_id)
                    << " and tag_id=" << std::to_string(tag_id) << ")";
    }
    auto result = prepareStatement(stmt_cache_.str());
    if (isError(executeStep(result)))
        throw DatabaseException("removing tag " + std::to_string(tag_id) +
                                " failed");
}
Beispiel #20
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());
}
Beispiel #21
0
std::vector<Note>
Sqlite3Database::loadNotesFromNotebook(const bigint_t notebook_id)
{
    clearStatement();
    stmt_cache_ << "SELECT * FROM notes where (notebook="
                << std::to_string(notebook_id) << ")";
    auto result = prepareStatement(stmt_cache_.str());
    int state = SQLITE_OK;

    std::vector<Note> result_vec;
    do {
        state = executeStep(result);
        if (isError(state))
            throw DatabaseException("listing notes failed, invalid result");
        if (state == SQLITE_DONE)
            break;

        result_vec.emplace_back(getInt(result, 0), getString(result, 1),
                                getString(result, 2), getInt(result, 3),
                                getTimestamp(result, 4),
                                getTimestamp(result, 5));
    } while (!isError(state) && state != SQLITE_DONE);
    return result_vec;
}
Beispiel #22
0
// The given `check' function must be called every iteration.
// It may call setPreempted() or perform other tasks.
bool BaseStrategy::execute(std::function<bool()> check)
{
    ros::Rate r(2);  // Hz
    while (node_.ok() && check() && !isPreempted() && !finished_)
    {
        callback_queue_.callAvailable();

        // TODO: check map age.
        // TODO: getNumPublishers here sometimes segfaults on
        //       succeeded/preempted, for no apparent reason.
        if (slam_map_subscriber_.getNumPublishers() == 0)
        {
            // SLAM is not running.
            ROS_INFO("Waiting for SLAM to start publishing a map...");
        }
        else if (map_ && pose_initialized_)
        {
            if (obstacle_map_publisher_.getNumSubscribers() > 0)
            {
                obstacle_map_publisher_.publish(createOccupancyGrid(*map_));
            }

            if (!map_ready_)
            {
                const int Rfree = std::ceil(initial_free_radius_ / map_->resolution);
                freeRobotPose(*map_, map_->getIdxForPosition(pose_.position), Rfree);

                // TODO: This is too conservative. "!= -1" should be used instead, but
                //       for now it's like this to handle the point of a map where the
                //       only frontier is the robot position.
                if (map_updated_ && map_->isBoxKnown(pose_.position, safety_radius_) == 1)
                {
                    map_ready_ = true;
                }
                else
                {
                    ROS_INFO_COND(map_updated_, "Position is outside map. Initialization manoeuvres...");
                    executeInitStep(map_updated_);
                }
            }

            if (map_ready_)
            {
                if (map_updated_)
                {
                    executeStep();
                }
                else
                {
                    executeControlStep();
                }
            }

            map_updated_ = false;
        }
        else
        {
            if (map_updated_)
            {
                ROS_INFO("Received map is empty. Initialization manoeuvres...");
            }
            executeInitStep(map_updated_);
        }

        r.sleep();
    }

    return finished_;
}
void executePlan(Plan *plan){
	for (int i = 0; i < plan->numSteps; i++)
     {
       executeStep(plan->steps[i]);
     }
}