X-Git-Url: http://git.hcoop.net/hcoop/zz_old/portal.git/blobdiff_plain/8023de7bf992fe7be73256cece7ba09e320e98f8..da3f3cbcf301e74d490e9ced63f09d45fedb84c1:/requestH.sml diff --git a/requestH.sml b/requestH.sml index f6bb4af..dd4e423 100644 --- a/requestH.sml +++ b/requestH.sml @@ -11,7 +11,8 @@ datatype status = | INSTALLED | REJECTED -type request = { id : int, usr : int, node : int, data : string, msg : string, status : status, stamp : C.timestamp } +type request = { id : int, usr : int, node : int, data : string, msg : string, status : status, + stamp : C.timestamp, cstamp : C.timestamp option } val statusFromInt = fn 0 => NEW @@ -27,10 +28,11 @@ val statusToInt = fun statusFromSql v = statusFromInt (C.intFromSql v) fun statusToSql s = C.intToSql (statusToInt s) -fun mkRow [id, usr, node, data, msg, status, stamp] = +fun mkRow [id, usr, node, data, msg, status, stamp, cstamp] = {id = C.intFromSql id, usr = C.intFromSql usr, node = C.intFromSql node, data = C.stringFromSql data, - msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp} + msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp, + cstamp = if C.isNull cstamp then NONE else SOME (C.timestampFromSql cstamp)} | mkRow r = rowError ("APT request", r) fun add {usr, node, data, msg} = @@ -38,9 +40,9 @@ fun add {usr, node, data, msg} = val db = getDb () val id = nextSeq (db, seq) in - C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp) + C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp, cstamp) VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.intToSql node), ^(C.stringToSql data), ^(C.stringToSql msg), - 0, CURRENT_TIMESTAMP)`); + 0, CURRENT_TIMESTAMP, NULL)`); id end @@ -48,6 +50,11 @@ fun modify (req : request) = let val db = getDb () in + if #status req <> NEW then + ignore (C.dml db ($`UPDATE ^table SET cstamp = CURRENT_TIMESTAMP WHERE id = ^(C.intToSql (#id req))`)) + else + (); + ignore (C.dml db ($`UPDATE ^table SET usr = ^(C.intToSql (#usr req)), data = ^(C.stringToSql (#data req)), node = ^(C.intToSql (#node req)), @@ -59,7 +66,7 @@ fun delete id = ignore (C.dml (getDb ()) ($`DELETE FROM ^table WHERE id = ^(C.intToSql id)`)) fun lookup id = - case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp + case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp, cstamp FROM ^table WHERE id = ^(C.intToSql id)`) of SOME row => mkRow row @@ -69,12 +76,12 @@ fun mkRow' (name :: rest) = (C.stringFromSql name, mkRow rest) | mkRow' r = rowError ("Apt.request'", r) fun list () = - C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp + C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp FROM ^table JOIN WebUser ON usr = WebUser.id ORDER BY stamp DESC`) fun listOpen () = - C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp + C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp FROM ^table JOIN WebUser ON usr = WebUser.id WHERE status = 0 ORDER BY stamp DESC`)