jorgebay/node-cassandra-cql — pull request #72 by DanielSmedegaardBuus (2014-03-20 16:25:43+00:00)
Title: Attempt casting of simple number types before throwing TypeError

Okay, so to continue the conversation :)

At the moment (in v0.5.0), if I do:

client.execute('SELECT * FROM cf WHERE intField = ?', ['1'], function () {});

Then NCC will guess the '1' value to be an integer, and call encodeInt(1), and everything goes according to plan.

If, however, I do:

client.execute('SELECT * FROM cf WHERE intField = ?', [{hint:'int', value:'1'}], function () {});

Then NCC will look at the hint and call encodeInt('1'), which will throw a TypeError, because of the string.

In other words: If we don't specify what we're sending, NCC will first try to guess what the type is, and then proceed accordingly if successful at doing so.

But if we DO specify what we're sending (or in this case, meaning to send ;) ), then we will be "penalized" for explicitly defining the schema type, and the code will fail.

I acknowledge there's a point in teaching people like me to sanitize their data :), but there are three reasons why I think this patch makes sense:

1) There's no type guessing going on that wasn't going on before. This only applies to cases where a hint is given. You might think of it as a service.
2) The behavior in 0.4.4 is to not throw an error, and thus those of us with "unsanitary" data won't have failures when upgrading.
3) There's no performance penalty at all. The casting is only performed when we'd otherwise throw a TypeError and die.

So ... If I'm not wrong in all of that (and I may be ;) ), then I hope you agree :dancers:

Cheers,
Daniel :)