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

INSERT statements cannot be prepared with sql.DB.Prepare() #170

Closed
ohaibbq opened this issue Feb 20, 2024 · 0 comments · Fixed by #171
Closed

INSERT statements cannot be prepared with sql.DB.Prepare() #170

ohaibbq opened this issue Feb 20, 2024 · 0 comments · Fixed by #171

Comments

@ohaibbq
Copy link
Contributor

ohaibbq commented Feb 20, 2024

We currently validate that the number of args passed matches the number of parameters for the query. When using prepared statements, arguments do not need to be passed until the query is executed.

Example:

	columnsWithEscape := []string{"`foo`", "`bar`"}
	placeholders := []string{"?", "?"}
	query := fmt.Sprintf(
		"INSERT `%s` (%s) VALUES (%s)",
		r.tablePath(projectID, datasetID, table.ID),
		strings.Join(columnsWithEscape, ","),
		strings.Join(placeholders, ","),
	)
	stmt, err := tx.Tx().PrepareContext(ctx, query)

Expected: a stmt is returned
Actual: err not enough query arguments is returned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant