steffengy / tiberius

TDS 7.4 (mssql / Microsoft SQL Server) async driver for rust. Fork at: https://github.com/prisma/tiberius
Apache License 2.0
151 stars 2 forks source link

Parameters: Equivalent of JDBC's setArray() #98

Open nevi-me opened 5 years ago

nevi-me commented 5 years ago

I'm trying to run something like:

select * from roles where role_group in ('a', 'b', 'c');

Is there a way of running?

connection.query(
    "SELECT * FROM roles WHERE role_group in @P1",
    &[???]
)
steffengy commented 5 years ago

No not currently. The closest would be to manually unroll and build IN(@P1, @P2, ...) as SQL and then pass multiple parameters.

nevi-me commented 5 years ago

I'll use a manual unroll for now, but it's something I'd like to work on with some guidance. Can you point me in the right direction? I can work on this in the coming days/weeks

steffengy commented 5 years ago

I doubt there's a nice way to support this, not even the microsoft JDBC driver does: https://github.com/Microsoft/mssql-jdbc/blob/cf700cafe61fe22e4eb5e1f2a175bcd7fb839990/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java#L3004

o01eg commented 5 years ago

There setStructured which accepts SQLServerDataTable. But it requires to define type in the database.