Skip to content

add value string output #821

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

Closed
zhujintao opened this issue Sep 18, 2023 · 5 comments · Fixed by #825
Closed

add value string output #821

zhujintao opened this issue Sep 18, 2023 · 5 comments · Fixed by #825

Comments

@zhujintao
Copy link

rowdata.go

if isNull {
	data[i].Type = FieldValueTypeNull
} else {
	isUnsigned := f[i].Flag&UNSIGNED_FLAG != 0
	data[i].str = v  //add here
@lance6716
Copy link
Collaborator

Hi, can you explain in which use case you meet the problem?

@zhujintao
Copy link
Author

simple and fast combination of string SQL statements, no need to determine the type.

values := make([]string, 0, len(row))
for _, v := range row {
	if v.Type == mysql.FieldValueTypeNull {
		values = append(values, "NULL")
	} else {
		values = append(values, fmt.Sprintf("'%s'", v.AsString()))
	}
}
// INSERT INTO xx VALUES ('a','b','1','2.0',NULL)

@lance6716
Copy link
Collaborator

I see that not all MySQL types implements AsString (for example, numbers uses FieldValue.value). So it does not totally solve the problem. And generally concatenating the SQL as string is a bad idea, it has security problems compared to letting SQL driver interpolate the arguments

@zhujintao
Copy link
Author

zhujintao commented Sep 19, 2023

can also use like String() Raw() methods to output the raw value v, FieldValue.str

@lance6716
Copy link
Collaborator

can also use like String() Raw() methods to output the raw value v, FieldValue.str

LGTM. Do you have time to write a PR for it? 😄

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

Successfully merging a pull request may close this issue.

2 participants