Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having several SQLiteOpenhelper in one appli Android

Tags:

android

sqlite

I would like to know if it is possible to have several DbOpenHelper in the same app Android but to use them to write and read in the same database? because I'm trying to create tables from 2 different OpenHelper (with different names) and only the first one seems to create. when I try to run the 2nd one, i get an error...

like image 939
Sephy Avatar asked Feb 11 '10 14:02

Sephy


2 Answers

Looks like You can't have more than one helper for each DB. Here's explained why: http://blog.foxxtrot.net/2009/01/a-sqliteopenhelper-is-not-a-sqlitetablehelper.html

like image 126
matekm Avatar answered Nov 15 '22 07:11

matekm


Add the TABLE_CREATE statement to onOpen(SQLiteDatabase db) to ensure that the second table gets created in case the database connection is already opened. Further, the TABLE_CREATE statement should include IF NOT EXIST in case the table already exists.

Reference: http://jiahaoliuliu.wordpress.com/2011/09/26/sqlite-create-multiple-tables-with-different-sqliteopenhelper-in-the-same-database/

like image 43
JJD Avatar answered Nov 15 '22 08:11

JJD