use of com.alibaba.druid.sql.dialect.oracle.parser.OracleLexer in project druid by alibaba.
the class OracleCompatibleTest method test_compatibleTest.
public void test_compatibleTest() throws Exception {
// oracle ppas
String sql = "select * from t where rownum < 10";
OracleLexer lexer = new OracleLexer(sql);
for (; ; ) {
lexer.nextToken();
Token token = lexer.token();
if (token == Token.EOF) {
break;
}
if (token == Token.IDENTIFIER) {
System.out.println(lexer.stringVal());
} else if (token == Token.LITERAL_CHARS || token == Token.LITERAL_INT || token == Token.LITERAL_ALIAS) {
// skip
}
System.out.println(token);
}
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleLexer in project druid by alibaba.
the class OracleLexerTest method test_hint.
public void test_hint() throws Exception {
String sql = "SELECT /*+FIRST_ROWS*/ * FROM T WHERE F1 = ? ORDER BY F2";
OracleLexer lexer = new OracleLexer(sql);
for (; ; ) {
lexer.nextToken();
Token tok = lexer.token();
switch(tok) {
case IDENTIFIER:
System.out.println(tok.name() + "\t\t" + lexer.stringVal());
break;
case HINT:
System.out.println(tok.name() + "\t\t\t" + lexer.stringVal());
break;
default:
System.out.println(tok.name() + "\t\t\t" + tok.name);
break;
}
if (tok == Token.EOF) {
break;
}
}
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleLexer in project druid by alibaba.
the class OracleSelectTest86_comment method test_0.
public void test_0() throws Exception {
//
String sql = //
"/*sqlId=9f0szhacj63ag*/SELECT /*+rule*/ SYS_XMLGEN(VALUE(KU$), XMLFORMAT.createFormat2('TABLE_T', '7')), KU$.OBJ_NUM FROM SYS.KU$_HTABLE_VIEW KU$ WHERE NOT (BITAND (KU$.PROPERTY,8192)=8192) AND NOT BITAND(KU$.SCHEMA_OBJ.FLAGS,128)!=0 AND KU$.SCHEMA_OBJ.NAME=:NAME1 AND KU$.SCHEMA_OBJ.OWNER_NAME=:SCHEMA2";
System.out.println(sql);
OracleLexer lexer = new OracleLexer(sql);
lexer.config(SQLParserFeature.SkipComments, false);
lexer.nextToken();
String comment = lexer.stringVal();
assertEquals("/*sqlId=9f0szhacj63ag*/", comment);
OracleStatementParser parser = new OracleStatementParser(sql, SQLParserFeature.KeepComments);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
{
String text = SQLUtils.toOracleString(stmt);
assertEquals("/*sqlId=9f0szhacj63ag*/\n" + "SELECT /*+rule*/ SYS_XMLGEN(VALUE(KU$), XMLFORMAT.createFormat2('TABLE_T', '7'))\n" + "\t, KU$.OBJ_NUM\n" + "FROM SYS.KU$_HTABLE_VIEW KU$\n" + "WHERE (NOT BITAND(KU$.PROPERTY, 8192) = 8192)\n" + "\tAND (NOT BITAND(KU$.SCHEMA_OBJ.FLAGS, 128) != 0)\n" + "\tAND KU$.SCHEMA_OBJ.NAME = :NAME1\n" + "\tAND KU$.SCHEMA_OBJ.OWNER_NAME = :SCHEMA2", text);
}
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
assertEquals(1, visitor.getTables().size());
assertEquals(8, visitor.getColumns().size());
assertEquals(2, visitor.getConditions().size());
assertEquals(0, visitor.getRelationships().size());
assertEquals(0, visitor.getOrderByColumns().size());
// Assert.assertTrue(visitor.containsTable("sup_registration"));
// Assert.assertTrue(visitor.containsTable("sup_task"));
// Assert.assertTrue(visitor.containsTable("sys_org"));
//
// Assert.assertTrue(visitor.containsColumn("sup_task", "orgid"));
// Assert.assertTrue(visitor.containsColumn("sup_task", "orgid"));
//
}
Aggregations