Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6528425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:59+00:00 2026-05-25T09:31:59+00:00

I want the sqlite database of my app to be cleared each time the

  • 0

I want the sqlite database of my app to be cleared each time the application is updated.
To do that, I make a drop table query on all my tables, in the “onUpgrade” function of SQLiteDatabase.

I got 2 problems:
– at the first launch of my app, I don’t do any special.
– at the second launch, I add a “setVersion(2)” line. It calls the onUpgrade method but the logs are strange:

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
    Log.d("GDB", "onUpgrade "+oldVersion+" -> "+newVersion);
}
----------------------------------------------------------
DEBUG/GDB(5928): onUpgrade 2 -> 1

So when I make a setVersion(), the 2 versions seems to be switched…..

My second problem is that is I launch my app a third time, without changing the code ( so the setVersion(2) is already here), the onUpgrade method is called again! Did I miss something to definitively set the version to 2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:32:00+00:00Added an answer on May 25, 2026 at 9:32 am

    I don’t think you should be setting the version of the database in code directly using the setVersion method. Instead you should pass the schema version into the constructor of your SQLiteOpenHelper (or at least your class which extends this). Your onUpgrade method should then contain condition statements to decide what to run depending on what version the user is upgrading from. These conditions should form a cascade so that coming from a low version applies in sequence all database updates required to get the user to the current level.
    So when you want to change your schema, you add a new condition to your onUpgrade and up the schema version passed to your constructor.

    This is what the constructor in the OpenHelper looks like:

    public TiftHelper(Context context) {
        super(context, DATABASE_NAME, null, SCHEMA_VERSION);
    }
    

    Then the onUpgrade looks something like this:

    @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.d(TAG, "on upgrade called. Old version:" + oldVersion
                    + ". New version:" + newVersion);
    
            if (oldVersion == 19) {
                db.execSQL("create table challenges_temp as select * from challenges;");
                db.execSQL("drop table challenges;");
                db.execSQL(create_challenges);
                db.execSQL("insert into challenges (_id, name, is_predef, status) select _id, name, is_predef, 'IN_PROGRESS' from challenges_temp");
                db.execSQL("drop table challenges_temp;");
            }
            if (oldVersion <= 20) {
                // adding the status column to the challenges table
                db.execSQL("create table challenges_temp as select * from challenges;");
                db.execSQL("drop table challenges;");
                db.execSQL(create_challenges);
                db.execSQL("insert into challenges (_id, name, is_predef, status) select _id, name, is_predef, 'IN_PROGRESS' from challenges_temp");
                db.execSQL("drop table challenges_temp;");
            }
    

    etc.

    That works fine for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to remove all rows that i entered from my SQLite database table.
I want to add a sqlite database in my app and all tutorials says
I am creating an iphone app that will run an SQLite database. I want
I have a SQLite database that I want my app to read and load
I want to drop a table in my SQLite Database file named database.db. After
I have a DataTable which I want to save to a SQLite Database Table.
I have a component that i want to store to an SQLite database. public
I developed one database related application for iPhone device(SQlite database). Now i want to
I want to use SQLite within my MFC application. for that, i'll create an
I want to store a row in an SQLite 3 table for each booking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.