Closed keegancsmith closed 7 years ago
Looks like a great improvement, do you think you can add a test to cover namedValueToValue
behavior?
@gchaincl I can't test this via the existing unit test, since all of the tested drivers implement ExecerContext
. So I pushed a commit which directly tests the function. Note the function is directly copied from the implementation used by database/sql
.
I see what you mean, anyway, do you know any driver which implements the driver.Execer|Context
interface?
postgres atleast does, because I need this change otherwise I can't instrument my code. Here is the link of it being used https://github.com/lib/pq/blob/8837942c3e09574accbc5f150e2c5e057189cace/conn_go18.go#L33
We may want to add go version guards around this? ExecContext seems to be for go >= 1.8 But implementing an interface should just be ignored in older versions if I am not mistaken.
If postgres does, can u exercise the behavior here: https://github.com/gchaincl/sqlhooks/blob/master/sqlhooks_postgres_test.go ?
Otherwise, I'll just merge this and try to add a test in the future.
It already is being exercised https://github.com/gchaincl/sqlhooks/blob/master/sqlhooks_test.go#L92
Before this change database/sql
translated that call into a Prepare followed by Exec on the statement. Now that conn implement ExecContext, it will just directly call the code I added. Check the code coverage and you will see that it is being exercised.
I see what you mean, apparently what's not being exercised is driver.Exec
which calls namedValueToValue, but that's ok. Please feel free to merge!
Wonderful, thanks!
A
driver.Conn
can optionally implementdriver.ExecerContext
ordriver.Execer
. When they do, instead of creating a prepared statement and then executing thatdatabase/sql
will directly callExecContext
orExec
respectively. We need to implement this since some drivers do not support all statements being prepared first. For example in postgresql you can run multiple statements in aconn.Exec
, but it will fail if you try to prepare multiple statements in one call.