本文整理了Java中com.yahoo.squidb.sql.Query.as
方法的一些代码示例,展示了Query.as
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.as
方法的具体详情如下:
包路径:com.yahoo.squidb.sql.Query
类名称:Query
方法名:as
[英]Alias this query, for use when creating a subquery to select from
[中]别名此查询,用于创建要从中选择的子查询时
代码示例来源:origin: yahoo/squidb
/**
* Construct a new Select statement that queries all the {@link Field}s of the given subquery
*
* @param subquery the inner Query object
* @param subqueryAlias the name to alias the subquery
* @return a new Query object
*/
public static Query fromSubquery(Query subquery, String subqueryAlias) {
SubqueryTable table = subquery.as(subqueryAlias);
return Query.select(table.qualifiedFields()).from(table);
}
代码示例来源:origin: yahoo/squidb
final SubqueryTable subqueryTable = subquery.as("t1");
代码示例来源: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 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
SqlTable<?> subTable = subquery.as("subTable");
StringProperty coworkers = subTable.qualifyField(subordinates);
Query query = Query.select(Employee.PROPERTIES).selectMore(coworkers)
代码示例来源:origin: yahoo/squidb
public void testSubstr() {
testSubstrInternal(2, 0);
testSubstrInternal(2, 2);
testSubstrInternal(3, 4);
String literal = "ABC/DEF";
StringProperty prefix = StringProperty.literal(literal.substring(0, literal.indexOf('/') + 1), "prefix");
StringProperty full = StringProperty.literal(literal, "full");
Field<String> fullField = Field.field(full.getName());
Field<String> prefixField = Field.field(prefix.getName());
SquidCursor<?> cursor = database.query(null,
Query.select(Function.substr(fullField, Function.add(Function.length(prefixField), 1)))
.from(Query.select(full, prefix).as("subquery")));
try {
assertTrue(cursor.moveToFirst());
assertEquals("DEF", cursor.getString(0));
} finally {
cursor.close();
}
}
代码示例来源:origin: com.yahoo.squidb/squidb
/**
* Construct a new Select statement that queries all the {@link Field}s of the given subquery
*
* @param subquery the inner Query object
* @param subqueryAlias the name to alias the subquery
* @return a new Query object
*/
public static Query fromSubquery(Query subquery, String subqueryAlias) {
SubqueryTable table = subquery.as(subqueryAlias);
return Query.select(table.qualifiedFields()).from(table);
}
内容来源于网络,如有侵权,请联系作者删除!