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

Function TestExecMultipleResults

driver_test.go:2587–2622  ·  driver_test.go::TestExecMultipleResults
(t *testing.T)

Source from the content-addressed store, hash-verified

2585}
2586
2587func TestExecMultipleResults(t *testing.T) {
2588 ctx := context.Background()
2589 runTestsWithMultiStatement(t, dsn, func(dbt *DBTest) {
2590 dbt.mustExec(`
2591 CREATE TABLE test (
2592 id INT NOT NULL AUTO_INCREMENT,
2593 value VARCHAR(255),
2594 PRIMARY KEY (id)
2595 )`)
2596 conn, err := dbt.db.Conn(ctx)
2597 if err != nil {
2598 t.Fatalf("failed to connect: %v", err)
2599 }
2600 conn.Raw(func(conn any) error {
2601 //lint:ignore SA1019 this is a test
2602 ex := conn.(driver.Execer)
2603 res, err := ex.Exec(`
2604 INSERT INTO test (value) VALUES ('a'), ('b');
2605 INSERT INTO test (value) VALUES ('c'), ('d'), ('e');
2606 `, nil)
2607 if err != nil {
2608 t.Fatalf("insert statements failed: %v", err)
2609 }
2610 mres := res.(Result)
2611 if got, want := mres.AllRowsAffected(), []int64{2, 3}; !reflect.DeepEqual(got, want) {
2612 t.Errorf("bad AllRowsAffected: got %v, want=%v", got, want)
2613 }
2614 // For INSERTs containing multiple rows, LAST_INSERT_ID() returns the
2615 // first inserted ID, not the last.
2616 if got, want := mres.AllLastInsertIds(), []int64{1, 3}; !reflect.DeepEqual(got, want) {
2617 t.Errorf("bad AllLastInsertIds: got %v, want %v", got, want)
2618 }
2619 return nil
2620 })
2621 })
2622}
2623
2624// tests if rows are set in a proper state if some results were ignored before
2625// calling rows.NextResultSet.

Callers

nothing calls this directly

Calls 5

mustExecMethod · 0.80
AllRowsAffectedMethod · 0.65
AllLastInsertIdsMethod · 0.65
ExecMethod · 0.45

Tested by

no test coverage detected