Add support for named INPUT/OUTPUT parameters in stored procedures#43
Add support for named INPUT/OUTPUT parameters in stored procedures#43Mr-Kaos wants to merge 8 commits intoelvanto:masterfrom
Conversation
The MSSQL trust server certificate option now requires a boolean value.
- Added function to execute query with named parameters - Implemented output parameter storage
* Add table tests for MSSQL driver * Add stored procedure tests for MSSQL driver
- Updated MSSQL unit tests
joshmcrae
left a comment
There was a problem hiding this comment.
@Mr-Kaos Thanks for implementing this, especially tests for MSSQL. Did you manage to run them during development? If so, could you perhaps update our docker-compose.yml to run the MSSQL preview container?
I think that since output is broken for MySQL we should throw an exception if an output param is bound when the driver is Mysql. Even an InvalidArgumentException would make sense to protect the use-case that we don't yet support.
|
@joshmcrae I have added SQL Server to the dockerfile and tested it to ensure that it can run the tests correctly. That being said, this is my first time playing with docker, but I believe everything should be in working order. I have set it to use SQL Server 2019, but SQL Server 2017 can be used instead if you want a smaller container size. I also noticed that there are some GitHub workflows defined for MySQL and PostgreSQL. I'm also not familiar with workflows and am unsure if one for SQL Server needs to be added or not. |
|
Thanks for these changes! I've copied some of them into #45 and added Mssql to the GitHub workflow. Once that PR is merged, you can merge down to your branch and I'll re-review. |
Stored procedures have the ability to set a parameter as an output, essentially acting as a means to return a value from a procedure.
Additionally, some SQL flavours (e.g. MSSQL) allow for named parameter placement in stored procedure and do not require parameters to be placed in the order of their definition.
A method to execute a stored procedure using named parameters with/without an output parameter would allow for the retrieval of an output from a stored procedure.
The addition I have proposed introduces a new
executeNamed()function, which allows the execution of a query using named parameters instead of positional ones (such as in theexecute()function).It can be used as follows (examples are using MSSQL T-SQL syntax):
I have included unit tests for the MSSQL driver to verify this functionality works as intended.
The reason for this feature addition is to allow support for PDO OUT and INOUT parameters.
However, there is an issue exclusive to MySQL with this:
From (The only proper) PDO tutorial: