
DBQ - Commands
==============
CREATE database fieldname type size [scale] [fieldname type size [scale]]
ERASE database
RENAME database newname
INSERT database
DELETE selection ;
UPDATE fieldnames OF selection ;
PRINT [USING formatfile] fieldnames OF selection [INTO reportfile] ;
FIND fieldnames OF selection ;
SORT database BY fieldname [direction] [fieldname [direction]] ;
IMPORT datafile INTO database
EXPORT [DELETED] database [INTO datafile] ;
EXTRACT database [INTO definitionfile] ;
COMPRESS database
DEFINE procedure / ENTER procedure
SHOW {procedure} ;
SET [NO] [FOLD] [VERIFY] [LOG] [PAGE [pagelength]] ;
HELP
EXIT

?<

Syntax
======
database, newname	: database file name (Identifier) (Ext. .DBQ)
fieldnames		: qualfieldname[+] [, qualfieldname[+] ...] | all[+]
qualfieldname		: [database.]fieldname
fieldname		: field name (identifier)
type : NUM | CHAR / size : 1 to 12 NUM, 1 to 128 CHAR / scale : 0 to 10
direction		: ASC (default) | DESC
selection		: database [, database ... ] WITH expression
expression		: [NOT] comparison [AND | OR [NOT] comparison ...]
comparison		: primary relation primary
primary			: qualfieldname | string | number
relation		: = | > | < | >= | <= | <> | }
procedure		: procedure name (Identifier)
pagelength		: length of paper in lines less 6 for heading
datafile		: data file name (Identifier) (Ext. .DAT)
formatfile		: format file name (Identifier) (Ext. .FMT)
reportfile		: report file name (Identifier) (Ext. .REP)
definitionfile		: definition file (Identifier) (Ext. .DEF)
identifier		: Alpha [ alpha | "_" ...]

?c

Create database
===============

create <database> <fname> <ftype> <flen> [<fscale>] . . . ;

Where
	database	::=	database name
	fname		::=	field name
	ftype		::=	(CHAR | NUM)
	flen		::=	field length
	fscale		::=	field scale (decimal places) - default 0

Example
	create accounts name char 10 acc_num num 6 balance num 8 2 ;

?i

Insert records
==============

insert <database>

Prompts for fields in record. Brackets show the width of the field.
[string] and <numeric> fields are indicated by the type of bracket.
A number after <numeric> brackets indicates the number of decimal places.
Pressing ENTER for first field terminates input.

Example:-

	insert accounts

name		 [          ]
acc_num		 <      >
balance		 <        > 2
------
name		 [          ]

?u

Update records
==============

update {<fields> | all } of <selection>;

Where
 - <fields> is a field list
 - <selection> is a record selection expression

This allows you to update the specified fields in the selected
records. The original value is printed first, and a prompt is issued
to allow a new value to be input. If no value is entered before
pressing ENTER, the original value is retained.

Example
-------

update balance of accounts with name = "john smith";

balance		= 2.34
balance		 <       > 2

?p

Print selected fields from selected records
===========================================

print [using <filename>] [{ <field>[+], <field>[+] . . . | all[+] }
	of] <selection> [into <tname>] ;

Where

 - using <filename> indicates a format file (ext=.FMT)
	will be used for output formatting.
 - <field>[+] is an optionally qualified field name with optional
	totalling (+) specified for numeric fields.
 - all indicates all fields with optional totalling (+) of all
	numeric fields
 - <selection> is a record selection expression
 - <tname> is the name of an output file (ext=.TXT) to be used instead of the
	terminal for output. (LST will cause output to the printer).
 
Example
-------
print name, acc_num, balance+ of accounts with name } "smith";

?s

Find records
============

find { <field>, <field> . . . | all } of <selection> ;

Where

 - <field> is an optionally qualified field name
 - all indicates all fields (can use * instead of 'all')
 - <selection> is a record selection expression

Creates a database called "current" containing the selected records.

Example
-------
find name, acc_num of accounts with name } "smith";
rename current smiths
print;

?i

Import records from a file
==========================

import <filename> into <database>

Where
 - <filename> is the name of a data file (ext .DAT) containing the values
   of the fields, one per line.
 - <database> is the name of the database to append the records to.

?e

Export records to a file
========================

export [deleted] <database> [into <filename>]

Where
 - <database> is the name of the database to export records from
 - <filename> is the name of a file (ext .DAT) to receive the records.
   If omitted, the records are written to the terminal.
 - the "deleted" option exports those records that have been marked
   as deleted since the file was created or compressed. It is used to
   recover overambitious deletions.
 - records are written to the output file one field per line.

?e

Extract database definition
===========================

extract <database> [into <filename>]

Where
 - <database> is the name of a database
 - <filename> is a file (ext .DEF) to receive the definition.
   If omitted, the definition is written to the terminal - this
   is handy for reminding you what fields are defined.
 - The definition is specified as the commands necessary to
   create the database again at the current size.

?c

Compress database file
======================

compress <database>

Where - <database> is a database name.

This compresses active records at the start of the database file,
and frees up space at the end for further records to be added.

To reduce the size of the file as well, assuming there is sufficient
disk space, the following sequence may be used instead

	DBQ> find all of <database>;
	DBQ> print; # To check if everything is O.K. before erasing old file
	DBQ> erase <database>
	DBQ> rename current <database>

?s

Sort a database
===============

sort <database> by <sname1> {, <sname2>} . . . ;

Where
 - <database> is a database name
 - <sname> is the name of a field to sort on, optionally followed
   by "asc" (default) or "desc" meaning ascending or descending.
 - The sort order is major through minor (e.g. <snameN> within <snameN-1>
   . . . within <sname2> within <sname1>.
 - Records are sorted in situ. It takes a while for a large database.
 - It is not advisable to abort a sort halfway through - be patient.
 - Unfortunately all sorting is done on the character value of the field,
   so numerics do not get sorted numerically.

Example
-------

sort accounts by name, balance descending;

?e

Erase a database
================

erase <database>

Where - <database> is the name of a database

The named database file is erased from the disk. It cannot be
recovered except by immediate use of a program such as UNERA.

?r

Rename a database
=================

rename <olddatabase> <newdatabase>

Where
 - <olddatabase> is the existing name of a database
 - <newdatabase> is the desired new name for the database

Example
-------

	DBQ> find all of employees with dept = 300;
	DBQ> rename current ourdept

?d

Define a procedure
==================

define <procname>

Where

 - <procname> is the name of the procedure to be defined

DBQ prompts you for the definition on subsequent lines. An empty line
is used to terminate the definition. As procedure definitions overwrite
previous definitions, a null definition effectively deletes the procedure.

Example
-------

	DBQ> define sum
	DBQ-DEF> print all+ of
	DBQ-DEF>
	DBQ> sum accounts;

?s

Show procedure definition
=========================

show <procname>

Where

 - <procname> is the name of the procedure to be listed

 - if <procname> is replaced by a terminator or keyword,
   a list of currently defined procedures is shown.

Example
-------

	DBQ> show sum
		print all+ of
	DBQ> show ;
		sum
	DBQ>

?e

Prompt for simple procedure value
=================================

enter <procname>

Where - <procname> is an identifier

Causes a prompt to be issued for the identifier, and after reading one
line, sets the procedure to that value. A null entry deletes the procedure.
This is used in command files, and in other procedures, to prompt for input
as part of a procedure of commands.

Example
-------
	DBQ> define findemp
	DEFINE> enter empno:
	DEFINE> print employees with empno = empno: ;
	DEFINE>
	DBQ> findemp
	DBQ> Enter empno:

?s

Set/unset options
=================

set [no] [fold] [verify] [log] [page {nn}] ;

This permits options to be set, or unset if "no" is first specified.

The options are:-

fold	- permits alphabetic case folding on comparisons.
	  e.g. "FrEd" would match with "fReD"
verify	- causes contents of command files to be output during execution.
log	- causes input to be logged to the file DBQ.LOG
          all log output for a run is concatenated, even if switched off
          in between sections. The file is closed on 'exit'.
page {nn} sets the page length to nn lines (or 66 if nn not specified).

Example
-------

set fold no verify;
Fold = 1, log = 0, page = 60, verify = 0

?h

Help on topics
==============

help

This causes an initial page of help information to be output to the
terminal. A prompt is then issued to press ^Z, ENTER, or a character.
If ENTER is pressed, the next page of help is printed.
If ^Z is pressed, the program returns to the DBQ> prompt.
If a character is pressed, the next help page relating to a topic
starting with that character is displayed.

Example
-------
	DBQ> help

... page of help ...
Press ^Z to abort, ENTER to continue, or x for help on x...
c

... page of help on "create" ...

?e

Exit from DBQ
=============

exit

This returns the user to the CPM+ prompt

?f

Format file
===========
The format file is used to provide a format for output, and can
contain control specifiers (<,>,%,question mark) and free text.

Fields
------
<field name> - is replaced by named field, space filled
		   to left for numbers and to right for strings
>field name< - is replaced by named field with no space fill

Heading
-------
%Heading text
%
At the start of the format file causes the specified heading text
to be output at the start of the output listing.

Pause
-----
A question mark at the end of the file causes a pause on every record.

?@

Command files
=============

@<filename>

Where - <filename> is the full name of a file containing commands.

This causes the contents of the specified file to be inserted at the
current point in the input. The command file may contain any input,
apart from the response to an "enter" request.

If "verify" is set, the contents of the file are output to the terminal
as it is read.

If the file "DBQINIT.CMD" is present when DBQ is started, it is executed
initially, and can be used to set up procedure definitions etc.

Comments can be inserted in a command file, or indeed in direct input,
by preceding them with "#". Everything on a line after a "#" is ignored.

?q

To quit type "exit"


d in direct input,
by preceding them with "#". Everything on a line after a "#" is 