|
| 1 | +// Copyright 2025 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 _go |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/dolthub/go-mysql-server/sql" |
| 21 | +) |
| 22 | + |
| 23 | +// TestSelect covers SELECT syntax not covered by our MySQL select tests |
| 24 | +func TestSelect(t *testing.T) { |
| 25 | + RunScripts(t, []ScriptTest{ |
| 26 | + { |
| 27 | + Name: "select values", |
| 28 | + Assertions: []ScriptTestAssertion{ |
| 29 | + { |
| 30 | + Query: "select * from (values(1,'峰哥',18),(2,'王哥',20),(3,'张哥',22));", |
| 31 | + Expected: []sql.Row{ |
| 32 | + {1, "峰哥", 18}, |
| 33 | + {2, "王哥", 20}, |
| 34 | + {3, "张哥", 22}, |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + Query: "select * from (values(1,'峰哥',18),(2,'王哥',20),(3,'张哥',22)) x(id,name,age);", |
| 39 | + Expected: []sql.Row{ |
| 40 | + {1, "峰哥", 18}, |
| 41 | + {2, "王哥", 20}, |
| 42 | + {3, "张哥", 22}, |
| 43 | + }, |
| 44 | + Cols: []string{ |
| 45 | + "id", |
| 46 | + "name", |
| 47 | + "age", |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + Query: "select * from (values(1,'峰哥',18),(2,'王哥',20),(3,'张哥',22)) x(id,name,age) limit $1;", |
| 52 | + BindVars: []any{2}, // forcing this to use prepared statements |
| 53 | + Expected: []sql.Row{ |
| 54 | + {1, "峰哥", 18}, |
| 55 | + {2, "王哥", 20}, |
| 56 | + }, |
| 57 | + Cols: []string{ |
| 58 | + "id", |
| 59 | + "name", |
| 60 | + "age", |
| 61 | + }, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }) |
| 66 | +} |
0 commit comments