func (l *LoadFile) getFile(ctx *sql.Context, row sql.Row, secureFileDir string) (*os.File, error) {
	fileName, err := l.fileName.Eval(ctx, row)
	if err != nil {
		return nil, err
	}
	if secureFileDir == "" {
		return os.Open(fileName.(string))
	}
	sDir, err := os.Open(secureFileDir)
	if err != nil {
		return nil, err
	}
	sStat, err := sDir.Stat()
	if err != nil {
		return nil, err
	}
	ffDir, err := os.Open(filepath.Dir(fileName.(string)))
	if err != nil {
		return nil, err
	}
	fStat, err := ffDir.Stat()
	if err != nil {
		return nil, err
	}
	if !os.SameFile(sStat, fStat) {
		return nil, nil
	}
	return os.Open(fileName.(string))
}
getFile returns the file handler for the passed in filename. The file must be in the secure_file_priv
directory.
package function
import (
	"fmt"
	"os"
	"path/filepath"
	"github.com/dolthub/go-mysql-server/sql"
)
type LoadFile struct {
	fileName sql.Expression
}
var _ sql.FunctionExpression = (*LoadFile)(nil)
func NewLoadFile(fileName sql.Expression) sql.Expression {
	return &LoadFile{
		fileName: fileName,
	}
}
func (l *LoadFile) Resolved() bool {
	return l.fileName.Resolved()
}
func (l *LoadFile) String() string {
	return fmt.Sprintf("LOAD_FILE(%s)", l.fileName)
}
func (l *LoadFile) Type() sql.Type {
	return sql.LongBlob
}
func (l *LoadFile) IsNullable() bool {
	return true
}
func (l *LoadFile) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
	dir, err := ctx.Session.GetSessionVariable(ctx, "secure_file_priv")
	if err != nil {
		return "", err
	}
	file, err := l.getFile(ctx, row, dir.(string))
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		}
		return nil, err
	}
	if file == nil {
		return nil, nil
	}
	defer file.Close()
	size, isTooBig, err := isFileTooBig(ctx, file)
	if err != nil {
		return nil, err
	}
	if isTooBig {
		return nil, nil
	}
	data := make([]byte, size)
	_, err = file.Read(data)
	if err != nil {
		return nil, err
	}
	return data, nil
}