Insert information on SQL with script editor

Hello

I have three buttons and 2 Display LED, in the button 1 and button 2 I have active the event action performed for sum the event click of button on tag sum event an show it in Display LED. in the button 3 I need the action click for save the informacion of button 1 and button 2

image

image

How could I save this information using script editor?

this is my code currentrly

fpmi.db.runUpdateQuery("INSERT INTO MyTable (Column1, Column2) VALUES ('Linea_Assy', 'event.source.parent.getComponent('Label 1').text', 'event.source.parent.getComponent('Led Display').dataQuality''')")

type or paste code here

Assuming 7.9:

clear = system.tag.read("[default]CLEAR")
decol = system.tag.read("[default]DECOLORACION")
system.db.runPrepUpdate("INSERT INTO db.table_name (column_1_name, column_2_name) VALUES (?,?)", [clear, decol])

hello @Matrix_Engineering ring

I have this INSERT

INS =  "INSERT INTO Defectos (Linea, Qty, Defecto, fecha) VALUES (?, ?, ?, ?)"
crackQty = system.tag.read("Botones/Linea_Assy/CRACK")
FisuraQty = system.tag.read("Botones/Linea_Assy/FISURA")
Fecha = system.date.now()
system.db.runPrepUpdate(INS,['Linea_Assy',crackQty.value,'Crack',Fecha],["Linea_Assy",FisuraQty.value,"Fisura",Fecha],"TOPY_MW")

but retur this error

Error executing script for event actionPerformed on component: Button 3

INS =  "INSERT INTO Defectos (Linea, Qty, Defecto, fecha) VALUES (?, ?, ?, ?)"
crackQty = system.tag.read("Botones/Linea_Assy/CRACK")
FisuraQty = system.tag.read("Botones/Linea_Assy/FISURA")
Fecha = system.date.now()
system.db.runPrepUpdate(INS,[crackQty, Fecha, FisuraQty, Fecha],"TOPY_MW")

You have the formatting wrong, see above as an example still might not be exactly what you need but will hopefully guide you

But I need the data CrackQty and FisuraQty save on Qty

Do you want the sum of them? So if crackQty is 2 and FisuraQty is 3 then qty in DB = 5?

No, I need to save crackQty and FisuraQty in the Qty database field

in SQL something like this

INSERT IN DEFECTS (Linea, Qty, Default, date) VALUES ('Linea_Assy', crackQty.value, 'Crack', Date), ('Linea_Assy', FisuraQty.value, 'Fissure', Date)

You need to run two insert statements then. You can’t write two values to one column.

I can’t have another solution, something like this

INS =  "INSERT INTO Defectos (Linea, Qty, Defecto, fecha) VALUES (?, ?, ?, ?)"
crackQty = system.tag.read("Botones/Linea_Assy/CRACK")
FisuraQty = system.tag.read("Botones/Linea_Assy/FISURA")
Fecha = system.date.getDate(year, month, day)
VAL = [('Linea_Assy',crackQty.value,'Crack',Fecha),('Linea_Assy',FisuraQty.value,'Fisura',Fecha)]
system.db.runPrepUpdate(INS,VAL,"TOPY_MW")

I don’t have so many INSERT

You could either run the INSERT query twice or insert multiple rows at once.

# Option 1
query = "INSERT INTO Defectos (Linea, Qty, Defecto, fecha) VALUES (?, ?, ?, ?)"
...
# Run each INSERT statement separately
values = ['Linea_Assy', crackQty.value, 'Crack', Fecha]
system.db.runPrepUpdate(query, values )
...
values = ['Linea_Assy', FisuraQty.value, 'Fisura', Fecha]
system.db.runPrepUpdate(query, values )

# Option 2
query = "INSERT INTO Defectos (Linea, Qty, Defecto, fecha) VALUES (?, ?, ?, ?), (?, ?, ?, ?)"
...
values = ['Linea_Assy', crackQty.value, 'Crack', Fecha, 'Linea_Assy', FisuraQty.value, 'Fisura', Fecha]
system.db.runPrepUpdate(query, values )

I haven’t tried something like Option 2 in Ignition, but it’s a valid SQL statement. Assuming your DB is MSSQL; allthough a little hard to read.

thank @thecesrom srom

the second option is my solution