· 8 years ago · Apr 09, 2018, 06:28 AM
1package com.examples;
2
3import com.act.ActPage2_Input.UserSchema1;
4import com.mc.McPage1.UserSchema;
5import com.thing.Things2.UserSchema2;
6
7import android.content.Context;
8import android.database.Cursor;
9import android.database.sqlite.SQLiteDatabase;
10import android.database.sqlite.SQLiteOpenHelper;
11
12public class SQLiteDB extends SQLiteOpenHelper {
13 private static final String DB_NAME = "CalendarDB.db" ;
14 private static final int DB_VERSION = 1 ;
15
16 private SQLiteDatabase db;
17 public SQLiteDB(Context context) {
18 super(context, DB_NAME, null, DB_VERSION);
19 db = this.getWritableDatabase();
20 // TODO Auto-generated constructor stub
21 }
22
23
24
25 @Override
26 public void onCreate(SQLiteDatabase arg0) {
27 // TODO Auto-generated method stub
28 String MensesDB = "CREATE TABLE " + UserSchema.TABLE_NAME + " ("
29 + UserSchema.ID + " INTEGER primary key autoincrement, "
30 + UserSchema.DATE_END + " text not null, "
31 + UserSchema.DAY + " INTEGER not null, "
32 + UserSchema.DATE_START + " text not null "+ ");";
33 arg0.execSQL(MensesDB);
34
35 String AccountDB = "CREATE TABLE " + UserSchema1.TABLE_NAME + " ("
36 + UserSchema1.ID1 + " INTEGER primary key autoincrement, "
37 + UserSchema1.Thing1 + " text not null, "
38 + UserSchema1.Thing2 + " text not null, "
39 + UserSchema1.Thing3 + " text not null, "
40 + UserSchema1.Money + " INTEGER not null "+ ");";
41 //Log.i("haiyang:createDB=", sql);
42 arg0.execSQL(AccountDB);
43
44 String ThingDB = "CREATE TABLE " + UserSchema2.TABLE_NAME + " ("
45 + UserSchema2.ID + " INTEGER primary key autoincrement, "
46 + UserSchema2.DUE + " text , "
47 + UserSchema2.NATIFI + " text , "
48 + UserSchema2.TITLE + " text not null, "
49 + UserSchema2.CONTENT + " text not null "+ ");";
50 //Log.i("haiyang:createDB=", sql);
51 arg0.execSQL(ThingDB);
52
53 //arg0.execSQL(DiaryDB);
54 //arg0.execSQL(PasswordDB);
55 //arg0.execSQL(BackDB);
56 }
57
58 @Override
59 public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
60 // TODO Auto-generated method stub
61 arg0.execSQL("DROP TABLE IF EXISTS config");
62 onCreate(arg0);
63 }
64
65 @Override
66 public void onOpen(SQLiteDatabase arg0)
67 {
68 super.onOpen(arg0);
69 // TODO æ¯æ¬¡æˆåŠŸæ‰“å¼€æ•°æ®åº“åŽé¦–先被执行
70 }
71 public Cursor getAll() {
72 return db.query(UserSchema2.TABLE_NAME, //資料表å稱
73 new String[] {UserSchema2.ID, UserSchema2.DUE, UserSchema2.NATIFI, UserSchema2.TITLE, UserSchema2.CONTENT}, //欄ä½å稱
74 null, // WHERE
75 null, // WHERE çš„åƒæ•¸
76 null, // GROUP BY
77 null, // HAVING
78 null // ORDOR BY
79 );
80 }
81 public int delete(long rowId) {
82 return db.delete(UserSchema2.TABLE_NAME, //資料表å稱
83 UserSchema2.ID + "=" + rowId, //WHERE
84 null //WHEREçš„åƒæ•¸
85 );
86 }
87
88
89}