【问题标题】:Why doesn't this sqlite query in a nested for loop return more than 1 result?为什么嵌套 for 循环中的这个 sqlite 查询不返回超过 1 个结果?
【发布时间】:2021-02-25 18:38:39
【问题描述】:

谁能帮我解决这个问题?我是 Swift 和 sqlite 的新手。

我将这个字符串传递给一个函数

let compositionstring = "iris, magenta, iris";

我将它转换为数组的地方

let compositionArr = string.components(separatedBy: ",")

然后我期待下面的代码查询数据库并打印组合字符串中每个的路径、文件名和类别。

       do {
        try compositionArr.forEach {
            print($0)
            
            for var files in try db.prepare(files.select(path, name, category).filter(category.like($0)).limit(1)) {
                print("path: \(files[path]), filename: \(files[name]), category: \(files[category])")

            }

        }

但我只得到第一个结果,之后什么都没有。

虹膜

路径:文件://localhost/Volumes/IWL%20Jen%20Vid/IWL%20Captions/Material_Sonia/Sonia%202019/IWL%20videos/Mexico/Palacio%20belle%20arte/IMG_7762.MOV,文件名:IMG_7762.MOV , 类别:鸢尾花

洋红色

虹膜

我必须缺少一些非常基本的东西。感谢您的帮助!

【问题讨论】:

    标签: ios swift xcode sqlite


    【解决方案1】:

    原因可能是其他项目没有匹配,所以 for 循环没有运行,因为 db.prepare...... 的结果为空

    【讨论】:

    • 感谢您的建议,但事实并非如此。如果我手动输入数组中的第二个条目并运行它,我会得到一个结果。路径:file://localhost/Volumes/IWL%20Jen%20Vid/IWL%20Captions/Material_Bernhard/Bernhard%20June%202018/IMG_1968.MOV,文件名:IMG_1968.MOV,类别:洋红色
    • 从你的字符串中有一个空格 -magenta 而不是 magenta ?你也可以单独试试看吗?
    • 是的,这就是解决方案!谢谢Sh_Khan
    猜你喜欢
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多