You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
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 beNULL
.If instead I do:
var values = ["externalKey":35, "title": nil]
db.insertInto("Items", values: values, error:&error)
The
externalKey
field will be35
. 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?
The text was updated successfully, but these errors were encountered: