diff --git a/IHP/IDE/Data/Controller.hs b/IHP/IDE/Data/Controller.hs index 4285a9690..c39094b97 100644 --- a/IHP/IDE/Data/Controller.hs +++ b/IHP/IDE/Data/Controller.hs @@ -73,7 +73,7 @@ instance Controller DataController where tableNames <- fetchTableNames connection let tableName = param "tableName" tableCols <- fetchTableCols connection tableName - let values :: [Text] = map (\col -> quoteIfLiteral (param @Bool (cs (get #columnName col) <> "_")) (param @Text (cs (get #columnName col)))) tableCols + let values :: [Text] = map (\col -> parseValues (param @Bool (cs (get #columnName col) <> "_")) (param @Bool (cs (get #columnName col) <> "-isBoolean")) (param @Text (cs (get #columnName col)))) tableCols let query = "INSERT INTO " <> tableName <> " VALUES (" <> intercalate "," values <> ")" PG.execute_ connection (PG.Query . cs $! query) PG.close connection @@ -100,7 +100,7 @@ instance Controller DataController where tableCols <- fetchTableCols connection tableName primaryKeyFields <- tablePrimaryKeyFields connection tableName - let values :: [Text] = map (\col -> quoteIfLiteral (param @Bool (cs (get #columnName col) <> "_")) (param @Text (cs (get #columnName col)))) tableCols + let values :: [Text] = map (\col -> parseValues (param @Bool (cs (get #columnName col) <> "_")) (param @Bool (cs (get #columnName col) <> "-isBoolean")) (param @Text (cs (get #columnName col)))) tableCols let columns :: [Text] = map (\col -> cs (get #columnName col)) tableCols let primaryKeyValues = map (\pkey -> "'" <> (param @Text (cs pkey <> "-pk")) <> "'") primaryKeyFields @@ -139,7 +139,7 @@ instance Controller DataController where connection <- connectToAppDb let targetCol = param "targetName" let targetValue = param "targetValue" - let query = "UPDATE " <> tableName <> " SET " <> targetCol <> " = '" <> targetValue <> "' WHERE id = " <> cs id + let query = "UPDATE " <> tableName <> " SET " <> targetCol <> " = '" <> targetValue <> "' WHERE id = '" <> cs id <> "'" PG.execute_ connection (PG.Query . cs $! query) PG.close connection redirectTo ShowTableRowsAction { .. } @@ -185,8 +185,13 @@ fetchRows connection tableName = do PG.query_ connection (PG.Query . cs $! query) -quoteIfLiteral :: Bool -> Text -> Text -quoteIfLiteral False text = "'" <> text <> "'" -quoteIfLiteral True text = text +-- parseValues sqlMode isBoolField input +parseValues :: Bool -> Bool -> Text -> Text +parseValues _ True "on" = "true" +parseValues _ True "off" = "false" +parseValues False False text = "'" <> text <> "'" +parseValues True False text = text +parseValues False True text = text +parseValues True True text = text updateValues list = map (\elem -> fst elem <> " = " <> snd elem) list diff --git a/IHP/IDE/Data/View/EditRow.hs b/IHP/IDE/Data/View/EditRow.hs index 02e52b252..7155059a8 100644 --- a/IHP/IDE/Data/View/EditRow.hs +++ b/IHP/IDE/Data/View/EditRow.hs @@ -72,25 +72,127 @@ instance View EditRowView ViewContext where