mirror of https://github.com/jackc/pgx.git
Extract bufferLastResult
Buffered exec methods need to read until pending ready for queries is 0. Factor this common logic out. Add stress test for PgConn.pull/483/head
parent
e78cefecc5
commit
4f0658d52b
|
@ -799,6 +799,10 @@ func (pgConn *PgConn) Exec(ctx context.Context, sql string) (*PgResult, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pgConn.bufferLastResult(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pgConn *PgConn) bufferLastResult(ctx context.Context) (*PgResult, error) {
|
||||||
var result *PgResult
|
var result *PgResult
|
||||||
|
|
||||||
for resultReader := pgConn.GetResult(ctx); resultReader != nil; resultReader = pgConn.GetResult(ctx) {
|
for resultReader := pgConn.GetResult(ctx); resultReader != nil; resultReader = pgConn.GetResult(ctx) {
|
||||||
|
@ -844,30 +848,7 @@ func (pgConn *PgConn) ExecParams(ctx context.Context, sql string, paramValues []
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resultReader := pgConn.GetResult(ctx)
|
return pgConn.bufferLastResult(ctx)
|
||||||
if resultReader == nil {
|
|
||||||
return nil, errors.New("unexpected missing result")
|
|
||||||
}
|
|
||||||
|
|
||||||
var result *PgResult
|
|
||||||
rows := [][][]byte{}
|
|
||||||
for resultReader.NextRow() {
|
|
||||||
row := make([][]byte, len(resultReader.Values()))
|
|
||||||
copy(row, resultReader.Values())
|
|
||||||
rows = append(rows, row)
|
|
||||||
}
|
|
||||||
|
|
||||||
commandTag, err := resultReader.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result = &PgResult{
|
|
||||||
Rows: rows,
|
|
||||||
CommandTag: commandTag,
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecPrepared executes a prepared statement via the PostgreSQL extended query protocol, buffers the entire result, and
|
// ExecPrepared executes a prepared statement via the PostgreSQL extended query protocol, buffers the entire result, and
|
||||||
|
@ -888,30 +869,7 @@ func (pgConn *PgConn) ExecPrepared(ctx context.Context, stmtName string, paramVa
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resultReader := pgConn.GetResult(ctx)
|
return pgConn.bufferLastResult(ctx)
|
||||||
if resultReader == nil {
|
|
||||||
return nil, errors.New("unexpected missing result")
|
|
||||||
}
|
|
||||||
|
|
||||||
var result *PgResult
|
|
||||||
rows := [][][]byte{}
|
|
||||||
for resultReader.NextRow() {
|
|
||||||
row := make([][]byte, len(resultReader.Values()))
|
|
||||||
copy(row, resultReader.Values())
|
|
||||||
rows = append(rows, row)
|
|
||||||
}
|
|
||||||
|
|
||||||
commandTag, err := resultReader.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result = &PgResult{
|
|
||||||
Rows: rows,
|
|
||||||
CommandTag: commandTag,
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare creates a prepared statement.
|
// Prepare creates a prepared statement.
|
||||||
|
|
Loading…
Reference in New Issue