2 year anniversary

Using TQuery and TQueryRemote


PageHome.ts

//Playing with query in remote query
import V = require(“VCL/VCL”);
 
export class PageHome extends V.TPage {
  constructor() {
    super();
    //this is a “bit” unasafe way to run a query
    var qur = new V.TQuery(this);
    qur.SQL = “Select * from orders”
    qur.open();
 
    //this is a better approach, the query now is located on the server, so injection is impossible
    var secureQur = new V.TQueryRemote(this);
    secureQur.QueryID = “ord100”;
    secureQur.open();
 
    qur.onAfterOpen = () => {
      //move to the first record
      qur.first();
 
      //applying filter
      qur.applyFilter(() => {
        if (qur.getFieldValue(‘SalesAmount’) > 1) return false;
        else return true;
      });
 
      //Dataset iterator
      var totalAmount = 0;
      qur.forEach(() => {
        //get the value from the current row
        totalAmount += qur.getFieldValue(‘SalesAmount’);
      });
    }
  }
}
 
 

Config\queries.json

[
  {
    "ID": "ord100",
    "SQL": "Select * from orders",
    "DB": "DB",
     "ROLE" : ""
  }
]

This entry was posted in Code Snippet and tagged , . Bookmark the permalink.