[MLton-commit] r5224

Wesley Terpstra wesley at mlton.org
Fri Feb 16 11:16:45 PST 2007


expose SQLite specific methods
----------------------------------------------------------------------

U   mltonlib/trunk/ca/terpstra/sqlite3/prim.sig
U   mltonlib/trunk/ca/terpstra/sqlite3/prim.sml
U   mltonlib/trunk/ca/terpstra/sqlite3/sql.sig
U   mltonlib/trunk/ca/terpstra/sqlite3/sql.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/ca/terpstra/sqlite3/prim.sig
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3/prim.sig	2007-02-16 17:17:26 UTC (rev 5223)
+++ mltonlib/trunk/ca/terpstra/sqlite3/prim.sig	2007-02-16 19:16:44 UTC (rev 5224)
@@ -84,4 +84,36 @@
       val createFunction:  db * string * (context * value vector -> unit) * int -> unit
       val createCollation: db * string * (string * string -> order) -> unit
       val createAggregate: db * string * (unit -> aggregate) * int -> unit
+      
+      val lastInsertRowid: db -> Int64.int
+      val changes: db -> int
+      val totalChanges: db -> int
+      val getAutocommit: db -> bool
+      
+      datatype access = ALLOW | DENY | IGNORE
+      datatype request =
+         CREATE_INDEX of { index: string, table: string, db: string, temporary: bool }
+       | CREATE_TABLE of { table: string, db: string, temporary: bool }
+       | CREATE_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+       | CREATE_VIEW of { view: string, db: string, temporary: bool }
+       | DROP_INDEX of { index: string, table: string, db: string, temporary: bool }
+       | DROP_TABLE of { table: string, db: string, temporary: bool }
+       | DROP_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+       | DROP_VIEW of { view: string, db: string, temporary: bool }
+       | ALTER_TABLE of { db: string, table: string }
+       | REINDEX of { index: string, db: string }
+       | ANALYZE of { table: string, db: string }
+       | INSERT of { table: string, db: string }
+       | UPDATE of { table: string, column: string, db: string }
+       | DELETE of { table: string, db: string }
+       | TRANSACTION of { operation: string }
+       | SELECT
+       | READ of { table: string, column: string, db: string  }
+       | PRAGMA of { pragma: string, arg: string, db: string option }
+       | ATTACH of { file: string }
+       | DETACH of { db: string }
+       | CREATE_VTABLE of { table: string, module: string, db: string }
+       | DROP_VTABLE of { table: string, module: string, db: string  }
+       | FUNCTION of { function: string }
+      val setAuthorizer: (request -> access) option -> unit
    end

Modified: mltonlib/trunk/ca/terpstra/sqlite3/prim.sml
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3/prim.sml	2007-02-16 17:17:26 UTC (rev 5223)
+++ mltonlib/trunk/ca/terpstra/sqlite3/prim.sml	2007-02-16 19:16:44 UTC (rev 5224)
@@ -80,22 +80,20 @@
 (*    val Presult_text16 = _import "sqlite3_result_text16" : Context.t * WideString.string * int * word -> unit; *)
       val Presult_error  = _import "sqlite3_result_error"  : Context.t * CStr.t * int -> unit;
       
-      (* expiry should just raise an exception... *)
-      
       (* we don't support extended result codes; that would break the case statement *)
-      
       (* the exec & get_table methods are better reimplemented in SML *)
+      (* we don't need silly printf; this is SML! *)
+      (* interrupt is a dangerous thing to add *)
+      (* omitting all experimental features *)
       
-      (* autocommit defaults to on. let's leave it that way! *)
-      
-      (* interrupt would require callback hooks during progress; we have none *)
-      
       val Plibversion = _import "sqlite3_libversion" : unit -> CStr.out;
       
-      (* we don't need silly printf; this is SML! *)
+      val PlastInsertRowid = _import "sqlite3_last_insert_rowid" : DB.t -> Int64.int;
+      val Pchanges = _import "sqlite3_changes" : DB.t -> int;
+      val PtotalChanges = _import "sqlite3_total_changes" : DB.t -> int;
+      val PgetAutocommit = _import "sqlite3_get_autocommit" : DB.t -> int;
+      val PsetAuthorizer = _import "sqlite3_set_authorizer" : DB.t * FnPtr.t * word -> int;
       
-      (* changes and total_changes might be useful to add *)
-      
       (* ---------------------------------------------------------------------------- *)
       
       val version = CStr.toString (Plibversion ())
@@ -376,6 +374,77 @@
                                           Word.fromInt (Buffer.push (colt, f)),
                                           colCallbackPtr))
       
+      val lastInsertRowid = PlastInsertRowid
+      val changes = Pchanges
+      val totalChanges = PtotalChanges
+      fun getAutocommit db = PgetAutocommit db <> 0
+      
+      datatype access = ALLOW | DENY | IGNORE
+      datatype request =
+         CREATE_INDEX of { index: string, table: string, db: string, temporary: bool }
+       | CREATE_TABLE of { table: string, db: string, temporary: bool }
+       | CREATE_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+       | CREATE_VIEW of { view: string, db: string, temporary: bool }
+       | DROP_INDEX of { index: string, table: string, db: string, temporary: bool }
+       | DROP_TABLE of { table: string, db: string, temporary: bool }
+       | DROP_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+       | DROP_VIEW of { view: string, db: string, temporary: bool }
+       | ALTER_TABLE of { db: string, table: string }
+       | REINDEX of { index: string, db: string }
+       | ANALYZE of { table: string, db: string }
+       | INSERT of { table: string, db: string }
+       | UPDATE of { table: string, column: string, db: string }
+       | DELETE of { table: string, db: string }
+       | TRANSACTION of { operation: string }
+       | SELECT
+       | READ of { table: string, column: string, db: string  }
+       | PRAGMA of { pragma: string, arg: string, db: string option }
+       | ATTACH of { file: string }
+       | DETACH of { db: string }
+       | CREATE_VTABLE of { table: string, module: string, db: string }
+       | DROP_VTABLE of { table: string, module: string, db: string  }
+       | FUNCTION of { function: string }
+      
+      fun switchRequest ( 1, a, b, c) = CREATE_INDEX { index = valOf a, table = valOf b, db = valOf c, temporary = false }
+        | switchRequest ( 3, a, b, c) = CREATE_INDEX { index = valOf a, table = valOf b, db = valOf c, temporary = true }
+        | switchRequest ( 2, a, _, c) = CREATE_TABLE { table = valOf a, db = valOf c, temporary = false }
+        | switchRequest ( 4, a, _, c) = CREATE_TABLE { table = valOf a, db = valOf c, temporary = true }
+        | switchRequest ( 7, a, b, c) = CREATE_TRIGGER { trigger = valOf a, table = valOf b, db = valOf c, temporary = false }
+        | switchRequest ( 5, a, b, c) = CREATE_TRIGGER { trigger = valOf a, table = valOf b, db = valOf c, temporary = true }
+        | switchRequest ( 8, a, _, c) = CREATE_VIEW { view = valOf a, db = valOf c, temporary = false }
+        | switchRequest ( 6, a, _, c) = CREATE_VIEW { view = valOf a, db = valOf c, temporary = true }
+        | switchRequest (10, a, b, c) = DROP_INDEX { index = valOf a, table = valOf b, db = valOf c, temporary = false }
+        | switchRequest (12, a, b, c) = DROP_INDEX { index = valOf a, table = valOf b, db = valOf c, temporary = true }
+        | switchRequest (11, a, _, c) = DROP_TABLE { table = valOf a, db = valOf c, temporary = false }
+        | switchRequest (13, a, _, c) = DROP_TABLE { table = valOf a, db = valOf c, temporary = true }
+        | switchRequest (16, a, b, c) = DROP_TRIGGER { trigger = valOf a, table = valOf b, db = valOf c, temporary = false }
+        | switchRequest (14, a, b, c) = DROP_TRIGGER { trigger = valOf a, table = valOf b, db = valOf c, temporary = true }
+        | switchRequest (17, a, _, c) = DROP_VIEW { view = valOf a, db = valOf c, temporary = false }
+        | switchRequest (15, a, _, c) = DROP_VIEW { view = valOf a, db = valOf c, temporary = true }
+        | switchRequest (26, a, b, _) = ALTER_TABLE { db = valOf a, table = valOf b }
+        | switchRequest (27, a, _, c) = REINDEX { index = valOf a, db = valOf c }
+        | switchRequest (28, a, _, c) = ANALYZE { table = valOf a, db = valOf c }
+        | switchRequest (18, a, _, c) = INSERT { table = valOf a, db = valOf c }
+        | switchRequest (23, a, b, c) = UPDATE { table = valOf a, column = valOf b, db = valOf c }
+        | switchRequest ( 9, a, _, c) = DELETE { table = valOf a, db = valOf c }
+        | switchRequest (22, a, _, _) = TRANSACTION { operation = valOf a }
+        | switchRequest (21, _, _, _) = SELECT
+        | switchRequest (20, a, b, c) = READ { table = valOf a, column = valOf b, db = valOf c }
+        | switchRequest (19, a, b, c) = PRAGMA { pragma = valOf a, arg = valOf b, db = c }
+        | switchRequest (24, a, _, _) = ATTACH { file = valOf a }
+        | switchRequest (25, a, _, _) = DETACH { db = valOf a }
+        | switchRequest (29, a, b, c) = CREATE_VTABLE { table = valOf a, module = valOf b, db = valOf c }
+        | switchRequest (30, a, b, c) = DROP_VTABLE { table = valOf a, module = valOf b, db = valOf c }
+        | switchRequest (31, _, b, _) = FUNCTION { function = valOf b }
+        | switchRequest (_, _, _, _) = raise Error "SQLite requested impossible authorization code"
+      fun parseRequest (code, a, b, c, d) =
+         switchRequest (code, CStr.toStringOpt a, 
+                              CStr.toStringOpt b, 
+                              CStr.toStringOpt c)
+         handle Option => raise Error "SQLite did not provided expected authorization paramater"
+      
+      fun setAuthorizer _ = ()
+      
       type db = DB.t
       type query = Query.t
       type value = Value.t

Modified: mltonlib/trunk/ca/terpstra/sqlite3/sql.sig
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3/sql.sig	2007-02-16 17:17:26 UTC (rev 5223)
+++ mltonlib/trunk/ca/terpstra/sqlite3/sql.sig	2007-02-16 19:16:44 UTC (rev 5224)
@@ -183,10 +183,56 @@
             val iAZ: (Int64.int,          'a, 'b, 'c) inputA
             val iAS: (string,             'a, 'b, 'c) inputA
             val iAX: (storage,            'a, 'b, 'c) inputA
+            
+            (* get/set auxdata? could be useful *)
          end
       
       (* SQL.Error exceptions in callbacks are propogated ok. Others not. *)
       val registerFunction:  db * string * Function.scalar -> unit
       val registerAggregate: db * string * Function.aggregate -> unit
       val registerCollation: db * string * (string * string -> order) -> unit
+      
+      (* SQLite specific methods; see its documentation *)
+      structure SQLite:
+         sig
+            val lastInsertRowId: db -> Int64.int
+            val changes: db -> int
+            val totalChanges: db -> int
+            val transactionActive: db -> bool
+            
+            datatype access = ALLOW | DENY | IGNORE
+            datatype request =
+               CREATE_INDEX of { index: string, table: string, db: string, temporary: bool }
+             | CREATE_TABLE of { table: string, db: string, temporary: bool }
+             | CREATE_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+             | CREATE_VIEW of { view: string, db: string, temporary: bool }
+             | DROP_INDEX of { index: string, table: string, db: string, temporary: bool }
+             | DROP_TABLE of { table: string, db: string, temporary: bool }
+             | DROP_TRIGGER of { trigger: string, table: string, db: string, temporary: bool }
+             | DROP_VIEW of { view: string, db: string, temporary: bool }
+             | ALTER_TABLE of { db: string, table: string }
+             | REINDEX of { index: string, db: string }
+             | ANALYZE of { table: string, db: string }
+             | INSERT of { table: string, db: string }
+             | UPDATE of { table: string, column: string, db: string }
+             | DELETE of { table: string, db: string }
+             | TRANSACTION of { operation: string }
+             | SELECT
+             | READ of { table: string, column: string, db: string  }
+             | PRAGMA of { pragma: string, arg: string, db: string option }
+             | ATTACH of { file: string }
+             | DETACH of { db: string }
+             | CREATE_VTABLE of { table: string, module: string, db: string }
+             | DROP_VTABLE of { table: string, module: string, db: string  }
+             | FUNCTION of { function: string }
+            val setAuthorizer: (request -> access) option -> unit
+            
+            (* All of these are omitted from the SML binding: *)
+            (* fun interrupt: db -> unit *) (* too dangerous to expose IMO *)
+            (* trace? who cares -- use debug.sml *)
+            (* update hook? who cares -- use a trigger+callback *)
+            (* commit/rollback hook? who cares, wrap them in SML *)
+            (* SQLite memory/thread management is explicitly NOT exposed *)
+            (* extension support omitted as it is experimental *)
+         end
    end

Modified: mltonlib/trunk/ca/terpstra/sqlite3/sql.sml
===================================================================
--- mltonlib/trunk/ca/terpstra/sqlite3/sql.sml	2007-02-16 17:17:26 UTC (rev 5223)
+++ mltonlib/trunk/ca/terpstra/sqlite3/sql.sml	2007-02-16 19:16:44 UTC (rev 5224)
@@ -99,4 +99,16 @@
       fun registerFunction  (db, s, (f, i)) = Prim.createFunction (db, s, f, i)
       fun registerAggregate (db, s, (a, i)) = Prim.createAggregate(db, s, a, i)
       val registerCollation = Prim.createCollation
+      
+      structure SQLite = 
+         struct
+            val lastInsertRowId = Prim.lastInsertRowid
+            val changes = Prim.changes
+            val totalChanges = Prim.totalChanges
+            val transactionActive = not o Prim.getAutocommit
+            
+            datatype access = datatype Prim.access
+            datatype request = datatype Prim.request
+            val setAuthorizer = Prim.setAuthorizer
+         end
    end




More information about the MLton-commit mailing list