Ejemplo n.º 1
0
void initCountryForUpdates(LCountry* country) {
    initCountryForUpdatesCommon(country);
    
    sqlite3* db = country->db;
    sqlite3_stmt* preloadNodesStatement;
    sqlite3_stmt* preloadWaysStatement;
    
    country->ifNodeExists = checkNodeInTree16;
    country->ifWayExists = checkWayInTree16;
    country->ifRelationExists = checkRelationInTree16;
    
    prepareStatement(db, "SELECT id FROM current_nodes", &preloadNodesStatement);
    prepareStatement(db, "SELECT id FROM current_ways", &preloadWaysStatement);
    printf("Preloading nodes ids...\n");
    while(sqlite3_step(preloadNodesStatement) == SQLITE_ROW) {
        OsmId id = sqlite3_column_int(preloadNodesStatement, 0);
        addTree16Node(&(country->nodesIndex), id, id);
    }
    printf("Preloading ways ids...\n");
    while(sqlite3_step(preloadWaysStatement) == SQLITE_ROW) {
        OsmId id = sqlite3_column_int(preloadWaysStatement, 0);
        addTree16Node(&(country->waysIndex), id, id);
    }
    
    
    sqlite3_finalize(preloadNodesStatement);
    sqlite3_finalize(preloadWaysStatement);
    
}
Ejemplo n.º 2
0
static void fillGlueTables(sqlite3 *db)
{
  int i;
  sqlite3_stmt *statement;
  int res;
                
  statement = prepareStatement(db,
                               "INSERT OR IGNORE INTO event_kind (name, description, enum)"
                               "VALUES (?, ?, ?)");
        
  i = 0;
  EventKindENUM(EVENT_KIND_DO_INSERT, X);
        
  finalizeStatement(db, statement);
        
  statement = prepareStatement(db, 
                               "INSERT OR IGNORE INTO event_type (name, code, always, kind)"
                               "VALUES (?, ?, ?, ?)");
  EVENT_LIST(EVENT_TYPE_DO_INSERT, X);
        
  finalizeStatement(db, statement);

  statement = prepareStatement(db,
                               "INSERT OR IGNORE INTO event_param (type, param_index, sort, ident)"
                               "VALUES (?, ?, ?, ?)");
  EVENT_LIST(EVENT_TYPE_INSERT_PARAMS, X);
        
  finalizeStatement(db, statement);
}
Ejemplo n.º 3
0
void initCountryForUpdatesNoCache(LCountry* country) {
    initCountryForUpdatesCommon(country);

    sqlite3* db = country->db;
    prepareStatement(db, "SELECT id FROM current_nodes WHERE id = ?1 LIMIT 1", &(country->nodeExistsStatement));
    prepareStatement(db, "SELECT id FROM current_ways WHERE id = ?1 LIMIT 1", &(country->wayExistsStatement));
    prepareStatement(db, "SELECT id FROM current_relations WHERE id = ?1 LIMIT 1", &(country->relationExistsStatement));
    
    country->ifNodeExists = checkNodeInDb;
    country->ifWayExists = checkWayInDb;
    country->ifRelationExists = checkRelationInDb;
}
Ejemplo n.º 4
0
void initOsd2Olm(osd2olm* self, const char* file, CountryPolygon* polygon, char fullMemory) {
    initOsm2OlmInternal((osm2olm*)self, ".", polygon, 1, fullMemory ? initCountryForUpdates : initCountryForUpdatesNoCache);
    
    if (fullMemory) {
        sqlite3* db = self->base.countries->db;
        sqlite3_stmt* preloadRelationsStatement;
        sqlite3_stmt* relationsCountStatement;
        prepareStatement(db, "SELECT id FROM current_relations", &preloadRelationsStatement);
        prepareStatement(db, "SELECT count(*) FROM current_relations", &relationsCountStatement);
        
        printf("Preloading relations ids...\n");
        
        if (sqlite3_step(relationsCountStatement) == SQLITE_ROW) {
            self->base.relations.count = self->base.relations.capacity = sqlite3_column_int(relationsCountStatement, 0);
            self->base.relations.values = malloc(sizeof(RelationChange) * self->base.relations.count);
            int i = 0;
            while (sqlite3_step(preloadRelationsStatement) == SQLITE_ROW) {
                RelationChange* relation = self->base.relations.values + i;
                relation->base.info.id = sqlite3_column_int(preloadRelationsStatement, 0);
                relation->change = OSM_CHANGE_NONE;
                relation->base.relationMembers.count = relation->base.relationMembers.capacity = 0;
                relation->base.tags.count = relation->base.tags.capacity = 0;
                relation->base.relationMembers.values = NULL;
                relation->base.tags.values = NULL;
                i++;
            }
            printf("%i relations on DB.\n", i);
            
        } else {
            self->base.relations.count = self->base.relations.capacity = 0;
        }
        
        sqlite3_finalize(preloadRelationsStatement);
        sqlite3_finalize(relationsCountStatement);
    }
    
    self->base.reader.finishWay[OSM_CHANGE_NONE] = NULL;
    self->base.reader.finishNode[OSM_CHANGE_NONE] = NULL;
    self->base.reader.finishRelation[OSM_CHANGE_NONE] = NULL;
    
    self->base.reader.finishNode[OSM_CHANGE_CREATE] = writeNode;
    self->base.reader.finishWay[OSM_CHANGE_CREATE] = writeWay;
    self->base.reader.finishRelation[OSM_CHANGE_CREATE] = writeRelation;
    
    self->base.reader.finishNode[OSM_CHANGE_MODIFY] = updateNode;
    self->base.reader.finishWay[OSM_CHANGE_MODIFY] = updateWay;
    self->base.reader.finishRelation[OSM_CHANGE_MODIFY] = updateRelation;
    
    self->base.reader.finishNode[OSM_CHANGE_DELETE] = deleteNode;
    self->base.reader.finishWay[OSM_CHANGE_DELETE] = deleteWay;
    self->base.reader.finishRelation[OSM_CHANGE_DELETE] = deleteRelation;
}
Ejemplo n.º 5
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");
}
Ejemplo n.º 6
0
bool SociContainer::begin(void)
{
	mRecordCount = 0;
	Progress prg("Open database", "Connecting ...");
	prg->setMaximum(prg->maximum()+2);

	if(!getSession())
	{
		prg->setValue(prg->value()+2);
		ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, "Unable to open database.");
		return false;
	}
	prg->setValue(prg->value()+1);
	if(isReader())
	{
		if(!prepareStatement(selectorToQuery()))
			return false;
	}
	prg->setValue(prg->value()+1);


	if(mSQLToFile)
	{
		mSQLFile.open(mSQLFilename, std::ios::out | std::ios::trunc);
		if(!mSQLFile.is_open())
		{
			ErrorMessage(spt::logging::LoggingItem::LOG_ERROR, MODULENAME, StdString("Unable to open the file: ")+mSQLFilename);
			return false;
		}
	}

	return true;
}
QgsSqlAnywhereFeatureIterator::QgsSqlAnywhereFeatureIterator( QgsSqlAnywhereProvider* p, const QgsFeatureRequest & request )
    : QgsAbstractFeatureIterator( request ), P( p )
    , mStmt( NULL ), mStmtRect()
{

  mClosed = false;
  QString whereClause = P->getWhereClause();

  if ( request.filterType() == QgsFeatureRequest::FilterRect && !P->mGeometryColumn.isNull() )
  {
    mStmtRect = mRequest.filterRect();
    SaDebugMsg( "initial rectangle =" + mStmtRect.toString() );
    mStmtRect = mStmtRect.intersect( &P->mSrsExtent );
    SaDebugMsg( "rectangle clipped to SRS extent =" + mStmtRect.toString() );

    whereClause += " AND " + whereClauseRect();
  }
  else if ( request.filterType() == QgsFeatureRequest::FilterFid )
  {
    whereClause += " AND " + whereClauseFid();
  }

  if ( !prepareStatement( whereClause ) )
  {
    mStmt = NULL;
    mClosed = true;
    return;
  }
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
static int tableExists(sqlite3* db, const char *tableName)
{
  int res;
  int exists = 0;
  sqlite3_stmt *statement = NULL;

  statement = prepareStatement(db,
                               "SELECT 1 FROM sqlite_master WHERE type='table' AND name=?");
  res = sqlite3_bind_text(statement, 1, tableName, -1, SQLITE_STATIC);
  if (res != SQLITE_OK)
    sqlite_error(res, db, "table existence bind of name failed.");
  res = sqlite3_step(statement);
  switch(res) {
  case SQLITE_DONE:
    exists = 0;
    break;
  case SQLITE_ROW:
    exists = 1;
    break;
  default:
    sqlite_error(res, db, "select from sqlite_master failed.");
  }
  finalizeStatement(db, statement);
  return exists;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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");
}
Ejemplo n.º 12
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();
}
Ejemplo n.º 13
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");
}
Ejemplo n.º 14
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);
}
Ejemplo n.º 15
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));
}
Ejemplo n.º 16
0
void MapDatabasePostgreSQL::initStatements()
{
	prepareStatement("read_block",
		"SELECT data FROM blocks "
			"WHERE posX = $1::int4 AND posY = $2::int4 AND "
			"posZ = $3::int4");

	if (getPGVersion() < 90500) {
		prepareStatement("write_block_insert",
			"INSERT INTO blocks (posX, posY, posZ, data) SELECT "
				"$1::int4, $2::int4, $3::int4, $4::bytea "
				"WHERE NOT EXISTS (SELECT true FROM blocks "
				"WHERE posX = $1::int4 AND posY = $2::int4 AND "
				"posZ = $3::int4)");

		prepareStatement("write_block_update",
			"UPDATE blocks SET data = $4::bytea "
				"WHERE posX = $1::int4 AND posY = $2::int4 AND "
				"posZ = $3::int4");
	} else {
		prepareStatement("write_block",
			"INSERT INTO blocks (posX, posY, posZ, data) VALUES "
				"($1::int4, $2::int4, $3::int4, $4::bytea) "
				"ON CONFLICT ON CONSTRAINT blocks_pkey DO "
				"UPDATE SET data = $4::bytea");
	}

	prepareStatement("delete_block", "DELETE FROM blocks WHERE "
		"posX = $1::int4 AND posY = $2::int4 AND posZ = $3::int4");

	prepareStatement("list_all_loadable_blocks",
		"SELECT posX, posY, posZ FROM blocks");
}
Ejemplo n.º 17
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;
}
Ejemplo n.º 18
0
QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
    : QgsAbstractFeatureIteratorFromSource<QgsSpatiaLiteFeatureSource>( source, ownSource, request )
    , sqliteStatement( NULL )
{

  mHandle = QgsSpatiaLiteConnPool::instance()->acquireConnection( mSource->mSqlitePath );

  mFetchGeometry = !mSource->mGeometryColumn.isNull() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry );
  mHasPrimaryKey = !mSource->mPrimaryKey.isEmpty();
  mRowNumber = 0;

  QString whereClause;
  if ( request.filterType() == QgsFeatureRequest::FilterRect && !mSource->mGeometryColumn.isNull() )
  {
    // some kind of MBR spatial filtering is required
    whereClause += whereClauseRect();
  }

  if ( request.filterType() == QgsFeatureRequest::FilterFid )
  {
    whereClause += whereClauseFid();
  }

  if ( request.filterType() == QgsFeatureRequest::FilterFids )
  {
    whereClause += whereClauseFids();
  }

  if ( !mSource->mSubsetString.isEmpty() )
  {
    if ( !whereClause.isEmpty() )
    {
      whereClause += " AND ";
    }
    whereClause += "( " + mSource->mSubsetString + ")";
  }

  // preparing the SQL statement
  if ( !prepareStatement( whereClause ) )
  {
    // some error occurred
    sqliteStatement = NULL;
    close();
    return;
  }
}
Ejemplo n.º 19
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;
}
Ejemplo n.º 20
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
                );
}
Ejemplo n.º 21
0
bool SqlConnection::existsUser(const std::string &name)
{
    sqlite3_stmt * stat;
    prepareStatement(&stat, PREPARE_SELECT_USER_STATEMENT);

    sqlite3_bind_text(stat, 1, name.c_str(), name.length() +1, NULL);
    QMutexLocker l(&mutex);
    qDebug("The locked searching");

    if(sqlite3_step(stat) != SQLITE_ROW)
    {
        sqlite3_finalize(stat);
        return false;
    }
    //sqlite3_finalize(getByName);
    sqlite3_finalize(stat);
    return true;
}
Ejemplo n.º 22
0
void initInsertStatements(LCountry* country) {
    sqlite3* db = country->db;
    prepareStatement(db, "INSERT INTO current_nodes(id, latitude, longitude, visible, timestamp, tile) VALUES (?1, ?2, ?3, 1, ?4, -1)", 
                     &(country->insertNodeStatement));
    
    prepareStatement(db, "INSERT INTO current_node_tags(id, k, v) VALUES (?1, ?2, ?3)", 
                     &(country->insertNodeTagStatement));
    
    prepareStatement(db, "INSERT INTO current_ways(id, visible, timestamp, user_id) VALUES (?1, 1, ?2, -1)", &(country->insertWayStatement));
    prepareStatement(db, "INSERT INTO current_way_tags(id, k, v) VALUES (?1, ?2, ?3)", &(country->insertWayTagStatement));
    prepareStatement(db, "INSERT INTO current_way_nodes(id, node_id, sequence_id) VALUES (?1, ?2, ?3)", &(country->insertWayNodeStatement));
    
    prepareStatement(db, "INSERT INTO current_relations(id, visible, timestamp, user_id) VALUES (?1, 1, ?2, -1)", &(country->insertRelationStatement));
    prepareStatement(db, "INSERT INTO current_relation_tags(id, k, v) VALUES (?1, ?2, ?3)", &(country->insertRelationTagStatement));
    prepareStatement(db, "INSERT INTO current_relation_members(id, member_type, member_id, member_role, sequence_id) VALUES (?1, ?2, ?3, ?4, ?5)", &(country->insertRelationMemberStatement));

    country->nodeExistsStatement = NULL;
    country->wayExistsStatement = NULL;
    country->relationExistsStatement = NULL;
}
Ejemplo n.º 23
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");
}
Ejemplo n.º 24
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;
}
Ejemplo n.º 25
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");
}
Ejemplo n.º 26
0
static void logFileCompleted(sqlite3 *db,
                             int64 completed)
{
  sqlite3_stmt *statement;
  int res;

  statement = prepareStatement(db,
                               "UPDATE event_log SET completed=? WHERE serial=?");
  res = sqlite3_bind_int64(statement, 2, logSerial);
  if (res != SQLITE_OK)
    sqlite_error(res, db, "event_log update bind of serial failed.");
  res = sqlite3_bind_int64(statement, 1, completed);
  if (res != SQLITE_OK)
    sqlite_error(res, db, "event_log update bind of completed failed.");
  res = sqlite3_step(statement); 
  if (res != SQLITE_DONE)
    sqlite_error(res, db, "insert into event_log failed.");
  evlog(LOG_SOMETIMES, "Marked in event_log: %lu events", completed);
  finalizeStatement(db, statement);
}
Ejemplo n.º 27
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());
}
Ejemplo n.º 28
0
bool SqlConnection::insertUser(const std::string &name, const std::string &password, const std::string &salt)
{

    sqlite3_stmt * stat;
    prepareStatement(&stat, PREPARE_INSERT_STATEMENT);

    sqlite3_bind_text(stat, 1, name.c_str(), name.length()+1, NULL);
    sqlite3_bind_text(stat, 2, password.c_str(), password.length()+1, NULL);
    sqlite3_bind_text(stat, 3, salt.c_str(), salt.length()+1, NULL);

    QMutexLocker  lock(&mutex);

    if(sqlite3_step(stat) != SQLITE_DONE)
    {
        sqlite3_finalize(stat);
        throw SqlException("The statement was not executed");
    }
    sqlite3_finalize(stat);

    //sqlite3_reset(include);
    return true;
}
Ejemplo n.º 29
0
SqlConnection::ContainedData SqlConnection::getUserByName(const std::string &username)
{

    sqlite3_stmt * stat;
    prepareStatement(&stat, PREPARE_SELECT_USER_STATEMENT);

    sqlite3_bind_text(stat, 1, username.c_str(), username.length() +1, NULL);
    QMutexLocker l(&mutex);


    if(sqlite3_step(stat) !=SQLITE_ROW)
    {
        sqlite3_finalize(stat);
        throw SqlException("The user is not in the db");
    }
    ContainedData t;
    t.id = sqlite3_column_int(stat, 0);

    char * t1, *t2, *t3;
    t1 = (char*)sqlite3_column_text(stat,1);
    t2 = (char*)sqlite3_column_text(stat,2);
    t3 = (char*)sqlite3_column_text(stat,3);


    QString name(t1), pass(t2), salt(t3);

    t.name = name;
    t.password = pass;
    t.salt = salt;
    //free(t1);
    //free(t2);
    //free(t3);
    sqlite3_finalize(stat);


    return t;

}
QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator( QgsSpatiaLiteProvider* p, const QgsFeatureRequest& request )
    : QgsAbstractFeatureIterator( request )
    , P( p )
    , sqliteStatement( NULL )
{
  P->mActiveIterators << this;

  mFetchGeometry = !P->mGeometryColumn.isNull() && !( mRequest.flags() & QgsFeatureRequest::NoGeometry );

  QString whereClause;
  if ( request.filterType() == QgsFeatureRequest::FilterRect && !P->mGeometryColumn.isNull() )
  {
    // some kind of MBR spatial filtering is required
    whereClause += whereClauseRect();
  }

  if ( request.filterType() == QgsFeatureRequest::FilterFid )
  {
    whereClause += whereClauseFid();
  }

  if ( !P->mSubsetString.isEmpty() )
  {
    if ( !whereClause.isEmpty() )
    {
      whereClause += " AND ";
    }
    whereClause += "( " + P->mSubsetString + ")";
  }

  // preparing the SQL statement
  if ( !prepareStatement( whereClause ) )
  {
    // some error occurred
    sqliteStatement = NULL;
    return;
  }
}