Skip to main content
Version: 7.9

system.db.runNamedQuery

New in 7.9.4

This function is used in Python Scripting.

Description

Runs a named query and returns the results. Note that the number of parameters in the function is determined by scope. Both versions of the function are listed below.

Client Permission Restrictions

This scripting function has no Client Permission restrictions.

Syntax (Client Scope)

system.db.runNamedQuery(path, parameters)

Parameters

TypeParameterDescription
StringpathThe path to the named query to run. Note that this is the full path to the query, including any folders.
PyDictionaryparametersA Python dictionary of parameters for the named query to use.

Returns

Object - The results of the query. The exact object returned depends on the Query Type property of the Named Query: typically either a dataset when set to Query, an integer representing the number of rows affected when set to Update Query, or an object matching the datatype of the value returned by a Scalar Query.

Scope

Client, Designer

Syntax (Gateway Scope)

system.db.runNamedQuery(project, path, parameters)

Parameters

TypeParameterDescription
StringprojectThe project name the query exists in.
StringpathThe path to the named query to run. Note that this is the full path to the query, including any folders.
PyDictionaryparametersA Python dictionary of parameters for the named query to use.

Returns

Object - The results of the query. The exact object returned depends on the Query Type property of the Named Query: typically either a dataset when set to Query, an integer representing the number of rows affected when set to Update Query, or an object matching the datatype of the value returned by a Scalar Query.

Scope

Gateway

Code Examples

Example #1 - Without Parameters
# This example will run a Named Query without any parameters in the Project scope.
# The second argument in the function is NOT optional, so named queries that do not require a parameter must still pass an empty dictionary as an argument.

# Request the Named Query with an empty dictionary as the second parameter.
system.db.runNamedQuery("folderName/myNamedQuery", {})
Example #2 - Gateway Scope
# This example will run a Named Query without any parameters in the Gateway scope.
# The last argument in the function is NOT optional, so named queries that do not require a parameter must still pass an empty dictionary as an argument.

# Request the Named Query to execute.
system.db.runNamedQuery("ProjectName", "folderName/myNamedQuery", {})
Example #3 - With Parameters
# This example will run a Named Query while passing some parameters in the Project scope.
# The Named Query is assumed to have two parameters already defined on the Named Query:
# param1 : A string
# param2 : An integer

# Create a python dictionary of parameters to pass
parameters = {"param1":"my string", "param2":10}

# Run the Named Query
system.db.runNamedQuery("myUpdateQuery", parameters)