Skip to content

Commit f79aac2

Browse files
fix builds for platforms with 32-bit integer size
1 parent b56c7c6 commit f79aac2

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

sql/expression/function/extract.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
169169
ss := dateTime.Second()
170170
return dd + hh + mm + ss, nil
171171
case "DAY_MICROSECOND":
172-
dd := dateTime.Day() * 1_00_00_00_000000
173-
hh := dateTime.Hour() * 1_00_00_000000
174-
mm := dateTime.Minute() * 1_00_000000
175-
ss := dateTime.Second() * 1_000000
176-
mmmmmm := dateTime.Nanosecond() / 1000
172+
dd := uint64(dateTime.Day()) * 1_00_00_00_000000
173+
hh := uint64(dateTime.Hour()) * 1_00_00_000000
174+
mm := uint64(dateTime.Minute()) * 1_00_000000
175+
ss := uint64(dateTime.Second()) * 1_000000
176+
mmmmmm := uint64(dateTime.Nanosecond()) / 1000
177177
return dd + hh + mm + ss + mmmmmm, nil
178178
case "HOUR_MINUTE":
179179
hh := dateTime.Hour() * 1_00
@@ -185,10 +185,10 @@ func (td *Extract) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
185185
ss := dateTime.Second()
186186
return hh + mm + ss, nil
187187
case "HOUR_MICROSECOND":
188-
hh := dateTime.Hour() * 1_00_00_000000
189-
mm := dateTime.Minute() * 1_00_000000
190-
ss := dateTime.Second() * 1_000000
191-
mmmmmm := dateTime.Nanosecond() / 1000
188+
hh := uint64(dateTime.Hour()) * 1_00_00_000000
189+
mm := uint64(dateTime.Minute()) * 1_00_000000
190+
ss := uint64(dateTime.Second()) * 1_000000
191+
mmmmmm := uint64(dateTime.Nanosecond()) / 1000
192192
return hh + mm + ss + mmmmmm, nil
193193
case "MINUTE_SECOND":
194194
mm := dateTime.Minute() * 1_00

sql/rowexec/proc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ func (b *BaseBuilder) buildLoop(ctx *sql.Context, n *plan.Loop, row sql.Row) (sq
304304
selectSeen := false
305305

306306
// It's technically valid to make an infinite loop, but we don't want to actually allow that
307-
const maxIterationCount = 10_000_000_000
307+
const maxIterationCount uint64 = 10_000_000_000
308308

309-
for loopIteration := 0; loopIteration <= maxIterationCount; loopIteration++ {
309+
for loopIteration := uint64(0); loopIteration <= maxIterationCount; loopIteration++ {
310310
if loopIteration >= maxIterationCount {
311311
return nil, fmt.Errorf("infinite LOOP detected")
312312
}

sql/types/geometry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func (t GeometryType) MatchSRID(v interface{}) error {
546546
}
547547

548548
func ValidateSRID(srid int, funcName string) error {
549-
if srid < 0 || srid > math.MaxUint32 {
549+
if srid < 0 || int64(srid) > int64(math.MaxUint32) {
550550
return sql.ErrInvalidSRID.New(funcName)
551551
}
552552
if _, ok := SupportedSRIDs[uint32(srid)]; !ok {

sql/types/number.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,27 +1114,27 @@ func convertToUint64(t NumberTypeImpl_, v interface{}) (uint64, sql.ConvertInRan
11141114
return uint64(v.UTC().Unix()), sql.InRange, nil
11151115
case int:
11161116
if v < 0 {
1117-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1117+
return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil
11181118
}
11191119
return uint64(v), sql.InRange, nil
11201120
case int8:
11211121
if v < 0 {
1122-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1122+
return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil
11231123
}
11241124
return uint64(v), sql.InRange, nil
11251125
case int16:
11261126
if v < 0 {
1127-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1127+
return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil
11281128
}
11291129
return uint64(v), sql.InRange, nil
11301130
case int32:
11311131
if v < 0 {
1132-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1132+
return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil
11331133
}
11341134
return uint64(v), sql.InRange, nil
11351135
case int64:
11361136
if v < 0 {
1137-
return uint64(math.MaxUint64 - uint(-v-1)), sql.OutOfRange, nil
1137+
return uint64(math.MaxUint64 - uint64(-v-1)), sql.OutOfRange, nil
11381138
}
11391139
return uint64(v), sql.InRange, nil
11401140
case uint:
@@ -1204,35 +1204,35 @@ func convertToUint32(t NumberTypeImpl_, v interface{}) (uint32, sql.ConvertInRan
12041204
switch v := v.(type) {
12051205
case int:
12061206
if v < 0 {
1207-
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1208-
} else if v > math.MaxUint32 {
1207+
return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil
1208+
} else if int64(v) > int64(math.MaxUint32) {
12091209
return uint32(math.MaxUint32), sql.OutOfRange, nil
12101210
}
12111211
return uint32(v), sql.InRange, nil
12121212
case int8:
12131213
if v < 0 {
1214-
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1215-
} else if int(v) > math.MaxUint32 {
1214+
return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil
1215+
} else if int64(v) > int64(math.MaxUint32) {
12161216
return uint32(math.MaxUint32), sql.OutOfRange, nil
12171217
}
12181218
return uint32(v), sql.InRange, nil
12191219
case int16:
12201220
if v < 0 {
1221-
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1222-
} else if int(v) > math.MaxUint32 {
1221+
return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil
1222+
} else if int64(v) > int64(math.MaxUint32) {
12231223
return uint32(math.MaxUint32), sql.OutOfRange, nil
12241224
}
12251225
return uint32(v), sql.InRange, nil
12261226
case int32:
12271227
if v < 0 {
1228-
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1229-
} else if int(v) > math.MaxUint32 {
1228+
return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil
1229+
} else if int64(v) > int64(math.MaxUint32) {
12301230
return uint32(math.MaxUint32), sql.OutOfRange, nil
12311231
}
12321232
return uint32(v), sql.InRange, nil
12331233
case int64:
12341234
if v < 0 {
1235-
return uint32(math.MaxUint32 - uint(-v-1)), sql.OutOfRange, nil
1235+
return uint32(math.MaxUint32 - uint64(-v-1)), sql.OutOfRange, nil
12361236
} else if v > math.MaxUint32 {
12371237
return uint32(math.MaxUint32), sql.OutOfRange, nil
12381238
}

sql/types/strings.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bytes"
1919
"context"
2020
"fmt"
21+
"math"
2122
"reflect"
2223
"strconv"
2324
strings2 "strings"
@@ -41,7 +42,7 @@ const (
4142
TinyTextBlobMax = charBinaryMax
4243
TextBlobMax = varcharVarbinaryMax
4344
MediumTextBlobMax = 16_777_215
44-
LongTextBlobMax = int64(4_294_967_295)
45+
LongTextBlobMax = int64(math.MaxInt32)
4546
)
4647

4748
var (

0 commit comments

Comments
 (0)