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

Setting one parameter nil (NULL) in an insert sets all subsequent parameters to NULL or default. #38

Closed
ghost opened this issue Mar 22, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 22, 2015

I have been working on building a simple ORM on top of Squeal, and overall it has been working great. But as I have been making and testing swift optional parameters I noticed that inserts are no longer being handled correctly. When I pass in a [String, Bindable?] Dictionary, if any of the values are nil(NULL), subsequent values are not being handled correctly.

For example, if I have a table that looks like:
CREATE TABLE Items (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
title VARCHAR,
externalKey INTEGER
);

And I do an insert like:
var values = ["title": nil, "externalKey":35]
db.insertInto("Items", values: values, error:&error)
The externalKey field will be NULL.

If instead I do:
var values = ["externalKey":35, "title": nil]
db.insertInto("Items", values: values, error:&error)
The externalKey field will be 35. So, order in this case makes the difference on whether it works.

To reproduce, you just need these 4 lines of code:
var error : NSErrorPointer = nil
db.execute("CREATE TABLE Items (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR,externalKey INTEGER);", error:error)
var values : Dictionary<String, Bindable?> = ["title": nil, "externalKey":35]
self.db!.insertInto("Items", values: values, error: error)

Since I found this issue, I also tried testing it with updates. Updates also had issues, but in some ways more substantive because if there were any nil values, they would just not update any of the values.

Is there something additional that I am missing in how to handle nil values on an insert or update?

@ghost ghost changed the title Setting one parameter nil (NULL) in an insert sets all subsequent parameters to NULL or default. Setting one parameter nil (NULL) in an insert sets all subsequent parameters to NULL or default. Mar 22, 2015
@nerdyc nerdyc closed this as completed in 0fdfd39 Mar 23, 2015
@nerdyc
Copy link
Owner

nerdyc commented Mar 23, 2015

Good catch! Thanks for reporting in such detail. It made it easy to spot what was going on and fix quickly.

@ghost
Copy link
Author

ghost commented Mar 23, 2015

Great, you fixed that fast. By the way, great project I am really enjoying working with it.

Thanks!

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

No branches or pull requests

1 participant