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

Dameng database cannot deserialize nested Struct using BLOB type #2594

Closed
tianbocheng opened this issue Apr 23, 2023 · 4 comments
Closed

Dameng database cannot deserialize nested Struct using BLOB type #2594

tianbocheng opened this issue Apr 23, 2023 · 4 comments
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. help wanted

Comments

@tianbocheng
Copy link

tianbocheng commented Apr 23, 2023

  • 达梦数据库版本:dm8_single:v8.1.2.128_ent_x86_64_ctm_pack4
  • gf版本:github.com/gogf/gf/v2 v2.3.3
  • 驱动版本:github.com/gogf/gf/contrib/drivers/dm/v2 v2.3.3

存储 struct 格式如下

type HandleInfoMysql struct {
	Id         int                `orm:"id,primary" json:"id"`
	SubPrefix  string             `orm:"sub_prefix"`
	Prefix     string             `orm:"prefix"`
	HandleName string             `orm:"handle_name"`
	CreateTime time.Time          `orm:"create_time"`
	UpdateTime time.Time          `orm:"update_time"`
	Value      []HandleValueMysql `orm:"value"`
}

type HandleValueMysql struct {
	Index       int64            `orm:"index"`
	Type        string           `orm:"type"`
	Data        []byte           `orm:"data"`
}

数据库脚本如下

DROP table HANDLE_INFO ;
CREATE TABLE HANDLE_INFO (
	ID INT IDENTITY (1, 1) NOT NULL,
	SUB_PREFIX VARCHAR(128),
	PREFIX VARCHAR(256),
	HANDLE_NAME VARCHAR(1024) NOT NULL,
	CREATE_TIME TIMESTAMP,
	UPDATE_TIME TIMESTAMP,
	VALUE BLOB   ,
	NOT CLUSTER PRIMARY KEY (ID)
);

数据写入操作,正常写入 blob 类型,正确序列化到了数据库中

handleInfo := &model.HandleInfoMysql{
		SubPrefix:  subPrefix,
		Prefix:     prefix,
		HandleName: handle,
		CreateTime: now,
		UpdateTime: now,
		Value:      *model.RecoveryValueMysql(valuesCore),
	}
_, err := g.DB().Model("handle_info").OmitEmptyData().Insert(handleInfo)

image

数据读取操作,无法反序列化嵌套 Struct

var handleInfoMysql model.HandleInfoMysql
err := g.DB().Model("handle_info").Where("handle_name", handle).Scan(&handleInfoMysql)

image

@Issues-translate-bot Issues-translate-bot changed the title 达梦数据库使用 BLOB 类型无法反序列化嵌套 Struct Dameng database cannot deserialize nested Struct using BLOB type Apr 23, 2023
@tianbocheng
Copy link
Author

tianbocheng commented Apr 23, 2023

当设置 HANDLE_INFO 表字段 VALUE 为 VARCHAR(1024) 发现写入数据为 16 进制数据,仍无法实现反序列化

DROP table  HANDLE_INFO ;
CREATE TABLE  HANDLE_INFO (
	ID INT IDENTITY (1, 1) NOT NULL,
	SUB_PREFIX VARCHAR(128),
	PREFIX VARCHAR(256),
	HANDLE_NAME VARCHAR(1024) NOT NULL,
	CREATE_TIME TIMESTAMP,
	UPDATE_TIME TIMESTAMP,
	VALUE VARCHAR(1024)   ,
	NOT CLUSTER PRIMARY KEY (ID)
);

handleInfo := &model.HandleInfoMysql{
		SubPrefix:  subPrefix,
		Prefix:     prefix,
		HandleName: handle,
		CreateTime: now,
		UpdateTime: now,
		Value:      *model.RecoveryValueMysql(valuesCore),
	}
_, err := g.DB().Model("handle_info").OmitEmptyData().Insert(handleInfo)

image

@gqcn gqcn added bug It is confirmed a bug, but don't worry, we'll handle it. help wanted labels Aug 21, 2023
@github-actions
Copy link

Hello @tianbocheng. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @tianbocheng。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I also encountered it today, but it still hasn't been solved as of the latest version, right?

@gqcn gqcn self-assigned this Feb 5, 2024
gqcn added a commit that referenced this issue Feb 5, 2024
@gqcn
Copy link
Member

gqcn commented Feb 5, 2024

#3303

@gqcn gqcn closed this as completed Feb 5, 2024
@gqcn gqcn added the done This issue is done, which may be release in next version. label Feb 5, 2024
oldme-git pushed a commit to oldme-git/gf that referenced this issue Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. help wanted
Projects
None yet
Development

No branches or pull requests

3 participants