本文整理汇总了Java中net.sqlcipher.database.SQLiteStatement.simpleQueryForLong方法的典型用法代码示例。如果您正苦于以下问题:Java SQLiteStatement.simpleQueryForLong方法的具体用法?Java SQLiteStatement.simpleQueryForLong怎么用?Java SQLiteStatement.simpleQueryForLong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sqlcipher.database.SQLiteStatement
的用法示例。
在下文中一共展示了SQLiteStatement.simpleQueryForLong方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupAndCacheId
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* Perform an internal string-to-integer lookup using the compiled
* {@link SQLiteStatement} provided. If a mapping isn't found in database, it will be
* created. All new, uncached answers are added to the cache automatically.
*
* @param query Compiled statement used to query for the mapping.
* @param insert Compiled statement used to insert a new mapping when no
* existing one is found in cache or from query.
* @param value Value to find mapping for.
* @param cache In-memory cache of previous answers.
* @return An unique integer mapping for the given value.
*/
private long lookupAndCacheId(SQLiteStatement query, SQLiteStatement insert, String value, HashMap<String, Long> cache) {
long id = -1;
try {
// Try searching database for mapping
DatabaseUtils.bindObjectToProgram(query, 1, value);
id = query.simpleQueryForLong();
} catch (SQLiteDoneException e) {
// Nothing found, so try inserting new mapping
DatabaseUtils.bindObjectToProgram(insert, 1, value);
id = insert.executeInsert();
}
if (id != -1) {
// Cache and return the new answer
cache.put(value, id);
return id;
} else {
// Otherwise throw if no mapping found or created
throw new IllegalStateException("Couldn't find or create internal lookup table entry for value " + value);
}
}
示例2: getIndexSpanningIteratorOrNull
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
protected SqlStorageIterator<T> getIndexSpanningIteratorOrNull(SQLiteDatabase db, boolean includeData) {
//If we're just iterating over ID's, we may want to use a different, much
//faster method depending on our stats. This method retrieves the
//index records that _don't_ exist so we can assume the spans that
//do.
if (!includeData && STORAGE_OPTIMIZATIONS_ACTIVE) {
SQLiteStatement min = db.compileStatement("SELECT MIN(" + DatabaseHelper.ID_COL + ") from " + table);
SQLiteStatement max = db.compileStatement("SELECT MAX(" + DatabaseHelper.ID_COL + ") from " + table);
SQLiteStatement count = db.compileStatement("SELECT COUNT(" + DatabaseHelper.ID_COL + ") from " + table);
int minValue = (int)min.simpleQueryForLong();
int maxValue = (int)max.simpleQueryForLong() + 1;
int countValue = (int)count.simpleQueryForLong();
min.close();
max.close();
count.close();
double density = countValue / (maxValue - minValue * 1.0);
//Ok, so basic metrics:
//1) Only use a covering iterator if the number of records is > 1k
//2) Only use a covering iterator if the number of records is less than 100k (vital, hard limit)
//3) Only use a covering iterator if the record density is 50% or more
if (countValue > 1000 &&
countValue < 100000 &&
density >= 0.5) {
return getCoveringIndexIterator(db, minValue, maxValue, countValue);
}
}
return null;
}
示例3: longForQuery
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* Utility method to run the query on the db and return the value in the
* first column of the first row.
*/
public static long longForQuery(SQLiteDatabase db, String query) {
SQLiteStatement prog = db.compileStatement(query);
try {
return prog.simpleQueryForLong();
} finally {
prog.close();
}
}
示例4: longForQuery
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
/**
* Utility method to run the pre-compiled query and return the value in the
* first column of the first row.
*/
public static long longForQuery(SQLiteStatement prog, String[] selectionArgs) {
if (selectionArgs != null) {
int size = selectionArgs.length;
for (int i = 0; i < size; i++) {
bindObjectToProgram(prog, i + 1, selectionArgs[i]);
}
}
long value = prog.simpleQueryForLong();
return value;
}
示例5: queryForLong
import net.sqlcipher.database.SQLiteStatement; //导入方法依赖的package包/类
public long queryForLong(String statement) throws SQLException {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement(statement);
long result = stmt.simpleQueryForLong();
logger.trace("{}: query for long simple query returned {}: {}", this, result, statement);
return result;
} catch (android.database.SQLException e) {
throw SqlExceptionUtil.create("queryForLong from database failed: " + statement, e);
} finally {
if (stmt != null) {
stmt.close();
}
}
}