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

Function TestIssue197Context

sqlx_context_test.go:1170–1209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1168}
1169
1170func TestIssue197Context(t *testing.T) {
1171 // this test actually tests for a bug in database/sql:
1172 // https://github.com/golang/go/issues/13905
1173 // this potentially makes _any_ named type that is an alias for []byte
1174 // unsafe to use in a lot of different ways (basically, unsafe to hold
1175 // onto after loading from the database).
1176 t.Skip()
1177
1178 type mybyte []byte
1179 type Var struct{ Raw json.RawMessage }
1180 type Var2 struct{ Raw []byte }
1181 type Var3 struct{ Raw mybyte }
1182 RunWithSchemaContext(context.Background(), defaultSchema, t, func(ctx context.Context, db *DB, t *testing.T) {
1183 var err error
1184 var v, q Var
1185 if err = db.GetContext(ctx, &v, `SELECT '{"a": "b"}' AS raw`); err != nil {
1186 t.Fatal(err)
1187 }
1188 if err = db.GetContext(ctx, &q, `SELECT 'null' AS raw`); err != nil {
1189 t.Fatal(err)
1190 }
1191
1192 var v2, q2 Var2
1193 if err = db.GetContext(ctx, &v2, `SELECT '{"a": "b"}' AS raw`); err != nil {
1194 t.Fatal(err)
1195 }
1196 if err = db.GetContext(ctx, &q2, `SELECT 'null' AS raw`); err != nil {
1197 t.Fatal(err)
1198 }
1199
1200 var v3, q3 Var3
1201 if err = db.QueryRowContext(ctx, `SELECT '{"a": "b"}' AS raw`).Scan(&v3.Raw); err != nil {
1202 t.Fatal(err)
1203 }
1204 if err = db.QueryRowContext(ctx, `SELECT '{"c": "d"}' AS raw`).Scan(&q3.Raw); err != nil {
1205 t.Fatal(err)
1206 }
1207 t.Fail()
1208 })
1209}
1210
1211func TestInContext(t *testing.T) {
1212 // some quite normal situations

Callers

nothing calls this directly

Calls 4

RunWithSchemaContextFunction · 0.85
QueryRowContextMethod · 0.80
ScanMethod · 0.65
GetContextMethod · 0.45

Tested by

no test coverage detected