How to check a value of some text?

i have a code linne which is :
call system.db.createSProcCall("Supervision_SelectCadencesInjection_100",event.source.parent.BDD_Statistique
I wanna know two things please.
First where can I find System.DB.CreatSProcCall ? I looked in project browser and I didn't find it.
the seconde thing : how can I know the value of event.source.parent.BDD_Statistique
thanks for ur help

Any functions that start with system are provided by... the system :smile:
They should have some documentation attached to them if you autocomplete, e.g. with Ctrl + Space, and if you're on a reasonably new version of Ignition 8.1 you should also be able to simply hover over the call and get a description of the function and its parameters.

If you want the absolute best resource, though, then I would highly recommend bookmarking this page in our online manual: System Functions - Ignition User Manual 8.1 - Ignition Documentation

You would log it or print it. I'm going to assume you're using Vision, and I'm also going to assume that the actual script looks like this:

call = system.db.createSProcCall("Supervision_SelectCadencesInjection_100", event.source.parent.BDD_Statistique)

So to check the value of the parameter, just bind it to a separate variable and use the print statement (built in to Python 2.7) to log it. In your client or designer, you can then check the Diagnostics -> Console tab from the menu bar. The reworked script should look something like this:

db = event.source.parent.BDD_Statistique
print db
call = system.db.createSProcCall("Supervision_SelectCadencesInjection_100", db)
2 Likes

If you want to find the event.source.parent.BDD_Statistique custom property in the designer, you will need to click on the container of that component. The event.source part of that code means the source of the event, or perhaps better stated, the component the event originated from. The parent part of that means the container the component is nested in. Finally, the BDD_Statistique part of that is the name of the property that lives on the parent container.

To see it, you will need to open the property editor pane:

The custom properties should be toward the bottom.

From your other post, it looks like you are working with version 7.9, so here is a link to the documentation on version 7.9 component properties:
docs.inductiveautomation.com/display/DOC79/Component+Properties

2 Likes

hello,
this is what I got when I deployed all propoerty editor !

2024-01-25 10_19_07-VM_ITM_CASTETS - VMware Remote Console

when I double click on running I see this :

What I understand is that the BDD_Statistique can be one of the two values ITM_Castets or ITM_Stats . The quesion is there an option to ignore the seconde Database ? without touching the code ?

image
The timer is the scripted component itself. The custom property is on the parent container it is nested in.

I'm not sure. Both of the code examples @bkarabinchak.psi and myself provided in the other post would essentially ignore the faulted database until it is fixed and will start working as it did before once it's repaired. Messing with the bindings could prevent the normal application behavior from resuming when and if the database connection is ever restored.

I can't tell what this timer actually does, so I don't know how important this function is to your customer's operation. Therefore, I can't advise you to permanently disable the database read.

I suspect the correct solution is to leave everything as it is, and fix the database.

3 Likes

sorry but something is wrong in this code
and I dont see where Dbstatut get the value Valid !!!!

The problem is the indention:
image

This happens sometimes when pasting code. Notice how in my code example the if is aligned with dbStatus?

In Python, the indentions have to be correct.

Here is the documentation on system.db.getConnectionInfo:
docs.inductiveautomation.com/display/DOC79/system.db.getConnectionInfo

It returns a dataset that has a column called status. If the database is working, the status will be 'Valid'. I also added a check to make sure data is returned in case one of the variable names for some reason doesn't match any of the database names.

3 Likes

thank u ! But I still get the pop up :smiling_face_with_tear: :smiling_face_with_tear: :smiling_face_with_tear:

That's surprising. It's the error message the same?

1 Like

yes it is the same

if event.propertyName  == "value":
# Get the connection info for the given database name
	dbConnectionInfo = system.db.getConnectionInfo(event.source.parent.BDD_Statistique)

	# If the database name returns any information, get the status value from the status column, else flag the result as invalid
	dbStatus = dbConnectionInfo.getValueAt(0, 'Status') if dbConnectionInfo.rowCount else 'inValid'

	# If the database connection status is valid (not faulted) continue with the code, else abort and quietly log the problem
	if dbStatus == 'Valid':
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectCadencesInjection_100",event.source.parent.BDD_Statistique)
		# Ajout du paramètre
		#call.registerInParam('System', system.db.INTEGER, 1)
		
		# Excecution de la procédure
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.LigneDataset = result
		
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectTauxSaturationPlateaux_100",event.source.parent.BDD_Statistique)
		# Excecution de la procédure	  
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.SaturationDataset = result
		
		
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectTopCinqSaturation_100",event.source.parent.BDD_Statistique)
		# Excecution de la procédure	  
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.OperateurDataset = result
		
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectRebuts_100",event.source.parent.BDD_Statistique)
		# Excecution de la procédure	  
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.RebutDataset = result
  ```

type or paste code here

I'm out of ideas then. Did bkarabinchak.psi's suggestion work?

1 Like

I'm gonna try it now but I donc understand his solution ! can u explain it to me please?
talking about this line
2024-01-25 11_39_21-Pop up always appears - Ignition - Inductive Automation Forum et 23 pages de plu

tried it, but still doesn't work

The error you were getting in your other post if you note you can see it says java.lang.Exception - this is a subclass of java.lang.Throwable so when you do a try/except if offers you the programmer a chance to do something with that error.

This part

except java.lang.Throwable, e:
    print e

would only print the error to your console. If you don't handle the error like this, then Vision gives you that popup you were seeing.

I am surprised it did not work. Did you start with a try? It will not work unless both try and except are present. You try do your code and then if there is an exception(error) - do this instead. Post your full code, I am surprised it would not work. Please use the formatting instead of a picture.

1 Like

Hi this is what I wrote :

import java.lang.Throwable # SQL errors come through as java
if event.propertyName  == "value":
    try:
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectCadencesInjection_100",event.source.parent.BDD_Statistique)
		# Ajout du paramètre
		#call.registerInParam('System', system.db.INTEGER, 1)
			
		# Excecution de la procédure
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.LigneDataset = result
			
		# Appel de la procédure stockée
		call = system.db.createSProcCall("Supervision_SelectTauxSaturationPlateaux_100",event.source.parent.BDD_Statistique)
		# Excecution de la procédure	  
		system.db.execSProcCall(call)
		# Copie des résultats dans un dataset
		result = call.getResultSet()
		if result.rowCount > 0:
			event.source.parent.SaturationDataset = result`Preformatted text`
    except java.lang.Throwable, e:
        # Now the popup won't appear, you probably want to log this somehwere though
        print e

exacly as U wrote it in the other post

And what happens? You are still getting the pop up error after you save and publish this change to the client?

If so can you click on the "details" part of the error popup copy and paste the stack trace here

1 Like

It just occurred to me what could be happening. When I first started scripting in Ignition, I would open the script console in windows, and it would open narrow, so the "Apply" button wasn't visible. Consequently, I would forget about pressing it, and my code changes would have no effect.

Both of our scripts should have changed the outcome, so I'm wondering if this the case, and the apply button has simply not been pressed to apply the code change.

Try widening your scripting window to see if the apply button becomes visible. The code changes won't take effect unless that button is pressed.

Traceback (most recent call last):
File "event:propertyChange", line 8, in

java.lang.Exception: java.lang.Exception: Error executing system.db.execSProcCall()

caused by Exception: Error executing system.db.execSProcCall()
caused by GatewayException: The database connection 'ITM_STATS' is disabled.
caused by DisabledDatabaseConnectionException: The database connection 'ITM_STATS' is disabled.

Ignition v7.9.3 (b2017060210)
Java: Oracle Corporation 1.8.0_191

The line number is even the same, so it really does seem like the changes haven't been applied. Please confirm that you've ordered the apply button on the bottom right side of the script window.

2 Likes