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.

801 questions
4
votes
0 answers

SQLiteOpenHelper: fastest way to execute ~ 20k statements?

I'm using SQLiteOpenHelper in my Android app and would like to insert ~20k statements in the onCreate method. I can't use a prefilled database as then I'm facing problems with OnePlus devices (SQLiteAssetHelper - problems on specific phones, e.g.…
swalkner
  • 16,679
  • 31
  • 123
  • 210
4
votes
1 answer

Android SQLiteOpenHelper.onUpgrade how handle database schema upgrade

I have an app in Google Play store and I'm working on new version of it. There will be change in SQLite database scheme (new tables) + new ContentProviders. I consider how to properly solve upgrade of database structure so that users when upgrading…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
4
votes
3 answers

getReadableDatabase often, but not always returns null

I see in the Crashlytics-Logs of my android application a NullPointerException in this code: try { mSQLDBreader = this.getReadableDatabase(); } catch (SQLException e) { if (mSQLDBreader != null) { mSQLDBreader.close(); …
swalkner
  • 16,679
  • 31
  • 123
  • 210
4
votes
1 answer

Difference between SQLiteOpenHelper and SQLiteAssetHelper?

What is the the difference between SQLiteOpenHelper and SQLiteAssetHelper?And how do I use them? I know that when you use SQLiteOpenHelper you have to override the onCreate() and onUpgrade() methods. Furthermore one can add, remove, and look-up…
KellysOnTop23
  • 1,325
  • 2
  • 15
  • 34
4
votes
1 answer

Fatal Exception : unknown error (code 14) could not open database

My application is throwing this Fatal Exception : unknown error (code 14) could not open database when running on Android Kitkat 4.4, The application is running perfectly on all the previous versions. Exception is being thrown in this line. …
Anchal
  • 859
  • 1
  • 10
  • 21
4
votes
1 answer

getDatabase called recursively when insert a record in oCreate of my DbHelper class

When I'm trying to insert a record in onCreate method of my DbHelper class which is extended from SQLiteOpenHelper, this error will be rised. I've found some similar topics like these: Android getDatabase called recursively getWritableDatabase…
ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112
4
votes
2 answers

Issue with SQLiteOpenHelper on android 2.X and 3.X

So i made a big mistake of testing my code on android 4.0 + and thinking it would work fine on other versions. But i am facing issues with 2.X and 3.X with SQLiteOpenHelper. First the code : public class HelperDB extends SQLiteOpenHelper implements…
user1492955
  • 1,728
  • 2
  • 12
  • 13
4
votes
4 answers

error inserting android.database.sqlite.sqliteconstraintexception error code 19 constraint failed

I know there are so lot of threads about this problem but none of my own problem. I have a spinner connected in the database that displaying the foreign key of the specific table. And it appears error inserting. 02-18 11:44:34.500:…
4
votes
1 answer

MyContentProvider.onCreate() is not being called?

The onCreate of my userDatabase that extends ContentProvider is not properly called Here is some of my userBatabase code: public class userDatabase extends ContentProvider { private MainDatabaseHelper mOpenHelper; public userDatabase(){} …
4
votes
1 answer

Reading SQLITE database from Android memory

I have created an sqlite database on a Java application and have pushed it to my android. I want to read this database (probably write into it later too). Most of the tutorials I have found so far create the DB within the android... I don't think I…
Achilles
  • 711
  • 2
  • 13
  • 35
4
votes
5 answers

SQLiteOpenHelper "onCreate" is not called? (the DB does not exist)

From a fragment I instantiate this way fmdata = new FileManagerData(getActivity()); the following class. I don't understand why onCreate() is not called and my database does not get created. public class FileManagerData { public static final String…
znat
  • 13,144
  • 17
  • 71
  • 106
3
votes
2 answers

Where/how to implement SQLiteDatabase and AsyncTask in TabActivity

I'm basically finished an application I'm developing (my very first!), except for implementing any data saving mechanism. I looked into the options a while ago and decided the SQLiteDatabase is the best to go with, but it was difficult to wrap my…
S Fitz
  • 1,074
  • 15
  • 31
3
votes
2 answers

no such table:@DatabseView

I was trying to create a database view in android but getting this error: error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: ChatsView) public abstract androidx.lifecycle.LiveData> …
3
votes
1 answer

Android Sqlite App crashes in Android pie and above Gives SQLiteDiskIOException (code 522)

I'm trying to backup tables from my database when onupgrade method is called. I' m using the solution provided here Android Sqlite onupgrade delete table from database . It works fine on Android 8 but on Android 9 and above it crashes. Here is the…
user11437625
3
votes
0 answers

Performing long-running tasks in onUpgrade() of SQLiteOpenHelper

I have a published app with several tables in its database. I want to add a new column to one of the tables and then populate it based on entries from another table. Basically, I'll need to: 1) Add the new column with ALTER TABLE 2) Query another…
Gavin Wright
  • 3,124
  • 3
  • 14
  • 35