Add support to consume return values from stored procedures
See original GitHub issueIt would make sense to consume out parameters returned from a stored procedure. Since the R2DBC spec doesn’t define how to consume out params, we could map these onto a Row
. R2DBC 0.9 allows defining out/in-out parameters so we could leverage Statement.bind(…)
to register out parameter declarations. The invocation syntax would follow SQL Server defaults without having the driver to rewrite a stored procedure call.
Schema setup:
CREATE PROCEDURE test_proc
@TheName nvarchar(50),
@Greeting nvarchar(255) OUTPUT
AS
SET NOCOUNT ON;
SET @Greeting = CONCAT('Hello ', @TheName)
SQL statement:
EXEC test_proc @P0, @Greeting OUTPUT
Java code:
MssqlConnection connection = …;
connection.createStatement("EXEC test_proc @P0, @Greeting OUTPUT")
.bind("@P0", "Walter")
.bind("@Greeting", Parameters.out(R2dbcType.VARCHAR))
.execute()
.flatMap(it -> it.map((row, metadata) -> {
return row.get(0); // row.get("@Greeting");
}))
.as(StepVerifier::create)
.expectNext("Hello Walter")
.verifyComplete();
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Using Stored Procedures with Return Values - SQLShack
In this article, we will learn how we can use a Stored Procedure with return values with all details. Introduction.
Read more >Return data from a stored procedure - SQL Server
Learn how to return data from a procedure to a calling program by using result sets, output parameters, and return codes.
Read more >SQL Stored Procedure with Parameters and Return Values
In this tip we look at how to write SQL Server stored procedures to handle input parameters, output parameters and return codes.
Read more >Returning values for Stored Procedures in PostgreSQL
In case you want to return a value from a stored procedure, you can use output parameters. The final values of the output...
Read more >c# - Calling stored procedure with return value - Stack Overflow
getQuery(), conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter(); param = cmd.Parameters.Add( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you file either a SPI ticket or submit a PR if you like? The changes are limited to the
Parameters
type and basically a copy of theout
methods with a separate type implementingIn
andOut
interfaces.The idea to map out values to something
Row
-like goes into a proper direction. Thanks for this suggestion. Feel free to leave a comment on https://github.com/r2dbc/r2dbc-spi/pull/215. Coming up with a proper name for the interfaces might be a more difficult challenge than actually implementing it.Row extends <result-thing>
for rows and<result-thing>
for anything (including out params) that can be described with metadata and retrieved by name/index sounds seems a neat arrangement. On theSegment
side, we can come up with a more fine-grained set of interfaces to represent row data and non-row data.OK: https://github.com/r2dbc/r2dbc-spi/issues/216. I’ll provide a PR suggestion also.
I will