[MLton-commit] r5251
Wesley Terpstra
wesley at mlton.org
Sat Feb 17 18:02:24 PST 2007
make the demo easier to read
----------------------------------------------------------------------
U mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.mlb
U mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.sml
----------------------------------------------------------------------
Modified: mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.mlb
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.mlb 2007-02-18 01:56:35 UTC (rev 5250)
+++ mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.mlb 2007-02-18 02:02:23 UTC (rev 5251)
@@ -12,6 +12,5 @@
** $Id$
*)
$(SML_LIB)/basis/basis.mlb
-$(SML_LIB)/basis/mlton.mlb
sqlite.mlb
demo.sml
Modified: mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.sml
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.sml 2007-02-18 01:56:35 UTC (rev 5250)
+++ mltonlib/trunk/ca/terpstra/sqlite3-sml/demo.sml 2007-02-18 02:02:23 UTC (rev 5251)
@@ -13,15 +13,13 @@
*)
val () = print ("SQLite version: " ^ SQL.version ^ "\n")
-fun die x = (
- print ("Caught exception: " ^ x ^ "\n");
- OS.Process.exit OS.Process.failure)
+fun die s = (print ("Failed: " ^ s ^ "\n"); OS.Process.exit OS.Process.failure)
-val (dbname, query) = case CommandLine.arguments () of
- [x, y] => (x, y)
- | _ => die "Expecting: <database name> <query>\n"
+val (dbname, query) = case CommandLine.arguments () of [x, y] => (x, y)
+ | _ => die "Expecting: <database name> <query>\n"
val db = SQL.openDB dbname handle SQL.Error x => die x
+(* Bind a number of (not so) interesting SQL functions *)
local
open SQL.Function
in
@@ -38,6 +36,10 @@
val () = SQL.registerAggregate (db, "sum2", aggrS iI iZ $ sum2)
end
+(* Create the base table needed for Q1 *)
+val () = SQL.simpleExec (db, "create table peanuts (x text, y integer);")
+
+(* Create some queries that have input / output parameters *)
local
open SQL.Query
in
@@ -48,6 +50,9 @@
handle SQL.Error x => die x
end
+(* Authorization functions at the moment are not safe to use.
+ * A future SQLite3 library may resolve this problem.
+ *)
(*
local
open SQL.SQLite
@@ -62,14 +67,7 @@
fun dumpP (s & i) = print (s ^ " " ^ Int.toString i ^ "\n")
fun dumpV v = (Vector.app (fn s => print (s ^ " ")) v; print "\n")
+(* Run the prepared queries and print the results *)
val () = SQL.app dumpP Q1 (4 & "hi") handle SQL.Error x => die x
val () = SQL.app dumpV Q2 () handle SQL.Error x => die x
-
-val pq = SQL.SQLite.preparedQueries
-val () = print ("Prepared queries: " ^ Int.toString (pq db) ^ "\n")
-val () = print "Running garbage collector... "
-val () = MLton.GC.collect ()
-val () = print "done\n"
-val () = print ("Prepared queries: " ^ Int.toString (pq db) ^ "\n")
-
val () = SQL.closeDB db handle SQL.Error x => die x
More information about the MLton-commit
mailing list