mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -194,11 +194,7 @@ public class SQLSelectBuilderImpl implements SQLSelectBuilder {
|
||||
@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);
|
||||
queryBlock.addWhere(SQLUtils.toSQLExpr(expr, dbType));
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -222,86 +218,9 @@ public class SQLSelectBuilderImpl implements SQLSelectBuilder {
|
||||
|
||||
@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();
|
||||
getQueryBlock()
|
||||
.limit(rowCount, offset);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected SQLSelectQueryBlock getQueryBlock() {
|
||||
|
||||
Reference in New Issue
Block a user