package com.tejia.lijin.app.sqlite; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; import com.wpc.library.util.common.StringUtils; /** * 首页弹框+配置信息 */ public class UserSQHelper { private SQLiteDatabase db; private CustomServiceSQLiteOpenHelper openHelper; public UserSQHelper(Context context) { openHelper = new CustomServiceSQLiteOpenHelper(context); } /** * 查询数据 * * @param id * @return */ public String getShowTime(String id, String Inquire) { if (StringUtils.isEmpty(id)) return ""; db = openHelper.getWritableDatabase();//以读写的方式访问数据库 Cursor cursor = db.rawQuery("select * from user_table where adid=?", new String[]{id}); String t = ""; if (cursor.getCount() != 0) { while (cursor.moveToNext()) { //遍历数据库 t = cursor.getString(cursor.getColumnIndex(Inquire)); } } cursor.close();//关闭cursor db.close();// 关闭数据库 Log.e("eee", "getShowTime: " + t); return t; } // /** // * 设置数据 // * // * @param id // * @param time // */ // public boolean setShowTime(String id, String time) { // if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time)) // return false; // boolean b = true; // //更具ID查询有这条数据 // if (getShowTime(id) != null && getShowTime(id).length() > 0) { // b = update(id, time);//更新信息 // } else { // b = insert(id, time);//插入数据 // } // return b; // } /** * 插入数据 * * @param id * @param time */ private boolean insertsharecheck(String id, String time) { if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time)) return false; db = openHelper.getWritableDatabase();//以读写的方式访问数据库 ContentValues value = new ContentValues(); value.put("defaultid", id); value.put("sharecheck", time); db.insert("user_table", null, value); db.close();// 关闭数据库 return true; } /** * 更新数据 * * @param id * @param time */ private boolean updatesharecheck(String id, String time) { if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time)) return false; db = openHelper.getWritableDatabase();//以读写的方式访问数据库 ContentValues value = new ContentValues(); value.put("defaultid", id); value.put("sharecheck", time); db.update("user_table", value, "defaultid=?", new String[]{id}); db.close();// 关闭数据库 return true; } }