Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
StreetGuardian/CrimeDBHelper.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (42 sloc)
2.06 KB
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
package com.example.datatest.Data; | |
import android.content.Context; | |
import android.database.Cursor; | |
import android.database.SQLException; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
public class CrimeDBHelper extends SQLiteOpenHelper | |
{ | |
// If you change the database schema you must increment the database version | |
public static final int DATABASE_VERSION = 1; | |
public static final String DATABASE_NAME = "CrimeData.db"; | |
//SQL Statement to create table | |
private static final String SQL_CREATE_TABLE = "CREATE TABLE " + CrimeContract.TABLE_NAME + " (" + | |
CrimeContract.COLUMN_ID + "INTEGER PRIMARY KEY AUTOINCREMENT," + | |
CrimeContract.COLUMN_CRIME_TYPE + "TEXT NOT NULL," + | |
CrimeContract.COLUMN_DAY + "INTEGER CHECK (" + CrimeContract.COLUMN_DAY + " > 0 AND " + CrimeContract.COLUMN_DAY + " < 32)," + | |
CrimeContract.COLUMN_MONTH + "INTEGER NOT NULL CHECK (" + CrimeContract.COLUMN_MONTH + " > 0 AND " + CrimeContract.COLUMN_MONTH + " < 13)," + | |
CrimeContract.COLUMN_YEAR + "INTEGER NOT NULL CHECK (" + CrimeContract.COLUMN_YEAR + ">= 2018)," + | |
CrimeContract.COLUMN_ROAD + "TEXT NOT NULL," + | |
CrimeContract.COLUMN_LONGITUDE + "REAL(8,6)," + | |
CrimeContract.COLUMN_LATITUDE + "REAL(8,6)," + | |
CrimeContract.COLUMN_REPORTED_BY + "TEXT NOT NULL)"; | |
//SQL Statement to drop the table | |
private static final String SQL_DELETE_TABLE = "DROP TABLE IF EXISTS " + CrimeContract.TABLE_NAME; | |
public CrimeDBHelper(Context context) | |
{ | |
super(context, DATABASE_NAME, null, DATABASE_VERSION); | |
} | |
public void onCreate(SQLiteDatabase db) | |
{ | |
db.execSQL(SQL_CREATE_TABLE); | |
} | |
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) | |
{ | |
db.execSQL(SQL_DELETE_TABLE); | |
onCreate(db); | |
} | |
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) | |
{ | |
onUpgrade(db, oldVersion, newVersion); | |
} | |
} |