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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s