Skip to content

Commit 12ff225

Browse files
committed
proof of correct parsing for #829
1 parent a416b96 commit 12ff225

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import java.util.StringTokenizer;
1919
import net.sf.jsqlparser.JSQLParserException;
2020
import net.sf.jsqlparser.parser.CCJSqlParserManager;
21+
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
2122
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
2223
import net.sf.jsqlparser.statement.create.table.CreateTable;
2324
import net.sf.jsqlparser.statement.create.table.Index;
2425
import net.sf.jsqlparser.test.TestException;
2526
import static net.sf.jsqlparser.test.TestUtils.*;
2627
import static org.junit.Assert.assertEquals;
2728
import static org.junit.Assert.assertFalse;
29+
import static org.junit.Assert.assertNotNull;
2830
import static org.junit.Assert.assertTrue;
2931
import org.junit.Test;
3032

@@ -552,4 +554,19 @@ public void testCreateTableIssue830() throws JSQLParserException {
552554
public void testCreateTableIssue830_2() throws JSQLParserException {
553555
assertSqlCanBeParsedAndDeparsed("CREATE TABLE testyesr (id int, yy year, mm month, dd day)");
554556
}
557+
558+
@Test
559+
public void testSettingCharacterSetIssue829() throws JSQLParserException {
560+
String sql = "CREATE TABLE test (id int (11) NOT NULL, name varchar (64) CHARACTER SET GBK NOT NULL, age int (11) NOT NULL, score decimal (8, 2) DEFAULT NULL, description varchar (64) DEFAULT NULL, creationDate datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id)) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4";
561+
assertSqlCanBeParsedAndDeparsed(sql);
562+
CreateTable stmt = (CreateTable) CCJSqlParserUtil.parse(sql);
563+
564+
ColumnDefinition colName = stmt.getColumnDefinitions().stream()
565+
.filter(col -> col.getColumnName().equals("name"))
566+
.findFirst().orElse(null);
567+
568+
assertNotNull(colName);
569+
570+
assertEquals("GBK", colName.getColDataType().getCharacterSet());
571+
}
555572
}

0 commit comments

Comments
 (0)