2
0

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:
Jack Christensen
2017-08-29 14:49:39 -05:00
committed by GitHub
2 changed files with 32 additions and 0 deletions
+4
View File
@@ -1458,6 +1458,10 @@ func (c *Conn) execEx(ctx context.Context, sql string, options *QueryExOptions,
return "", err
}
} 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)
if err != nil {
return "", err
+28
View File
@@ -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) {
t.Parallel()