Unattended Batch Mode
This feature of AQT allows you to run a set of SQL statements (and other AQT functions) in unattended batch mode.
An AQT batch script consists of:
- a batch file which runs AQT, and specifies the name of the script file
- a script file containing the AQT scripting control statements
- a log file to which AQT reports on the running of the script
- other files to which AQT has exported data
Samples
A number of example batch files are supplied with AQT. These will be in the AQT install directory, and have names starting with batch_.
We recommend that you use these as models for building your own scripts.
Batch file
The batch file consists of the following statement
aqt infile logfile options
where
- infile is a script file containing SQL statements and AQT script statements.
- logfile (optional) is a file where AQT will write messages about the processing of the script. If logfile is not specified, AQT will write log output to file aqt_output.log in the same directory as infile. If the log file already exists, AQT will append the output to it.
- options. This specifies some miscellaneous options. If these are specified, you should also code logfile.
At this stage, only one option is implement: NOAPPEND. When this is specified, the log output over-writes the existing log file (eg. the output is not appended to it).
- if the batch file is not in the same directory as your AQT executable, you will need to use a fully-qualified name for the aqt executable.
Example
aqt "c:\Program Files\Advanced Query Tool\batch_sample.sql" batch_sample.log
Running the script
You run the batch script by running the batch file. This can be done by double clicking the file in the Windows explorer.
Exit code
If AQT hits any errors while running your batch script, it will return attempt to set an exit code; however instead will crash. This is discussed in the section Crash in smartuishared when AQT is closing.
Scheduling AQT batch scripts
AQT does not supply a scheduler for running your batch scripts. This is because Windows has a scheduler which can be used for this purpose. The Window scheduler can be run with the AT command (from a command prompt). In Windows XP, there is a graphical interface into this - see Start > Programs > Accessories > System Tools > Scheduled Tasks.
Script file
The script file consists of a series of AQT scripting statements and SQL statements. batch_sample.sql is an example of this, and demonstrates many of the script statements.
- Your script should have at least one Connect function to sign onto the database you wish to run your SQL against.
- You can sign onto multiple databases; the Use function specifies which database a particular SQL statement runs against.
- You can run both Action SQL statements and Select statements. Select statements can only send output to a file.
- Most AQT script statements can be run from the Run SQL window. You can test a statement in this window before putting it in your script file.
- Many AQT functions have an option for generating a script control statement. For instance, in the export data window you can do this through File > View Export Options or Ctrl+G. This shows how more complicated scripting statements are set up.