Home >php教程 >PHP开发 >How to call a certain SQL statement using JS

How to call a certain SQL statement using JS

高洛峰
高洛峰Original
2016-12-09 14:47:351437browse

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);

How to call a certain SQL statement using JS

Page preview Template, click the button, the effect is as follows:

How to call a certain SQL statement using JS

How to call a certain SQL statement using JS

How to call a certain SQL statement using JS


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn