You can automate report creation process using command line. Such possibility can be very useful if you need to create a report using the same report file. For this, you will need to create a report template to use it afterwards in the command line. Note that some parameters can be specified directly in the command line. In this case values of these parameters specified in your template file will be overridden.
The walkthrough described further in this topic will show you how to use command line in order to automate the following data report routines: saving a report on disk in the HTML format, sending it by email and FTP.
To create a report template, you should perform the following actions:
To complete the following walkthrough, you need to have an already created report file with *.rdb extension. Refer to the corresponding tutorials to create and master-detail report files that can be used in command line as input files.
In this walkthrough Report1.rdb file, created in the Creating a Simple Data-Aware Report will be used.
Suppose you need to send a data report containing customers’ address and phone number list in HTML format to your authorities via e-mail and FTP every day. For this, you have a report template Report1.rdb (the file is located in C:\dbForge Studio\Reports), the folder on disk to which the report should be saved is C:\dbForge Studio for MySQL\Reports\Output\, the e-mail address of your authorities is my_chief@company.com, the address of your FTP server is ftp://myftphost.net/reports/, login is send-report, and password is report.
To accomplish such task through command line, you need to perform the following steps:
Open Command Prompt by pressing Win+R and type cmd in the Open line.
Note
To run Command Line in Windows 8:
From the Desktop Mode
- Move the mouse cursor to the exact lower left corner until the desktop shortcuts menu appears
- Right-click to see the shortcut menu and then click Run
From the Charms Bar
- Move your mouse to the upper right corner until the Charms Bar appears
- Select Apps from the list and type run in the search box
- Click Run from the search results
Use Windows + R Shortcut Keys
In the desktop mode, press Windows key + R to show the Run command line.
Change the path available in your Command Prompt window to the path where the dbforgemysql.com file is located (by default it’s C:\Program Files\Devart\dbForge Studio for MySQL). For this, use the cd operator:
C:\Users\User>cd C:\Program Files\Devart\dbForge Studio for MySQL\
Press Enter. You can see that the path has changed:
C:\Program Files\Devart\dbForge Studio for MySQL>
Now, call the dbforgemysql.com file:
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com
Specify the /datareport operation switch:
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport
Specify the path to your Report1.rdb input file and the name of the file itself:
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\Report1.rdb”
Specify the format you want to save your report in. In this case, it’s HTML:
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\Report1.rdb” /format:HTML
(Optional) To include parameters declared in a query script to command line, you can use the /parameters operation. For example, the following query script:
SELECT
first_name,
last_name,
email
FROM customer
WHERE store_id = :store_id and active = :active
will look as follows:
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”D:\Projects\Report1.rdb” /parameters store_id:2 active:0
To start working with the result file, type the /result operation.
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\Report1.rdb” /format:HTML /result folder:”C:\dbForge Studio\Reports\Output"
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\Report1.rdb” /format:HTML /result email:”address@hostname.net”
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\DataReport1.rdb” /format:HTML /result email:”address1@hostname.net, address2@hostname.net”
C:\Program Files\Devart\dbForge Studio for MySQL> dbforgemysql.com /datareport /reportfile:”C:\dbForge Studio for MySQL\Reports\Report1.rdb” /format:HTML /result folder:”ftp://myftphost.net/reports/ “ ftplogin:send-report ftppassword:report
Note
If your report is in HTML format and consists of several files or folders, it is not possible to send such report by email or FTP using command line interface.
Note
You can perform two actions at a time with the result: save it on disk and send by e-mail, or send it by FTP and e-mail.
Note
If you need to create the same report and perform the same action with the result frequently, you can save the needed command line in a *.bat file and run it each time you need to create a report. In this case you will not have to type all necessary operators manually in Command Prompt any more.
Note
To see quick help on the arguments available in the command line, you can type /datareport /?