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

Function TestMultiQuery

driver_test.go:451–494  ·  driver_test.go::TestMultiQuery
(t *testing.T)

Source from the content-addressed store, hash-verified

449}
450
451func TestMultiQuery(t *testing.T) {
452 runTestsWithMultiStatement(t, dsn, func(dbt *DBTest) {
453 // Create Table
454 dbt.mustExec("CREATE TABLE `test` (`id` int(11) NOT NULL, `value` int(11) NOT NULL) ")
455
456 // Create Data
457 res := dbt.mustExec("INSERT INTO test VALUES (1, 1)")
458 count, err := res.RowsAffected()
459 if err != nil {
460 dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error())
461 }
462 if count != 1 {
463 dbt.Fatalf("expected 1 affected row, got %d", count)
464 }
465
466 // Update
467 res = dbt.mustExec("UPDATE test SET value = 3 WHERE id = 1; UPDATE test SET value = 4 WHERE id = 1; UPDATE test SET value = 5 WHERE id = 1;")
468 count, err = res.RowsAffected()
469 if err != nil {
470 dbt.Fatalf("res.RowsAffected() returned error: %s", err.Error())
471 }
472 if count != 1 {
473 dbt.Fatalf("expected 1 affected row, got %d", count)
474 }
475
476 // Read
477 var out int
478 rows := dbt.mustQuery("SELECT value FROM test WHERE id=1;")
479 if rows.Next() {
480 rows.Scan(&out)
481 if out != 5 {
482 dbt.Errorf("expected 5, got %d", out)
483 }
484
485 if rows.Next() {
486 dbt.Error("unexpected data")
487 }
488 } else {
489 dbt.Error("no data")
490 }
491 rows.Close()
492
493 })
494}
495
496func TestInt(t *testing.T) {
497 runTestsParallel(t, dsn, func(dbt *DBTest, tbl string) {

Callers

nothing calls this directly

Calls 8

mustExecMethod · 0.80
RowsAffectedMethod · 0.80
mustQueryMethod · 0.80
ScanMethod · 0.80
ErrorMethod · 0.45
NextMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected