Skip to content

The reflectx.Mapper from conn cannot be passed to stmt when creating stmt from conn #975

@liukaifei

Description

@liukaifei

I set tagMapFunc,but the reflectx.Mapper from conn cannot be passed to stmt when creating stmt from conn. The mapperFor function lacks handling for database connection (conn) types, which prevents the proper propagation of the reflectx.Mapper to statements created from connections.

func setDBTagMapper(db *sqlx.DB, dbtype DBType) {
	switch dbtype {
	case DBTypeDM, DBTypeORA:
		db.Mapper = reflectx.NewMapperTagFunc("db", nil, strings.ToUpper)
	}
}
my func
stmt, err := conn.PreparexContext(ctx, querySql)
if err != nil {
	t.Error(err)
}
defer stmt.Close()

func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error) {
	s, err := p.PrepareContext(ctx, query)
	if err != nil {
		return nil, err
	}
	return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
}
func mapperFor(i interface{}) *reflectx.Mapper {
	switch i := i.(type) {
	case DB:
		return i.Mapper
	case *DB:
		return i.Mapper
	case Tx:
		return i.Mapper
	case *Tx:
		return i.Mapper
	default:
		return mapper()
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions