-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dca2593
commit a827fcd
Showing
7 changed files
with
230 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/example/android/pets/data/PetContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.android.pets.data; | ||
|
||
import android.provider.BaseColumns; | ||
|
||
public final class PetContract | ||
{ | ||
private PetContract() {} | ||
|
||
public static final class PetEntry implements BaseColumns | ||
{ | ||
public static final String TABLE_NAME = "pets"; | ||
|
||
public static final String _ID = BaseColumns._ID; | ||
public static final String COLUMN_PET_NAME = "name"; | ||
public static final String COLUMN_PET_BREED = "breed"; | ||
public static final String COLUMN_PET_GENDER = "gender"; | ||
public static final String COLUMN_PET_WEIGHT = "weight"; | ||
|
||
public static final int GENDER_MALE = 1; | ||
public static final int GENDER_FEMALE = 2; | ||
public static final int GENDER_UNKNOWN = 0; | ||
|
||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/example/android/pets/data/PetDbHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.example.android.pets.data; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
import android.util.Log; | ||
|
||
import com.example.android.pets.data.PetContract.*; | ||
|
||
public class PetDbHelper extends SQLiteOpenHelper | ||
{ | ||
private static final int DATABASE_VERSION = 1; | ||
private static final String DATABASE_NAME = "shelter.db"; | ||
|
||
public PetDbHelper(Context context) | ||
{ | ||
super(context, DATABASE_NAME, null, DATABASE_VERSION); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
// db.execSQL(DELETE_ALL_ENTRIES); | ||
// onCreate(db); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) | ||
{ | ||
String SQL_CREATE_ENTRIES = "CREATE TABLE "+ PetEntry.TABLE_NAME +" (" | ||
+ PetEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " | ||
+ PetEntry.COLUMN_PET_NAME + " TEXT NOT NULL ," | ||
+ PetEntry.COLUMN_PET_BREED+ " TEXT," | ||
+ PetEntry.COLUMN_PET_GENDER+ " INTEGER NOT NULL ," | ||
+PetEntry.COLUMN_PET_WEIGHT+ " INTEGER NOT NULL DEFAULT 0" | ||
+ ");"; | ||
Log.d("In onCreate", SQL_CREATE_ENTRIES); | ||
db.execSQL(SQL_CREATE_ENTRIES); | ||
} | ||
|
||
|
||
|
||
public static final String DELETE_ALL_ENTRIES = "DROP TABLE IF EXISTS " + PetEntry.TABLE_NAME; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters