You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Description
typeDatastruct{
IDint64IntColint64
}
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 lowercasepgsql.Exec(ctx, fmt.Sprintf(createSql, tableName))
//Insert data//Write any datavardata=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 (c *Core) mappingAndFilterData This method will get all the fields of the table, and then compare it with the field name of the structure to be inserted, and delete the ones that do not exist, but because the table I passed in during the Insert operation The name is not all lowercase, so the field cannot be found and no error is returned. As a result, when inserting later, there is no data and an error is reported.
// when inserting
// when updating
Additional
No response
Issues-translate-bot
changed the title
database/gdb: 当(更新/插入)操作时,如果数据表字段数量为0,直接返回错误
database/gdb: When (update/insert) operation, if the number of fields in the data table is 0, an error will be returned directly
Apr 30, 2024
Description
经过调试后发现
(c *Core) mappingAndFilterData
这个方法会获取表的所有字段,然后和要插入的结构体字段名做对比,删掉不存在的,但是由于我在Insert操作时传入的表名不是全小写的,所以查不到字段,也没有返回错误,导致后面在Insert时,没有数据,然后报错// 插入时
// 更新时
Additional
No response
The text was updated successfully, but these errors were encountered: