Skip to content
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
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ var keywords = []keyword{
{"utc_time", UTC_TIME},
{"utc_timestamp", UTC_TIMESTAMP},
{"validation", VALIDATION},
{"value", VALUE},
{"values", VALUES},
{"var_pop", VAR_POP},
{"var_samp", VAR_SAMP},
Expand Down
28 changes: 23 additions & 5 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,31 @@ var (
}, {
input: "insert /* multi-value list */ into a values (1, 2), (3, 4)",
}, {
input: "insert /* no values */ into a values ()",
input: "insert /* simple */ into a value (1)",
output: "insert /* simple */ into a values (1)",
}, {
input: "insert /* a.b */ into a.b value (1)",
output: "insert /* a.b */ into a.b values (1)",
}, {
input: "insert /* multi-value */ into a value (1, 2)",
output: "insert /* multi-value */ into a values (1, 2)",
}, {
input: "insert /* multi-value list */ into a value (1, 2), (3, 4)",
output: "insert /* multi-value list */ into a values (1, 2), (3, 4)",
}, {
input: "insert /* no values */ into a value ()",
output: "insert /* no values */ into a values ()",
}, {
input: "insert /* set */ into a set a = 1, b = 2",
output: "insert /* set */ into a(a, b) values (1, 2)",
}, {
input: "insert /* set default */ into a set a = default, b = 2",
output: "insert /* set default */ into a(a, b) values (default, 2)",
}, {
input: "replace into a values (1, 2), (3, 4)",
}, {
input: "replace into a value (1, 2), (3, 4)",
output: "replace into a values (1, 2), (3, 4)",
}, {
input: "insert /* value expression list */ into a values (a + 1, 2 * 3)",
}, {
Expand Down Expand Up @@ -2144,14 +2162,14 @@ var (
input: "create procedure DeclareAndIfProcedure(in input_value int) begin declare message varchar(50); if input_value > 100 then set message = 'High'; elseif input_value > 50 then set message = 'Medium'; else set message = 'Low'; end if; select message; end;",
output: "create procedure DeclareAndIfProcedure (in input_value int) begin declare message varchar(50); if input_value > 100 then set message = 'High'; elseif input_value > 50 then set message = 'Medium'; else set message = 'Low'; end if; select message from dual; end;",
}, {
input: "create procedure NestedIfProcedure(in value int) begin if value > 0 then if value > 100 then select 'Very High'; else select 'High'; end if; else select 'Low or Negative'; end if; end;",
output: "create procedure NestedIfProcedure (in value int) begin if value > 0 then if value > 100 then select 'Very High' from dual; else select 'High' from dual; end if; else select 'Low or Negative' from dual; end if; end;",
input: "create procedure NestedIfProcedure(in test_value int) begin if test_value > 0 then if test_value > 100 then select 'Very High'; else select 'High'; end if; else select 'Low or Negative'; end if; end;",
output: "create procedure NestedIfProcedure (in test_value int) begin if test_value > 0 then if test_value > 100 then select 'Very High' from dual; else select 'High' from dual; end if; else select 'Low or Negative' from dual; end if; end;",
}, {
input: "create procedure MultipleDeclareProcedure(in val1 int, in val2 int) begin declare sum_result int; declare diff_result int; set sum_result = val1 + val2; set diff_result = val1 - val2; select sum_result as Sum, diff_result as Difference; end;",
output: "create procedure MultipleDeclareProcedure (in val1 int, in val2 int) begin declare sum_result int; declare diff_result int; set sum_result = val1 + val2; set diff_result = val1 - val2; select sum_result as `Sum`, diff_result as Difference from dual; end;",
}, {
input: "create procedure ErrorHandlingProcedure(in value int) begin declare exit handler for sqlexception begin select 'An error occurred'; end; if value < 0 then signal sqlstate '45000' set message_text = 'Negative values not allowed'; else select 'Valid value'; end if; end;",
output: "create procedure ErrorHandlingProcedure (in value int) begin declare exit handler for sqlexception begin select 'An error occurred' from dual; end; if value < 0 then signal sqlstate '45000' set message_text = 'Negative values not allowed'; else select 'Valid value' from dual; end if; end;",
input: "create procedure ErrorHandlingProcedure(in test_value int) begin declare exit handler for sqlexception begin select 'An error occurred'; end; if test_value < 0 then signal sqlstate '45000' set message_text = 'Negative values not allowed'; else select 'Valid value'; end if; end;",
output: "create procedure ErrorHandlingProcedure (in test_value int) begin declare exit handler for sqlexception begin select 'An error occurred' from dual; end; if test_value < 0 then signal sqlstate '45000' set message_text = 'Negative values not allowed'; else select 'Valid value' from dual; end if; end;",
}, {
input: "create procedure HandlerWithSQLEXCEPTION() begin declare undo handler for sqlexception begin select 'SQL Exception occurred'; end; insert into non_existing_table values (1); end;",
output: "create procedure HandlerWithSQLEXCEPTION () begin declare undo handler for sqlexception begin select 'SQL Exception occurred' from dual; end; insert into non_existing_table values (1); end;",
Expand Down
Loading
Loading