MCPcopy Create free account
hub / github.com/apecloud/myduckserver / Next

Method Next

backend/iter.go:112–185  ·  view source on GitHub ↗

Next retrieves the next row. It will return io.EOF if it's the last row.

(ctx *sql.Context)

Source from the content-addressed store, hash-verified

110
111// Next retrieves the next row. It will return io.EOF if it's the last row.
112func (iter *SQLRowIter) Next(ctx *sql.Context) (sql.Row, error) {
113 if !iter.rows.Next() {
114 if err := iter.rows.Err(); err != nil {
115 return nil, err
116 }
117 return nil, io.EOF
118 }
119
120 // Scan the values into the buffer
121 if err := iter.rows.Scan(iter.pointers[:len(iter.columns)]...); err != nil {
122 return nil, err
123 }
124
125 // Process decimal values
126 for _, idx := range iter.decimals {
127 switch v := iter.buffer[idx].(type) {
128 case duckdb.Decimal:
129 iter.buffer[idx] = decimal.NewFromBigInt(v.Value, -int32(v.Scale))
130 case string:
131 iter.buffer[idx], _ = decimal.NewFromString(v)
132 }
133 }
134
135 // Process interval values
136 for _, idx := range iter.intervals {
137 t := types.TimespanType_{}
138 switch v := iter.buffer[idx].(type) {
139 case duckdb.Interval:
140 iter.buffer[idx] = t.MicrosecondsToTimespan(v.Micros + int64(v.Days)*24*60*60*1000000) // ignore the month part, which does not appear in MySQL
141 }
142 }
143
144 // Process type conversions
145 for _, targetType := range iter.conversions {
146 idx := targetType.idx
147 rawValue := iter.buffer[idx]
148 if targetType.kind == reflect.Float64 {
149 switch v := rawValue.(type) {
150 case *big.Int:
151 iter.buffer[idx], _ = v.Float64()
152 }
153 }
154 if targetType.kind == reflect.Int64 {
155 switch v := rawValue.(type) {
156 case float64:
157 iter.buffer[idx] = int64(v)
158 case float32:
159 iter.buffer[idx] = int64(v)
160 case *big.Int:
161 iter.buffer[idx] = v.Int64()
162 }
163 }
164 }
165
166 // Prune or fill the values to match the schema
167 width := len(iter.schema) // the desired width
168 if width == 0 {
169 width = len(iter.columns)

Callers 15

TestDebugHarnessFunction · 0.45
executeMethod · 0.45
TestResetReplicaFunction · 0.45
TestForeignKeyChecksFunction · 0.45
assertWarningFunction · 0.45
readNextRowFunction · 0.45
readAllRowsIntoMapsFunction · 0.45
readAllRowsIntoSlicesFunction · 0.45

Calls 2

EncodeFunction · 0.92
ErrMethod · 0.45

Tested by 12

TestDebugHarnessFunction · 0.36
TestResetReplicaFunction · 0.36
TestForeignKeyChecksFunction · 0.36
assertWarningFunction · 0.36
readNextRowFunction · 0.36
readAllRowsIntoMapsFunction · 0.36
readAllRowsIntoSlicesFunction · 0.36
executeQueryAndVerifyFunction · 0.36