Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 62 additions & 4 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,9 @@ func TestInsertComments(t *testing.T) {
}
}

func TestEmptySpecialComments(t *testing.T) {
for _, input := range []string{"select /*!*/ 1", "select /*!1234*/ 1"} {
func TestFloatColumnPrecision(t *testing.T) {
for _, typ := range []string{"float", "double", "real"} {
input := "create table t (a " + typ + "(24) default current_timestamp)"
queries, statements, err := ParseMultiple(NewStringTokenizer(input))
if err != nil {
t.Errorf("ParseMultiple(%q): %v", input, err)
Expand All @@ -737,8 +738,48 @@ func TestEmptySpecialComments(t *testing.T) {
t.Errorf("ParseMultiple(%q): unexpected result %v, %v", input, queries, statements)
continue
}
if got := String(statements[0]); got != "select 1" {
t.Errorf("ParseMultiple(%q) = %q, want select 1", input, got)
ddl := statements[0].(*DDL)
if ddl.TableSpec == nil || len(ddl.TableSpec.Columns) != 1 {
t.Errorf("ParseMultiple(%q): missing column specification", input)
continue
}
column := ddl.TableSpec.Columns[0].Type
if column.Type != typ || column.Length == nil || string(column.Length.Val) != "24" || column.Scale != nil {
t.Errorf("ParseMultiple(%q): unexpected column type %+v", input, column)
}
foundDefault := false
Walk(func(node SQLNode) (bool, error) {
if value, ok := node.(*SQLVal); ok && value.Type == ValArg && bytes.EqualFold(value.Val, []byte("current_timestamp")) {
foundDefault = true
}
return true, nil
}, column.Default)
if !foundDefault {
t.Errorf("ParseMultiple(%q): missing stateful default", input)
}
}
}

func TestFloatColumnPrecisionSemicolonDefault(t *testing.T) {
for _, typ := range []string{"float", "double", "real"} {
input := "create table t (a " + typ + "(24) default 'a;b')"
queries, statements, err := ParseMultiple(NewStringTokenizer(input))
if err != nil {
t.Errorf("ParseMultiple(%q): %v", input, err)
continue
}
if len(queries) != 1 || queries[0] != input || len(statements) != 1 {
t.Errorf("ParseMultiple(%q): unexpected result %v, %v", input, queries, statements)
continue
}
ddl := statements[0].(*DDL)
if ddl.TableSpec == nil || len(ddl.TableSpec.Columns) != 1 {
t.Errorf("ParseMultiple(%q): missing column specification", input)
continue
}
value := ddl.TableSpec.Columns[0].Type.Default
if value == nil || value.Type != StrVal || string(value.Val) != "a;b" {
t.Errorf("ParseMultiple(%q): unexpected default %v", input, value)
}
}
}
Expand Down Expand Up @@ -846,6 +887,23 @@ func TestKeywords(t *testing.T) {
}
}

func TestEmptySpecialComments(t *testing.T) {
for _, input := range []string{"select /*!*/ 1", "select /*!1234*/ 1"} {
queries, statements, err := ParseMultiple(NewStringTokenizer(input))
if err != nil {
t.Errorf("ParseMultiple(%q): %v", input, err)
continue
}
if len(queries) != 1 || queries[0] != input || len(statements) != 1 {
t.Errorf("ParseMultiple(%q): unexpected result %v, %v", input, queries, statements)
continue
}
if got := String(statements[0]); got != "select 1" {
t.Errorf("ParseMultiple(%q) = %q, want select 1", input, got)
}
}
}

func TestConvert(t *testing.T) {
validSQL := []struct {
input string
Expand Down
Loading
Loading