80835162211b0d56c06b0736a0ee0964b9ab7dc0
[JavaForFun] /
1 package de.example.exampletdd.model;
2
3 import android.content.Context;
4 import android.database.sqlite.SQLiteDatabase;
5 import android.database.sqlite.SQLiteOpenHelper;
6 import android.util.Log;
7
8 public class WeatherLocationDbHelper extends SQLiteOpenHelper {
9         private static final String TAG = "LocationDbHelper";
10         public static final int DATABASE_VERSION = 1;
11     public static final String DATABASE_NAME = "Location.db";
12     
13     public WeatherLocationDbHelper(final Context context) {
14         super(context, DATABASE_NAME, null, DATABASE_VERSION);
15     }
16     
17         @Override
18         public void onCreate(final SQLiteDatabase db) {
19                 db.execSQL("CREATE TABLE " + WeatherLocationContract.WeatherLocation.TABLE_NAME + " ("
20                                 + WeatherLocationContract.WeatherLocation._ID + " INTEGER PRIMARY KEY, "
21                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_CITY + " TEXT" + " NOT NULL, "
22                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_COUNTRY + " TEXT" + " NOT NULL, "
23                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_IS_SELECTED + " INTEGER" + " NOT NULL, "
24                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LAST_CURRENT_UI_UPDATE + " INTEGER, "
25                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LAST_FORECAST_UI_UPDATE + " INTEGER, "
26                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LATITUDE + " REAL" + " NOT NULL, "
27                                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LONGITUDE + " REAL" + " NOT NULL "
28                                 + ");");
29         }
30
31         @Override
32         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
33         Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
34                 + newVersion + ", which will destroy all old data");
35
36         // Kills the table and existing data
37         db.execSQL("DROP TABLE IF EXISTS " + WeatherLocationContract.WeatherLocation.TABLE_NAME);
38
39         // Recreates the database with a new version
40         onCreate(db);
41         }
42
43 }