How to call a certain SQL statement through JS. This requirement is very common in report and data platform development. Take the development of the reporting platform FineReport as an example. For example, after clicking a certain button, you can judge the number of database entries and then decide the next step. So how does this happen behind the scenes?
Solution ideas
To implement this function, you first need to understand the built-in formulas and SQL functions of Finereport. Everyone knows this, so I won’t introduce it.
Call FineRepor's built-in formula: FR.remoteEvaluate("specific formula"), the return value is: the result of this specific formula.
For example:
var a = FR.remoteEvaluate("sum(1+2)");
At this time, the value of variable a is 3.
It should be noted here that since double quotes (") need to be used multiple times in SQL functions, everyone should pay attention to using backslash () to escape:
var sql = "SQL("FRDemo" ,"Select count(*) from sales_basic",1,1)"
Or in order to reduce the complexity caused by escaping, it can be written in the following format: var sql="select count(*) from sales_basic"; varres=FR. remoteEvaluate('sql("FRDemo","'+sql+'",1,1)');
Add a button in the parameter panel, and write the following SQL in the button's click event:
var sql ="SQL(\"FRDemo\",\"Select count(*) fromsales_basic\",1,1)" alert(sql); var Count = FR.remoteEvaluate(sql); alert(Count);
Page preview Template, click the button, the effect is as follows: