Skip to content

Commit b2e697e

Browse files
committed
fix: handle null decimals and improve error reporting in DecimalColumn
1 parent 5a3e29b commit b2e697e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

buffer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,12 @@ func (b *buffer) DecimalColumn(name string, val any) *buffer {
581581
if b.lastErr != nil {
582582
return b
583583
}
584-
b.WriteByte('=')
585584
if str, ok := val.(string); ok {
586585
if err := validateDecimalText(str); err != nil {
587586
b.lastErr = err
588587
return b
589588
}
589+
b.WriteByte('=')
590590
b.WriteString(str)
591591
b.WriteByte('d')
592592
b.hasFields = true
@@ -603,6 +603,11 @@ func (b *buffer) DecimalColumn(name string, val any) *buffer {
603603
b.lastErr = err
604604
return b
605605
}
606+
if len(payload) == 0 {
607+
// Don't write null decimals
608+
return b
609+
}
610+
b.WriteByte('=')
606611
b.WriteByte('=')
607612
b.WriteByte(decimalBinaryTypeCode)
608613
b.WriteByte(scale)

buffer_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,13 @@ func TestDecimalColumnErrors(t *testing.T) {
618618
assert.ErrorContains(t, err, "unsupported decimal column value type")
619619
assert.Empty(t, buf.Messages())
620620
})
621+
622+
t.Run("no column", func(t *testing.T) {
623+
buf := newTestBuffer()
624+
err := buf.Table(testTable).DecimalColumn("price", qdb.NullDecimal()).At(time.Time{}, false)
625+
assert.ErrorContains(t, err, "no symbols or columns were provided: invalid message")
626+
assert.Empty(t, buf.Messages())
627+
})
621628
}
622629

623630
func TestFloat64Array1DColumn(t *testing.T) {

0 commit comments

Comments
 (0)