use of com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock in project druid by alibaba.
the class SQLSelectBuilderImpl method into.
@Override
public SQLSelectBuilderImpl into(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
queryBlock.setInto(exprObj);
return this;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock in project druid by alibaba.
the class SQLSelectBuilderImpl method limit.
@Override
public SQLSelectBuilderImpl limit(int rowCount, int offset) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
if (queryBlock instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock mySqlQueryBlock = (MySqlSelectQueryBlock) queryBlock;
SQLLimit limit = new SQLLimit();
limit.setRowCount(new SQLIntegerExpr(rowCount));
if (offset > 0) {
limit.setOffset(new SQLIntegerExpr(offset));
}
mySqlQueryBlock.setLimit(limit);
return this;
}
if (queryBlock instanceof SQLServerSelectQueryBlock) {
SQLServerSelectQueryBlock sqlserverQueryBlock = (SQLServerSelectQueryBlock) queryBlock;
if (offset <= 0) {
SQLServerTop top = new SQLServerTop();
top.setExpr(new SQLIntegerExpr(rowCount));
sqlserverQueryBlock.setTop(top);
} else {
throw new UnsupportedOperationException("not support offset");
}
return this;
}
if (queryBlock instanceof PGSelectQueryBlock) {
PGSelectQueryBlock pgQueryBlock = (PGSelectQueryBlock) queryBlock;
SQLLimit limit = new SQLLimit();
if (offset > 0) {
limit.setOffset(new SQLIntegerExpr(offset));
}
limit.setRowCount(new SQLIntegerExpr(rowCount));
pgQueryBlock.setLimit(limit);
return this;
}
if (queryBlock instanceof DB2SelectQueryBlock) {
DB2SelectQueryBlock db2QueryBlock = (DB2SelectQueryBlock) queryBlock;
if (offset <= 0) {
SQLExpr rowCountExpr = new SQLIntegerExpr(rowCount);
db2QueryBlock.setFirst(rowCountExpr);
} else {
throw new UnsupportedOperationException("not support offset");
}
return this;
}
if (queryBlock instanceof OracleSelectQueryBlock) {
OracleSelectQueryBlock oracleQueryBlock = (OracleSelectQueryBlock) queryBlock;
if (offset <= 0) {
SQLExpr rowCountExpr = new SQLIntegerExpr(rowCount);
SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanAnd, rowCountExpr, false, oracleQueryBlock.getWhere());
queryBlock.setWhere(newCondition);
} else {
throw new UnsupportedOperationException("not support offset");
}
return this;
}
if (queryBlock instanceof OdpsSelectQueryBlock) {
OdpsSelectQueryBlock odpsQueryBlock = (OdpsSelectQueryBlock) queryBlock;
if (offset > 0) {
throw new UnsupportedOperationException("not support offset");
}
odpsQueryBlock.setLimit(new SQLLimit(new SQLIntegerExpr(rowCount)));
return this;
}
throw new UnsupportedOperationException();
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock in project druid by alibaba.
the class SQLSelectBuilderImpl method whereOr.
@Override
public SQLSelectBuilderImpl whereOr(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanOr, exprObj, false, queryBlock.getWhere());
queryBlock.setWhere(newCondition);
return this;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock in project druid by alibaba.
the class SQLSelectBuilderImpl method where.
@Override
public SQLSelectBuilderImpl where(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
queryBlock.setWhere(exprObj);
return this;
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock in project druid by alibaba.
the class SQLSelectBuilderImpl method whereAnd.
@Override
public SQLSelectBuilderImpl whereAnd(String expr) {
SQLSelectQueryBlock queryBlock = getQueryBlock();
SQLExpr exprObj = SQLUtils.toSQLExpr(expr, dbType);
SQLExpr newCondition = SQLUtils.buildCondition(SQLBinaryOperator.BooleanAnd, exprObj, false, queryBlock.getWhere());
queryBlock.setWhere(newCondition);
return this;
}
Aggregations