Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2253 bug fixes #2264

Merged
merged 3 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -21,6 +21,7 @@
import lombok.RequiredArgsConstructor;
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 @@ -53,6 +54,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_keyword">
<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_keyword" 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>