0

I have an app published in the play store.

The app uses a database which holds a table which has a column of type int.

I'm doing a new change where I need to change the column type to long.

How do I go about handling it in the DatabaseHandler I'v created.

I want to preserve the data stored in the older apps database, so what should ideally be the code in the onUpgrade() function???

Prathamesh Shetye
  • 915
  • 2
  • 8
  • 27

3 Answers3

3

You don't need to change the database column type. An INTEGER column will happily contain all the bits needed to represent a Java long.

In fact, there's no long column type in sqlite.

laalto
  • 150,114
  • 66
  • 286
  • 303
  • I also have the same problem, but I need to change the column type from VARCHAR to BOOL. How to convert the existing data stored as VARCHAR to BOOL. – Madhan Jan 31 '17 at 05:54
  • @Iaalto: I have the database in the assets folder. In the database, I have a column named “type” which is of data type “Varchar”. I need to release an update for my app. In the new version, I need to change the data type of the column “type” from “Varchar” to “Integer”. If I change it to “Integer”, what happens to the existing data in the “type” column which are already stored as “Varchar”. Will I need to write any migration code? If yes, how to do that. – Madhan Jan 31 '17 at 11:00
1

I think using SQLite, the best way is to create a temporary table, copy all your table content, drop the old table and recreate the table with the right type on your column, then you can just copy the content from the temporary table and drop it...

I know this don't fell like the best approach, but I don't think SQLite have some alter table function.

GhostDerfel
  • 1,533
  • 1
  • 11
  • 18
0

As far I know you can t do this . But You can drop your table if it exists and create it again . Maybe you can find out some useful information here SQLite Modify Column or here Modify a Column's Type in sqlite3

Community
  • 1
  • 1
Raluca Lucaci
  • 2,058
  • 3
  • 20
  • 37