signature SQLITE structure SQLite : SQLITE
The SQLite structure provides an interface to a database engine using a simple flat-file format. See the SQLite web page for further details.
import structure SQLite from "x-alice:/lib/sqlite/SQLite"
signature SQLITE = sig type db exception SQLError of string exception TypeError of string val opendb : string -> db val closedb : db -> unit val query : db * string -> 'a[...] list end
Opens the SQLite database stored in file fileName.
Closes the SQLite database referened through db.
Runs the SQL query sql on database db. The resulting rows are returned as a lazy list. Each row is returned as a tuple or record of strings, integers, or reals, or the corresponding option types.
The return type must match the result of your query: It must be either a tuple of the right size or a record with the same labels as the column names.
Assuming a database of users with the following layout:table users: lastname (text), firstname (text), uid (int), password (text)
the following queries would be legal:
val users : {lastname:string, firstname:string, uid:int option} list = query (db, "SELECT lastname,firstname,uid FROM users") val [pwd:string] = query (db, "SELECT password FROM users WHERE uid=42") val all : (string * string * int * string) list = = query (db, "SELECT * FROM users")
The special null value in a field is converted to the empty string or 0 if the field type is a plain type, or to NONE if an option type was given.