Skip to content

incendium.db.get_return_value

César Román edited this page Mar 24, 2022 · 14 revisions

Description

Get the Return Value from the Stored Procedure.

Syntax

incendium.db.get_return_value(stored_procedure, return_type_code, [database], [transaction], [params])

Args:

  • stored_procedure (str): The name of the stored procedure to execute.
  • return_type_code (int): The Type Code of the Return Value.
  • database (str): The name of the database connection to execute against. If omitted or "", the project's default database connection will be used. Optional.
  • transaction (str): A transaction identifier. If omitted, the call will be executed in its own transaction. Optional.
  • params (list[InParam]): A Dictionary containing all INPUT parameters. Optional.

Returns:

  • int: The return value.

Recommendations

For Microsoft SQL Server, the return type is INT. See: Return Types, and Returning status codes.

Code Examples

from __future__ import print_function

from incendium import db
from incendium.db import InParam
from java.lang import Exception as JException


# Stored procedure:
# USE AdventureWorks2012;
# GO
# CREATE PROCEDURE dbo.checkstate @param varchar(11)
# AS
# IF (SELECT StateProvince FROM Person.vAdditionalContactInfo WHERE ContactID = @param) = 'WA'
#     RETURN 1
# ELSE
#    RETURN 2;
# GO
def check_state():
    try:
        # Initialize INPUT parameters.
        params = [InParam("param", system.db.VARCHAR, "WA")]
        return db.get_return_value(
            "dbo.checkstate", return_type_code=system.db.INTEGER, params=params
        )
    except JException as e:  # system.db functions throw java.lang.Exception
        # TODO: Handle exception.
        print(repr(e))
Clone this wiki locally