ziutek/mymysql — Issue #4: godrv Exec() creates new prepared statements
Author: coopernurse
Created: 2012-01-10 00:35:16+00:00
State: open

Here's a base test case that fails on my machine. Error message:

--- FAIL: godrv.TestTooManyStatements (51.87 seconds)
driver_test.go:11: Error: Received #1461 error from MySQL server: "Can't create more than max_prepared_stmt_count statements (current value: 16382)"

It looks like this is godrv related -- i was unable to repro this in native_test.go with a similar test against the native interface.

I haven't dug into the root cause yet. If you have time, please take a look. Otherwise I may get to this tomorrow.

// Add to: driver_test.go
func TestTooManyStatements(t *testing.T) {
db, err := sql.Open("mymysql", "test/testuser/TestPasswd9")
checkErr(t, err)
_, err = db.Exec("drop table if exists M")
checkErr(t, err)
_, err = db.Exec("create table M (id int primary key, str varchar(20))")
checkErr(t, err)

defer db.Exec("drop table M")
defer db.Close()

query := "insert into M (id, str) values (?, ?)"
insert, err := db.Prepare(query)
checkErr(t, err)
defer insert.Close()

for i := 0; i < 20000 && err == nil; i++ {
_, err = insert.Exec(i, "mystr")
checkErr(t, err)

if i % 100 == 0 {
fmt.Printf("Inserted %d rows\n", i)
}
}
}