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