Home | Using DataLoad | Macro Loads | Browser Control | Forms Playback | Scripting | Problems |
This section provide information about key concepts or solutions for common requirements when using DataLoad Scripting.
How can a load be written that only uses a script instead of using a Macro or Forms Playback load? Scripts can add functionality to Macro and Forms Playback loads but they are most powerful when the load is entirely implemented using a script. With this approach you do not use a Macro or Forms Playback load and instead the script performs all data manipulation and loading functionality. This makes Data Scripting very powerful because almost anything can be achieved. To create an entirely script driven load follow these steps:
The DataLoad load will now not execute any of the Macro load functions and instead the load will be driven by the PHP script. |
|
How do I add data validation to a Macro or Forms Playback load? First, look at the built-in data validation available in DataLoad. If custom data validation is required then this can be implemented using a PHP script. A new script should be created and the data validation code added to the OnStartLoad event handler. The script will need to analyse the data in the DataLoad spreadsheets and that can be done using the DataLoad Scripting PHP functions. When the user is ready to run the load, whether it is a Macro or Forms Playback load, they should press the start load button. This is as normal for Macro loads but this button is not normally used for Forms Playback loads, however in this case we use this button to trigger the data validation. Alternatively, with Forms Playback loads it may be appropriate to add the validation code to the OnSave event handler. With that approach the validation code will run every time the file is saved and there is no need for the user to press any additional buttons. Where data issues are found they should be reported to user using the Console or MessageBox, as described below. If the load is a Macro load and the validation issues mean the load should not progress then the CancelMacro() function can be called and this will stop the load from continuing. |
Is a log of PHP warnings & errors available to assist with debugging scripts? All PHP errors and warnings are written to the phperrors.log file in the PHP directory. |
|
How can I provide feedback to the user when the script is running?
Providing feedback to the user is very important otherwise they will not know what the script is doing. This is especially so when the script is loading the data, as described above. There are a number of ways to provide information to the user:
|
How do I connect to a database, either to load or retrieve date?
One of PHP's strengths is its massive function library and this includes support for all major database platforms, including Oracle, MS SQL Server, MySQL and IBM DB2. These functions can be used to perform all the required operations on these databases and thus data can be loaded in to these databases from DataLoad.
DataLoad Scripting comes fully configured ready to connect to Oracle databases. The PHP Oracle (OCI8) library and Oracle's Instant Client libraries are provided and pre-configured. Connecting to and using Oracle databases from within a DataLoad script just requires that these the OCI8 functions are used. Alternatively, included with DataLoad Scripting is a PHP class that provides a simplified interface to the OCI8 functions. Not all functionality is available in this class so the standard PHP OCI8 functions must be used in some loads but the DataLoad Oracle class is simple to use and covers common requirements. The DataLoad Oracle class is fully documented here. If Oracle database connectivity is required in a load then at some stage the connection details must be collected. DataLoad includes a window to collect the connection details and this can be shown using the GetDBConn() function. A screen shot of this window is shown on the right. The connection details can be supplied as an Oracle TNS alias, assuming one or more tnsnames.ora files are available on the PC, or the "raw" details may be provided (database SID, server IP or hostname, and database port). The connection window also includes fields for the username and password. All these details are returned by the GetDBConn() function when the user clicks "OK". Example loads that load data directly in to an Oracle database are included with DataLoad and it is recommended that these are reviewed to show how scripts can integrate with databases.
|