QueryParam

Used to verify or strongly type a query parameter to a valid SQL Type.

Component Signature

<bx:QueryParam value=[any]
sqltype=[string]
maxLength=[integer]
scale=[integer]
null=[boolean]
list=[boolean]
separator=[string] />

Attributes

Atrribute
Type
Required
Description
Default

value

any

false

The value of the parameter

sqltype

string

false

The SQL type of the parameter. One of: bigint, bit, blob, boolean, char, clob, date, decimal, double, float, int, integer, idstamp, longvarchar, money, numeric, real, smallint, string, time, timestamp, tinyint, varbinary, or varchar.

maxLength

integer

false

The maximum length of the parameter

scale

integer

false

The scale of the parameter, used only on double and decimal types. Defaults to null

null

boolean

false

Whether the parameter can be null or not.

list

boolean

false

Whether the parameter is a list or not

separator

string

false

The separator to use for the parameter. Defaults to a comma.

Examples

Use bx:queryParam to protect your application from SQL-injection attacks:

It is highly recommended to set the sqltype of the incoming data:

Using Lists in QueryParam

For SQL IN clauses with comma-separated param values, use list=true:

Assuming url.mediaTypes is equal to book,magazine,newspaper, this will generate the following SQL statement:

Basic example

Shows how to use a bx:queryparam tag within bx:query.

Using a list on an IN statement

Assumes url.idList is a comma separated list of integers, eg: 1,2,3

Using an expressions to controll null values

Shows a basic example of using an expression to control whether null is passed to the queryparam

script equivalent of bx:queryparam

Script syntax using queryExecute and struct notation

Run Example

Result: Man walks on Moon

script equivalent of bx:queryparam

Script syntax using queryExecute and struct notation for multiple parameters

Run Example

Result: Man walks on Moon

script equivalent of bx:queryparam

script syntax using queryExecute and full array notation

Run Example

Result: Man walks on Moon

script equivalent of bx:queryparam

script syntax using queryExecute and array shorthand

Run Example

Result: Man walks on Moon

Last updated

Was this helpful?