add value string output
zhujintao opened this issue · 5 comments
zhujintao commented
rowdata.go
if isNull {
data[i].Type = FieldValueTypeNull
} else {
isUnsigned := f[i].Flag&UNSIGNED_FLAG != 0
data[i].str = v //add here
lance6716 commented
Hi, can you explain in which use case you meet the problem?
zhujintao commented
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 commented
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 commented
can also use like String() Raw()
methods to output the raw value v
, FieldValue.str
lance6716 commented
can also use like
String() Raw()
methods to output the raw valuev
,FieldValue.str
LGTM. Do you have time to write a PR for it? 😄