-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: When (update/insert) operation, if the number of fields in the data table is 0, an error will be returned directly #3554
Comments
Descriptiontype Data struct{
ID int64
IntCol int64
}
createSql:=`CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
int_col INT);`
pgsql := g.DB("pgsql")
tableName := "Type_Table_" + gtime.Now().TimestampMilliStr()
// pgsql will convert the table name to lowercase
pgsql.Exec(ctx, fmt.Sprintf(createSql, tableName))
//Insert data
//Write any data
var data = Data {
Id:1,
IntCol:2,
}
// The tableName here is the same variable as above.
_, err := pgsql.Model(tableName).Data(data).Insert()
fmt.Println(err)
//output:
// INSERT INTO "Type_Table_1714453562918"("") VALUES() : pq: delimiter identifier of length 0 at or near """"
// The error given is confusing
// When the table name is the same as the one that just created the table, after randomly inserting a piece of data into the table
// update data,
_, err = pgsql.Model(tableName).Where("id", 1).Data(g.Map{
"int_col": 9999,
}).Update()
fmt.Printf("%+v\n", err)
//output:
// data cannot be empty
// The error given is also confusing After debugging, I found that AdditionalNo response |
Description
经过调试后发现
(c *Core) mappingAndFilterData
这个方法会获取表的所有字段,然后和要插入的结构体字段名做对比,删掉不存在的,但是由于我在Insert操作时传入的表名不是全小写的,所以查不到字段,也没有返回错误,导致后面在Insert时,没有数据,然后报错// 插入时
// 更新时
Additional
No response
The text was updated successfully, but these errors were encountered: