2

I'm attempting to back up a version of my database on dropbox. Everything works fine uploading the file to dropbox but I'm having trouble replacing the one that is currently on the phone with the one on dropbox.

    new Thread(new Runnable() {
        public void run() {
            File file = new File(getDatabasePath("my_database").getPath());
            file.getParentFile().mkdirs();

            try {
                FileOutputStream outputStream = new FileOutputStream(file);
                DropboxFileInfo info =dbInstance.getFile("/BackupFolder/my_database", null,
                        outputStream, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();

When the operation completes I get a lot of "SQLiteException: no such table" errors after this. I have verified that the database in dropbox is correct.

01-09 20:03:37.601: W/System.err(7185): android.database.sqlite.SQLiteException: no such table: transaction_table (code 1)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
01-09 20:03:37.601: W/System.err(7185): at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:1036)
01-09 20:03:37.601: W/System.err(7185):     at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
01-09 20:03:37.601: W/System.err(7185):     at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
01-09 20:03:37.601: W/System.err(7185):     at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:144)
01-09 20:03:37.601: W/System.err(7185):     at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
01-09 20:03:37.601: W/System.err(7185):     at android.content.ContentResolver.query(ContentResolver.java:436)
01-09 20:03:37.601: W/System.err(7185):     at android.content.ContentResolver.query(ContentResolver.java:360)

UPDATE

I've downloaded the file to another location on the device so that I can view it using sqlite3 and everything is in there. So, apparently the download is working correctly but I'm not able to overwrite the existing database at runtime with this file.

DroidT
  • 3,168
  • 3
  • 31
  • 29
  • Please, add your exception. – Mahmoud Jan 10 '14 at 01:28
  • I've added one of the exceptions I get when making a query. – DroidT Jan 10 '14 at 02:11
  • Check the name and location of your database. And check if the database file exist or not. And print file size, it will be useful info. – Mahmoud Jan 10 '14 at 02:38
  • I updated my answer with new findings. – DroidT Jan 10 '14 at 03:14
  • in this answer i explain a safe method to copy sqlite files to the app data folder and use it as main db http://stackoverflow.com/questions/21101515/getting-a-prepopulated-database-located-in-the-assets-folder-into-the-data-data/21103946#21103946 – Carlos Robles Jan 23 '14 at 05:20

1 Answers1

0

Try to close all database connection before overwrite database.

You can do:

  • Close connection to the old database.
  • Delete old database file.
  • Move or copy new database.
  • Create a new connection to the new database.
Mahmoud
  • 2,683
  • 1
  • 30
  • 32