Blame view

partieAndroid/codesJava/StringSQLite.java 3.14 KB
b8e00f52   martin.rohmer   mise à dispositio...
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  package com.example.martin.projetv5;

  

  import android.content.Context;

  import android.database.sqlite.SQLiteDatabase;

  import android.database.sqlite.SQLiteOpenHelper;

  

  /**

   * Created by martin on 21/02/2017.

   */

  

  public class StringSQLite extends SQLiteOpenHelper {

      private static final int VERSION_BDD = 1;

      private static final String NOM_BDD = "evenements.db";

      private static StringSQLite sInstance;

  

      private static final String TABLE_EVENTS = "table_events";

      private static final String TABLE_PRISES = "table_prises";

      private static final String TABLE_MEDOCS = "table_medocs";

  

      private static final String COL_ID_EV = "ID_ev";

      private static final String COL_DATE = "Date";

      private static final String COL_HEURE_EV = "Heure_ev";

      private static final String COL_EVENT = "Event";

  

      private static final String COL_ID_P = "ID_prise";

      private static final String COL_MEDOC = "Medoc";

      private static final String COL_HEURE = "Heure";

      private static final String COL_BOOL = "Bool";

  

      private static final String COL_ID_M = "ID_medoc";

      private static final String COL_NOM1 = "Nom1";

      private static final String COL_NOM2 = "Nom2";

      private static final String COL_POSO = "Posologies";

      private static final String COL_INFOS = "Indications";

      private static final String COL_LOGO = "Logo";

  

      private static final String CREATE_BDD = "CREATE TABLE " + TABLE_EVENTS + " ("

              + COL_ID_EV + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_DATE + " TEXT NOT NULL, "

              + COL_HEURE_EV + " TEXT NOT NULL, " + COL_EVENT + " TEXT NOT NULL);";

  

      private static final String CREATE_BDD_PRISES = "CREATE TABLE " + TABLE_PRISES + " ("

              + COL_ID_P + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_MEDOC + " TEXT NOT NULL, "

              + COL_HEURE + " TEXT NOT NULL, " + COL_BOOL + " TEXT NOT NULL);";

  

      private static final String CREATE_BDD_MEDOCS = "CREATE TABLE " + TABLE_MEDOCS + " ("

              + COL_ID_M + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_NOM1 + " TEXT NOT NULL, "

              + COL_NOM2 + " TEXT NOT NULL, " + COL_POSO + " TEXT NOT NULL, " + COL_INFOS + " TEXT NOT NULL, "

              + COL_LOGO + " TEXT NOT NULL);";

  

      public static synchronized StringSQLite getInstance(Context context){

          if(sInstance == null){sInstance = new StringSQLite(context);}

          return sInstance;

      }

  

      public StringSQLite(Context context){

          super(context, NOM_BDD, null, VERSION_BDD);

      }

  

      @Override

      public void onCreate(SQLiteDatabase db) {

          //on crée la table à partir de la requête écrite dans la variable CREATE_BDD

          db.execSQL(CREATE_BDD);

          db.execSQL(CREATE_BDD_PRISES);

          db.execSQL(CREATE_BDD_MEDOCS);

      }

  

      @Override

      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

          //On supprime la table puis la recrée afin de faire repartir les id à 0

          db.execSQL("DROP TABLE " + TABLE_EVENTS + ";");

          db.execSQL("DROP TABLE " + TABLE_PRISES + ";");

          db.execSQL("DROP TABLE " + TABLE_MEDOCS + ";");

          onCreate(db);

      }

  }