SQLite.swift执行左连接并使用数据

时间:2015-07-24 13:54:28

标签: swift sqlite sqlite.swift

我正在尝试执行左连接

$week_ending = db_quote(date('Y-m-d',strtotime($_POST['week_ending'])));
快照。所以我做了以下事情。

SELECT TProgram.ProgramName, TProgram.ProgramPath From TProgram
LEFT JOIN TIcons ON TIcons.ProgramName = TProgram.ProgramName
WHERE TIcons.ProgramName IS NULL
GROUP BY TProgram.ProgramName

我无法检查它是否有效,因为以下内容会产生let program = db["TProgram"] let icons = db["TIcons"] let programNameDB = Expression<String>("ProgramName") let programNameDBI = Expression<String>("ProgramName") let programPathDB = Expression<String>("ProgramPath") let all = program.select(programNameDB, programPathDB).join(Query.JoinType.LeftOuter, icons, on: programNameDB == icons[programNameDBI]).filter(programNameDBI == "").group(programNameDB)

fatal error: ambiguous column name:

如果我尝试let item = all.first! let arr = Array(all) ,我可以在调试控制台中看到“TProgram”。

我如何访问数据?

更新 我尝试了以下内容。错误消失但似乎没有值。

println(all)

1 个答案:

答案 0 :(得分:2)

知道了。重要String?.leftouter

func readTProgramNames(){
    let program = db["TProgram"]
    let icons = db["TIcons"]
    let programNameDB = Expression<String?>("ProgramName")
    let programNameDBI = Expression<String?>("ProgramName")
    let programPathDB = Expression<String?>("ProgramPath")
    //let all = table.select(programNameDB, programPathDB).group(programNameDB)
    //let all = program.join("LEFT OUTER", icons, on: programNameDB == icons[programNameDBI])
    let all = program
        .select(program[programNameDB], program[programPathDB])
        .join(.LeftOuter, icons, on: program[programNameDB] == icons[programNameDBI])
        .filter(icons[programNameDBI] == nil)
        .group(program[programNameDB])

    for item in all{
        println("programName: \(item[program[programNameDB]]!)")
    }
}