先建立一个table的基类:
public abstract class DbBaseTable {
private static final String TAG = "DbBaseTable";
/**
* @return the DB table name
*/
abstract String getName();
/**
* Creates the DB table according to the DB scheme
*
* @param db
*/
abstract void onCreate(SQLiteDatabase db);
void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion, String tempName) {
}
void joinColumns(SQLiteDatabase db, String tempName, String tableName) {
DbUtils.joinColumns(db, tempName, tableName);
}
}
我们通过这种方式来建立表:
public final class DataBaseClass {
private DataBaseClass() {};
public static final int DB_VERSION = 2;
static final String DB_FILE = "my.db";
//这里放公共的字段
public interface RCMColumns {
public static final String account_ID = "account_id"; //INTEGER (long)
}
public static final class MyTest1Table extends DbBaseTable implements BaseColumns, RCMColumns {
private MyTest1Table() {
}
private static final MyTest1Table sInstance = new MyTest1Table();
static MyTest1Table getInstance() {
return sInstance;
}