|
5 | 5 | "database/sql/driver" |
6 | 6 | "fmt" |
7 | 7 | "io" |
| 8 | + "math/big" |
8 | 9 | "strings" |
9 | 10 |
|
10 | 11 | "github.com/dolthub/go-mysql-server/sql" |
@@ -87,6 +88,7 @@ type SqlRowIter struct { |
87 | 88 |
|
88 | 89 | decimals []int |
89 | 90 | lists []int |
| 91 | + hugeInts []int |
90 | 92 | } |
91 | 93 |
|
92 | 94 | func NewSqlRowIter(rows *stdsql.Rows, schema sql.Schema) (*SqlRowIter, error) { |
@@ -116,7 +118,14 @@ func NewSqlRowIter(rows *stdsql.Rows, schema sql.Schema) (*SqlRowIter, error) { |
116 | 118 | } |
117 | 119 | } |
118 | 120 |
|
119 | | - iter := &SqlRowIter{rows, columns, schema, buf, ptrs, decimals, lists} |
| 121 | + var hugeInts []int |
| 122 | + for i, t := range columns { |
| 123 | + if t.DatabaseTypeName() == "HUGEINT" { |
| 124 | + hugeInts = append(hugeInts, i) |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + iter := &SqlRowIter{rows, columns, schema, buf, ptrs, decimals, lists, hugeInts} |
120 | 129 | if logrus.GetLevel() >= logrus.DebugLevel { |
121 | 130 | logrus.Debugf("New " + iter.String() + "\n") |
122 | 131 | } |
@@ -197,6 +206,21 @@ func (iter *SqlRowIter) Next(ctx *sql.Context) (sql.Row, error) { |
197 | 206 | iter.buffer[idx] = pgtype.FlatArray[any](list) |
198 | 207 | } |
199 | 208 |
|
| 209 | + for _, idx := range iter.hugeInts { |
| 210 | + switch v := iter.buffer[idx].(type) { |
| 211 | + case nil: |
| 212 | + continue |
| 213 | + case *big.Int: |
| 214 | + var n pgtype.Numeric |
| 215 | + if err := n.Scan(v.String()); err != nil { |
| 216 | + return nil, err |
| 217 | + } |
| 218 | + iter.buffer[idx] = n |
| 219 | + default: |
| 220 | + return nil, fmt.Errorf("unexpected type %T for big.Int value", v) |
| 221 | + } |
| 222 | + } |
| 223 | + |
200 | 224 | // Prune or fill the values to match the schema |
201 | 225 | width := len(iter.schema) // the desired width |
202 | 226 | if width == 0 { |
|
0 commit comments