use of io.requery.sql.QueryBuilder in project requery by requery.
the class SqliteMetaData method getTables.
@Override
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
if (types == null) {
types = new String[] { "TABLE", "VIEW" };
}
if (tableNamePattern == null) {
tableNamePattern = "%";
}
Map<String, String> select = new LinkedHashMap<>();
select.put("TABLE_CAT", null);
select.put("TABLE_SCHEM", null);
select.put("TABLE_NAME", "name");
select.put("TABLE_TYPE", "type");
select.put("REMARKS", null);
select.put("TYPE_CAT", null);
select.put("TYPE_SCHEM", null);
select.put("TYPE_NAME", null);
select.put("SELF_REFERENCING_COL_NAME", null);
select.put("REF_GENERATION", null);
QueryBuilder qb = new QueryBuilder(new QueryBuilder.Options(getIdentifierQuoteString(), true, null, null, false, false)).keyword(Keyword.SELECT).commaSeparated(select.entrySet(), new QueryBuilder.Appender<Map.Entry<String, String>>() {
@Override
public void append(QueryBuilder qb, Map.Entry<String, String> entry) {
String value = entry.getValue() == null ? "null" : entry.getValue();
qb.append(value).append(" as ").append(entry.getKey());
}
}).keyword(Keyword.FROM).openParenthesis().append("select name, type from sqlite_master").closeParenthesis().keyword(Keyword.WHERE).append(" TABLE_NAME like ").append(tableNamePattern).append(" && TABLE_TYPE in ").openParenthesis().commaSeparated(Arrays.asList(types)).closeParenthesis().keyword(Keyword.ORDER, Keyword.BY).append(" TABLE_TYPE, TABLE_NAME");
return queryMemory(new Function<Cursor, ResultSet>() {
@Override
public ResultSet apply(Cursor cursor) {
return new CursorResultSet(null, cursor, true);
}
}, qb.toString());
}
use of io.requery.sql.QueryBuilder in project requery by requery.
the class OffsetFetchGenerator method write.
@Override
public void write(Output output, LimitedElement query) {
QueryBuilder qb = output.builder();
Integer limit = query.getLimit();
if (limit != null && limit > 0) {
Integer offset = query.getOffset();
write(qb, limit, offset);
}
}
use of io.requery.sql.QueryBuilder in project requery by requery.
the class SelectGenerator method write.
@Override
public void write(final Output output, SelectionElement query) {
QueryBuilder qb = output.builder();
qb.keyword(SELECT);
if (query.isDistinct()) {
qb.keyword(DISTINCT);
}
Set<? extends Expression<?>> selection = query.getSelection();
if (selection == null || selection.isEmpty()) {
qb.append("*");
} else {
qb.commaSeparated(selection, new QueryBuilder.Appender<Expression<?>>() {
@Override
public void append(QueryBuilder qb, Expression<?> value) {
output.appendColumnForSelect(value);
}
});
}
qb.keyword(FROM);
output.appendTables();
}
use of io.requery.sql.QueryBuilder in project requery by requery.
the class SetOperatorGenerator method write.
@Override
public void write(Output output, SetOperationElement query) {
if (query.getInnerSetQuery() != null) {
QueryBuilder qb = output.builder();
switch(query.getOperator()) {
case UNION:
qb.keyword(UNION);
break;
case UNION_ALL:
qb.keyword(UNION, ALL);
break;
case INTERSECT:
qb.keyword(INTERSECT);
break;
case EXCEPT:
qb.keyword(EXCEPT);
break;
}
output.appendQuery(query.getInnerSetQuery());
}
}
use of io.requery.sql.QueryBuilder in project requery by requery.
the class StatementGenerator method write.
@Override
public void write(Output output, QueryElement<?> query) {
QueryBuilder qb = output.builder();
switch(query.queryType()) {
case SELECT:
select.write(output, query);
break;
case INSERT:
insert.write(output, query);
break;
case UPDATE:
update.write(output, checkEmpty(query.updateValues()));
break;
case UPSERT:
upsert.write(output, checkEmpty(query.updateValues()));
break;
case DELETE:
qb.keyword(DELETE, FROM);
output.appendTables();
break;
case TRUNCATE:
qb.keyword(TRUNCATE);
output.appendTables();
break;
}
where.write(output, query);
groupBy.write(output, query);
orderBy.write(output, query);
limit.write(output, query);
setOperation.write(output, query);
}
Aggregations