diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java index a1ce7b2fc..43a5303f6 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBHelper.java @@ -300,7 +300,7 @@ public class DBHelper extends SQLiteOpenHelper { String[] columnNames = DBUtils.getColumns( db, name ); if ( null != columnNames ) { // no data means no need to copy query = String.format( "ALTER table %s RENAME TO 'temp_%s'", - name, name ); + name, name ); db.execSQL( query ); } createTable( db, name, data ); @@ -309,9 +309,19 @@ public class DBHelper extends SQLiteOpenHelper { if ( null != columnNames ) { ArrayList oldCols = new ArrayList( Arrays.asList( columnNames ) ); - String[] newColNames = DBUtils.getColumns( db, name ); - ArrayList newCols = - new ArrayList( Arrays.asList( newColNames ) ); + + // Make a list of columns in the new DB, using it to + // remove from the old list any that aren't in the + // new. Old tables may have column names we no longer + // use, but we can't try to copy them because the new + // doesn't have 'em. Note that calling getColumns() on + // the newly-created table doesn't work, perhaps + // because we're in a transaction and nothing's been + // committed. + ArrayList newCols = new ArrayList(); + for ( int ii = 0; ii < data.length; ii += 2 ) { + newCols.add( data[ii] ); + } oldCols.retainAll( newCols ); String cols = TextUtils.join( ",", oldCols );