On this page

@

Core command

Runs a Script: a text file of SQL statements and BroadSQL commands.

Syntax

@<script> [<name>=<value> ...]

Quick start

@maintenance/cleanup.bsql

Runs the Script maintenance/cleanup.bsql of the Scripts Library.

@reports/customer.bsql customer_id=42

Runs a Script that reads ${customer_id}.

Arguments

ArgumentRequiredValuesDefault
<script>YesA path in the Scripts Library, a ./ path, or an absolute path; in double quotes when it contains spacesNone
<name>=<value>No, unless the Script requires itA named argument: a number, a quoted string, TRUE, FALSE, NULL or ${variable}For a -- @param parameter: the variable of that name set by LET, otherwise its default

Examples

@maintenance/cleanup.bsql
@./helper.bsql
@reports/customer.bsql customer_id=42 country='FR'
@"C:\My Scripts\foo.bsql" since=${last_run}

Example session

@countries/largest.sql continent='Europe';
-- continent = 'Europe'
-- min_population = 50000000
|----|----------------------------------------------------|-----------|
|CODE|NAME                                                |POPULATION |
|----|----------------------------------------------------|-----------|
|RUS |Russian Federation                                  |146934000  |
|DEU |Germany                                             |82164700   |
|GBR |United Kingdom                                      |59623400   |
|FRA |France                                              |59225700   |
|ITA |Italy                                               |57680000   |
|UKR |Ukraine                                             |50456000   |
|----|----------------------------------------------------|-----------|

6 rows fetched in 12 ms.

countries/largest.sql: SUCCESS (1 statement, 0 failed) [run BUZ2SI4X]
Running the Script with continent='Europe'

Details

A Script is a text file of SQL statements, BroadSQL commands, or both, separated by ;. The file extension means nothing to BroadSQL. A reference is found the same way by every command and by the Editor.

Where the Script is found

  • @foo.bsql and @maintenance/foo.bsql: relative to the Scripts Library root, never to the working directory. No extension is ever guessed: @foo is the file named foo.
  • @./foo.bsql: relative to the working directory when typed at the prompt, and to the folder of the running Script when written inside a Script, so a folder of Scripts can be moved as a whole.
  • @C:\temp\foo.bsql or @/tmp/foo.bsql: an explicit path to a Script outside the library.

Put a reference that contains spaces in double quotes.

Named arguments

@report.bsql customer_id=42 country='FR': each argument sets a scripting variable for this call, and the Script reads it as ${customer_id}.

  • A value is a number, a single-quoted string, TRUE, FALSE, NULL or one ${other} variable.
  • Every value is computed before any is set, and a call that fails sets none of them. There is no limit on the number of arguments.
  • The arguments last as long as the call: when the Script returns, a variable of the same name gets back the value it had before, or is undefined again. A LET run by the Script itself stays.
  • A parameter declared with -- @param and not passed takes the value of the variable of the same name set by LET, otherwise its default: LET continent = 'Europe'; then @largest.sql; uses Europe. A required parameter with neither refuses the call.
  • A Script can require arguments with a -- @params: customer_id, country comment line: each call must then pass them explicitly.

The positional parameters %1 to %9 were removed: @report.bsql 42 FR fails with an explanation. Write @report.bsql customer_id=42 country='FR' and use ${customer_id} in the Script.

Result

At the end of a Script started at the prompt, a status line gives the result (SUCCESS, COMPLETED_WITH_ERRORS, FAILED or CANCELLED), the number of statements run and failed, and a run identifier. @, LIB RUN and the BroadSQL Editor run Scripts the same way.

Used in these how-tos

Last modified in release 5.5.0.

Found something wrong or unclear on this page? , with the page address.