Confirmation box

Hi.
The following works fine by its self:

[code]response = fpmi.db.runScalarQuery(“select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Close/Open’, ‘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]

I cant seem to make the fpmi.gui.confirm work with it. I have tried different variations. But anyway how do I make the following to work:

[code]if fpmi.gui.confirm(“Are you sure you want to Close Switch 1 for ‘%s’?”, “Please Confirm” %event.source.parent.parent.Device):

response = fpmi.db.runScalarQuery(“select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Close/Open’, ‘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]

I get the following error:

Unable to register action mouseClicked Parse Error: Traceback (innermost last): (no code object) at line 0 SyntaxError: ('invalid syntax', ('<string>', 7, 1, 'response = fpmi.db.runScalarQuery("select * from elan_pgres_elanhost_dig_out_ctl(\'localhost\', %d, \'%s\', \'Close/Open\', \'digital-out\', \'Direct Operate\', \'None\', \'Close\', \'500\', \'500\')" %(event.source.parent.parent.rns_port,event.source.parent.parent.Device));'))

I’d guess the problem is probably that your indenting isn’t correct under the If statement. Try throwing a TAB in front of your “response = …”

One small pointer for the forum: if you enclose your scripting examples in the CODE tag (using the “Code”) button next to quote, bold, italic, etc. it will make things more readable and more importantly preserve your character spacing.

Hope that helps,

No Indenting is not it. The statements work without the if statement, When I try to save it after adding the “if” statement, that is when I get the error. I’ll post them again with the code tag.

The following works:

[code]response = fpmi.db.runScalarQuery(“select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Close/Open’, ‘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 following when trying to save throws an error:

[code]if fpmi.gui.confirm(“Are you sure you want to Close Switch 1 for ‘%s’?”, “Please Confirm” %event.source.parent.parent.Device):

response = fpmi.db.runScalarQuery(“select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Close/Open’, ‘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 following is the error:

Unable to register action mouseClicked Parse Error: Traceback (innermost last): (no code object) at line 0 SyntaxError: ('invalid syntax', ('<string>', 7, 1, 'response\t=\tfpmi.db.runScalarQuery("select * from elan_pgres_elanhost_dig_out_ctl(\'localhost\', %d, \'%s\', \'Close/Open\', \'digital-out\', \'Direct Operate\', \'None\', \'Close\', \'500\', \'500\')" %(event.source.parent.parent.rns_port,event.source.parent.parent.Device));'))

Qurban,

The problem is that you’ve entered invalid Python syntax. When you want to use an if for flow control, you need to define a new block. You do this with a colon (:slight_smile: at the end of your if (which you did), and by indenting the rest of the block (you didn’t do this). You might want to take a look at a python tutorial, or just have a look at the examples with a more critical eye. Indentation is crucial in Python.

You also had your % operator for the string in the Confirm in the wrong place.

More thoughts before I get to the script:

don’t be afraid to use variables - they could clean this code up quite a bit (see below)

You’re ending your lines in semicolons. Don’t do that - Python doesn’t require it.

Don’t use SELECT * with a runScalarQuery. This is dangerous. You are selecting all rows and all columns from a table, but only looking at the first row and first column. The danger is, with SELECT *, you don’t know what order the columns will be returned in. Do a SELECT myColumn FROM … instead.

Ok, here is a script (cleaned up a bit too) that would work:

[code]device = event.source.parent.parent.Device
rns_port = event.source.parent.parent.rns_port
if fpmi.gui.confirm(“Are you sure you want to Close Switch 1 for ‘%s’?” % device, “Please Confirm”):

query = “select * from elan_pgres_elanhost_dig_out_ctl(‘localhost’, %d, ‘%s’, ‘Close/Open’, ‘digital-out’, ‘Direct Operate’, ‘None’, ‘Close’, ‘500’, ‘500’)” % (rns_port, device)

response = fpmi.db.runScalarQuery(query)

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

One last thought - I hope you don’t think this script is going to do anything (like, say, close a switch). You’re just selecting a point, not modifying anything, but I assume you’re not done…

Hope this helps,

On second thought - it appears you’re calling a stored procedure. In this case, it probably does do something, and your Select * might not matter. Sorry about that.

Thanks Carl.
The indenting, “Tab” before the two lines after the ‘IF’ statement was the culprit. Yes using variables like you suggested makes a lot of sense. Yes it is a stored procedure which should return only one row with one column.
It does not seem like this code would handle a database timeout(I stumbled upon the error once) Any suggestions?
Thanks for your prompt help guys. Actually providing support to integrators(Specially those under the gun) is a strong asset of yours.

What do you mean exactly? What kind of handling are you looking for? It will currently pop up a message box, which you can catch with a try: except: clause if you wish

No problem, thats what we're here for! Also, pretty much everyone who works here has had some sort of experience as an integrator in the field, so we know what it feels like to be under the gun.