From 14005723841b9b410aa5801e1b71ecd4952ee236 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Wed, 10 Jul 2019 03:39:11 +0900 Subject: [PATCH] relational-query: bugfix. fix record width of fromMaybe result. --- .../src/Database/Relational/Projectable.hs | 2 +- relational-query/test/sqlsEq.hs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/relational-query/src/Database/Relational/Projectable.hs b/relational-query/src/Database/Relational/Projectable.hs index 438f3d73..c09c3b85 100644 --- a/relational-query/src/Database/Relational/Projectable.hs +++ b/relational-query/src/Database/Relational/Projectable.hs @@ -300,7 +300,7 @@ negate' = unsafeFlatUniOp $ SQL.word "-" unsafeCastProjectable :: SqlContext c => Record c a -> Record c b -unsafeCastProjectable = unsafeProjectSql' . unsafeShowSql' +unsafeCastProjectable = Syntax.record . Syntax.untypeRecord -- | Number fromIntegral uni-operator. fromIntegral' :: (SqlContext c, Integral a, Num b) diff --git a/relational-query/test/sqlsEq.hs b/relational-query/test/sqlsEq.hs index 4044f34a..e0224363 100644 --- a/relational-query/test/sqlsEq.hs +++ b/relational-query/test/sqlsEq.hs @@ -414,6 +414,15 @@ maybeX = relation $ do return $ fromMaybe (value 1) (a ?! intA0') >< b +maybeY :: Relation () (SetA, SetB) +maybeY = relation $ do + a <- queryMaybe setA + b <- query setB + + wheres $ a ?! strA2' .=. b ! mayStrB1' + + return $ fromMaybe (SetA |$| value 1 |*| value "foo" |*| value "var") a >< b + notX :: Relation () (Maybe Bool) notX = relation $ return $ not' valueFalse @@ -438,6 +447,12 @@ uni = "SELECT ALL CASE WHEN (T0.int_a0 IS NULL) THEN 1 ELSE T0.int_a0 END AS f0, \ \ T1.int_b0 AS f1, T1.may_str_b1 AS f2, T1.str_b2 AS f3 \ \ FROM TEST.set_a T0 RIGHT JOIN TEST.set_b T1 ON (0=0) WHERE (T0.str_a2 = T1.may_str_b1)" + , eqProp "fromMaybe record" maybeY + "SELECT ALL CASE WHEN (T0.int_a0 IS NULL) THEN 1 ELSE T0.int_a0 END AS f0, \ + \ CASE WHEN (T0.int_a0 IS NULL) THEN 'foo' ELSE T0.str_a1 END AS f1, \ + \ CASE WHEN (T0.int_a0 IS NULL) THEN 'var' ELSE T0.str_a2 END AS f2, \ + \ T1.int_b0 AS f3, T1.may_str_b1 AS f4, T1.str_b2 AS f5 \ + \ FROM TEST.set_a T0 RIGHT JOIN TEST.set_b T1 ON (0=0) WHERE (T0.str_a2 = T1.may_str_b1)" , eqProp "not" notX "SELECT ALL (NOT (0=1)) AS f0" , eqProp "exists" existsX