My goal is to store the DateTime when an event occurs. I have a conveyor system that has several Incoming conveyor stubs where product may be loaded. I have a MYSQL database that consists of one table and several columns. Each column name corresponds to one of the incoming sensors, DD121, DD122, and DD123 are the column names and also the sensor names. So, when sensor DD122 goes high, it triggers a Gateway Tag Change event. The Tag Change Event script is:
‘’’
if newValue.value:
Get the name of the tag that called this script
Tag_Name = event.getTagPath().getItemName()
Set the Parameters to pass to the Named Query
InductColumn = {Tag_Name}
t1 = system.date.now()
currentDateTime = system.date.format(t1,'yyyy-MM-dd HH:mm:ss')
Put the Parameters in a python dictonary
params = {"param1" : "InductColumn","param2" : "currentDateTime"}
Call the query
system.db.runNamedQuery("dockDoorUpdate", params)
‘’’
the Named Query is:
‘’’
INSERT INTO amazon_stats.dock_door_induct_counts :param1 VALUES :param2;
‘’’
When trying to test the named query, param1 is set to (DD122). param2 is set to 2020-09-14 09:24:59.
When I execute the query, I get the following error:
GatewayException: 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 ‘’(DD122)’ VALUES ‘2020-09-14 09:24:59.0’’ at line 1
If I test the script in the script console with static values that are ( I think) represented with param1 and param2
I am using MySQL. Please be gentle, big-time newbie with Ignition, Python, and SQL in general.
Thanks in advance.