MCPcopy
hub / github.com/jmoiron/sqlx / TestScanErrorContext

Function TestScanErrorContext

sqlx_context_test.go:694–726  ·  sqlx_context_test.go::TestScanErrorContext
(t *testing.T)

Source from the content-addressed store, hash-verified

692}
693
694func TestScanErrorContext(t *testing.T) {
695 var schema = Schema{
696 create: `
697 CREATE TABLE kv (
698 k text,
699 v integer
700 );`,
701 drop: `drop table kv;`,
702 }
703
704 RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) {
705 type WrongTypes struct {
706 K int
707 V string
708 }
709 _, err := db.Exec(db.Rebind("INSERT INTO kv (k, v) VALUES (?, ?)"), "hi", 1)
710 if err != nil {
711 t.Error(err)
712 }
713
714 rows, err := db.QueryxContext(ctx, "SELECT * FROM kv")
715 if err != nil {
716 t.Error(err)
717 }
718 for rows.Next() {
719 var wt WrongTypes
720 err := rows.StructScan(&wt)
721 if err == nil {
722 t.Errorf("%s: Scanning wrong types into keys should have errored.", db.DriverName())
723 }
724 }
725 })
726}
727
728// FIXME: this function is kinda big but it slows things down to be constantly
729// loading and reloading the schema..

Callers

nothing calls this directly

Calls 9

RunWithSchemaContextFunction · 0.85
ErrorMethod · 0.80
NextMethod · 0.80
ErrorfMethod · 0.80
ExecMethod · 0.65
RebindMethod · 0.65
QueryxContextMethod · 0.65
DriverNameMethod · 0.65
StructScanMethod · 0.45

Tested by

no test coverage detected