下面列出了android.database.DatabaseUtils#longForQuery ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
int calculateDebugTableInsertionPoint() {
SQLiteDatabase db = mDeDatabase.getReadableDatabase();
String queryCountDebugDbRows = "SELECT COUNT(*) FROM " + TABLE_DEBUG;
int size = (int) DatabaseUtils.longForQuery(db, queryCountDebugDbRows, null);
if (size < MAX_DEBUG_DB_SIZE) {
return size;
}
// This query finds the smallest timestamp value (and if 2 records have
// same timestamp, the choose the lower id).
queryCountDebugDbRows = "SELECT " + DEBUG_TABLE_KEY +
" FROM " + TABLE_DEBUG +
" ORDER BY " + DEBUG_TABLE_TIMESTAMP + "," + DEBUG_TABLE_KEY +
" LIMIT 1";
return (int) DatabaseUtils.longForQuery(db, queryCountDebugDbRows, null);
}
public static long getChangeCount(String tableName)
{
String selection = getSelectionForSync();
MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
SQLiteDatabase db = map.getDatabase(true);
try {
// From sources of DatabaseUtils.queryNumEntries()
String s = (!TextUtils.isEmpty(selection)) ? " where " + selection : "";
return DatabaseUtils.longForQuery(db, "select count(*) from " + tableName + s, null);
} catch (SQLiteException e) {
e.printStackTrace();
Log.d(TAG, e.getLocalizedMessage());
return 0;
}
}
long findAccountLastAuthenticatedTime(Account account) {
SQLiteDatabase db = mDeDatabase.getReadableDatabase();
return DatabaseUtils.longForQuery(db,
"SELECT " + AccountsDb.ACCOUNTS_LAST_AUTHENTICATE_TIME_EPOCH_MILLIS
+ " FROM " + TABLE_ACCOUNTS + " WHERE " + ACCOUNTS_NAME + "=? AND "
+ ACCOUNTS_TYPE + "=?",
new String[] {account.name, account.type});
}
/**
* Sets the maximum size the database will grow to. The maximum size cannot
* be set below the current size.
*
* @param numBytes the maximum database size, in bytes
* @return the new maximum database size
*/
public long setMaximumSize(long numBytes) {
long pageSize = getPageSize();
long numPages = numBytes / pageSize;
// If numBytes isn't a multiple of pageSize, bump up a page
if ((numBytes % pageSize) != 0) {
numPages++;
}
long newPageCount = DatabaseUtils.longForQuery(this, "PRAGMA max_page_count = " + numPages,
null);
return newPageCount * pageSize;
}
public long countForQuery(String query, String[] selectionArgs) {
if (StringUtil.isEmpty(query)) {
return 0l;
}
SQLiteDatabase db = dbHelper.getReadableDatabase();
return DatabaseUtils.longForQuery(db, query, selectionArgs);
}
public int getBookCategoryId(int bookId) {
return (int) DatabaseUtils.longForQuery(getReadableDatabase(),
" SELECT " +
BooksInformationDBContract.BooksCategories.COLUMN_NAME_CATEGORY_ID +
" FROM " +
BooksInformationDBContract.BooksCategories.TABLE_NAME +
" WHERE " +
BooksInformationDBContract.BooksCategories.COLUMN_NAME_BOOK_ID + "=?",
new String[]{String.valueOf(bookId)}
);
}
public long getBookIdByDownloadId(long enquId) {
return DatabaseUtils.longForQuery(getReadableDatabase(),
SQL.SELECT +
BooksInformationDBContract.StoredBooks.COLUMN_NAME_BookID +
SQL.FROM +
BooksInformationDBContract.StoredBooks.TABLE_NAME +
SQL.WHERE +
BooksInformationDBContract.StoredBooks.COLUMN_NAME_ENQID + "=?",
new String[]{Long.toString(enquId)}
);
}
public boolean isDownloadEnqueue(long enqueueId) {
return 1L == DatabaseUtils.longForQuery(getReadableDatabase(),
" SELECT COUNT(*)" +
" FROM " +
BooksInformationDBContract.StoredBooks.TABLE_NAME +
" WHERE " +
BooksInformationDBContract.StoredBooks.COLUMN_NAME_ENQID + "=?",
new String[]{String.valueOf(enqueueId)}
);
}
/**
* @param titleId the title id to return its positin
* @param parentId
* @return the o based position of this title within is parent
*/
public int getTitlePositionUnderParent(int titleId, int parentId) {
return (int) DatabaseUtils.longForQuery(getReadableDatabase(),
SQL.SELECT + "count(*)" + SQL.FROM +
"(" + SQL.SELECT + " null " + SQL.FROM + BookDatabaseContract.TitlesEntry.TABLE_NAME +
SQL.WHERE +
BookDatabaseContract.TitlesEntry.COLUMN_NAME_PARENT_ID + "=? and " +
BookDatabaseContract.TitlesEntry.COLUMN_NAME_ID + "<? )",
new String[]{String.valueOf(parentId), String.valueOf(titleId)});
}
public boolean isPartPageCombinationValid(int partNumber, int pageNumber) {
return DatabaseUtils.longForQuery(getReadableDatabase(),
SQL.SELECT + " count(*) " + SQL.FROM +
"(" + SQL.SELECT + SQL.NULL + SQL.FROM + BookDatabaseContract.PageEntry.TABLE_NAME
+ SQL.WHERE +
BookDatabaseContract.PageEntry.COLUMN_NAME_PART_NUMBER + "=?" + SQL.AND +
BookDatabaseContract.PageEntry.COLUMN_NAME_PAGE_NUMBER + "=?)",
new String[]{String.valueOf(partNumber), String.valueOf(pageNumber)}) > 0L;
}
long findMatchingGrantsCount(int uid, String authTokenType, Account account) {
SQLiteDatabase db = mDeDatabase.getReadableDatabase();
String[] args = {String.valueOf(uid), authTokenType, account.name, account.type};
return DatabaseUtils.longForQuery(db, COUNT_OF_MATCHING_GRANTS, args);
}
long findMatchingGrantsCountAnyToken(int uid, Account account) {
SQLiteDatabase db = mDeDatabase.getReadableDatabase();
String[] args = {String.valueOf(uid), account.name, account.type};
return DatabaseUtils.longForQuery(db, COUNT_OF_MATCHING_GRANTS_ANY_TOKEN, args);
}
public void sampleDatabaseUtils(DatabaseUtils databaseUtils, String input) {
databaseUtils.longForQuery(null, input, null);
databaseUtils.stringForQuery(null, input, null);
databaseUtils.blobFileDescriptorForQuery(null, input, null);
databaseUtils.createDbFromSqlStatements(null, null, 0, input);
}
@Override
public long getTotalTweetsEverSeen () {
return DatabaseUtils.longForQuery(this.mDb, "SELECT max(" + TBL_TW_ID + ") FROM " + TBL_TW, null);
}
/**
* Returns the maximum size the database may grow to.
*
* @return the new maximum database size
*/
public long getMaximumSize() {
long pageCount = DatabaseUtils.longForQuery(this, "PRAGMA max_page_count;", null);
return pageCount * getPageSize();
}
/**
* Returns the current database page size, in bytes.
*
* @return the database page size, in bytes
*/
public long getPageSize() {
return DatabaseUtils.longForQuery(this, "PRAGMA page_size;", null);
}