( load "ffs.met" ) ;--------------------- ;N sql.cam - rudimentary SQL-like operations on top of ffs.cam ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This is a CAMILA library for very rudimentary SQL-like operations ; whose semantics are specified on top of ffs.cam. ; This is expected to evolve towards realistic CAMILA animation of a ; formal semantics of mSQL ;E ; ; sqlUpdate(ffs,c1,ue,c2,se) corresponds to the outcome of ; the SQL command "UPDATE ffs SET c1=ue WHERE se(c2)", ; where the update expression ue and the selection predicate se ; are provided as lambda-expressions. ; ( def _ops ( plus _ops ( makeff ( ( quote sqlUpdate ) ( quote ( ( ( SET FF A B ) ( A ) ( FF B B ) ( A ) ( FF A INT ) ) ( SET FF A B ) ) ) ) ) ) ) ;--------------------- ( def sqlUpdate lambda ( ffs c1 ue c2 se ) ( let ( ( st ( set t ( from t ffs ( se ( ap t c2 ) ) ) ) ) ( _ ( princ "[ " ( card st ) " object(s) selected ]\n" ) ) ( rt ( difference ffs st ) ) ( update ( lambda ( t ) ( let ( ( v ( ap t c1 ) ) ) ( plus t ( makeff ( c1 ( ue v ) ) ) ) ) ) ) ) ( union rt ( ( lambda ( _y_ ) ( set ( update _x_ ) ( from _x_ _y_ ) ) ) st ) ) ) ) ;--------------------- ; ; sqlSelect(ffs,cs,c,se) specifies the outcome of ; SQL command " SELECT cs FROM ffs WHERE se(c) ", ; where the selection predicate se is provided as a lambda-expression. ; ( def _ops ( plus _ops ( makeff ( ( quote sqlSelect ) ( quote ( ( ( SET FF A B ) ( SET A ) ( A ) ( FF A INT ) ) ( SET FF A B ) ) ) ) ) ) ) ;--------------------- ( def sqlSelect lambda ( ffs cs c se ) ( let ( ( st ( set t ( from t ffs ( se ( ap t c ) ) ) ) ) ( _ ( princ "[ " ( card st ) " object(s) selected ]\n" ) ) ( project ( lambda ( t ) ( dr t cs ) ) ) ) ( ( lambda ( _y_ ) ( set ( project _x_ ) ( from _x_ _y_ ) ) ) st ) ) ) ;--------------------- ; ; sqlDelete(ffs,c,se) specifies the outcome of ; SQL command "DELETE FROM ffs WHERE se(c) ", ; where the selection predicate se is provided as a lambda-expression. ; ( def _ops ( plus _ops ( makeff ( ( quote sqlDelete ) ( quote ( ( ( SET FF A B ) ( A ) ( FF A INT ) ) ( SET FF A B ) ) ) ) ) ) ) ;--------------------- ( def sqlDelete lambda ( ffs c se ) ( let ( ( st ( set t ( from t ffs ( not ( se ( ap t c ) ) ) ) ) ) ( _ ( princ "[ " ( card ( difference ffs st ) ) " object(s) deleted ]\n" ) ) ) st ) ) ;---------------------