當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.compile方法代碼示例

本文整理匯總了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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:21,代碼來源:ContentProviderQueryBuilderTest.java

示例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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:24,代碼來源:ContentProviderQueryBuilderTest.java

示例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();
        }
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:24,代碼來源:ContentProviderQueryBuilderTest.java

示例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();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:23,代碼來源:SquidDatabase.java

示例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();
    }
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:16,代碼來源:SquidDatabase.java

示例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);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:14,代碼來源:SquidDatabase.java

示例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);
}
 
開發者ID:yahoo,項目名稱:squidb,代碼行數:14,代碼來源:SquidDatabase.java


注:本文中的com.yahoo.squidb.sql.Query.compile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。