1 package de.example.exampletdd.model;
3 import android.content.Context;
4 import android.database.sqlite.SQLiteDatabase;
5 import android.database.sqlite.SQLiteOpenHelper;
6 import android.util.Log;
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";
13 public WeatherLocationDbHelper(final Context context) {
14 super(context, DATABASE_NAME, null, DATABASE_VERSION);
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 "
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");
36 // Kills the table and existing data
37 db.execSQL("DROP TABLE IF EXISTS " + WeatherLocationContract.WeatherLocation.TABLE_NAME);
39 // Recreates the database with a new version