Skip to content
Draft
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
3 changes: 1 addition & 2 deletions pkg/parser/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@
fallthrough
case 'C':
offset := len(data) - len(BEGIN_ATOMIC)
if offset >= 0 && strings.EqualFold(string(data[offset:]), BEGIN_ATOMIC) {
if offset > 0 && strings.EqualFold(string(data[offset:]), BEGIN_ATOMIC) && unicode.IsSpace(rune(data[offset-1])) {
return &AtomicState{prev: s, delimiter: []byte(END_ATOMIC)}
}
}
return s
}

// Opened a line comment
type CommentState struct{}

func (s *CommentState) Next(r rune, data []byte) State {

Check failure on line 59 in pkg/parser/state.go

View workflow job for this annotation

GitHub Actions / Link

syntax error: unexpected name rune in argument list; possibly missing comma or )

Check failure on line 59 in pkg/parser/state.go

View workflow job for this annotation

GitHub Actions / Start

syntax error: unexpected name rune in argument list; possibly missing comma or )

Check failure on line 59 in pkg/parser/state.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: unexpected name rune in argument list; possibly missing comma or )

Check failure on line 59 in pkg/parser/state.go

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected name rune in argument list; possibly missing comma or ))) (typecheck)
if r == '-' {
// No characters are escaped in comments, which is the same as dollar
return &DollarState{delimiter: []byte{'\n'}}
Expand Down
23 changes: 23 additions & 0 deletions pkg/parser/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,27 @@ END
;`}
checkSplit(t, sql)
})

t.Run("atomic in table name", func(t *testing.T) {
sql := []string{"create table public.atomic_test (id int);", "\nselect 1;"}
checkSplit(t, sql)
})

t.Run("atomic in function name", func(t *testing.T) {
sql := []string{
"CREATE OR REPLACE FUNCTION public.my_function_atomic(p_id uuid)\nRETURNS void\nLANGUAGE plpgsql\nAS $$\nBEGIN\n RAISE NOTICE 'hello';\nEND;\n$$;",
"\nGRANT EXECUTE ON FUNCTION public.my_function_atomic(uuid) TO authenticated;",
}
checkSplit(t, sql)
})

t.Run("atomic in column name", func(t *testing.T) {
sql := []string{"select is_atomic from flags;", "\nselect 1;"}
checkSplit(t, sql)
})

t.Run("digit before atomic", func(t *testing.T) {
sql := []string{"select col1atomic from t;", "\nselect 1;"}
checkSplit(t, sql)
})
}
Loading