I ran into a problem where the tag exists (or not) in my SQLTag structure but the tag.exists is not (or is) seeing the tag. Is there a chance the internal database got corrupted before the SQLTag was completely created?
When I first ran this code (see below), an SQL Query timed out on me while I was trying to monitor the database tables. The tags were not created yet, but I was still getting the same error. I imported the tags in from a test project but it is still generating the same error.
The console is generating the following error:
Gateway Timer script:
...
#AlarmState tag
sTag = "AlarmState"
sTagPath = sParentPath + "/" + sTag
if not system.tag.exists(sTagPath):
system.tag.addTag(parentPath=sParentPath, name=sTag, tagType="DB", dataType="Boolean")
system.tag.write(sTagPath, 0)
...
With Greg Simpson’s help, we narrowed this down to the fact that we needed to prefix the tag path and folder name with the specific SQLTag provider when checking to see if the tag exists and also when creating the new tags with addTag:
...
sParentPath = "[MySQLTagProvider]" + sParentPath
#AlarmState tag
sTag = "AlarmState"
sTagPath = sParentPath + "/" + sTag
if not system.tag.exists(sTagPath):
system.tag.addTag(parentPath=sParentPath, name=sTag, tagType="DB", dataType="Boolean")
system.tag.write(sTagPath, 0)
...