Skip to content

Commit

Permalink
Done S07.02-PreventInvaildInserts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina committed Sep 29, 2017
1 parent 787c094 commit 2668bfa
Showing 1 changed file with 12 additions and 9 deletions.
Expand Up @@ -44,7 +44,7 @@ public class WeatherDbHelper extends SQLiteOpenHelper {
* use-case, we wanted to watch out for it and warn you what could happen if you mistakenly
* version your databases.
*/
private static final int DATABASE_VERSION = 1;
private static final int DATABASE_VERSION = 2;

public WeatherDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand Down Expand Up @@ -75,18 +75,18 @@ public void onCreate(SQLiteDatabase sqLiteDatabase) {
*/
WeatherEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +

WeatherEntry.COLUMN_DATE + " INTEGER, " +
WeatherEntry.COLUMN_DATE + " INTEGER NOT NULL, " +

WeatherEntry.COLUMN_WEATHER_ID + " INTEGER, " +
WeatherEntry.COLUMN_WEATHER_ID + " INTEGER NOT NULL, " +

WeatherEntry.COLUMN_MIN_TEMP + " REAL, " +
WeatherEntry.COLUMN_MAX_TEMP + " REAL, " +
WeatherEntry.COLUMN_MIN_TEMP + " REAL NOT NULL, " +
WeatherEntry.COLUMN_MAX_TEMP + " REAL NOT NULL, " +

WeatherEntry.COLUMN_HUMIDITY + " REAL, " +
WeatherEntry.COLUMN_PRESSURE + " REAL, " +
WeatherEntry.COLUMN_HUMIDITY + " REAL NOT NULL, " +
WeatherEntry.COLUMN_PRESSURE + " REAL NOT NULL, " +

WeatherEntry.COLUMN_WIND_SPEED + " REAL, " +
WeatherEntry.COLUMN_DEGREES + " REAL" + ");";
WeatherEntry.COLUMN_WIND_SPEED + " REAL NOT NULL, " +
WeatherEntry.COLUMN_DEGREES + " REAL NOT NULL" + ");";

/*
* After we've spelled out our SQLite table creation statement above, we actually execute
Expand All @@ -110,6 +110,9 @@ public void onCreate(SQLiteDatabase sqLiteDatabase) {
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
// TODO (3) Within onUpgrade, drop the weather table if it exists
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + WeatherEntry.TABLE_NAME);

// TODO (4) call onCreate and pass in the SQLiteDatabase (passed in to onUpgrade)
onCreate(sqLiteDatabase);
}
}

0 comments on commit 2668bfa

Please sign in to comment.