Here's a snippet of code that may help you.  I rename the old table,
create the new table, and then insert the data into the new table
while modifying the data.

@Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
                Log.d(getClass().getName(), "Upgrading Database.");
                if(oldVersion==1) {
                        db.execSQL(VEHICLE_RENAME_VERSION_1);
                        db.execSQL(VEHICLE_CREATE);
                        upgradeVehicle2(db);
                }
        }

        private void upgradeVehicle2(SQLiteDatabase db){
                //get cursor to old vehicle table
                Cursor cursor = db.query("vehicle_1", new String[]
{"_id","vehicle","notes","selected","vehicle_uri","weight"}, null,
null, null, null, null);

                while(cursor.moveToNext()){
                        ContentValues values = new ContentValues();
                        values.put("_id", cursor.getLong(0));
                        values.put("vehicle", cursor.getString(1));
                        values.put("notes", cursor.getString(2));
                        values.put("selected", cursor.getShort(3));
                        values.put("vehicle_uri", cursor.getString(4));
                        values.put("weight", cursor.getFloat(5));
                        values.put("drivetrain_loss",
Constants.VEHICLE_DEFAULT_DRIVETRAIN_LOSS);
                        db.insert("vehicle", null, values);
                }
        }

Jeff
http://www.trackaroo.com

On Nov 29, 9:02 am, "Dexter&#39;s Brain" <[email protected]> wrote:
> Is it sufficient if I change the database version? Or, first I will
> have to back up the db programatically and then restore all the tables
> with contents?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to