Previous Table of Contents

## 6. Supported SQL

Currently, XBSQL supports the following:

- select e1, ... from t1, ... [ where c1<ii> ... ] [ group by g1, ... ] [ having h ] [ order by o1, ... ]
- insert into t values (e1, ...)
- insert into t (c1, ...) select ...
- insert into t select ...
- insert into t (c1, ...) values (e1, ...)
- update t set c1 = e1, ... where c1, ...
- delete from t where c1, ...
- create table t (colspec, ...)
- drop table t

XBSQL supports aggregate functions, group by, and having. Note, however, that there are currently no sanity checks (hence, select n, sum(n) is valid. The results of such a query are not defined.

The following aggregate functions are available:

- min(e)
- max(e)
- sum(e)
- count(*)

The following general functions are implemented:

- upper(e)
- lower(e)
- nullif(e1,e2)
- tochar(e)

Since XBase has no notion of null values, nullif is only defined for text arguments; the result is the value of the first argument unless it is an empty string, in which case the result is the value of the second argument.

Expressions e1 are currently fairly limited, just some basic arithmetic and string concatenations, plus equality/inequality, greater/less greater-or-equal/less-or-equal. like is also supported using either % as the wildcard character, or UNIX shell-like wildcards, and with (by default) case-insensitive matching.

Available column types for create column specifications are as below. A blob is binary data; XBase itself does not have a time data type.

- int
- double
- char
- date
- blob

The SQL parser accepts as column names any non-empty string of alphanumeric characters, or the underscore _ character, provided that at least one character a alphabetic or the underscore. To allow for column names in exising table which are the same as the SQL keywords, or which contain a space, the notation [name] can be used, hence select [The Date], [The Time] from MyTable is syntactically valid.

XBase files all contain fixed-width columns, with the exception of the blob type, which maps to a memo column. The first three cases can therefore have (width) appended. Individual columns can be indexed, for example, (...., ident int(10) index, ...). The date type will default to a width of 8 if the width is not specified or is specified as zero (since XBase stores dates in the format YYYYMMDD).

Memo fields are always created with a notional width of 10, as required by the XBase specification. This works around a minor bug in xbase-2.0.0.

Unsupported SQL includes

- sub-selects
- create .... as
- alter table ...
- inner, etc., joins