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

Function TestExecPerQuerySimpleProtocol

conn_test.go:391–418  ·  conn_test.go::TestExecPerQuerySimpleProtocol
(t *testing.T)

Source from the content-addressed store, hash-verified

389}
390
391func TestExecPerQuerySimpleProtocol(t *testing.T) {
392 t.Parallel()
393
394 conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
395 defer closeConn(t, conn)
396
397 ctx := t.Context()
398
399 commandTag, err := conn.Exec(ctx, "create temporary table foo(name varchar primary key);")
400 if err != nil {
401 t.Fatal(err)
402 }
403 if commandTag.String() != "CREATE TABLE" {
404 t.Fatalf("Unexpected results from Exec: %v", commandTag)
405 }
406
407 commandTag, err = conn.Exec(ctx,
408 "insert into foo(name) values($1);",
409 pgx.QueryExecModeSimpleProtocol,
410 "bar'; drop table foo;--",
411 )
412 if err != nil {
413 t.Fatal(err)
414 }
415 if commandTag.String() != "INSERT 0 1" {
416 t.Fatalf("Unexpected results from Exec: %v", commandTag)
417 }
418}
419
420func TestPrepare(t *testing.T) {
421 t.Parallel()

Callers

nothing calls this directly

Calls 4

mustConnectStringFunction · 0.85
closeConnFunction · 0.70
ExecMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected