otelsql
otelsql copied to clipboard
Error when using mssql and table-valued parameters
Hello! Thanks for all the great work on otelsql, it's been a pleasure to use.
Description
I'm getting the following error when using github.com/denisenkom/go-mssqldb and mssql.TVP parameter:
sql: converting argument with name "TVP" type: unsupported type mssql.TVP, a struct
The problem is that mssql doesn't implement CheckNamedValue(*NamedValue) error
for Stmt, only for Conn.
otelsql on the other hand, implements it on both Stmt and Conn, but then returns driver.ErrSkip in otStmt.CheckNamedValue if the underlying Stmt doesn't implement CheckNamedValue which causes the issue.
In my opinion it would be more fair wrapping if otStmt.CheckNamedValue falls back to the underlying Conn.CheckNamedValue when Stmt.CheckNamedValue is not implemented. But then the otStmt needs to have the Conn as a field.
I'm happy to submit a PR is it makes sense.
Hi @glebteterin, thanks for raising this issue.
In my opinion it would be more fair wrapping if otStmt.CheckNamedValue falls back to the underlying Conn.CheckNamedValue when Stmt.CheckNamedValue is not implemented.
I am not so sure about using Conn.CheckNamedValue
as the fallback of Stmt.CheckNamedValue
, it could bring unexpected behavior.
Besides, the library that is using database.sql
interfaces should respect driver.ErrSkip
error, and try to work without the method that throws the error.
Another solution could be implementing CheckNamedValue
by mssql
. See https://github.com/XSAM/otelsql/issues/63#issuecomment-1125646081 for related issues.