Пример #1
0
void MyTblPlnrMStructure::updateRec(
			PlnrMStructure* rec
		) {
	unsigned long l[8]; my_bool n[8]; my_bool e[8];

	l[2] = rec->sref.length();

	MYSQL_BIND bind[] = {
		bindUint(&rec->hkIxVTbl,&(l[0]),&(n[0]),&(e[0])), 
		bindUbigint(&rec->hkUref,&(l[1]),&(n[1]),&(e[1])), 
		bindCstring((char*) (rec->sref.c_str()),&(l[2]),&(n[2]),&(e[2])), 
		bindDouble(&rec->x0,&(l[3]),&(n[3]),&(e[3])), 
		bindDouble(&rec->x1,&(l[4]),&(n[4]),&(e[4])), 
		bindDouble(&rec->y0,&(l[5]),&(n[5]),&(e[5])), 
		bindDouble(&rec->y1,&(l[6]),&(n[6]),&(e[6])), 
		bindUbigint(&rec->ref,&(l[7]),&(n[7]),&(e[7]))
	};

	if (mysql_stmt_bind_param(stmtUpdateRec, bind)) throw DbsException("DbsException / MySQL: error binding to statement! (TblPlnrMStructure / stmtUpdateRec)\n");
	if (mysql_stmt_execute(stmtUpdateRec)) throw DbsException("DbsException / MySQL: error executing statement! (TblPlnrMStructure / stmtUpdateRec)\n");
};
Пример #2
0
void TrackDAOSqlite3Impl::insertOrUpdateTrack( Track* track ) {
	sqlite3_stmt *pStmt = NULL;
	bool rowExists = false;

	checkDb();

	pStmt = prepare( "SELECT `Checksum` FROM `Tracks` WHERE `Filename` = :name;" );
	bindText( pStmt, ":name", track->filename.c_str() );
	if( step( pStmt ) == SQLITE_ROW ) {
		rowExists = true;
		//TODO: Consider checking this file's checksum
		//checksum.assign( sqlite3_column_text( pStmt, 0 ) );
	}
	finalize( pStmt );

	if( rowExists) {
		pStmt = prepare(
				"UPDATE `Tracks` SET "
				"`Checksum` = :checksum,"
				"`Name` = :name,"
				"`Art_Filename` = :art_filename,"
				"`ArtistId` = :artist_id,"
				"`AlbumArtistId` = :album_artist_id,"
				"`AlbumId` = :album_id,"
				"`TrackNumber` = :track_number,"
				"`DiscNumber` = :disc_number,"
				"`ReplayGain` = :replay_gain "
				"WHERE `Filename` = :filename;" );
	} else {
		pStmt = prepare(
				"INSERT INTO `Tracks`"
				"(`Filename`, `Checksum`, `Name`, `Art_Filename`, `ArtistId`, `AlbumArtistId`, `AlbumId`, `TrackNumber`,`DiscNumber`, `ReplayGain`)"
				"values(:filename, :checksum, :name, :art_filename, :artist_id, :album_artist_id, :album_id, :track_number, :disc_number, :replay_gain);" );
	}
	bindText( pStmt, ":filename", track->filename.c_str() );
	bindText( pStmt, ":checksum", "nop" );
	bindText( pStmt, ":name", track->name.c_str() );
	bindText( pStmt, ":art_filename", track->artFilename.c_str() );
	if( track->artist != NULL )
		bindLong( pStmt, ":artist_id", track->artist->id );
	if( track->album != NULL ) {
		bindLong( pStmt, ":album_id", track->album->id );
		if( track->album->artist != NULL ) {
			bindLong( pStmt, ":album_artist_id", track->album->artist->id );
		}
	}
	bindLong( pStmt, ":track_number", track->trackNumber );
	bindLong( pStmt, ":disc_number", track->discNumber );
	bindDouble( pStmt, ":replay_gain", track->replayGain );
	step( pStmt );
	finalize( pStmt );
}
Пример #3
0
int SQLiteStatement::bindValue(int index, const SQLValue& value) {
  switch (value.getType()) {
    case SQLValue::StringValue:
      return bindText(index, value.string());
    case SQLValue::NumberValue:
      return bindDouble(index, value.number());
    case SQLValue::NullValue:
      return bindNull(index);
  }

  ASSERT_NOT_REACHED();
  return SQLITE_ERROR;
}
Пример #4
0
unique_ptr<SqlStatement> CommonClause::createStatementAndBindValuesToPlaceholders(SqliteDatabase* db, const string& sql) const
{
    auto stmt = db->prepStatement(sql);
    if (stmt == nullptr) return nullptr;

    // bind the actual column values to the placeholders
    int curPlaceholderIdx = 1;   // leftmost placeholder is at position 1
    for (int i=0; i < colVals.size(); ++i)
    {
        const ColValInfo& curCol = colVals[i];

        // NULL or NOT NULL has to handled directly as literal value when
        // creating the sql statement's text
        if ((curCol.type == ColValType::Null) || (curCol.type == ColValType::NotNull)) continue;

        switch (curCol.type)
        {
        case ColValType::Int:
            stmt->bindInt(curPlaceholderIdx, intVals[curCol.indexInList]);
            break;

        case ColValType::Double:
            stmt->bindDouble(curPlaceholderIdx, doubleVals[curCol.indexInList]);
            break;

        case ColValType::String:
            stmt->bindString(curPlaceholderIdx, stringVals[curCol.indexInList]);
            break;

        default:
            throw std::runtime_error("unhandled argument type when binding argument values to statement");
        }

        ++curPlaceholderIdx;
    }

    return stmt;
}