MCPcopy
hub / github.com/jackc/pgx / TestConnExecInsertByteSliceIntoJSON

Function TestConnExecInsertByteSliceIntoJSON

stdlib/sql_test.go:599–628  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

597}
598
599func 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
630func TestTransactionLifeCycle(t *testing.T) {
631 testWithAllQueryExecModes(t, func(t *testing.T, db *sql.DB) {

Callers

nothing calls this directly

Calls 5

openDBFunction · 0.85
closeDBFunction · 0.85
ExecMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected