Railo and MySQL column alias

This seems like a very odd situation, but Railo has stopped supporting column aliases by default – well it’s the JDBC database driver I think… I’m not too good at all this back end java/database stuff.

But basically it all worked fine, now I’ve upgraded Railo, and things like this will throw an error.

SELECT col1 AS colOne FROM table

I don’t see why, this is such a common thing to do… Anyway, some one else has had the exact same problem not that long ago, and Google very kindly found me their blog post so I could fix it.

You just have to set “Alias Handling” to “true” for your datasources in the Railo Server Administrator. Then every thing works fine again.

I think the point of it is something to do with being able to grab the true column name and get hold of better metadata, but at the moment that’s no use to me!

I really hope Adobe don’t start doing this with Coldfusion!

Credit has to go to Anuj Gakhar for this fix: http://www.anujgakhar.com/2012/01/11/railo-mysql-and-column-aliases/

MySQL update/insert/delete rows affected in CFScript

There’s a way of getting the rows affected by an update, insert or delete MySQL query in CFScript.

I didn’t realise this until yesterday, and I’ve been doing this for a while now. I really should read more release notes.

I’ll update my http://skeater.co.uk/page.cfm/CFScript-Snippets page to show this, but I thought it was worth posting about anyway

// create query string
strSelectRows = 'DELETE FROM table WHERE col = "potato"';

// create query, assign datasource, assign query string, execute and capture returned result
qrySelectRows= new Query();
qrySelectRows.setDataSource(APPLICATION.dsn);
qrySelectRows.setSQL(strSelectRows);
qrySelectRows= qrySelectRows.Execute().getResult();

// dump results out
writeDump(qrySelectRows.getPrefix().recordcount);
writeDump(qrySelectRows.getPrefix());

Check the demo here to see the tasty results. I’ve also shown the whole prefix component in the demo.