Hey all,
I'm having an issue executing a Named Query with parameters of type QueryString that get their value from a variable.
Database: MySql
I have the following code for running a Named Query:
table_name = query_params[0]
column_name = query_params[1]
system.perspective.print(table_name)
system.perspective.print(column_name)
# Convert duration of query into Days, as this is used in Named Query
duration_in_days = Cpv_Utilities.minutes_to_days(self.custom["chart-data"]["duration-minutes"])
# Parameters for Named Query
params = {"tableName":table_name, "columnName":column_name, "duration":duration_in_days}
data = system.db.runNamedQuery("CpvDashboard/ManualChartDataDaily", params)
The Named Query's parameter types for tableName
and columnName
are QueryString
and the Data Type assigned to them (in the Named Query editor) is String
.
I have verified, via the print statements, that I have the correct string values for script variables table_name
and column_name
.
If I use string literals for the values of keys tableName
and columnName
in the params
, the Named Query works. But when I try to assign those keys their value via variable assignment, it fails.
I would appreciate any feedback on this. Thank you.
ETA:
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"report_p4" WHERE t_stamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 90 DAY) * 100' at line 5
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:972)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.executeQuery(SRConnectionWrapper.java:973)
at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper.runPrepQuery(SRConnectionWrapper.java:167)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.runPrepQuery(NamedQueryExecutor.java:490)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:399)
... 32 common frames omitted