mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Fix Execute SQL larger than sharedBufferSize
This commit is contained in:
parent
e99a9b2306
commit
fe2f62f034
@ -76,7 +76,7 @@ func Connect(parameters ConnectionParameters) (c *Connection, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
c.buf = bytes.NewBuffer(make([]byte, sharedBufferSize))
|
||||
c.buf = bytes.NewBuffer(make([]byte, 0, sharedBufferSize))
|
||||
c.runtimeParams = make(map[string]string)
|
||||
c.preparedStatements = make(map[string]*PreparedStatement)
|
||||
|
||||
@ -402,7 +402,6 @@ func (c *Connection) Execute(sql string, arguments ...interface{}) (commandTag s
|
||||
var t byte
|
||||
var r *MessageReader
|
||||
if t, r, err = c.rxMsg(); err == nil {
|
||||
// fmt.Printf("Execute received: %c\n", t)
|
||||
switch t {
|
||||
case readyForQuery:
|
||||
return
|
||||
@ -611,7 +610,7 @@ func (c *Connection) txPasswordMessage(password string) (err error) {
|
||||
func (c *Connection) getBuf() *bytes.Buffer {
|
||||
c.buf.Reset()
|
||||
if cap(c.buf.Bytes()) > sharedBufferSize {
|
||||
c.buf = bytes.NewBuffer(make([]byte, sharedBufferSize))
|
||||
c.buf = bytes.NewBuffer(make([]byte, 0, sharedBufferSize))
|
||||
}
|
||||
return c.buf
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package pgx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -170,6 +171,15 @@ func TestExecute(t *testing.T) {
|
||||
t.Error("Unexpected results from Execute")
|
||||
}
|
||||
|
||||
// Can execute longer SQL strings than sharedBufferSize
|
||||
results, err = conn.Execute(strings.Repeat("select 42; ", 1000))
|
||||
if err != nil {
|
||||
t.Fatal("Execute failed: " + err.Error())
|
||||
}
|
||||
if results != "SELECT 1" {
|
||||
t.Errorf("Unexpected results from Execute: %v", results)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSelectFunc(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user