2012-03-31 73 views
0

我的應用程序使用了一個sqlite數據庫,該數據庫是從assets文件夾預先創建並在運行時複製的。它通常工作得很好。 我已經recenetly添加到數據庫的新列,並增加了數據庫版本,以便onUpgrade方法運行。這一切運作良好,但新的數據庫複製沒有新增列。這是onUpgrade代碼:Android Sqlite onUpgrade不會複製新列

//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(); 

任何想法如何解決它?

10X!

+1

我建議你考慮切換到['SQLiteAssetHelper'](https://github.com/jgilfelt/android-sqlite-asset-helper),它已經完成了所有這些工作並進行了調試。 – CommonsWare 2012-03-31 22:56:31

+0

乍一看似乎很有趣,我會試一試並回報:) 10X! – 2012-03-31 23:23:43

+0

試試這個: http://stackoverflow.com/questions/9109438/using-already-created-database-with-android/9109728#9109728 – 2012-04-01 00:19:01

回答

0

有時候顯然需要問。 :)

您確定已將新的數據庫複製到您的資產文件夾,以便它可以再次移入數據庫目錄嗎?

+0

是的,我做了它,10X :) – 2012-04-10 23:06:37