Messagebox and result of a select statement

Hi Guys,
I have the following code in the ‘Script Editor’ of the ‘MouseClicked’ event of a button.

[code]response = fpmi.db.runQuery(“select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Automatic Operation’, ‘digital-out’, ‘Direct Operate’, ‘None’, ‘Close’, ‘500’, ‘500’)” %(event.source.parent.parent.rns_port,event.source.parent.parent.Device));

fpmi.gui.messageBox(“the response for the control is %s” % response )[/code]

The problem is that the message box that pops up says: "the response for the control is " instead of actually showing the message which is received after the execution of the stored procedure called by the select statement.

Regards
Qurban

Hi-

Looks like you want to perform a scalar query, that is- one that only returns 1 value. Otherwise, as is happening in this case, you’re going to get back a set of rows, or a single row with multiple columns. Your query is selecting ‘*’ after all, so the first thing to do would be to select the specific column you want, and then run it with the “fpmi.db.runScalarQuery” function instead. That function will return the first value it sees from the result set as an actual value that you can pass in to your message box.

Regards,

I just want to point out that the example scripts on the relevant page of the user manual probably would have helped in this case.

You can see that page here:
inductiveautomation.com/prod … m#runquery

Thanks.
The runScalarQuery works. The runquery with a ‘[0][0]’ option would also work in most cases, but it would not work if a timeout from the database occurs and nothing is returned or for some other reason nothing is returned.
Thanks

Correct. Runquery returns a dataSet. A Null dataSet does not have a ‘[0][0]’ value. RunScalarQuery is the correct function to use if you expect a single item to be returned.

[quote=“qurban”]Thanks.
The runScalarQuery works. The runquery with a ‘[0][0]’ option would also work in most cases, but it would not work if a timeout from the database occurs and nothing is returned or for some other reason nothing is returned.
Thanks[/quote]