com.yahoo.squidb.sql.Query.sqlForValidation()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中com.yahoo.squidb.sql.Query.sqlForValidation方法的一些代码示例,展示了Query.sqlForValidation的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.sqlForValidation方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:sqlForValidation

Query.sqlForValidation介绍

暂无

代码示例

代码示例来源:origin: yahoo/squidb

/**
 * Query the database
 *
 * @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
 * or view corresponding to this model class will be used.
 * @param query the query to execute
 * @return a {@link SquidCursor} containing the query results
 */
public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
  query = inferTableForQuery(modelClass, query);
  CompiledStatement compiled = query.compile(getCompileContext());
  if (compiled.needsValidation) {
    String validateSql = query.sqlForValidation(getCompileContext());
    ensureSqlCompiles(validateSql); // throws if the statement fails to compile
  }
  ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
  return new SquidCursor<>(cursor, modelClass, query.getFields());
}

代码示例来源:origin: yahoo/squidb

public void testNeedsValidationUpdatedBySubqueryTable() {
  Query subquery = Query.select(Thing.PROPERTIES).from(Thing.TABLE).where(Criterion.literal(123));
  subquery.requestValidation();
  assertTrue(subquery.compile(database.getCompileContext()).sql.contains("WHERE (?)"));
  Query baseTestQuery = Query.select().from(Thing.TABLE).where(Thing.FOO.isNotEmpty()).freeze();
  assertFalse(baseTestQuery.needsValidation());
  Query testQuery = baseTestQuery.from(subquery.as("t1"));
  assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  testQuery = baseTestQuery.innerJoin(subquery.as("t2"), (Criterion[]) null);
  assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  testQuery = baseTestQuery.union(subquery);
  assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
}

代码示例来源:origin: yahoo/squidb

public void testValidationPropagatesToSubqueryJoinAndCompoundSelect() {
  Query subquery = Query.select(Thing.FOO).from(Thing.TABLE).where(Thing.BAR.gt(0));
  Query joinSubquery = Query.select(Thing.BAR).from(Thing.TABLE).where(Thing.FOO.isNotEmpty());
  Query compoundSubquery = Query.select(Thing.BAZ).from(Thing.TABLE).where(Thing.IS_ALIVE.isTrue());
  SubqueryTable subqueryTable = subquery.as("t1");
  SubqueryTable joinTable = joinSubquery.as("t2");
  Query query = Query.select().from(subqueryTable).innerJoin(joinTable, (Criterion[]) null)
      .union(compoundSubquery);
  final int queryLength = query.compile(database.getCompileContext()).sql.length();
  String withValidation = query.sqlForValidation(database.getCompileContext());
  assertEquals(queryLength + 6, withValidation.length());
}

代码示例来源:origin: yahoo/squidb

public void testNeedsValidationUpdatedByQueryFunction() {
  Query subquery = Query.select(Function.max(Thing.ID)).from(Thing.TABLE).where(Criterion.literal(123));
  subquery.requestValidation();
  assertTrue(subquery.compile(database.getCompileContext()).sql.contains("WHERE (?)"));
  Query baseTestQuery = Query.select().from(Thing.TABLE).where(Thing.FOO.isNotEmpty()).freeze();
  assertFalse(baseTestQuery.needsValidation());
  Query testQuery = baseTestQuery.selectMore(subquery.asFunction());
  assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
}

代码示例来源:origin: com.yahoo.squidb/squidb

/**
 * Query the database
 *
 * @param modelClass the type to parameterize the cursor by. If the query does not contain a FROM clause, the table
 * or view corresponding to this model class will be used.
 * @param query the query to execute
 * @return a {@link SquidCursor} containing the query results
 */
public <TYPE extends AbstractModel> SquidCursor<TYPE> query(Class<TYPE> modelClass, Query query) {
  query = inferTableForQuery(modelClass, query);
  CompiledStatement compiled = query.compile(getCompileContext());
  if (compiled.needsValidation) {
    String validateSql = query.sqlForValidation(getCompileContext());
    ensureSqlCompiles(validateSql); // throws if the statement fails to compile
  }
  ICursor cursor = rawQuery(compiled.sql, compiled.sqlArgs);
  return new SquidCursor<>(cursor, modelClass, query.getFields());
}

相关文章