Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.SQLException;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.os.Environment;
- import android.util.Log;
- public class FavBaDbAdapter2 {
- public static final String KEY_ROWID = "rowid _id";
- public static final String KEY_CODE = "word";
- public static final String KEY_NAME = "content";
- public static final String KEY_TIME = "time";
- public static final String KEY_FAVID = "favid";
- private static final String TAG = "ItemsDbAdapter";
- private DatabaseHelper mDbHelper;
- private SQLiteDatabase mDb;
- private static final String DATABASE_NAME = "favtemp";
- private static final String SQLITE_TABLE = "favitems";
- private static final int DATABASE_VERSION = 1;
- private final Context mCtx;
- private static class DatabaseHelper extends SQLiteOpenHelper {
- public DatabaseHelper(final Context context) {
- super(context, Environment.getExternalStorageDirectory()
- + File.separator + "Kadict/fav/"
- + File.separator + DATABASE_NAME, null, DATABASE_VERSION);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- }
- }
- public FavBaDbAdapter2(Context ctx) {
- this.mCtx = ctx;
- }
- public FavBaDbAdapter2 open() throws SQLException {
- mDbHelper = new DatabaseHelper(mCtx);
- mDb = mDbHelper.getWritableDatabase();
- return this;
- }
- public void close() {
- if (mDbHelper != null) {
- mDbHelper.close();
- }
- }
- public long createCountry(String code, String name,
- String time, String favid) {
- ContentValues initialValues = new ContentValues();
- initialValues.put(KEY_CODE, code);
- initialValues.put(KEY_NAME, name);
- initialValues.put(KEY_TIME, time);
- initialValues.put(KEY_FAVID, favid);
- return mDb.insert(SQLITE_TABLE, null, initialValues);
- }
- public boolean deleteAllItems() {
- int doneDelete = 0;
- doneDelete = mDb.delete(SQLITE_TABLE, null , null);
- Log.w(TAG, Integer.toString(doneDelete));
- return doneDelete > 0;
- }
- public Cursor fetchItemsByName(String inputText) throws SQLException {
- Log.w(TAG, inputText);
- Cursor mCursor = null;
- if (inputText == null || inputText.length () == 0) {
- mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
- KEY_CODE, KEY_NAME, KEY_TIME, KEY_FAVID},
- null, null, null, null, null);
- }
- else {
- mCursor = mDb.query(true, SQLITE_TABLE, new String[] {KEY_ROWID,
- KEY_CODE, KEY_NAME, KEY_TIME},
- KEY_CODE + " LIKE ?",
- new String[] { inputText+"%" }, null, null, null,
- null);
- }
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor; //inputText
- }
- public Cursor fetchAllItems() {
- Cursor mCursor = mDb.query(SQLITE_TABLE, new String[] {KEY_ROWID,
- KEY_CODE, KEY_NAME, KEY_TIME, KEY_FAVID},
- null, null, null, null, null);
- if (mCursor != null) {
- mCursor.moveToFirst();
- }
- return mCursor;
- }
- public void insertSomeItems() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement