telophase: (Default)
telophase ([personal profile] telophase) wrote2009-12-07 11:49 am

(no subject)

This won't mean anything to 99% of you, but I finally cracked a problem with our SQL queries to the catalog at work. We've parameterized them using ADO Command objects to help stop SQL injection attacks, and were having a bitch of a time connecting to the catalog with some SELECT queries, which would fail with an "Invalid use of default parameter" error.

Turns out the problem lies in sending a parameter without a value. When working in classic ASP, VBscript automagically puts in a special null called DBnull in those cases, which causes SQL Server (eta: Oracle, in this case, actually) to freak out. You have to explicitly rename it to null (strVariable = null). Solution found here.

I had no clue there were different types of nulls. I mean, it's a null!

(Most of you, if you read all the way through that, are now thoroughly confused, but maybe it'll eventually help someone who's Googling the problem. :D)
(deleted comment)

[identity profile] telophase.livejournal.com 2009-12-07 10:21 pm (UTC)(link)
I'm still boggling, actually, as my programming experience is nowhere near broad enough to have run into typed nulls before.

[identity profile] vom-marlowe.livejournal.com 2009-12-07 07:01 pm (UTC)(link)
Different kinds of nulls? That seems unfair. I always found that SELECT queries were tricksy, but that's something new and special.

[identity profile] telophase.livejournal.com 2009-12-07 10:19 pm (UTC)(link)
We'd been chasing our tails on this for ages, assuming it had something to do with the database, as the queries we were hitting it on were from the catalog's database and not the one we use for the website. It was a fortuitous combination of keywords that got me the answer from Google finally. :)

[identity profile] tool-of-satan.livejournal.com 2009-12-07 07:11 pm (UTC)(link)
I've certainly encountered typed nulls before, e.g.

string foo = null;
othertype bar = null;
foo = bar;

will generally speaking not work unless you are using a very weakly typed language. That might be what is going on here, but I dunno from ASP.

[identity profile] telophase.livejournal.com 2009-12-07 10:22 pm (UTC)(link)
It's something I'm definitely going to be keeping in mind from now on!

[identity profile] nockergeek.livejournal.com 2009-12-07 07:31 pm (UTC)(link)
That's interesting. I don't think I've encountered typed nulls when working with either PHP or Java, but it's good to know that they're out there in some languages.

[identity profile] telophase.livejournal.com 2009-12-07 10:23 pm (UTC)(link)
Yeah. It seems non-intuitive to me, but I assume there were Reasons for setting it up that way. (Whether they were good reasons may be another matter entirely. XD)

[identity profile] golden-bastet.livejournal.com 2009-12-08 02:06 am (UTC)(link)
I don't really work with coding databases these days, but... I actually know what you're talking about. And no, I thought a null was a null, too.