|
|
@@ -101,6 +101,41 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
|
|
|
return rows
|
|
|
}
|
|
|
|
|
|
+func TestReuseClosedConnection(t *testing.T) {
|
|
|
+ // this test does not use sql.database, it uses the driver directly
|
|
|
+ if !available {
|
|
|
+ t.Logf("MySQL-Server not running on %s. Skipping TestReuseClosedConnection", netAddr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ driver := &mysqlDriver{}
|
|
|
+ conn, err := driver.Open(dsn)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Error connecting: %s", err.Error())
|
|
|
+ }
|
|
|
+ stmt, err := conn.Prepare("DO 1")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Error preparing statement: %s", err.Error())
|
|
|
+ }
|
|
|
+ _, err = stmt.Exec(nil)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Error executing statement: %s", err.Error())
|
|
|
+ }
|
|
|
+ err = conn.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Error closing connection: %s", err.Error())
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err := recover(); err != nil {
|
|
|
+ t.Errorf("Panic after reusing a closed connection: %v", err)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ _, err = stmt.Exec(nil)
|
|
|
+ if err != nil && err != errInvalidConn {
|
|
|
+ t.Errorf("Unexpected error '%s', expected '%s'",
|
|
|
+ err.Error(), errInvalidConn.Error())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestCharset(t *testing.T) {
|
|
|
mustSetCharset := func(charsetParam, expected string) {
|
|
|
db, err := sql.Open("mysql", strings.Replace(dsn, charset, charsetParam, 1))
|
|
|
@@ -578,6 +613,16 @@ func TestNULL(t *testing.T) {
|
|
|
dbt.Error("Unexpected NullString value:" + ns.String + " (should be `1`)")
|
|
|
}
|
|
|
|
|
|
+ // bytes
|
|
|
+ // Check input==output with input!=nil
|
|
|
+ b := []byte("")
|
|
|
+ if err = dbt.db.QueryRow("SELECT ?", b).Scan(&b); err != nil {
|
|
|
+ dbt.Fatal(err)
|
|
|
+ }
|
|
|
+ if b == nil {
|
|
|
+ dbt.Error("nil echo from non-nil input")
|
|
|
+ }
|
|
|
+
|
|
|
// Insert NULL
|
|
|
dbt.mustExec("CREATE TABLE test (dummmy1 int, value int, dummy2 int)")
|
|
|
|