제목처럼 하는 이유는 drawerLayout에서 서랍장에 항목1 항목2 에 따라서 사용하는 table이 다르기 때문입니다.
그런데 현재는 table을 2개 만들어서 설정해놨음에도 항목1과 항목2가 분리되지 않고, 동일하게 insert/update/delete가 되고 있습니다.
여러 방법으로 테스트해봤으나, 방법을 모르겠어서 adapter 부분 소스가 잘못된건지 고수님들이 확인 좀 해주셨으면 해서 질문드립니다.
부탁드리겠습니다...
감사합니다!
public class NotesDbAdapter {
public static final String KEY_TITLE = "title";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";
private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_NAME = "data";
private static final int DATABASE_VERSION = 3;
private final Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table notes (_id integer primary key autoincrement, "
+ "title text not null, body text not null);");
db.execSQL("create table notes1 (_id integer primary key autoincrement, "
+ "title text not null, body text not null);");
}
@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 notes");
db.execSQL("DROP TABLE IF EXISTS notes1");
onCreate(db);
}
}
public NotesDbAdapter(Context ctx) {
this.mCtx = ctx;
}
public NotesDbAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
public long createNote(String title, String body) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_BODY, body);
return mDb.insert("notes", null, initialValues);
}
public long createNote1(String title, String body) {
ContentValues initialValues1 = new ContentValues();
initialValues1.put(KEY_TITLE, title);
initialValues1.put(KEY_BODY, body);
return mDb.insert("notes1", null, initialValues1);
}
public boolean deleteNote(long rowId) {
return mDb.delete("notes", KEY_ROWID + "=" + rowId, null) > 0;
}
public boolean deleteNote1(long rowId) {
return mDb.delete("notes1", KEY_ROWID + "=" + rowId, null) > 0;
}
public Cursor fetchAllNotes() {
return mDb.query("notes",
new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY }, null, null,
null, null, null);
}
public Cursor fetchAllNotes1() {
return mDb.query("notes1", new String[] { KEY_ROWID, KEY_TITLE,
KEY_BODY }, null, null, null, null, null);
}
public Cursor fetchNote(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, "notes",
new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY }, KEY_ROWID
+ "=" + rowId, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public Cursor fetchNote1(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, "notes1",
new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY }, KEY_ROWID
+ "=" + rowId, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public boolean updateNote(long rowId, String title, String body) {
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
args.put(KEY_BODY, body);
return mDb.update("notes", args, KEY_ROWID + "=" + rowId, null) > 0;
}
public boolean updateNote1(long rowId, String title, String body) {
ContentValues args1 = new ContentValues();
args1.put(KEY_TITLE, title);
args1.put(KEY_BODY, body);
return mDb.update("notes1", args1, KEY_ROWID + "=" + rowId, null) > 0;
}
}