Merge pull request #311 from kelseyfrancis/fix-one-round-trip-exec-bug
Fix some invalid one round trip execs failing to return non-nil error
This commit is contained in:
@@ -1458,6 +1458,10 @@ func (c *Conn) execEx(ctx context.Context, sql string, options *QueryExOptions,
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
} else if options != nil && len(options.ParameterOIDs) > 0 {
|
} else if options != nil && len(options.ParameterOIDs) > 0 {
|
||||||
|
if err := c.ensureConnectionReadyForQuery(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
buf, err := c.buildOneRoundTripExec(c.wbuf, sql, options, arguments)
|
buf, err := c.buildOneRoundTripExec(c.wbuf, sql, options, arguments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -1196,6 +1196,34 @@ func TestConnExecExSuppliedIncorrectParameterOIDs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnExecExIncorrectParameterOIDsAfterAnotherQuery(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
mustExec(t, conn, "create temporary table foo(name varchar primary key);")
|
||||||
|
|
||||||
|
var s string
|
||||||
|
err := conn.QueryRow("insert into foo(name) values('baz') returning name;").Scan(&s)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Executing query failed: %v", err)
|
||||||
|
}
|
||||||
|
if s != "baz" {
|
||||||
|
t.Errorf("Query did not return expected value: %v", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.ExecEx(
|
||||||
|
context.Background(),
|
||||||
|
"insert into foo(name) values($1);",
|
||||||
|
&pgx.QueryExOptions{ParameterOIDs: []pgtype.OID{pgtype.Int4OID}},
|
||||||
|
"bar'; drop table foo;--",
|
||||||
|
)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error but got none")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrepare(t *testing.T) {
|
func TestPrepare(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user