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

database/gdb: fix confusing error message in Insert/Update operations when table not exist or the table contains no fields #3553

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wln32
Copy link
Member

@wln32 wln32 commented Apr 30, 2024

当 更新/插入操作时,表字段数量为0,直接返回error,不在后续操作,具体请看 #3554

@wln32 wln32 requested a review from gqcn April 30, 2024 03:16
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)
Copy link
Member

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行可以增加完全过滤后的报错。
  • 缺少单测。

@gqcn gqcn changed the title database/gdb: 更新/插入操作时,表字段数量为0,直接返回error database/gdb: fix confusing error message when table not exist or the table contains no fields May 7, 2024
@gqcn gqcn changed the title database/gdb: fix confusing error message when table not exist or the table contains no fields database/gdb: fix confusing error message in Insert/Update operations when table not exist or the table contains no fields May 7, 2024
database/gdb/gdb_core_structure.go Show resolved Hide resolved
@@ -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`)
Copy link
Member

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)

Copy link
Member Author

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放到最后面

Copy link
Member

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)

Copy link
Member Author

@wln32 wln32 May 16, 2024

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“”

@@ -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`)
Copy link
Member

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)

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