Dorian
Dorian

Reputation: 761

SQLite.swift and Swift 3 "Ambiguous reference to member ==" in join

I'm developping an iOS application which use an SQLite database and I use the SQLite.swift library (https://github.com/stephencelis/SQLite.swift).

I'm trying to migrate my application in Swift 3, so I changed my library to use the branch swift3-mariotaku (https://github.com/stephencelis/SQLite.swift/tree/swift3-mariotaku)

I still have one issue when I try to use a join: Ambiguous reference to member ==

This is my code :

class ArticlesDAO {
    static let articles = Table("Article")
    static let id = Expression<Int?>("id")
}

class FiltresVehiculesDAO {

    let vfiltres = Table("VFiltre")
    let idVehi = Expression<Int?>("vehicule")

    func get(_ idVehicule: Int) throws -> [FiltreVehicule] {

        let sqlQuery = vfiltres.join(
            ArticlesDAO.articles,
            // Next Line : "Ambiguous reference to member ==" error
            on: vfiltres[idArticle] == ArticlesDAO.articles[ArticlesDAO.id]
        )

        //[...]
    }
}

After few searches, I found this thread Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug). So I try to apply the solution specifying the return type in the on argument like this :

on: (vfiltres[idArticle] == ArticlesDAO.articles[ArticlesDAO.id]) as Expression<Bool?>

I also try to precise every element :

on: ((vfiltres[idArticle] as Expression<Int?>) == (ArticlesDAO.articles[ArticlesDAO.id] as Expression<Int?>)) as Expression<Bool?>

The error is still the same.

I check the library code but I don't know how to resolve this, so this is the library code used, maybe it should help to understand :

The join method :

public func join(_ table: QueryType, on condition: Expression<Bool>) -> Self {
    return join(table, on: Expression<Bool?>(condition))
}

The == overload :

public func ==<V : Value>(lhs: Expression<V>, rhs: Expression<V>) -> Expression<Bool> where V.Datatype : Equatable {
    return "=".infix(lhs, rhs)
}

The String extension (for the infix method) :

extension String {
    func infix<T>(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression<T> {
        let expression = Expression<T>(" \(self) ".join([lhs, rhs]).expression)
        guard wrap else {
            return expression
        }
        return "".wrap(expression)
    }

    func wrap<T>(_ expression: Expressible) -> Expression<T> {
        return Expression("\(self)(\(expression.expression.template))", expression.expression.bindings)
    }

    func wrap<T>(_ expressions: [Expressible]) -> Expression<T> {
        return wrap(", ".join(expressions))
    }
}

Thank you for your help

Upvotes: 1

Views: 662

Answers (1)

Dorian
Dorian

Reputation: 761

I found the solution, my problem wasn't in the line designed by XCode (I think it may be an issue in Xcode 8 builder).

The problem was on the next lines, I didn't have change the .LeftOuter in .leftOuter :

let sqlQuery = vfiltres
    .join(
        ArticlesDAO.articles,
        on: ArticlesDAO.articles[ArticlesDAO.id] == vfiltres[idArticle]
    )
    .join(
        .leftOuter, // was : .LeftOuter
        DesignationsDAO.designations,
        on: [...]
    )

Upvotes: 1

Related Questions