Using Parameterized Views

From Lianjapedia
Jump to: navigation, search

Parameterized views are implemented using "Named parameters" in desktop/web/mobile Apps to query Virtual Tables which contain ?parameters and {macros}.

Default values for named parameters can be specified in the Virtual Table "properties" e.g. "mycvar=hello;mynvar=n:123" etc.

The setNamedParameter(name, value) method on the Section section is used to dynamically specify named parameters.

Using parameterized views for virtual tables results in high performance queries that are dynamically generated based on user selections in the UI.

Basic method usage

section.clearNamedParameters()
section.setNamedParameter("name", "value")
section.reOpenTable()

Value notation

When setting a named parameter you can denote the data type so that any ?name parameter markers are substituted with the correct data type e.g numerics or ‘string’ constants. e.g.

pname=string
pname=c:string
pname=n:number
section.clearNamedParameters()
section.setNamedParameter("c:name", "value")
section.setNamedParameter("n:num", "1000")
section.reOpenTable()

Note that {macros} are substituted in place with no surrounding quotes.

Example

//
// Assume we have a grid section which is bound to a VT called vcustomers
// and the vcustomers VT was created with
//
// create virtualtable vcustomers 
//     connstr "local" 
//     properties "pkwhere=where 1 eq 0"
//     as select * from customers {pkwhere}
//
mysection = Lianja.get("page1.section1")
mysection.setNamedParameter("pkwhere", " where customerid like 'A%'")
// The special named parameter defaultnamedparameters when set to "0" causes
// default named parameters in the VT properties to be ignored
mysection.setNamedParameter("defaultnamedparameters", "0")
mysection.reOpenTable()

Note that JavaScript code in a Web / Mobile app is exactly the same except you should terminate each code statement with a semi colon.