Note: This is taken from the Chicken Wiki, where a more recent version could be available.
A library for using the SQLite database engine.
This extension is obsolete. Consider using sqlite3 instead.
Original code by Lars Rustemeier, with modifications by felix winkelmann.
This extension provides an interface for the SQLite relational database. Any errors triggered by the database system signal a composite condition of the exn and sqlite kinds.
<procedure>(sqlite:open FILENAME [BOOL])</procedure>
Opens the database FILENAME and returns a foreign pointer object representing the database in memory. If the file does not exist and the optional flag BOOL is false, a new database is created, otherwise an error is signaled.
Closes the database represented by DB.
<procedure>(sqlite:execute DB QUERY)</procedure>
Executes the SQL command in the string QUERY for the database DB and returns a list of all returned rows, where each row is a vector containing strings (one for each column).
<procedure>(sqlite:iterator DB QUERY)</procedure>
Returns an iterator object from the database DB and the SQL command passed in the string QUERY.
Returns a vector containing the columns of the next result row from the query represented by ITERATOR. If no more rows are available, #f is returned.
Frees up resources allocated by ITERATOR.
<procedure>(sqlite:call-with-query DB QUERY PROC)</procedure>
Calls the procedure PROC for each result-row returned by the SQL command QUERY with a vector containing the columns.
Returns #t if X is an iterator object or #f otherwise.
Create a table of number pairs:
<example> <init>(use sqlite)</init> <expr> (define db (sqlite:open "foo.db"))
(sqlite:execute db "CREATE TABLE t1(a int, b int);")
(lambda (i) (sqlite:execute db (sprintf "INSERT INTO t1 VALUES(~A, ~A);" i (* i i)) ) ) (iota 10) )
(sqlite:execute db "SELECT * FROM t1;") ; returns ; (#("0" "0") #("1" "1") #("2" "4") #("3" "9") #("4" "16") #("5" "25") #("6" "36") #("7" "49") #("8" "64") #("9" "81"))
(sqlite:call-with-query db "SELECT * FROM t1;" (compose print car vector→list)) ; prints: ; 0 ; 1 ; 4 ; 9 ; 16 ; 25 ; 36 ; 49 ; 64 ; 81
(sqlite:close db) ; cleaning up is always good. </expr> </example>
Copyright (c) 2000-2003, Lars Rustemeier and Felix L. Winkelmann 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 its 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 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICESLOSS OF USE, DATA, OR PROFITSOR 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.