Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NAME PYTHON-NOTATION HASKELL-NOTATION
- -- selektion: S[a.name != b.name]( ... ) S String Rel
- -- projektion: P[a.name, b.budget]( ... ) P String Rel
- -- join: J[a.budget = b.budget, proj]( RELA, RELB ) J String String Rel Rel
- -- rename: R[budget->geld, name->zeug]( ... ) R [(String,String)] Rel
- -- from: F[a]( ... ) F String Rel
- -- T[""]() T String
- --
- -- Beispiel: (P "a.name,a.einnahmen,b.alter,CONCAT(b.vname, b.nname)" (J "a.angestellter = b.id" "a.name, a.einnahmen, b.alter, b.vname, b.nname" (T "a") (T "b")))
- data Rel = T String | F String Rel | R [(String,String)] Rel | J String String Rel Rel | P String Rel | S String Rel deriving Show
- render rel = "SELECT * FROM " ++ (render' rel)
- render' (T a) = a
- render' (F new rel) = (render' rel) ++ " AS " ++ new
- render' (R a rel) = "(SELECT " ++ (rename a) ++ " FROM " ++ (render' rel) ++ ")"
- render' (J cond sel a b) = "(SELECT " ++ sel ++ " FROM " ++ (render' a) ++ ", " ++ (render' b) ++ " WHERE " ++ cond ++ ")"
- render' (P sel rel) = "(SELECT " ++ sel ++ " FROM " ++ (render' rel) ++ ")"
- render' (S cond rel) = "(SELECT * FROM " ++ (render' rel) ++ " WHERE " ++ cond ++ ")"
- rename [] = ""
- rename ((o,n):[]) = o ++ " AS " ++ n
- rename ((o,n):rs) = o ++ " AS " ++ n ++ ", " ++ (rename rs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement