mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql parser enhance
This commit is contained in:
@@ -9,12 +9,12 @@ import junit.framework.TestCase;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDescribeStatement;
|
||||
<<<<<<< HEAD
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement;
|
||||
=======
|
||||
>>>>>>> fc222e6172fe4786fb2c68d21d9ef79937042e92
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowAuthorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinaryLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -123,7 +123,6 @@ public class DALParserTest extends TestCase {
|
||||
Assert.assertEquals("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", output);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public void test_setNames() throws Exception {
|
||||
String sql = "SET names default ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -169,76 +168,35 @@ public class DALParserTest extends TestCase {
|
||||
Assert.assertEquals("SET CHARACTER SET DEFAULT", output);
|
||||
}
|
||||
|
||||
=======
|
||||
// public void testSet() throws Exception {
|
||||
//
|
||||
//
|
||||
// sql = "SET names default ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// set = (DALSetNamesStatement) parser.set();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(set, sql);
|
||||
// Assert.assertEquals("SET NAMES DEFAULT", output);
|
||||
//
|
||||
// sql = "SET NAMEs 'utf8' collatE \"latin1_danish_ci\" ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// set = (DALSetNamesStatement) parser.set();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(set, sql);
|
||||
// Assert.assertEquals("SET NAMES utf8 COLLATE latin1_danish_ci", output);
|
||||
//
|
||||
// sql = "SET NAMEs utf8 ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// set = (DALSetNamesStatement) parser.set();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(set, sql);
|
||||
// Assert.assertEquals("SET NAMES utf8", output);
|
||||
//
|
||||
// sql = "SET CHARACTEr SEt 'utf8' ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// set = (DALSetCharacterSetStatement) parser.set();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(set, sql);
|
||||
// Assert.assertEquals("SET CHARACTER SET utf8", output);
|
||||
//
|
||||
// sql = "SET CHARACTEr SEt DEFaULT ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// set = (DALSetCharacterSetStatement) parser.set();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(set, sql);
|
||||
// Assert.assertEquals("SET CHARACTER SET DEFAULT", output);
|
||||
// }
|
||||
>>>>>>> fc222e6172fe4786fb2c68d21d9ef79937042e92
|
||||
public void test_show_authors() throws Exception {
|
||||
String sql = "shoW authors ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowAuthorsStatement show = (MySqlShowAuthorsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW AUTHORS", output);
|
||||
}
|
||||
|
||||
public void test_show_binaryLogs() throws Exception {
|
||||
String sql = "SHOW BINARY LOGS ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowBinaryLogsStatement show = (MySqlShowBinaryLogsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW BINARY LOGS", output);
|
||||
}
|
||||
|
||||
public void test_show_masterLogs() throws Exception {
|
||||
String sql = "SHOW MASTER LOGS ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowMasterLogsStatement show = (MySqlShowMasterLogsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW MASTER LOGS", output);
|
||||
}
|
||||
|
||||
//
|
||||
// public void testShow() throws Exception {
|
||||
// String sql = "shoW authors ";
|
||||
// SQLLexer lexer = new SQLLexer(sql);
|
||||
// DALParser parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// DALShowStatement show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// String output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW AUTHORS", output);
|
||||
//
|
||||
// sql = "SHOW BINARY LOGS ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW BINARY LOGS", output);
|
||||
//
|
||||
// sql = "SHOW MASTER LOGS ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW BINARY LOGS", output);
|
||||
//
|
||||
// sql = "SHOW binlog events in 'a' from 1 limit 1,2 ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
|
||||
Reference in New Issue
Block a user