Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Query embed blocks support UNION queries https://github.com/siyuan-note/siyuan/issues/16594

Daniela201aebf59fc
diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go
index 6387febf7c..e032bac45f 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
}