use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.
the class AddWordAsyncTask method doInBackground.
@SuppressLint("SimpleDateFormat")
@Override
protected Boolean doInBackground(Void... params) {
if (mAdding == true) {
return false;
}
mDictionaryDB = new DictionaryDB(mContext, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
SQLiteDatabase sqLiteDatabase = mDictionaryDB.getWritableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery(// 检查是否已经在生词表中存在
"select * from word where word='" + mToAddWord + "' limit 1", null);
Boolean returnResult = false;
if (cursor.getCount() == 0) {
// 检查是否在word中存在
if (QueryProcessor.instance(mContext).getWordID(mToAddWord) == QueryProcessor.MSG_WORD_NOT_EXISIT) {
returnResult = false;
mErrorCode = ERROR_NOT_EXSIST;
} else {
ContentValues contentValues = new ContentValues();
contentValues.put("word", mToAddWord);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String addTime = simpleDateFormat.format(new Date());
contentValues.put("addtime", addTime);
sqLiteDatabase.insert("word", null, contentValues);
returnResult = true;
}
} else {
returnResult = false;
mErrorCode = ERROR_ALREADY_ADDED;
}
sqLiteDatabase.close();
mAddingList.remove(mToAddWord);
return returnResult;
}
use of com.zhan_dui.dictionary.db.DictionaryDB in project little-bear-dictionary by daimajia.
the class OfflineListCursorAdapter method onCheckedChanged.
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String id = buttonView.getContentDescription().toString();
String status = isChecked == true ? "1" : "0";
DictionaryDB dictionaryDB = new DictionaryDB(mContext, DictionaryDB.DB_NAME, null, DictionaryDB.DB_VERSION);
SQLiteDatabase sqLiteDatabase = dictionaryDB.getWritableDatabase();
String[] argsStrings = { status, id };
sqLiteDatabase.execSQL("update `dictionary_list` set `dictionary_show`=? where `_id`=?", argsStrings);
sqLiteDatabase.close();
}
Aggregations