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
database/gdb: fix confusing error message in Insert/Update operations when table not exist or the table contains no fields #3553
base: master
Are you sure you want to change the base?
Conversation
database/gdb/gdb_core_structure.go
Outdated
if toLowerTableName == table { | ||
return nil, gerror.Newf("The table %s may not exist, or the field is 0", table) | ||
} | ||
return nil, gerror.Newf("The table %s may not exist, or the field is 0, you can try %s", table, toLowerTableName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 不用增加表名称的大小写判断逻辑,这里直接报错即可:
`The table "%s" may not exist, or the table contains no fields`
- 下面的
415
行可以增加完全过滤后的报错。 - 缺少单测。
database/gdb/gdb_core_structure.go
Outdated
@@ -406,6 +409,9 @@ func (c *Core) mappingAndFilterData(ctx context.Context, schema, table string, d | |||
delete(data, dataKey) | |||
} | |||
} | |||
if len(data) == 0 { | |||
return nil, gerror.Newf(`The insert/update fields are filtered and have a quantity of 0`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这里要把data keys
作为数组[]string
拿出来放到错误提示中:
gerror.Newf(`input data keys "%v" match no fields in table "%s"`, dataKeys, table)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这里要把
data keys
作为数组[]string
拿出来放到错误提示中:gerror.Newf(`input data keys "%v" match no fields in table "%s"`, dataKeys, table)
不需要吧,要是太长了,影响阅读体验,或者可以把keys放到最后面
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这里要把
data keys
作为数组[]string
拿出来放到错误提示中:gerror.Newf(`input data keys "%v" match no fields in table "%s"`, dataKeys, table)不需要吧,要是太长了,影响阅读体验,或者可以把keys放到最后面
那么就简化一下gerror.Newf(`input data match no fields in table "%s"`, table)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这里要把
data keys
作为数组[]string
拿出来放到错误提示中:gerror.Newf(`input data keys "%v" match no fields in table "%s"`, dataKeys, table)不需要吧,要是太长了,影响阅读体验,或者可以把keys放到最后面
那么就简化一下
gerror.Newf(`input data match no fields in table "%s"`, table)
ok,我没有给table加引号,因为到这里的时候table已经有引号了貌似,在使用"%s" 格式的输出会变成“”table“”
database/gdb/gdb_core_structure.go
Outdated
@@ -406,6 +409,9 @@ func (c *Core) mappingAndFilterData(ctx context.Context, schema, table string, d | |||
delete(data, dataKey) | |||
} | |||
} | |||
if len(data) == 0 { | |||
return nil, gerror.Newf(`The insert/update fields are filtered and have a quantity of 0`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这里要把
data keys
作为数组[]string
拿出来放到错误提示中:gerror.Newf(`input data keys "%v" match no fields in table "%s"`, dataKeys, table)不需要吧,要是太长了,影响阅读体验,或者可以把keys放到最后面
那么就简化一下gerror.Newf(`input data match no fields in table "%s"`, table)
当 更新/插入操作时,表字段数量为0,直接返回error,不在后续操作,具体请看 #3554