Example #1
0
func validate_multi_second_select(dbt *DBTest, rows *sql.Rows) {
	if _, ok := rows.Sibling(); false == ok {
		dbt.Fatal("rows should have a another sibling.")
	}

	if false == rows.Next() {
		dbt.Fatalf("should be one row exists.\n")
	}

	if err := rows.Scan(&id, &fv, &id2); err != nil {
		dbt.Fatalf("should not get error :%s\n", err.Error())
	}

	if 323890472 != id {
		dbt.Fatalf("expect 323890472, but got %d\n", id)
	}

	if math.Abs(42342.43-float64(fv)) > 0.01 {
		dbt.Fatalf("expect 42342.432, but not got %+v\n", fv)
	}

	if rows.Next() {
		dbt.Fatal("rows should not have more than one row.")
	}

	if 298723987 != id2 {
		dbt.Fatalf("expect 298723987, but got %d\n", id2)
	}
}
Example #2
0
func validate_result_of_sp(dbt *DBTest, rows *sql.Rows) {

	// final OK packet , indicate last INSERT effected rows
	// https://dev.mysql.com/doc/internals/en/multi-resultset.html
	if res, ok := rows.Sibling(); false == ok {
		dbt.Fatal("there should be a last ok packet.")
	} else if nil == res {
		dbt.Fatal("last packet of CALL should return a Result.")
	} else {
		if affcted, err := res.RowsAffected(); nil != err {
			dbt.Fatal("should not return err when RowsAffected")
		} else if 1 != affcted {
			dbt.Fatal("Last INSERT STMT in SP should affected one row. ")
		}

		if insertId, err := res.LastInsertId(); nil != err {
			dbt.Fatal("should not return err when LastInsertId")
		} else if 0 != insertId {
			dbt.Fatalf("Last INSERT STMT in SP should not return LAST_INSERT_ID:%d ", insertId)
		}
		if true == rows.Next() {
			dbt.Fatal("last packet has no rows, but just affected rows and last insert id")
		}
	}

}