mydbr_doc

249
myDBR Documentation

Upload: ajit-dixit

Post on 22-Nov-2015

192 views

Category:

Documents


2 download

TRANSCRIPT

  • myDBR Documentation

  • myDBR DocumentationCopyright 2007 - 2014 mydbr.com

    About myDBR

    myDBR is enterprise ready reporting system for MySQL and Microsoft SQL Server, Sybase ASE and SQL Anywheredatabases. myDBR scales from personal database reporting tool to enterprise business intelligence system. Creatingand maintaining reports with myDBR is fast, fun, and productive.

    For more information visit mydbr.com

  • iii

    Table of Contents1. Welcome to myDBR ........................................................................................................................... 12. Installation .......................................................................................................................................... 2

    Quick Start ..................................................................................................................................... 2Manual Installation .......................................................................................................................... 2Prerequisites .................................................................................................................................. 3

    PHP ....................................................................................................................................... 3ionCube PHP loader ............................................................................................................... 3Database version requirement ................................................................................................. 3Choosing a Database Driver ................................................................................................... 4

    myDBR application ......................................................................................................................... 5Download the myDBR application ........................................................................................... 6Select database user for myDBR ............................................................................................ 6Prepare the report database ................................................................................................... 7Install the myDBR application ................................................................................................. 8Installation wizard ................................................................................................................... 9

    Optional installs ............................................................................................................................ 10Graphviz support - recommended ......................................................................................... 10wkhtmltopdf - recommended ................................................................................................. 10Image chart support with ChartDirector .................................................................................. 10Google Maps registration ...................................................................................................... 11

    Update myDBR ............................................................................................................................ 11Automatic updater using web interface .................................................................................. 11Scripting the automatic updater ............................................................................................. 11Manual update ...................................................................................................................... 12

    Database access .......................................................................................................................... 12User login ............................................................................................................................. 12Report execution .................................................................................................................. 15

    myDBR License ............................................................................................................................ 15Requesting a license ............................................................................................................ 15How many licenses do I need? ............................................................................................. 15Information contained in the license ...................................................................................... 15

    3. Getting started .................................................................................................................................. 17Creating your first report ............................................................................................................... 17

    First report ........................................................................................................................... 17Assign the report to the myDBR report structure .................................................................... 18Adding parameters to a report .............................................................................................. 20

    Cross-tabulation report .................................................................................................................. 21Understanding the data parts in a cross-tabulation report ....................................................... 22

    Charts .......................................................................................................................................... 23Generating a chart ................................................................................................................ 23

    Pageview report ............................................................................................................................ 25User Parameters .......................................................................................................................... 26

    ............................................................................................................................................ 26Basic fields (text/number) ...................................................................................................... 26Date picker ........................................................................................................................... 28Default values ....................................................................................................................... 28Predefined / dynamic parameters .......................................................................................... 29Popups ................................................................................................................................. 29Radio buttons ....................................................................................................................... 31Checkboxes .......................................................................................................................... 32Autocomplete fields ............................................................................................................... 33One-line autocomplete .......................................................................................................... 33Two-line autocomplete .......................................................................................................... 34Getting the IDs of the selected autocomplete value ................................................................ 35Connected parameters ........................................................................................................ 36

  • myDBR Documentation

    iv

    Automatic parameter ............................................................................................................. 38Example: Identifying the user running the report ................................................................... 39Parameters in linked reports ................................................................................................. 39

    Report linking ............................................................................................................................... 40Linking to column values ...................................................................................................... 40Linking to parameters ........................................................................................................... 42Passing on multiple parameters ............................................................................................ 42Letting the user edit the passed parameters .......................................................................... 43

    Referencing columns and parameters or passing on constants ....................................................... 43Column reference ................................................................................................................. 44Parameter reference ............................................................................................................. 45Passing constants on ............................................................................................................ 45

    Report layout ................................................................................................................................ 46Placing elements side-by-side using 'dbr.keepwithnext'-command .................................. 47Using templates .................................................................................................................... 48Placing elements with the dbr.html-command ......................................................................... 48

    Creating editable reports ............................................................................................................... 49Editing / creating new database entities ................................................................................. 49'Delete a row'-example, use Javascript to enhance editing ...................................................... 50In-place editing ..................................................................................................................... 52

    4. Preferences ...................................................................................................................................... 55Report categories ......................................................................................................................... 55Users ........................................................................................................................................... 55

    myDBR users ....................................................................................................................... 55Importing users from another system ..................................................................................... 56

    Groups ......................................................................................................................................... 56User group concept .............................................................................................................. 56Adding group ........................................................................................................................ 56Removing group ................................................................................................................... 56Adding a user to a group ...................................................................................................... 56Remove a user from a group ................................................................................................ 56

    Styles ........................................................................................................................................... 56Row styles ........................................................................................................................... 57Column styles ....................................................................................................................... 57

    Parameter queries ........................................................................................................................ 57Server side files ............................................................................................................................ 58

    ............................................................................................................................................ 58defaults.php .......................................................................................................................... 58userstyle.css ......................................................................................................................... 58

    Templates .................................................................................................................................... 58Report Map .................................................................................................................................. 58Notifications .................................................................................................................................. 59

    Login notification ................................................................................................................... 59Main-screen notification ........................................................................................................ 60

    Environmental settings .................................................................................................................. 60Report Database Setup ........................................................................................................ 60Authentication ....................................................................................................................... 60Password settings when using myDBR authentication ............................................................ 61Single Sign-On (SSO) settings .............................................................................................. 61Active Directory settings ........................................................................................................ 61Automatic login ..................................................................................................................... 61Formatting defaults ............................................................................................................... 61Installed modules .................................................................................................................. 62Miscellaneous settings .......................................................................................................... 62

    Single Sign-On (SSO) ................................................................................................................... 62Introduction ........................................................................................................................... 62Authentication protocol .......................................................................................................... 62Local myDBR login when SSO is enabled ............................................................................. 63

  • myDBR Documentation

    v

    Logout process in SSO ......................................................................................................... 63Example for integration with SugarCRM ................................................................................ 64

    Active Directory ............................................................................................................................ 65Introduction ........................................................................................................................... 65Active Directory settings ........................................................................................................ 65Local myDBR login when AD login is enabled ....................................................................... 66

    Remote servers ............................................................................................................................ 67Demo / Localization ...................................................................................................................... 67

    Demo ................................................................................................................................... 67Localization .......................................................................................................................... 67

    About ........................................................................................................................................... 685. Managing reports .............................................................................................................................. 69

    General ........................................................................................................................................ 69Adding/deleting folders .......................................................................................................... 69Adding/deleting reports ......................................................................................................... 69Moving reports and folders .................................................................................................... 69Defining report parameters .................................................................................................... 70Report privileges ................................................................................................................... 70

    Report access rights ..................................................................................................................... 70All logged in users ................................................................................................................ 70Access without login allowed via direct URL .......................................................................... 70Individual users .................................................................................................................... 70Groups inside myDBR .......................................................................................................... 70Identifying the user running the report ................................................................................... 70Showing report privileges at one glance ................................................................................ 71

    Direct URL access to reports ........................................................................................................ 71URL parameters ................................................................................................................... 71Generating a direct URL ....................................................................................................... 72Example ............................................................................................................................... 73Embedding reports in a web page ......................................................................................... 74Direct accessible image reports ............................................................................................. 74Getting only the report object's content .................................................................................. 74Using HTTP basic access authentication ............................................................................... 74

    Statistics ....................................................................................................................................... 75Localization .................................................................................................................................. 76

    Localizing myDBR's User Interface for your own language ...................................................... 76Multilingual support in myDBR .............................................................................................. 76Handling dates in string ........................................................................................................ 77Example of a localized report ................................................................................................ 77Using DATE.FORMAT .......................................................................................................... 78

    Favorites ...................................................................................................................................... 78Customization ............................................................................................................................... 79

    Customize the Main Screen .................................................................................................. 79Customize the report ............................................................................................................ 80Customize the PDF output .................................................................................................... 80Using CSS for customization ................................................................................................. 80OEM customization ............................................................................................................... 81

    Utilizing version control ................................................................................................................. 81Usage .................................................................................................................................. 81Sample configuration files ..................................................................................................... 82Additional configuration settings ............................................................................................ 82

    6. Commands ....................................................................................................................................... 83Aggregate functions ...................................................................................................................... 83

    Explanation ........................................................................................................................... 84Example use of an aggregate function ................................................................................... 84Including header levels in calculation ..................................................................................... 85Calculations .......................................................................................................................... 86Basic calculation ................................................................................................................... 86

  • myDBR Documentation

    vi

    Calculation applied to a crosstable ........................................................................................ 87Calculation with aggregate column reference ......................................................................... 87Calculation with horizontal aggregate column reference .......................................................... 88Combining calculation with horizontal and vertical aggregate column reference ........................ 89

    Titles / text ................................................................................................................................... 90Applying styles ............................................................................................................................. 93

    Column hiding ...................................................................................................................... 94Define a column style ........................................................................................................... 94Summary calculation with column style .................................................................................. 96Define a row style ................................................................................................................ 96Define a cell style or class .................................................................................................... 97Hiding the header from a result table .................................................................................... 98Header and footer styles ....................................................................................................... 98Custom CSS class for result tables ....................................................................................... 99Fetching images from the database ....................................................................................... 99

    Cross tabulation .......................................................................................................................... 100Calculating column and row summaries ............................................................................... 101Predefine data columns ...................................................................................................... 102Full cross tabulation example .............................................................................................. 104

    Header levels ............................................................................................................................. 105Appearance ................................................................................................................................ 109

    Pageview ............................................................................................................................ 110Placing elements side by side ............................................................................................. 111Creating an automatic row number ...................................................................................... 111Set column sorting and override the default sorting method for a column ............................... 112Disabling sorting on selected columns ................................................................................. 112Search / export visibility ...................................................................................................... 113Auto refresh ........................................................................................................................ 114Set dynamic column title ..................................................................................................... 114Show parameters within report ............................................................................................ 114Use DIV's instead of tables ................................................................................................. 115Paging result sets ............................................................................................................... 115Using tabs to organize your report content ........................................................................... 116Using accordions to organize your report content ................................................................. 117Placeholder for nonexistent data ......................................................................................... 119Sticky headers .................................................................................................................... 119Using column filters ............................................................................................................ 119Resultset options ................................................................................................................ 120

    Charts ........................................................................................................................................ 121How to create a chart? ....................................................................................................... 127Setting own chart colors ...................................................................................................... 129Chart options ...................................................................................................................... 130Sparkline charts .................................................................................................................. 141Chart examples .................................................................................................................. 142Graphviz ............................................................................................................................. 148

    Linked reports ............................................................................................................................. 155Linked report parameters .................................................................................................... 157Linked report placement ...................................................................................................... 157Output destination of the linked report ................................................................................. 158Optional links based on data ............................................................................................... 159Examples ............................................................................................................................ 159Buttons as links .................................................................................................................. 164Select lists as links ............................................................................................................. 165Lists as links ...................................................................................................................... 165Optional links ...................................................................................................................... 167

    Editable reports .......................................................................................................................... 167Passing HTML into the page ....................................................................................................... 175Templates ................................................................................................................................... 178

  • myDBR Documentation

    vii

    Using full queries inside a template ..................................................................................... 183Recording template variables .............................................................................................. 185

    Running total .............................................................................................................................. 186Import commands ....................................................................................................................... 188Export commands ....................................................................................................................... 190Remote calls to other myDBR servers ......................................................................................... 195

    7. Extensions ...................................................................................................................................... 199Overview .................................................................................................................................... 199

    Processing the result set ..................................................................................................... 199JavaScript ........................................................................................................................... 200extensions.php .................................................................................................................... 200Extension example .............................................................................................................. 201Dummy extension example ................................................................................................. 202

    Google Maps extension .............................................................................................................. 202Mail extension ............................................................................................................................ 208

    Usage ................................................................................................................................. 209Sending report output as mail ............................................................................................. 209Using attachments .............................................................................................................. 210

    eChart extension ......................................................................................................................... 210Usage ................................................................................................................................. 211

    SMS extension ........................................................................................................................... 212Usage ................................................................................................................................. 213

    HERE Maps extension ................................................................................................................ 213Organization chart extension ....................................................................................................... 216

    8. Supported datatypes ....................................................................................................................... 223MySQL ....................................................................................................................................... 223Microsoft SQL Server, Sybase ASE, SQL Anywhere .................................................................... 224

    9. Security .......................................................................................................................................... 22610. myDBR SQL Editor ....................................................................................................................... 227

    Editor basics ............................................................................................................................... 227Query Builder ............................................................................................................................. 228

    Building a query .................................................................................................................. 228myDBR Commands .................................................................................................................... 229Using SQL Editor ........................................................................................................................ 229

    Executing statements .......................................................................................................... 229Getting code for additional objects ....................................................................................... 229

    Output as SQL ........................................................................................................................... 230A. MySQL Stored Procedures ............................................................................................................. 232

    Using parameters ....................................................................................................................... 232Stored procedure without parameters .................................................................................. 232Stored procedure with parameters ....................................................................................... 232

    Using Variables .......................................................................................................................... 233Using Conditions ......................................................................................................................... 233

    IF-THEN-ELSE ................................................................................................................... 234CASE ................................................................................................................................. 235

    Using Loops ............................................................................................................................... 235WHILE ... END WHILE ........................................................................................................ 236REPEAT .. END REPEAT ................................................................................................... 236LOOP .. END LOOP ........................................................................................................... 237

    Using Temporary Tables ............................................................................................................. 237B. Command reference ....................................................................................................................... 239

  • 1Chapter 1. Welcome to myDBR

    myDBR is a web-based reporting system for relational databases that allows you build a feature rich,manageable and scalable reporting environment. myDBR manages the distribution and access rightsautomatically, so it also scales well to large scale installations. Users are able to access reports using just aweb browser, no additional software installations is required.

    Fast and feature rich report authoringWhen authoring a report, all your effort should be concentrated into the content of the report. myDBR helps youto achieve this by taking away the unnecessary work needed in traditional reporting systems. Features can betaken into use with a single mouse click; even the most complex ones.

    Browse through your data with report networkWith myDBR you can easily link reports together allowing you to building a report network. This gives yourusers a natural path for data mining and drill-down reports using business concepts close to them. Moving fromindividual reports to a report network makes sure you are getting the most out of your data.

    Automated distribution and access rightsBy automating the distribution and access rights to reports, you can rest assured that the right people have theright data at their disposal. You can easily connect the reporting system's access control mechanism to yourown data and automate access.

  • 2Chapter 2. InstallationmyDBR is a PHP application which stores it's information (reports, report privileges, required database objectsetc.) into the database. In order to install myDBR, a working PHP environment with database support is needed.myDBR is shipped as a compiled PHP application, for which a PHP loader is needed. myDBR also supportsoptional modules which you may want to install.

    Quick StartThe recommended way to install myDBR is by using the installation wizard which will check your environmentand set up myDBR for you in a matter of minutes.

    1. Download the myDBR application from myDBR.com

    2. Extract the downloaded mydbr.zip to the desired location on your web server

    3. Point your favorite web browser to the location where you put the myDBR files

    4. Follow the instructions provided by the installation wizard

    5. You will be prompted to install the ionCube PHP loader if your environment does not have it installed

    6. See also Optional installs

    Installation complete - Enjoy using myDBR!

    Manual InstallationmyDBR installation requires following steps:

    A working PHP environment with database support. See Installation prerequisites.

    Database requirements

    PHP 5.x

    mysqli for MySQL support

    FreeTDS / Microsoft PHP drivers for Microsoft SQL Server

    FreeTDS Sybase ASE or SQL Anywhere support

    myDBR application. See Installing myDBR application.

    Prepare the report database

    Install the PHP loader

    Installing myDBR application

    Optional installs

    Graphviz support for hierarchical and network charts (recommended, free). myDBR also uses Graphvizinternally (if installed) to show the report network structure.

    wkhtmltopdf for full quality PDF output

    Image chart support (commercial ChartDirector support). By default myDBR ships with the Flash chartsupport (with the help of InfoSoft Global's nice FusionCharts Free) package

  • Installation

    3

    Installation prerequisitesmyDBR installer will guide you to install the required component. Following setup is required for successfulinstallation of myDBR:

    A web server (Apache, IIS) with PHP installed PHP database extension for your database

    ionCube PHP loader

    MySQL, Microsoft SQL Server, Sybase ASE or SQL Anywhere database

    PHPMake sure that your PHP (5.1 or greater) installation is in order. More information on http://www.php.net.

    ionCube PHP loadermyDBR is a compiled PHP application. In order to use the application the ionCube PHP loader needs to beinstalled in your system (if not already present). Download the loader suitable for your environment and followthe instructions.

    First check if the loader is already installed in your system. Check your phpinfo output for text "ionCube PHPLoader".

    If the ionCube PHP Loader is not installed, ionCube provides a helper script to generate specific installationinstructions for your environment. Below is an example to enable the helper script - download, unpack and copythe loader script to the web server root.

    $ wget http://downloads2.ionCube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz...

    $ gunzip -c ioncube_loaders_lin_x86.tar | tar xopf -$ cd ionCube$ sudo cp ionCube-loader-helper.php /var/www/html

    Now access the ionCube-loader-helper.php with your browser: http://localhost/ionCube-loader-helper.php andclick the "php.ini installation instructions". Follow the instructions to install the correct version of the loader.

    Once correct loader version has been identified we'll include it to the php.ini file and restart the web server.See example below.

    $ sudo mkdir /usr/local/ionCube/$ sudo cp ioncube_loader_lin_5.4.so /usr/local/ionCube/$ sudo vi /etc/php5/apache2/php.ini

    $ sudo apache2ctl restart

    myDBR will check the existence of the loader, so you can proceed to installing the myDBR application.

    Database version requirementMySQL: use database version 5.0.7 or greater. More information on http://www.mysql.com.

    MariaDB: all versions are compatible with myDBR.

  • Installation

    4

    Microsoft SQL Server: use database version SQL Server 6.5 or greater. More information on http://www.microsoft.com/sql/default.mspx.

    Sybase ASE: use database version 15.0.2 or greater. More information on http://www.sybase.com/ase.

    SQL Anywhere: use database version 11 or greater. More information on http://www.sybase.com/products/databasemanagement/sqlanywhere.

    Choosing a Database DriverTo choose the most suitable PHP database driver, use the following table:

    PHP running on Windows OS PHP running on any other OSMySQL mysqli mysqliMicrosoft SQL Server FreeTDS/Microsoft Drivers 3.0 for PHP for SQL

    ServerFreeTDS

    Sybase ASE FreeTDS FreeTDSSQL Anywhere FreeTDS FreeTDS

    MySQL support: mysqliFor MySQL, PHP must have the mysqli extension enabled. For information on installation of mysqli, see http://www.php.net/mysqli. Most of the PHP installations have this enabled by default.

    Microsoft SQL Server with Windows PHP serverIf you are running a Microsoft SQL Server and your PHP runs on Windows server, you can choose betweenFreeTDS (php_dblib.dll) and Microsoft Drivers 3.0 for PHP for SQL Server extension (version 3.0). Microsoft'sextension is referred as 'sqlsrv' inside myDBR.

    Microsoft SQL Server, Sybase ASE and SQL Anywhere support: mssql +FreeTDS

    If you are using Microsoft SQL Server (non MS PHP), Sybase ASE or SQL Anywhere a FreeTDS version ofmssql PHP extension is used. You can check the phpinfo.php output for the MSSQL Support string. myDBRinstallation will check that the mssql-extension is installed. Do not use the old deprecated mssql-extension asit is not supported.

    Microsoft SQL Server, Sybase ASE and SQL Anywhere supportmyDBR uses PHP's mssql (FreeTDS) extension to access Microsoft SQL Server, Sybase ASE and SQLAnywhere. Usage of FreeTDS is required as with FreeTDS myDBR can use UTF-8 character set. Note thatif you are running Microsoft SQL Server and your PHP runs on Windows server, you can also choose to useabove mentioned Microsoft PHP Drivers.

    Required FreeTDS configurationWindows

    Use php_dblib.dll instead of php_mssql.dll in the php.ini. php_dblib.dll c ontains the FreeTDS libraries neededfor proper character set (UTF-8) handling. A good source for the Windows php_dblib.dll extension is moodle.org

    Other OS

    Make sure you have FreeTDS installed and that your PHP installation has mssql-support enabled.

    FreeTDS Configuration

    To access Microsoft SQL Server, Sybase ASE or SQL Anywhere install FreeTDS libraries. FreeTDSconfiguration is handled by the freetds.conf-file. You can check the location of the freetds.conf file by issuing

  • Installation

    5

    the command "tsql -C". If you are accessing only a single database server, you can make the configurationsunder the [global]. If you plan to use FreeTDS to access multiple database servers, make the specificationsunder a specific database server section.

    SQL Server freetds.conf configuration:

    [global] client charset = UTF-8 text size = 2147483647 tds version = 8.0

    Sybase ASE and SQL Anywhere freetds.conf configuration:

    [global] client charset = UTF-8 text size = 65536 tds version = 5.0

    If you expect to handle longer text or images larger than 2K, change following php.ini-settings:

    mssql.textlimit = 2147483647mssql.textsize = 2147483647

    myDBR expects the dates in the form of Y-m-d H:M:S, so check that your FreeTDS's locales.conf containsfollowing setting:

    [default] date format = %Y-%m-%d %H:%M:%S

    In order to check the connection and the correct character set, use the tsql command to see what everything isok. You should be able to connect and see that the used charset is UTF-8 and your dates are correctly formatted(your locale might vary):

    $ tsql -Sserver -Uuser -Ppasswordlocale is "fi_FI.UTF-8"locale charset is "UTF-8"1> select getdate()2> go

    2009-03-31 12:45:10(1 row affected)1>

    Installing the myDBR applicationIn order to install the myDBR application manually you need to complete following steps. (Please note thatmyDBR provides also an automated installation wizard. Launch the wizard by simply pointing your browser atthe mydbr-directory):1. Download the application

    2. Setup the database

  • Installation

    6

    3. Install the PHP loader

    4. Install the application

    Download the myDBR applicationDownload the myDBR application from the myDBR website. You will receive a zip-package containing theapplication. Extract the files from the zip-package and place them under your web root.

    Select database user for myDBRWhen you launch myDBR for the first time, you will be asked for the username and password under whichmyDBR operates. The username and the password provided need to have:

    1. Full access to reporting database's objects (by default mydbr) - see picture below

    2. Select access to the database which contains the actual data to be reported (user database) - see picturebelow

    myDBR application and database access

    You can use your existing database account to access myDBR or create a new database account. Below is anexample of how to create a new myDBR user account 'mydbr'.

  • Installation

    7

    $ mysql -uroot -p --default-character-set=utf8Enter password: ******mysql> create user 'mydbr'@'localhost' identified by 'mydbr_password';mysql> exit;

    If you do not have permissions to create new users, you can use an existing user and assign the requiredprivileges (see later steps).

    Prepare the report databasemyDBR stores all the reporting information (reports, internal objects etc.) into a database. You can either installthem into a separate database (recommended) or if you only have access to one database, you can installthe items directly to the database you will be reporting from. All items in myDBR are named with '*mydbr*' toseparate them from the user's data and objects.

    myDBR requires full access to the myDBR reporting database and select-access to the database you arereporting from. See picture above. You can either use an existing database user or create a new one. In thisexample installation we have created a user [6] with name 'mydbr'.

    Change to the db_creation directory (we'll use the database creation scripts):

    $ cd install/db_creation

    For MySQL:

    1. Create the mydbr database (or use any existing database):

    $ mysql -uroot -p --default-character-set=utf8Enter password: ******mysql> create database mydbr character set = 'utf8';mysql> exit

    2. Add required privileges for the 'mydbr' user:

    a. Full access to myDbr database and

    b. Select-access to 'mydatabase'As an example we have created a user called 'mydbr' and our data resides in the 'mydatabase' database.

    $ mysql -uroot -p --default-character-set=utf8Enter password: ******mysql> grant all on mydbr.* to 'mydbr'@'localhost';mysql> grant select on mydatabase.* to 'mydbr'@'localhost';mysql> exit

    3. Create the mydbr reporting database objects:

  • Installation

    8

    $ mysql -umydbr -p --default-character-set=utf8 mydbr < mydbr_create_mysql.sqlEnter password: ******

    If the creation script finishes without any errors, you are ready to move to next step.

    For Microsoft Sql Server:

    1. Create a database called 'mydbr' with the Microsoft SQL Server Management Studio with 'mydbr' as theowner

    2. Create the database objects:

    C:\>osql -n -U mydbr -P password -d mydbr < mydbr_create_mssql.sql

    If you do encounter problems during the database creation, please check that you have sufficient privilegesfor creating database objects.

    For Sybase ASE

    1. Create a database called 'mydbr' with the Sybase tool with 'mydbr' as the owner

    2. Create the database objects:

    isql -Umydbr -Ppasssword -Dmydbr < mydbr_create_sybase.sql

    If you do encounter problems during the database creation, please check that you have sufficient privilegesfor creating database objects.

    SQL Anywhere:

    1. SQL Anywhere uses one database model so the objects are created in a user database. Use a differentusername (mydbr) to create the objects

    2. Create the database objects:

    isql -Umydbr -Ppasssword -Dmydb < mydbr_create_sybase.sql

    If you do encounter problems during the database creation, please check that you have sufficient privilegesfor creating database objects.

    NoteThe install script will create a myDBR admin (user inside myDBR) with a username/password dba/dba.You should change the username/password as soon as you have installed the application.

    Install the myDBR applicationThe last thing to be done is to move the unpacked mydbr-directory to your server root and change itspermissions.

    1. Check your server root and copy the unpacked mydbr-directory into it.

  • Installation

    9

    2. Ensure that all the files are the have appropriate owner, i.e. the files are readable by the web server. Seethe example below.

    3. Make sure that the myDBR's configuration file config.php is writable to the web server. This allows theadmin to change myDBR's settings via browser. Also make sure that it is not readable to other users.

    4. The first time you launch the application (point the browser to the myDBR web share), the application willask you for the connection information and formatting options. The username and the password asked in thisscreen need to have ownership of the myDBR database and access to the reported data.

    Example permissions on linux (check your document directory and apache user). On MacOS X the apache useris by default "_www".

    $ sudo mv mydbr /var/www/html$ cd /var/www/html/mydbr$ sudo chown -R apache:apache * .$ sudo chmod -R go-r *$ sudo chmod -R u+w *

    Point your browser to http://localhost/mydbr/. If your installation is complete you are greeted with the setupscreen.

    If you ever need to reset the install to this point, in the config.php you'll find a key 'SETUPDONE' which willdetermine if the myDBR application will present the install screen or the normal login screen.

    Installation wizardThe first time you use the application, you will be greeted by the install wizard. By this point you should beable to enter the connection details to your reporting database. myDBR also makes system checks to see thatyour environment is in working order. If you see error messages on screen, please fix the configuration errorsbefore proceeding.

    Required fields

    Database vendor Select the database vendor. myDBR uses native connection to eachdatabase for maximum performance.

    Host The computer where the reporting database is located. Hostname or IPaddress.

    Database The name of the database containing the mydbr objects.Username The admin user's username. This user must have the privileges to mydbr

    database object, including the right to execute stored routines. In theexample installation we created user mydbr for this purpose.

    If myDBR will be configured in MySQL (at later stage), to use databaseauthentication, root access is needed. If the authentication is myDBR orexternal application authentication, no root access is required.

    Password The password for the admin user.

    Use SSL When using MySQL, the traffic between web server and database servercan be secured with SSL. Checking this option will force the connection touse SSL. You can additionally use certificates to limit connection to knownclient / host.

    Key File The client's private key (must be used with Certificate)

  • Installation

    10

    Certificate (must be used withKey File)

    The client's certificate

    CA Cert The certificate authority certificate

    Complete the setup and you should be ready log in with the default username dba and password dba. Youmight want to change this after the setup is done.

    Optional installsGraphviz support - recommended

    Graphviz adds support for the hierarchical and network charts. myDBR also uses Graphviz internally (if installed)to show the report network structure. In order to take advantage of Graphviz charts, the basic package forGraphviz and the PEAR Graphviz-package needs to be installed.

    1. Graphviz Download and install the latest Graphviz support from http://www.graphviz.org/Download.php foryour environment.

    2. PEAR Download and install latest version of PEAR

    3. Image_GraphViz PEAR package. Install the PEAR Graphviz-package (1.3.0 is the latest one as of thiswriting)

    $ sudo pear install -f Image_Graphviz-1.3.0

    More information about PEAR package installations.

    wkhtmltopdf - recommended

    myDBR supports wkhtmltopdf if installed on the server. wkhtmltopdf uses the Webkit rendering engine to convertcontent to PDF. Using wkhtmltopdf enables pixel perfect PDF reports generated from the server side thereforallowing things like forms to be generated.

    If wkhtmltopdf is not installed on the server, myDBR uses an alternative PDF output method. However installingwkhtmltopdf is recommended. To install wkhtmltopdf, follow the instructions on the wkhtmltopdf website.wkhtmltopdf will be installed as a command line tool and should be found in the PHP path. If it cannot beadded to a PATH variable, a direct link to the command can be given in mydbr/user/defaults.php by setting the$mydbr_defaults['export']['wkhtmltopdf']['command'] variable to a full path to the command.

    Example if wkhtmltopdf is not found in PHP's PATH:

    $mydbr_defaults['export']['wkhtmltopdf']['command'] = '"C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe"';

    Once you have installed wkhtmltopdf to the server, go to 'Environment settings' and see the 'Installed modules' ifPHP is able to see the program. If not, you may need to define the full path to the command in $mydbr_defaults.

    Image chart support with ChartDirector

  • Installation

    11

    The myDBR Premium version of myDBR includes a license for the commercial ChartDirector charting modulefrom Advanced Software Engineering. The benefit of using the ChartDirector instead of the flash chart modulethat ships with myDBR is the ability to produce the pictures without client side flash plugin, support for morechart types, better support for printing and iPhone / iPod touch support for charts.

    Both image and flash charts can be used simultaneously. Image and flash charts share the same syntax inmyDBR, so you can choose which one to use without changes to the actual report code.

    To make best use of the myDBR Premium version download your copy of ChartDirector for PHP packagepackage from the Advanced Software Engineering's website and follow the instructions. Once you have installedChartDirector to your system, myDBR recognizes it and you can set it as a preferred charting module (seeEnvironmental settings)

    Google Maps registrationmyDBR supports Google Maps as an extension (source code included). Prior to using the Google Mapsextension, you need to register your Google Maps API key. Follow the instructions on Google Maps extensionhelp.

    Update myDBRmyDBR will release new versions regularly. If your server has a connection to myDBR.com, an updatenotification is shown when new major versions are available. It is recommended to run the update once newversions are introduced, the new versions can contain bug fixes and new functionality. Updates are designedto keep existing report running as is.

    Automatic updater using web interfaceThe preferred update method for myDBR is to use the built-in automatic update method. myDBR periodicallychecks if new versions are available and will notify the admin user in the main page of new versions. At any time,if you wish to update myDBR, you can invoke the update from Admin Tools -> About / Update -> Updatenow... . If your license has expired and you cannot see the Admin Tools-section, you can click on myDBR-logoin top left corner to bring up the "About / Update"-dialog.

    While carrying out the automatic update, myDBR replaces the application itself and updates the myDBRreporting database to include the latest changes. All the user's reports will be kept intact. Also, any modificationsto user settings under user-directory are kept (this includes user specific logos, settings etc.).If your server is behind a proxy and is not able to contact the myDBR update server, the proxy settings canbe entered in the Environment settings. If you unable to update myDBR even with the correct proxy settings,please see that you have php_curl installed.

    Scripting the automatic updaterThe automatic updater can also be scripted.

    When the update URL (see example) is called, authentication is carried out using HTTP basic accessauthentication. myDBR defines, by default, username 'mydbr_updater' to be used with scripted updates. Thisis defined in defaults.php and can be overridden in mydbr/user/defaults.php.

    To activate the username (mydbr_updater) to be used in scripts, the username needs to be added to myDBRusers. Usernames defined as updater-usernames are limited to the update function only and cannot thereforebe used as normal login users.

    The update URL is called using basic access authentication (replace the myserver.com/mydbr with your owndefinition):

  • Installation

    12

    % curl -H "X-MYDBR-AUTH: 1" -u mydbr_updater:mydbr_updater_password "http://myserver.com/mydbr/install/index.php?controller=update&action=update"

    The result for the updater is a JSON object with following fields:

    { "host":"myserver.com", "expiration":"2013-12-22", "version": { "before_update":"3.9.0\/2003", "after_update":"3.9.4\/2099" }}

    If there was an error in the update process, an "error" entry will be added to the JSON object. The entry hasthe error message that caused update to fail.

    Manual updateIf your server does not have a connection to myDBR.com (direct or through a proxy), manual update needs tobe applied. To perform a manual update, do following:

    Save possible changes made to the myDBR configuration by saving the mydbr_config.php (contains the logininformation to the database) and any changes made in /mydbr/user-directory

    Download the myDBR zip package from http://mydbr.com

    Replace the existing myDBR install with the new unzipped content of the zip-package

    Restore the saved mydbr_config.php and any changes made to /mydbr/user-directory

    Access myDBR through the web server

    myDBR will now see the updated application and will guide through the rest of the installation through the updatewizard. All your reports will stay intact.

    How does myDBR access the database?myDBR was designed to be a reporting system that can be used without any modifications to the actual userdatabases. By default myDBR installs into it's own reporting database ('mydbr' by default). All myDBR databaseobjects (including reports) are stored in this database. myDBR only needs read access to the database wherethe actual data is held.

    You can also install myDBR directly to the user database, where your data is (instead of the default mydbr).myDBR uses its own naming scheme, so it will not conflict your data. (myDBR objects have a prefix of: "mydbr_"for tables, "sp_MyDBR_" for myDBR internal procedures, "sp_DBR" for report procedures).myDBR database access can be divided into two parts: login process and the report execution. Here we'll gothrough both of them.

    User loginIn the login process myDBR checks if the user has credentials to log in to the system. By default myDBR usesit's internal structure to hold usernames/passwords. Following authentication modules are available in myDBRpreferences:

  • Installation

    13

    myDBR user authentication Users username and password hash are checked against themyDBR's internal structure (mydbr_userlogin-table). The password field inmydbr_userlogin-table is an md5 hash of the actual password.

    Database login Users username and password are used for an single log in to the databasesystem. The user is allowed to log in and his/her username/password canbe used to log in to the database.

    Single Sign-On Users username and password are checked against external applicationsauthentication. Please see more info at Single Sign-On

    Active Directory Users username and password are checked against Microsoft ActiveDirectory.

    If you want to allow the use of myDBR without any login process (public intranet, extranet), you can set automaticlogin credentials in Admin preferences. When automatic logins are set, admin access can be gained by pointingthe browser to login.php instead of the usual index.php.

  • Installation

    14

  • Installation

    15

    Report executionOnce the login process has been completed, all the operations in the database are done using the username/password stored in the admin preferences (section Database connection info: Username/Password). Theseare stored in the config.php (entries admin_username and admin_password). These are referred here as'myDBR credentials'. myDBR credentials must have full access to the mydbr-database and read access to theuser database objects.

    Report creationThe reports are created in the mydbr-database as stored procedures. myDBR credentials must have executionaccess to these stored procedures. When accessing the data in the actual user database one refers to tablesusing format 'mydatabase.mytable' in MySQL and 'mydatabase..mytable' in MS SQL Server, SybaseASE.

    SQL Anywhere does not support multiple databases so reports are created in same database. As an alternative,you can install myDBR in a separate database and use SQL Anywhere proxy tables to link your data tables.

    myDBR LicensemyDBR requires a license for each myDBR installation. The myDBR server is identified by its host name /installation path. You can get the license from myDBR shop.

    Requesting a licenseYou can request new licenses and manage your existing licenses from the myDBR shop. myDBR willautomatically provide you with a link to request a license if it cannot find a valid license for your server.

    Once you have received your license via e-mail, copy the text between the --- clip lines to the setup screenor the Licenses tab of myDBR.

    If myDBR does not accept your new license, make sure you have updated myDBR to the latest version. SeeUpdate myDBR for more info. myDBR licenses are always generated for the latest version.

    How many licenses do I need?You will need a separate license for each myDBR instance you are running.

    Let's assume that you have installed myDBR on your workstation, so you would usually access the solution viathe URL http://localhost/mydbr. Therefore you will need a license for the domain localhost. If youthen deploy myDBR to your production server with the URL http://www.myserver.com/mydbr you wouldneed another license for the domain www.myserver.com

    Information contained in the licenseThe license you receive via e-mail contains the following information:

    Owner The name of the person to whom the license is registered

    Mail The e-mail address of the owner

    Host The host name under which myDBR is accessed. If you have myDBR installed at http://reports.mycompay.com/mydbr the host is reports.mycompay.com. If you are using nonstandardport, include the port to hostname.

    Company The name of the company where myDBR is installed

    DB The type of database used

  • Installation

    16

    Expiration The date when the license expires, in YYYY-MM-DD format. For example 2010-11-30 means30th November 2010

    Type The type of the license

    Version The minimum version of myDBR required to use this license. If your installed myDBR versionis to old, you will need to update first

    Key The license key generated for you by the myDBR Team

    A license usually looks like this:

    ----- clipowner=John [email protected]=reports.mycompay.comcompany=My Company Ltd.db=mysqlexpiration=2010-11-30type=premiumversion=1.5.0key=6dad519753be1bc24c6d33e784d17f32c31f188e----- clip

  • 17

    Chapter 3. Getting startedCreating your first report

    myDBR reports are database native stored procedures that you can create using the built in SQL Editor (or anySQL editor that you prefer). For more details see myDBR SQL Editor.To create a report, you will create a stored procedure in the myDBR database. The report stored procedurehas a prefix ('sp_DBR') which helps myDBR to differentiate report procedures from other procedures in thedatabase. Once the procedure has been created, it will be attached to the myDBR application's report hierarchyvia 'Add report' function. When attached, the report is ready to run.

    Once the report has been attached to the myDBR structure, you are free to edit (or drop/recreate) the storedprocedure behind it. This allows maximum flexibility when developing your reports.

    In addition to normal SQL data queries, myDBR reports include myDBR commands which are interpreted bymyDBR when the report is run.

    First reportAs an example, we'll write a simple report and go through the steps needed to use myDBR. The setup used inthe example is the default setup where user has the data in his/hers own database (called 'mydb') and myDBR isusing its own reporting database ('mydbr'). The examples are partly based on MySQL sample database Sakila.If you wish to try out myDBR with Sakila-database, please follow the link and download it.

    The first report will list films from the table 'film' from the user database 'mydb'. (We'll add up features to thereport later).We'll write a stored procedure called sp_DBR_FilmList that will show the films in the database. 'sp_DBR' is thedefault prefix for the report procedures. myDBR will use this prefix to assist you when you attach the storedprocedure as a report in the myDBR structure (i.e. distinguishes the report from other stored procedures inthe database). In the example we'll create the report by using the built in SQL editor and store it to the mydbrdatabase.

    1. Click 'Add report' from main screens Admin tools.

    If no unassigned stored procedures (procedures starting with 'sp_DBR' that are not used in report) can be found,myDBR asks for the procedure name to be created:

    2. Enter the procedure name and click OK.

    myDBR will create you a template report into which you will add your queries and logic.

  • Getting started

    18

    If you want to browse the database structure or get help with writing the SQL code, you can open the QueryBuilder by clicking the "Show Query Builder"-button. You can pick the database, table and columns you wish tobe included in the report. Please see more ino on myDBR SQL Editor.

    3. Create a new procedure by using the Query Browser or by editing the code manually.

    1. Select database

    2. Select table

    3. Select columns

    4. Click 'Generate SQL into selection'

    5. Edit procedure if necessary and click 'Execute' to save the procedure

    You'll notice that we are giving each column a name which the user sees as column header in the report whenthe report is run. If you do not specify the name, the name is derived from the column/data used.

    Assign the report to the myDBR report structureClick 'Execute' to save the report procedure to the database. If there were any errors, fix them and click 'Execute'again. Once the report's stored procedure is successfully saved into the database, click the "Add report tomyDBR" button to attach the procedure as a report in myDBR's report structure.

  • Getting started

    19

    myDBR will fetch all the procedures from the database which match the prefix mentioned earlier and that havenot yet been assigned as a report. The report name is the name visible to the user, and the description showsup in the report listings. After we accept the data, the report will be assigned to myDBR and is ready to be used.

    For your convenience, myDBR opens up a screen where you can name the input parameters and grant privilegesto the report. We'll skip this for now and go back to main screen.

    You should now be able to see the report in the main screen and run it.

    The report has a title, which, by default, is the same as the report's name. If you wish to change the title in thereport (for example add dynamic data/parameters to it) you can use the command dbr.title to achieve this. Bydefault, myDBR makes columns sortable, just click on a header column to sort the data.

  • Getting started

    20

    Adding parameters to a reportWe'll extend the report by adding parameters to the report. Report parameters are normally stored procedureinput parameters. By default, myDBR uses stored procedure parameters 'as is', but myDBR can also furtherextend the parameters by:

    Naming the parameters

    Providing assistance based on data type (date pickers) Using predefined lists as parameters (as radio buttons, popups) Using live autocomplete fields from the database (AJAX autocomplete) With linked reports automatically fill in parameters based on user input / report flow

    In this example we'll set a film name (or part of it) as a parameter. We'll introduce a parameter 'vFilmName'into the stored procedure.

    create procedure sp_DBR_FilmList( vFilmName varchar(30) )begin

    select title as 'Title', release_year as 'Release Year', rental_rate as 'Rental Rate', length as 'Length'from mydb.filmwhere title like concat('%', vFilmName, '%');

    end

    Since the stored procedure has already been assigned to myDBR, we do not need to reassign it. Just edit theprocedure and you are ready to run it. Now when you re-run the report, the parameter is asked from us asan input:

    The variable name is not necessarily the name you want the user to see. Let's create a more descriptive namefor it. We'll go back to the main screen and edit the report's data by clicking the 'edit'-link below the report.

    You'll go the screen where you can edit the ready filled basic data about the report, handle the parameters andassign privileges to the report. We'll just give a name to our parameter.

  • Getting started

    21

    When we re-run the report we'll see that the new name for the parameter is used.

    In order to learn how to use more advanced features on parameters, please consult the Managing Reports /Report Parameter for further info.

    Cross-tabulation reportIn cross tabulation the result set's data is divided into header and data sections divided by a cross tabulationcolumn. Header columns, left from the cross tabulation-column (and optionally also on the right) will determinethe distinct rows in the final result set and the data columns will be repeated under distinct values under valuesderived for the cross tabulation-column.

    The purpose in cross tabulation is to turn the table from this:

    into this:

    When using cross tabulation, the order of the rows in the report will be determined by the order of the data inthe query. Similarly the order of the data columns are determined by the order of the data in the query. If youwant the data columns to appear in certain order or you data may not contain all the data columns, you can usedbr.crosstab.col-command to predefine the data columns.

  • Getting started

    22

    Understanding the data parts in a cross-tabulation reportSay we have a basic data set:

    select RepArea as 'Reporting area', Period, last_year as 'Last year', this_year as 'This year', next_year as 'Next year'from mydb.ProductionSummary;

    We can determine the different parts of the result set:

    By defining the column 'Period' as a cross tabulation column, the distinct values in that column are calculatedas group columns and the data columns are calculated underneath each group column.

    If any other column contains myDBR commands, they are automatically handled. In the example we'll use styleand some aggregate functions in data columns.

    /* Define the Period as a cross tabulation column Make sure you remember to order the result set accordingly*/select 'dbr.crosstab', 'Period';

    /* Highlight the current year */select 'dbr.colstyle', 'this', mydbr_style('Diff colors with bg');

    /* Calculate sums */select 'dbr.sum', 'last','this','next';

    select RepArea as 'Reporting area', Period, last_year as 'Last year[last]', this_year as 'This year[this]', next_year as 'Next year[next]'from mydb.ProductionSummary;

  • Getting started

    23

    See full description of Cross Tabulation command.

    ChartsmyDBR allows you to generate different kinds of charts based on your data. For complete documentation oncharts see the Charts section. In this example we'll generate a sample chart.

    Generating a chartAs with the previous examples, we'll generate a stored report to generate the report and the data needed forthe chart. We'll create a sample Pie-chart of total sales of the film categories. The procedure to be createdlooks like this:

    create procedure sp_DBR_FilmByCategoryChart()begin

    select category, total_salesfrom mydb.sales_by_film_category;

    end

    After we assign the procedure to myDBR and run it, we'll get the data needed for the chart.

  • Getting started

    24

    To generate a chart, a dbr.chart -command is added in front of the result set.

    create procedure sp_DBR_FilmByCategoryChart()begin

    select 'dbr.chart', 'Pie', 'Sample Pie chart';

    select category, total_salesfrom mydb.sales_by_film_category;

    end

    When we re-run the report, we'll get the data drawn as a chart.

  • Getting started

    25

    For complete documentation on charts see the Charts- and Graphviz-section.

    Pageview reportPageview allows you to view the data in a 'record' format. It is mostly used in cases where you have only onedata row to be displayed. Instead of showing the data as a row, the format shows the data in a more readable'record' -format (see picture below).

    If we have a report that returns a single row the result might look something like this:

    If the result contains multiple columns, it might be better to change the layout to use the Pageview-feature. We'llplace the command select 'dbr.pageview'; in front of the actual dataset query to turn the following resultset's columns into rows. So adding the command:

    select 'dbr.pageview';

    select f.title as 'Title', f.description as 'Description', f.release_year as 'Release year', f.rating as 'Rating', l.name as 'Language'from mydb.film f, mydb.language lwhere f.film_id = vID and f.language_id=l.language_id;

    produces a result like this:

  • Getting started

    26

    If the report produces multiple rows, each row is displayed as an individual record.

    User ParametersmyDBR reports can have parameters that will be asked from the user when the report is run. The parametersare the parameters for the stored procedure containing the report. Parameters can be any of the following:

    Parameters can have default values which are used if user runs the report the first time. On subsequent runsparameters contain the last value used.

    Parameters can be any of the following:

    Basic fields

    Date picker

    Default values

    Popups

    Radio buttons

    Checkboxes

    Autocomplete fields

    Connected parameters

    Automatic parameter

    Parameters in linked reports

    If nothing is pre-defined myDBR reads the stored procedures parameters (name and type) and simply asks thevalues from the user. myDBR checks the datatype of the parameter and adapts the input field accordingly.

    Basic fields (text/number)Basic parameters in the report are requested as is from the user. myDBR allows the parameter name to bechanged, so instead of using the actual procedure parameter name, admin can assign a title for the parameter.

    In this example we'll use a film name (or part of it) as a parameter. We'll introduce a parameter 'vFilmName'into the stored procedure.

  • Getting started

    27

    create procedure sp_DBR_FilmList( vFilmName varchar(30) )begin

    select title as 'Title', release_year as 'Release Year', rental_rate as 'Rental Rate', length as 'Length'from mydb.filmwhere title like concat('%', vFilmName, '%');

    end

    Since the stored procedure has already been introduced as a report, we do not need to reassign it. Just edit theprocedure and you are ready to run it. Now when we re-run the report the parameter is asked from us as input:

    The variable name is not necessarily the parameter name that you want to use. Let's create a more descriptivename for it. We'll go back to the main screen and edit the report's data by pressing the Edit-button

    next to the report.

    You'll get the screen where you can edit the ready filled basic data about the report, handle the parameters andassign privileges to the report. We'll just give a name to our parameter.

    When we re-run the report we'll see that the new name for the parameter is used.

  • Getting started

    28

    Date pickerWhen the report parameter is a date or a datetime, myDBR automatically offers a date picker to the user tomake up the data entry easier. The date format is defined in the myDBR preferences.

    create procedure sp_DBR_FilmUpdates( vStartDate date, vEndDate date )begin

    select title as 'Title', release_year as 'Release Year', rental_rate as 'Rental Rate', length as 'Length', last_update as 'Last Update'from mydb.filmwhere last_update between vStartDate and vEndDate;

    end

    When we run the report, we are asked about the dates with the assistance of a picker:

    myDBR shows the time in the picker if the datatype contains time elements (datetime).

    Default valuesA report's parameters can have default values. These values are used when the report is run the first time. Onsubsequent runs the default values are the ones the user used during the last run. Default values are definedin the 'Admin->Parameter queries'-page.

    Let's examine the myDBR statistics report's defaults. The report has two date fields; one for the start time andone for the end time. By default myDBR offers to run the statistics for the past month with the start time bydefault to be one months back from now. The default query is defined in 'Admin->Parameter queries' page:

  • Getting started

    29

    The defined defaults are then associated with the query parameters in the 'Edit query' screen:

    When the report is run for the first time, the report's date fields defaults to the set default dates.

    Predefined / dynamic parametersIn addition to simply requesting parameters from the user, myDBR allows one to present choices to the user.These choices can be static or dynamic. In the latter case the choices are read from the live data. These choicescan be presented to the user as via a popup, radio button or an Ajax-style autocomplete field. The one to choosedepends on the data and the amount of choices available. A radio button is most suitable for limited numbers ofchoices, a popup when there are more, but still a limited number of choices and finally the autocomplete whichcan initially have a bigger selection.

    Predefined / dynamic parameters are defined in the myDBR preferences (Admin->Parameter queries). Theseare parameter queries that can be shared among all the reports. Parameter queries should return:

    The popup - id and user visible value

    The radio button - id and user visible value

    The autocomplete field - visible value

    The checkbox - id and user visible value

    PopupsIn order to convert a report parameter to a popup with different choices, we'll define the popup in the 'Admin->Parameter queries'-page. The popup list consist of a list of visual values for the user combined with theassociated id.

    Popup parameter query can return following result set with some optional columns:

    ID [, Visible value to user[, Grouping]]

    If the query returns just one column, the same column will be used for both ID and as the value visible to user. Ifthe group for the row is returned the values belonging to same group will be grouped with the HTML optgroup.

  • Getting started

    30

    As an example, we'll create a report which will list films based on a selected film category. In this example theuser can also to choose to show the full film list. We'll use the parameter inCategory so that when it equalszero, well show all films, in other cases we'll show just the selected category.

    create procedure sp_DBR_FilmsByCategory( inCategory tinyint )begin

    select f.title as 'Title', f.description as 'Description', f.release_year as 'Release year', f.rating as 'Rating'from mydb.film fwhere f.film_id in ( select film_id from film_category where category_id = inCategory or inCategory = 0 );

    end

    We'll then prepare the popup list with query that returns the id and the user visible value.

    The parameter query is then attached to the report in the 'Edit query' screen. We can at same time name theparameter:

    When we now run the report, a popup with predefined values is shown:

  • Getting started

    31

    Radio buttonsThe radio button-parameter works exactly the same way as in the popups. We'll create a radio buttons showingjust simple Yes/No selection:

    The radio button parameter query can return following result set:

    ID [, Visible value to user]

    If the query returns just one column, the same column will be used for both ID and as the value visible to user.

    Let's create a very simple example procedure that uses the defined popup when we attach the radio buttonparameter into it:

    create procedure sp_DBR_YesNoParam( inYesNo tinyint )begin

    select inYesNo;

    end

    When we now run the report, a radio button selection is shown:

  • Getting started

    32

    CheckboxesCheckboxes differ from other parameters in so far as multiple ID's are sent to the report. myDBR does this bydelivering a comma separated list of the selected ID's to the report. Report will parse the comma separated list(examples below) and use the ID's as part of query.

    We'll start by defining the checkbox choices in the 'Settings->Parameter queries'.

    select category_id, namefrom mydb.category;

    The defined parameter query is attached to the following report. The report will convert the comma separatedlist to a table of ID's which can then later in the report be joined to other objects. The conversion will be doneby a prepared statement. This example is using MySQL.

    create procedure sp_DBR_checkbox( inCheckbox varchar(255) )begin

    /* Our ID's are integers, so we'll prepare a temporary table for those */drop temporary table if exists data_tmp;create temporary table data_tmp (id int);

    /* We'll grab the exiting ID's by searching using a prepared statement(Alternatively one could just parse the string in a loop)*/set @vSQL = concat('insert into data_tmp select category_id from category where category_id in (', inValue, ')');prepare stmt from @vSQL;execute stmt;DEALLOCATE PREPARE stmt ;

    /* We could use the temporary table as part of the report */select id as 'User choice'from data_tmp;

    /* We are done with the temporary table */drop temporary table if exists data_tmp;

    end

    Comma separated list parsing Microsoft SQL Server is done by using the sp_executesql-system procedure. InSybase ASE and in SQL Anywhere you can use EXECUTE statement.

  • Getting started

    33

    IF object_id('sp_DBR_checkbox','P') IS NOT NULLDROP PROCEDURE [sp_DBR_checkbox]GOCREATE PROCEDURE sp_DBR_checkbox@inCB varchar(200)ASBEGINdeclare @sql nvarchar(200)

    create table #data_tmp (id int)

    select @sql = 'insert into #data_tmp select category_id from category where category_id in ('+@inCB+')'

    exec sp_executesql @sql

    select id from #data_tmp

    drop table #data_tmp

    ENDGO

    Autocomplete fieldsAutocomplete fields narrow the selection by performing live queries on the database based on user data entry.The user is presented with a simple entry field, and while the user enters the data into the field, suggestionsbased on actual data are offered to user. The returned suggestions can be freely defined ('start of string'-match,'contains'-match etc.). The actual definition for fetching SQL is different from the popup or the radio button. Theparameter defining the SQL must be a stored procedure and it will return the matching value and optional