Questions tagged [sqliteopenhelper]

SQLiteOpenHelper is a class from the Android SDK which can be used for easier handling of a SQLiteDatabase.

Using the SQLiteOpenHelper only requires implementing its two abstract methods(other methods for different events can be implemented if the user chooses) onCreate(used for initializing the database) and onUpgrade(used when the database is being changed). The Android system will call this methods according to the state of the database( not created/created/upgrading) and in return, it will offer the user a valid SQLiteDatabase reference with the methods getWritableDatabase() and/or getReadableDatabase(). More information can be found in the documentation for the SQLiteOpenHelper class.

776 questions
305
votes
15 answers

When does SQLiteOpenHelper onCreate() / onUpgrade() run?

I have created my tables in my SQLiteOpenHelper onCreate() but receive SQLiteException: no such table or SQLiteException: no such column errors. Why? NOTE: (This is the amalgamated summary of tens of similar questions every week. Attempting to…
laalto
  • 137,703
  • 64
  • 254
  • 280
54
votes
4 answers

Android SQLite Example

I am new to Android and I have to create an application where I need to use a SQLite database. I am not so well equipped with the SQLite. Could you tell me what the purpose and use of the SQLiteOpenHelper class, and provide a simple database…
Rushabh Chheda
  • 643
  • 1
  • 6
  • 5
39
votes
3 answers

SQLite Connection leaked although everything closed

I found many stuff like close the connection and close the cursor, but I do all this stuff. Still the SQLite connection leaks and I get a warning like this: A SQLiteConnection object for database was leaked! I have a database manager this, which I…
flp
  • 950
  • 2
  • 11
  • 18
30
votes
5 answers

how to bulk insert in sqlite in android

I am using SQLiteOpenHelper for data insertion. I need to insert 2500 id and 2500 names, So it takes too much time. Please any one help me how to reduce the insertion time. can we insert multiple records at a time ? any one help me. thank you in…
kartheeki j
  • 1,828
  • 4
  • 22
  • 45
27
votes
8 answers

Backup Room database

I'm trying to backup a room database programmatically. For that, I'm simply copying the .sqlite file that contains the whole database But, before copying, due to the fact that room has write ahead logging enabled, we must close the database so that…
27
votes
4 answers

Confusion: How does SQLiteOpenHelper onUpgrade() behave? And together with import of an old database backup?

let's assume I have a database table test_table with 2 columns and a corresponding create script in the SQLiteOpenHelper: DB_VERSION = 1: public void onCreate(SQLiteDatabase db) { db.execSql("CREATE table test_table (COL_A, COL_B); } This is the…
Toni Kanoni
  • 1,996
  • 4
  • 20
  • 26
26
votes
1 answer

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,166
  • 1
  • 23
  • 31
21
votes
3 answers

DB File in Assets Folder. Will it be Updated?

I'm new to the Android SQLite whole thing. This is what I have: I have db.sqlite in my assets folder. The intent of the db is to READ ONLY. The user will not write to it. When the app gets updated, the db.sqlite will be replaced be a new db (I'll…
iTurki
  • 15,656
  • 19
  • 82
  • 128
19
votes
4 answers

Cursor finalized without prior close() Android

In my application I have a listview. I get my data with a query from a SQLiteDatabase. When I get the data from the db I get this error: It occurs when I go from line 20 to 21. I tried placing cursor.deactivate() and cursor.close() on regel 50.…
Timon Devos
  • 433
  • 1
  • 6
  • 18
18
votes
2 answers

Using a SQLite database in Libgdx

I'm new in Libgdx and I'm getting trouble on using a database on my game. I searched for a tutorial on how to make SQLite work on both Android and Desktop applications using Libgdx but I didn't found a easy one. The last time I used a database in…
Cristiano Santos
  • 2,055
  • 2
  • 33
  • 47
17
votes
1 answer

Robolectric: running multiple tests fails

I am trying to run multiple tests with Robolectric 3.0 + Gradle using SQLite (OpenHelper) as database. Running each single tests works fine, but starting the whole test suite always results in RuntimeException in the 2nd test. This is my test dummy,…
user2504611
  • 183
  • 1
  • 7
17
votes
4 answers

Android SQLiteException: Failed to change locale for db to 'en_US'

I recently updated one of my (open-source) Android apps and my users are getting an exception that I can't replicate. The key parts are : android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5) and then Caused by:…
liftdeadtrees
  • 441
  • 4
  • 16
16
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
  • 471
  • 1
  • 5
  • 16
16
votes
2 answers

SQLiteOpenHelper vs ContentProvider

I'm new to Android development. I'm trying to create an application that reads from the internal database (SQLite) and list all the data in a list (I'm using listView). So far I got a class called DatabaseHandler that extends SQLiteOpenHelper and…
André Alves
  • 5,605
  • 3
  • 15
  • 22
15
votes
2 answers

When should I call close() on SQLiteOpenHelper used by ContentProvider

In my android app, I use SQLiteOpenHelper to implements ContentProvider. Query, add, delete operations are all through ContentProvider. But in one of my android phone(htc g13), I found *.db-wal file in directory /data/data/[package name]/databases.…
cmoaciopm
  • 1,686
  • 1
  • 19
  • 29
1
2 3
51 52