diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go index 6387febf7..e032bac45 100644 --- a/kernel/sql/block_query.go +++ b/kernel/sql/block_query.go @@ -602,6 +602,38 @@ func SelectBlocksRawStmt(stmt string, page, limit int) (ret []*Block) { } stmt = sqlparser.String(slct) + case *sqlparser.Union: + union := parsedStmt.(*sqlparser.Union) + if nil == union.Limit { + union.Limit = &sqlparser.Limit{ + Rowcount: &sqlparser.SQLVal{ + Type: sqlparser.IntVal, + Val: []byte(strconv.Itoa(limit)), + }, + } + union.Limit.Offset = &sqlparser.SQLVal{ + Type: sqlparser.IntVal, + Val: []byte(strconv.Itoa((page - 1) * limit)), + } + } else { + if nil != union.Limit.Rowcount && 0 < len(union.Limit.Rowcount.(*sqlparser.SQLVal).Val) { + limit, _ = strconv.Atoi(string(union.Limit.Rowcount.(*sqlparser.SQLVal).Val)) + if 0 >= limit { + limit = 32 + } + } + + union.Limit.Rowcount = &sqlparser.SQLVal{ + Type: sqlparser.IntVal, + Val: []byte(strconv.Itoa(limit)), + } + union.Limit.Offset = &sqlparser.SQLVal{ + Type: sqlparser.IntVal, + Val: []byte(strconv.Itoa((page - 1) * limit)), + } + } + + stmt = sqlparser.String(union) default: return }