How to Upgrade my Database with a New table without losing the First Table in the SAme Database.

1,529 views
Skip to first unread message

anuj mukul

unread,
Mar 14, 2012, 3:39:05 AM3/14/12
to gree...@googlegroups.com
Hi there,

Actually I am trying to create a new table in the Already existing Database which has a Table existing in it, I want to add a new Table in the Same Database without even touching the First Table, can you help me as to where I need to make changes in the Green Dao Sample to Achieve this?

Thanks

Markus Junginger

unread,
Mar 16, 2012, 6:11:52 PM3/16/12
to gree...@googlegroups.com
Currently, there is no special support for updating database schema. You have to do it with standard SQLiteOpenHelper means.

Related to this, there might be a possibility for automatism in the future: see https://github.com/greenrobot/greenDAO/issues/27. Any thoughts on this? Did I miss some problems?

Markus

rick

unread,
Mar 22, 2012, 3:03:48 PM3/22/12
to gree...@googlegroups.com
Looking at the DaoMaster class, couldn't I create a new class that extends the OpenHelper class and override the onUpgrade method.

In this override, instead of simply dropping every table (as in the DevOpenHelper), we could add a step to create and migrate all data to temp tables.  Then do the drop, and create using greenDAOs methods.  Then add queries to migrate the data from the temp tables back to the newly created schema?

Markus Junginger

unread,
Mar 22, 2012, 4:37:16 PM3/22/12
to gree...@googlegroups.com
Looking at the DaoMaster class, couldn't I create a new class that extends the OpenHelper class and override the onUpgrade method.
Yes, that's how it's meant to be.
 
In this override, instead of simply dropping every table (as in the DevOpenHelper), we could add a step to create and migrate all data to temp tables.  Then do the drop, and create using greenDAOs methods.  Then add queries to migrate the data from the temp tables back to the newly created schema?
If ALTER TABLE is not sufficient for your purpose, you could do that.

Markus
Reply all
Reply to author
Forward
0 new messages