このクラスはテーブルを作成します。このクラスを編集して必須フィールドを作成できます。
public class TableCreater extends SQLiteOpenHelper
{
public static final String DATABASE_NAME = "userregister.db";
public static final int VERSION = 1;
public static final String TABLE_NAME = "USER_SESSION";
public static final String COLUMN_ID = "_id";
public static final String USER_ID = "user_id";
public static final String TABLE_CREATE =
"create table " + TABLE_NAME + " (" + COLUMN_ID
+ " integer primary key autoincrement," + USER_ID + " integer);";
public static final String FIRST_QUERY = "insert into " + TABLE_NAME
+ " (user_id) values(0);";
public loginchecker(Context context) {
super(context, DATABASE_NAME, null, VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
db.execSQL(FIRST_QUERY);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(loginchecker.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
このメソッドは、テーブル内のデータを更新します..必要に応じて編集できます
public InsertingClass InsertID(int uid)
{
ContentValues values = new ContentValues();
values.put(loginchecker.USER_ID, uid);
long insertedId = database.insert(loginchecker.TABLE_NAME, null,
values);
Cursor cursor = database.query(loginchecker.TABLE_NAME, allColumnsLogin,
loginchecker.COLUMN_ID + " = " + insertedId, null, null,
null, null);
cursor.moveToFirst();
return cursorToModel(cursor);
}