diff --git a/connection.go b/connection.go index 8c2807e9..01c23f38 100644 --- a/connection.go +++ b/connection.go @@ -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 } diff --git a/connection_test.go b/connection_test.go index e7f44f7b..7206c2b3 100644 --- a/connection_test.go +++ b/connection_test.go @@ -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) {