on dev help sign in
UPDATE test and fix
commit3cf8a5bff7545cc9c83b9bc50c29bfc39f6e337f authorEitan Chatav <eitan.chatav@gmail.com> dateTue 18 Jul 2017, 10:37 (9 years ago) parent4c6c3b4
2 files changed+9−3
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+3−3 squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+6
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+3−3
@@ -736,10 +736,10 @@ instance {-# OVERLAPPABLE #-}
736736UPDATE statements
737737-----------------------------------------}
738738
739−set :: g x -> (Maybe :.: g) x
739+set :: Expression params tables x -> (Maybe :.: Expression params tables) x
740740set = Comp . Just
741741
742−same :: (Maybe :.: g) x
742+same :: (Maybe :.: Expression params tables) x
743743same = Comp Nothing
744744
745745update
@@ -754,7 +754,7 @@ update (Alias table) columns where' = UnsafeStatement $ mconcat
754754 , " SET "
755755 , ByteString.intercalate ", " . catMaybes . hcollapse $
756756 hmap (K . renderSet) columns
757− , " WHERE ", renderExpression where'
757+ , " WHERE ", renderExpression where', ";"
758758 ] where
759759 renderSet
760760 :: Aliased (Maybe :.: Expression params tables) column
squeel-postgresql/test/Squeel/PostgreSQL/StatementSpec.hs+6
@@ -75,6 +75,12 @@ spec = do
7575 statement = insertInto #table1 $ 2 `As` #col1 :* 4 `As` #col2 :* Nil
7676 statement `shouldRenderAs`
7777 "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;"
7884 it "should be safe against SQL injection in literal text" $ do
7985 let
8086 statement :: Statement '[] '[] StudentsTable StudentsTable