Passing HTML into the page

Commands

dbr.html - Pass HTML directly into the report. Use this for safe HTML (your own HTML)
dbr.html.ext - Pass HTML directly into the report. HTML content will be filtered for unsafe code. Use this for usafe HTML.
dbr.purehtml - Same as dbr.html, kept for compatibility
dbr.html: - Include HTML into a string. Use this for safe HTML (your own HTML)
dbr.html.ext: - Include HTML into a string. HTML content will be filtered for unsafe code. Use this for unsafe HTML
dbr.purehtml: - Same as dbr.html:, kept for compatibility
dbr.javascript - Include Javascript code in the report
dbr.css - Include CSS definitions in the report
dbr.head - Include tags into HTML head part
dbr.file - Include a HTML file into the report
dbr.redirect - Do a server side 302 redirect to another page. Uses the same syntax as dbr.report
dbr.http.get - Make a HTTP GET requests and optionally return the result
dbr.http.delete - Make a HTTP DELETE requests and optionally return the result
dbr.http.post - Make a HTTP POST requests and return the result
dbr.http.put - Make a HTTP PUT requests and return the result
dbr.http.save - Call a procedure to handle a HTTP POST/GET result
dbr.http.option - Pass options to dbr.http.post
dbr.http.header - Save HTTP headers
dbr.http.debug - Debug HTTP PUT/POST call

Syntax

select 'dbr.html', 'HTML statement'
select 'dbr.html.ext', 'HTML statement'
select 'dbr.purehtml', 'HTML statement'
select 'dbr.html:HTML statement'
select 'dbr.html.ext:HTML statement'
select 'dbr.purehtml:HTML statement'
select 'dbr.javascript', 'javascript code' [, 'onload']
select 'dbr.css', 'css'
select 'dbr.head', html_tags
select 'dbr.file', path_to_file
select 'dbr.redirect', URL | report [, param1,[ ,param2]]]
select 'dbr.http.get', URL [,params..[, 'silent']]
select 'dbr.http.delete', URL [,params..[, 'silent']]
select 'dbr.http.post', URL [,params..[, 'silent']]
select 'dbr.http.put', URL [,params..[, 'silent']]
select 'dbr.http.save', 'procedure_name', [,params..]
select 'dbr.http.option', option, value1 [, value2]
select 'dbr.http.header', 'procedure_name', id
select 'dbr.http.debug', 1

Explanation

The 'http.option' can be:

  • 'curl', cURL_option, value - Pass cURL options to dbr.http.post
  • 'accept', comma_separated_http_code - List codes that are accepted HTTP values in addition to default 200,400,409,422

By default, if you include HTML tags in the report, myDBR will escape those tags. With these commands, myDBR lets the browser render the selected HTML code.

With the dbr.html command you can allow the client browser to render the HTML. The dbr.html command makes the whole result set to be passed directly to the browser, as with the dbr.html:-syntax, this allows mixing HTML within the query. The dbr.html: allows HTML formatting inside the result table's cell.

You can also pass Javascript code with 'dbr.javascript'. The command is a short version of 'dbr.html' and adds script tags around the parameter. The optional 'onload'-parameter makes the script run after the DOM tree has been loaded. Adding your own CSS can be done with 'dbr.css', which works similarly.

Example - dbr.html

Putting a logo in the left top corner of the report. Embed Google Maps map and YouTube video side by side in a report.

select 'dbr.title', ''; /* We do not need the title */

/* Putting up the logo. We'll use a predefined left div */
select 'dbr.html', '<div class="left"><img src="https://mydbr.com/images/apppic.png"></div>'; 

/* Use this as title */
select 'dbr.hideheader';
select 'BMW F1 vs, BMW M5';

/* Put map and video side by side. 1st column */
select 'dbr.html', '<table align="center"><tr><td>'; 

select 'dbr.hideheader';
select 'Google map: Rockingham Race Track';

/* We have the Google Map URL here */
select 'dbr.html', RockinghamURL
from mydb.Racetracks;

/* 2nd column */
select 'dbr.html', '</td><td>'; 

select 'dbr.hideheader';
select 'Video: Fifth Gear';

/* We have the YouTube video URL here */
select 'dbr.html', F1vsM5URL
from mydb.Videos;

/* Close the table */
select 'dbr.html', '</td></tr></table>';

The report will position the logo on the top left. Map and video will appear side-by-side:

Example - 'dbr.html:'

The report will output a list of parts and their picture.

select 'Part 1' as 'Part name', 
       'WDC-2345-1' as 'Code', 
       'dbr.html:<img src="http://www.mysite.com/parts/WDC-2345-1.jpg">' as 'Preview'
union
select 'Part 2', 
       'WDC-2345-2', 
       'dbr.html:<img src="http://www.mysite.com/parts/WDC-2345-2.jpg">'
union
select 'Part 3', 
       'WDC-2345-3', 
       'dbr.html:<img src="http://www.mysite.com/parts/WDC-2345-3.jpg">';

The report will output a normal myDBR report list. myDBR will just put the indicated picture in the third column's cell.

Example - 'dbr.head'

You can include your own tags into HTML HEAD section with dbr.head

select 'dbr.head', '<meta property="og:url" content="http://mydomain.com/index.htm">';
select 'dbr.head', '<meta name="twitter:card" content="summary_large_image">';
select 'dbr.head', '<meta name="twitter:card" content="summary_small_image">';

'dbr.redirect' with the OEM license

The OEM license allows for you to use dbr.redirect to redirect page to another page with server side 302. The syntax is the same as in dbr.report. The command takes a single line as a result set. The redirect is useful when handling forms with Post/Redirect/Get pattern where the page handling the POST, redirects the page to another page after it has handled the POST.

select 'dbr.redirect', 'sp_DBR_landing_page', 'inInt=par', 'append=&hdr=0'

select 12345 as 'par'; 

'dbr.head' head with the OEM license

The OEM license allows for you to set dynamic title element

select 'dbr.head', concat('<title'>', thetitle, '</title'>');

Example - 'dbr.head'

You can include your own tags into HTML HEAD section with dbr.head

select 'dbr.head', '<meta property="og:url" content="http://mydomain.com/index.htm">';
select 'dbr.head', '<meta name="twitter:card" content="summary_large_image">';
select 'dbr.head', '<meta name="twitter:card" content="summary_small_image">';

Example - 'dbr.http.get' and 'dbr.http.post'

Commands allow for you to make HTTP POST and HTTP GET calls and optionally returns results. The result can be shown in the report directly, passed into a template, or pass into a linked report as a parameter.

Parameters named user and pass will be used as username and password for HTTP authentication.

A HTTP POST call. The call shows the data returning from the call.

select 'dbr.http.post', 'https://financial_system/entry.php?action=cost',  'Purchase' as 'title', 200 as 'amount';

A silent HTTP POST call. The call is made and no data is shown. After silent call one can do a redirect. Can be used for example on form handling.

select 'dbr.http.post', 'https://financial_system/entry.php?action=cost',  'Purchase' as 'title', 200 as 'amount', 'silent';
select 'dbr.redirect', 'sp_DBR_entry_finished';

A HTTP GET call with return data stored in the record variable. Can be shown/handled in the template code.

select 'dbr.title', '';
select 'dbr.record', 'begin', 'get';
select 'dbr.http.post', 'https://financial_system/entry.php',  1234 as 'businessline';

select 'dbr.record', 'end';
select 'dbr.template', '#get';

select 1 as 'dummy';

Passing cURL options to the HTTP POST with dbr.http.option:

select 'dbr.http.option', 'curl', 'CURLOPT_HTTPHEADER', 'Accept: application/json';
select 'dbr.http.option', 'curl', 'CURLOPT_HTTPHEADER', 'Authorization: Bearer {token}';
select 'dbr.http.option', 'curl', 'CURLOPT_HTTPHEADER', 'Content-Type: application/json';

select 'dbr.http.post', 'https://financial_system/entry.php',    
  'sample@email.com' as 'email',
  123 as 'id';

A HTTP POST/GET result is passed in as a parameter to a linked report

When the dbr.http.post or dbr.http.post is preceeded with dbr.report, the result of the HTTP call (usually a JSON), is passed to the report parameter marked as special columnReference get_data, post_data or put_data. All parameters used in the dbr.report command (see id and date), will removed from the GET/POST. They are used for the dbr.report only. If the result of the HTTP call exceeds the one that the server can handle (usually 8K, depends on your server setup), you can use dbr.http.save to save the HTTP call result to the database prior calling the linked report.

When a linked report is used with dbr.http.post, dbr.http.put or dbr.http.get, myDBR will do a redirect to that report. Make sure you do not have any output before that so that you will not get 'Cannot modify header information' error.

  select 'dbr.report', 'sp_DBR_post_json', 'inID=id', 'in_date=date','inJSON=post_data';
 select 'dbr.http.post', 'https://financial_system/entry.php',  1234 as 'businessline', 'abc' as 'sdata', current_date() as 'date', v_ID as 'id';

myDBR will first do a HTTP POST with data businessline=1234&sdata=abc and get the result. It then calls the sp_DBR_post_json with id, date and the JSON data from the POST.

A HTTP POST/GET result is saved prior to calling the linked report

To handle larget results from the HTTP POST/GET call, one can save the result to the DB. The linked report is called after the save is done. The saving procedure is not a myDBR report, but a helper one. You can pass parameters to it. The result from the HTTP POST/GET call is added as the last parameter.

The saving procedure can return one row (usually an ID for the saved data). In that case the returned value will be added to the linked report. In the example the saving procedure returns the last inserted id as id. The id is passed to sp_DBR_post_json as a parameter.

The example also saves the HTTP headers for the POST call. Note that the headers saving is done after the main report is run, so the headers are available in the report defined by dbr.report, not in the main report.

CREATE PROCEDURE `sp_save_json`(inLogin varchar(30), in_whatever varchar(5), inJSON JSON)
begin

insert into json_data (username, additional_data, json_data)
values (inLogin, in_whatever, inJSON);

select last_insert_id() as 'id';
end
create procedure sp_post_header ( 
in_id int, 
in_line int,
in_header varchar(255)
)
begin

if (in_line=1) then
  delete 
  from http_post_headers 
  where id=in_id;
end if;

insert into http_post_headers (id, line, header)
values (in_id, in_line, in_header);

end
 select 'dbr.http.save', 'sp_save_json', inLogin, 'whatever';
 select 'dbr.http.header', 'sp_post_header ', 1;
 select 'dbr.report', 'sp_DBR_post_json', 'inID=id', 'in_date=date';
 select 'dbr.http.post', 'https://financial_system/entry.php',  1234 as 'businessline', 'abc' as 'sdata', current_date() as 'date';

myDBR will first do a HTTP POST with data businessline=1234&sdata=abc and get the result. The headers are passed to the sp_post_header. It then calls the sp_save_json with inLogin, 'whatever' and the JSON data from the POST. Finally, the linked report is called. As the sp_save_json returned a column with same name as the parameter reference for the linked report (inID=id), the returned value is passed to the linked report.