Fix #974 RPC error when function has single OUT param
This commit is contained in:
committed by
Steve Chávez
parent
7a3f350f1c
commit
d1a8c3a6f8
@@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #954, make OpenAPI rpc output dependent on user privileges - @steve-chavez
|
- #954, make OpenAPI rpc output dependent on user privileges - @steve-chavez
|
||||||
- #955, Support configurable aud claim - @statik
|
- #955, Support configurable aud claim - @statik
|
||||||
- #996, Fix embedded column conflicts table name - @grotsev
|
- #996, Fix embedded column conflicts table name - @grotsev
|
||||||
|
- #974, Fix RPC error when function has single OUT param - @steve-chavez
|
||||||
|
|
||||||
## [0.4.3.0] - 2017-09-06
|
## [0.4.3.0] - 2017-09-06
|
||||||
|
|
||||||
|
|||||||
@@ -150,14 +150,14 @@ callProc qi params returnsScalar selectQuery countQuery _ countTotal isSingle pa
|
|||||||
where
|
where
|
||||||
sql =
|
sql =
|
||||||
if returnsScalar then [qc|
|
if returnsScalar then [qc|
|
||||||
WITH {sourceCTEName} AS ({_callSql})
|
WITH {sourceCTEName} AS (select {fromQi qi}({_args}))
|
||||||
SELECT
|
SELECT
|
||||||
{countResultF} AS total_result_set,
|
{countResultF} AS total_result_set,
|
||||||
1 AS page_total,
|
1 AS page_total,
|
||||||
{scalarBodyF} as body
|
{scalarBodyF} as body
|
||||||
FROM ({selectQuery}) _postgrest_t;|]
|
FROM ({selectQuery}) _postgrest_t;|]
|
||||||
else [qc|
|
else [qc|
|
||||||
WITH {sourceCTEName} AS ({_callSql})
|
WITH {sourceCTEName} AS (select * from {fromQi qi}({_args}))
|
||||||
SELECT
|
SELECT
|
||||||
{countResultF} AS total_result_set,
|
{countResultF} AS total_result_set,
|
||||||
pg_catalog.count(_postgrest_t) AS page_total,
|
pg_catalog.count(_postgrest_t) AS page_total,
|
||||||
@@ -170,7 +170,6 @@ callProc qi params returnsScalar selectQuery countQuery _ countTotal isSingle pa
|
|||||||
else intercalate "," $ map _assignment (HM.toList params)
|
else intercalate "," $ map _assignment (HM.toList params)
|
||||||
_procName = qiName qi
|
_procName = qiName qi
|
||||||
_assignment (n,v) = pgFmtIdent n <> ":=" <> insertableValue v
|
_assignment (n,v) = pgFmtIdent n <> ":=" <> insertableValue v
|
||||||
_callSql = [qc|select * from {fromQi qi}({_args}) |] :: Text
|
|
||||||
decodeProc = HD.maybeRow procRow
|
decodeProc = HD.maybeRow procRow
|
||||||
procRow = (,,) <$> HD.nullableValue HD.int8 <*> HD.value HD.int8
|
procRow = (,,) <$> HD.nullableValue HD.int8 <*> HD.value HD.int8
|
||||||
<*> HD.value HD.bytea
|
<*> HD.value HD.bytea
|
||||||
|
|||||||
@@ -257,6 +257,25 @@ spec =
|
|||||||
get "/rpc/test" `shouldRespondWith`
|
get "/rpc/test" `shouldRespondWith`
|
||||||
[json|[{"test":"hello","value":1}]|] { matchHeaders = [matchContentTypeJson] }
|
[json|[{"test":"hello","value":1}]|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
context "procs with OUT/INOUT params" $ do
|
||||||
|
it "returns a scalar result when there is a single OUT param" $ do
|
||||||
|
get "/rpc/single_out_param?num=5" `shouldRespondWith`
|
||||||
|
[json|6|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
get "/rpc/single_json_out_param?a=1&b=two" `shouldRespondWith`
|
||||||
|
[json|{"a": 1, "b": "two"}|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "returns a scalar result when there is a single INOUT param" $
|
||||||
|
get "/rpc/single_inout_param?num=2" `shouldRespondWith`
|
||||||
|
[json|3|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "returns a row result when there are many OUT params" $
|
||||||
|
get "/rpc/many_out_params" `shouldRespondWith`
|
||||||
|
[json|[{"my_json":{"a": 1, "b": "two"},"num":3,"str":"four"}]|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "returns a row result when there are many INOUT params" $
|
||||||
|
get "/rpc/many_inout_params?num=1&str=two" `shouldRespondWith`
|
||||||
|
[json| [{"num":1,"str":"two","b":true}]|] { matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
context "only for POST rpc" $ do
|
context "only for POST rpc" $ do
|
||||||
context "expects a single json object" $ do
|
context "expects a single json object" $ do
|
||||||
it "does not expand posted json into parameters" $
|
it "does not expand posted json into parameters" $
|
||||||
|
|||||||
Vendored
+12
@@ -1273,10 +1273,22 @@ create table test.being_part (
|
|||||||
part int not null references test.part(part)
|
part int not null references test.part(part)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create function test.single_out_param(num int, OUT num_plus_one int) AS $$
|
||||||
|
select num + 1;
|
||||||
|
$$ language sql;
|
||||||
|
|
||||||
|
create function test.single_json_out_param(a int, b text, OUT my_json pg_catalog.json) AS $$
|
||||||
|
select json_build_object('a', a, 'b', b);
|
||||||
|
$$ language sql;
|
||||||
|
|
||||||
create function test.many_out_params(OUT my_json pg_catalog.json, OUT num int, OUT str text) AS $$
|
create function test.many_out_params(OUT my_json pg_catalog.json, OUT num int, OUT str text) AS $$
|
||||||
select '{"a": 1, "b": "two"}'::json, 3, 'four'::text;
|
select '{"a": 1, "b": "two"}'::json, 3, 'four'::text;
|
||||||
$$ language sql;
|
$$ language sql;
|
||||||
|
|
||||||
|
create function test.single_inout_param(INOUT num int) AS $$
|
||||||
|
select num + 1;
|
||||||
|
$$ language sql;
|
||||||
|
|
||||||
create function test.many_inout_params(INOUT num int, INOUT str text, INOUT b bool DEFAULT true) AS $$
|
create function test.many_inout_params(INOUT num int, INOUT str text, INOUT b bool DEFAULT true) AS $$
|
||||||
select num, str, b;
|
select num, str, b;
|
||||||
$$ language sql;
|
$$ language sql;
|
||||||
|
|||||||
Reference in New Issue
Block a user