Error when accessing table with undefined param
When using the SQL table() function to define a table with an undefined paramater `table($undefined)`, the database would attempt to access a nil table, and would eventually crash.
This commit is contained in:
parent
480ae04046
commit
1a0c8b018f
4 changed files with 33 additions and 0 deletions
|
@ -17,11 +17,19 @@ package fncs
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/abcum/surreal/mem"
|
||||
"github.com/abcum/surreal/sql"
|
||||
)
|
||||
|
||||
func batch(ctx context.Context, args ...interface{}) (interface{}, error) {
|
||||
|
||||
tb, _ := ensureString(args[0])
|
||||
id, _ := ensureSlice(args[1])
|
||||
return sql.NewBatch(tb, id), nil
|
||||
|
||||
if len(tb) == 0 {
|
||||
return nil, mem.ErrorTBNotFound
|
||||
}
|
||||
|
||||
return sql.NewBatch(tb, id), nil
|
||||
|
||||
}
|
||||
|
|
|
@ -17,11 +17,18 @@ package fncs
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/abcum/surreal/mem"
|
||||
"github.com/abcum/surreal/sql"
|
||||
)
|
||||
|
||||
func model(ctx context.Context, args ...interface{}) (interface{}, error) {
|
||||
|
||||
tb, _ := ensureString(args[0])
|
||||
|
||||
if len(tb) == 0 {
|
||||
return nil, mem.ErrorTBNotFound
|
||||
}
|
||||
|
||||
switch len(args) {
|
||||
case 2:
|
||||
if max, ok := ensureFloat(args[1]); ok {
|
||||
|
@ -42,5 +49,7 @@ func model(ctx context.Context, args ...interface{}) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,18 @@ package fncs
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/abcum/surreal/mem"
|
||||
"github.com/abcum/surreal/sql"
|
||||
)
|
||||
|
||||
func table(ctx context.Context, args ...interface{}) (interface{}, error) {
|
||||
|
||||
tb, _ := ensureString(args[0])
|
||||
return sql.NewTable(tb), nil
|
||||
|
||||
if len(tb) == 0 {
|
||||
return nil, mem.ErrorTBNotFound
|
||||
}
|
||||
|
||||
return sql.NewTable(tb), nil
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,18 @@ package fncs
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/abcum/surreal/mem"
|
||||
"github.com/abcum/surreal/sql"
|
||||
)
|
||||
|
||||
func thing(ctx context.Context, args ...interface{}) (interface{}, error) {
|
||||
|
||||
tb, _ := ensureString(args[0])
|
||||
return sql.NewThing(tb, args[1]), nil
|
||||
|
||||
if len(tb) == 0 {
|
||||
return nil, mem.ErrorTBNotFound
|
||||
}
|
||||
|
||||
return sql.NewThing(tb, args[1]), nil
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue