This commit is contained in:
wenshao
2017-12-13 13:39:22 +08:00
12 changed files with 212 additions and 100 deletions
@@ -0,0 +1,29 @@
package com.alibaba.druid.bvt.sql.mysql.createTable;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import org.junit.Assert;
import java.util.List;
public class MySqlCreateTableTest92 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE `test` (\n"
+ " `id` bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT 'id',\n"
+ " `c_set` set('a','b','c') COMMENT 'set',\n" + " PRIMARY KEY (`id`)\n"
+ ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='10000000';";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
MySqlCreateTableStatement statemen = (MySqlCreateTableStatement)statementList.get(0);
Assert.assertEquals(1, statementList.size());
Assert.assertEquals(3, statemen.getTableElementList().size());
Assert.assertEquals("`c_set` set('a', 'b', 'c') COMMENT 'set'", SQLUtils.toMySqlString(statemen.getTableElementList().get(1)));
}
}
@@ -16,6 +16,7 @@
package com.alibaba.druid.bvt.sql.mysql.param;
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
import com.alibaba.druid.sql.visitor.VisitorFeature;
import com.alibaba.druid.util.JdbcConstants;
import junit.framework.TestCase;
@@ -40,4 +41,23 @@ public class SQL_Parser_Parameterize_Test extends TestCase {
assertEquals(102, outParameters.get(1));
assertEquals("wenshao", outParameters.get(2));
}
public void test_parameterized_2() throws Exception {
final String dbType = JdbcConstants.MYSQL;
List<Object> outParameters = new ArrayList<Object>();
String sql = "select * from t where id = 101 or id in (1,2,3,4)";
String psql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType, null, outParameters, VisitorFeature.OutputParameterizedQuesUnMergeInList);
assertEquals("SELECT *\n" +
"FROM t\n" +
"WHERE id = ?\n" +
"\tOR id IN ( ?, ?, ?, ?)", psql);
assertEquals(5, outParameters.size());
assertEquals(101, outParameters.get(0));
assertEquals(1, outParameters.get(1));
assertEquals(2, outParameters.get(2));
assertEquals(3, outParameters.get(3));
assertEquals(4, outParameters.get(4));
}
}