List of usage examples for android.database.sqlite SQLiteDatabase query
public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy,
String having, String orderBy)
From source file:Main.java
public static boolean hasDraftsToMigrate(Context context) { try {// w w w .j av a 2 s . co m SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null); String byString = "localDraft=1 OR isLocalChange=1"; Cursor c = db.query(DEPRECATED_POSTS_TABLE, null, byString, null, null, null, null); if (c.getCount() > 0) { c.close(); return true; } c.close(); return false; } catch (SQLException e) { return false; } }
From source file:Main.java
public static ArrayList<ContentValues> getArea(SQLiteDatabase db, int dqx_dqxx01) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;/*from w ww . j ava2 s .co m*/ Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02", "DQXX05" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { while (cursor.moveToNext()) { values = new ContentValues(); values.put("area_id", cursor.getInt(0)); values.put("area", cursor.getString(1)); values.put("full_area", cursor.getString(2)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
From source file:Main.java
public static Map<String, Integer> getCity(SQLiteDatabase db, String tableName, int dqx_dqxx01, boolean municipalities) { Map<String, Integer> cityMap = new LinkedHashMap<String, Integer>(); Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext();/*from w ww. j av a 2s .c om*/ } while (cursor.moveToNext()) { cityMap.put(cursor.getString(0), cursor.getInt(1)); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return cityMap; }
From source file:Main.java
public static ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;//from www . j a va 2s . com Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext(); } while (cursor.moveToNext()) { values = new ContentValues(); values.put("city_id", cursor.getInt(0)); values.put("city", cursor.getString(1)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
From source file:org.opendatakit.common.android.database.IdInstanceNameStruct.java
/** * Accessor to retrieve the database tableId given a formId * * @param db/* ww w. ja v a 2 s . co m*/ * @param formId * -- either the integer _ID or the textual form_id * @return */ public static IdInstanceNameStruct getIds(SQLiteDatabase db, String formId) { boolean isNumericId = StringUtils.isNumeric(formId); Cursor c = null; try { c = db.query(DatabaseConstants.FORMS_TABLE_NAME, new String[] { FormsColumns._ID, FormsColumns.FORM_ID, FormsColumns.TABLE_ID, FormsColumns.INSTANCE_NAME }, (isNumericId ? FormsColumns._ID : FormsColumns.FORM_ID) + "=?", new String[] { formId }, null, null, null); if (c.moveToFirst()) { int idxId = c.getColumnIndex(FormsColumns._ID); int idxFormId = c.getColumnIndex(FormsColumns.FORM_ID); int idxTableId = c.getColumnIndex(FormsColumns.TABLE_ID); int idxInstanceName = c.getColumnIndex(FormsColumns.INSTANCE_NAME); return new IdInstanceNameStruct(c.getInt(idxId), ODKDatabaseUtils.get().getIndexAsString(c, idxFormId), ODKDatabaseUtils.get().getIndexAsString(c, idxTableId), ODKDatabaseUtils.get().getIndexAsString(c, idxInstanceName)); } } finally { if (c != null && !c.isClosed()) { c.close(); } } return null; }
From source file:uk.ac.horizon.ubihelper.service.PeersOpenHelper.java
public static Cursor getPeerCursor(SQLiteDatabase database) { return database.query(PEER_TABLE_NAME, PEER_TABLE_COLUMNS, null, null, null, null, null); }
From source file:co.rewen.statex.AsyncLocalStorageUtil.java
/** * Returns the value of the given key, or null if not found. *///from w ww. j av a2 s. c o m /* package */ static @Nullable String getItemImpl(SQLiteDatabase db, String key) { String[] columns = { VALUE_COLUMN }; String[] selectionArgs = { key }; Cursor cursor = db.query(TABLE_STATE, columns, KEY_COLUMN + "=?", selectionArgs, null, null, null); try { if (!cursor.moveToFirst()) { return null; } else { return cursor.getString(0); } } finally { cursor.close(); } }
From source file:com.onesignal.NotificationOpenedProcessor.java
private static void updateSummaryNotification(SQLiteDatabase writableDb) { String grpId = intent.getStringExtra("grp"); Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, new String[] { NotificationTable.COLUMN_NAME_ANDROID_NOTIFICATION_ID }, // retColumn NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED + " = 0 AND " + NotificationTable.COLUMN_NAME_IS_SUMMARY + " = 0", new String[] { grpId }, // whereArgs null, null, null);//from w w w . j ava 2 s . co m // All individual notifications consumed, make summary notification as consumed as well. if (cursor.getCount() == 0) writableDb.update(NotificationTable.TABLE_NAME, newContentValuesWithConsumed(), NotificationTable.COLUMN_NAME_GROUP_ID + " = ?", new String[] { grpId }); else { try { GenerateNotification.createSummaryNotification(context, true, new JSONObject("{\"grp\": \"" + grpId + "\"}")); } catch (JSONException e) { } } cursor.close(); }
From source file:org.noorganization.instalist.utils.SQLiteUtils.java
/** * Generates for the table in the given database a unique id. * * @param _db the database where the table is. * @param _table the table to get the uuid for. * @return a really unique id.// w w w. j a v a 2 s. c o m */ public static UUID generateId(SQLiteDatabase _db, String _table) { UUID rtn = null; while (rtn == null) { rtn = UUID.randomUUID(); Cursor counter = _db.query(_table, new String[] { "_id" }, "_id = ?", new String[] { rtn.toString() }, null, null, null); if (counter.getCount() != 0) { rtn = null; } counter.close(); } return rtn; }
From source file:org.noorganization.instalist.utils.SQLiteUtils.java
/** * Generates for the table in the given database a unique id for the specified column. * * @param _db the database where the table is. * @param _table the table to get the uuid for. * @param _column the column where the value should be unique. * @return a really unique id.// ww w. j a va 2 s. c o m */ public static UUID generateId(SQLiteDatabase _db, String _table, String _column) { UUID rtn = null; while (rtn == null) { rtn = UUID.randomUUID(); Cursor counter = _db.query(_table, new String[] { _column }, _column + " = ?", new String[] { rtn.toString() }, null, null, null); if (counter.getCount() != 0) { rtn = null; } counter.close(); } return rtn; }