diff --git a/go.mod b/go.mod index c687324..ffa6b89 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/sqlc-dev/marino go 1.25 require ( - github.com/go-sql-driver/mysql v1.7.1 go.uber.org/goleak v1.3.0 golang.org/x/text v0.19.0 modernc.org/mathutil v1.6.0 diff --git a/go.sum b/go.sum index 8c892df..5d43d9b 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= -github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= diff --git a/parser/reserved_words_test.go b/parser/reserved_words_test.go deleted file mode 100644 index 3377df1..0000000 --- a/parser/reserved_words_test.go +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2020 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build reserved_words_test -// +build reserved_words_test - -// This file ensures that the set of reserved keywords is the same as that of -// MySQL. To run: -// -// 1. Set up a MySQL server listening at 127.0.0.1:3306 using root and no password -// 2. Run this test with: -// -// go test -tags reserved_words_test -run '^TestCompareReservedWordsWithMySQL$' - -package parser - -import ( - // needed to connect to MySQL - dbsql "database/sql" - gio "io" - "os" - "testing" - - _ "github.com/go-sql-driver/mysql" - "github.com/sqlc-dev/marino/ast" - - "fmt" - "regexp" -) - -func TestCompareReservedWordsWithMySQL(t *testing.T) { - parserFilename := "parser.y" - parserFile, err := os.Open(parserFilename) - if err != nil { - t.Fatal(err) - } - data, err := gio.ReadAll(parserFile) - if err != nil { - t.Fatal(err) - } - content := string(data) - - reservedKeywordStartMarker := "\t/* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */" - unreservedKeywordStartMarker := "\t/* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */" - notKeywordTokenStartMarker := "\t/* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */" - tidbKeywordStartMarker := "\t/* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */" - identTokenEndMarker := "%token\t" - - reservedKeywords := extractKeywords(content, reservedKeywordStartMarker, unreservedKeywordStartMarker) - unreservedKeywords := extractKeywords(content, unreservedKeywordStartMarker, notKeywordTokenStartMarker) - notKeywordTokens := extractKeywords(content, notKeywordTokenStartMarker, tidbKeywordStartMarker) - tidbKeywords := extractKeywords(content, tidbKeywordStartMarker, identTokenEndMarker) - - p := New() - db, err := dbsql.Open("mysql", "root@tcp(127.0.0.1:3306)/") - if err != nil { - t.Fatal(err) - } - defer func() { - if db.Close() != nil { - t.Fatal(db.Close()) - } - }() - - for _, kw := range reservedKeywords { - switch kw { - case "CURRENT_ROLE", // Present in both, reserved only in TiDB - "STATS_EXTENDED", // Only in TiDB - "TABLESAMPLE", // Only in TiDB - "ARRAY", // added in 8.0.17 (reserved); became nonreserved in 8.0.19 - "ILIKE", // Only in TiDB - "TIDB_CURRENT_TSO", // Only in TiDB - "UNTIL": // Present in both, reserved only in TiDB - // special cases: we do reserve these words but MySQL didn't, - // and unreservering it causes legit parser conflict. - continue - } - - query := "do (select 1 as " + kw + ")" - errRegexp := ".*" + kw + ".*" - - var err error - - if _, ok := windowFuncTokenMap[kw]; !ok { - // for some reason the query does parse even then the keyword is reserved in TiDB. - _, _, err = p.Parse(query, "", "") - if err == nil { - t.Fatal("expected error") - } - if !regexp.MustCompile(errRegexp).MatchString(err.Error()) { - t.Fatalf("expected %q to match %q", err.Error(), errRegexp) - } - } - _, err = db.Exec(query) - if err == nil { - t.Fatal(query) - } - if !regexp.MustCompile(errRegexp).MatchString(err.Error()) { - t.Fatalf("%s: expected %q to match %q", fmt.Sprintf("MySQL suggests that '%s' should *not* be reserved!", kw), err.Error(), errRegexp) - } - } - - for _, kws := range [][]string{unreservedKeywords, notKeywordTokens, tidbKeywords} { - for _, kw := range kws { - switch kw { - case "FUNCTION", // Reserved in MySQL 8.0.1 - "PURGE", // Reserved in MySQL - "SYSTEM", // Reserved in MySQL 8.0.3 - "SEPARATOR", // Reserved in MySQL - "DECLARE": // Reserved in MySQL - continue - } - - query := "do (select 1 as " + kw + ")" - - stmts, _, err := p.Parse(query, "", "") - if err != nil { - t.Fatal(err) - } - if got := len(stmts); got != 1 { - t.Fatalf("expected length %d, got %d", 1, got) - } - if _, ok := stmts[0].(*ast.DoStmt); !ok { - t.Fatalf("expected type %T, got %T", &ast.DoStmt{}, stmts[0]) - } - - _, err = db.Exec(query) - if err != nil { - t.Fatalf("%s: %v", fmt.Sprintf("MySQL suggests that '%s' should be reserved!", kw), err) - } - } - } -}