@@ -7,6 +7,7 @@ import ProjectM36.Tuple
77import ProjectM36.TupleSet
88import ProjectM36.Error
99import ProjectM36.DatabaseContext
10+import ProjectM36.AtomFunctions.Primitive
1011import ProjectM36.DataTypes.Either
1112import ProjectM36.DataTypes.Primitive
1213import ProjectM36.DateExamples
@@ -81,6 +82,12 @@ main = do
8182 byteStringAttributes = A.attributesFromList [Attribute "y" byteStringAtomType]
8283 groupCountAttrs = A.attributesFromList [Attribute "z" intAtomType]
8384 minMaxAttrs = A.attributesFromList [Attribute "s#" textAtomType, Attribute "z" intAtomType]
85+ updateParisPlus10 = relMap (\tuple -> do
86+ statusAtom <- atomForAttributeName "status" tuple
87+ cityAtom <- atomForAttributeName "city" tuple
88+ if cityAtom == textAtom "Paris" then
89+ Right $ updateTupleWithAtoms (M.singleton "status" (intAtom ((castInt statusAtom) + 10))) tuple
90+ else Right tuple) suppliersRel
8491 dateExampleRelTests = [("x:=s where true", Right suppliersRel),
8592 ("x:=s where city = \"London\"", restrict (\tuple -> atomForAttributeName "city" tuple == (Right $ textAtom "London")) suppliersRel),
8693 ("x:=s where false", Right $ Relation (attributes suppliersRel) emptyTupleSet),
@@ -89,8 +96,9 @@ main = do
8996 ("x:=s minus (s where status=20)", mkRelationFromList (attributes suppliersRel) [[textAtom "S2", textAtom "Jones", intAtom 10, textAtom "Paris"], [textAtom "S3", textAtom "Blake", intAtom 30, textAtom "Paris"], [textAtom "S5", textAtom "Adams", intAtom 30, textAtom "Athens"]]),
9097 --atom function tests
9198 ("x:=((s : {status2 := add(10,@status)}) where status2=add(10,@status)){city,s#,sname,status}", Right suppliersRel),
92− ("x:=s; update x where sname=\"Blake\" (city:=\"Boston\")", relMap (\tuple -> if atomForAttributeName "sname" tuple == (Right $ textAtom "Blake") then updateTuple (M.singleton "city" (textAtom "Boston")) tuple else tuple) suppliersRel),
9399 ("x:=relation{tuple{a 5}} : {b:=s}", mkRelation extendTestAttributes (RelationTupleSet [mkRelationTuple extendTestAttributes (V.fromList [intAtom 5, Atom suppliersRel])])),
100+ ("x:=s; update x where sname=\"Blake\" (city:=\"Boston\")", relMap (\tuple -> if atomForAttributeName "sname" tuple == (Right $ textAtom "Blake") then Right $ updateTupleWithAtoms (M.singleton "city" (textAtom "Boston")) tuple else Right tuple) suppliersRel),
101+ ("x:=s; update x where city=\"Paris\" (status:=add(@status,10))", updateParisPlus10),
94102 --relatom function tests
95103 ("x:=((s group ({city} as y)):{z:=count(@y)}){z}", mkRelation groupCountAttrs (RelationTupleSet [mkRelationTuple groupCountAttrs (V.singleton $ intAtom 1)])),
96104 ("x:=(sp group ({s#} as y)) ungroup y", Right supplierProductsRel),
@@ -116,7 +124,7 @@ main = do
116124 ("x:=relation{tuple{a Just 3}}", mkRelationFromList simpleMaybeIntAttributes [[ConstructedAtom "Just" maybeIntAtomType [intAtom 3]]]),
117125 --test Either Int Text
118126 ("x:=relation{tuple{a Left 3}}", Left (TypeConstructorTypeVarsMismatch (S.fromList ["a","b"]) (S.fromList ["a"]))), -- Left 3, alone is not enough information to imply the type
119− ("x:=relation{a Either Int Text}{tuple{a Left 3}}", mkRelationFromList simpleEitherIntTextAttributes [[ConstructedAtom "Left" (eitherAtomType intAtomType textAtomType) [intAtom 3]]])
127+ ("x:=relation{a Either Int Text}{tuple{a Left 3}}", mkRelationFromList simpleEitherIntTextAttributes [[ConstructedAtom "Left" (eitherAtomType intAtomType textAtomType) [intAtom 3]]])
120128 ]
121129
122130assertTutdEqual :: DatabaseContext -> Either RelationalError Relation -> String -> Assertion