diff --git a/cesql/spec.md b/cesql/spec.md index 921c40d7..1566b3a6 100644 --- a/cesql/spec.md +++ b/cesql/spec.md @@ -268,7 +268,7 @@ Similarly, whenever the left operand of the OR operation evaluates to `true`, th | `x LIKE pattern: String x String -> Boolean` | Returns `true` if the value x matches the `pattern` | | `x NOT LIKE pattern: String x String -> Boolean` | Same as `NOT (x LIKE PATTERN)` | -The pattern of the `LIKE` operator can contain: +The pattern of the `LIKE` operator MUST be a string literal, and can contain: - `%` represents zero, one, or multiple characters - `_` represents a single character @@ -278,6 +278,10 @@ For example, the pattern `_b*` will accept values `ab`, `abc`, `abcd1` but won't Both `%` and `_` can be escaped with `\`, in order to be matched literally. For example, the pattern `abc\%` will match `abc%` but won't match `abcd`. +In cases where the left operand is not a `String`, it MUST be cast to a `String` before the comparison is made. +The pattern of the `LIKE` operator (that is, the right operand of the operator) MUST be a valid string literal without casting, +otherwise the parser MUST return a parse error. + #### 3.4.4. Exists operator | Definition | Semantics | @@ -353,6 +357,35 @@ left operand of the OR operation evalues to `true`, the right operand MUST NOT b #### 3.7. Type casting +The following table indicates which type casts a CESQL engine MUST or MUST NOT support: + +| Type | Integer | String | Boolean | +| ------- | ------- | ------ | ------- | +| Integer | N/A | MUST | MUST | +| String | MUST | N/A | MUST | +| Boolean | MUST | MUST | N/A | + +For all of the type casts which a CESQL engine MUST support, the semantics which the engine MUST use are defined as follows: + +| Definition | Semantics | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `Integer -> String` | Returns the string representation of the integer value in base 10, without leading `0`s. If the value is less than 0, the '-' character is prepended to the result. | +| `Integer -> Boolean` | Returns `false` if the integer is `0`, and `true` otherwise. | +| `String -> Integer` | Returns the result of interpreting the string as a 32 bit base 10 integer. The string MAY begin with a leading sign '+' or '-'. If the result will overflow or the string is not a valid integer an error is returned along with a value of `0`. | +| `String -> Boolean` | Returns `true` or `false` if the lower case representation of the string is exactly "true" or "false, respectively. Otherwise returns an error along with a value of `false` | +| `Boolean -> Integer` | Returns `1` if the boolean is `true`, and `0` if the boolean is `false`. | +| `Boolean -> String` | Returns `"true"` if the boolean is `true`, and `"false"` if the boolean is `false`. | + +An example of how _Boolean_ values cast to _String_ combines with the case insensitivity of CESQL keywords is that: +``` +TRUE = "true" AND FALSE = "false" +``` +will evaluate to `true`, while +``` +TRUE = "TRUE" OR FALSE = "FALSE" +``` +will evaluate to `false`. + When the argument types of an operator/function invocation don't match the signature of the operator/function being invoked, the CESQL engine MUST try to perform an implicit cast. This section defines an **ambiguous** operator/function as an operator/function that is overloaded with another