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

If it contains the "?" character, gdb.Raw generates an error SQL #3525

Closed
lijianbj opened this issue Apr 20, 2024 · 1 comment
Closed

If it contains the "?" character, gdb.Raw generates an error SQL #3525

lijianbj opened this issue Apr 20, 2024 · 1 comment
Labels

Comments

@lijianbj
Copy link

lijianbj commented Apr 20, 2024

What version of Go and system type/arch are you using?
go version go1.21.4 darwin/arm64

What version of GoFrame are you using?
v2.5.7

Can this bug be re-produced with the latest release?
yes

What did you do?

setting := g.Map{
		"url": "https://www.xxx.com?v=2.3",
	}
	data := g.Map{
		dao.Client.Columns().Setting: gdb.Raw(fmt.Sprintf("%s||'%s'", dao.Client.Columns().Setting, gjson.New(setting).MustToJsonString())),
	}
	if _, err := dao.Client.Ctx(ctx).Update(data, dao.Client.Columns().Id, req.ID); err != nil {
		return err
	}

What did you expect to see?
Looking forward to the success of the execution

What did you see instead?
Bad SQL was generated:The character "?" cannot be parsed。Remove the “?” character to execute successfully

UPDATE "client" SET "updated_at"='2024-04-20 21:09:25',"setting"=setting||'{"url":"https://www.xxx.com81346976072401993v=2.3"}' WHERE ("id"=$3) AND "deleted_at" IS NULL
Error: pq: could not determine data type of parameter $2

@lijianbj lijianbj added the bug It is confirmed a bug, but don't worry, we'll handle it. label Apr 20, 2024
@oldme-git oldme-git added question and removed bug It is confirmed a bug, but don't worry, we'll handle it. labels Apr 21, 2024
@oldme-git
Copy link
Member

oldme-git commented Apr 21, 2024

@lijianbj You have to use correct SQL value that Go Standard library can accept.

setting := g.Map{
	"url": "https://www.xxx.com?v=2.5",
}
ss := gjson.New(setting).MustToJsonString()
ss = strings.Replace(ss, "\"", "\\\"", -1)

data := g.Map{
	"setting": gdb.Raw(fmt.Sprintf("\"%s||'%s'\"", "setting", ss)),
}

wln32 added a commit to wln32/gf that referenced this issue Apr 22, 2024
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

2 participants