Skip to content

Commit

Permalink
For issue #540.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed Jan 18, 2018
1 parent 5e1fce3 commit 6d0b926
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ public Optional<String> parseTableAlias() {

private TokenType[] getDefaultAvailableKeywordsForTableAlias() {
return new TokenType[] {
Literals.IDENTIFIER, Literals.CHARS, DefaultKeyword.TABLESPACE, DefaultKeyword.FUNCTION, DefaultKeyword.SEQUENCE, DefaultKeyword.OF, DefaultKeyword.DO,
DefaultKeyword.NO, DefaultKeyword.TEMPORARY, DefaultKeyword.TEMP, DefaultKeyword.COMMENT, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.ROW,
DefaultKeyword.STATEMENT, DefaultKeyword.EXECUTE, DefaultKeyword.BITMAP, DefaultKeyword.NOSORT, DefaultKeyword.REVERSE, DefaultKeyword.COMPILE,
DefaultKeyword.PASSWORD, DefaultKeyword.USER, DefaultKeyword.END, DefaultKeyword.CASE, DefaultKeyword.KEY, DefaultKeyword.INTERVAL, DefaultKeyword.CONSTRAINT, };
Literals.IDENTIFIER, Literals.CHARS, DefaultKeyword.SEQUENCE, DefaultKeyword.NO, DefaultKeyword.WITHOUT, DefaultKeyword.TEMPORARY,
DefaultKeyword.TEMP, DefaultKeyword.AFTER, DefaultKeyword.INSTEAD, DefaultKeyword.STATEMENT, DefaultKeyword.BITMAP, DefaultKeyword.NOSORT, DefaultKeyword.REVERSE,
DefaultKeyword.COMPILE, DefaultKeyword.ENABLE, DefaultKeyword.DISABLE, DefaultKeyword.NEW, DefaultKeyword.UNTIL, DefaultKeyword.ADVISE, DefaultKeyword.PASSWORD,
DefaultKeyword.LOCAL, DefaultKeyword.GLOBAL, DefaultKeyword.STORAGE, DefaultKeyword.DATA, DefaultKeyword.TIME, DefaultKeyword.BOOLEAN, DefaultKeyword.GREATEST,
DefaultKeyword.LEAST, DefaultKeyword.ROUND, DefaultKeyword.TRUNC, DefaultKeyword.POSITION, DefaultKeyword.LENGTH, DefaultKeyword.CHAR_LENGTH, DefaultKeyword.SUBSTRING,
DefaultKeyword.SUBSTR, DefaultKeyword.INSTR, DefaultKeyword.INITCAP, DefaultKeyword.UPPER, DefaultKeyword.LOWER, DefaultKeyword.TRIM,
};
}

protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() {

@Override
protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() {
return new TokenType[] {DefaultKeyword.LENGTH};
return new TokenType[]{
DefaultKeyword.VIEW, DefaultKeyword.FUNCTION, DefaultKeyword.OF, DefaultKeyword.DO, DefaultKeyword.COMMENT, DefaultKeyword.ROW, DefaultKeyword.EXECUTE, DefaultKeyword.MODIFY,
DefaultKeyword.VALIDATE, DefaultKeyword.USER, DefaultKeyword.IDENTIFIED, DefaultKeyword.TRUNCATE, DefaultKeyword.END, DefaultKeyword.FULL, DefaultKeyword.CLOSE, DefaultKeyword.CAST,
DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.OPEN, DefaultKeyword.OVER, DefaultKeyword.COALESCE, DefaultKeyword.VARCHAR2, DefaultKeyword.DATE, DefaultKeyword.ANY,
MySQLKeyword.OFFSET, MySQLKeyword.VALUE, MySQLKeyword.BEGIN, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT,
MySQLKeyword.FIRST, MySQLKeyword.ALGORITHM, MySQLKeyword.DISCARD, MySQLKeyword.IMPORT, MySQLKeyword.VALIDATION, MySQLKeyword.REORGANIZE, MySQLKeyword.EXCHANGE, MySQLKeyword.REBUILD,
MySQLKeyword.REPAIR, MySQLKeyword.UPGRADE, MySQLKeyword.KEY_BLOCK_SIZE, MySQLKeyword.AUTO_INCREMENT, MySQLKeyword.AVG_ROW_LENGTH, MySQLKeyword.CHECKSUM,
MySQLKeyword.COMPRESSION, MySQLKeyword.CONNECTION, MySQLKeyword.DIRECTORY, MySQLKeyword.DELAY_KEY_WRITE, MySQLKeyword.ENCRYPTION, MySQLKeyword.ENGINE, MySQLKeyword.INSERT_METHOD,
MySQLKeyword.MAX_ROWS, MySQLKeyword.MIN_ROWS, MySQLKeyword.PACK_KEYS, MySQLKeyword.ROW_FORMAT, MySQLKeyword.DYNAMIC, MySQLKeyword.FIXED, MySQLKeyword.COMPRESSED, MySQLKeyword.REDUNDANT,
MySQLKeyword.COMPACT, MySQLKeyword.STATS_AUTO_RECALC, MySQLKeyword.STATS_PERSISTENT, MySQLKeyword.STATS_SAMPLE_PAGES, MySQLKeyword.DISK, MySQLKeyword.MEMORY, MySQLKeyword.ROLLUP,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() {

@Override
protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() {
return new TokenType[0];
return new TokenType[] {
DefaultKeyword.SCHEMA, DefaultKeyword.DATABASE, DefaultKeyword.VIEW, DefaultKeyword.INDEX, DefaultKeyword.TRIGGER, DefaultKeyword.PROCEDURE, DefaultKeyword.FUNCTION,
DefaultKeyword.CURSOR, DefaultKeyword.OF, DefaultKeyword.WHILE, DefaultKeyword.BY, DefaultKeyword.COMMENT, DefaultKeyword.REPLACE, DefaultKeyword.BEFORE, DefaultKeyword.EACH,
DefaultKeyword.ROW, DefaultKeyword.EXECUTE, DefaultKeyword.FULLTEXT, DefaultKeyword.ALTER, DefaultKeyword.MODIFY, DefaultKeyword.IDENTIFIED,
DefaultKeyword.TRUNCATE, DefaultKeyword.INSERT, DefaultKeyword.VALUES, DefaultKeyword.UPDATE, DefaultKeyword.DELETE,
DefaultKeyword.USE, DefaultKeyword.DECLARE, DefaultKeyword.REVOKE, DefaultKeyword.CLOSE, DefaultKeyword.ESCAPE, DefaultKeyword.LOCK, DefaultKeyword.LEAVE, DefaultKeyword.ITERATE,
DefaultKeyword.REPEAT, DefaultKeyword.OPEN, DefaultKeyword.OUT, DefaultKeyword.INOUT, DefaultKeyword.OVER, DefaultKeyword.LOOP, DefaultKeyword.EXPLAIN, DefaultKeyword.COALESCE,
DefaultKeyword.CHAR, DefaultKeyword.CHARACTER, DefaultKeyword.VARYING, DefaultKeyword.VARCHAR, DefaultKeyword.VARCHAR2, DefaultKeyword.INTEGER, DefaultKeyword.INT,
DefaultKeyword.SMALLINT, DefaultKeyword.DECIMAL, DefaultKeyword.DEC, DefaultKeyword.NUMERIC, DefaultKeyword.FLOAT, DefaultKeyword.REAL, DefaultKeyword.DOUBLE, DefaultKeyword.PRECISION,
DefaultKeyword.DATE, DefaultKeyword.INTERVAL, DefaultKeyword.BLOB, DefaultKeyword.XOR, DefaultKeyword.BETWEEN, DefaultKeyword.EXISTS, DefaultKeyword.CONVERT, DefaultKeyword.KEY,
PostgreSQLKeyword.SHOW, PostgreSQLKeyword.FIRST, PostgreSQLKeyword.NEXT, PostgreSQLKeyword.LAST, PostgreSQLKeyword.RESTART, PostgreSQLKeyword.RECURSIVE, PostgreSQLKeyword.CURRENT,
PostgreSQLKeyword.NOWAIT, PostgreSQLKeyword.TYPE, PostgreSQLKeyword.UNLOGGED, PostgreSQLKeyword.CONTINUE, PostgreSQLKeyword.ROWS, PostgreSQLKeyword.SHARE,
PostgreSQLKeyword.IDENTITY, PostgreSQLKeyword.STATISTICS, PostgreSQLKeyword.PLAIN, PostgreSQLKeyword.EXTERNAL, PostgreSQLKeyword.EXTENDED, PostgreSQLKeyword.MAIN,
PostgreSQLKeyword.VALID, PostgreSQLKeyword.ALWAYS, PostgreSQLKeyword.RULE, PostgreSQLKeyword.OIDS, PostgreSQLKeyword.INHERIT,
PostgreSQLKeyword.OWNER, PostgreSQLKeyword.DEFERRED, PostgreSQLKeyword.IMMEDIATE, PostgreSQLKeyword.EXTRACT,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() {

@Override
protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() {
return new TokenType[0];
return new TokenType[] {
DefaultKeyword.DO, DefaultKeyword.TRUE, DefaultKeyword.FALSE, DefaultKeyword.COMMENT, DefaultKeyword.REPLACE, DefaultKeyword.BEFORE, DefaultKeyword.EACH, DefaultKeyword.ROW,
DefaultKeyword.FULLTEXT, DefaultKeyword.IDENTIFIED, DefaultKeyword.USING, DefaultKeyword.NATURAL, DefaultKeyword.CAST, DefaultKeyword.LOCK, DefaultKeyword.LEAVE,
DefaultKeyword.ITERATE, DefaultKeyword.REPEAT, DefaultKeyword.OUT, DefaultKeyword.INOUT, DefaultKeyword.LOOP, DefaultKeyword.EXPLAIN, DefaultKeyword.CHAR, DefaultKeyword.CHARACTER,
DefaultKeyword.VARCHAR, DefaultKeyword.VARCHAR2, DefaultKeyword.INTEGER, DefaultKeyword.INT, DefaultKeyword.SMALLINT, DefaultKeyword.DECIMAL, DefaultKeyword.DEC,
DefaultKeyword.NUMERIC, DefaultKeyword.FLOAT, DefaultKeyword.REAL, DefaultKeyword.PRECISION, DefaultKeyword.DATE, DefaultKeyword.INTERVAL, DefaultKeyword.BLOB,
DefaultKeyword.XOR, DefaultKeyword.BOTH, DefaultKeyword.LEADING, DefaultKeyword.TRAILING,
SQLServerKeyword.TIES, SQLServerKeyword.PARTITION, SQLServerKeyword.ONLY, SQLServerKeyword.OUTPUT, SQLServerKeyword.AUTO, SQLServerKeyword.TYPE, SQLServerKeyword.ELEMENTS,
SQLServerKeyword.XML, SQLServerKeyword.XSINIL, SQLServerKeyword.XMLSCHEMA, SQLServerKeyword.TYP, SQLServerKeyword.APPLY, SQLServerKeyword.REDUCE, SQLServerKeyword.REPLICATE,
SQLServerKeyword.EXTRACT, SQLServerKeyword.REDISTRIBUTE,
};
}
}
2 changes: 1 addition & 1 deletion sharding-jdbc-core/src/test/resources/sql/dql/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
<sql id="assertSelectWithUpperCaseBindingTableAndConfigTable" value="SELECT i.*,c.status c_status FROM T_ORDER o JOIN T_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id JOIN t_config c ON o.status = c.status WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s AND c.status = %s ORDER BY i.item_id" />
<sql id="assertSelectCountWithBindingTable" value="SELECT COUNT(*) AS items_count FROM t_order o, t_order_item i WHERE o.user_id = i.user_id AND o.order_id = i.order_id AND o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s" />
<sql id="assertSelectCountWithBindingTableWithJoin" value="SELECT COUNT(*) AS items_count FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s" />
<sql id="assertSelectAliasWithKeyword" value="SELECT length.item_id password FROM t_order_item length where length.item_id = %s "/>
<sql id="assertSelectAliasWithKeyword" value="SELECT length.item_id password FROM t_order_item length where length.item_id = %s " type="MySQL,H2,SQLServer,Oracle" />
</sqls>

0 comments on commit 6d0b926

Please sign in to comment.