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

Function TestExec

conn_test.go:220–255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestExec(t *testing.T) {
221 t.Parallel()
222
223 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
224 defer cancel()
225
226 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
227 if results := mustExec(t, conn, "create temporary table foo(id integer primary key);"); results.String() != "CREATE TABLE" {
228 t.Error("Unexpected results from Exec")
229 }
230
231 // Accept parameters
232 if results := mustExec(t, conn, "insert into foo(id) values($1)", 1); results.String() != "INSERT 0 1" {
233 t.Errorf("Unexpected results from Exec: %v", results)
234 }
235
236 if results := mustExec(t, conn, "drop table foo;"); results.String() != "DROP TABLE" {
237 t.Error("Unexpected results from Exec")
238 }
239
240 // Multiple statements can be executed -- last command tag is returned
241 if results := mustExec(t, conn, "create temporary table foo(id serial primary key); drop table foo;"); results.String() != "DROP TABLE" {
242 t.Error("Unexpected results from Exec")
243 }
244
245 // Can execute longer SQL strings than sharedBufferSize
246 if results := mustExec(t, conn, strings.Repeat("select 42; ", 1000)); results.String() != "SELECT 1" {
247 t.Errorf("Unexpected results from Exec: %v", results)
248 }
249
250 // Exec no-op which does not return a command tag
251 if results := mustExec(t, conn, "--;"); results.String() != "" {
252 t.Errorf("Unexpected results from Exec: %v", results)
253 }
254 })
255}
256
257type testQueryRewriter struct {
258 sql string

Callers

nothing calls this directly

Calls 4

RunWithQueryExecModesFunction · 0.92
mustExecFunction · 0.85
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected