I have multiple projects on a gateway, each with their own databases to store e.g. audit data. I would like to configure a single named query to query the database I choose. At the moment it's super awkward as I have to create multiple duplicate named queries, one for each database, and then have one Table component in Perspective for each one, only showing the one selected. Very inefficient...
There’s a special parameter type for selecting a datasource. If otherwise identical, only one NQ is needed.
I realise I never got back to this, and am trying to do something similar again. When you said there was a special parameter type, I'm not sure what you mean(t)?
https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery
These are the only parameters:
String path - The path to the Named Query to run. Note that this is the full path to the query, including any folders.
Dictionary[String, Any] parameters - A Python dictionary of parameters for the Named Query to use. [optional]
String tx - An transaction ID, obtained from beginNamedQueryTransaction. If blank, will not be part of a transaction. [optional]
Boolean getKey - Only used for Update Query types. A flag indicating whether or not the result should be the number of rows affected (getKey=0) or the newly generated key value that was created as a result of the update (getKey=1). Not all databases support automatic retrieval of generated keys. [optional]
In other db functions, there's a database
parameter which you can use to set the database to query against, but there's no such thing in the named query function
In the dictionary parameters you can pass a data with key as "database" and value as the name of the database.
In the named query set Database Connection to Parameter, don't add any extra parameter for "database".
I hope I understood the requirement correctly
Oh right, yep, that makese sense. I didn't know the option was even there! Thanks all