Skip to content

Commit

Permalink
allowing DDL, INSERT, UPDATE without crashing the custom query page
Browse files Browse the repository at this point in the history
  • Loading branch information
fegu committed Oct 22, 2020
1 parent d087389 commit 4b3cf1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
12 changes: 5 additions & 7 deletions IHP/IDE/Data/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ instance Controller DataController where
connection <- connectToAppDb
tableNames <- fetchTableNames connection
primaryKeyFields <- tablePrimaryKeyFields connection tableName

rows :: [[DynamicField]] <- fetchRows connection tableName

tableCols <- fetchTableCols connection tableName

PG.close connection
render ShowTableRowsView { .. }

action ShowQueryAction = do
connection <- connectToAppDb
let query = (param @Text "query")
when (query == "") do
redirectTo ShowDatabaseAction
rows :: [[DynamicField]] <- PG.query_ connection (fromString (cs query))

when (query == "") $ redirectTo ShowDatabaseAction
rows :: [[DynamicField]] <- if isQuery query then PG.query_ connection (fromString (cs query)) else PG.execute_ connection (fromString (cs query)) >> return []
PG.close connection
render ShowQueryView { .. }

Expand Down Expand Up @@ -195,3 +190,6 @@ parseValues False True text = text
parseValues True True text = text
updateValues list = map (\elem -> fst elem <> " = " <> snd elem) list
isQuery sql = T.isInfixOf "SELECT" u
where u = T.toUpper sql
1 change: 0 additions & 1 deletion IHP/IDE/Data/View/EditValue.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module IHP.IDE.Data.View.EditValue where

import IHP.ViewPrelude
Expand Down

0 comments on commit 4b3cf1b

Please sign in to comment.