+
+fun equalizeBalances () =
+ ignore (C.dml (getDb ()) ($`UPDATE Balance SET amount = (SELECT SUM(amount) FROM Charge JOIN WebUser ON usr = WebUser.id WHERE bal = Balance.id)`))
+
+fun lookupHostingUsage trn =
+ let
+ val usageFile = TextIO.openIn (Init.scratchDir ^ "/usage/" ^ Int.toString trn)
+
+ fun loop acc =
+ case TextIO.inputLine usageFile of
+ NONE => String.concat (List.rev acc)
+ | SOME line => loop (line :: acc)
+ in
+ SOME (loop [])
+ before TextIO.closeIn usageFile
+ end handle _ => NONE
+
+fun costBase amt =
+ case C.oneRow (getDb ()) ($`SELECT ^(C.realToSql amt) / SUM(shares) FROM WebUserPaying`) of
+ [share] => C.realFromSql share
+ | row => Init.rowError ("Bad costBase result", row)
+
+end