on dev help sign in
UPDATE test and fix
3cf8a5bEitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+3−3
@@ -736,10 +736,10 @@ instance {-# OVERLAPPABLE #-}
736UPDATE statements
736UPDATE statements
737-----------------------------------------}
737-----------------------------------------}
738
738
739−set :: g x -> (Maybe :.: g) x
739+set :: Expression params tables x -> (Maybe :.: Expression params tables) x
740set = Comp . Just
740set = Comp . Just
741
741
742−same :: (Maybe :.: g) x
742+same :: (Maybe :.: Expression params tables) x
743same = Comp Nothing
743same = Comp Nothing
744
744
745update
745update
@@ -754,7 +754,7 @@ update (Alias table) columns where' = UnsafeStatement $ mconcat
754 , " SET "
754 , " SET "
755 , ByteString.intercalate ", " . catMaybes . hcollapse $
755 , ByteString.intercalate ", " . catMaybes . hcollapse $
756 hmap (K . renderSet) columns
756 hmap (K . renderSet) columns
757− , " WHERE ", renderExpression where'
757+ , " WHERE ", renderExpression where', ";"
758 ] where
758 ] where
759 renderSet
759 renderSet
760 :: Aliased (Maybe :.: Expression params tables) column
760 :: Aliased (Maybe :.: Expression params tables) column
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+6
@@ -75,6 +75,12 @@ spec = do
75 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
75 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
76 statement `shouldRenderAs`
76 statement `shouldRenderAs`
77 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
77 "INSERT INTO table1 (col1, col2) VALUES (2, 4);"
78+ it "correctly render simple UPDATEs" $ do
79+ let
80+ statement :: Statement '[] '[] Tables Tables
81+ statement = update #table1 (set 2 `As` #col1 :* same `As` #col2 :* Nil) true
82+ statement `shouldRenderAs`
83+ "UPDATE table1 SET col1 = 2 WHERE TRUE;"
78 it "should be safe against SQL injection in literal text" $ do
84 it "should be safe against SQL injection in literal text" $ do
79 let
85 let
80 statement :: Statement '[] '[] StudentsTable StudentsTable
86 statement :: Statement '[] '[] StudentsTable StudentsTable