From d3cc2d6bce3d907794450048125858a34cbee7cb Mon Sep 17 00:00:00 2001 From: u Date: Fri, 10 Feb 2023 19:33:41 +0800 Subject: [PATCH] 'fix' --- types.go | 6 +++++- vql.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index 372833f..7cc67a2 100644 --- a/types.go +++ b/types.go @@ -453,7 +453,9 @@ func (q *Query) FromSelect(selectStmt *sqlparser.Select) error { } switch exp := form.Expr.(type) { case sqlparser.TableName: + // log.Println("TableName:", jsonEncode(exp)) q.From.Table = string(exp.Name.String()) + case *sqlparser.Subquery: subQuery := &Query{} if err := subQuery.FromSelect(exp.Select.(*sqlparser.Select)); err != nil { @@ -462,6 +464,7 @@ func (q *Query) FromSelect(selectStmt *sqlparser.Select) error { q.From.SubQuery = subQuery } case *sqlparser.JoinTableExpr: //有联表 + // log.Println("JoinTableExpr:", jsonEncode(form)) //确定主表 leftmost := getTheLeftmost(form) @@ -480,6 +483,7 @@ func (q *Query) FromSelect(selectStmt *sqlparser.Select) error { } q.From.SubQuery = subQuery } + } else { //找不到最左边的表 return fmt.Errorf("can not find the leftmost table") @@ -502,7 +506,7 @@ func (q *Query) FromSelect(selectStmt *sqlparser.Select) error { } switch rightExpr := right.Expr.(type) { case sqlparser.TableName: - log.Println("rightExpr:", jsonEncode(rightExpr)) + // log.Println("rightExpr:", jsonEncode(rightExpr)) join.Query.From.Table = string(rightExpr.Name.String()) case *sqlparser.Subquery: subQuery := &Query{} diff --git a/vql.go b/vql.go index 90a238f..e3ae627 100644 --- a/vql.go +++ b/vql.go @@ -130,6 +130,9 @@ func (vql *VirtualQL) convert(query *Query, val map[string]interface{}) error { if err != nil { return err } + if convertSql == "" { + return fmt.Errorf("table %s is not register!", query.From.Table) + } newAs := query.From.As if newAs == "" {