Questions tagged [android-sqlite]

Android uses SQLite to store and retrieve data persistently. Use this tag for questions regarding the Android implementation of SQLite, how to use it in your application, or for help when your implementation of SQLite doesn't work.

uses a SQLite database to store and retrieve data persistantly.

Every Android App gets a private SQLite database to persistantly store data.

See also

8244 questions
35
votes
4 answers

Get the ID of a new record inserted into a database from the returned Uri

When you insert a new item into a database like this Uri uri = getContentResolver().insert(Tournaments.CONTENT_URI, values); is there any way to get the id from the uri that is returned so I don't have to run a query to get the id since its…
tyczj
  • 71,600
  • 54
  • 194
  • 296
34
votes
2 answers

Android getting database disk image is malformed (code 11) error

In my application I'm getting this database disk image is malformed (code 11) error for some users. I googled it and come to know that when db image is malformed Android deletes it and recreate new db file which is happening for some users. The…
Pramod Yadav
  • 2,316
  • 2
  • 23
  • 36
33
votes
3 answers

Get the field value with a Cursor

I'm creating an application and I have problems with Cursor. I have an SQLiteDatabase that returns me a Cursor when I try to fetch the values with this function: public Cursor fetchOption(long rowId) throws SQLException { Cursor mCursor =…
Michaël
  • 3,679
  • 7
  • 39
  • 64
32
votes
1 answer

SQLiteDiskIOException with error code 10: disk I/O error

I moved an SQLite database to an SD card, but sometimes it will throw the following exception: android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error Any suggestions on how I can prevent this from happening?
yava
  • 2,511
  • 3
  • 20
  • 17
32
votes
4 answers

When the SQLiteOpenHelper onCreate method is called?

I tried to create an SQLite database and do some stuff with it. But I found that my onCreate method is not even invoked!! I am sending a message to LogCat on the begining of the onCreate method. My assumption is, the (super) constructor will invoke…
malhobayyeb
  • 2,725
  • 11
  • 57
  • 91
31
votes
1 answer

expected, got '?'

When typing a SQLite statement as a string literal in a class in Android Studio, the IDE gives me this warning: " expected, got '?'". I don't understand what this means, but the code is working fine, and I'd like to disable the inspection. But…
Flarosa
  • 1,287
  • 1
  • 13
  • 27
30
votes
4 answers

Best practices for working with multiple tables

I use a database with multiple tables in my application. I have an XML parser which needs to write data to two tables while parsing. I created two database adapters for both tables, but now I have a problem. When I'm working with one table, it's…
Burjua
  • 12,506
  • 27
  • 80
  • 111
29
votes
5 answers

java.lang.IllegalArgumentException: column '_id' does not exist

I'm trying to debug my application on a real device but I get this error: ERROR/AndroidRuntime(981): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist When I'm testing on an emulator, the error doesn't appear. The…
rogcg
  • 10,451
  • 20
  • 91
  • 133
28
votes
17 answers

Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android

We have a sqlite database in our Application. Its working fine for all the users but few of them experiencing the Caused by: android.database.sqlite.SQLiteException: no such table: generalSettings (code 1): , while compiling: select * from…
Sniper
  • 2,412
  • 11
  • 44
  • 49
27
votes
2 answers

What is the limit of SQL variables one can specify in a single execSQL query

I am trying to improve the speed of my android database inserts. What I am currently doing is generate a string like: SELECT ? as title, ? as musician_id, ? as album_id, ? as genre UNION SELECT ?, ?, ?, ? UNION SELECT ?, ?, ?, ? UNION SELECT ?, ?,…
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
27
votes
3 answers

store long value in android database

How do I store long values in Android SQLite database ? I am trying to store the time(milliseconds) values which comes in long type format .
zafi005
  • 500
  • 1
  • 5
  • 12
26
votes
5 answers

Convert SQLite to JSON

Is there a way to convert sqlite to json? All other questions are parsing json and saving to sqlite. I can't seem to find any reference on this, please help me. I have a sqlite db inside the app and i need it to be converted to json, upgrade db…
Lendl Leyba
  • 2,287
  • 3
  • 34
  • 49
26
votes
3 answers

How to convert milliseconds to date in SQLite

I store date from Calendar.getTimeInMilliseconds() in SQLite DB. I need to mark first rows by every month in SELECT statement, so I need convert time in milliseconds into any date format using SQLite function only. How can I avoid this?
Konstantin.Efimenko
  • 1,242
  • 1
  • 14
  • 38
26
votes
9 answers

Android SQLite Query - Getting latest 10 records

I have a database saved in my Android application and want to retrieve the last 10 messages inserted into the DB. When I use: Select * from tblmessage DESC limit 10; it gives me the 10 messages but from the TOP. But I want the LAST 10 messages. Is…
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
25
votes
3 answers

SQLiteConstraintException error showing after start of every activity

I have this error popping out in logcat all the time. It always shows after every change of activity. And sometimes, the app disappears and in a second it shows again. There is not any fatal error in logcat, all I see is this: 2020-05-20…
Adam Knirsch
  • 443
  • 1
  • 6
  • 16