分类: SQLite/嵌入式数据库
2011-10-09 16:28:43
public class DBAdapter
{
public static final String KEY_ROWID = "_id";
public static final String KEY_BOB = "bob";
public static final String KEY_X = "xx";
public static final String KEY_Y = "yy";
private static final String TAG = "xxx";
private static final String DATABASE_NAME = "sprite";
private static final String DATABASE_TABLE = "bob";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table "+DATABASE_TABLE +
"(_id integer primary key autoincrement,"+
"bob text not null,"+
"xx float not null,"+
"yy float not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
//@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
//@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion)
{
Log.w(TAG,"Upgrading database from version "+oldVersion+" to "
+newVersion+", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS titles");
onCreate(db);
}
}