Passing query string as a script

How do I pass a query string in a script?
image

This script is not correct:

p1 = event.source.parent.getComponent('pid 1').intValue
p2 = event.source.parent.getComponent('SpecID').selectedValue
p3 = event.source.parent.getComponent('Data').text
p4 = event.source.parent.getComponent('DBColumn').selectedValue

parameters = {"pid":p1,
			"specID":p2,
			"data":p3,
			"column":p4}
	
system.db.runNamedQuery("UpdateSpec",parameters)

Seems like you are trying to pass {column} aka your p4 variable correctly, QueryStrings get {}.

Are you getting any error or stack trace, that would be helpful in figuring out what is going wrong.

1 Like
Traceback (most recent call last):
  File "<event:actionPerformed>", line 11, in <module>
com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '0'.

	caused by GatewayException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '0'.
	caused by Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '0'.

Ignition v8.1.33 (b2023101913)
Java: Azul Systems, Inc. 17.0.8

This is what i'm getting

Perhaps you should print out p4 before the database call to see what it has. (I think you are getting a number from your dropdown, not a column name.

5 Likes

@pturmel you are absolutely right. I am sending the number. Corrected with string and now all good.
Thank you all.

Consider hardening your named query by using identifier quoting around the column name placeholder's curly braces. This reduces the chances that garbled data (or malicious data) can get through to your database.

2 Likes