import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DataBaseHelper extends SQLiteOpenHelper { public static final String TABLE_GPS = "gps"; public static final String COLUMN_ID = "_id"; public static final String COLUMN_LAT = "lat"; public static final String COLUMN_LON = "lon"; public static final String COLUMN_TIME = "timestamp"; public static final String COLUMN_FREQUENCY = "frequency"; public static final String COLUMN_BATTERY_LEVEL = "battery"; public static final String DATABASE_NAME = "gps.db"; private static final int DATABASE_VERSION = 1; // Database creation sql statement private static final String DATABASE_CREATE = "create table " + TABLE_GPS + "(" + COLUMN_ID + " integer primary key autoincrement, " + COLUMN_LAT + " double not null, " + COLUMN_LON + " double not null, " + COLUMN_TIME + " text not null, " + COLUMN_FREQUENCY + " int not null," + COLUMN_BATTERY_LEVEL + " integer default 0);"; public DataBaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase database) { database.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(DataBaseHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_GPS); onCreate(db); } }