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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:44:49+00:00 2026-06-08T00:44:49+00:00

I am using a class to extend SQLiteOpenHelper as follow: public class PocketSQLite extends

  • 0

I am using a class to extend SQLiteOpenHelper as follow:

public class PocketSQLite extends SQLiteOpenHelper {
    public String TableNames[];
    public String FieldNames[][];
    public String FieldTypes[][];
    public static String NO_CREATE_TABLES = "no tables";
    private String message = "";

    public PocketSQLite(Context context, String name, CursorFactory factory, int version, String tableNames[], String fieldNames[][], String fieldTypes[][]) {
        super(context, name, factory, version);
        TableNames = tableNames;
        FieldNames = fieldNames;
        FieldTypes = fieldTypes;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        if (TableNames == null) {
            message = NO_CREATE_TABLES;
            return;
        }

        for (int i = 0; i < TableNames.length; i++) {
            String sql = "CREATE TABLE " + TableNames[i] + "(";
            for (int j = 0; j < FieldNames[i].length; j++)
                sql += FieldNames[i][j] + " " + FieldTypes[i][j] + ",";
            sql = sql.substring(0, sql.length() - 1);
            sql += ")";
            db.execSQL(sql);
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        for (int i = 0; i < TableNames[i].length(); i++) {
            String sql = "DROP TABLE IF EXISTS " + TableNames[i];
            db.execSQL(sql);
        }
        onCreate(db);
    }
}

As you see, the constructor will enter the fields of table. How can I update the onUpgrade function to add a new field to exist table?

For example:

Old Table(2 Fields): “Name”, “Phone”

New Table(3 Fields): “Name”, “Phone”, “Email”

  • 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-08T00:44:50+00:00Added an answer on June 8, 2026 at 12:44 am

    First, You need to change the Database version, when you make such a structural change. And then, in the upgrade method, write your sql statements, which would modify your tables.

    When you run your app next time, the onUpgrade method would be called, and your sql statement would be executed, which will modify your table.

    http://www.w3schools.com/sql/sql_alter.asp

    You can drop the table as well, but as you said, you will lose the existing data.

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

Sidebar

Related Questions

The code I am using is: public class Test extends JFrame implements ActionListener {
I am using Expandable ListView example found on net Activity: public class ExpandableListViewActivity extends
i am using following code. public class MyCount extends CountDownTimer { public MyCount(long millisInFuture,
I'm using CakeDC-Users plugin. <?php class Post extends AppModel { public $useTable='posts'; public $belongsTo
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected
I am creating a database in android using this code: public class PackageDBHelper extends
i am using a class which extends Handler class to update my activity UI.
I'm using a custom class that extends JFrame, but sometimes it shows nothing. I
I'm using my own class for database queries, extending mysqli: class iDatabase extends mysqli
I am using the following code class AddTask extends AsyncTask<Void, Void, Void> { ProgressDialog

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.