node-odbc icon indicating copy to clipboard operation
node-odbc copied to clipboard

Binding parameters using a key value type

Open ranjithchev opened this issue 6 years ago • 2 comments

Hi

I understand that currently this library supports binding parameters but expects it be in the right order. select a,b from table1 where a=? and b=? and the binding parameters should be an array in the right order like ["abc", 2]

Is there a way we can support or have support to give the binding parameters as below (This is supported in mssql library).

select a,b from table1 where a=@v1 and b=@v2 request.add(paramname, paramvalue, paramtype) In the above example it would translate to request.add("v1", "abc", sql.Varchar) request.add("v2", 2, sql.Int)

Thanks Ranjith

ranjithchev avatar Oct 23 '18 21:10 ranjithchev

I don't think this is possible. See the below quote from MSDN (emphasis mine):

Certain DBMSs allow an application to specify the parameters to a stored procedure by name instead of by position in the procedure call. Such parameters are called named parameters. ODBC supports the use of named parameters. In ODBC, named parameters are used only in calls to stored procedures and cannot be used in other SQL statements.

https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/binding-parameters-by-name-named-parameters?view=sql-server-2017

asztal avatar Oct 24 '18 08:10 asztal

Thank you.

ranjithchev avatar Oct 24 '18 13:10 ranjithchev