use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project Mycat-Server by MyCATApache.
the class PageSQLUtil method convertLimitToNativePageSql.
public static String convertLimitToNativePageSql(String dbType, String sql, int offset, int count) {
if (JdbcConstants.ORACLE.equalsIgnoreCase(dbType)) {
OracleStatementParser oracleParser = new OracleStatementParser(sql);
SQLSelectStatement oracleStmt = (SQLSelectStatement) oracleParser.parseStatement();
return PagerUtils.limit(oracleStmt.getSelect(), JdbcConstants.ORACLE, offset, count);
} else if (JdbcConstants.SQL_SERVER.equalsIgnoreCase(dbType)) {
SQLServerStatementParser oracleParser = new SQLServerStatementParser(sql);
SQLSelectStatement sqlserverStmt = (SQLSelectStatement) oracleParser.parseStatement();
SQLSelect select = sqlserverStmt.getSelect();
SQLOrderBy orderBy = select.getOrderBy();
if (orderBy == null) {
SQLSelectQuery sqlSelectQuery = select.getQuery();
if (sqlSelectQuery instanceof SQLServerSelectQueryBlock) {
SQLServerSelectQueryBlock sqlServerSelectQueryBlock = (SQLServerSelectQueryBlock) sqlSelectQuery;
SQLTableSource from = sqlServerSelectQueryBlock.getFrom();
if ("limit".equalsIgnoreCase(from.getAlias())) {
from.setAlias(null);
}
}
SQLOrderBy newOrderBy = new SQLOrderBy(new SQLIdentifierExpr("(select 0)"));
select.setOrderBy(newOrderBy);
}
return PagerUtils.limit(select, JdbcConstants.SQL_SERVER, offset, count);
} else if (JdbcConstants.DB2.equalsIgnoreCase(dbType)) {
DB2StatementParser db2Parser = new DB2StatementParser(sql);
SQLSelectStatement db2Stmt = (SQLSelectStatement) db2Parser.parseStatement();
return limitDB2(db2Stmt.getSelect(), JdbcConstants.DB2, offset, count);
} else if (JdbcConstants.POSTGRESQL.equalsIgnoreCase(dbType)) {
PGSQLStatementParser pgParser = new PGSQLStatementParser(sql);
SQLSelectStatement pgStmt = (SQLSelectStatement) pgParser.parseStatement();
SQLSelect select = pgStmt.getSelect();
SQLSelectQuery query = select.getQuery();
if (query instanceof PGSelectQueryBlock) {
PGSelectQueryBlock pgSelectQueryBlock = (PGSelectQueryBlock) query;
pgSelectQueryBlock.setOffset(null);
pgSelectQueryBlock.setLimit(null);
}
return PagerUtils.limit(select, JdbcConstants.POSTGRESQL, offset, count);
} else if (JdbcConstants.MYSQL.equalsIgnoreCase(dbType)) {
MySqlStatementParser pgParser = new MySqlStatementParser(sql);
SQLSelectStatement pgStmt = (SQLSelectStatement) pgParser.parseStatement();
SQLSelect select = pgStmt.getSelect();
SQLSelectQuery query = select.getQuery();
if (query instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock pgSelectQueryBlock = (MySqlSelectQueryBlock) query;
pgSelectQueryBlock.setLimit(null);
}
return PagerUtils.limit(select, JdbcConstants.MYSQL, offset, count);
}
return sql;
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class Issue_685 method test_for_issue.
public void test_for_issue() throws Exception {
OracleStatementParser parser = new OracleStatementParser("select upper(*) from aa order by now()");
SQLStatement st = parser.parseStatement();
st.toString();
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class MySqlParameterizedOutputVisitorTest method validateOracle.
void validateOracle(String sql, String expect) {
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
Assert.assertEquals(1, statementList.size());
StringBuilder out = new StringBuilder();
OracleParameterizedOutputVisitor visitor = new OracleParameterizedOutputVisitor(out, false);
stmt.accept(visitor);
Assert.assertTrue(visitor.getReplaceCount() > 0);
Assert.assertEquals(expect, out.toString());
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class CallTest method test_select.
public void test_select() throws Exception {
String sql = "call dbms_session.set_identifier('nfs_special_syncview')";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
output(statementList);
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class LargeOrTest method test_largeOr.
public void test_largeOr() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("SELECT 1 FROM T WHERE ID = ?");
for (int i = 0; i < 10000; ++i) {
buf.append(" OR ID = ?");
}
String sql = buf.toString();
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
SQLBinaryOpExpr where = (SQLBinaryOpExpr) select.getWhere();
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getRight();
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
}
Aggregations