本文整理汇总了Java中android.database.sqlite.SQLiteDatabase.query方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteDatabase.query方法的具体用法?Java SQLiteDatabase.query怎么用?Java SQLiteDatabase.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.sqlite.SQLiteDatabase
的用法示例。
在下文中一共展示了SQLiteDatabase.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKey
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public byte[] getKey(int Major, int Minor, int indicator) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.query(KEYS_TABLE_NAME,
new String[] { KEYS_COLUMN_INDICATOR, KEYS_COLUMN_VALUE },
KEYS_COLUMN_MAJORMINOR + "=? AND " + KEYS_COLUMN_INDICATOR + "=?",
new String[] { utils.majorMinorToHexString(Major,Minor), Integer.toString(indicator)},
null,null, null);
if (res.moveToFirst()) {
byte[] key = utils.hexStringToByteArray(res.getString(res.getColumnIndex(KEYS_COLUMN_VALUE)));
return key;
}
else {
return null;
}
}
示例2: getMaxSeqNum
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Get the maximum sequence number in the database associated with the given public key
*
* @param pubkey - public key for which to search for blocks
* @return the maximum sequence number found
*/
public int getMaxSeqNum(byte[] pubkey) {
SQLiteDatabase dbReadable = getReadableDatabase();
int res = -1;
String[] projection = new String[]{"max(" +
TrustChainDBContract.BlockEntry.COLUMN_NAME_SEQUENCE_NUMBER + ")"};
String whereClause = TrustChainDBContract.BlockEntry.COLUMN_NAME_PUBLIC_KEY + " = ?";
String[] whereArgs = new String[]{Base64.encodeToString(pubkey, Base64.DEFAULT)};
Cursor cursor = dbReadable.query(
TrustChainDBContract.BlockEntry.TABLE_NAME,
projection,
whereClause,
whereArgs,
null,
null,
null
);
if (cursor.getCount() == 1) {
cursor.moveToFirst();
res = cursor.getInt(cursor.getColumnIndex(
"max(" + TrustChainDBContract.BlockEntry.COLUMN_NAME_SEQUENCE_NUMBER + ")"));
}
cursor.close();
return res;
}
示例3: fillCache
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void fillCache() {
Cursor cursor = null;
try {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
cursor = db.query(TABLE, null, null, null, null, null, null);
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID_COLUMN));
String address = cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS_COLUMN));
if (address == null || address.trim().length() == 0)
address = "Anonymous";
idCache.put(id, address);
addressCache.put(address, id);
}
} finally {
if (cursor != null)
cursor.close();
}
}
示例4: getPauseButtonValue
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public List getPauseButtonValue() {
String coloumns[] = {storePauseValue};
SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
Cursor cursor = db.query(TABLE_NAME11, coloumns, null, null, null, null, null);
List<Integer> list = new ArrayList<>();
while (cursor.moveToNext()) {
int pauseValue = cursor.getInt(0);
list.add(pauseValue);
}
db.setTransactionSuccessful();
db.endTransaction();
cursor.close();
db.close();
return list;
}
示例5: getSetCards
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public List<Stats> getSetCards(String setId) {
List<Stats> cardList = new ArrayList<Stats>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.query(TABLE_STATS,
new String[]{KEY_ID, KEY_TRUE_ANSWERS, KEY_TIME_SPENT, KEY_DATE},
KEY_ID + "=?",
new String[]{setId}, null, null, null, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Stats stats = new Stats();
stats.setSetId(cursor.getString(0));
stats.setTrueAnswers(cursor.getString(1));
stats.setTimeSpent(cursor.getString(2));
stats.setDate(cursor.getString(3));
// Adding card to list
cardList.add(stats);
} while (cursor.moveToNext());
}
cursor.close();
// return contact list
return cardList;
}
示例6: init
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Initialize data.
* @param startDate The first month of the report period
* @param periodLength The number of months in the report period
* @param currency The report reference currency
* @param filterColumn The report filtering column in transactions table
* @param filterId The report filtering id in transactions table
* @param dbAdapter Database adapter to query data
*/
private void init(Context context, Calendar startDate, int periodLength, Currency currency, String filterColumn, int[] filterId, MyEntityManager em) {
this.context = context;
this.periodLength = periodLength;
startDate.set(startDate.get(Calendar.YEAR), startDate.get(Calendar.MONTH), 01, 00, 00, 00);
this.startDate = startDate;
SQLiteDatabase db = em.db();
Cursor cursor = null;
fillEmptyList(startDate, periodLength);
try {
// search accounts for which the reference currency is the given currency
int[] accounts = getAccountsByCurrency(currency, db);
if (accounts.length==0) {
max=min=0;
absMax=absMin=0;
return;
}
// prepare query based on given report parameters
String where = getWhereClause(filterColumn, filterId, accounts);
String[] pars = getWherePars(startDate, periodLength, filterId, accounts);
// query data
cursor = db.query(TRANSACTION_TABLE, new String[]{filterColumn, TransactionColumns.from_amount.name(), TransactionColumns.datetime.name(), TransactionColumns.datetime.name()},
where, pars, null, null, TransactionColumns.datetime.name());
// extract data and fill statistics
extractData(cursor);
} finally {
if (cursor!=null) cursor.close();
}
}
示例7: getNote
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
* Recupera el detalle de una nota
* @param id id del regsitro a recuperar
* @return detalles de la nota, null si no se encuentra
*/
public Note getNote (long id) {
Note note = null;
try {
SQLiteDatabase db = this.getReadableDatabase();
String[] columns = new String [] { NoteTable._ID,
NoteTable.COLUMN_TITLE,
NoteTable.COLUMN_CONTENT,
NoteTable.COLUMN_CREATION_DATE,
NoteTable.COLUMN_UPDATE_DATE};
String selection = NoteTable._ID + " = ? ";
String[] selectionArgs = new String [] {Long.toString(id)};
Cursor cursor = db.query(NoteTable.TABLE_NAME, columns, selection, selectionArgs, null, null, null);
if (cursor != null) {
if (cursor.moveToNext ()) {
note = new Note (cursor.getLong (cursor.getColumnIndex(NoteTable._ID)),
cursor.getString (cursor.getColumnIndex(NoteTable.COLUMN_TITLE)),
cursor.getString (cursor.getColumnIndex(NoteTable.COLUMN_CONTENT)),
new Date (cursor.getLong (cursor.getColumnIndex(NoteTable.COLUMN_CREATION_DATE))),
new Date (cursor.getLong (cursor.getColumnIndex(NoteTable.COLUMN_UPDATE_DATE))));
}
// liberamos y cerramos el cursor.
cursor.close();
}
} catch (Exception ex) {
Log.e (AppConstants.APP_TAG, "Error en getNote", ex);
}
return note;
}
示例8: getAddressFromId
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public @NonNull String getAddressFromId(long id) {
String cachedAddress = idCache.get(id);
if (cachedAddress != null)
return cachedAddress;
Cursor cursor = null;
try {
Log.w(TAG, "Hitting DB on query [ID].");
SQLiteDatabase db = databaseHelper.getReadableDatabase();
cursor = db.query(TABLE, null, ID_COLUMN + " = ?", new String[] {id+""}, null, null, null);
if (!cursor.moveToFirst())
return "Anonymous";
String address = cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS_COLUMN));
if (address == null || address.trim().equals("")) {
return "Anonymous";
} else {
idCache.put(id, address);
return address;
}
} finally {
if (cursor != null)
cursor.close();
}
}
示例9: query
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String order) {
OModel model = getModel(getContext(), uri);
setMatcher(model);
SQLiteDatabase db = model.getWritableDatabase();
Cursor cr = db.query(model.getTableName(), projection, selection, selectionArgs, null, null, order);
Context ctx = getContext();
if (cr != null && ctx != null)
cr.setNotificationUri(ctx.getContentResolver(), uri);
return cr;
}
示例10: assertMessageWithSubjectExists
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
private void assertMessageWithSubjectExists(SQLiteDatabase database, String subject) {
Cursor cursor = database.query("messages", new String[] { "subject" }, null, null, null, null, null);
try {
assertTrue(cursor.moveToFirst());
assertEquals(subject, cursor.getString(0));
} finally {
cursor.close();
}
}
示例11: getDetalhePessoa
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public Pessoa getDetalhePessoa(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_PESSOA,
new String[]{Pessoa.TAG_ID,
Pessoa.TAG_NOME,
Pessoa.TAG_SOBRENOME,
Pessoa.TAG_DESCRICAO,
Pessoa.TAG_EMPRESA,
Pessoa.TAG_PROFISSAO,
Pessoa.TAG_FOTO,
Pessoa.TAG_CONTATOS,
Pessoa.TAG_ULTIMA_ATUALIZACAO},
Pessoa.TAG_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);
Pessoa pessoa = new Pessoa();
if (cursor.moveToFirst()) {
pessoa.setId(id);
pessoa.setNome(cursor.getString(1));
pessoa.setSobrenome(cursor.getString(2));
pessoa.setDescricao(cursor.getString(3));
pessoa.setEmpresa(cursor.getString(4));
pessoa.setProfissao(cursor.getString(5));
pessoa.setFoto(cursor.getBlob(6));
pessoa.setContatos(cursor.getString(7));
pessoa.setHorarioUltimaAtualizacao(cursor.getString(8));
cursor.close();
}
db.close();
return pessoa;
}
示例12: query
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**查询单个数据
* @param column
* @param value
* @return
*/
public Cursor query(String column, String value) {
SQLiteDatabase db = this.getReadableDatabase();
try {
return db.query(TABLE_NAME, null, getSelection(column), getSelectionArgs(column, value), null, null, null);
} catch (Exception e) {
Log.e(TAG, "query try { return db.query(...} catch (Exception e) {\n" + e.getMessage());
}
return null;
}
示例13: getBeacon
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public BeaconResult getBeacon(String uuid, String major, String minor) {
SQLiteDatabase db = dbHelper.getReadableDatabase();
try {
String[] columns = {
COLUMN_NAME_UUID,
COLUMN_NAME_MAJOR,
COLUMN_NAME_MINOR,
COLUMN_NAME_INFORMAL_NAME,
};
Cursor cursor = db.query(TABLE_NAME, columns, PRIMARY_KEY_SELECTION, new String[] {uuid, major, minor}, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
String informalName = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_INFORMAL_NAME));
cursor.close();
return new BeaconResult(uuid, major, minor, informalName);
}
} finally {
if (db != null) {
db.close();
}
}
return null;
}
示例14: getSince
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
static List<OpenLocateLocation> getSince(SQLiteDatabase database, long millisecondsSince1970) {
if (database == null) {
return null;
}
Cursor cursor = database.query(TABLE_NAME, null, LocationTable.COLUMN_CREATED_AT + " > " + millisecondsSince1970,
null, null, null, LocationTable.COLUMN_CREATED_AT, QUERY_LIMIT);
if (cursor == null || cursor.isClosed()) {
return null;
}
return getLocations(cursor);
}
示例15: getLastReadTime
import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public long getLastReadTime(int id) {
SQLiteDatabase db = this.getReadableDatabase();
try (Cursor bookscursor = db.query(BOOK_TABLE, new String[] {BOOK_LASTREAD}, BOOK_ID + "=?", new String[] {""+id}, null, null, null)) {
if (bookscursor.moveToNext()) {
return bookscursor.getLong(bookscursor.getColumnIndex(BOOK_LASTREAD));
}
}
return -1;
}