diff --git a/internal/parser/issue29_test.go b/internal/parser/issue29_test.go new file mode 100644 index 00000000..0ed35552 --- /dev/null +++ b/internal/parser/issue29_test.go @@ -0,0 +1,31 @@ +package parser + +import "testing" + +func TestIssue29(t *testing.T) { + NegativeTest{ + Name: "issue29", + Query: "CREATE TABLE(n,FOREIGN KEY()REFERENCES n ON DELETE CASCADE)", + }.Run(t) +} + +func TestIssue29WithoutTableName(t *testing.T) { + NegativeTest{ + Name: "issue29 without table name", + Query: "CREATE TABLE (foo)", + }.Run(t) +} + +func TestIssue29WithNumericColumn(t *testing.T) { + NegativeTest{ + Name: "issue29 with numeric column", + Query: "CREATE TABLE foo(1)", + }.Run(t) +} + +func TestIssue29WithNumericTable(t *testing.T) { + NegativeTest{ + Name: "issue29 with numeric column", + Query: "CREATE TABLE 1(foo)", + }.Run(t) +} diff --git a/internal/parser/negative_test.go b/internal/parser/negative_test.go new file mode 100644 index 00000000..9b1b0317 --- /dev/null +++ b/internal/parser/negative_test.go @@ -0,0 +1,27 @@ +package parser + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +type NegativeTest struct { + Name string + Query string +} + +func (nt NegativeTest) Run(t *testing.T) { + t.Helper() + t.Run(nt.Name, func(t *testing.T) { + assert := assert.New(t) + + p, err := New(nt.Query) + assert.NoError(err) + _, errs, ok := p.Next() + assert.True(ok, "expected exactly one statement") + assert.NotEmpty(errs, "expected errors") + + _, _, ok = p.Next() + assert.False(ok, "expected only one statement") + }) +} diff --git a/internal/parser/simple_parser_rules.go b/internal/parser/simple_parser_rules.go index 576b2df3..51d4a347 100644 --- a/internal/parser/simple_parser_rules.go +++ b/internal/parser/simple_parser_rules.go @@ -2532,6 +2532,8 @@ func (p *simpleParser) parseCreateTableStmt(createToken, tempToken, temporaryTok stmt.SchemaName = next stmt.TableName = next p.consumeToken() + } else { + r.unexpectedToken(token.Literal) } next, ok = p.lookahead(r)