fix: db settings and pg version query not prepared
This commit is contained in:
committed by
Steve Chavez
parent
c656a870f4
commit
c06237cc56
@@ -44,6 +44,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #2705, Fix bug when using the `Range` header on `PATCH/DELETE` - @laurenceisla
|
- #2705, Fix bug when using the `Range` header on `PATCH/DELETE` - @laurenceisla
|
||||||
+ Fix the`"message": "syntax error at or near \"RETURNING\""` error
|
+ Fix the`"message": "syntax error at or near \"RETURNING\""` error
|
||||||
+ Fix doing a limited update/delete when an `order` query parameter was present
|
+ Fix doing a limited update/delete when an `order` query parameter was present
|
||||||
|
- #2742, Fix db settings and pg version queries not getting prepared - @steve-chavez
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ import Text.InterpolatedString.Perl6 (q)
|
|||||||
|
|
||||||
import Protolude
|
import Protolude
|
||||||
|
|
||||||
queryPgVersion :: Session PgVersion
|
queryPgVersion :: Bool -> Session PgVersion
|
||||||
queryPgVersion = statement mempty pgVersionStatement
|
queryPgVersion prepared = statement mempty $ pgVersionStatement prepared
|
||||||
|
|
||||||
pgVersionStatement :: SQL.Statement () PgVersion
|
pgVersionStatement :: Bool -> SQL.Statement () PgVersion
|
||||||
pgVersionStatement = SQL.Statement sql HE.noParams versionRow False
|
pgVersionStatement = SQL.Statement sql HE.noParams versionRow
|
||||||
where
|
where
|
||||||
sql = "SELECT current_setting('server_version_num')::integer, current_setting('server_version')"
|
sql = "SELECT current_setting('server_version_num')::integer, current_setting('server_version')"
|
||||||
versionRow = HD.singleRow $ PgVersion <$> column HD.int4 <*> column HD.text
|
versionRow = HD.singleRow $ PgVersion <$> column HD.int4 <*> column HD.text
|
||||||
@@ -31,11 +31,11 @@ pgVersionStatement = SQL.Statement sql HE.noParams versionRow False
|
|||||||
queryDbSettings :: Bool -> Session [(Text, Text)]
|
queryDbSettings :: Bool -> Session [(Text, Text)]
|
||||||
queryDbSettings prepared =
|
queryDbSettings prepared =
|
||||||
let transaction = if prepared then SQL.transaction else SQL.unpreparedTransaction in
|
let transaction = if prepared then SQL.transaction else SQL.unpreparedTransaction in
|
||||||
transaction SQL.ReadCommitted SQL.Read $ SQL.statement mempty dbSettingsStatement
|
transaction SQL.ReadCommitted SQL.Read $ SQL.statement mempty $ dbSettingsStatement prepared
|
||||||
|
|
||||||
-- | Get db settings from the connection role. Global settings will be overridden by database specific settings.
|
-- | Get db settings from the connection role. Global settings will be overridden by database specific settings.
|
||||||
dbSettingsStatement :: SQL.Statement () [(Text, Text)]
|
dbSettingsStatement :: Bool -> SQL.Statement () [(Text, Text)]
|
||||||
dbSettingsStatement = SQL.Statement sql HE.noParams decodeSettings False
|
dbSettingsStatement = SQL.Statement sql HE.noParams decodeSettings
|
||||||
where
|
where
|
||||||
sql = [q|
|
sql = [q|
|
||||||
WITH
|
WITH
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ type SqlQuery = ByteString
|
|||||||
querySchemaCache :: [Schema] -> [Schema] -> Bool -> SQL.Transaction SchemaCache
|
querySchemaCache :: [Schema] -> [Schema] -> Bool -> SQL.Transaction SchemaCache
|
||||||
querySchemaCache schemas extraSearchPath prepared = do
|
querySchemaCache schemas extraSearchPath prepared = do
|
||||||
SQL.sql "set local schema ''" -- This voids the search path. The following queries need this for getting the fully qualified name(schema.name) of every db object
|
SQL.sql "set local schema ''" -- This voids the search path. The following queries need this for getting the fully qualified name(schema.name) of every db object
|
||||||
pgVer <- SQL.statement mempty pgVersionStatement
|
pgVer <- SQL.statement mempty $ pgVersionStatement prepared
|
||||||
tabs <- SQL.statement schemas $ allTables pgVer prepared
|
tabs <- SQL.statement schemas $ allTables pgVer prepared
|
||||||
keyDeps <- SQL.statement (schemas, extraSearchPath) $ allViewsKeyDependencies prepared
|
keyDeps <- SQL.statement (schemas, extraSearchPath) $ allViewsKeyDependencies prepared
|
||||||
m2oRels <- SQL.statement mempty $ allM2OandO2ORels pgVer prepared
|
m2oRels <- SQL.statement mempty $ allM2OandO2ORels pgVer prepared
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ establishConnection appState =
|
|||||||
|
|
||||||
getConnectionStatus :: IO ConnectionStatus
|
getConnectionStatus :: IO ConnectionStatus
|
||||||
getConnectionStatus = do
|
getConnectionStatus = do
|
||||||
pgVersion <- AppState.usePool appState queryPgVersion
|
pgVersion <- AppState.usePool appState $ queryPgVersion False -- No need to prepare the query here, as the connection might not established
|
||||||
case pgVersion of
|
case pgVersion of
|
||||||
Left e -> do
|
Left e -> do
|
||||||
AppState.logPgrstError appState e
|
AppState.logPgrstError appState e
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
pool <- P.acquire 3 10 60 $ toUtf8 $ configDbUri testCfg
|
pool <- P.acquire 3 10 60 $ toUtf8 $ configDbUri testCfg
|
||||||
|
|
||||||
actualPgVersion <- either (panic . show) id <$> P.use pool queryPgVersion
|
actualPgVersion <- either (panic . show) id <$> P.use pool (queryPgVersion False)
|
||||||
|
|
||||||
baseSchemaCache <-
|
baseSchemaCache <-
|
||||||
loadSchemaCache pool
|
loadSchemaCache pool
|
||||||
|
|||||||
Reference in New Issue
Block a user