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
21 changes: 16 additions & 5 deletions oracle/parser/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ type splitState struct {
topLevelTokens int
pendingSubprogram bool
pendingCaseEnd bool
callSpecStarted bool

endPending bool
closedOutermost bool
Expand Down Expand Up @@ -312,6 +313,18 @@ func (s *splitState) observePLSQL(tok Token) {
top.compound = true
return
}
if len(s.frames) == 1 && !top.bodyStarted {
switch top.kind {
case splitPLSQLStoredUnit:
if tok.Str == "LANGUAGE" || tok.Str == "EXTERNAL" {
s.callSpecStarted = true
}
case splitPLSQLTrigger:
if tok.Type == kwCALL {
s.callSpecStarted = true
}
}
}

if s.canStartNestedSubprogram(tok) {
s.pendingSubprogram = true
Expand Down Expand Up @@ -340,11 +353,8 @@ func (s *splitState) plsqlCanEndAtSemicolon() bool {
if s.endPending {
return s.closedOutermost
}
if len(s.frames) == 1 {
top := s.frames[0]
if (top.kind == splitPLSQLStoredUnit || top.kind == splitPLSQLTrigger) && !top.bodyStarted {
return true
}
if s.callSpecStarted {
return true
}
return false
}
Expand All @@ -354,6 +364,7 @@ func (s *splitState) afterPLSQLSemicolon() {
s.closedOutermost = false
s.pendingSubprogram = false
s.pendingCaseEnd = false
s.callSpecStarted = false
}

func (s *splitState) pushFrame(kind splitPLSQLKind, bodyStarted bool) {
Expand Down
29 changes: 29 additions & 0 deletions oracle/parser/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ func TestSplitPLSQLBlocks(t *testing.T) {
"\nCREATE TABLE t (id NUMBER)",
},
},
{
name: "create function with declarations without slash separator",
sql: "CREATE FUNCTION calc_bonus(p_start_date DATE)\n" +
"RETURN DATE\n" +
"IS\n" +
" v_current_date DATE := p_start_date;\n" +
"BEGIN\n" +
" RETURN v_current_date;\n" +
"END calc_bonus;\n" +
"CREATE TABLE t (id NUMBER);",
want: []string{
"CREATE FUNCTION calc_bonus(p_start_date DATE)\nRETURN DATE\nIS\n v_current_date DATE := p_start_date;\nBEGIN\n RETURN v_current_date;\nEND calc_bonus;",
"\nCREATE TABLE t (id NUMBER)",
},
},
{
name: "create procedure with declarations without slash separator",
sql: "CREATE PROCEDURE update_salary(p_employee_id NUMBER)\n" +
"IS\n" +
" v_delta NUMBER := 1;\n" +
"BEGIN\n" +
" UPDATE employees SET salary = salary + v_delta WHERE id = p_employee_id;\n" +
"END update_salary;\n" +
"CREATE TABLE t (id NUMBER);",
want: []string{
"CREATE PROCEDURE update_salary(p_employee_id NUMBER)\nIS\n v_delta NUMBER := 1;\nBEGIN\n UPDATE employees SET salary = salary + v_delta WHERE id = p_employee_id;\nEND update_salary;",
"\nCREATE TABLE t (id NUMBER)",
},
},
{
name: "create editionable procedure",
sql: "CREATE OR REPLACE EDITIONABLE PROCEDURE p IS\n" +
Expand Down
Loading