Repository navigation
Fix fixed-length CHAR encoding in batches #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,9 +123,19 @@ func ReadRowData(x *XDRReader, rowDescriptor []FieldDescriptor, scratch *rowScra | |
| return &SQLData{Nulls: nullsBitset, RowData: scratch.data, RowDescriptor: rowDescriptor}, nil | ||
| } | ||
|
|
||
| // WriteRowData - write fields null-bitset and data in 13+ protocol version | ||
| // WriteRowData writes the null-bitset and values in protocol 13+ format. | ||
| // https://firebirdsql.org/file/documentation/html/en/firebirddocs/wireprotocol/firebird-wire-protocol.html#wireprotocol-row-data-format | ||
| func WriteRowData(x *XDRWriter, rowDescriptor []FieldDescriptor, values [][]byte) error { | ||
| return writeRowData(x, rowDescriptor, values, false) | ||
| } | ||
|
|
||
| // 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 { | ||
| return writeRowData(x, rowDescriptor, values, true) | ||
| } | ||
|
|
||
| func writeRowData(x *XDRWriter, rowDescriptor []FieldDescriptor, values [][]byte, useDeclaredTextLength bool) error { | ||
| var err error | ||
| nulls := NewBitSet(len(rowDescriptor)) | ||
| for n, value := range values { | ||
|
|
@@ -144,7 +154,13 @@ func WriteRowData(x *XDRWriter, rowDescriptor []FieldDescriptor, values [][]byte | |
| } | ||
| valueBuf := values[n] | ||
| valueBufLen := len(valueBuf) | ||
| l := field.CalculateIoLength(values[n]) | ||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this length check fails, |
||
| } | ||
| l = field.GetIOLength() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| if l == 0 { | ||
| if err = x.WriteInt32(valueBufLen); err != nil { | ||
| return err | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could
WriteBatchRowDatacheck thatlen(values) == len(rowDescriptor)before writing the NULL bitmap? With oneCHARdescriptor and no values, it writes four bytes and then panics atvalues[0]. An extra non-nil value is silently dropped. Returning an error in both cases would matchCalculateBLRand leave the writer untouched.