List of usage examples for android.database.sqlite SQLiteDatabase rawQuery
public Cursor rawQuery(String sql, String[] selectionArgs)
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static Vector<Long> getUnreadNoncatchedArticleList(String group, Context context) { int groupid = getGroupIdFromName(group, context); Vector<Long> artList = null; DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); String q = "SELECT server_article_number FROM headers WHERE subscribed_group_id=" + groupid + " AND read=0 AND catched=0"; Cursor c = dbread.rawQuery(q, null); int count = c.getCount(); artList = new Vector<Long>(count); c.moveToFirst();/*from www .j av a 2s . co m*/ for (int i = 0; i < count; i++) { artList.add(c.getLong(0)); c.moveToNext(); } c.close(); dbread.close(); db.close(); return artList; }
From source file:com.dpcsoftware.mn.Widget1Config.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/* w w w .ja v a2 s .co m*/ wPrefs = getSharedPreferences(App.WIDGET_PREFS_FNAME, MODE_PRIVATE); Intent intent = getIntent(); Bundle extras = intent.getExtras(); wId = AppWidgetManager.INVALID_APPWIDGET_ID; if (extras != null) wId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); else finish(); setContentView(R.layout.widget1_config); resultIntent = new Intent(); resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, wId); ActionBar abar = getSupportActionBar(); abar.setTitle("Configuraes do Widget"); SQLiteDatabase db = DatabaseHelper.quickDb(this, DatabaseHelper.MODE_READ); Cursor c = db.rawQuery("SELECT " + Db.Table3._ID + "," + Db.Table3.COLUMN_NGRUPO + " FROM " + Db.Table3.TABLE_NAME + " ORDER BY " + Db.Table3.COLUMN_NGRUPO + " ASC", null); SimpleCursorAdapter sAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, new String[] { Db.Table3.COLUMN_NGRUPO }, new int[] { android.R.id.text1 }, 0); sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp = ((Spinner) findViewById(R.id.spinner1)); sp.setAdapter(sAdapter); }
From source file:com.bufarini.reminders.AlarmReceiver.java
private void setReminders(Context context, String accountName) { RemindersDbHelper dbHelper = new RemindersDbHelper(context); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery(String.format("select %s, %s, %s, %s, %s, %s, %s from %s where %s=\"%s\"", Tables.COMPLETED, Tables.REMINDER_DATE, Tables.REMINDER_INTERVAL, Tables.ID, Tables.DUE_DATE, Tables.LIST_ID, Tables.TITLE, Tables.TASK_TABLE, Tables.ACCOUNT_NAME, accountName), null); try {// w w w . ja v a 2 s. co m while (cursor.moveToNext()) { boolean notCompleted = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.COMPLETED)) == 0; if (notCompleted) { long reminderDate = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.REMINDER_DATE)); long reminderInterval = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.REMINDER_INTERVAL)); if (reminderDate > System.currentTimeMillis() || reminderInterval > 0) { long id = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.ID)); String title = cursor.getString(cursor.getColumnIndexOrThrow(Tables.TITLE)); long dueDate = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.DUE_DATE)); long listId = cursor.getLong(cursor.getColumnIndexOrThrow(Tables.LIST_ID)); NotificationUtils.setReminder(context, id, title, dueDate, listId, reminderDate, reminderInterval); } } } } finally { cursor.close(); db.close(); } }
From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java
public static Vector<Object> isHeaderInDatabase(Long number, String group, Context context) { int groupid = getGroupIdFromName(group, context); DBHelper db = new DBHelper(context); SQLiteDatabase dbread = db.getReadableDatabase(); Vector<Object> retVal = null; String q = "SELECT _id, server_article_id FROM headers WHERE subscribed_group_id=" + groupid + " AND server_article_number=" + number; Cursor c = dbread.rawQuery(q, null); int count = c.getCount(); if (count > 0) { c.moveToFirst();//w w w . j av a 2s . c o m retVal = new Vector<Object>(2); retVal.add(c.getLong(0)); retVal.add(c.getString(1)); } c.close(); dbread.close(); db.close(); return retVal; }
From source file:com.example.sergey.currentweather.ui.activity.MainActivity.java
public boolean doesTableExist(SQLiteDatabase db, String tableName) { if (tableName == null || db == null || !db.isOpen()) { return false; }//from w w w . j a va 2 s. c om Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM " + tableName, null); if (!cursor.moveToFirst()) { return false; } int count = cursor.getInt(0); cursor.close(); return count > 0; }
From source file:DictionaryDatabase.java
public Cursor getWordList() { SQLiteDatabase db = getReadableDatabase(); String query = "SELECT _id, " + FIELD_WORD + " FROM " + TABLE_DICTIONARY + " ORDER BY " + FIELD_WORD + " ASC"; return db.rawQuery(query, null); }
From source file:org.egov.android.data.SQLiteHelper.java
public Cursor query(String sql, String[] selectionArgs) { SQLiteDatabase db = getReadableDatabase(); Cursor cursor = db.rawQuery(sql, selectionArgs); return cursor; }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
private void resetDatabase(SQLiteDatabase db) { Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type=\'table\'", null); SparseArrayCompat<String> tables = new SparseArrayCompat<>(); if (cursor.moveToFirst()) { do {//from w w w.j a v a 2 s .c om tables.append(tables.size(), cursor.getString(0)); } while (cursor.moveToNext()); } cursor.close(); for (int i = 0; i < tables.size(); i++) { try { String dropQuery = "DROP TABLE IF EXISTS " + tables.get(i); if (!tables.get(i).equalsIgnoreCase("SQLITE_SEQUENCE")) db.execSQL(dropQuery); } catch (Exception ignored) { } } onCreate(db); }
From source file:asu.edu.msse.gpeddabu.moviedescriptions.AddMovie.java
public void getGenreList() { genreArr = new ArrayList<>(); try {/* w w w . j av a2 s . c om*/ MovieDB db = new MovieDB(con); SQLiteDatabase crsDB = db.openDB(); Cursor cur = crsDB.rawQuery("select distinct genre from movie;", null); while (cur.moveToNext()) { genreArr.add(cur.getString(0)); } cur.close(); crsDB.close(); db.close(); } catch (Exception ex) { android.util.Log.w(this.getClass().getSimpleName(), "Exception getting genre info: " + ex.getMessage()); } }
From source file:DictionaryDatabase.java
public Cursor getWordList() { SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String query = "SELECT _id, " + FIELD_WORD + " FROM " + TABLE_DICTIONARY + " ORDER BY " + FIELD_WORD + " ASC"; return db.rawQuery(query, null); }