|
sqliteProvider.command.Parameters.AddWithValue("$screenName", (object) task.screenName ?? System.DbNull.Value);
That should work. C# won't coerce a type (even if it's valid) to a type not present in the expression. Here it sees string and DBNull , so even though object is a valid base for them, object isn't available unless you explicitly opt-in. That's my understanding at least
EDIT: You might need a ? for the cast. Unsure since I'm still on an older version of C# so I haven't had to deal with that new stuff yet.
|
|
|
|
|
Very good point and thanks for posting.
I will try this out right now and let you know.
|
|
|
|
|
Oh my gosh!! I was so close!!!
That works -- well it compiles anyways. I will test to insure that it definitely does what I expect, but it looks good:
sqliteProvider.command.Parameters.AddWithValue("$screenName",(object)task.ScreenName ?? System.DBNull.Value);
Wow!
confirmed!! I built it and ran it and it works.
I'm so glad I ranted.
Thanks again.
|
|
|
|
|
That's an API problem, not really related to null or not null, but the fact that .NET DB drivers assume "null" as unset, and DBNull.Value as real null (WPF did it a little better, as we have Unset as a separate item, and null really means null).
You can probably create a helper/extension method that converts null to DBNull.Value and it should work fine.
I also consider it very bad that IDataParameter always box value types. It shouldn't need to do it, as I can clearly tell by working on C++ drivers that primitive types can just be primitive types and never "boxed" or similar there.
|
|
|
|
|
|
raddevus wrote: I need to actually insert a System.DbNull.Value into the databse -- that's a true DBNull -- not the String null which the db chokes on.
That statement makes no sense.
Given a string/text value in a database it can have one of the following values.
1. Null
2. Empty string. Some databases do not allow this
3. Any other non-empty value.
That list does not include 'DBNull'.
The 'DBNull' value is usually a value that is intended as a stand in for results for the first item in the list above.
Perhaps your real problem is that you need to represent the following
1. A value that is not null
2. User did not 'choose' anything. So you need to represent 'no value', but you cannot use 'null'.
In the above you then use a magical value. If your database supports it and there NO chance it will be needed then an empty string can be used. But otherwise some nonsensical value is chosen.
For example say you need to provide a customer telephone number. So you allow numbers. But for your special value you allow 'xxx-xxx-xxxx'. Naturally you must special case the code.
HOWEVER, this is not an idea solution. And you should first examine the requirements that state that 'null' cannot be used in the first place. That the database does not allow it is NOT a argument for that. Because that to is just code and it must meet the needs of the business and not arbitrary developer opinions.
|
|
|
|
|
|
First driving goldfish, now rats playing doom?
Should we be getting ready to bow to our pea-sized brain overlords?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Well to be fair, the size of brain doesn't seem to matter much. Rats are probably smarter than cats, and one of the few animals capable of metacognition (thinking about thinking basically - little philosophers, they are!)
One of the reasons I'm such a fan of scavenging animals like rats, racoons and crows is they are bloody intelligent. It makes them interesting as animals go.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: little philosophers, they are! SocRATes!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Well, there is a video in which an orangutan driving a golf cart and even take the turns
|
|
|
|
|
I pretty certain they were in front of me this morning.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
|
A couple of years ago we had a TV show where they took a bunch of different pet dogs and whittled them down via various agility and obedience tests etc until they had a dog which they taught to pilot an light aircraft, by using lights to indicate to it what adjustments to make. It didn't just have to fly straight and level, though, they set it a route it had to navigate.
They didn't expect it to take off and land, of course. A pilot took it up, then handed the controls over to the dog.
|
|
|
|
|
Wrong section, you should have posted that in the newsletter!
And I am ever so happy I navigated on this forum out of boredom!
|
|
|
|
|
I thought this qualified as weird at least. =)
Real programmers use butterflies
|
|
|
|
|
Mm quite the Rube Goldberg's contraption. Though I have to say, the rat doesn't seem very invested in the game to me!
|
|
|
|
|
|
OT: I've seen the randomly capitalized headlines for a while now. Is there a rule for 'randomizing' the capitals? Just trying to make certain I'm up to date on all the important stuff...
Rats playing DOOM seems kinda pointless. After all, it can be played on toasters. Teach them to perform open-heart surgery, though, and I'll be impressed!
|
|
|
|
|
David O'Neil wrote: OT: I've seen the randomly capitalized headlines for a while now. Is there a rule for 'randomizing' the capitals? Just trying to make certain I'm up to date on all the important stuff...
Sometimes it can be used to hold a secret message (e.g. just read the uppercase letters or just the lowercase letters), but that doesn't reveal anything obvious in this instance. 'RuN DoOM' is almost RANDOM; perhaps it should have been 'RAts ruN DoOM'
The longest alternating consonant/vowel/consonant/vowel country name (like cAnAdA / cUbA) is UnItEd ArAb EmIrAtEs.
|
|
|
|
|
|
Those are not suction cups... are rocket propellants...
PS: As you can see, ants came even from further...
|
|
|
|
|
Joan M: PS: As you can see, ants came even from further...
Yes they did Joan...
Yes they did...
|
|
|
|
|
...and cockroaches, spiders, fleas, ticks, etc. just to piss us off.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
Well, Cthulhu is a cephalopod. So, checks out!
|
|
|
|