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
15
votes
2 answers

Room - insert or replace, but keep a database field?

I have in my local database a table called event with the fields: id (PK) name (text) date (time) favorite (int, 0 or 1) The server would give me a list of events, without the favorite field, the favorite field is only local. I'm using this code…
Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
15
votes
3 answers

Android Sqlite Performance

I have been doing some experiments to measure sqlite performance on android. I was disappointed a little bit with the results. What i did was inserting 10.000 queries to table and it took 130-140 seconds but with these conditions; 1. Samsung galaxy…
Mert Serimer
  • 1,217
  • 2
  • 16
  • 38
15
votes
2 answers

How to translate the PostgreSQL array_agg function to SQLite?

This query works in PostgreSQL: Select ot.MCode,array_to_string(array_agg(tk1.TName || ',' || ot.TTime), ' - ') as oujyu_name_list From TR_A ot inner join MS_B tk1 on ot.Code = tk1.Code Where ot.Code in (Select Code From TR_C )…
D T
  • 3,522
  • 7
  • 45
  • 89
15
votes
4 answers

The best way to caching json

My application should work not only in online but also in offline mode. For that reason I am considering find the best way for cashing data. I't like use SharedPreference for store data but in android documentation writen Maximum size in characters…
fish40
  • 5,738
  • 17
  • 50
  • 69
15
votes
3 answers

SQLiteException: table already exists

I added to my DB the table called "MEDIA_TABLE" and i got the following error code: 05-15 20:56:22.976: E/AndroidRuntime(5968): android.database.sqlite.SQLiteException: table personal_stats already exists (code 1): , while compiling: CREATE TABLE…
tomer
  • 389
  • 2
  • 6
  • 16
15
votes
4 answers

SQLiteDatabase: Insert only if the value does not exist (not via raw SQL command)

I know there's an SQL command that goes like this: IF NOT EXISTS, but since Android's SQLiteDatabase class has some fine methods, I was wondering if it's possible to insert a value if it doesn't exist via a method. Currently I'm using this to insert…
gosr
  • 4,593
  • 9
  • 46
  • 82
15
votes
3 answers

get a single row from table

These are the ids in my table: KEY_ID(autoincremented integer primary key) KEY_NAME(text) KEY_PH_NO(text) 1 james 1234567890 2 kristein …
Vaishali Sharma
  • 602
  • 3
  • 6
  • 24
15
votes
2 answers

How to use SQLiteDatabase.CursorFactory

Does anyone understand how to use SQLiteDatabase.CursorFactory on Android? I am looking to obtain a persistent SQLiteCursor object which uses an SQL SELECT statement where several of it's WHERE clause expressions use parameters which can be changed…
alex
  • 1,250
  • 2
  • 12
  • 19
14
votes
2 answers

Room (SQLite) WHERE clause with null arguments doesn't work

I have entity class Person and I want to query persons from database by feature which may or may not be null. When I set feature to non-null the query works but when the feature is null the query returns empty list. What I am doing…
Egis
  • 5,081
  • 5
  • 39
  • 61
14
votes
3 answers

Is it possible to use StringFormat or Constant Variable in android Room Query

I want to query the user associations list with the following room query using public constant variable Association.MEMBER_STATUS_APPROVED. @Query("SELECT * FROM Association WHERE memberStatus = " +…
Toe Lie
  • 551
  • 1
  • 5
  • 8
14
votes
1 answer

What's the correct way to put a birthdate into a contact data?

Background I'm trying to update contacts data and put there the birthdate of each. The problem It seems that for each device I try (and I didn't even try that many devices), the insertion has one or more of those issues: when viewing/editing the…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
14
votes
2 answers

GROUP_CONCAT in SQLite

I am having data like this 1 A 1 B 1 C 1 D 2 E 2 F 3 G 3 H 3 I 3 J 3 K by using this query select ABSTRACTS_ITEM._id,Name from ABSTRACTS_ITEM , ABSTRACT_AUTHOR , AUTHORS_ABSTRACT where ABSTRACTS_ITEM._id =…
user2579475
  • 1,051
  • 3
  • 11
  • 20
14
votes
1 answer

Correctly open/close a database with Singleton design pattern

I am creating an application which makes a lot of interactions with a database (both read and write operations). To avoid open/close operations at each request, I created a class extending SQLiteOpenHelper with a Singleton design pattern. This way,…
mithrop
  • 3,283
  • 2
  • 21
  • 40
14
votes
1 answer

"android.database.sqlite.SQLiteException: no such table" error in rare cases

I have an app currently available in the app store, but there is one type of error report that I can't seem to figure out completely. My app uses an internal sqlite database, but on some devices (certainly not the majority) the following error…
Toverbal
  • 256
  • 3
  • 14
13
votes
3 answers

Create Room Entity for a Table which has a field with LONG datatype in Sqlite

App Database has Items table with a column Price with datatype Long. Db Version = 1 CREATE TABLE items (_id INTEGER PRIMARY KEY AUTOINCREMENT,item_id INTEGER,title TEXT,price LONG, UNIQUE (item_id) ON CONFLICT IGNORE) While trying to migrate to…
Karthikeyan
  • 199
  • 1
  • 3
  • 9