Friday, 17 May 2013

OK, another handy new Railo feature

G'day:
I have some downtime @ cf.Objective() at the mo', so looking at some of the stuff Gert showed us in his presentation. It's that or have a beer... but it's perhaps slightly too early for that. Maybe... hmmm. Anyway, whilst I mull over having a beer, I have this article in my head, so I'll type it in.

Railo has a new function queryColumnData(). This is kind of an augmentation of valueArray(). valueArray() is a function I was unaware Railo had... it's an array equivalent of valueList(). I think returning an array is better than a list, so this is good stuff too.

Anyway, queryColumnData() works like this:

array queryColumnData(Query, column [, callback])

So one can either just specify the query and the column to return as an array, or one can pass-in a callback to, and this is called on each row value in the column before being appended to the resultant array. EG:

q = queryNew("");
queryAddColumn(q, "id", "Integer", [1,2,3,4]);
queryAddColumn(q, "en", "VarChar" , ["one", "two", "three", "four"]);
queryAddColumn(q, "ma", "VarChar" , ["tahi", "rua", "toru", "wha"]);

ids = valueArray(q.id);
english = queryColumnData(q, "en");


maori = queryColumnData(q, "ma", function(v){
    return ucase(v);
});

dump([ids,english,maori]);

Result:

Array
1
Array
1
string1
2
string2
3
string3
4
string4
2
Array
1
stringone
2
stringtwo
3
stringthree
4
stringfour
3
Array
1
stringTAHI
2
stringRUA
3
stringTORU
4
stringWHA

I like the idea of adding more callback functionality in the language. Nice one!

Anyway... I have a session to go to now. And then a beer.

--
Adam