0

My application uses a sqlite DB, which is pre-created and copied on runtime from the assets folder. It usually works just fine. I have recenetly added a new column to the DB, and incremented the DB version in order for the onUpgrade method to run. this all works well, but the new DB is copied without the newly added column. This is the onUpgrade code:

//Open your local db as the input stream
                        InputStream myInput = myContext.getAssets().open(DB_NAME);

                        // Path to the just created empty db
                        String outFileName = DB_PATH + DB_NAME;

                        //Open the empty db as the output stream
                        OutputStream myOutput = new FileOutputStream(outFileName);

                        //transfer bytes from the inputfile to the outputfile
                        byte[] buffer = new byte[1024];
                        int length;
                        while ((length = myInput.read(buffer))>0){
                            myOutput.write(buffer, 0, length);
                        }

                        //Close the streams
                        myOutput.flush();
                        myOutput.close();
                        myInput.close();

Any ideas how to solve it?

10X!

SuperFrog
  • 7,631
  • 9
  • 51
  • 81
  • 1
    I recommend you consider switching to [`SQLiteAssetHelper`](https://github.com/jgilfelt/android-sqlite-asset-helper), which has all of this worked out and debugged. – CommonsWare Mar 31 '12 at 22:56
  • at first glance it seems interesting, I will give it a try and report back :) 10X! – SuperFrog Mar 31 '12 at 23:23
  • Try this: http://stackoverflow.com/questions/9109438/using-already-created-database-with-android/9109728#9109728 – Yaqub Ahmad Apr 01 '12 at 00:19
  • Tried SQLiteAssetHelper, the problem is that it requires a sql script for the upgrade, including the old version and the new one. In my case, all I want to do, is replace the DB. I really dont want to create a script for each upgrade possible, as I have a lot of versions out there in the Android Market. – SuperFrog Apr 10 '12 at 23:54

1 Answers1

0

Sometimes the obvious needs to be asked. :)

Are you sure you copied the new db to your assets folder so it could be moved into the database directory again?

Barak
  • 16,318
  • 9
  • 52
  • 84