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

SQLLiteral with Data interpolation #591

Closed
bikram990 opened this issue Aug 11, 2019 · 4 comments
Closed

SQLLiteral with Data interpolation #591

bikram990 opened this issue Aug 11, 2019 · 4 comments
Labels

Comments

@bikram990
Copy link

bikram990 commented Aug 11, 2019

What did you do?

I created a SQLLiteral with one of the interpolation as Binary Data.

What did you expect to happen?

I expected my Data to bind as whole.

What happened instead?

Bindings where created for each byte in the data and final sql ended up having to many bindings.

Environment

GRDB flavor(s): GRDB
GRDB version: 4.1.0
Installation method: CocoaPods
Xcode version: 10.2.1
Swift version: 5
Platform(s) running GRDB: iOS
macOS version running Xcode: 10.14.6

Demo SQL

try db.execute(literal: """ INSERT INTO tableName (identifier, data) VALUES (\(item.identifier), \(item.data)) """)

resulted in

INSERT INTO tableName (identifier, data) VALUES (?, (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?))

I know my expectations might be wrong here, as GRDB uses string interpolation and according to that I'm supposed to pass a string convertible item instead of Data. But I see that GRDB is able to recognize Data as a special type and has inserted () to contain its value. If GRDB is able to recognize this then why not support Data in SQLLiteral.

@groue
Copy link
Owner

groue commented Aug 11, 2019

Hello @bikram990,

What is the exact type of item.data?

@bikram990
Copy link
Author

Hi @groue ,
item.data is of Data type and the column is of blob type.

@groue
Copy link
Owner

groue commented Aug 11, 2019

Oops, sorry for the useless question. I could reproduce the unexpected interpolation.

The reason is that the Data conformance to the Sequence protocol kicks in when it should not: sql interpolation sees the data as a sequence of bytes instead of a whole data.

This will be fixed in the next GRDB version. Meanwhile, you can use this workaround:

// temp workaround for https://github.com/groue/GRDB.swift/issues/591
// Hide the Sequence in Data with item.data.databaseValue
"INSERT ... VALUES (..., \(item.data.databaseValue))"

groue added a commit that referenced this issue Aug 11, 2019
@groue groue added the bug label Aug 12, 2019
@groue groue closed this as completed in 8e38af9 Aug 13, 2019
@groue
Copy link
Owner

groue commented Aug 13, 2019

Fixed in v4.2.1

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

No branches or pull requests

2 participants