Testing MasonSQL Queries
On this page:
Running test_callRemote.html
This test file
/opt/masonsql/htdocs/test/test_callRemote.html
is small enough to analyze it quickly. In the header of the trasmitted page we can see included the
dojo.js
and bunch of Dojo style sheets. Further we see included the core .js files from
htdocs/lib/
directory.
After the includes there is the
require function which is also seen commonly in all of the MasonSQL htmls. We can find it in the
htdocs/autohandler
file which is the topmost parent of the
test_callRemote.html
.
We see the
require
callback function uses
window.masonSql
object which is found in the
htdocs/lib/library.js
file. It is inherited from the
dojo/Evented class.
We see that the
window.masonSql.ready()
function fires a
ready
event:
this.emit("ready", obj);
Above the
require
in the
htdocs/autohandler
file we can also see the Perl code that outputs the header with all includes.
After resolving the headings we continue with the button code (.../test_callRemote.htm contents):
<h1>Test callRemote</H1>
<button onclick="Call();">call /test_callRemote.mql - test_callRemote</button>
<script>
function Call(){
var db = new DataBinding('Recordset', 'test_callRemote', 1);
db.callRemote('test_callRemote', {par1: 'parametro uno', par2: 'parametro due'}, 'html', {title: 'Test call remote'});
}
</script>
Data Binding
Here we see the
DataBinding()
object under test which is found in
htdocs/lib/databinding.js
file. We see that the
DataBinding_callRemote()
method at first saves the input parameters into the
JavaScript Object:
var call_params = {'caller':'.callRemote',
'name':this.prefix, 'orderby': this.orderby, 'where2': this.where, remote_func_params:params,
'father_id': this.father_id, 'father_id_update':this.father_id_update, remote_func_name: remote_func
Then it defines callback on the server which uses the
masonSql_Dialog.openUrl()
method to run the
.mql
file with the JSON formatted
call_params
. The masonSql_Dialog.openUrl() method finally shows the query result in the browser dialog box:
masonSql_Dialog.openUrl('<%$DataBaseUrl%>/'+db.from+'.mql', url_params, X, Y, title);
Running test_callRemote.mql
This last piece of code which is executed on the server does basically the same thing as writing the following text in the browser:
https://www.mysite.com/data/public/test_callRemote.mql?method=call_remote&json_params=%7B%22caller%22%3A%22.callRemote%22%2C%22name%22%3A%22Recordset%22%2C%22orderby%22%3A%22%22%2C%22where2%22%3A%22%22%2C%22remote_func_params%22%3A%7B%22par1%22%3A%22parametro%20uno%22%2C%22par2%22%3A%22parametro%20due%22%7D%2C%22father_id%22%3Anull%2C%22father_id_update%22%3Anull%2C%22%22test_callRemote%22%7D&Ver=8199aabd5471c4e5e71ec0c6cf276d3e&U=1454509609235681
In order to find out where the request's parameters are parsed we must follow the
inherit flag,
the parents of the
test_callRemote.mql
are:
-
htdocs/data/public/autohandler
-
htdocs/data/autohandler
-
htdocs/data/global_autohandler
- htdocs/lib/dbms_library.comp
-
htdocs/init.comp
-
htdocs/library.comp
(topmost parent)
We see that the HTML GET or POST parameters are normalized and stored in the global variable
%{$Session{ARGS}}
from
htdocs/init.comp
When the request gets interpreted there is an
if
statement at the end of the
htdocs/lib/dbms_library.comp which checks how component was called. If the component was called without a method it runs the
call_method()
with the normalized parameters.
$m->base_comp->call_method($method, %{$Session{ARGS}});
Running .mql Files
Its possible to use the mechanism, described in previous chapter, for making query requests from a browser. For example:
https://www.mysite.com/data/public/funzioni.mql?method=xml&rows=8
Parameter
method
accepts file format, it supports these formats:
Parameter Name |
Description |
select |
Request displays query results transformed into a Select object. |
array |
Displays query results transformed into a DataBinding object. |
txt |
Displays query results is in the txt format. |
xml |
Displays query results is in the xml format. |
html |
Displays query results is in the html format. |
xls |
Returns .mql file which contains query results in the xls format. |
pdf |
Generates a pdf report and sends it to the printer (requires the appropriate .rep file to generate a report). |
call_remote |
Launch a remote method on the server which must be predefined as the CALL_REMOTE_<function_name> |
Running frame.html
For example the MasonSQL Demo website user can look up the descriptions of the MasonSQL tables under the menu
Authorizations->Functions and authorizations. The same information can be displayed by entering following address:
https://www.mysite.com/frame.html?from=funzioni