mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge branch 'master' of https://github.com/alibaba/druid
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by szf on 2017/11/16.
|
||||
*/
|
||||
public class MysqlCreateTableTest {
|
||||
public class MysqlVarantRefTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
@@ -28,8 +28,8 @@ public class MysqlCreateTableTest {
|
||||
|
||||
SQLVariantRefExpr resultExpr = (SQLVariantRefExpr)result.getItems().get(0).getTarget();
|
||||
SQLVariantRefExpr resultExpr2 = (SQLVariantRefExpr)result.getItems().get(1).getTarget();
|
||||
Assert.assertTrue(resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr.isSession());
|
||||
Assert.assertTrue(resultExpr2.isSession());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ public class MysqlCreateTableTest {
|
||||
|
||||
MySqlSetTransactionStatement x = (MySqlSetTransactionStatement)stmtList.get(0);
|
||||
|
||||
Assert.assertTrue(x.getHasSessionBefore());
|
||||
Assert.assertTrue(x.getSession());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +65,7 @@ public class MysqlCreateTableTest {
|
||||
|
||||
MySqlSetTransactionStatement x = (MySqlSetTransactionStatement)stmtList.get(0);
|
||||
|
||||
Assert.assertTrue(x.getHasSessionBefore()==null);
|
||||
Assert.assertTrue(x.getSession() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,8 +78,8 @@ public class MysqlCreateTableTest {
|
||||
|
||||
SQLVariantRefExpr resultExpr = (SQLVariantRefExpr)result.getItems().get(0).getTarget();
|
||||
SQLVariantRefExpr resultExpr2 = (SQLVariantRefExpr)result.getItems().get(1).getTarget();
|
||||
Assert.assertTrue(resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr.isSession());
|
||||
Assert.assertTrue(!resultExpr2.isSession());
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ public class MysqlCreateTableTest {
|
||||
|
||||
SQLVariantRefExpr resultExpr = (SQLVariantRefExpr)result.getItems().get(0).getTarget();
|
||||
SQLVariantRefExpr resultExpr2 = (SQLVariantRefExpr)result.getItems().get(1).getTarget();
|
||||
Assert.assertTrue(!resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr.isSession());
|
||||
Assert.assertTrue(!resultExpr2.isSession());
|
||||
}
|
||||
|
||||
|
||||
@@ -108,8 +108,8 @@ public class MysqlCreateTableTest {
|
||||
|
||||
SQLVariantRefExpr resultExpr = (SQLVariantRefExpr)result.getItems().get(0).getTarget();
|
||||
SQLVariantRefExpr resultExpr2 = (SQLVariantRefExpr)result.getItems().get(1).getTarget();
|
||||
Assert.assertTrue(!resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr.isSession());
|
||||
Assert.assertTrue(resultExpr2.isSession());
|
||||
}
|
||||
|
||||
|
||||
@@ -124,9 +124,9 @@ public class MysqlCreateTableTest {
|
||||
SQLVariantRefExpr resultExpr = (SQLVariantRefExpr)result.getItems().get(0).getTarget();
|
||||
SQLVariantRefExpr resultExpr2 = (SQLVariantRefExpr)result.getItems().get(1).getTarget();
|
||||
SQLVariantRefExpr resultExpr3 = (SQLVariantRefExpr)result.getItems().get(2).getTarget();
|
||||
Assert.assertTrue(!resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr3.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr.isSession());
|
||||
Assert.assertTrue(resultExpr2.isSession());
|
||||
Assert.assertTrue(resultExpr3.isSession());
|
||||
}
|
||||
|
||||
|
||||
@@ -143,11 +143,11 @@ public class MysqlCreateTableTest {
|
||||
SQLVariantRefExpr resultExpr3 = (SQLVariantRefExpr)result.getItems().get(2).getTarget();
|
||||
SQLVariantRefExpr resultExpr4 = (SQLVariantRefExpr)result.getItems().get(3).getTarget();
|
||||
SQLVariantRefExpr resultExpr5 = (SQLVariantRefExpr)result.getItems().get(4).getTarget();
|
||||
Assert.assertTrue(!resultExpr.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr2.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr3.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr4.isHasSessionBefore());
|
||||
Assert.assertTrue(resultExpr5.isHasSessionBefore());
|
||||
Assert.assertTrue(!resultExpr.isSession());
|
||||
Assert.assertTrue(resultExpr2.isSession());
|
||||
Assert.assertTrue(resultExpr3.isSession());
|
||||
Assert.assertTrue(!resultExpr4.isSession());
|
||||
Assert.assertTrue(resultExpr5.isSession());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user