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

Avoid a conflict between possible named params & map as param #424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions gorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,21 @@ func extractExecutorAndContext(e SqlExecutor) (executor, context.Context) {
// as input to a named query. If so, it rewrites the query to use
// dialect-dependent bindvars and instantiates the corresponding slice of
// parameters by extracting data from the map / struct.
// If not, returns the input values unchanged.
// If not or if the first arg is a time.Time or implements
// driver.Valuer, returns the input values unchanged.
func maybeExpandNamedQuery(m *DbMap, query string, args []interface{}) (string, []interface{}) {
var (
arg = args[0]
argval = reflect.ValueOf(arg)
)
arg := args[0]

switch arg.(type) {
case time.Time:
// time.Time is driver.Value
return query, args
case driver.Valuer:
// driver.Valuer will be converted to driver.Value.
return query, args
}

argval := reflect.ValueOf(arg)
if argval.Kind() == reflect.Ptr {
argval = argval.Elem()
}
Expand All @@ -221,14 +230,6 @@ func maybeExpandNamedQuery(m *DbMap, query string, args []interface{}) (string,
if argval.Kind() != reflect.Struct {
return query, args
}
if _, ok := arg.(time.Time); ok {
// time.Time is driver.Value
return query, args
}
if _, ok := arg.(driver.Valuer); ok {
// driver.Valuer will be converted to driver.Value.
return query, args
}

return expandNamedQuery(m, query, argval.FieldByName)
}
Expand Down