3 comments on “SQLite DROP COLUMN support

  1. The SQLite documentation on this is wrong. Sure you’ll get a new table without the column, but you’ll also lose all indexes (including the primary key index), any features like autoincrement, and foreign key references, which means performance of the new table will be pretty awful and the table itself might be broken. SQLite itself should emulate this feature (even if it takes forever on large tables) because the existing “solution” in the documentation doesn’t work.

    I originally found your code on StackOverflow. The “correct” way using this approach is probably more trouble than it is worth – rebuild an entire CREATE TABLE statement from the ground up without the column(s) being dropped while maintaining indexes and foreign key constraint information. Ugh.

    I’m not saying your solution is bad, just that those using it need to be aware of the limitations.

    • You are right, and I don’t think it’s “more trouble than it is worth”.

      Most SQLite DBs don’t use many indexes and FK due to their simplicity, but a generic solution should be made for all cases.

      I don’t know if I’ll have time to get to that in the near future, so any code suggestions are welcome.

  2. The getTableColumns code appears to use a “name” string out of the blue.

    But anyway, you don’t need to build the array manually using a loop, you can just use:

    Cursor cur = db.query(TABLE_NAME, null, null, null, null, null, null);
    String[] names = cur.getColumnNames();
    cur.close();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s