EPOC logo Left Right Up
Appendix F: SQL Specification for Series 5

Appendix F: SQL Specification for Series 5


Chapter Contents


Note on syntax

The use of square brackets [ ] indicates that something is optional, while a vertical line | indicates a choice shold be made between mutually exclusive options. Words in heavy mono-spaced type (e.g. SELECT) should be typed in literally .

SQL keywords are case insensitive.


Select statement

Section Contents

select-statement :

SELECT select-list
      FROM
table-name
      
[ WHERE search-condition ]
      
[ ORDER BY sort-order ]

Use a select-statement to specify what data should be present in the view, and how to present it.


Selecting columns

select-list :
      
*
      column-name-comma-list

Specify * to request that all columns for the table be returned in the view, in an undefined order; otherwise a comma separated list specifies which columns to return, and the order that the columns appear in the view.


Names

table-name

column-name

The table-name should be a table which exists in the database. Column names should refer to columns which exist in the specified table.


Search condition

Section Contents

search-condition :
      boolean-term
[ OR search-condition ]

boolean-term
:
      boolean-factor
[ AND boolean-term ]

boolean-factor
:
      
[ NOT ] boolean-primary

boolean-primary
:
      predicate

      
( search-condition )

This specifies a condition which a row must meet to be present in the generated view. A trivial search condition is just a single predicate, more complex search conditions are constructed by combining predicates using the keywords AND, OR and NOT, and using parentheses to override the standard precedence of these operators. Without brackets, the order of precedence is NOT, AND then OR. e.g.

    a=1 or not b=2 and c=3

is equivalent to

    (a=1 or ((not b=2) and c=3))

Predicates

predicate :
      comparison-predicate

      like-predicate

      null-predicate

These are the building blocks of the search condition. Each predicate tests one condition of a column in the selected table.


Comparison predicate

comparison-predicate :
      column-name
comparison-operator literal

comparison-operator
:
      
< | > | <= | >= | = | <>

Compare a column value with a supplied literal value. Numeric columns (including bit columns) are compared numerically, text columns are compared lexically and date columns are compared historically. Binary columns cannot be compared. The literal must be of the same type (numeric, string, date) as the column.


Literals

literal :
      string-literal
      numeric-literal
      date-literal

A string-literal is a character string enclosed in single quote characters ‘. To include a single literal quote character ‘ in a string-literal, use two literal quote characters ‘’.

A numeric-literal is any sequence of characters which can be interpreted as a valid decimal integral or floating point number.

A date-literal is a character string enclosed by the # character, which can be interpreted as a valid date.


Like predicate

like-predicate :
      column-name [ NOT ] LIKE pattern-value

pattern-value :
      string-literal

Test whether or not a text column matches a pattern string. The wildcard characters used in the pattern-value are not standard SQL, instead the EPOC32 wildcard characters are used: ? for matching any single character and * for matching zero or more characters.


Null predicate

null-predicate :
      column-name
IS [ NOT ] NULL

Test whether or not a column is Null. This predicate can be applied to all column types.


Specifying a sort order

sort-order :
      sort-specification-comma-list

sort-specification :
      column-name [
ASC | DESC ]

Without an ORDER BY clause in the select statement the order that rows are presented is undefined. The columns specified in the sort-order can be ordered in ascending (the default) or descending order, and should appear in the sort-order in decreasing order of precedence. e.g.

    surname, first_name

will order the rows by the column surname, and any rows with identical surnames will then be ordered by the column first_name.


EPOC logo Left Right Up