This is sql.egg.info, produced by makeinfo version 4.7 from
eggdoc-output.texi.

INFO-DIR-SECTION The Algorithmic Language Scheme
START-INFO-DIR-ENTRY
* sql.egg: (sql.egg).		A small scheme library for constructing SQL queries.
END-INFO-DIR-ENTRY


File: sql.egg.info,  Node: Top,  Next: About this egg,  Up: (dir)

sql egg
*******

A small scheme library for constructing SQL queries.

Written by Hans Bulfone (http://www.nil.at/)

   This manual corresponds to version 1.0 of the sql extension library
for Chicken Scheme.

* Menu:

* About this egg::
* Documentation::
* Examples::
* License::
* Index::


File: sql.egg.info,  Node: About this egg,  Next: Documentation,  Prev: Top,  Up: Top

1 About this egg
****************

* Menu:

* Version history::
* Usage::


File: sql.egg.info,  Node: Version history,  Next: Usage,  Up: About this egg

1.1 Version history
===================

`1.0'
     Initial release

`1.1'
     Documentation, some fixes/features


File: sql.egg.info,  Node: Usage,  Prev: Version history,  Up: About this egg

1.2 Usage
=========

Load this egg like so:

   `(require-extension sql)'


File: sql.egg.info,  Node: Documentation,  Next: Examples,  Prev: About this egg,  Up: Top

2 Documentation
***************

* Menu:

* Introduction::
* Notes::
* NULL object::
* Quoting strings::
* Transforming S-expressions to SQL::
* Utility functions for generating common SQL queries::


File: sql.egg.info,  Node: Introduction,  Next: Notes,  Up: Documentation

2.1 Introduction
================

This extension provides procedures for constructing SQL queries from
S-expressions.

   No support for actually accessing a database is provided so this
extension is meant to be used together with other extensions like
`postgresql' or `mysql'.


File: sql.egg.info,  Node: Notes,  Next: NULL object,  Prev: Introduction,  Up: Documentation

2.2 Notes
=========

   * sql.egg is incomplete. It mostly contains what I've needed so far
     :)

   * sql.egg has only been used with PostgreSQL so far.



File: sql.egg.info,  Node: NULL object,  Next: Quoting strings,  Prev: Notes,  Up: Documentation

2.3 NULL object
===============

 -- procedure: sql:null
          (sql:null)

     Returns the NULL object

 -- procedure: sql:null?
          (sql:null? X)

     Returns `#t' if `X' is the NULL object, `#f' otherwise.

   These functions can be redefined to recognize the NULL object of the
database that is in use, for example:


(require-extension postgresql sql)
(define (sql:null) pg:sql-null-object)
(define sql:null? pg:sql-null-object?)

   `'()' is also recognized as NULL by the sql egg, no matter how
`sql:null?' is defined.


File: sql.egg.info,  Node: Quoting strings,  Next: Transforming S-expressions to SQL,  Prev: NULL object,  Up: Documentation

2.4 Quoting strings
===================

 -- procedure: sql:quote
          (sql:quote S)

     Returns a copy of `S' with `'' replaced by `''' and `\' replaced
     by `\\'.


File: sql.egg.info,  Node: Transforming S-expressions to SQL,  Next: Utility functions for generating common SQL queries,  Prev: Quoting strings,  Up: Documentation

2.5 Transforming S-expressions to SQL
=====================================

 -- procedure: sql:transform
          (sql:transform EXPR)

     Returns the S-expression `EXPR' converted to SQL syntax as a list.
     The following transformation rules exist:

     `(and)'              ->                   `TRUE'
     `(and x ...)'        ->                   `(x AND ...)'
     `(or)'               ->                   `FALSE'
     `(or x ...)'         ->                   `(x OR ...)'
     `(not x)'            ->                   `(NOT x)'
     `(null? x)'          ->                   `(x IS NULL)'
     `(= x _(sql:null)_)' ->                   `(x IS NULL)'
     `(_binary-operator_  ->                   `(x1 _op_ x2)'
     x1 x2)'                                   
     `(_n-ary-operator_   ->                   `(x _op_ ...)'
     x ...)'                                   
     `(-> type x)'        ->                   `(x::type)'
     `(as x alias)'       ->                   `x AS alias'
     `(asc x)'            ->                   `x ASC'
     `(desc x)'           ->                   `x DESC'
     `(extract f s)'      ->                   `EXTRACT(f FROM s)'
     `(substring s start  ->                   `SUBSTRING(s FROM
     count)'                                   start FOR count)'
     `(string-append x    ->                   `(x || ...)'
     ...)'                                     
     `(bitwise-and x      ->                   `(x & ...)'
     ...)'                                     
     `(bitwise-ior x      ->                   `(x | ...)'
     ...)'                                     
     `(bitwise-xor x      ->                   `(x # ...)'
     ...)'                                     
     `(bitwise-not x)'    ->                   `(~x)'
     `(join/on type a b   ->                   `(a type JOIN b ON
     on)'                                      on)'
     `(join/using type a  ->                   `(a type JOIN b
     b (using1 u2 ...))'                       USING
                                               (using1,u2,...))'
     `(join/natural type  ->                   `(a NATURAL type
     a b)'                                     JOIN b)'
     `(func x ...)'       ->                   `func(x,...)'
     _string_             ->                   `'(quoted-string)''
     `#t'                 ->                   `TRUE'
     `#f'                 ->                   `FALSE'
     `_(sql:null)_'       ->                   `NULL'
     `()'                 ->                   `NULL'

 -- procedure: sql:list->string
          (sql:list->string L)

     Returns the elements of `L' concatenated as a string.

 -- parameter: sql:binary-operators
     A list of binary operators recognized by `sql:transform', by
     default `'(< > <= >= = <> != << >>)'.

 -- parameter: sql:n-ary-operators
     A list of n-ary operators recognized by `sql:transform', by
     default `'(+ - * /)'.


File: sql.egg.info,  Node: Utility functions for generating common SQL queries,  Prev: Transforming S-expressions to SQL,  Up: Documentation

2.6 Utility functions for generating common SQL queries
=======================================================

 -- procedure: sql:select
          (sql:select WHAT FROM WHERE #!optional (ORDER-BY #f))

     Returns a SQL SELECT-query as a string. `WHAT' and `FROM' are
     lists of S-expressions. `WHERE' is an S-expression or `#f'.
     `ORDER-BY', if given, is a list of S-expressions.

 -- procedure: sql:insert
          (sql:insert TABLE VALUES)

     Returns a SQL INSERT-query as a string. `TABLE' is a string or
     symbol naming the table to receive the data. `VALUES' is an alist
     mapping column names (symbols) to values (S-expressions)

 -- procedure: sql:delete
          (sql:delete TABLE WHERE)

     Returns a SQL DELETE-query as a string. `TABLE' is a string or
     symbol naming the table to modify. `WHERE' is either an
     S-expression specifying the rows to delete or `#f'.

 -- procedure: sql:update
          (sql:update TABLE UPDATES WHERE)

     Returns a SQL UPDATE-query as a string. `TABLE' is a string or
     symbol naming the table to modify. `UPDATES' is an alist mapping
     column names (symbols) to values (S-expressions), `WHERE' is
     either an S-expression specifying the rows to modify or `#f'.


File: sql.egg.info,  Node: Examples,  Next: License,  Prev: Documentation,  Up: Top

3 Examples
**********


$ csi
 )   ___
(__/_____) /)   ,    /)
  /       (/      _ (/_   _ __
 /        / )__(_(__/(___(/_/ (_
(______)
Version 2, Build 3 - linux-unix-gnu-x86 - [ libffi dload ptables ]
(c)2000-2005 Felix L. Winkelmann
#;1> (use sql)
; loading /usr/lib/chicken/sql.so ...
#;2> (define (get-some-data) "some-data")
#;3> (sql:insert "foobar" `((timestamp . (now)) (data . ,(get-some-data)) (quux . 5)))
"INSERT INTO foobar(timestamp,data,quux) VALUES(now(),'some-data',5)"
#;4> (sql:update "foobar" `((timestamp . (+ timestamp 5))) `(< quux 10))
"UPDATE foobar SET timestamp=(timestamp+5) WHERE (quux<10)"
#;5> (sql:select '(f.data quux.name) '((as foobar f) quux) '(and (= f.quux quux.bla) (>= f.timestamp (- (now) (-> interval "5")))))
"SELECT f.data,quux.name FROM foobar AS f,quux WHERE ((f.quux=quux.bla) AND (f.timestamp>=(now()-('5'::interval))))"
#;6>


File: sql.egg.info,  Node: License,  Next: Index,  Prev: Examples,  Up: Top

4 License
*********


Copyright (c) 2006, Hans Bulfone
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of his contributors may
      be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


File: sql.egg.info,  Node: Index,  Prev: License,  Up: Top

Index
*****

 [index ]
* Menu:

* sql:binary-operators:                  Transforming S-expressions to SQL.
                                                               (line 59)
* sql:delete:                            Utility functions for generating common SQL queries.
                                                               (line 21)
* sql:insert:                            Utility functions for generating common SQL queries.
                                                               (line 14)
* sql:list->string:                      Transforming S-expressions to SQL.
                                                               (line 54)
* sql:n-ary-operators:                   Transforming S-expressions to SQL.
                                                               (line 63)
* sql:null:                              NULL object.          (line  7)
* sql:null?:                             NULL object.          (line 12)
* sql:quote:                             Quoting strings.      (line  7)
* sql:select:                            Utility functions for generating common SQL queries.
                                                               (line  7)
* sql:transform:                         Transforming S-expressions to SQL.
                                                               (line  7)
* sql:update:                            Utility functions for generating common SQL queries.
                                                               (line 28)



Tag Table:
Node: Top247
Node: About this egg607
Node: Version history771
Node: Usage968
Node: Documentation1124
Node: Introduction1418
Node: Notes1775
Node: NULL object2031
Node: Quoting strings2669
Node: Transforming S-expressions to SQL2973
Node: Utility functions for generating common SQL queries6101
Node: Examples7493
Node: License8456
Node: Index10067

End Tag Table
