| 597 | } |
| 598 | |
| 599 | func TestConnExecInsertByteSliceIntoJSON(t *testing.T) { |
| 600 | // Not testing with simple protocol because there is no way for that to work. A []byte will be considered binary data |
| 601 | // that needs to escape. No way to know whether the destination is really a text compatible or a bytea. |
| 602 | |
| 603 | db := openDB(t) |
| 604 | defer closeDB(t, db) |
| 605 | |
| 606 | _, err := db.Exec(` |
| 607 | create temporary table docs( |
| 608 | body json not null |
| 609 | ); |
| 610 | `) |
| 611 | require.NoError(t, err) |
| 612 | |
| 613 | expected := []byte(`{"foo": "bar"}`) |
| 614 | |
| 615 | _, err = db.Exec(`insert into docs(body) values($1)`, expected) |
| 616 | require.NoError(t, err) |
| 617 | |
| 618 | var actual []byte |
| 619 | err = db.QueryRow(`select body from docs`).Scan(&actual) |
| 620 | require.NoError(t, err) |
| 621 | |
| 622 | if !bytes.Equal(actual, expected) { |
| 623 | t.Errorf(`Expected "%v", got "%v"`, string(expected), string(actual)) |
| 624 | } |
| 625 | |
| 626 | _, err = db.Exec(`drop table docs`) |
| 627 | require.NoError(t, err) |
| 628 | } |
| 629 | |
| 630 | func TestTransactionLifeCycle(t *testing.T) { |
| 631 | testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) { |