Skip to content

Commit dbe42eb

Browse files
committed
[planbuilder] nil database doesn't panic building procedure call
1 parent f61a772 commit dbe42eb

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

enginetest/enginetests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,6 +4877,7 @@ func TestNoDatabaseSelected(t *testing.T, harness Harness) {
48774877
AssertErrWithCtx(t, e, harness, ctx, "create table a (b int primary key)", nil, sql.ErrNoDatabaseSelected)
48784878
AssertErrWithCtx(t, e, harness, ctx, "show tables", nil, sql.ErrNoDatabaseSelected)
48794879
AssertErrWithCtx(t, e, harness, ctx, "show triggers", nil, sql.ErrNoDatabaseSelected)
4880+
AssertErrWithCtx(t, e, harness, ctx, "call non_existent_proc()", nil, sql.ErrNoDatabaseSelected)
48804881

48814882
_, _, _, err := e.Query(ctx, "ROLLBACK")
48824883
require.NoError(t, err)

sql/planbuilder/proc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ func (b *Builder) buildCall(inScope *scope, c *ast.Call) (outScope *scope) {
311311
} else if b.ctx.GetCurrentDatabase() != "" {
312312
db = b.currentDb()
313313
}
314+
if db == nil {
315+
b.handleErr(sql.ErrNoDatabaseSelected.New())
316+
}
314317

315318
var proc *plan.Procedure
316319
var innerQFlags *sql.QueryFlags

0 commit comments

Comments
 (0)