SQLite-db corrupt only on Android 2.2 - android

I'm using this method to copy a pre-existing sqlite-database from my assets-directory to the app's /databases/-directory on the first app launch. This works fine on emulators with different SDK-levels and on my 4.4 devices, but fails on a 2.2.2 device with the following logcat message:
sqlite returned: error code = 11, msg = database corruption found by source line 40107
and further on SELECT locale FROM android_metadata failed
There are other SO-questions with this error, but my database definitely contains an android_metadata-table with a locale column and an en_US entry (which is why the app works on many other emulators and higher-SDK devices) and isn't large (32KB), which I read can be an issue.
Update: I switched to using the SQLiteAssetHelper-library, but am still getting the same error:
copying database from assets...
database copy complete
sqlite returned: error code = 11, msg = database corruption found by source line 40107
sqlite returned: error code = 11, msg = database disk image is malformed
CREATE TABLE android_metadata failed
Failed to setLocale() when constructing, closing the database
It seems the SQLiteOpenHelper (not the AssetHelper) is trying to create the android_metadata table (even though it's already present) and fails because of this?
Update 2: The full stacktrace can be found here

and add a new android_metadata-table with a locale-column and an en_us-row
Now that you are using SQLiteAssetHelper, and given the error message (CREATE TABLE android_metadata failed), remove your manual android_metadata table from your packaged copy of the database. This will be created for you as part of unpacking the database via SQLiteAssetHelper.

Related

Android app crashes after generating signed apk

UPDATE:
When I delete app storage, it starts to work. I don´t understand...
When I generate a signed APK for my project and I install it to my phone, app crashes.
When I debug the app, it works correctly.
I use Android Studio 3 and I disabled instant run.
Using logcat, I get the following exception:
2019-01-15 19:19:30.594 7317-7317/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: me.agomezgz.bng.programa, PID: 7317
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.agomezgz.bng.programa/me.agomezgz.bng.programa.SplashActivity}: android.database.sqlite.SQLiteException: no such table: comentario (code 1 SQLITE_ERROR):  
it complains about no such table: comentario ...which means that table comentario had not been previously created - and that the stack-trace is just a follow-up error. see the build output for the ProGuard warnings (or even add them to the question); there might something obfuscated, which should not have been obfuscated. the code of the database class is completely irrelevant (simply because it works, while not being obfuscated); only the build-log matters. adding -verbose into the ProGuard configuration might help to obtain some more details.
UPDATE: When I delete app storage, it starts to work. I don´t understand...
You had an earlier version of the database file around that did not have that table. Clearing app storage removed the database file and forced sqlite helper onCreate() to run again.
See When is SQLiteOpenHelper onCreate() / onUpgrade() run?
Why it worked in debug is that the debug package is another application id and has a separate private directory where the database files are stored. That database file did not have this problem.
change your database onCreate method to this :
db.execSQL("CREATE TABLE IF NOT EXISTS comentario(_id integer,
nome text not null,
correo text not null,
texto text not null,
idLoc integer not null, primary key (_id));");

Unable to update database in android using SQLiteAssetHelper

I'm using SQLiteAssetHelper. I tried to upgrade the database by adding few insertions into the testdb.db file then according to instructions on
https://github.com/jgilfelt/android-sqlite-asset-helper
I renamed this new file to testdb.db_upgrade_1-2.sql and added to the asset folder in the android app. I changed the database version to 2 in the Databasehandler, but still there is an error as shown in the stacktrace which is as follows
I/SQLiteAssetHelper: successfully opened database testdb.db
W/SQLiteAssetHelper: Upgrading database testdb.db from version 1 to 2...
W/SQLiteAssetHelper: processing upgrade: databases/testdb.db_upgrade_1-2.sql
E/SQLiteLog: (1) near "SQLite": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
After this the app crashes.
My asset folder contains both /databases/testdb.db
and /databases/testdb.db_upgrade_1-2.sql
I'm using sqlite3 on my computer to generate the database file
I renamed this new file to testdb.db_upgrade_1-2.sql
That is incorrect. testdb.db_upgrade_1-2.sql is supposed to be a text file containing SQL statements to apply to your schema v1 database to convert it into a schema v2 database.
Quoting the documentation, with emphasis added:
Update the initial SQLite database in the project's assets/databases directory with the changes and create a text file containing all required SQL commands to upgrade the database from its previous version to it's current version and place it in the same folder.

Android SQLCipher - attempt to write a readonly database error in android version 5.x and above

I am facing one problem with sqlcipher since last month.
In my project I use existing database which is stored in raw folder of resources folder.
I open the database by using SQLiteDatabase.openOrCreateDatabase() method.
It is working fine in all devices before version 5.0.
But It shows me error on Android 5.x and above version with log as follows:
I also searched on internet.I found same issues found in link but there is no solution of it.
link as: https://github.com/sqlcipher/android-database-sqlcipher/issues/161
Error log as follows:
DELETE failed setting locale 08-13 09:44:58.388: E/Database(6507):
Failed to setLocale() when constructing, closing the database 08-13
09:44:58.388: E/Database(6507):
net.sqlcipher.database.SQLiteException: attempt to write a readonly
database
08-13 09:44:58.388: E/Database(6507): at
net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
08-13 09:44:58.388: E/Database(6507): at
net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2098)

Asset/data size limit on android using SQLiteAssetHelper?

Everything was working fine before I added some "big" tables to my file.
I have a table that weights about 2Mo, and now I am getting this error :
07-19 00:47:51.210 4703-4703/com.lectem.gecharacters
W/SQLiteAssetHelper﹕ copying database from assets... 07-19
00:47:51.280 4703-4705/com.lectem.gecharacters E/Database﹕ close()
was never explicitly called on database
'/data/data/com.lectem.gecharacters/databases/gechar2.sqlite'
android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was
opened here
at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1810)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.returnDatabase(SQLiteAssetHelper.java:408)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.createOrOpenDatabase(SQLiteAssetHelper.java:386)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getWritableDatabase(SQLiteAssetHelper.java:182)
at com.readystatesoftware.sqliteasset.SQLiteAssetHelper.getReadableDatabase(SQLiteAssetHelper.java:254)
I tried to empty the table, and it works again after this...
I am using the SQLite Manager plugin for Firefox, and the SQLiteAssetHelper library.
Can't open database with SQLiteAssetHelper didn't help.
EDIT: I forgot to mention that it works fine on my phone (android 4.1) but the error occurs on my Tablet (android 2.2.1)
The answer was in the readme... https://github.com/jgilfelt/android-sqlite-asset-helper
I was compressing my database using gzip, but it seems you really need to use zip for old devices.
Earlier versions of this library required the database asset to be
compressed within a ZIP archive. This is no longer a requirement, but
is still supported. Applications still targeting Gingerbread (API 10)
or lower should continue to provide a compressed archive to ensure
large database files are not corrupted during the packaging process.
The more Linux friendly GZIP format is also supported. The naming
conventions using the above example are as follows:
ZIP: assets/databases/northwind.db.zip (a single SQLite database file must be the only file within the archive)
GZIP: assets/databases/northwind.db.gz

SQLite database webview.db error on Android 4.0.4 using Phonegap

I am using Phonegap on Android 4.0.3
I have created a database and then try to create some table and insert some data. Everything works fine on 4.2 but on 4.0.3 it just doesn't work.
I got the following error all the time
sqlite returned: error code = 1, msg = near ",": syntax error,
db=/data/data/com.vs.bettercommunity/databases/webview.db

Categories

Resources