Skip to content

MYSQL using LIKE doesn't allow for wildcards #634

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

Closed
torrayne opened this issue Jul 28, 2020 · 2 comments · Fixed by #1162
Closed

MYSQL using LIKE doesn't allow for wildcards #634

torrayne opened this issue Jul 28, 2020 · 2 comments · Fixed by #1162
Labels
📚 mysql bug Something isn't working
Milestone

Comments

@torrayne
Copy link

The generated code asks for a int which prevents me from providing something like "10_" or "%10"

/* name: ListExtensions :many */
SELECT `id`,
    `student_id`,
    `length`,
    `created_at`
FROM `extensions`
WHERE `student_id` LIKE ?

Generated code

const listExtensions = `-- name: ListExtensions :many
select id, student_id, length, created_at from extensions where student_id like ? order by created_at desc limit 25
`

type ListExtensionsRow struct {
	ID        int       `json:"id"`
	StudentID int       `json:"student_id"`
	Length    int       `json:"length"`
	CreatedAt time.Time `json:"created_at"`
}

func (q *Queries) ListExtensions(ctx context.Context, student_id int) ([]ListExtensionsRow, error) {
	rows, err := q.query(ctx, q.listExtensionsStmt, listExtensions, student_id)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []ListExtensionsRow{}
	for rows.Next() {
		var i ListExtensionsRow
		if err := rows.Scan(
			&i.ID,
			&i.StudentID,
			&i.Length,
			&i.CreatedAt,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
@torrayne
Copy link
Author

Using the new mysql:beta engine LIKE just doesn't work at all.

@kyleconroy kyleconroy added the bug Something isn't working label Aug 17, 2020
@kyleconroy kyleconroy added this to the v1.6.0 milestone Aug 25, 2020
@kyleconroy kyleconroy removed this from the v2.0.0 milestone Nov 17, 2020
@kyleconroy
Copy link
Collaborator

Reproduced the error here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants