github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/external_procedure_queries.go (about) 1 // Copyright 2022 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package queries 16 17 import "github.com/dolthub/go-mysql-server/sql" 18 19 var ExternalProcedureTests = []ScriptTest{ 20 { 21 Name: "Call external stored procedure that does not exist", 22 Assertions: []ScriptTestAssertion{ 23 { 24 Query: "CALL procedure_does_not_exist('foo');", 25 ExpectedErr: sql.ErrStoredProcedureDoesNotExist, 26 }, 27 }, 28 }, 29 { 30 Name: "INOUT on first param, IN on second param", 31 SetUpScript: []string{ 32 "SET @outparam = 5;", 33 "CALL memory_inout_add(@outparam, 11);", 34 }, 35 Assertions: []ScriptTestAssertion{ 36 { 37 Query: "SELECT @outparam;", 38 Expected: []sql.Row{{16}}, 39 }, 40 }, 41 }, 42 { 43 Name: "Handle setting uninitialized user variables", 44 SetUpScript: []string{ 45 "CALL memory_inout_set_unitialized(@uservar12, @uservar13, @uservar14, @uservar15);", 46 }, 47 Assertions: []ScriptTestAssertion{ 48 { 49 Query: "SELECT @uservar12;", 50 Expected: []sql.Row{{5}}, 51 }, 52 { 53 Query: "SELECT @uservar13;", 54 Expected: []sql.Row{{uint(5)}}, 55 }, 56 { 57 Query: "SELECT @uservar14;", 58 Expected: []sql.Row{{"5"}}, 59 }, 60 { 61 Query: "SELECT @uservar15;", 62 Expected: []sql.Row{{0}}, 63 }, 64 }, 65 }, 66 { 67 Name: "Called from standard stored procedure", 68 SetUpScript: []string{ 69 "CREATE PROCEDURE p1(x BIGINT) BEGIN CALL memory_inout_add(x, x); SELECT x; END;", 70 }, 71 Assertions: []ScriptTestAssertion{ 72 { 73 Query: "CALL p1(11);", 74 Expected: []sql.Row{{22}}, 75 }, 76 }, 77 }, 78 { 79 Name: "Overloaded Name", 80 Assertions: []ScriptTestAssertion{ 81 { 82 Query: "CALL memory_overloaded_mult(1);", 83 Expected: []sql.Row{{1}}, 84 }, 85 { 86 Query: "CALL memory_overloaded_mult(2, 3);", 87 Expected: []sql.Row{{6}}, 88 }, 89 { 90 Query: "CALL memory_overloaded_mult(4, 5, 6);", 91 Expected: []sql.Row{{120}}, 92 }, 93 }, 94 }, 95 { 96 Name: "Passing in all supported types", 97 Assertions: []ScriptTestAssertion{ 98 { 99 Query: "CALL memory_overloaded_type_test(1, 100, 10000, 1000000, 100000000, 3, 300," + 100 "10, 1000, 100000, 10000000, 1000000000, 30, 3000);", 101 Expected: []sql.Row{{1111114444}}, 102 }, 103 { 104 Query: "CALL memory_overloaded_type_test(false, 'hi', 'A', '2020-02-20 12:00:00', 123.456," + 105 "true, 'bye', 'B', '2022-02-02 12:00:00', 654.32);", 106 Expected: []sql.Row{{`aa:false,ba:true,ab:"hi",bb:"bye",ac:[65],bc:[66],ad:2020-02-20,bd:2022-02-02,ae:123.456,be:654.32`}}, 107 }, 108 { 109 Query: "CALL memory_type_test3(1, 100, 10000, 1000000, 100000000, 3, 300," + 110 "10, 1000, 100000, 10000000, 1000000000, 30, 3000);", 111 Expected: []sql.Row{{uint64(1111114444)}}, 112 }, 113 }, 114 }, 115 { 116 Name: "BOOL and []BYTE INOUT conversions", 117 SetUpScript: []string{ 118 "SET @outparam1 = 1;", 119 "SET @outparam2 = 0;", 120 "SET @outparam3 = 'A';", 121 "SET @outparam4 = 'B';", 122 }, 123 Assertions: []ScriptTestAssertion{ 124 { 125 Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", 126 Expected: []sql.Row{{1, 0, "A", "B"}}, 127 }, 128 { 129 Query: "CALL memory_inout_bool_byte(@outparam1, @outparam2, @outparam3, @outparam4);", 130 Expected: []sql.Row{}, 131 }, 132 { 133 Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", 134 Expected: []sql.Row{{1, 1, "A", []byte("C")}}, 135 }, 136 { 137 Query: "CALL memory_inout_bool_byte(@outparam1, @outparam2, @outparam3, @outparam4);", 138 Expected: []sql.Row{}, 139 }, 140 { 141 Query: "SELECT @outparam1, @outparam2, @outparam3, @outparam4;", 142 Expected: []sql.Row{{1, 0, "A", []byte("D")}}, 143 }, 144 }, 145 }, 146 { 147 Name: "Errors returned", 148 Assertions: []ScriptTestAssertion{ 149 { 150 Query: "CALL memory_error_table_not_found();", 151 ExpectedErr: sql.ErrTableNotFound, 152 }, 153 }, 154 }, 155 { 156 Name: "Variadic parameter", 157 Assertions: []ScriptTestAssertion{ 158 { 159 Query: "CALL memory_variadic_add();", 160 Expected: []sql.Row{{0}}, 161 }, 162 { 163 Query: "CALL memory_variadic_add(1);", 164 Expected: []sql.Row{{1}}, 165 }, 166 { 167 Query: "CALL memory_variadic_add(1, 2);", 168 Expected: []sql.Row{{3}}, 169 }, 170 { 171 Query: "CALL memory_variadic_add(1, 2, 3);", 172 Expected: []sql.Row{{6}}, 173 }, 174 { 175 Query: "CALL memory_variadic_add(1, 2, 3, 4);", 176 Expected: []sql.Row{{10}}, 177 }, 178 }, 179 }, 180 { 181 Name: "Variadic byte slices", 182 Assertions: []ScriptTestAssertion{ 183 { 184 Query: "CALL memory_variadic_byte_slice();", 185 Expected: []sql.Row{{""}}, 186 }, 187 { 188 Query: "CALL memory_variadic_byte_slice('A');", 189 Expected: []sql.Row{{"A"}}, 190 }, 191 { 192 Query: "CALL memory_variadic_byte_slice('A', 'B');", 193 Expected: []sql.Row{{"AB"}}, 194 }, 195 }, 196 }, 197 { 198 Name: "Variadic overloading", 199 Assertions: []ScriptTestAssertion{ 200 { 201 Query: "CALL memory_variadic_overload();", 202 ExpectedErr: sql.ErrCallIncorrectParameterCount, 203 }, 204 { 205 Query: "CALL memory_variadic_overload('A');", 206 ExpectedErr: sql.ErrCallIncorrectParameterCount, 207 }, 208 { 209 Query: "CALL memory_variadic_overload('A', 'B');", 210 Expected: []sql.Row{{"A-B"}}, 211 }, 212 { 213 Query: "CALL memory_variadic_overload('A', 'B', 'C');", 214 ExpectedErr: sql.ErrInvalidValue, 215 }, 216 { 217 Query: "CALL memory_variadic_overload('A', 'B', 5);", 218 Expected: []sql.Row{{"A,B,[5]"}}, 219 }, 220 }, 221 }, 222 { 223 Name: "show create procedure for external stored procedures", 224 Assertions: []ScriptTestAssertion{ 225 { 226 Query: "show create procedure memory_variadic_overload;", 227 Expected: []sql.Row{{ 228 "memory_variadic_overload", 229 "", 230 "CREATE PROCEDURE memory_variadic_overload() SELECT 'External stored procedure';", 231 "utf8mb4", 232 "utf8mb4_0900_bin", 233 "utf8mb4_0900_bin", 234 }}, 235 }, 236 }, 237 }, 238 }