-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDatabase.java
57 lines (47 loc) · 1.96 KB
/
AppDatabase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.sachet.database2;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class AppDatabase extends SQLiteOpenHelper {
private static final String TAG = "AppDatabase";
public static final String DATABASE_NAME = "TaskTimer.db";
public static final int DATABASE_VERSION = 1;
private static AppDatabase instance = null;
private AppDatabase(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Log.d(TAG, "AppDatabase: constructor called ");
}
public static AppDatabase getInstance(Context context){
if(instance == null){
instance = new AppDatabase(context);
Log.d(TAG, "getInstance: creating the singleton instance");
}
return instance;
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG, "onCreate: creating the database ");
String sSql;
// sSql = "CREATE TABLE Tasks(_id INTEGER PRIMARY KEY NOT NULL, Name TEXT NOT NULL, Description TEXT, SortOrder INTEGER);";
sSql = "CREATE TABLE "+TaskContracts.TABLE_NAME+
"( "+TaskContracts.Columns._ID+" INTEGER PRIMARY KEY NOT NULL, "
+TaskContracts.Columns.TASKS_NAME+" TEXT NOT NULL, "
+TaskContracts.Columns.TASKS_DESCRIPTION+" TEXT, "
+TaskContracts.Columns.TASKS_SORTORDER+" INTEGER"+
" );";
db.execSQL(sSql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(TAG, "onUpgrade: starts");
switch (oldVersion){
case 1:
//update logic from version 1
break;
default:
throw new IllegalStateException("OnUpgrade called with unknown new version "+newVersion);
}
Log.d(TAG, "onUpgrade: finished");
}
}