From a201aebf59fcc21fb4ceb7ded7de095d8152fcb8 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 16 Dec 2025 12:15:28 +0800 Subject: [PATCH] :art: Query embed blocks support UNION queries https://github.com/siyuan-note/siyuan/issues/16594 Signed-off-by: Daniel <845765@qq.com> --- kernel/sql/block_query.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 }