database/sql: ColumnConverter is bypassed when NumInput returns -1 #68342
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I wrote a
database/sql
driver that implements the optionalColumnConverter
interface for prepared statements, and for whichNumInputs()
returns -1.Technically, I wrote a
databse/sql
proxy driver, for the purpose of adding hooks to DB operations, to aide in debugging. See https://gitlab.com/flimzy/errsqlBut using this library with
modernc.org/sqlite
is what triggered the buggy behavior.modernc.org/sqlite
itself does not implement theColumnConverter
interface, but it does return -1 forNumInputs
. Because the proxy driver does implementColumnConverter
(because it must implement it for all drivers it proxies, or none), it triggers the observed behavior.What did you see happen?
The
ColumnConverter
method is never called, leading to the following error from sqlite:What did you expect to see?
I expected that
ColumnConverter
would be called.Analysis & Possible Fix
This line appears to be the culprit:
c.want
is set to the return value fromstmt.NumInputs()
, so is-1
in this case. The method containing this code is only executed whenColumnConverter
is implemented, as we can see here.I believe the solution is to change the above mentioned line to:
The text was updated successfully, but these errors were encountered: