Skip to content
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

Why gorm case sql.RawBytes to string when scanIntoMap? #7189

Open
APshenkin opened this issue Sep 5, 2024 · 3 comments
Open

Why gorm case sql.RawBytes to string when scanIntoMap? #7189

APshenkin opened this issue Sep 5, 2024 · 3 comments
Assignees
Labels

Comments

@APshenkin
Copy link

GORM Playground Link

Description

I find out that GORM cast byte arrays to strings, if ColumnTypeScanType returns sql.RawBytes.

gorm/scan.go

Line 44 in 0daaf17

} else if b, ok := mapValue[column].(sql.RawBytes); ok {

This behaviour was introduced in 2020 and actually it's not clear why it do so.

I thing it's logical that if db value is sql.RawBytes, then it should return []byte, not string, because you can have arbitrary byte array there that during scanning should not change to other type.

go-sqlite return sql.RawBytes as type for BLOB which is https://www.sqlite.org/datatype3.htmlThe value is a blob of data, stored exactly as it was input.

But together with GORM if dest is map[string]interface{} we get string instead

@APshenkin
Copy link
Author

I'll not recommend anyone to open link that was posted by @afreisz . This looks like a phishing

Copy link

github-actions bot commented Sep 5, 2024

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@jinzhu @APshenkin and others