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
gdb/gdb_core: issue title When cross-database query is not done using Schema, the corresponding table structure fields cannot be obtained correctly; if you want to add a parameter, you can directly use data as the table field.
#3879
Open
yimuysl001 opened this issue
Oct 22, 2024
· 4 comments
_, err:=g.DB("local").Model("BAK..TBA").Data(map[string]interface{}{
"id": 2,
"name": "aaa",
}).Insert()
fmt.Println(err) //报错 The table "BAK".."TBA" may not exist, or the table contains no fields_, err=g.DB("local").Schema("BAK").Model("TBA").Data(map[string]interface{}{
"id": 2,
"name": "aaa",
}).Insert()
fmt.Println(err) //处理成功
Additional
func (c*Core) mappingAndFilterData(ctx context.Context, schema, tablestring, datamap[string]interface{}, filterbool) (map[string]interface{}, error) {
// 是否可以直接从table中把 schema 拆出来,fieldsMap, err:=c.db.TableFields(ctx, c.guessPrimaryTableName(table), schema)
iferr!=nil {
returnnil, err
}
iflen(fieldsMap) ==0 {
// 或者没查到数据使用data的key ,而不是直接报错returnnil, gerror.Newf(`The table %s may not exist, or the table contains no fields`, table)
}
fieldsKeyMap:=make(map[string]interface{}, len(fieldsMap))
fork:=rangefieldsMap {
fieldsKeyMap[k] =nil
}
// Automatic data key to table field name mapping.varfoundKeystringfordataKey, dataValue:=rangedata {
if_, ok:=fieldsKeyMap[dataKey]; !ok {
foundKey, _=gutil.MapPossibleItemByKey(fieldsKeyMap, dataKey)
iffoundKey!="" {
if_, ok=data[foundKey]; !ok {
data[foundKey] =dataValue
}
delete(data, dataKey)
}
}
}
// Data filtering.// It deletes all key-value pairs that has incorrect field name.iffilter {
fordataKey:=rangedata {
if_, ok:=fieldsMap[dataKey]; !ok {
delete(data, dataKey)
}
}
iflen(data) ==0 {
returnnil, gerror.Newf(`input data match no fields in table %s`, table)
}
}
returndata, nil
}
func (c*Core) fieldsToSequence(ctx context.Context, tablestring, fields []string) ([]string, error) {
var (
fieldSet=gset.NewStrSetFrom(fields)
fieldsResultInSequence=make([]string, 0)
tableFields, err=c.db.TableFields(ctx, table)
)
iferr!=nil {
returnnil, err
}
/****/// todo 希望如果没查询到字段,能返回fieldsiflen(tableFields)<1 {
returnfields,nil
}
/****/// Sort the fields in order.varfieldsOfTableInSequence=make([]string, len(tableFields))
for_, field:=rangetableFields {
fieldsOfTableInSequence[field.Index] =field.Name
}
// Sort the input fields.for_, fieldName:=rangefieldsOfTableInSequence {
iffieldSet.Contains(fieldName) {
fieldsResultInSequence=append(fieldsResultInSequence, fieldName)
}
}
returnfieldsResultInSequence, nil
}
The text was updated successfully, but these errors were encountered:
Issues-translate-bot
changed the title
gdb/gdb_core: issue title 不使用Schema 跨库查询时,无法正确获取到相应的表结构字段;希望添加一个参数,可以直接使用data作为表字段
gdb/gdb_core: issue title When cross-database query is not done using Schema, the corresponding table structure fields cannot be obtained correctly; if you want to add a parameter, you can directly use data as the table field.
Oct 22, 2024
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
@yimuysl001 Hello, we like your suggestion very much. Please submit the complete minimum runnable code. If the evaluation can be developed, we can use it as a single test verification.
Description
不使用Schema 跨库查询时
(使用事务时无法正确切换到相应的库)
,无法正确获取到相应的表结构字段;希望添加一个参数,可以直接使用data作为表字段Additional
The text was updated successfully, but these errors were encountered: