MySQL 列属性为 JSON 时,若此列未设值,则跳过插入,避免引起错误:Invalid JSON text: "The document is empty." at position 0 in value
This commit is contained in:
parent
3180c418c2
commit
7ec9d5c0a2
|
@ -304,6 +304,7 @@ func (db *mysql) SQLType(c *schemas.Column) string {
|
||||||
c.Length = 40
|
c.Length = 40
|
||||||
case schemas.Json:
|
case schemas.Json:
|
||||||
res = schemas.Text
|
res = schemas.Text
|
||||||
|
c.IsJSON = true
|
||||||
case schemas.UnsignedInt:
|
case schemas.UnsignedInt:
|
||||||
res = schemas.Int
|
res = schemas.Int
|
||||||
isUnsigned = true
|
isUnsigned = true
|
||||||
|
|
|
@ -501,6 +501,10 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if col.IsJSON && fieldValue.String() == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// !evalphobia! set fieldValue as nil when column is nullable and zero-value
|
// !evalphobia! set fieldValue as nil when column is nullable and zero-value
|
||||||
if _, ok := getFlagForColumn(session.statement.NullableMap, col); ok {
|
if _, ok := getFlagForColumn(session.statement.NullableMap, col); ok {
|
||||||
if col.Nullable && utils.IsValueZero(fieldValue) {
|
if col.Nullable && utils.IsValueZero(fieldValue) {
|
||||||
|
|
Loading…
Reference in New Issue