MCPcopy
hub / github.com/go-sql-driver/mysql / TestMultiResultSet

Function TestMultiResultSet

driver_test.go:2428–2566  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2426)
2427
2428func TestMultiResultSet(t *testing.T) {
2429 type result struct {
2430 values [][]int
2431 columns []string
2432 }
2433
2434 // checkRows is a helper test function to validate rows containing 3 result
2435 // sets with specific values and columns. The basic query would look like this:
2436 //
2437 // SELECT 1 AS col1, 2 AS col2 UNION SELECT 3, 4;
2438 // SELECT 0 UNION SELECT 1;
2439 // SELECT 1 AS col1, 2 AS col2, 3 AS col3 UNION SELECT 4, 5, 6;
2440 //
2441 // to distinguish test cases the first string argument is put in front of
2442 // every error or fatal message.
2443 checkRows := func(desc string, rows *sql.Rows, dbt *DBTest) {
2444 expected := []result{
2445 {
2446 values: [][]int{{1, 2}, {3, 4}},
2447 columns: []string{"col1", "col2"},
2448 },
2449 {
2450 values: [][]int{{1, 2, 3}, {4, 5, 6}},
2451 columns: []string{"col1", "col2", "col3"},
2452 },
2453 }
2454
2455 var res1 result
2456 for rows.Next() {
2457 var res [2]int
2458 if err := rows.Scan(&res[0], &res[1]); err != nil {
2459 dbt.Fatal(err)
2460 }
2461 res1.values = append(res1.values, res[:])
2462 }
2463
2464 cols, err := rows.Columns()
2465 if err != nil {
2466 dbt.Fatal(desc, err)
2467 }
2468 res1.columns = cols
2469
2470 if !reflect.DeepEqual(expected[0], res1) {
2471 dbt.Error(desc, "want =", expected[0], "got =", res1)
2472 }
2473
2474 if !rows.NextResultSet() {
2475 dbt.Fatal(desc, "expected next result set")
2476 }
2477
2478 // ignoring one result set
2479
2480 if !rows.NextResultSet() {
2481 dbt.Fatal(desc, "expected next result set")
2482 }
2483
2484 var res2 result
2485 cols, err = rows.Columns()

Callers

nothing calls this directly

Calls 11

ScanMethod · 0.80
ColumnsMethod · 0.80
mustQueryMethod · 0.80
mustExecMethod · 0.80
PrepareMethod · 0.80
NextMethod · 0.45
ErrorMethod · 0.45
NextResultSetMethod · 0.45
CloseMethod · 0.45
QueryMethod · 0.45

Tested by

no test coverage detected