Skip to content

Commit

Permalink
EDIT - Increase Depth Limit in ptrFromMapping
Browse files Browse the repository at this point in the history
- Increase Depth Limit in ptrFromMapping Function
  for Deeper Structure Access in reflect.go
- This fix addresses errors encoutered with tables
  exceeding 255 columns.
- this fixes issue volatiletech#1359
  • Loading branch information
doscode-kr committed Mar 1, 2024
1 parent 42be9e1 commit 815f3ff
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions queries/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const (
loadMethodPrefix = "Load"
relationshipStructName = "R"
loaderStructName = "L"
sentinel = uint64(255)
sentinel = uint64(4095)
depthShift = 12
)

// BindP executes the query and inserts the
Expand Down Expand Up @@ -354,8 +355,9 @@ func ptrFromMapping(val reflect.Value, mapping uint64, addressOf bool) reflect.V
var ignored interface{}
return reflect.ValueOf(&ignored)
}
for i := 0; i < 8; i++ {
v := (mapping >> uint(i*8)) & sentinel
// I am not confident that this replacing the magic number 8 with `depthShift` is the correct solution.
for i := 0; i < depthShift; i++ {
v := (mapping >> uint(i*depthShift)) & sentinel

if v == sentinel {
if addressOf && val.Kind() != reflect.Ptr {
Expand Down Expand Up @@ -407,11 +409,11 @@ func makeStructMappingHelper(typ reflect.Type, prefix string, current uint64, de
}

if recurse {
makeStructMappingHelper(f.Type, tag, current|uint64(i)<<depth, depth+8, fieldMaps)
makeStructMappingHelper(f.Type, tag, current|uint64(i)<<depth, depth+depthShift, fieldMaps)
continue
}

fieldMaps[tag] = current | (sentinel << (depth + 8)) | (uint64(i) << depth)
fieldMaps[tag] = current | (sentinel << (depth + depthShift)) | (uint64(i) << depth)
}
}

Expand Down

0 comments on commit 815f3ff

Please sign in to comment.