Last active
August 29, 2015 14:13
-
-
Save siddug/a29e200faf0b767774e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbManager extends SQLiteOpenHelper{ | |
//Database name | |
private static final String dbName = "sampleData"; | |
private static final Integer version = 1; | |
//initializer | |
public DbManager(Context context) { | |
super(context, dbName, null, version); | |
} | |
//Once database is created, Create a table with columns - id, count, name | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
db.execSQL("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, count INTEGER, name TEXT);"); | |
} | |
//Changing the version number in the database initialization calls for an upgrade of database. Drop or delete exisiting tables and create new one's | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) { | |
db.execSQL("DROP TABLE IF EXISTS test"); | |
onCreate(db); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment