本文整理汇总了Java中com.yahoo.squidb.sql.Query.compile方法的典型用法代码示例。如果您正苦于以下问题:Java Query.compile方法的具体用法?Java Query.compile怎么用?Java Query.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.yahoo.squidb.sql.Query
的用法示例。
在下文中一共展示了Query.compile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRawSelection
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
public void testRawSelection() {
String selection = COL_LUCKY_NUMBER + " > ? AND " + COL_IS_HAPPY + " != ?";
String[] selectionArgs = new String[]{"50", "0"};
ContentProviderQueryBuilder builder = getBuilder();
Query query = builder.setDataSource(TestModel.TABLE).build(null, selection, selectionArgs, null);
CompiledStatement compiled = query.compile(database.getCompileContext());
verifyCompiledSqlArgs(compiled, 2, "50", "0");
SquidCursor<TestModel> cursor = null;
try {
cursor = database.query(TestModel.class, query);
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
assertEquals(model2, buildModelFromCursor(cursor));
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例2: testRawOrderBy
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
public void testRawOrderBy() {
String sortOrder = COL_GIVEN_NAME + " ASC";
ContentProviderQueryBuilder builder = getBuilder();
Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, sortOrder);
CompiledStatement compiled = query.compile(database.getCompileContext());
verifyCompiledSqlArgs(compiled, 0);
SquidCursor<TestModel> cursor = null;
try {
cursor = database.query(TestModel.class, query);
assertEquals(3, cursor.getCount());
cursor.moveToFirst();
assertEquals(model3, buildModelFromCursor(cursor));
cursor.moveToNext();
assertEquals(model2, buildModelFromCursor(cursor));
cursor.moveToNext();
assertEquals(model1, buildModelFromCursor(cursor));
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例3: testDefaultOrderBy
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
public void testDefaultOrderBy() {
ContentProviderQueryBuilder builder = getBuilder();
builder.setDefaultOrder(TestModel.LUCKY_NUMBER.desc());
Query query = builder.setDataSource(TestModel.TABLE).build(null, null, null, null);
CompiledStatement compiled = query.compile(database.getCompileContext());
verifyCompiledSqlArgs(compiled, 0);
SquidCursor<TestModel> cursor = null;
try {
cursor = database.query(TestModel.class, query);
assertEquals(3, cursor.getCount());
cursor.moveToFirst();
assertEquals(model2, buildModelFromCursor(cursor));
cursor.moveToNext();
assertEquals(model1, buildModelFromCursor(cursor));
cursor.moveToNext();
assertEquals(model3, buildModelFromCursor(cursor));
} finally {
if (cursor != null) {
cursor.close();
}
}
}
示例4: count
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
/**
* Count the number of rows matching a given {@link Criterion}. Use null to count all rows.
*
* @param modelClass the model class corresponding to the table
* @param criterion the criterion to match
* @return the number of rows matching the given criterion
*/
public int count(Class<? extends AbstractModel> modelClass, Criterion criterion) {
Property.IntegerProperty countProperty = Property.IntegerProperty.countProperty();
Query query = Query.select(countProperty);
if (criterion != null) {
query.where(criterion);
}
query = inferTableForQuery(modelClass, query);
CompiledStatement compiled = query.compile(getCompileContext());
acquireNonExclusiveLock();
try {
return (int) getDatabase().simpleQueryForLong(compiled.sql, compiled.sqlArgs);
} finally {
releaseNonExclusiveLock();
}
}
示例5: explainQueryPlan
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
/**
* Directly analogous to {@link #query(Class, Query)}, but instead of returning a result, this method just logs the
* output of EXPLAIN QUERY PLAN for the given query. This is method is intended for debugging purposes only.
*/
public void explainQueryPlan(Class<? extends AbstractModel> modelClass, Query query) {
query = inferTableForQuery(modelClass, query);
CompiledStatement compiled = query.compile(getCompileContext());
ICursor cursor = rawQuery("EXPLAIN QUERY PLAN " + compiled.sql, compiled.sqlArgs);
try {
Logger.d(Logger.LOG_TAG, "Query plan for: " + compiled.sql);
SquidUtilities.dumpCursor(cursor, -1);
} finally {
cursor.close();
}
}
示例6: simpleQueryForString
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
/**
* Execute a statement that returns a 1x1 String result. If you know your result set will only have one row and
* column, this is much more efficient than calling {@link #rawQuery(String, Object[])} and parsing the cursor.
* <br>
* Note: This will throw an exception if the given SQL query returns a result that is not a single column
*
* @param query a sql query
* @return the String result of the query
*/
public String simpleQueryForString(Query query) {
CompiledStatement compiled = query.compile(getCompileContext());
return simpleQueryForString(compiled.sql, compiled.sqlArgs);
}
示例7: simpleQueryForLong
import com.yahoo.squidb.sql.Query; //导入方法依赖的package包/类
/**
* Execute a statement that returns a 1x1 long result. If you know your result set will only have one row and
* column, this is much more efficient than calling {@link #rawQuery(String, Object[])} and parsing the cursor.
* <br>
* Note: This will throw an exception if the given SQL query returns a result that is not a single column
*
* @param query a sql query
* @return the long result of the query
*/
public long simpleQueryForLong(Query query) {
CompiledStatement compiled = query.compile(getCompileContext());
return simpleQueryForLong(compiled.sql, compiled.sqlArgs);
}