mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -357,9 +357,11 @@ public class MySqlLexer extends Lexer {
|
||||
token = LITERAL_CHARS;
|
||||
break;
|
||||
} else {
|
||||
initBuff(bufPos);
|
||||
arraycopy(mark + 1, buf, 0, bufPos);
|
||||
hasSpecial = true;
|
||||
if (!hasSpecial) {
|
||||
initBuff(bufPos);
|
||||
arraycopy(mark + 1, buf, 0, bufPos);
|
||||
hasSpecial = true;
|
||||
}
|
||||
putChar('\'');
|
||||
continue;
|
||||
}
|
||||
@@ -378,7 +380,6 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
|
||||
if (!hasSpecial) {
|
||||
stringVal = "";
|
||||
stringVal = subString(mark + 1, bufPos);
|
||||
} else {
|
||||
stringVal = new String(buf, 0, bufPos);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alibaba.druid.bvt.bug;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
|
||||
public class Issue_697 extends TestCase {
|
||||
|
||||
public void test_for_issue() throws Exception {
|
||||
String sql = "insert into tag_rule_detail(id, gmt_create, gmt_modified, group_id, priority, rule_condition, rule_action) values(1010102, now(), now(), 10101, 0, 'flow=''trustLogin''', 'be:login,dev:pc, env:web, type:trust_login, from:$loginfrom, result:true') ;\n"
|
||||
+ "insert into tag_rule_detail(id, gmt_create, gmt_modified, group_id, priority, rule_condition, rule_action) values(1010103, now(), now(), 10101, 0, 'flow=''Ctr''', 'be:login,dev:pc, env:web, type:ctr, from:$loginfrom, result:true') ;";
|
||||
|
||||
String expected = "INSERT INTO tag_rule_detail (id, gmt_create, gmt_modified, group_id, priority"
|
||||
+ "\n\t, rule_condition, rule_action)"
|
||||
+ "\nVALUES (1010102, now(), now(), 10101, 0"
|
||||
+ "\n\t, 'flow=''trustLogin''', 'be:login,dev:pc, env:web, type:trust_login, from:$loginfrom, result:true');"
|
||||
+ "\nINSERT INTO tag_rule_detail (id, gmt_create, gmt_modified, group_id, priority"
|
||||
+ "\n\t, rule_condition, rule_action)"
|
||||
+ "\nVALUES (1010103, now(), now(), 10101, 0"
|
||||
+ "\n\t, 'flow=''Ctr''', 'be:login,dev:pc, env:web, type:ctr, from:$loginfrom, result:true');\n";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
MySqlOutputVisitor visitor = new MySqlOutputVisitor(out);
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
for (SQLStatement statement : statementList) {
|
||||
statement.accept(visitor);
|
||||
visitor.print(";");
|
||||
visitor.println();
|
||||
}
|
||||
|
||||
System.out.println(out.toString());
|
||||
|
||||
Assert.assertEquals(expected, out.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user