Skip to content

Commit

Permalink
apache#2253 bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
codefairy08 committed Apr 25, 2019
1 parent ac44049 commit a03aa05
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLIgnoreExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLNumberExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLPlaceholderExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLTextExpression;
Expand Down Expand Up @@ -132,6 +133,8 @@ protected final String getColumnSQLExpressionValue(final int columnValueIndex) {
return "?";
} else if (sqlExpression instanceof SQLTextExpression) {
return String.format("'%s'", ((SQLTextExpression) sqlExpression).getText());
} else if (sqlExpression instanceof SQLIgnoreExpression) {
return ((SQLIgnoreExpression) sqlExpression).getExpression();
} else {
return String.valueOf(((SQLNumberExpression) sqlExpression).getNumber());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import lombok.Setter;
import org.apache.shardingsphere.core.parse.old.lexer.token.DefaultKeyword;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLIgnoreExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLNumberExpression;
import org.apache.shardingsphere.core.parse.old.parser.expression.SQLTextExpression;

Expand Down Expand Up @@ -55,6 +56,6 @@ public SQLExpression getSQLExpression(final String sql) {
if (DefaultKeyword.NULL.name().equalsIgnoreCase(value)) {
return new SQLNumberExpression(null);
}
return new SQLTextExpression(value);
return new SQLIgnoreExpression(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@
</or-condition>
</parser-result>

<parser-result sql-case-id="insert_with_now_function" parameters="1, 1, 'init'">
<tables>
<table name="t_order" />
</tables>
<tokens>
<table-token start-index="12" table-name="t_order" length="7" />
<insert-values-token begin-position="20" />
</tokens>
<or-condition>
<and-condition>
<condition column-name="order_id" table-name="t_order" operator="EQUAL">
<value index="0" literal="1" type="int" />
</condition>
<condition column-name="user_id" table-name="t_order" operator="EQUAL">
<value index="1" literal="1" type="int" />
</condition>
</and-condition>
</or-condition>
</parser-result>

<parser-result sql-case-id="insert_without_parameters">
<tables>
<table name="t_order" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,15 @@
</aggregation-select-items>
</select-items>
</parser-result>
<parser-result sql-case-id="select_with_coloumns_in_paren">
<parser-result sql-case-id="select_with_row_subquery_without_row">
<tables>
<table name="t_order"/>
</tables>
<tokens>
<table-token start-index="14" table-name="t_order" length="7" />
</tokens>
</parser-result>
<parser-result sql-case-id="select_with_coloumns_in_row">
<parser-result sql-case-id="select_with_row_subquery">
<tables>
<table name="t_order"/>
</tables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
<assertion parameters="1:int, 1:int, insert:String" expected-data-file="insert_for_order_1.xml" />
<assertion parameters="2:int, 2:int, insert:String" expected-data-file="insert_for_order_2.xml" />
</dml-test-case>

<dml-test-case sql-case-id="insert_with_now_function">
<assertion parameters="1:int, 1:int, insert:String" expected-data-file="insert_for_order_1.xml" />
<assertion parameters="2:int, 2:int, insert:String" expected-data-file="insert_for_order_2.xml" />
</dml-test-case>

<dml-test-case sql-case-id="insert_without_parameters">
<assertion expected-data-file="insert_for_order_1.xml" />
Expand Down
1 change: 1 addition & 0 deletions sharding-sql-test/src/main/resources/sql/dml/insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<sql-cases>
<sql-case id="insert_with_all_placeholders" value="INSERT INTO t_order (order_id, user_id, status) VALUES (?, ?, ?)" />
<sql-case id="insert_with_now_function" value="INSERT INTO t_order (order_id, user_id, status,create_time) VALUES (?, ?, ?,now())" db-types="MySQL" />
<sql-case id="insert_without_parameters" value="INSERT INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert')" />
<sql-case id="insert_with_special_characters" value="INSERT INTO `t_order` (`order_id`, `user_id`, `status`) VALUES (1, 1, 'insert')" db-types="MySQL" />
<sql-case id="insert_with_special_syntax" value="INSERT /*+ index(field1) */ INTO t_order (order_id, user_id, status) VALUES (1, 1, 'insert') RETURNING order_id" db-types="PostgreSQL" />
Expand Down
4 changes: 2 additions & 2 deletions sharding-sql-test/src/main/resources/sql/dql/select.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
<sql-case id="select_alias_as_single_quote_string" value="SELECT status as 'status' FROM t_order" />
<sql-case id="select_alias_as_string_double_quote" value="SELECT status as &quot;status&quot; FROM t_order" />
<sql-case id="select_special_function_nested" value="SELECT sum(if(status=0, 1, 0)) FROM t_order" />
<sql-case id="select_with_coloumns_in_paren" value="SELECT * FROM t_order WHERE (user_id,order_id) = (SELECT user_id,order_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
<sql-case id="select_with_coloumns_in_row" value="SELECT * FROM t_order WHERE ROW(user_id,order_id) = (SELECT user_id,order_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
<sql-case id="select_with_row_subquery_without_row" value="SELECT * FROM t_order WHERE (user_id,order_id) = (SELECT user_id,order_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
<sql-case id="select_with_row_subquery" value="SELECT * FROM t_order WHERE ROW(user_id,order_id) = (SELECT user_id,order_id FROM t_order_item WHERE id = 10)" db-types="MySQL" />
</sql-cases>

0 comments on commit a03aa05

Please sign in to comment.