Browse Source

'fix'

apijson
u 2 years ago
parent
commit
d3cc2d6bce
  1. 6
      types.go
  2. 3
      vql.go

6
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{}

3
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 == "" {

Loading…
Cancel
Save