MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestValidateSQLForEditor

Function TestValidateSQLForEditor

backend/plugin/parser/snowflake/query_test.go:13–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestValidateSQLForEditor(t *testing.T) {
14 tests := []struct {
15 statement string
16 valid bool
17 gotAllQuery bool
18 err bool
19 }{
20 {
21 statement: "SHOW TABLES;",
22 valid: true,
23 gotAllQuery: true,
24 },
25 {
26 // Result-pipe: read-only source + trailing SELECT over $1 is a query.
27 statement: "SHOW TABLES ->> SELECT * FROM $1;",
28 valid: true,
29 gotAllQuery: true,
30 },
31 {
32 // Result-pipe with a non-read-only source must not classify as a query.
33 statement: "CALL P() ->> SELECT * FROM $1;",
34 valid: false,
35 gotAllQuery: false,
36 },
37 {
38 // A non-read-only statement piped FROM a SHOW must not classify as a query.
39 statement: "SHOW TABLES ->> DELETE FROM T1;",
40 valid: false,
41 gotAllQuery: false,
42 },
43 {
44 statement: "DESC TABLE bytebase;",
45 valid: true,
46 gotAllQuery: true,
47 },
48 {
49 statement: "SELECT * FROM t1 WHERE c1 = 1; SELECT * FROM t2;",
50 valid: true,
51 gotAllQuery: true,
52 },
53 {
54 statement: "CREATE TABLE t1 (c1 INT);",
55 valid: false,
56 gotAllQuery: false,
57 },
58 {
59 statement: "UPDATE t1 SET c1 = 1;",
60 valid: false,
61 gotAllQuery: false,
62 },
63 {
64 statement: "EXPLAIN SELECT * FROM t1;",
65 valid: true,
66 gotAllQuery: true,
67 },
68 {
69 statement: `select* from t`,
70 valid: true,

Callers

nothing calls this directly

Calls 3

validateQueryFunction · 0.70
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected