Closed jiyang7 closed 1 month ago
StatementSelect().select(Column.all()).from("tableName1").where(condition1).union().select(Column.all()).from("tableName2").where(condition2)
请问 LIMIT 40是否添加 如果按回复添加 StatementSelect().select(Column.all()).from("tableName1").where(condition1).limit(40).union().select(Column.all()).from("tableName2").where(condition2)
通过输出 description 发现语句是,总数限制40,并非单条语句限制40条 SELECT FROM tableName1 WHERE condition1 union SELECT FROM tableName2 WHERE condition2 LIMIT 40 并非 (SELECT FROM tableName1 WHERE condition1 LIMIT 40) union (SELECT FROM tableName2 WHERE condition2)
SQLite's select syntax can only put limit at the end of the statement: https://www.sqlite.org/lang_select.html
May be you should use two queries.
麻烦看下第一个问题
我在一个do catch内查询同一个表中两个不同条件的数据,发现结果1 result 和 结果2 otherResult 数据相同,理论上两个条件不同结果是不应该相同的,如果分开至两个do catch执行两次查询结果则不同。
do {
let condition = PCNotificationMessageInfo.Properties.notifyType.in([6, 7, 10])
let select = try messageNoticeDB.prepareSelect(of: MessageNoticeTableType.messageInfo.tableType, fromTable: MessageNoticeTableType.messageInfo.rawValue).where(condition).limit(40)
var result = try select.allObjects(of: PCNotificationMessageInfo.self)
resultArray.append(contentsOf: result)
let otherSelect = try messageNoticeDB.prepareSelect(of: MessageNoticeTableType.messageInfo.tableType, fromTable: MessageNoticeTableType.messageInfo.rawValue).where(!condition)
let otherResult = try otherSelect.allObjects(of: PCNotificationMessageInfo.self)
resultArray.append(contentsOf: otherResult)
} catch {
}
请问这个问题有原因么?issues/wiki是否有相关内容?
You can give a demo project to reproduce it.
简单建了一个测试工程,麻烦看一下。
https://github.com/jiyang7/WCDBTestSample.git
点击“SelectWrongTestData”按钮,“selectWrongTestData”方法中,“result”和“otherResult”的个数为什么相同???即使不加limit限制,“result”和“otherResult”的个数也会相同,这显然是不正确的。
Got it, it is indeed an obvious bug. I will fix it in the next version.
For now, you can use this interface to avoid this problem: database.getObjects(on: Sample.Properties.all, fromTable: tableName, where: condition, orderBy: [orderBy])
Fixed in v2.1.6
The language of WCDB
The version of WCDB
The platform of WCDB
The installation of WCDB
What's the issue?
尝试使用union发现无法使用括号 let statementSelect = StatementSelect().select(properties).from(tableName).where(condition).limit(40).union().select(properties).from(tableName).where(!condition)
请问如下语句该如何实现 (SELECT FROM tableName WHERE condition1 LIMIT 40) union (SELECT FROM tableName WHERE condition2)