Looping updates in a transaction question (execUpdate vs beginNamedQueryTransaction)

I’m using ignition 8.3 and have some questions about looping a few thousand update statements.

We found that some data was entered incorrectly and its easier to update the rows programaicly rather than doing them manually.

Looking into using transactions I noticed that the runNamedQuery is deprecated for execUpdate while beginNamedQueryTransaction is still available.

I planned on creating a screen that shows the updates for validation and then using a named query for the update statement, looping the result set in a transaction with beginNamedQueryTransaction and performing the updates in one fail swoop.

Is there any reason to use execUpdate or something different? Any suggestions or alternatives? Thanks!

I would recommend using execUpdate since it handles scoping better. This was a pain point for projects that used NamedQuery in gateway and client scopes. ExecUpdates’ default behavior handles this gracefully. Specifically, the optional project argument.

Manual link: system.db.execUpdate | Ignition User Manual
Excerpt:

Note: If no project is specified when run in the Gateway scope, an associated project or the Gateway scripting project will be used.

2 Likes

Essentially, in 8.3 runNamedQuery was split into three functions - execQuery, execUpdate, and execScalar. They do essentially the same thing as they previously did, it's just a bit easier to reason about. You still create transactions with beginNamedQueryTransaction and pass transactions to the functions in the same way. As @code_skin mentioned, a key reason for the new functions was the unfixable error in the function signature(s) of runNamedQuery across different scopes.