Difference between revisions of "Using Parameters Views"

From Lianjapedia
Jump to: navigation, search
(Example)
(Example)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:Using Parameterized Views}}
 
{{DISPLAYTITLE:Using Parameterized Views}}
Lianja 4.1 introduced parameterized views.
 
 
 
Parameterized views are implemented using "Named parameters" in desktop/web/mobile Apps to query Virtual Tables which contain ?parameters and {macros}.  
 
Parameterized views are implemented using "Named parameters" in desktop/web/mobile Apps to query Virtual Tables which contain ?parameters and {macros}.  
  
Line 14: Line 12:
 
<code lang="recital">
 
<code lang="recital">
 
section.clearNamedParameters()
 
section.clearNamedParameters()
section.setNamedParameter(“name”, “value”)
+
section.setNamedParameter("name", "value")
 
section.reOpenTable()
 
section.reOpenTable()
 
</code>
 
</code>
Line 27: Line 25:
 
pname=n:number
 
pname=n:number
 
</pre>
 
</pre>
 +
 +
<code lang="recital">
 +
section.clearNamedParameters()
 +
section.setNamedParameter("c:name", "value")
 +
section.setNamedParameter("n:num", "1000")
 +
section.reOpenTable()
 +
</code>
  
 
Note that {macros} are substituted in place with no surrounding quotes.
 
Note that {macros} are substituted in place with no surrounding quotes.
Line 38: Line 43:
 
//
 
//
 
// create virtualtable vcustomers  
 
// create virtualtable vcustomers  
//    connstr “local”
+
//    connstr "local"
//    properties “pkwhere=1 eq 0“
+
//    properties "pkwhere=where 1 eq 0"
//    as select * from southwind!customers {pkwhere}
+
//    as select * from customers {pkwhere}
 
//
 
//
mysection = Lianja.get(“page1.section1”)
+
mysection = Lianja.get("page1.section1")
 
mysection.setNamedParameter("pkwhere", " where customerid like 'A%'")
 
mysection.setNamedParameter("pkwhere", " where customerid like 'A%'")
// The special named parameter defaultnamedparameters when set to “0” causes
+
// The special named parameter defaultnamedparameters when set to "0" causes
 
// default named parameters in the VT properties to be ignored
 
// default named parameters in the VT properties to be ignored
 
mysection.setNamedParameter("defaultnamedparameters", "0")
 
mysection.setNamedParameter("defaultnamedparameters", "0")
Line 50: Line 55:
 
</code>
 
</code>
  
Note that javascript code in a Web / Mobile app is exactly the same except you should terminate each code statement with a semi colon.
+
Note that JavaScript code in a Web / Mobile app is exactly the same except you should terminate each code statement with a semi colon.
  
 
[[Category:Third Party Database Connectivity]]
 
[[Category:Third Party Database Connectivity]]
 
[[Category:Virtual Tables]]
 
[[Category:Virtual Tables]]
 
[[Category:Databases]]
 
[[Category:Databases]]

Latest revision as of 07:50, 15 December 2020

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.