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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:38:04+00:00 2026-05-25T00:38:04+00:00

I am upgrading my database to add another column. What I am trying to

  • 0

I am upgrading my database to add another column. What I am trying to do is (after the column is added in onUpgrade) this method is called from the main activity for each table (3 were upgraded). The method is supposed to replace all of the blanks in the new column with “1”.

The code runs fine, stepping through, boolean test is true every time but when I open the table to view the data, the entire column is blank. The weird part is, my rowId numbers are incrementing every time. It starts out with 3 rows with rowIds of 1,2,3 respectively. After my code runs once, they now have rowIds of 4,5,6 respectively.

Can anyone help me out? KEY_ROWID is just my auto rowId number. KEY_MODE is just “mode” for column title. If I run through debugging it, the three rows I have show up in the code (it runs through the while loop 3 times).

public void checkBlanks(String table) {
    Cursor cursor =  mDb.query(table, new String[] {KEY_ROWID, KEY_MODE}, null, null, null, null, null);
    while (cursor.moveToNext()) {
        int modeCol = cursor.getColumnIndexOrThrow(KEY_MODE);
        if (cursor.isNull(modeCol)) {

            int rowId = cursor.getInt(cursor.getColumnIndexOrThrow(KEY_ROWID));
            ContentValues args = new ContentValues();
            args.put(KEY_MODE, 1); // replace the blank space with a "1"
            boolean test = mDb.update(table, args, KEY_ROWID + "=" + rowId, null) > 0;
        }
    }
    cursor.close();

}
  • 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-25T00:38:05+00:00Added an answer on May 25, 2026 at 12:38 am

    Instead of manually looping through the rows, why don’t you just leverage the power of SQL and update ALL of the rows in one call? E.g.

    mDb.execSQL("UPDATE " + table + " SET " + KEY_MODE + " = 1;");
    

    Since it’s so simple, you can do this right in your onUpgrade() method.

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

Sidebar

Related Questions

After upgrading from EF 4.2 and Migration to EF 4.3 and enabling migration,restarting Visual
I'm trying to deploy an application to Heroku after upgrading to Rails 3.1 with
Are there any common reasons why upgrading a database from SQL Server 2000 to
I have a database that I want to add a column to, I changed
I was trying to add the data i receive from some specific messages to
I'm looking for a general solution for upgrading database schema with ORM tools, like
When upgrading MySQL, I first create a backup of the database. Then I will
I'm upgrading a script to a new version with a hole new database layout.
Can anyone give me some idea about uploading data from excel to access database
After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no

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.