69e10f5ed913a5a35a44fde27eae9f91155b656d
[JavaForFun] /
1 package com.weather.information.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                 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_IS_NEW + " INTEGER" + " NOT NULL "
29                                 + ");");
30         }
31
32         @Override
33         public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
34         Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
35                 + newVersion + ", which will destroy all old data");
36
37         // Kills the table and existing data
38         db.execSQL("DROP TABLE IF EXISTS " + WeatherLocationContract.WeatherLocation.TABLE_NAME);
39
40         // Recreates the database with a new version
41         onCreate(db);
42         }
43
44 }