Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,15 @@ func (stmt *Stmt) write() error {
execFlag = 1
}

session.PutUint(stmt.cursorID, 2, true, true)
session.PutUint(count, 2, true, true)
session.PutUint(exeOf, 2, true, true)
session.PutUint(execFlag, 2, true, true)
// cursor, iteration count, execute options and flags are UB4 on the
// wire: a 2-byte cap writes a length byte of 2 followed by three
// bytes for any value over 0xFFFF (an array bind of 65,536 rows, or
// exeOf with 0x40000 set), and the server reads every later field
// one byte off (ORA-03106 on 23ai/26ai).
session.PutUint(stmt.cursorID, 4, true, true)
session.PutUint(count, 4, true, true)
session.PutUint(exeOf, 4, true, true)
session.PutUint(execFlag, 4, true, true)
// err := stmt.writePars()
// if err != nil {
// return err
Expand Down
35 changes: 35 additions & 0 deletions v2/network/session_putuint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package network

import (
"bytes"
"testing"
)

// A compressed integer is a length byte followed by exactly that many bytes.
// Stmt.write sends the re-execute iteration count this way; an array bind of
// 65,536 rows or more needs three bytes, so the field must be written with a
// 4-byte cap (UB4), as the other execute fields are.
func TestPutUintCompressedUB4(t *testing.T) {
cases := []struct {
n int
want []byte
}{
{0, []byte{0}},
{1, []byte{1, 1}},
{0xFFFF, []byte{2, 0xFF, 0xFF}},
{0x10000, []byte{3, 1, 0, 0}},
{0x40020, []byte{3, 4, 0, 0x20}},
{100000, []byte{3, 0x01, 0x86, 0xA0}},
}
for _, c := range cases {
s := NewSessionWithInputBufferForDebug(nil)
s.PutUint(c.n, 4, true, true)
got := s.outBuffer.Bytes()
if !bytes.Equal(got, c.want) {
t.Errorf("PutUint(%d, 4) = % x, want % x", c.n, got, c.want)
}
if int(got[0]) != len(got)-1 {
t.Errorf("PutUint(%d, 4): length byte %d, %d bytes follow", c.n, got[0], len(got)-1)
}
}
}