Commit 456b99c4 authored by Srikanth Raju's avatar Srikanth Raju

ML: Fix BuildUpdate() and add some error messages

parent a607963a
...@@ -236,6 +236,7 @@ int BuildUpdate( media_library_t *p_ml, ...@@ -236,6 +236,7 @@ int BuildUpdate( media_library_t *p_ml,
i_ret = BuildWhere( p_ml, &psz_where, where ); i_ret = BuildWhere( p_ml, &psz_where, where );
if( i_ret != VLC_SUCCESS ) if( i_ret != VLC_SUCCESS )
goto quit_buildupdate; goto quit_buildupdate;
i_ret = VLC_ENOMEM;
/** Firstly, choose the right table */ /** Firstly, choose the right table */
switch( selected_type ) switch( selected_type )
...@@ -277,9 +278,13 @@ int BuildUpdate( media_library_t *p_ml, ...@@ -277,9 +278,13 @@ int BuildUpdate( media_library_t *p_ml,
"title = %Q", "title = %Q",
find->value.str ); find->value.str );
if( !psz_set[i_type] ) if( !psz_set[i_type] )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
} }
}
else if( selected_type == ML_MEDIA ) else if( selected_type == ML_MEDIA )
{ {
if( !psz_album ) if( !psz_album )
...@@ -301,10 +306,14 @@ int BuildUpdate( media_library_t *p_ml, ...@@ -301,10 +306,14 @@ int BuildUpdate( media_library_t *p_ml,
"album_id = '%d'", "album_id = '%d'",
find->value.i ); find->value.i );
if( !psz_set[i_type] ) if( !psz_set[i_type] )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
} }
} }
}
break; break;
case ML_PEOPLE: case ML_PEOPLE:
if( selected_type == ML_MEDIA ) if( selected_type == ML_MEDIA )
...@@ -433,19 +442,32 @@ int BuildUpdate( media_library_t *p_ml, ...@@ -433,19 +442,32 @@ int BuildUpdate( media_library_t *p_ml,
exitfor: exitfor:
/* TODO: Album artist. Verify albumart */ /* TODO: Album artist. Verify albumart */
if( i_album_id <= 0 && psz_album && *psz_album ) if( i_album_id <= 0 || ( psz_album && *psz_album ) )
{
i_album_id = ml_GetAlbumId( p_ml, psz_album );
if( i_album_id < 0 ) //0 is Unknown
{ {
i_ret = AddAlbum( p_ml, psz_album, psz_cover, 0 ); i_ret = AddAlbum( p_ml, psz_album, psz_cover, 0 );
if( i_ret != VLC_SUCCESS ) if( i_ret != VLC_SUCCESS )
{
msg_Err( p_ml, "Couldn't AddAlbum at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
}
i_album_id = ml_GetAlbumId( p_ml, psz_album ); i_album_id = ml_GetAlbumId( p_ml, psz_album );
if( i_album_id <= 0 ) if( i_album_id < 0 )
goto quit_buildupdate; goto quit_buildupdate;
}
psz_set[ML_ALBUM_ID] = sql_Printf( p_ml->p_sys->p_sql, psz_set[ML_ALBUM_ID] = sql_Printf( p_ml->p_sys->p_sql,
"album_id = '%d'", i_album_id ); "album_id = '%d'", i_album_id );
if( !psz_set[i_type] ) if( !psz_set[ML_ALBUM_ID] )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
}
for( unsigned i = 0; i <= ML_DIRECTORY; i++ ) for( unsigned i = 0; i <= ML_DIRECTORY; i++ )
{ {
...@@ -456,7 +478,11 @@ exitfor: ...@@ -456,7 +478,11 @@ exitfor:
free( psz_tmp ); free( psz_tmp );
if( asprintf( &psz_tmp, "%s%s%s", psz_extra ? psz_extra : "", if( asprintf( &psz_tmp, "%s%s%s", psz_extra ? psz_extra : "",
psz_extra ? ", ": "", psz_set[i] ) == -1 ) psz_extra ? ", ": "", psz_set[i] ) == -1 )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
}
free( psz_extra ); free( psz_extra );
psz_extra = strdup( psz_tmp ); psz_extra = strdup( psz_tmp );
} }
...@@ -465,7 +491,11 @@ exitfor: ...@@ -465,7 +491,11 @@ exitfor:
free( psz_tmp ); free( psz_tmp );
if( asprintf( &psz_tmp, "%s%s%s", psz_fullset ? psz_fullset : "", if( asprintf( &psz_tmp, "%s%s%s", psz_fullset ? psz_fullset : "",
psz_fullset ? ", ": "", psz_set[i] ) == -1 ) psz_fullset ? ", ": "", psz_set[i] ) == -1 )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
}
free( psz_fullset ); free( psz_fullset );
psz_fullset = strdup( psz_tmp ); psz_fullset = strdup( psz_tmp );
} }
...@@ -477,10 +507,12 @@ exitfor: ...@@ -477,10 +507,12 @@ exitfor:
assert( psz_where && *psz_where ); assert( psz_where && *psz_where );
/** Finally build the full query */ /** Finally build the full query */
/** Pass if we have some people to add - Indirect update*/ /** Pass if we have some people to add - Indirect update */
if( !psz_fullset && i_people_add == 0 ) if( !psz_fullset && i_people_add == 0 )
{ {
i_ret = VLC_EGENERIC; i_ret = VLC_EGENERIC;
msg_Err( p_ml, "Nothing found to create update at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
...@@ -488,6 +520,8 @@ exitfor: ...@@ -488,6 +520,8 @@ exitfor:
if( asprintf( ppsz_query, "UPDATE %s SET %s WHERE %s", psz_table, if( asprintf( ppsz_query, "UPDATE %s SET %s WHERE %s", psz_table,
psz_fullset, psz_where ) == -1 ) psz_fullset, psz_where ) == -1 )
{ {
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
} }
...@@ -498,7 +532,11 @@ exitfor: ...@@ -498,7 +532,11 @@ exitfor:
{ {
if( asprintf( &psz_tmp, "%s; UPDATE extra SET %s WHERE %s", if( asprintf( &psz_tmp, "%s; UPDATE extra SET %s WHERE %s",
*ppsz_query, psz_extra, psz_where ) == -1 ) *ppsz_query, psz_extra, psz_where ) == -1 )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
}
free( *ppsz_query ); free( *ppsz_query );
*ppsz_query = psz_tmp; *ppsz_query = psz_tmp;
psz_tmp = NULL; psz_tmp = NULL;
...@@ -513,6 +551,8 @@ exitfor: ...@@ -513,6 +551,8 @@ exitfor:
{ {
free( psz_tmp ); free( psz_tmp );
free( psz_idstring ); free( psz_idstring );
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
free( psz_idstring ); free( psz_idstring );
...@@ -533,6 +573,8 @@ exitfor: ...@@ -533,6 +573,8 @@ exitfor:
psz_idstring, psz_idstring ) == -1 ) psz_idstring, psz_idstring ) == -1 )
{ {
free( psz_idstring ); free( psz_idstring );
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
free( *ppsz_query ); free( *ppsz_query );
...@@ -550,7 +592,11 @@ exitfor: ...@@ -550,7 +592,11 @@ exitfor:
"(media_id,people_id) SELECT media.id, %d FROM media WHERE %s", "(media_id,people_id) SELECT media.id, %d FROM media WHERE %s",
*ppsz_query == NULL ? "" : *ppsz_query, pi_padd_ids[i], *ppsz_query == NULL ? "" : *ppsz_query, pi_padd_ids[i],
psz_where ) == -1 ) psz_where ) == -1 )
{
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
}
FREENULL( *ppsz_query ); FREENULL( *ppsz_query );
*ppsz_query = psz_tmp; *ppsz_query = psz_tmp;
psz_tmp = NULL; psz_tmp = NULL;
...@@ -561,13 +607,18 @@ exitfor: ...@@ -561,13 +607,18 @@ exitfor:
if( asprintf( ppsz_id_query, "SELECT id AS %s_id FROM %s WHERE %s", if( asprintf( ppsz_id_query, "SELECT id AS %s_id FROM %s WHERE %s",
psz_table, psz_table, psz_where ) == -1 ) psz_table, psz_table, psz_where ) == -1 )
{ {
msg_Err( p_ml, "Couldn't create string at BuildUpdate():(%s, %d)",
__FILE__, __LINE__ );
goto quit_buildupdate; goto quit_buildupdate;
} }
#ifndef NDEBUG #ifndef NDEBUG
msg_Dbg( p_ml, "updated media where %s", psz_where ); msg_Dbg( p_ml, "updated media where %s", psz_where );
#endif #endif
goto quit_buildupdate_success;
quit_buildupdate: quit_buildupdate:
msg_Warn( p_ml, "BuildUpdate() could not generate update sql query" );
quit_buildupdate_success:
free( psz_tmp ); free( psz_tmp );
free( psz_table ); free( psz_table );
free( psz_fullset ); free( psz_fullset );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment