sql-null

Description

An extension for providing a portable SQL NULL object.

Author

Ivan Shmakov

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/sql-null

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Documentation

The sql-null extension implements the following interface.

[procedure] (sql-null)

Return an object, corresponding to a SQL NULL value. The object is guaranteed to be of a type disjoint from all of the R5RS' standard types. It's unspecified whether the values returned by this function will be eq? to each other:

(eq? (sql-null) (sql-null)) => ; unspecified.
[procedure] (sql-null? OBJECT)

Return #t if OBJECT is a SQL NULL object. Return #f otherwise.

[syntax] (sql-not OBJECT)

Return OBJECT if OBJECT is a SQL NULL object. Return the value of (not OBJECT) otherwise.

(sql-not (sql-null)) => SQL-NULL
(sql-not 'a) => #f
(sql-not #f) => #t

(let ((null (sql-null)))
  (eq? null (sql-not null))) => #t
[syntax] (sql-and TEST-1 ...)

The TEST expressions are evaluated from left to right, and the value of the first expression that evaluates to a false value is returned, and any remaining TESTs are not evaluated. If there were no expressions to evaluate to a false value, the value of any of the expressions to evaluate to a SQL NULL is returned. If there were no such expressions as well, #t is returned.

(sql-and 1) => 1
(sql-and 1 (sql-null) 2) => SQL-NULL
(sql-and #f (sql-null)) => #f

In the absence of the expressions that evaluate to SQL NULL values, the semantics is the same as for (and test-1 ...). One could think of the SQL NULL as "sticky"; as soon as it is encountered, it will be the result of the entire expression (unless #f is also encountered).

[syntax] (sql-or test-1 ...)

The TEST expressions are evaluated from left to right, and the value of the first expression that evaluates to a value, other than SQL NULL and a false value (a ``SQL true'' value), is returned, and any remaining TESTs are not evaluated. If there were no expressions to evaluate to a SQL true value, the value of any of the expressions to evaluate to a SQL NULL is returned. If there were no such expressions as well, #f is returned.

(sql-or 1) => 1
(sql-or #t (sql-null) 2) => #t
(sql-or #f (sql-null)) => SQL-NULL
(sql-or #f (sql-null) 1) => 1

In the absence of the expressions that evaluate to SQL NULL values, the semantics is the same as for (or test-1 ...).

[syntax] (sql-coalesce test-1 ...)

The TEST expressions are evaluated from left to right, and the value of the first expression that is not SQL NULL is returned, and any remaining TESTs are not evaluated. If no such value is found, SQL NULL is returned, similar to the SQL `COALESCE' function.

(sql-coalesce 1) => 1
(sql-coalesce (sql-null)) => SQL NULL
(sql-coalesce (sql-null) 2) => 2
(sql-coalesce #f (sql-null) 1) => #f

This is like Scheme's or macro, instead of treating #f as the only false value, it treats SQL NULL as false and everything else as true.

License

Public Domain

Changelog