Scripting help: inserting data to a table, none type, dictionary, dynamic paths, f-string

Not true for python. Single quoted strings process backslashes just like double-quoted strings.

I use single quotes for keys or “keywords”, and double quotes for simple strings.

some_dict = {
    'key': "value"
}
some_function("string parameter", 'constant parameter')
# for example:
system.tag.configure(path, tags, 'o') # and not "o"

I think it makes it easier to read.

1 Like

I require some assistance.

Hours = self.parent.parent.getChild("flex_0").getChild("TextField").props.text
if Hours==None:
	 Hour=0
	
test1 = 1.0*Hours

getting an error

Caused by: org.python.core.PyException: Traceback (most recent call last):
 File "", line 51, in runAction TypeError: can't multiply sequence by 
non-int of type 'float'

omg don’t tell me, don’t even say it
facepalm .text

why would someone set hours to text? omg

3 Likes

Haha we all make mistakes. So you got the fix then?

1 Like

The person who made it did not know about numerical entry field components I think.

They stuff it in a table that has been used for months.

So now I am trying to do math on it.

This works in script console

Hours = None
if Hours is None or Hours =='' or Hours==' ':
 	Hours='4'
 
print (Hours)	
 	
this=int(Hours)

print (this*2)

but in the button, this does not work

Hours = self.parent.parent.getChild("flex_0").getChild("TextField").props.text
if Hours is None or Hours =='' or Hours==' ':
	 Hours='0'
	
this=int(Hours
test1 = 1.0*this
Caused by: org.python.core.PyException: 
Traceback (most recent call last): File "",
 line 52, in runAction TypeError: unsupported operand type(s) for *: 
'com.inductiveautomation.ignition.common.model.values.BasicQualifiedValue' 
and 'int'

ah I think this one was me, need .value
was reading a tag and multiplying it by the value in hours
needed to convert hours to an integer and use the .value of the variable that read the tag

one good thing is when I quote the error, that is searchable in the forums

I am getting errors on this still

Error executing 
system.db.runPrepUpdate(INSERT INTO mytable (Date, Shift, Machine, number, 
othernumber, Hours, 
thirdnumber, fourthnumber, fifthnumber, productinfo, Operator, materialdetail, 
Mechanic, Comments)
 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), [Tue Apr 05 11:35:23 EDT 2022, 1,
 thismachine, 7799, 
9268, 1, 1250.0, -0.006175820387899876, 0.17048554282596837, alphanumeric, , 
productinfo, , test 
3],databaseinfo, , false, false)

I guess the " [ " "] " is noting the subset of information

I don’t know what the actual error is about

com.inductiveautomation.ignition.common.script.JythonExecException:
 Traceback (most recent call last): File "", line 47, in runAction at 
com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) 
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258) at
 jdk.internal.reflect.GeneratedMethodAccessor147.invoke(Unknown Source) at 

java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at 
java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO 

At a glance it looks like perhaps your list of values comes up to a length 13. Maybe a missing comma?

2 Likes

I see in your values you sometimes having nothing, like a complete blank in your list

alphanumeric, , and productinfo, , test . If you want those columns to be Null you can pass in None as the value. I think this may be messing with it or may be a miscount.

1 Like

is there a way to assign named variables instead of question marks in prepUpdate ?

works for some machines
maybe a tag is bad

No, anything other than a ? Will not work with the prepared statement functions.

2 Likes

The square brackets denote a list, as system.db.runPrepUpdate() requires you to supply a list of values to use in place of the question marks.

1 Like

I have 14 “?”
14 pieces of data

VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

[Tue Apr 05 13:01:51 EDT 2022, 1, machine, 1234, 5678, 0, 0.0, 0, 0.00, X85, Green, Red, Big red oak 2x4, BACK, test 5],


it works for one machine, but not this one

yet I have all the data here
I think I need to do a support ticket with nda protection, something must be wrong in the subset of data

I counted 14 question marks and 15 items in your list.

3 Likes

For this to work, the number of columns in the Insert statement must match the number of “?” in the values list, which must match the length of the list supplied to the runPrepUpdate function.

If you supply more values in the list than are needed I don’t think it will error out, it will just fail silently, as in it appears to work but you don’t write all the data to the database. Don’t know that for certain though.

If you have less values in the list than are needed I believe you will get an error.

If you have more columns than “?” you will get a SQL Syntax error, and the same for if you have more “?” than Columns.

If it needs to be dynamic there are ways to make it dynamic.

1 Like

I don’t see it when I test in excel

You aren't posting complete error reports, so none of us will ever know what the actual error is, either.

1 Like

I submitted a ticket, but also responded to that count comment.

The error:

com.inductiveautomation.ignition.common.script.JythonExecException:
 Traceback (most recent call last): File "", line 47, in runAction at 
com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) 
at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:258) at
 jdk.internal.reflect.GeneratedMethodAccessor147.invoke(Unknown Source) at 

java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at 
java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO

and approximately

system.db.runPrepUpdate(INSERT INTO mytable (Date, Shift, Machine, number, 
othernumber, Hours, 
thirdnumber, fourthnumber, fifthnumber, productinfo, Operator, materialdetail, 
Mechanic, Comments)
 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?), [Tue Apr 05 11:35:23 EDT 2022, 1,
 thismachine, 7799, 
9268, 1, 1250.0, -0.006175820387899876, 0.17048554282596837, alphanumeric, , 
productinfo, , test 
3],databaseinfo, , false, false)

You’ve cut off all the “caused by” groups that actually tell us something.

2 Likes

Yah, I submitted a ticket.

it says like all these unknown sources

then it lists my query with exactly the data I wanted it to have, but don’t want to show specifics here because that is all company side info

if my count was off though, that would have been nice
It is so bizarre to me because everything I check is correct, and other machines work fine with the prepupdate

Going to be real honest, testing in excel is not the same as testing in ignition. At the very least you should be testing in the script console with Ignition functions.

2 Likes