mirror of https://github.com/jackc/pgx.git
Fix explicitly prepared statements with describe statement cache mode
fixes https://github.com/jackc/pgx/issues/1196pull/1200/head
parent
c6335a30d0
commit
7ceeea6fe6
2
conn.go
2
conn.go
|
@ -645,7 +645,7 @@ optionLoop:
|
||||||
resultFormats = c.eqb.resultFormats
|
resultFormats = c.eqb.resultFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.stmtcache != nil && c.stmtcache.Mode() == stmtcache.ModeDescribe {
|
if c.stmtcache != nil && c.stmtcache.Mode() == stmtcache.ModeDescribe && !ok {
|
||||||
rows.resultReader = c.pgConn.ExecParams(ctx, sql, c.eqb.paramValues, sd.ParamOIDs, c.eqb.paramFormats, resultFormats)
|
rows.resultReader = c.pgConn.ExecParams(ctx, sql, c.eqb.paramValues, sd.ParamOIDs, c.eqb.paramFormats, resultFormats)
|
||||||
} else {
|
} else {
|
||||||
rows.resultReader = c.pgConn.ExecPrepared(ctx, sd.Name, c.eqb.paramValues, c.eqb.paramFormats, resultFormats)
|
rows.resultReader = c.pgConn.ExecPrepared(ctx, sd.Name, c.eqb.paramValues, c.eqb.paramFormats, resultFormats)
|
||||||
|
|
44
conn_test.go
44
conn_test.go
|
@ -496,6 +496,50 @@ func TestPrepareIdempotency(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrepareStatementCacheModes(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
buildStatementCache pgx.BuildStatementCacheFunc
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "disabled",
|
||||||
|
buildStatementCache: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prepare",
|
||||||
|
buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache {
|
||||||
|
return stmtcache.New(conn, stmtcache.ModePrepare, 32)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "describe",
|
||||||
|
buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache {
|
||||||
|
return stmtcache.New(conn, stmtcache.ModeDescribe, 32)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
config.BuildStatementCache = tt.buildStatementCache
|
||||||
|
conn := mustConnect(t, config)
|
||||||
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
|
_, err := conn.Prepare(context.Background(), "test", "select $1::text")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var s string
|
||||||
|
err = conn.QueryRow(context.Background(), "test", "hello").Scan(&s)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "hello", s)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestListenNotify(t *testing.T) {
|
func TestListenNotify(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue