| 1691 | } |
| 1692 | |
| 1693 | func TestEmbeddedLiterals(t *testing.T) { |
| 1694 | var schema = Schema{ |
| 1695 | create: ` |
| 1696 | CREATE TABLE x ( |
| 1697 | k text |
| 1698 | );`, |
| 1699 | drop: `drop table x;`, |
| 1700 | } |
| 1701 | |
| 1702 | RunWithSchema(schema, t, func(db *DB, t *testing.T, now string) { |
| 1703 | type t1 struct { |
| 1704 | K *string |
| 1705 | } |
| 1706 | type t2 struct { |
| 1707 | Inline struct { |
| 1708 | F string |
| 1709 | } |
| 1710 | K *string |
| 1711 | } |
| 1712 | |
| 1713 | db.MustExec(db.Rebind("INSERT INTO x (k) VALUES (?), (?), (?);"), "one", "two", "three") |
| 1714 | |
| 1715 | target := t1{} |
| 1716 | err := db.Get(&target, db.Rebind("SELECT * FROM x WHERE k=?"), "one") |
| 1717 | if err != nil { |
| 1718 | t.Error(err) |
| 1719 | } |
| 1720 | if *target.K != "one" { |
| 1721 | t.Error("Expected target.K to be `one`, got ", target.K) |
| 1722 | } |
| 1723 | |
| 1724 | target2 := t2{} |
| 1725 | err = db.Get(&target2, db.Rebind("SELECT * FROM x WHERE k=?"), "one") |
| 1726 | if err != nil { |
| 1727 | t.Error(err) |
| 1728 | } |
| 1729 | if *target2.K != "one" { |
| 1730 | t.Errorf("Expected target2.K to be `one`, got `%v`", target2.K) |
| 1731 | } |
| 1732 | }) |
| 1733 | } |
| 1734 | |
| 1735 | func BenchmarkBindStruct(b *testing.B) { |
| 1736 | b.StopTimer() |