Database onUpgrade from Assts Folder
<p>When my app is created, my database is copied from the assets folder to my app.</p>

<p>Now if i want to do an onUpgrade, i just want to overwrite all Tables EXCEPT of one.</p>

<p>But how can i do this?
I just can write the whole database or nothing...</p>

<p>Please help me with this.</p>

<p>This doesnt work of course, because it doesnt overwrite the existing tables, it just backups the one i do not replace..</p>

<pre><code>public void createDataBase() throws IOException{
        boolean dbExist = checkDataBase();
        if(dbExist){   
            myDataBase = this.getWritableDatabase();
        } else {
            myDataBase = this.getReadableDatabase(); 
            try { 
                copyDataBase(); 
            } catch (IOException e) { 
                throw new Error("Error copying database"); 
            }
        }       
    }
private void copyDataBase() throws IOException{

        //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))&gt;0){
            myOutput.write(buffer, 0, length);
        }

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

    }
@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i("onUpgrade", "newVersion: "+newVersion+", oldVersion: "+oldVersion);
        try{
        if(newVersion &gt; oldVersion){
            db.execSQL("ALTER TABLE Results RENAME TO temp_Results");
            db.execSQL("CREATE TABLE Results (lektionenId INTEGER PRIMARY KEY, testPassed Integer, lektionPassed Integer)");
            db.execSQL("INSERT INTO Results (testPassed, lektionPassed) SELECT testPassed, lektionPassed FROM temp_Results");
            db.execSQL("DROP TABLE IF EXISTS temp_Results");
        }
        } catch(Exception e){
            Log.i("exc", ""+e);
        }
    }
</code></pre>

<p>EDIT:</p>

<p>Where i call the Database:</p>

<pre><code>myDbHelper = new LernAppOpenHelper(this, "LernApp", DbConfig.DB_VERSION_LERNAPP);       

        try {
            String[] columns = {"_id","description"};
            myDbHelper.createDataBase();
            myDbHelper.openDataBase();

            cursor = myDbHelper.getQuery("Uebersicht", columns, null, null, null, null, null);
</code></pre>

<p>And my onUpgrade Method:</p>

<pre><code>@Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if(newVersion &gt; oldVersion){
            if("LernApp".equals(DATABASE_NAME)){
                myContext.deleteDatabase(DATABASE_NAME);
                try { 
                    copyDataBase(); 
                } catch (IOException e) { 
                    throw new Error("Error copying database"); 
                }
            }

        }

    }
</code></pre>
