Skip to content

Commit

Permalink
Merge pull request alibaba#643 from yakolee/master
Browse files Browse the repository at this point in the history
improve sqlwall
  • Loading branch information
yakolee committed Sep 5, 2014
2 parents dab8f15 + 959e525 commit e6eddc5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement

private List<SQLCommentHint> hints = new ArrayList<SQLCommentHint>();

private List<SQLCommentHint> optionHints = new ArrayList<SQLCommentHint>();

private SQLExprTableSource like;

public MySqlCreateTableStatement(){
Expand Down Expand Up @@ -156,4 +158,12 @@ public void accept0(MySqlASTVisitor visitor) {
}

}

public List<SQLCommentHint> getOptionHints() {
return optionHints;
}

public void setOptionHints(List<SQLCommentHint> optionHints) {
this.optionHints = optionHints;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ public MySqlCreateTableStatement parseCrateTable(boolean acceptCreate) {
SQLSelect query = new MySqlSelectParser(this.exprParser).select();
stmt.setQuery(query);
}


while (lexer.token() == (Token.HINT)) {
this.exprParser.parseHints(stmt.getOptionHints());
}
return stmt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ public boolean visit(MySqlCreateTableStatement x) {
decrementIndent();
}

for (SQLCommentHint hint : x.getOptionHints()) {
print(' ');
hint.accept(this);
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@ public void test_true_8() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(sql)); //
}

public void test_true_9() throws Exception {
WallConfig config = new WallConfig();
config.setHintAllow(true);
config.setMultiStatementAllow(true);
String sql = "CREATE TABLE `session` ("//
+ " `sess_id` varchar(128) NOT NULL,"//
+ " `created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',"//
+ " `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',"//
+ " `ip` varchar(40) NOT NULL,"//
+ " `vars` mediumtext NOT NULL,"//
+ " PRIMARY KEY(`sess_id`),"//
+ " INDEX `changed_index` (`changed`)"//
+ ") /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */ ";
Assert.assertTrue(WallUtils.isValidateMySql(sql, config)); //
}
}

0 comments on commit e6eddc5

Please sign in to comment.