How to invoke a SQL statement via JS is common in the development of reports and data platforms. Take the report platform Finereport Development as an example, for example, after clicking on a button, determine the number of database bars, and then decide what to do next. So how does this work in the background?
Solution Ideas
Realize this function, first need to understand finereport built-in formula, SQL function, this Ken can everybody understand, do not introduce.
Call Finerepor's built-in formula: Fr.remoteevaluate ("concrete formula"), the return value is: The result of this specific formula.
For example: var a = Fr.remoteevaluate ("sum (1+2)");
At this point, the value of variable A is 3.
It is important to note that since you need to use double quotation marks (") multiple times in the SQL function, you should be aware of escaping with a backslash (\): var sql =" SQL (\ "frdemo\", \ "SELECT COUNT (*) fromsales_basic\", )"
Or to reduce the complexity of escaping, you can write the following format: Var sql= "SELECT COUNT (*) from Sales_basic"; Varres=fr.remoteevaluate (' SQL ' ("Frdemo", "' +sql+ '", 1, 1) ');
Add a button to the parameters panel and write the following SQL in the button's Click event:
var sql = "SQL (\" frdemo\ ", \" SELECT COUNT (*) fromsales_basic\ ",") "Alert (sql); var count = fr.remoteevaluate (SQL); alert (Count);
650) this.width=650; "Src=" http://img.blog.csdn.net/20161020150517450?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "Width=" 831 "height=" 418 "/>
Pagination Preview template, click the button, the effect is as follows:
650) this.width=650; "Src=" http://img.blog.csdn.net/20161020150641245?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "Width=" 834 "height=" 627 "/>
650) this.width=650; "Src=" http://img.blog.csdn.net/20161020150727652?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "Width=" 782 "height=" 588 "/>
How to invoke a segment of SQL statement via JS