Search code examples
androidsqliteormlitegreendao

How to dynamically create table in database using greendao or ORMLite?


How to dynamically create table in database using greendao or ORMLite? I want to create new table in database when user pressed button, for each new table in database, data model is same but I need table with diffrent name. Is that possible ?


Solution

  • Concerning greendao:

    It's not possible to dynamically create a new table. With greendao the code for handling your database is created on your development station by a J2SE-Application (using the daogenerator).

    Concerning Ormlite:

    I haven't been using Ormlite until now, but I doupt that generating new tables at runtime is possible.

    Conclusion:

    IMHO a database design, where you have to create new tables at runtime is bad practice, because you won't beable to benefit from ORM-frameworks. A design like that is also very difficult to maintain (if not impossible) and/or to test. On top of that a design like that may be difficult to understand for other developers as it is really uncommon. Thus you should redesign your database schema.