mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
fix crash upgrading from beta 30 (which is two years old!)
This commit is contained in:
parent
b33991486c
commit
6bb2a9bb9a
1 changed files with 14 additions and 4 deletions
|
@ -300,7 +300,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
String[] columnNames = DBUtils.getColumns( db, name );
|
String[] columnNames = DBUtils.getColumns( db, name );
|
||||||
if ( null != columnNames ) { // no data means no need to copy
|
if ( null != columnNames ) { // no data means no need to copy
|
||||||
query = String.format( "ALTER table %s RENAME TO 'temp_%s'",
|
query = String.format( "ALTER table %s RENAME TO 'temp_%s'",
|
||||||
name, name );
|
name, name );
|
||||||
db.execSQL( query );
|
db.execSQL( query );
|
||||||
}
|
}
|
||||||
createTable( db, name, data );
|
createTable( db, name, data );
|
||||||
|
@ -309,9 +309,19 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||||
if ( null != columnNames ) {
|
if ( null != columnNames ) {
|
||||||
ArrayList<String> oldCols =
|
ArrayList<String> oldCols =
|
||||||
new ArrayList<String>( Arrays.asList( columnNames ) );
|
new ArrayList<String>( Arrays.asList( columnNames ) );
|
||||||
String[] newColNames = DBUtils.getColumns( db, name );
|
|
||||||
ArrayList<String> newCols =
|
// Make a list of columns in the new DB, using it to
|
||||||
new ArrayList<String>( Arrays.asList( newColNames ) );
|
// 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<String> newCols = new ArrayList<String>();
|
||||||
|
for ( int ii = 0; ii < data.length; ii += 2 ) {
|
||||||
|
newCols.add( data[ii] );
|
||||||
|
}
|
||||||
oldCols.retainAll( newCols );
|
oldCols.retainAll( newCols );
|
||||||
|
|
||||||
String cols = TextUtils.join( ",", oldCols );
|
String cols = TextUtils.join( ",", oldCols );
|
||||||
|
|
Loading…
Add table
Reference in a new issue