-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #787 from bucketli/master
fix create table varchar binary bug and binary(10) bug
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/java/com/alibaba/druid/bvt/sql/mysql/MySqlCreateTableTest57.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 1999-2011 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.bvt.sql.mysql; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
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.parser.MySqlStatementParser; | ||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor; | ||
|
||
public class MySqlCreateTableTest57 extends MysqlTest { | ||
|
||
@Test | ||
public void test_one() throws Exception { | ||
String sql = "CREATE TABLE `t_cpi_driskconfig_bak` (" + "`Sequence` bigint(20) NOT NULL AUTO_INCREMENT," | ||
+ "`comcode` varchar(20) binary NOT NULL," + "`riskcode` varchar(10) binary NOT NULL," | ||
+ "`configcodehead` varchar(30) binary NOT NULL," + "`configcodebody` varchar(100) binary," | ||
+ "`configvalue` varchar(200) binary ," + "`inputdate` datetime NOT NULL," | ||
+ "`validstatus` char(1) NOT NULL," + "`remark` varchar(3000)," + "`flag` varchar(10) ," | ||
+ "PRIMARY KEY (`Sequence`)" + ") ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;"; | ||
|
||
MySqlStatementParser parser = new MySqlStatementParser(sql); | ||
SQLStatement stmt = parser.parseCreateTable(); | ||
|
||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor(); | ||
stmt.accept(visitor); | ||
|
||
System.out.println("Tables : " + visitor.getTables()); | ||
System.out.println("fields : " + visitor.getColumns()); | ||
System.out.println("coditions : " + visitor.getConditions()); | ||
|
||
Assert.assertEquals(1, visitor.getTables().size()); | ||
Assert.assertEquals(10, visitor.getColumns().size()); | ||
Assert.assertEquals(0, visitor.getConditions().size()); | ||
|
||
String output = SQLUtils.toMySqlString(stmt); | ||
Assert.assertEquals("CREATE TABLE `t_cpi_driskconfig_bak` (" + "\n\t`Sequence` bigint(20) AUTO_INCREMENT NOT NULL, " | ||
+ "\n\t`comcode` varchar(20) BINARY NOT NULL, " + "\n\t`riskcode` varchar(10) BINARY NOT NULL, " | ||
+ "\n\t`configcodehead` varchar(30) BINARY NOT NULL, " + "\n\t`configcodebody` varchar(100) BINARY , " | ||
+ "\n\t`configvalue` varchar(200) BINARY , " + "\n\t`inputdate` datetime NOT NULL, " | ||
+ "\n\t`validstatus` char(1) NOT NULL, " + "\n\t`remark` varchar(3000), " + "\n\t`flag` varchar(10), " | ||
+ "\n\tPRIMARY KEY (`Sequence`)" + "\n) ENGINE = InnoDB AUTO_INCREMENT = 49 CHARSET = utf8",output); | ||
|
||
} | ||
|
||
@Test | ||
public void test_two() throws Exception { | ||
String sql = "CREATE TABLE `t_cpi_driskconfig_bak` (" + "`Sequence` bigint(20) NOT NULL AUTO_INCREMENT," | ||
+ "`comcode` binary(20) NOT NULL," + "`riskcode` varchar(10) binary NOT NULL," | ||
+ "`configcodehead` varchar(30) binary NOT NULL," + "`configcodebody` varchar(100) binary," | ||
+ "`configvalue` varchar(200) binary ," + "`inputdate` datetime NOT NULL," | ||
+ "`validstatus` char(1) NOT NULL," + "`remark` varchar(3000)," + "`flag` varchar(10) ," | ||
+ "PRIMARY KEY (`Sequence`)" + ") ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;"; | ||
|
||
MySqlStatementParser parser = new MySqlStatementParser(sql); | ||
SQLStatement stmt = parser.parseCreateTable(); | ||
|
||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor(); | ||
stmt.accept(visitor); | ||
|
||
System.out.println("Tables : " + visitor.getTables()); | ||
System.out.println("fields : " + visitor.getColumns()); | ||
System.out.println("coditions : " + visitor.getConditions()); | ||
|
||
Assert.assertEquals(1, visitor.getTables().size()); | ||
Assert.assertEquals(10, visitor.getColumns().size()); | ||
Assert.assertEquals(0, visitor.getConditions().size()); | ||
|
||
String output = SQLUtils.toMySqlString(stmt); | ||
Assert.assertEquals("CREATE TABLE `t_cpi_driskconfig_bak` (" + "\n\t`Sequence` bigint(20) AUTO_INCREMENT NOT NULL, " | ||
+ "\n\t`comcode` binary(20) NOT NULL, " + "\n\t`riskcode` varchar(10) BINARY NOT NULL, " | ||
+ "\n\t`configcodehead` varchar(30) BINARY NOT NULL, " + "\n\t`configcodebody` varchar(100) BINARY , " | ||
+ "\n\t`configvalue` varchar(200) BINARY , " + "\n\t`inputdate` datetime NOT NULL, " | ||
+ "\n\t`validstatus` char(1) NOT NULL, " + "\n\t`remark` varchar(3000), " + "\n\t`flag` varchar(10), " | ||
+ "\n\tPRIMARY KEY (`Sequence`)" + "\n) ENGINE = InnoDB AUTO_INCREMENT = 49 CHARSET = utf8",output); | ||
|
||
} | ||
} |