The idea is, that a Contract
class is an abstraction of the database, So, in MatchContract
you will have all the global variables of the database and in the inner class, MatchEntry
you will implement the abstraction of the database itself (columns etc). Then, with MatchDBHelper
you will be managing the database (Creating it, upgrading it etc) And writing SQL entries.
As I said in the comments, You need to create the helper class as a normal class, not an inner class:
public class MatchContract {
public MatchContract() {
}
/// Global variables for the DB
public static abstract class MatchEntry implements BaseColumns {
// Structure of the database
}
}
public class MatchDBHelper extends SQLiteOpenHelper {
// Manage the database
}
As a complete example:
public final class PersonContract {
public PersonContract() {
}
public static abstract class PersonEntry implements BaseColumns{
public static final String TABLE_NAME = "person";
public static final String COLUMN_NAME_ENTRY_ID = "personID";
public static final String COLUMN_NAME_FIRST_NAME = "firstname";
public static final String COLUMN_NAME_SECOND_NAME = "secondname";
}
}
public class PersonDbBHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "Persons.db";
private static final String TEXT_TYPE = " TEXT";
private static final String COMMA_SEP = ",";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + PersonEntry.TABLE_NAME + " (" +
PersonEntry._ID + " INTEGER PRIMARY KEY," + // Heredado de BaseColumns
PersonEntry.COLUMN_NAME_ENTRY_ID + TEXT_TYPE + COMMA_SEP +
PersonEntry.COLUMN_NAME_FIRST_NAME + TEXT_TYPE + COMMA_SEP +
PersonEntry.COLUMN_NAME_SECOND_NAME + TEXT_TYPE +
" )";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + PersonEntry.TABLE_NAME;
public PersonDbBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DELETE_ENTRIES);
onCreate(db);
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}