Command: db

Syntax

db <dbase> {
    <db_command>
    ...
}

Description

Execute a database command block.

Parameters

Switches

Notes

In addition to standard SQL statements, which are passed directly to the database, there are two special forms of the SQL FETCH statement.

They have the following syntax, either:

* FETCH INTO <ident> { ,<ident> ... }

where <ident> is one or more language identifiers whose values are to be retrieved from the database.

and

* MULTIFETCH {<num>} INTO <array> { ,<array> ... }

where <array> is one or more language identifier arrays whose values are to be retrieved from the database. If <num> is specified, then num rows are fetched, otherwise all rows corresponding to the current SELECT criteria are read. Each <array> is filled by a column of data and the sizes of variable-length arrays are adjusted accordingly.

In SQL statements which require identifier values, language identifiers may be specified by preceding them with a : character, e.g.

* INSERT INTO mytable VALUES(:x, :y[55], :sss)

Such language variables may be array expressions, e.g. y[55] above, but must not contain any embedded white space. The only permitted identifier types are numeric, string, time and point. An attempt to output other types of identifier will produce an error. Colons within quoted strings are treated literally and are not assumed to prefix language variables. Numeric values will be expanded with trailing zeros stripped off, string values will be enclosed within quotes, time values will be output in a suitable form for the database, point values will be output in the form (x,y) or (x,y,z) depending on the current value of the <dbase>.dimensions attribute, which can only be 2 or 3.

For more details on SQL (Structured Query Language) statements, consult the relevant documentation on Embedded SQL for your particular database.

db command blocks may be nested to a depth of 16.

The system numeric dberr, maintained by the system, records whether any database errors have occurred during execution of the db command block. It is reset to 0 at the beginning of a db command.

The dbtrans command, which is very similar to db, executes a command block as a single transaction with commit/rollback capability.

Examples

Block of sub-commands (school is a database identifier already set up).

db school {
    string name, class; numeric age
    string s = 'Huntley'
  * SELECT * FROM pupils WHERE name = :s
  * FETCH INTO name, age, class
    string names[], classes[]
    numeric ages[]
  * SELECT * FROM pupils
  * MULTIFETCH INTO names,ages,classes
}

See Also

Commands:

database, dbdelete, dbinsert, dbrefresh, dbstructure, dbtrans, dbupdate

Identifiers:

dberr (numeric)

Structures:

database, database.query (procedure), database.session (procedure), database.transaction (procecdure)