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

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

本文整理了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

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

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

  1. public void testNeedsValidationUpdatedBySubqueryTable() {
  2. Query subquery = Query.select(Thing.PROPERTIES).from(Thing.TABLE).where(Criterion.literal(123));
  3. subquery.requestValidation();
  4. assertTrue(subquery.compile(database.getCompileContext()).sql.contains("WHERE (?)"));
  5. Query baseTestQuery = Query.select().from(Thing.TABLE).where(Thing.FOO.isNotEmpty()).freeze();
  6. assertFalse(baseTestQuery.needsValidation());
  7. Query testQuery = baseTestQuery.from(subquery.as("t1"));
  8. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  9. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  10. testQuery = baseTestQuery.innerJoin(subquery.as("t2"), (Criterion[]) null);
  11. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  12. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  13. testQuery = baseTestQuery.union(subquery);
  14. assertTrue(testQuery.compile(database.getCompileContext()).needsValidation);
  15. assertTrue(testQuery.sqlForValidation(database.getCompileContext()).contains("WHERE ((?))"));
  16. }

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

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

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

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

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

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

相关文章