Repository navigation
Conversation
Code coverage overviewLanguages: Go Go / code-coverage/gotest
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. |
| l := field.CalculateIoLength(valueBuf) | ||
| if useDeclaredTextLength && field.Type == SQL_TYPE_TEXT { | ||
| if valueBufLen > field.Length { | ||
| return fmt.Errorf("batch CHAR parameter %d: value length %d exceeds declared length %d", n, valueBufLen, field.Length) |
There was a problem hiding this comment.
When this length check fails, PreparedBatch.Add returns before clearing b.eqb. Passing a 16 MiB byte slice to CHAR(5) CHARACTER SET OCTETS leaves the batch holding the entire copy even after Cancel and Close. Could we set b.eqb = ExtendedQueryBuilder{} on the EncodeBatchRow error path? Previously accepted rows are already in b.encodedRows, so they stay queued.
|
|
||
| // WriteBatchRowData writes rows using the declared CHAR lengths, matching | ||
| // the batch BLR generated by CalculateBLR(rowDescriptor, nil). | ||
| func WriteBatchRowData(x *XDRWriter, rowDescriptor []FieldDescriptor, values [][]byte) error { |
There was a problem hiding this comment.
Could WriteBatchRowData check that len(values) == len(rowDescriptor) before writing the NULL bitmap? With one CHAR descriptor and no values, it writes four bytes and then panics at values[0]. An extra non-nil value is silently dropped. Returning an error in both cases would match CalculateBLR and leave the writer untouched.
| realFieldLen := l - 1 | ||
|
|
||
| if valueBufLen >= realFieldLen { | ||
| if err = x.WriteBytes(valueBuf[:realFieldLen]); err != nil { | ||
| return err | ||
| } | ||
| if err = x.WriteCustomPadding((4-realFieldLen)&3, field.GetPaddingByte()); err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| if err = x.WriteBytes(valueBuf); err != nil { | ||
| return err | ||
| } | ||
| if err = x.WriteCustomPadding(realFieldLen-valueBufLen+((4-realFieldLen)&3), field.GetPaddingByte()); err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
Both arms of the fixed-width branch in writeRowData call WriteBytes and WriteCustomPadding. Could we slice the value first and share those calls? This reduces the block after realFieldLen := l - 1 from 15 lines to 8. The batch and row-format tests passed with -race using this version.
| valueBuf = valueBuf[:min(valueBufLen, realFieldLen)] | |
| if err = x.WriteBytes(valueBuf); err != nil { | |
| return err | |
| } | |
| alignedLen := (realFieldLen + 3) &^ 3 | |
| if err = x.WriteCustomPadding(alignedLen-len(valueBuf), field.GetPaddingByte()); err != nil { | |
| return err | |
| } |
| if valueBufLen > field.Length { | ||
| return fmt.Errorf("batch CHAR parameter %d: value length %d exceeds declared length %d", n, valueBufLen, field.Length) | ||
| } | ||
| l = field.GetIOLength() |
There was a problem hiding this comment.
WriteCustomPadding allocates a temporary slice the size of the padding. For CHAR(32767) CHARACTER SET ASCII, both a one-byte value and a full-width value produce the same number of encoded bytes. In a WriteBatchRowData benchmark writing to io.Discard, "x" allocated 32,784 B/op and the full-width value allocated 16 B/op. Could we write the padding in chunks from reusable blocks of spaces and zero bytes? That would avoid the per-row padding allocation for wide columns.
Use declared CHAR lengths when encoding batch rows to match the batch BLR.
Pad shorter values and reject values that exceed the declared length.
Closes #38