I am using Sqlite database in one of my Android project. It works fine in all the devices except One Plus Two device.
I am getting exception while trying to open the database. This is the crashlog.
12-23 19:14:35.235: E/SQLiteLog(3133): (11) database corruption at line 53216 of [9491ba7d73]
12-23 19:14:35.235: E/SQLiteLog(3133): (11) statement aborts at 7: [SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1]
12-23 19:14:35.237: E/SQLiteDatabase(3133): Failed to open database '/data/data/com.mycompany.myapp/databases/alcochange.sqlite'.
12-23 19:14:35.237: E/SQLiteDatabase(3133): android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.mycompany.myapp/databases/myapp.sqlite' to 'en_US'.
Please click here to see the full crash log
I have seen other questions like that here, I have tried almost every answers, but nothing works.
I have tried this and this.
EDIT: The device runs on Oxygen Lollipop.
I can't find the reason why I am having this error, but somehow I have avoided this by doing the following.
Previously, I had a .sqlite database in the bundle and when the user open our app for the first time, I copied the .sqlite database from the bundle to the correct path.
But now, I have exported the raw queries from the .sqlite and added it with the bundle as a txt file. Now when the user opens the app for the first time, I will first create an empty .sqlite file in the path and then I read all the .sql queries from the txt file from the bundle and execute them over the .sqlite file in the path.
Try to change locale manually.
Open your database file with a SQLite editor such as SQLiteStudio, then open android_metadata table. if it does not exist, create it. (you may create it with the query editor (tools>open query editor) and copy/paste the DDL code below)
CREATE TABLE android_metadata (
locale TEXT
);
for inserting the record you may copy/paste this line in the query editor:
INSERT INTO android_metadata VALUES ('en_us');
Hint: to run the query in SQLiteStudio you should push the button with icon in the toolbar.
Related
I'm inserting queries like below in sqlite database from sql file via eclipse:
INSERT INTO "Country_Table"
("countryid", "country_name" , "language", "currency", "VAT_abbr", "VAT_rate", "VAT_label", "creation_date" , "update_date", "status")
VALUES
("3","Austria","German","€","USt.","20,00","UID-Nr.","2013/06/27","2013/06/27","1");
Execution is as below:
07-19 16:46:43.739: I/System.out(23733): ---------------------executing----------------INSERT INTO "Country_Table" ("countryid", "country_name" , "language", "currency", "VAT_abbr", "VAT_rate", "VAT_label", "creation_date" , "update_date", "status") VALUES ("3","Austria","German","�","USt.","20,00","UID-Nr.","2013/06/27","2013/06/27","1");
This sql file is placed in assets folder.
But executing this queries, I found problem with the symbols "€" & "£", but it works fine with "$".
Insertion of the symbols takes place with '?' symbol whenever executed.
EDIT
I'm executing this query in SQLite then it works properly, but when executing this for android local database, the symbols of EURO and POUND are inserted as '?' in the database.
You have to ensure that the SQL file is encoded as UTF-8, and that your code that reads the file (which you have not shown) does not change the encoding.
I create a database. In this datebase create 3 lines. When I using this database in Android i get this error:
12-18 10:30:10.882: INFO/Database(477): sqlite returned: error code = 11, msg = database corruption found by source line 40107
12-18 10:30:10.882: INFO/Database(477): sqlite returned: error code = 11, msg = database disk image is malformed
This error is obtained, when I do: Select or Insert. How to solve this error?
Delete your app from emulator then install it again, this will create a new database.
EDIT:
Make sure you have a table named android_metadata with a column locale (TEXT), put a string in it (en_US)
A little trick that i do is to create the database normally in the application, I populate it, then i retrieve it from emulator using DDMS or adb (from /data/data/mypackage/databases/nameofthedatabase), and then I put it in the assets. This way I can be sure the database is valid.
Or you can create it in the application, retrieve it, then populate it or modify it (I use sqlitebrowser in linux, works beautifully), then I put it back in /data/data/mypackage/databases/nameofthedatabase, or in assets and copy it there.
I am creating a database using a DataHelper class and then creating a table using FTS virtual table.
The values are being imported from the text file in RAW folder which contains 1000 entries and a total file size of 64 kB.
But during the first time use the data values are not appearing during table query as though the full table is not yet created. Perhaps the file size is not at all huge(64 kB). The values appear when i restart the application and again make the query.
Is there any solution for this??
There is a solution: you can package your SQLite database in the APK and copy it on first run.
That way you will avoid long initial population...
More about this solution: Ship an application with a database
Hi im trying to read sqlite file which is placed in assets/databases folder
i followed this link to read data from sqlite file
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
im getting error
no such table : while compiling
SELECT _id, name, address FROM
stores
Is there any permission i need to write in manifest to read sqlite file data?
Please let me know how i can solve this issue. Or else please give me any reference link to follow.
Thanks in advance
The way you'd want to do this is to make a new DBManager object that creates the database in its onCreate method--that way when the DatabaseHelper is first instantiated, the table will be created for you. Then you'd instantiate one and call getReadableDatabase() on it to get a DB object which you can then query.
This tutorial may help you more, it's more succinct and up to date: http://developer.android.com/guide/topics/data/data-storage.html#db
After that, to set up the list view in a ListActivity, you can call setListAdapter and pass in a SimpleCursorAdapter. Here's a tutorial on that: http://developer.android.com/guide/appendix/faq/commontasks.html#binding
Check if database already exists or not.
If you are running on emulator.
write following on terminal/shell:
adb shell
cd data/data/your package name(ex. com.android.etc)
ls
if there exists databases directory then may be database is created
cd databases
ls
it will show your database if exists;
sqlite3 "your db name"
then write
.tables
it will show the name of table if exist:
now write your query over here to check for errors for ex:
sqlite> SELECT _id, name, address FROM stores
hope it helps.....
and yes there are no as such required permissions for this.
So far we have developed apps in android that create database on runtime. We like to know how can we access a pre-built or existing database/sqlite file in our android app? Please provide detail
Take a look at the documentation for android.database.sqlite.SQLiteDatabase.
In particular, there's an openDatabase() command that will access a database given a file path.
SQLiteDatabase db = SQLiteDatabase.openDatabase(path, null, 0);
Just specify the path to your database as the path variable, and it should work.
I have followed the same road and found two issues:
Include the _id field on any table you create and make sure it is
part of the columns to return when you query any table.
You may run into an error like Failed to open the database. closing
it.. This is because we are copying the database from an existing
file instead of creating tables on top of a db created by the sqlite
android API and the table android_metadata may not exist. For
creating it just run the following query on your db:
CREATE TABLE android_metadata (locale TEXT);
And add the corresponding locale, for example en_US
First copy your SDCARD and give it's path in the variable "DBNAME" in the following example.
it will be something like "/sdcard/persons.db" if you are directly pulling it to sdcard.
Use this for accessing database in application :
Context context = getApplicationContext();
context.getDatabasePath(DataBaseHelper.database_Name);