denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.82k stars 495 forks source link

Use RPC to execute a stored proc without parameters #676

Closed tc-hib closed 3 years ago

tc-hib commented 3 years ago

This is a case where one could say "if it ain't broke don't fix it".

I noticed stored procedures are executed in SQL batches instead of RPC if we don't pass parameters. This is a little inconsistent, but there doesn't seem to be a significant difference. In both cases, SQL Server returns an error if you pass too many arguments. I can't think of another difference.

Please note that a stored procedure can have default parameters, which means one could call it with or without arguments. This means that db.Exec("my_proc") and db.Exec("my_proc", 42) both work, but one is an RPC while the other one is an SQL batch, until this PR is merged.