特定条件でアプリデータのインポートに失敗するバグを修正

This commit is contained in:
tateisu 2017-05-23 03:50:49 +09:00
parent ffefc95d72
commit df76426796
2 changed files with 32 additions and 15 deletions

View File

@ -3275,7 +3275,7 @@ public class ActMain extends AppCompatActivity
if( pager_adapter != null ){ if( pager_adapter != null ){
pager.setAdapter( pager_adapter ); pager.setAdapter( pager_adapter );
}else{ }else{
tablet_pager_adapter.notifyDataSetChanged(); resizeColumnWidth();
} }
} }
@ -3377,8 +3377,9 @@ public class ActMain extends AppCompatActivity
if( pager_adapter != null ){ if( pager_adapter != null ){
pager.setAdapter( pager_adapter ); pager.setAdapter( pager_adapter );
}else{ }else{
tablet_pager_adapter.notifyDataSetChanged(); resizeColumnWidth();
} }
updateColumnStrip();
} }
// 通知サービスをリスタート // 通知サービスをリスタート
@ -3387,8 +3388,6 @@ public class ActMain extends AppCompatActivity
intent.setAction( AlarmService.ACTION_APP_DATA_IMPORT_AFTER ); intent.setAction( AlarmService.ACTION_APP_DATA_IMPORT_AFTER );
startService( intent ); startService( intent );
} }
updateColumnStrip();
} }
}; };

View File

@ -156,7 +156,6 @@ public class AppDataExporter {
SavedAccount.onDBCreate( db ); SavedAccount.onDBCreate( db );
} }
boolean bOK = false;
db.execSQL( "BEGIN TRANSACTION" ); db.execSQL( "BEGIN TRANSACTION" );
try{ try{
db.execSQL( "delete from " + table ); db.execSQL( "delete from " + table );
@ -178,6 +177,14 @@ public class AppDataExporter {
continue; continue;
} }
// 一時的に存在したが現在のDBスキーマにはない項目は読み飛ばす
if( SavedAccount.table.equals( table ) &&
( "nickname".equals( name ) || "color".equals( name ) )
){
reader.skipValue();
continue;
}
JsonToken token = reader.peek(); JsonToken token = reader.peek();
switch( token ){ switch( token ){
case NULL: case NULL:
@ -204,19 +211,24 @@ public class AppDataExporter {
} }
} }
reader.endObject(); reader.endObject();
long new_id = db.insert( table, null, cv ); long new_id = db.insertWithOnConflict( table, null, cv, SQLiteDatabase.CONFLICT_REPLACE );
if( id_map != null ) id_map.put( old_id, new_id ); if( new_id == - 1L ){
throw new RuntimeException( "importTable: invalid row_id" );
}
if( id_map != null ){
id_map.put( old_id, new_id );
}
} }
reader.endArray(); reader.endArray();
bOK = true; db.execSQL( "COMMIT TRANSACTION" );
}catch( Throwable ex ){ }catch( Throwable ex ){
ex.printStackTrace(); ex.printStackTrace();
log.e( ex, "saveList failed." ); log.e( ex, "importTable failed." );
} try{
if( bOK ){
db.execSQL( "COMMIT TRANSACTION" );
}else{
db.execSQL( "ROLLBACK TRANSACTION" ); db.execSQL( "ROLLBACK TRANSACTION" );
}catch( Throwable ignored ){
}
throw ex;
} }
} }
@ -330,7 +342,13 @@ public class AppDataExporter {
throw new RuntimeException( "readColumn: can't convert account id" ); throw new RuntimeException( "readColumn: can't convert account id" );
} }
item.put( Column.KEY_ACCOUNT_ROW_ID, (long) new_id ); item.put( Column.KEY_ACCOUNT_ROW_ID, (long) new_id );
try{
result.add( new Column( app_state, item ) ); result.add( new Column( app_state, item ) );
}catch( Throwable ex ){
ex.printStackTrace();
log.e( ex, "column load failed." );
throw ex;
}
} }
reader.endArray(); reader.endArray();
return result; return result;