Skip to content

Instantly share code, notes, and snippets.

@atuttle atuttle/approach_a.cfc
Last active Jan 18, 2016

Embed
What would you like to do?
Which way is better? Why?
var messageStatus = new util.iQuery("
select
status
from
Message
where
messageId = :id
",{
id: { cfsqltype: "cf_sql_numeric", value: batch.messageId[1] }
});
if (messageStatus.status != "archived"){
new util.iQuery("
update
Message
set
dateTimeArchived = current_timestamp
,status = 'archived'
where
messageId = :id
",{
id: { cfsqltype: "cf_sql_numeric", value: batch.messageId[1] }
});
}
new util.iQuery("
update
Message
set
dateTimeArchived = current_timestamp
,status = 'archived'
where
messageId = :id
and status <> 'archived'
",{
id: { cfsqltype: "cf_sql_numeric", value: batch.messageId[1] }
});
@barneyb

This comment has been minimized.

Copy link

commented Jan 18, 2016

In general, I'd say "b", because it only requires a single round trip to the database (and no resultset inflation, which may or may not matter). Approach "a" also requires a transaction in order to behave correctly, though hopefully you're using one regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.