lundi 25 mai 2015

Using a downloaded SQlite database

with a PHP-file I generate SQL-Database. If the md5-sum is different from the one which is stored in /Android/data/PACKAGENAME/files/databases/ its downloaded automatically. This all works fine.

In the app, I want to use the database:

public void requestEAN(){
    SQLiteDatabase sampleDB = null;
    try {
        //Instantiate sampleDB object
        sampleDB =  StaffActivity.this.openOrCreateDatabase("/Android/data/" + getApplicationContext().getPackageName() + "/files/databases/SqliteTmp.sqlite", MODE_PRIVATE, null);
        //this.getDatabasePath(DATABASE_NAME).getPath();
        //Create Cursor object to read versions from the table
        Cursor c = sampleDB.rawQuery("SELECT bezeichnung, art, stammkost, marker FROM SqliteTmp", null);
        //If Cursor is valid
        if (c != null ) {
            //Move cursor to first row
            if  (c.moveToFirst()) {
                    //Get version from Cursor
                    bezeichnung = c.getString((1));
                    art = c.getString((2));
                    stammkost = c.getString((3));
                    marker = c.getString((4));
                    Intent out = new Intent(getApplicationContext(), OutActivity.class);
                    startActivity(out);

            }
        }

    } catch (SQLiteException se ) {
        Toast.makeText(getApplicationContext(), "Couldn't create or open the database", Toast.LENGTH_LONG).show();
    }
}

The database looks like: error

The access to the database fails with:

05-25 14:29:36.214      822-822/eu.straff E/SQLiteLog﹕ (14) cannot open file at line 30241 of [00bb9c9ce4]
05-25 14:29:36.214      822-822/eu.straff E/SQLiteLog﹕ (14) os_unix.c:30241: (2) open(/Android/data/eu.straff/files/databases/SqliteTmp.sqlite) -
05-25 14:29:36.214      822-822/eu.straff E/SQLiteDatabase﹕ Failed to open database '/Android/data/eu.straff/files/databases/SqliteTmp.sqlite'.
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

Aucun commentaire:

Enregistrer un commentaire