· 10 years ago · Sep 07, 2016, 11:50 AM
1public class QuizHelper extends SQLiteOpenHelper {
2
3 private static final int DATABASE_VERSION = 1;
4 private static final String DATABASE_NAME = "creativequestion";
5 private static final String TABLE_QUEST = "quest";
6 private static final String KEY_ID = "qid";
7 private static final String KEY_QUEST = "question";
8
9 private SQLiteDatabase dbase;
10
11
12
13 public QuizHelper(Context context) {
14 super( context, DATABASE_NAME, null, DATABASE_VERSION );
15 }
16
17 @Override
18 public void onCreate(SQLiteDatabase db) {
19 dbase = db;
20 String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST + " ( " + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUEST + " TEXT)";
21 db.execSQL( sql );
22 addQuestion();
23
24
25 }
26
27 private void addQuestion() {
28
29 QuestionFaci q1 = new QuestionFaci( "OTHER USES: Name other uses of a Hammer. nn Example: Stir a soup." );
30 this.addQuestion(q1);
31 QuestionFaci q2 = new QuestionFaci( "RHYMES: Words that rhymes with Rice. nn Example: Ice" );
32 this.addQuestion(q2);
33 QuestionFaci q3 = new QuestionFaci( "WITH: I can cook eggs with... nn Example: A Piece of Plywood" );
34 this.addQuestion(q3);
35 QuestionFaci q4 = new QuestionFaci( "WITHOUT: I can wash my clothes without... nn Example: My Aunt" );
36 this.addQuestion(q4);
37 QuestionFaci q5 = new QuestionFaci( "I WILL: If I was Bill Gates, I will... nn Example: Buy a spaceship" );
38 this.addQuestion(q5);
39 QuestionFaci q6 = new QuestionFaci( "CREATE A MOVIE TITLE: A NIGHT nn Example: To Remember" );
40 this.addQuestion(q6);
41 QuestionFaci q7 = new QuestionFaci( "OTHER NAMES: Other names of a cow nn Example: Milk giver" );
42 this.addQuestion(q7);
43 QuestionFaci q8 = new QuestionFaci( "OTHER USES: Name other uses of a Cowboy Boots. nn Example: Pound a nail." );
44 this.addQuestion(q8);
45 QuestionFaci q9 = new QuestionFaci( "RHYMES: Bake a. nn Example: Flake." );
46 this.addQuestion(q9);
47 QuestionFaci q10 = new QuestionFaci( "I WILL: I will drive a helicopter nn Example: with eyes closed" );
48 this.addQuestion(q10);
49 QuestionFaci q11 = new QuestionFaci( "CREATE A TITLE: The Greatest nn Example: Heist" );
50 this.addQuestion(q11);
51 QuestionFaci q12 = new QuestionFaci( "CHANGE AN INGREDIENT: --- Cookie nn Example: Orange Chip" );
52 this.addQuestion(q12);
53 QuestionFaci q13 = new QuestionFaci( "FINISH ME: Can you remember the times when.. nn Example: push me over a cliff" );
54 this.addQuestion(q13);
55 QuestionFaci q14 = new QuestionFaci( "OTHER NAMES: Ball bearings nn Example: Mommy's new bangles" );
56 this.addQuestion(q14);
57 QuestionFaci q15 = new QuestionFaci( "FINISH ME: The donut rolls nn Example: down the hill" );
58 this.addQuestion(q15);
59 QuestionFaci q16 = new QuestionFaci( "RHYMES: Flip the nn Example: clip" );
60 this.addQuestion(q16);
61 QuestionFaci q17 = new QuestionFaci( "OTHER NAMES: Police nn Example: civilian peacekeeper" );
62 this.addQuestion(q17);
63 QuestionFaci q18 = new QuestionFaci( "CREATE A TITLE: Go Go nn Example: Changin" );
64 this.addQuestion(q18);
65 QuestionFaci q19 = new QuestionFaci( "I WILL: I will distribute screwdrivers nn Example: to all drivers" );
66 this.addQuestion(q19);
67 QuestionFaci q20 = new QuestionFaci( "CREATE A DISH: Chicken --- Soup nn Example: Dumpling" );
68 this.addQuestion(q20);
69 }
70
71 @Override
72 public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {
73 String upgradeQuery = "ALTER TABLE quest ADD COLUMN question TEXT";
74 if(newV>oldV)
75 db.execSQL( upgradeQuery );
76 onCreate( db );
77
78
79 }
80
81 private void addQuestion(QuestionFaci quest) {
82 ContentValues values = new ContentValues( );
83 values.put(KEY_QUEST, quest.getQUESTION());
84 dbase.insert( TABLE_QUEST, null, values );
85 }
86
87
88 public List<QuestionFaci> getAllQuestions(){
89 List<QuestionFaci> quesList = new ArrayList<QuestionFaci>( );
90 String selectQuery = "SELECT * FROM " + TABLE_QUEST;
91 dbase = this.getReadableDatabase();
92 Cursor cursor = dbase.rawQuery( selectQuery, null );
93 if (cursor.moveToFirst()){
94 do{
95 QuestionFaci quest = new QuestionFaci( );
96 quest.setID( cursor.getInt( 0 ) );
97 quest.setQUESTION( cursor.getString( 1 ) );
98
99 quesList.add(quest);
100 } while (cursor.moveToNext());
101 }
102
103 return quesList;
104
105 }
106}