2 * Copyright 2014 Gustavo Martin Morcuende
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package name.gumartinm.weather.information.model;
18 import android.content.Context;
19 import android.database.sqlite.SQLiteDatabase;
20 import android.database.sqlite.SQLiteOpenHelper;
21 import android.util.Log;
23 public class WeatherLocationDbHelper extends SQLiteOpenHelper {
24 private static final String TAG = "LocationDbHelper";
25 public static final int DATABASE_VERSION = 1;
26 public static final String DATABASE_NAME = "Location.db";
28 public WeatherLocationDbHelper(final Context context) {
29 super(context, DATABASE_NAME, null, DATABASE_VERSION);
33 public void onCreate(final SQLiteDatabase db) {
34 db.execSQL("CREATE TABLE " + WeatherLocationContract.WeatherLocation.TABLE_NAME + " ("
35 + WeatherLocationContract.WeatherLocation._ID + " INTEGER PRIMARY KEY, "
36 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_CITY + " TEXT" + " NOT NULL, "
37 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_COUNTRY + " TEXT" + " NOT NULL, "
38 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_IS_SELECTED + " INTEGER" + " NOT NULL, "
39 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LAST_CURRENT_UI_UPDATE + " INTEGER, "
40 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LAST_FORECAST_UI_UPDATE + " INTEGER, "
41 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LATITUDE + " REAL" + " NOT NULL, "
42 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_LONGITUDE + " REAL" + " NOT NULL, "
43 + WeatherLocationContract.WeatherLocation.COLUMN_NAME_IS_NEW + " INTEGER" + " NOT NULL "
48 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
49 Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
50 + newVersion + ", which will destroy all old data");
52 // Kills the table and existing data
53 db.execSQL("DROP TABLE IF EXISTS " + WeatherLocationContract.WeatherLocation.TABLE_NAME);
55 // Recreates the database with a new version