Search in sources :

Example 1 with DALShowStatement

use of com.alibaba.cobar.parser.ast.stmt.dal.DALShowStatement in project cobar by alibaba.

the class MySQLDALParserTest method testShow.

public void testShow() throws Exception {
    String sql = "shoW authors  ";
    MySQLLexer lexer = new MySQLLexer(sql);
    MySQLDALParser parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    DALShowStatement show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    String output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW AUTHORS", output);
    sql = "SHOW BINARY LOGS  ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW BINARY LOGS", output);
    sql = "SHOW MASTER LOGS  ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW BINARY LOGS", output);
    sql = "SHOW binlog events in 'a' from 1 limit 1,2  ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW BINLOG EVENTS IN 'a' FROM 1 LIMIT 1, 2", output);
    sql = "SHOW binlog events from 1 limit 1,2  ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW BINLOG EVENTS FROM 1 LIMIT 1, 2", output);
    sql = "SHOW binlog events ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW BINLOG EVENTS", output);
    sql = "SHOW CHARACTER SET like 'var' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CHARACTER SET LIKE 'var'", output);
    sql = "SHOW CHARACTER SET where (select a from tb)in(a) ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CHARACTER SET WHERE (SELECT a FROM tb) IN (a)", output);
    sql = "SHOW CHARACTER SET ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CHARACTER SET", output);
    sql = "SHOW collation ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COLLATION", output);
    sql = "SHOW Collation like 'var1' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COLLATION LIKE 'var1'", output);
    sql = "SHOW collation where avg((select * from (tb1,tb2)))!=100 ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COLLATION WHERE AVG(SELECT * FROM tb1, tb2) != 100", output);
    sql = "SHOW full columns from tb1 from db1 like 'var' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL COLUMNS FROM db1.tb1 LIKE 'var'", output);
    sql = "SHOW full columns from tb1 from db1 where count(col)>10 ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL COLUMNS FROM db1.tb1 WHERE COUNT(col) > 10", output);
    sql = "SHOW columns from tb1 from db1 like 'var' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COLUMNS FROM db1.tb1 LIKE 'var'", output);
    sql = "SHOW columns from tb1 like 'var' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COLUMNS FROM tb1 LIKE 'var'", output);
    sql = "SHOW full columns from tb1 from db1 ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL COLUMNS FROM db1.tb1", output);
    sql = "SHOW contributors ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CONTRIBUTORS", output);
    sql = "SHOW CREATE DATABASE db_name ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE DATABASE db_name", output);
    sql = "SHOW create event expr ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE EVENT expr", output);
    sql = "SHOW create function func ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE FUNCTION func", output);
    sql = "SHOW create procedure pro ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE PROCEDURE pro", output);
    sql = "SHOW create table tb ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE TABLE tb", output);
    sql = "SHOW create trigger tri ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE TRIGGER tri", output);
    sql = "SHOW create view view";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW CREATE VIEW view", output);
    sql = "SHOW databases like 'var'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW DATABASES LIKE 'var'", output);
    sql = "SHOW databases where (select * from `select`)is not null";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW DATABASES WHERE (SELECT * FROM `select`) IS NOT NULL", output);
    sql = "SHOW databases ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW DATABASES", output);
    sql = "SHOW engine innodb status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ENGINE INNODB STATUS", output);
    sql = "SHOW engine innodb mutex";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ENGINE INNODB MUTEX", output);
    sql = "SHOW engine performance_schema status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ENGINE PERFORMANCE SCHEMA STATUS", output);
    sql = "SHOW engines";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ENGINES", output);
    sql = "SHOW storage engines";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ENGINES", output);
    sql = "SHOW errors";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ERRORS", output);
    sql = "SHOW errors limit 1 ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW ERRORS LIMIT 0, 1", output);
    sql = "SHOW count(*) errors";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COUNT(*) ERRORS", output);
    sql = "SHOW events";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW EVENTS", output);
    sql = "SHOW events from expr like 'var' ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW EVENTS FROM expr LIKE 'var'", output);
    sql = "SHOW events from expr where expr1";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW EVENTS FROM expr WHERE expr1", output);
    sql = "SHOW function code expr";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FUNCTION CODE expr", output);
    sql = "SHOW function status like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FUNCTION STATUS LIKE 'expr'", output);
    sql = "SHOW function status where a is true";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FUNCTION STATUS WHERE a IS TRUE", output);
    sql = "SHOW function status ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FUNCTION STATUS", output);
    sql = "SHOW grants for 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GRANTS FOR 'expr'", output);
    sql = "SHOW grants";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GRANTS", output);
    sql = "SHOW index from tb1 from db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW INDEX IN db.tb1", output);
    sql = "SHOW index from tb1 in db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW INDEX IN db.tb1", output);
    sql = "SHOW index in tb1 from db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW INDEX IN db.tb1", output);
    sql = "SHOW index in tb1 in db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW INDEX IN db.tb1", output);
    sql = "SHOW indexes from tb1";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW INDEXES IN tb1", output);
    sql = "SHOW keys in tb1";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW KEYS IN tb1", output);
    sql = "SHOW master status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW MASTER STATUS", output);
    sql = "SHOW open tables from db like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW OPEN TABLES FROM db LIKE 'expr'", output);
    sql = "SHOW open tables from db where tb is not null";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW OPEN TABLES FROM db WHERE tb IS NOT NULL", output);
    sql = "SHOW open tables from db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW OPEN TABLES FROM db", output);
    sql = "SHOW open tables in db";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW OPEN TABLES FROM db", output);
    sql = "SHOW open tables";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW OPEN TABLES", output);
    sql = "SHOW plugins";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PLUGINS", output);
    sql = "SHOW privileges";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PRIVILEGES", output);
    sql = "SHOW procedure code proc";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROCEDURE CODE proc", output);
    sql = "SHOW procedure status like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROCEDURE STATUS LIKE 'expr'", output);
    sql = "SHOW procedure status where (a||b)*(a&&b)";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROCEDURE STATUS WHERE (a OR b) * (a AND b)", output);
    sql = "SHOW procedure status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROCEDURE STATUS", output);
    sql = "SHOW processlist";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROCESSLIST", output);
    sql = "SHOW full processlist";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL PROCESSLIST", output);
    sql = "SHOW profiles";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROFILES", output);
    sql = "SHOW profile all,block io,context switches,cpu,ipc,memory," + "page faults,source,swaps for query 2 limit 1 offset 2";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROFILE ALL, BLOCK IO, CONTEXT SWITCHES, CPU, IPC, MEMORY, " + "PAGE FAULTS, SOURCE, SWAPS FOR QUERY 2 LIMIT 2, 1", output);
    sql = "SHOW profile";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROFILE", output);
    sql = "SHOW profile all,block io,context switches,cpu,ipc," + "memory,page faults,source,swaps for query 2";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROFILE ALL, BLOCK IO, CONTEXT SWITCHES, CPU, IPC, " + "MEMORY, PAGE FAULTS, SOURCE, SWAPS FOR QUERY 2", output);
    sql = "SHOW profile all for query 2";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW PROFILE ALL FOR QUERY 2", output);
    sql = "SHOW slave hosts";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SLAVE HOSTS", output);
    sql = "SHOW slave status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SLAVE STATUS", output);
    sql = "SHOW global status like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL STATUS LIKE 'expr'", output);
    sql = "SHOW global status where ${abc}";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL STATUS WHERE ${abc}", output);
    sql = "SHOW session status like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS LIKE 'expr'", output);
    sql = "SHOW session status where ?";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS WHERE ?", output);
    sql = "SHOW status like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS LIKE 'expr'", output);
    sql = "SHOW status where 0b10^b'11'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS WHERE b'10' ^ b'11'", output);
    sql = "SHOW status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS", output);
    sql = "SHOW global status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL STATUS", output);
    sql = "SHOW session status";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION STATUS", output);
    sql = "SHOW table status from db like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLE STATUS FROM db LIKE 'expr'", output);
    sql = "SHOW table status in db where (select a)>(select b)";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLE STATUS FROM db WHERE (SELECT a) > (SELECT b)", output);
    sql = "SHOW table status from db where id1=a||b";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLE STATUS FROM db WHERE id1 = a OR b", output);
    sql = "SHOW table status ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLE STATUS", output);
    sql = "SHOW tables from db like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLES FROM db LIKE 'expr'", output);
    sql = "SHOW tables in db where !a";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLES FROM db WHERE ! a", output);
    sql = "SHOW tables like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLES LIKE 'expr'", output);
    sql = "SHOW tables where log((select a))=b";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLES WHERE LOG(SELECT a) = b", output);
    sql = "SHOW tables ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TABLES", output);
    sql = "SHOW full tables from db like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL TABLES FROM db LIKE 'expr'", output);
    sql = "SHOW full tables in db where id1=abs((select a))";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL TABLES FROM db WHERE id1 = ABS(SELECT a)", output);
    sql = "SHOW full tables ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW FULL TABLES", output);
    sql = "SHOW triggers from db like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TRIGGERS FROM db LIKE 'expr'", output);
    sql = "SHOW triggers in db where strcmp('test1','test2')";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TRIGGERS FROM db WHERE STRCMP('test1', 'test2')", output);
    sql = "SHOW triggers ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW TRIGGERS", output);
    sql = "SHOW global variables like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL VARIABLES LIKE 'expr'", output);
    sql = "SHOW global variables where ~a is null";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL VARIABLES WHERE ~ a IS NULL", output);
    sql = "SHOW session variables like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES LIKE 'expr'", output);
    sql = "SHOW session variables where a*b+1=c";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES WHERE a * b + 1 = c", output);
    sql = "SHOW variables like 'expr'";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES LIKE 'expr'", output);
    sql = "SHOW variables where a&&b";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES WHERE a AND b", output);
    sql = "SHOW variables";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES", output);
    sql = "SHOW global variables";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW GLOBAL VARIABLES", output);
    sql = "SHOW session variables";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW SESSION VARIABLES", output);
    sql = "SHOW warnings limit 1,2 ";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW WARNINGS LIMIT 1, 2", output);
    sql = "SHOW warnings";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW WARNINGS", output);
    sql = "SHOW count(*) warnings";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
    show = (DALShowStatement) parser.show();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(show, sql);
    Assert.assertEquals("SHOW COUNT(*) WARNINGS", output);
}
Also used : MySQLLexer(com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer) DALShowStatement(com.alibaba.cobar.parser.ast.stmt.dal.DALShowStatement)

Aggregations

DALShowStatement (com.alibaba.cobar.parser.ast.stmt.dal.DALShowStatement)1 MySQLLexer (com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer)1