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
25
votes
1 answer

How can I list all the triggers of a database in sqlite?

I can not drop a trigger, but when I try to create a new one with same name — it alerts me that trigger exists. So, I want to list all the triggers, to figure out what's wrong.
waiter.james
  • 591
  • 2
  • 6
  • 16
24
votes
6 answers

How to reset SqLite database in Android?

I want my users to be able to reset the application, then I need to reset the SQLite database that I have created. How can I do that? I want to reset the database or delete and recreate the database.
Roland
  • 826
  • 2
  • 9
  • 24
23
votes
2 answers

Android SQLite query where column is not null and not empty

I cannot figure out the syntax for the .query call. I need to select all records that match a certain column that do not have a null or empty value for a second (different) column my best attempt: Cursor cursor =…
cfrz
  • 325
  • 1
  • 3
  • 12
23
votes
2 answers

How to specify the sort order for the query to a content provider

I am trying to load all items from a Sqlite Table in Android and want to order the result. How do I specify the order for the returned cursor? I query the ContentProvider through a CursorLoader the following way: new CursorLoader(context,…
Janusz
  • 187,060
  • 113
  • 301
  • 369
23
votes
3 answers

Android SQLite database and app update

I have developed an android app and released version 1.0. The app contains SQLite local database with 5 tables. Now we planned to release version 2.0 also update the version 1.0 users. In version 2.0 we have included extra two tables with previous…
Rajesh Rajaram
  • 3,271
  • 4
  • 29
  • 48
22
votes
4 answers

Update with parameter using room persistent library

How will I update an entire row using room library, the @Update take a @Entity annotated object and updates it via referencing primary key but how will I update via some other parameter like update where certain value matches a value in cell in a…
Nikhil Soni
  • 1,011
  • 1
  • 11
  • 23
22
votes
3 answers

How to get started with SQLCipher for android?

I need to use SQLCipher for android...i've already made my app using SQLite and want to just convert it to SQLCipher. The problem is, I know nothing about SQLCipher. I have read about it in this link: http://sqlcipher.net/sqlcipher-for-android/ But…
Randomly Named User
  • 1,889
  • 7
  • 27
  • 47
22
votes
5 answers

java.lang.IllegalStateException: attempt to re-open an already-closed object(Tried closing )

public int getRecordsCount() { String countQuery = "SELECT * FROM " + TABLE_LOGIN; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); if(cursor != null &&…
onkar
  • 4,427
  • 10
  • 52
  • 89
22
votes
3 answers

Why does insertWithOnConflict(..., CONFLICT_IGNORE) return -1 (error)?

I have an SQLite table: CREATE TABLE regions (_id INTEGER PRIMARY KEY, name TEXT, UNIQUE(name)); And some Android code: Validate.notBlank(region); ContentValues cv = new ContentValues(); cv.put(Columns.REGION_NAME, region); long regionId = …
George
  • 2,110
  • 5
  • 26
  • 57
21
votes
3 answers

Specify max sqlite db size for my app. How to handle db full exception

I was asked in an interview how can we set max size for sqlite db for our android app. And how can we handle when max size is reached? EDIT: Marina Lynn's answer below seems acceptable to this question. But Are there some sort of listeners which are…
user517491
20
votes
6 answers

How to store sqlite database directly on sdcard

i want to create my sqlite database in sdcard instead of default path...i want to access all my data from sdcard also I have Used This Code: private static class OpenHelper extends SQLiteOpenHelper { OpenHelper(Context context) { …
Shiv
  • 4,569
  • 4
  • 25
  • 39
20
votes
3 answers

Should there be one SQLiteOpenHelper for each table in the database?

Is it better to have a single big SQLiteOpenHelper subclass that defines onCreate and onUpgrade methods for every table in the database, or is better to have many SQLiteOpenHelper subclasses, one for each table? Is there a best practice? Or are both…
Matteo Bononi 'peorthyr'
  • 2,170
  • 8
  • 46
  • 95
19
votes
2 answers

Android Room: How to Migrate Column Renaming?

Issue My app is crashing because I am not handling migration properly. I'm looking for a solution to migrate the name of 1 column in my table. In my project I a have a room table named 'content' with a Double attribute 'archivedCount'. In the…
AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
19
votes
1 answer

How to get list of cursor object from room dao access?

I am trying to chnage my code to make use of room database APIs. For documents table I have defined Entity class Document, when I query getAll() it returns me all the document. Now I have old implementation of Adapter which makes user of Cursor (…
Prashant
  • 4,474
  • 8
  • 34
  • 82
19
votes
3 answers

Android SQLite Database Unit Testing

I'm new to android app development and I just made a note app. I want to do unit tests for the insertNote, readNote and updateNote methods for the database. How do I go about this? This is the code for my database. Thanks. public class …
Anderson
  • 211
  • 1
  • 2
  • 3