Parameters
It's all about being flexible ..
Dynamic queries are essential for flexible data retrieval. By using variable criteria instead of hard-coded values, you can filter records differently each time without modifying the query structure. This makes your queries more reusable and adaptable to changing requirements.
SQL
MDX
A parameter acts as a dynamic variable in your queries, allowing you to change values without modifying the query structure itself. Let's explore how they work and how to use them effectively.
Instead of using fixed values in your queries, you can use parameters that change based on user input or other conditions.
Parameters use the syntax: ${parameterName}
.
In CDA, parameters are defined using XML syntax under a Parameters element:
So now when defined in the CDA, the Query attribute needs to match the name in the parameter:
Prepared statements in SQL are a security and performance feature where query parameters are replaced by placeholders. When the JDBC driver supports it, these queries are precompiled in the database during preparation; otherwise, precompilation happens at execution time.
The key benefits are twofold:
First, the database can reuse the access plan for similar queries, making execution significantly faster than regular statement objects.
Second, prepared statements automatically protect against SQL injection attacks by properly escaping and handling input parameters.
Defining Multiple Parameters in a Query
You can define several parameters within a single query using the Parameters
tag. Each parameter needs its own Parameter
element with three key attributes:
• Name - Must match the parameter reference in your query
• Default Value - Used when no specific value is provided
• Type - Determines what kind of data the parameter accepts
Available Parameter Types:
Single Value Types:
• String
: Text values
• Integer
: Whole numbers only (e.g., 10, 365)
• Numeric
: Numbers with decimals (e.g., 15.39)
• Date
: Date values
Array Types (for IN conditions):
• StringArray
: Multiple text values
• IntegerArray
: Multiple whole numbers
• NumericArray
: Multiple decimal numbers
• DateArray
: Multiple date values
Last updated
Was this helpful?