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 8830913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:11:52+00:00 2026-06-14T08:11:52+00:00

As the title says, I have a production Android app with about 1000 installs.

  • 0

As the title says, I have a production Android app with about 1000 installs. I had to make a DB change in SQLite, up to this point the version of the SQLite DB has been set to version “1”.

Hopefully I explain the code below sufficiently in the comments, this code resides in my SQLiteOpenHelper Class so the onUpgrade method is part of the Class:

// Provides an upgrade path for the DB when the apps version is updated.
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        // First version of the DB was 1. Logic: each if statement will
        // alter the DB cumulatively based on the version code. So, if the
        // newVersion was version 3, there would be two if statements, one
        // for oldVersion 1 and one for oldVersion 2. oldVersion 2 will
        // contain the logic for upgrading from version 2 to 3, while
        // oldVersion 1 will contain a combination of alter statements
        // allowing the database to upgrade from version 1 directly to
        // version 3.
        if (oldVersion == 1) {
            db.execSQL("ALTER TABLE plans ADD COLUMN " + App.CURRENCYCODE
                    + " TEXT");
            Locale locale = Locale.getDefault();
            ContentValues content_values = new ContentValues();
            content_values.put(App.CURRENCYCODE, locale.toString());

            db.update(App.DBPLANS, content_values, App.ID + " > ?", new String[] {
                    "0"
            });
        }

        if (oldVersion == 2) {
            // Placeholder for next database upgrade instructions.
        }
    }

Please let me know if there are any pitfalls here. So far, it’s tested fine, though I’m very concerned about messing up my first DB upgrade. I have a 1,000 users or so, I’d hate to lose them all.

Thanks again!

  • 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-06-14T08:11:54+00:00Added an answer on June 14, 2026 at 8:11 am

    When I need to update a database like this, I typically do it with a switch statement where cases fall through to one another, such as:

    switch (oldVersion) {
        case 1:
            // update to version 2
            // do _not_ break; -- fall through!
        case 2:
            // update to version 3
            // again, do not break;
        case 3:
            // you're already up to date
    

    The benefits to this is you do not end up repeating your update statements in multiple if-statements as you continue to change the database, and adding a database update requires only adding a new case statement, not updating multiple blocks of code.

    There are sometimes exceptions to this, such as a column added in one version but then deleted in a future one, so you need to pay attention as you go.

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

Sidebar

Related Questions

As the title says, I have a problem with binding to a change in
As the title says I have a string like this: $string = "Hello World<br>hello
as the title says, I want to make a tab interface where I have
as the title says, I have to make a prolog progam that solves the
Title says all. I'll have navigation that looks like this and it's dynamically created
As title says i have some problems with IE8 and Javascript. It's known about
I currently have this written but the title says is there a better way
I just want what my title says.I have already read all the previous similar
As title says, I have a list of words, Like stopWords = [the, and,
As title says, I have access to the current listitem - and it's easy

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.