Last active
January 18, 2016 20:48
-
-
Save atuttle/08a912390d43db532b3c to your computer and use it in GitHub Desktop.
Which way is better? Why?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] } | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.