Skip to content

Commit

Permalink
Improve default names for BETWEEN ? AND ? to have prefixes from_ and to_
Browse files Browse the repository at this point in the history
issue #2277
  • Loading branch information
Jille committed Jun 24, 2023
1 parent 28696e5 commit 4fe183a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
17 changes: 11 additions & 6 deletions internal/compiler/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
}
}

number := 0
if pr, ok := n.Left.(*ast.ParamRef); ok {
number = pr.Number
}

for _, table := range tables {
schema := table.Schema
Expand All @@ -269,10 +265,19 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
if c, ok := typeMap[schema][table.Name][key]; ok {
defaultP := named.NewInferredParam(key, c.IsNotNull)
p, isNamed := params.FetchMerge(ref.ref.Number, defaultP)
var namePrefix string
if !isNamed {
if ref.ref == n.Left {
namePrefix = "from_"
} else if ref.ref == n.Right {
namePrefix = "to_"
}
}

a = append(a, Parameter{
Number: number,
Number: ref.ref.Number,
Column: &Column{
Name: p.Name(),
Name: namePrefix + p.Name(),
DataType: dataType(&c.Type),
NotNull: p.NotNull(),
Unsigned: c.IsUnsigned,
Expand Down
18 changes: 9 additions & 9 deletions internal/endtoend/testdata/between_args/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions internal/endtoend/testdata/between_args/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fe183a

Please sign in to comment.