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

executor: add placeholder count check in prepare stage (#7162) #7250

Merged
merged 5 commits into from Aug 3, 2018
Merged

executor: add placeholder count check in prepare stage (#7162) #7250

merged 5 commits into from Aug 3, 2018

Conversation

lysu
Copy link
Collaborator

@lysu lysu commented Aug 2, 2018

What have you changed? (mandatory)

cherry-pick #7162

Now, client will meet error when input parameter placeholder count > 65535 in exec stage
this PR add placeholder num check in prepare stage to return error more quick and more evident and make it compatible with mysql.

What is the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

  • uint tests
  • manual tests

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

no

Does this PR affect tidb-ansible update? (mandatory)

no

Does this PR need to be added to the release notes? (mandatory)

no

Refer to a related PR or issue link (optional)

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

run

package main

import "database/sql"

import (
	"bytes"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	_, err = db.Exec("drop table if exists t")
	if err != nil {
		panic(err)
	}

	_, err = db.Exec("create table t (v int)")
	if err != nil {
		panic(err)
	}

	const pc = 65535 + 2

	var param [pc]interface{}
	param[0] = 0
	var sqlBuilder bytes.Buffer
	sqlBuilder.WriteString("insert into t values (?)")
	for i := 0; i < pc-1; i++ {
		sqlBuilder.WriteString(",(?)")
		param[i+1] = i
	}

	stmt, err := db.Prepare(sqlBuilder.String())
	if err != nil {
		panic(err)
	}

	result, err := stmt.Exec(param[:]...)
	if err != nil {
		panic(err)
	}

	fmt.Println(result)

}

expect:

panic: Error 1390: Prepared statement contains too many placeholders

goroutine 1 [running]:
main.main()
	test/main.go:41 +0x3d2

but got:

panic: sql: expected 1 arguments, got 65537

goroutine 1 [running]:
main.main()
	test/main.go:46 +0x3c2

This change is Reviewable

@lysu lysu added type/2.0 cherry-pick type/bug-fix This PR fixes a bug. labels Aug 2, 2018
@lysu
Copy link
Collaborator Author

lysu commented Aug 2, 2018

/run-all-tests tidb-test=release-2.0 tikv=release-2.0 pd=release-2.0

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 2, 2018
Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@iamxy
Copy link
Member

iamxy commented Aug 2, 2018

/rebuild

@shenli
Copy link
Member

shenli commented Aug 2, 2018

/run-all-tests tidb-test=release-2.0 tikv=release-2.0 pd=release-2.0

@shenli shenli added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 2, 2018
@zz-jason zz-jason merged commit ad86390 into pingcap:release-2.0 Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note status/LGT2 Indicates that a PR has LGTM 2. type/bug-fix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants