Tabnine Logo
SupportSQLiteDatabase.query
Code IndexAdd Tabnine to your IDE (free)

How to use
query
method
in
androidx.sqlite.db.SupportSQLiteDatabase

Best Java code snippets using androidx.sqlite.db.SupportSQLiteDatabase.query (Showing top 20 results out of 315)

origin: ankidroid/Anki-Android

@Override
public void disableDatabaseWriteAheadLogging(SupportSQLiteDatabase db) {
  db.query("PRAGMA journal_mode = DELETE", null);
}
origin: ankidroid/Anki-Android

public long queryLongScalar(String query) {
  Cursor cursor = null;
  long scalar;
  try {
    cursor = mDatabase.query(query, null);
    if (!cursor.moveToNext()) {
      return 0;
    }
    scalar = cursor.getLong(0);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  return scalar;
}
origin: ankidroid/Anki-Android

public int queryScalar(String query, String[] selectionArgs) {
  Cursor cursor = null;
  int scalar;
  try {
    cursor = mDatabase.query(query, selectionArgs);
    if (!cursor.moveToNext()) {
      return 0;
    }
    scalar = cursor.getInt(0);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  return scalar;
}
origin: ankidroid/Anki-Android

public String queryString(String query) throws SQLException {
  Cursor cursor = null;
  try {
    cursor = mDatabase.query(query, null);
    if (!cursor.moveToNext()) {
      throw new SQLException("No result for query: " + query);
    }
    return cursor.getString(0);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
origin: ankidroid/Anki-Android

public Pair<String, Integer> syncInfo(String fname) {
  Cursor cur = null;
  try {
    cur = mDb.getDatabase().query("select csum, dirty from media where fname=?", new String[] { fname });
    if (cur.moveToNext()) {
      String csum = cur.getString(0);
      int dirty = cur.getInt(1);
      return new Pair<>(csum, dirty);
    } else {
      return new Pair<>(null, 0);
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }
}
origin: ankidroid/Anki-Android

public ArrayList<Object[]> _qaData(String where) {
  ArrayList<Object[]> data = new ArrayList<>();
  Cursor cur = null;
  try {
    cur = mDb.getDatabase().query(
        "SELECT c.id, n.id, n.mid, c.did, c.ord, "
            + "n.tags, n.flds FROM cards c, notes n WHERE c.nid == n.id " + where, null);
    while (cur.moveToNext()) {
      data.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getLong(2), cur.getLong(3), cur.getInt(4),
          cur.getString(5), cur.getString(6) });
    }
  } finally {
    if (cur != null && !cur.isClosed()) {
      cur.close();
    }
  }
  return data;
}
origin: ankidroid/Anki-Android

public TodayStats(SupportSQLiteDatabase db, long dayStartCutoff) {
  Cursor cur = null;
  String query = "select cards.did, "+
      "sum(case when revlog.type = 0 then 1 else 0 end)"+ /* learning */
      " from revlog, cards where revlog.cid = cards.id and revlog.id > " + dayStartCutoff +
      " group by cards.did";
  Timber.d("AdvancedStatistics.TodayStats query: %s", query);
  try {
    cur = db.query(query, null);
    while(cur.moveToNext()) {
      nLearnedPerDeckId.put(cur.getLong(0), cur.getInt(1));
    }
  } finally {
    if (cur != null && !cur.isClosed()) {
      cur.close();
    }
  }
}
origin: ankidroid/Anki-Android

/**
 * Field checksums and sorting fields ***************************************
 * ********************************************************
 */
private ArrayList<Object[]> _fieldData(String snids) {
  ArrayList<Object[]> result = new ArrayList<>();
  Cursor cur = null;
  try {
    cur = mDb.getDatabase().query("SELECT id, mid, flds FROM notes WHERE id IN " + snids, null);
    while (cur.moveToNext()) {
      result.add(new Object[] { cur.getLong(0), cur.getLong(1), cur.getString(2) });
    }
  } finally {
    if (cur != null && !cur.isClosed()) {
      cur.close();
    }
  }
  return result;
}
origin: ankidroid/Anki-Android

public String loadColumn(String columnName) {
  int pos = 1;
  int chunk = 256*1024;
  StringBuffer buf = new StringBuffer("");
  while (true) {
    Cursor cursor = null;
    try {
      cursor = mDb.getDatabase().query(
          "SELECT substr(" + columnName + ", ?, ?) FROM col",
          new String[]{Integer.toString(pos), Integer.toString(chunk)});
      if (!cursor.moveToFirst()) {
        return buf.toString();
      }
      String res = cursor.getString(0);
      if (res.length() == 0) {
         break;
      }
      buf.append(res);
      if (res.length() < chunk) {
        break;
      }
      pos += chunk;
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }
  return buf.toString();
}
origin: ankidroid/Anki-Android

public String emptyCardReport(List<Long> cids) {
  StringBuilder rep = new StringBuilder();
  Cursor cur = null;
  try {
    cur = mDb.getDatabase().query("select group_concat(ord+1), count(), flds from cards c, notes n "
                    + "where c.nid = n.id and c.id in " + Utils.ids2str(cids) + " group by nid", null);
    while (cur.moveToNext()) {
      String ords = cur.getString(0);
      //int cnt = cur.getInt(1);  // present but unused upstream as well
      String flds = cur.getString(2);
      rep.append(String.format("Empty card numbers: %s\nFields: %s\n\n", ords, flds.replace("\u001F", " / ")));
    }
  } finally {
    if (cur != null && !cur.isClosed()) {
      cur.close();
    }
  }
  return rep.toString();
}
origin: ankidroid/Anki-Android

public ArrayList<Card> cards() {
  ArrayList<Card> cards = new ArrayList<>();
  Cursor cur = null;
  try {
    cur = mCol.getDb().getDatabase()
        .query("SELECT id FROM cards WHERE nid = " + mId + " ORDER BY ord", null);
    while (cur.moveToNext()) {
      cards.add(mCol.getCard(cur.getLong(0)));
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }
  return cards;
}
origin: ankidroid/Anki-Android

public CardIterator(SupportSQLiteDatabase db, int today, Deck deck) {
  this.today = today;
  this.deck = deck;
  long did = deck.getDid();
  String query;
  query = "SELECT id, due, ivl, factor, type, reps " +
      "FROM cards " +
      "WHERE did IN (" + did + ") " +
      "order by id;";
  Timber.d("Forecast query: %s", query);
  cur = db.query(query, null);
}
origin: ankidroid/Anki-Android

/** Add any missing tags from notes to the tags list. */
public void registerNotes(long[] nids) {
  // when called with a null argument, the old list is cleared first.
  String lim;
  if (nids != null) {
    lim = " WHERE id IN " + Utils.ids2str(nids);
  } else {
    lim = "";
    mTags.clear();
    mChanged = true;
  }
  List<String> tags = new ArrayList<>();
  Cursor cursor = null;
  try {
    cursor = mCol.getDb().getDatabase().query("SELECT DISTINCT tags FROM notes"+lim, null);
    while (cursor.moveToNext()) {
      tags.add(cursor.getString(0));
    }
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
  HashSet<String> tagSet = new HashSet<>();
  for (String s : split(TextUtils.join(" ", tags))) {
    tagSet.add(s);
  }
  register(tagSet);
}
origin: ankidroid/Anki-Android

private Cursor cursorForTable(String table) {
  String lim = usnLim();
  if ("revlog".equals(table)) {
    return mCol
        .getDb()
        .getDatabase()
        .query(
            String.format(Locale.US,
                "SELECT id, cid, %d, ease, ivl, lastIvl, factor, time, type FROM revlog WHERE %s",
                mMaxUsn, lim), null);
  } else if ("cards".equals(table)) {
    return mCol
        .getDb()
        .getDatabase()
        .query(
            String.format(
                Locale.US,
                "SELECT id, nid, did, ord, mod, %d, type, queue, due, ivl, factor, reps, lapses, left, odue, odid, flags, data FROM cards WHERE %s",
                mMaxUsn, lim), null);
  } else {
    return mCol
        .getDb()
        .getDatabase()
        .query(
            String.format(
                Locale.US,
                "SELECT id, guid, mid, mod, %d, tags, flds, '', '', flags, data FROM notes WHERE %s",
                mMaxUsn, lim), null);
  }
}
origin: ankidroid/Anki-Android

private String _findDupes(String val) {
  // caller must call stripHTMLMedia on passed val
  String[] split = val.split(",", 1);
  if (split.length != 2) {
    return null;
  }
  String mid = split[0];
  val = split[1];
  String csum = Long.toString(Utils.fieldChecksum(val));
  List<Long> nids = new ArrayList<>();
  Cursor cur = null;
  try {
    cur = mCol.getDb().getDatabase().query(
        "select id, flds from notes where mid=? and csum=?",
        new String[] { mid, csum });
    long nid = cur.getLong(0);
    String flds = cur.getString(1);
    if (Utils.stripHTMLMedia(Utils.splitFields(flds)[0]).equals(val)) {
      nids.add(nid);
    }
  } finally {
    if (cur != null) {
      cur.close();
    }
  }
  return "n.id in " +  Utils.ids2str(nids);
}
origin: ankidroid/Anki-Android

    "group by day order by day",
    mCol.getSched().getToday(), chunk, _limit(), lim);
cur = mCol.getDb().getDatabase().query(query, null);
while (cur.moveToNext()) {
  d.add(new int[]{cur.getInt(0), cur.getInt(1), cur.getInt(2)});
origin: ankidroid/Anki-Android

public void _transformFields(JSONObject m, TransformFieldVisitor fn) {
  // model hasn't been added yet?
  try {
    if (m.getLong("id") == 0) {
      return;
    }
    ArrayList<Object[]> r = new ArrayList<>();
    Cursor cur = null;
    try {
      cur = mCol.getDb().getDatabase()
          .query("select id, flds from notes where mid = " + m.getLong("id"), null);
      while (cur.moveToNext()) {
        r.add(new Object[] {
            Utils.joinFields(fn.transform(Utils.splitFields(cur.getString(1)))),
            Utils.intNow(), mCol.usn(), cur.getLong(0) });
      }
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
    mCol.getDb().executeMany("update notes set flds=?,mod=?,usn=? where id = ?", r);
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
}
origin: ankidroid/Anki-Android

public void load() {
  Timber.d("load()");
  Cursor cursor = null;
  try {
    cursor = mCol.getDb().getDatabase()
        .query("SELECT guid, mid, mod, usn, tags, flds, flags, data FROM notes WHERE id = " + mId, null);
    if (!cursor.moveToFirst()) {
      throw new RuntimeException("Notes.load(): No result from query for note " + mId);
    }
    mGuId = cursor.getString(0);
    mMid = cursor.getLong(1);
    mMod = cursor.getLong(2);
    mUsn = cursor.getInt(3);
    mTags = mCol.getTags().split(cursor.getString(4));
    mFields = Utils.splitFields(cursor.getString(5));
    mFlags = cursor.getInt(6);
    mData = cursor.getString(7);
    mModel = mCol.getModels().get(mMid);
    mFMap = mCol.getModels().fieldMap(mModel);
    mScm = mCol.getScm();
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}
origin: ankidroid/Anki-Android

public int getNewCards(AxisType timespan) {
  String filter = getRevlogFilter(timespan,false);
  String queryNeg = "";
  if (timespan != AxisType.TYPE_LIFE){
    String invfilter = getRevlogFilter(timespan,true);
    queryNeg = " EXCEPT SELECT distinct cid FROM revlog " + invfilter;
  }
  String query = "SELECT COUNT(*) FROM(\n" +
      "            SELECT distinct cid\n" +
      "            FROM revlog \n" +
             filter +
             queryNeg +
      "        )";
  Timber.d("New cards query: %s", query);
  Cursor cur = null;
  int res = 0;
  try {
    cur = mCol.getDb().getDatabase().query(query, null);
    while (cur.moveToNext()) {
      res = cur.getInt(0);
    }
  } finally {
    if (cur != null && !cur.isClosed()) {
      cur.close();
    }
  }
  return res;
}
origin: ankidroid/Anki-Android

/**
 * Open a database connection to an ".anki" SQLite file.
 */
public DB(String ankiFilename) {
  SupportSQLiteOpenHelper.Configuration configuration = SupportSQLiteOpenHelper.Configuration.builder(AnkiDroidApp.getInstance())
      .name(ankiFilename)
      .callback(getDBCallback())
      .build();
  SupportSQLiteOpenHelper helper = getSqliteOpenHelperFactory().create(configuration);
  mDatabase = helper.getWritableDatabase();
  // TODO: remove this once everyone has stopped using old AnkiDroid clients with WAL (API >= 16)
  CompatHelper.getCompat().disableDatabaseWriteAheadLogging(mDatabase);
  mDatabase.query("PRAGMA synchronous = 2", null);
  mMod = false;
}
androidx.sqlite.dbSupportSQLiteDatabasequery

Popular methods of SupportSQLiteDatabase

  • execSQL
  • close
  • beginTransaction
  • disableWriteAheadLogging
  • endTransaction
  • insert
  • setTransactionSuccessful
  • enableWriteAheadLogging
  • getPath
  • inTransaction
  • isOpen
  • isWriteAheadLoggingEnabled
  • isOpen,
  • isWriteAheadLoggingEnabled,
  • setForeignKeyConstraintsEnabled,
  • update

Popular in Java

  • Updating database using SQL prepared statement
  • getSharedPreferences (Context)
  • onRequestPermissionsResult (Fragment)
  • notifyDataSetChanged (ArrayAdapter)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Random (java.util)
    This class provides methods that return pseudo-random values.It is dangerous to seed Random with the
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • JButton (javax.swing)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now