Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit b596500

Browse files
author
Sergei Sobolev
committed
implement RowsColumnTypeNullable and RowsColumnTypePrecisionScale interfaces by rows struct to get decimal's precision and scale via func (*Rows) ColumnTypes
https://golang.org/pkg/database/sql/#Rows.ColumnTypes interfaces are defined here https://github.com/golang/go/blob/master/src/database/sql/driver/driver.go
1 parent d8e3533 commit b596500

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/column/decimal.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,11 @@ func parseDecimal(name, chType string) (Column, error) {
239239

240240
return decimal, nil
241241
}
242+
243+
func (d *Decimal) GetPrecision() int {
244+
return d.precision
245+
}
246+
247+
func (d *Decimal) GetScale() int {
248+
return d.scale
249+
}

lib/column/nullable.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ func parseNullable(name, chType string, timezone *time.Location) (*Nullable, err
7979
column: column,
8080
}, nil
8181
}
82+
83+
func (null *Nullable) GetColumn() Column {
84+
return null.column
85+
}

rows.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,22 @@ func (rows *rows) setError(err error) error {
161161
rows.mutex.Unlock()
162162
return err
163163
}
164+
165+
func (rows *rows) ColumnTypeNullable(idx int) (nullable, ok bool) {
166+
_, ok = rows.blockColumns[idx].(*column.Nullable)
167+
return ok, true
168+
}
169+
170+
func (rows *rows) ColumnTypePrecisionScale(idx int) (precision, scale int64, ok bool) {
171+
decimalVal, ok := rows.blockColumns[idx].(*column.Decimal)
172+
if !ok {
173+
if nullable, nullOk := rows.blockColumns[idx].(*column.Nullable); nullOk {
174+
decimalVal, ok = nullable.GetColumn().(*column.Decimal)
175+
}
176+
}
177+
if ok {
178+
return int64(decimalVal.GetPrecision()), int64(decimalVal.GetScale()), ok
179+
180+
}
181+
return 0, 0, false
182+
}

0 commit comments

Comments
 (0)