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

Function TestEmbeddedLiteralsContext

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

Source from the content-addressed store, hash-verified

1303}
1304
1305func TestEmbeddedLiteralsContext(t *testing.T) {
1306 var schema = Schema{
1307 create: `
1308 CREATE TABLE x (
1309 k text
1310 );`,
1311 drop: `drop table x;`,
1312 }
1313
1314 RunWithSchemaContext(context.Background(), schema, t, func(ctx context.Context, db *DB, t *testing.T) {
1315 type t1 struct {
1316 K *string
1317 }
1318 type t2 struct {
1319 Inline struct {
1320 F string
1321 }
1322 K *string
1323 }
1324
1325 db.MustExecContext(ctx, db.Rebind("INSERT INTO x (k) VALUES (?), (?), (?);"), "one", "two", "three")
1326
1327 target := t1{}
1328 err := db.GetContext(ctx, &target, db.Rebind("SELECT * FROM x WHERE k=?"), "one")
1329 if err != nil {
1330 t.Error(err)
1331 }
1332 if *target.K != "one" {
1333 t.Error("Expected target.K to be `one`, got ", target.K)
1334 }
1335
1336 target2 := t2{}
1337 err = db.GetContext(ctx, &target2, db.Rebind("SELECT * FROM x WHERE k=?"), "one")
1338 if err != nil {
1339 t.Error(err)
1340 }
1341 if *target2.K != "one" {
1342 t.Errorf("Expected target2.K to be `one`, got `%v`", target2.K)
1343 }
1344 })
1345}
1346
1347func TestConn(t *testing.T) {
1348 var schema = Schema{

Callers

nothing calls this directly

Calls 6

RunWithSchemaContextFunction · 0.85
ErrorMethod · 0.80
ErrorfMethod · 0.80
RebindMethod · 0.65
MustExecContextMethod · 0.45
GetContextMethod · 0.45

Tested by

no test coverage detected