The manual states that system.db.runNamedQuery() returns “an integer representing the number of rows affected when set to Update Query.”
My question is:
If an update/insert fails due to a database error (for example, a duplicate key constraint), does the function return 0, or does it always throw an exception?
From my testing, it seems to throw an error instead of returning 0.
I'm deciding how to structure my script and considering two approaches
Option A (Check for return value 0)
Params = {"database":"DB_NAME","param1":"value1","param2":"value2"}
Insert_result = system.db.runNamedQuery("folderName/myNamedQuery",params)
If Insert_result == 0:
Alert.popup("Failure Message")
Option B (Catch the exception)
Params = {"database":"DB_NAME","param1":"value1","param2":"value2"}
Try:
Insert_result = system.db.runNamedQuery("folderName/myNamedQuery",params)
exception:
Alert.popup("Failure Message")
I'm trying to figure out in what scenarios function would actually return 0 for an update/insert query.
Am I missing something?
Any suggestions or improvements are welcome