Beispiel #1
0
// 更新操作
bool COracleDB::Update( const char *stable, const CSqlObj *obj, const CSqlWhere *where )
{
	string supdate;
	// 构建更新操作
	if ( ! BuildUpdate( ( OracleSqlObj* ) obj, supdate ) ) {
		return false;
	}

	string sql = "update ";
	sql += stable;
	sql += " set ";
	sql += supdate;

	string swhere;
	// 构建的条件
	if ( BuildWhere( where, swhere ) ) {
		sql += " where ";
		sql += swhere;
	}

	// 执行更新操作
	int ret = oracle_exec( sql.c_str(), true )  ;
	if ( ret != DB_ERR_SUCCESS ) {
		OUT_ERROR( NULL, 0, "Oracle", "Exceute sql: %s, result %d", sql.c_str() , ret );
		return false;
	}

	return true;
}
Beispiel #2
0
/**
 * @brief Generic update in Media Library database
 *
 * @param p_ml the media library object
 * @param selected_type the type of the element we're selecting
 * @param where the list of ids or uri to change
 * @param changes list of changes to make in the entries
 * @return VLC_SUCCESS or VLC_EGENERIC
 * @note This function is transactional
 */
int Update( media_library_t *p_ml, ml_select_e selected_type,
        const char* psz_lvalue, ml_ftree_t *where, vlc_array_t *changes )
{
    int i_ret = VLC_EGENERIC;
    char *psz_query = NULL;
    char *psz_id_query = NULL;
    char **pp_results = NULL;
    int i_rows = 0, i_cols = 0;

    i_ret = BuildUpdate( p_ml, &psz_query, &psz_id_query,
                         psz_lvalue, selected_type, where, changes );

    if( i_ret != VLC_SUCCESS )
    {
        msg_Err(p_ml,"Failed to generate update query" );
        return i_ret;
    }
    i_ret = VLC_EGENERIC;

    Begin( p_ml );
    if( QuerySimple( p_ml, "%s", psz_query ) != VLC_SUCCESS )
    {
        msg_Err( p_ml, "Couldn't run the generated update query successfully" );
        goto quitdelete;
    }

    /* Get the updated IDs to send events! */
    if( Query( p_ml, &pp_results, &i_rows, &i_cols, psz_id_query )
            != VLC_SUCCESS )
        goto quitdelete;

    i_ret = VLC_SUCCESS;
quitdelete:
    if( i_ret != VLC_SUCCESS )
        Rollback( p_ml );
    else
    {
        Commit( p_ml );
        if( i_rows > 0 )
        {
            for( int i = 0; i < i_rows; i++ )
            {
                var_SetInteger( p_ml, "media-meta-change",
                        atoi( pp_results[i*i_cols] ) );
            }
        }
    }
    FreeSQLResult( p_ml, pp_results );
    free( psz_id_query );
    free( psz_query );
    return i_ret;
}