-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(contrib/drivers/pgsql): preserve bytea data integrity on read and write #4678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,10 @@ func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fie | |||||
| var fieldValueKind = reflect.TypeOf(fieldValue).Kind() | ||||||
|
|
||||||
| if fieldValueKind == reflect.Slice { | ||||||
| // For bytea type, pass []byte directly without any conversion. | ||||||
| if _, ok := fieldValue.([]byte); ok && gstr.Contains(fieldType, "bytea") { | ||||||
| return d.Core.ConvertValueForField(ctx, fieldType, fieldValue) | ||||||
| } | ||||||
| // For pgsql, json or jsonb require '[]' | ||||||
| if !gstr.Contains(fieldType, "json") { | ||||||
| fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue), | ||||||
|
|
@@ -62,6 +66,7 @@ func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fie | |||||
| // | _varchar, _text | []string | | ||||||
| // | _char, _bpchar | []string | | ||||||
| // | _numeric, _decimal, _money | []float64 | | ||||||
| // | bytea | []byte | | ||||||
| // | _bytea | [][]byte | | ||||||
| // | _uuid | []uuid.UUID | | ||||||
| func (d *Driver) CheckLocalTypeForField(ctx context.Context, fieldType string, fieldValue any) (gdb.LocalType, error) { | ||||||
|
|
@@ -107,6 +112,9 @@ func (d *Driver) CheckLocalTypeForField(ctx context.Context, fieldType string, f | |||||
| case "_numeric", "_decimal", "_money": | ||||||
| return gdb.LocalTypeFloat64Slice, nil | ||||||
|
|
||||||
| case "bytea": | ||||||
| return gdb.LocalTypeBytes, nil | ||||||
|
|
||||||
| case "_bytea": | ||||||
| return gdb.LocalTypeBytesSlice, nil | ||||||
|
|
||||||
|
|
@@ -141,6 +149,7 @@ func (d *Driver) CheckLocalTypeForField(ctx context.Context, fieldType string, f | |||||
| // | _numeric | numeric[] | pq.Float64Array | []float64 | | ||||||
| // | _decimal | decimal[] | pq.Float64Array | []float64 | | ||||||
| // | _money | money[] | pq.Float64Array | []float64 | | ||||||
| // | bytea | bytea | - | []byte | | ||||||
| // | _bytea | bytea[] | pq.ByteaArray | [][]byte | | ||||||
| // | _uuid | uuid[] | pq.StringArray | []uuid.UUID | | ||||||
| // | ||||||
|
|
@@ -154,6 +163,13 @@ func (d *Driver) ConvertValueForLocal(ctx context.Context, fieldType string, fie | |||||
| // Basic types are mostly handled by Core layer, only handle array types here | ||||||
| switch typeName { | ||||||
|
|
||||||
| // []byte | ||||||
| case "bytea": | ||||||
| if v, ok := fieldValue.([]byte); ok { | ||||||
| return v, nil | ||||||
| } | ||||||
| return fieldValue, nil | ||||||
|
||||||
| return fieldValue, nil | |
| return d.Core.ConvertValueForLocal(ctx, fieldType, fieldValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says this function only handles array types, but the newly-added
case "bytea"is a basic (non-array) type. Please update the comment to reflect the current behavior so future changes don’t accidentally regress bytea handling.