Would like a bit of clarification with SQLite database's onUpgrade method

Would like a bit of clarification with SQLite database's onUpgrade method

By : Peter O'Gorman
Date : November 21 2020, 03:00 PM
will be helpful for those in need
The SQL_CREATE_STRING starts with "CREATE TABLE IF NOT EXISTS", so I'm assuming I could just leave it in the onUpgrade method, correct? Since if it sees the table already it already exists, it wont try to make another one.
code :
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {
    for(int i = oldVersion + 1; i < newVersion; i++) {
        switch(i) {
        case 2: upgradeFromv1Tov2(); break;
        case 3: upgradeFromv2Tov3(); break;

Share : facebook icon twitter icon
Own SQLite Database and onUpgrade

Own SQLite Database and onUpgrade

By : user3129705
Date : March 29 2020, 07:55 AM
To fix the issue you can do Here is the answer thanks to Joe Masilotti on http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/comment-page-2/
code :
private static final int DATABASE_VERSION = 1;
public DataBaseHelper(Context context) {
    super(context, DB_NAME, null, DATABASE_VERSION);
    this.myContext = context;
public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
        Log.v(“DB Exists”, “db exists”);
        // By calling this method here onUpgrade will be called on a
        // writeable database, but only if the version number has been
        // bumped
    dbExist = checkDataBase();
    if (!dbExist) {
        // By calling this method and empty database will be created into
        // the default system path of your application so we are gonna be
        // able to overwrite that database with our database.
        try {
        } catch (IOException e) {
            throw new Error(“Error copying database”);
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    if (newVersion > oldVersion)
        Log.v(“Database Upgrade”, “Database version higher than old.”);
How to modify type in a table of SQLite in Android, using onUpgrade method?

How to modify type in a table of SQLite in Android, using onUpgrade method?

By : kaycee
Date : March 29 2020, 07:55 AM
I wish this help you SQLite indeed does not allow changing existing table columns.
However, SQLite uses dynamic typing, so what column type you set in the table definition does not really matter (except for conversions due to type affinity).
code :
CREATE TABLE TempTable (...);
INSERT INTO TempTable SELECT col1, col2, ... FROM MyTable;
INSERT INTO TempTable SELECT CAST(col1 AS TEXT), ... From MyTable;
SQLite onUpgrade()

SQLite onUpgrade()

By : Max Kohl
Date : March 29 2020, 07:55 AM
around this issue 1. About onCreate() and onUpdate()
onCreate(..) is called whenever the app is freshly installed. onUpgrade is called whenever the app is upgraded and launched and the database version is not the same.
SQLiteOpenHelper.onUpgrade how does it exactly works? (app with multiple databases)

SQLiteOpenHelper.onUpgrade how does it exactly works? (app with multiple databases)

By : Garikk
Date : March 29 2020, 07:55 AM
this one helps. If you want, you may want to use SQLiteDabase (the first parameter of onUpgrade), with the method getPath to know which databse will be updated.
When you will ask SQLiteOpenHelper.getWritableDatabase (or getReadableDatabase()), it will be updated if the version you set in constructor is greater than the current version of the database.
what is the use of onUpgrade() in sqlite?

what is the use of onUpgrade() in sqlite?

By : Al Nad
Date : March 29 2020, 07:55 AM
I wish did fix the issue. when you change your database table element or column value then you must have to update to data to reflect that change. other wise no such table or other kind of error will occur. so after changing in database if your application is already uploaded then you have to change database version and all the all table recreate in onUpdate() method.
Related Posts Related Posts :
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Turn on the screen when timer calls onFinish()
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Correct way to add more views to adapter
  • Getting error in android support library
  • Instant app zip uploading error
  • "No emulator installed" error in Android Studio even though Intel HAXM is up and running
  • AsyncTask without leaks
  • SQLiteException : No such table found whereas a table was created
  • Using @Component.Builder with constructor params
  • No injector was found for fragment dagger 2.11
  • Android Volley Https SSL self signed and Google Maps API
  • Why does the onClickListener not work anymore in this example?
  • Why are my map marker ObjectAnimators getting canceled?
  • Android App update only working after deleting all local data
  • Getting unknown attribute error in android studio
  • How to remove space in Toolbar
  • Phonegap - Push notification with embedded web app (InAppBrowser window)
  • Broadcast receiver is not triggered for incoming calls
  • How to know whether realm.commitTransaction() succefull
  • How to create title bar in android?
  • Control RecyclerView inflated views from outside the adapter: keep selection state
  • How to swap items from two recyclerview items that are in two fragments in one activity?
  • Having trouble with interfaces in Java regarding retrieval and storage of data from a Firebase Database
  • ViewPager overlaps AppBarLayout
  • Custom view downcasting not working
  • New release on Google Play Store - Keystore was tampered with
  • How do I display items in a RecyclerView one by one onButtonClick instead of loading all questions at once
  • Why use inline without lambdas
  • Retrofit2 - Expected BEGIN_ARRAY but was BEGIN_OBJECT using Call<List<JSONObject>>
  • Notification icon showing up in status bar but not in notification itself
  • Method Not Allowed (405) while uploadFileTask to QuickBlox - (Android)
  • how get Drawable from String path?
  • Why do the ":" not sit on the top in layout files?
  • How do I differentiate between two WhatsApp messages?
  • UTF-8 in Android compared to definition of UTF-8
  • Gradle 3.0 BuildException cannot create directory
  • How to make a screen not fall asleep if the app runs on boot?
  • Share PDF from assets. FileUriExposedException
  • Vertical ViewPager with HorizontalScrollView inside Fragment
  • Adding subscribeOn() is changing return type of observable
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org