|
@@ -46,7 +46,7 @@ type selectClause struct {
|
|
|
fromSubQuery string
|
|
|
selectClause string
|
|
|
where string
|
|
|
- orderBy []string
|
|
|
+ orderBy string
|
|
|
groupBy []string
|
|
|
having string
|
|
|
pageNo int
|
|
@@ -144,7 +144,7 @@ func insertWalk(sql string) (*insertClause, error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return false
|
|
|
+ return true
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -186,7 +186,7 @@ func deleteWalk(sql string) (*deleteClause, error) {
|
|
|
|
|
|
clause.where = parseWhere(realNode.Where)
|
|
|
|
|
|
- return false
|
|
|
+ return true
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -240,7 +240,7 @@ func updateWalk(sql string) (*updateClause, error) {
|
|
|
clause.newTableRow[fmt.Sprint(expr.Names[0])] = *value
|
|
|
}
|
|
|
|
|
|
- return false
|
|
|
+ return true
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -273,9 +273,17 @@ func selectWalk(sql string) (*selectClause, error) {
|
|
|
|
|
|
|
|
|
clause.selectClause = parseSelect(nodeSelectClause.Exprs)
|
|
|
+ if clause.selectClause == "*" {
|
|
|
+ clause.selectClause = ""
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- asFromSubQuery, from := parseFrom(&nodeSelectClause.From)
|
|
|
+ asFromSubQuery, from, err := parseFrom(&nodeSelectClause.From)
|
|
|
+ if err != nil {
|
|
|
+ walkFuncErr = err
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
if asFromSubQuery {
|
|
|
clause.fromSubQuery = from
|
|
|
} else {
|
|
@@ -314,7 +322,7 @@ func selectWalk(sql string) (*selectClause, error) {
|
|
|
clause.having = parseWhere(nodeSelectClause.Having)
|
|
|
}
|
|
|
|
|
|
- return false
|
|
|
+ return true
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -347,32 +355,30 @@ func parseSelect(selectExprs tree.SelectExprs) string {
|
|
|
return selectFmtCtx.String()
|
|
|
}
|
|
|
|
|
|
-func parseFrom(from *tree.From) (bool, string) {
|
|
|
- asFromSubQuery := false
|
|
|
-
|
|
|
+func parseFrom(from *tree.From) (bool, string, error) {
|
|
|
switch fromTable := from.Tables[0].(type) {
|
|
|
case *tree.JoinTableExpr:
|
|
|
- asFromSubQuery = true
|
|
|
+ return true, fromTable.String(), nil
|
|
|
case *tree.AliasedTableExpr:
|
|
|
_, ok := fromTable.Expr.(*tree.Subquery)
|
|
|
- asFromSubQuery = ok
|
|
|
+ if ok {
|
|
|
+ return true, fromTable.String(), nil
|
|
|
+ } else {
|
|
|
+ return false, fromTable.String(), nil
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return false, "", errors.New("不支持的From类型")
|
|
|
}
|
|
|
-
|
|
|
- return asFromSubQuery, fmt.Sprint(from.Tables)
|
|
|
}
|
|
|
|
|
|
func parseWhere(where *tree.Where) string {
|
|
|
return where.Expr.String()
|
|
|
}
|
|
|
|
|
|
-func parseOrderBy(orderBy tree.OrderBy) []string {
|
|
|
- orderBySlice := make([]string, 0)
|
|
|
-
|
|
|
- for _, o := range orderBy {
|
|
|
- orderBySlice = append(orderBySlice, o.Expr.String())
|
|
|
- }
|
|
|
-
|
|
|
- return orderBySlice
|
|
|
+func parseOrderBy(orderBy tree.OrderBy) string {
|
|
|
+ orderByFmtCtx := tree.NewFmtCtx(tree.FmtBareStrings)
|
|
|
+ orderBy[0].Format(orderByFmtCtx)
|
|
|
+ return orderByFmtCtx.String()
|
|
|
}
|
|
|
|
|
|
func parseLimit(limit *tree.Limit) (int, int, error) {
|