Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace all of a table’s columns using * #249

Closed
S4TNEW opened this issue Oct 8, 2015 · 5 comments · Fixed by #363
Closed

Namespace all of a table’s columns using * #249

S4TNEW opened this issue Oct 8, 2015 · 5 comments · Fixed by #363
Labels

Comments

@S4TNEW
Copy link

S4TNEW commented Oct 8, 2015

Hello,

after changing to the swift2 branch it is not possible to select all table columns from a join query using [*]:

let db = FLFDBManager.sharedInstance.database()!
var tyres = Table(FLFDatabaseTables.MountedTyre)
let articles = Table(FLFDatabaseTables.Article)
let brands = Table(FLFDatabaseTables.Brand)
let vehicles = Table(FLFDatabaseTables.Vehicle)
let warehouses = Table(FLFDatabaseTables.Warehouse)

tyres = tyres.join(JoinType.LeftOuter,
            articles, on:
                tyres[FLFMountedTyre.kItemNumber] == articles[FLFArticle.kItemNumber] &&
                tyres[FLFMountedTyre.kCompanyId] == articles[FLFArticle.kCompanyId])
tyres = tyres.join(JoinType.Inner,
            brands, on:
                articles[FLFArticle.kBrand] == brands[FLFBrand.kBrandcode])
tyres = tyres.join(JoinType.Inner,
            vehicles, on:
                tyres[FLFMountedTyre.kVehicleNo] == vehicles[FLFVehicle.kVehicleNo] &&
                tyres[FLFMountedTyre.kCompanyId] == vehicles[FLFVehicle.kCompanyId])
tyres = tyres.join(JoinType.Inner,
            warehouses, on:
                tyres[FLFMountedTyre.kWarehouseNo] == warehouses[FLFWarehouse.kWarehouseNo])

tyres = tyres.filter(tyres[FLFMountedTyre.kCompanyId] == companyId && vehicles[FLFVehicle.kCustomerNo] == customerNo)
let x = tyres.select(tyres[*]) // Error: Cannot invoke 'select' with an argument list of tyre '(Expression<Void>)'

Are we doing something wrong? According to the documentation this should work as it has been in the trunk version. If we change the [*] to any column name the compile succeeds but we don't want to add every column manually in the code.

Thank you in advance

@shnhrrsn
Copy link

I'm also running into this, the following code:

let query = someTable.select(someTable[*])

Throws: Cannot invoke 'select' with an argument list of type '(Expression<Void>)'

The compiler also gives some more info: Overloads for 'select' exist with these partially matching parameter lists: ([Expressible]), (Star), (Expression<V>), (Expression<V?>)

@stephencelis
Copy link
Owner

Looks like a regression. If you can avoid table.* in the meantime (either by using the implicit * for everything, or by using explicit column names), that should hopefully get you situated for now.

@hiltonc
Copy link
Contributor

hiltonc commented Nov 28, 2015

+1

@mikemee
Copy link
Collaborator

mikemee commented Jan 10, 2016

Confirmed this is still happening with the current Swift (2.1.1).

Any swift geeks want to take a pass at this? Likely some some syntax change between 1.x and 2.x. The relevant code is https://github.com/stephencelis/SQLite.swift/blob/master/Source/Typed/Query.swift, around line 113:

    public func select(star: Star) -> Self {
        return select([star(nil, nil)])
    }

Here's a copy-paste playground repo case:

import SQLite

let db = try! Connection()
db.trace { print($0) }

let emails = Table("emails")
let to = Expression<String>("to")
let subject = Expression<String?>("subject")

try! db.run(emails.create {t in t.column(to); t.column(subject)} )
try! db.run(emails.insert(to <- "stephen@example.com", subject <- "Hello, world!" ))

let query = emails.select(emails[*])

for row in try db.prepare(query) {
    print (row)
}

This gives the error:

playground1624.swift:13:20: error: cannot invoke 'select' 
with an argument list of type '(Expression<Void>)'
let query = emails.select(emails[*])
                   ^
playground1624.swift:13:20: note: overloads for 'select' exist with these partially 
matching parameter lists: ([Expressible]), (Star), (Expression<V>), (Expression<V?>)
let query = emails.select(emails[*])
                   ^

@mikemee
Copy link
Collaborator

mikemee commented Jan 10, 2016

Note the work around for now is to change:

let query = emails.select(emails[*])

to

let query = emails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants