The documentation for system.db.beginNamedQueryTransaction fails to mention that an argument for ‘project’ is required when running in the gateway scope.
Why is the project name required at all to begin a named query transaction?
What’s the logic behind the differences in named query functions between gateway/client scopes? It would make everything simpler if ‘project’ was an optional parameter in the client scope.
Thanks for catching the documentation issue – I’ll give that dept a heads up.
As to your other questions…
Named queries are a project resource – you could have a named query with the same path in multiple projects. When you begin a transaction, we need to know what project that transaction belongs to in order to send that info to the correct named query execution manager. In the designer/client we know the name of the project, but in the gateway you need to tell us.
If you could put project as a parameter in the client scope it would imply you could run named queries from other projects in that client, which you can’t do (except via something like a sendRequest() or a tag or other non-project route).
If you need the same named query in multiple projects, you can use inheritance. Doesn’t solve the problem of trying to reuse the same script in both gateway and client scope – you would need to check the scope you’re in and run the appropriate version of the function.
I think this is the source of some confusion. In the gateway, you know the project when the caller is a gateway event script. You don't know the project when called from a tag event. The corresponding scripting functions in system.db.* that have a datasource argument should have been the model for the named query functions. These functions take an optional datasource in client and gateway project scopes, but the argument is mandatory in gateway non-project scope. Arguably, with v8's new global scripting project, it could be optional there, too.
The project argument for named queries should have been optional for gateway project scopes, and mandatory for gateway non-project scope. (Again, arguably optional in v8 by using the global scripting project.) Whether it should be allowed for client scopes (I think it should) is not relevant for the gateway cases.
The function signature in the gateway (with the project argument first) complicates the situation, but I think it should be changed. It is the one part of Ignition that does not intuitively fall back to the caller's project as needed.
Though the named query vs standard db transaction dichotomy still hasn't been paid off, and the same project name signature issue still exists for beginNamedQueryTransaction.
My goal is to add a single (context manager) transaction function that, ideally, works for both named queries and 'regular' DB queries. Not sure whether that plan will survive contact with the enemy the codebase.