TestMultipleStatements is a test for: https://github.com/dolthub/doltgresql/issues/2175
(t *testing.T)
| 28 | |
| 29 | // TestMultipleStatements is a test for: https://github.com/dolthub/doltgresql/issues/2175 |
| 30 | func TestMultipleStatements(t *testing.T) { |
| 31 | ctx := context.Background() |
| 32 | var conn *Connection |
| 33 | if runOnPostgres { |
| 34 | pgxConn, err := pgx.Connect(ctx, "postgres://postgres:password@127.0.0.1:5432/postgres?sslmode=disable") |
| 35 | require.NoError(t, err) |
| 36 | conn = &Connection{ |
| 37 | Default: pgxConn, |
| 38 | Current: pgxConn, |
| 39 | } |
| 40 | require.NoError(t, pgxConn.Ping(ctx)) |
| 41 | defer func() { |
| 42 | conn.Close(ctx) |
| 43 | }() |
| 44 | } else { |
| 45 | var controller *svcs.Controller |
| 46 | ctx, conn, controller = CreateServer(t, "postgres") |
| 47 | defer func() { |
| 48 | conn.Close(ctx) |
| 49 | controller.Stop() |
| 50 | err := controller.WaitForStop() |
| 51 | require.NoError(t, err) |
| 52 | }() |
| 53 | } |
| 54 | queries := []string{ |
| 55 | `BEGIN;`, |
| 56 | `DROP TABLE IF EXISTS migrations;`, |
| 57 | `DROP TABLE IF EXISTS animals;`, |
| 58 | `CREATE TABLE IF NOT EXISTS migrations (file_name TEXT NOT NULL, file_hash TEXT NOT NULL);`, |
| 59 | `CREATE TABLE IF NOT EXISTS animals (id SERIAL PRIMARY KEY NOT NULL, name TEXT NOT NULL);`, |
| 60 | `;`, // This should be ignored in the output |
| 61 | `INSERT INTO migrations (file_name, file_hash) VALUES ('2021-09-07T154500-create-animals-table.sql', '42331f4277227d09e9bb32eeaf7e04d9c7fe320160e05372ed0ef010cfbf666b');`, |
| 62 | `INSERT INTO animals(name) VALUES('Alpaca');`, |
| 63 | `INSERT INTO animals(name) VALUES('Highland cow');`, |
| 64 | `INSERT INTO animals(name) VALUES('Aardvark');`, |
| 65 | `INSERT INTO migrations (file_name, file_hash) VALUES ('2021-09-07T154700-insert-animals.sql', '3223d0deb6fb7fb2accf6abffc0667ebe4503379987c472d10a585a553f9b3b6');`, |
| 66 | `SELECT * FROM migrations ORDER BY file_name;`, |
| 67 | `SELECT * FROM animals ORDER BY id;`, |
| 68 | `COMMIT;`, |
| 69 | } |
| 70 | combinedQueries := "" |
| 71 | for _, query := range queries { |
| 72 | // We do this just to homogenize the queries, even though we're adding the delimiter right back |
| 73 | query = sql.RemoveSpaceAndDelimiter(query, ';') |
| 74 | combinedQueries += query + ";" |
| 75 | } |
| 76 | // First we'll check all invalid modes that fail immediately |
| 77 | invalidModes := []pgx.QueryExecMode{ |
| 78 | pgx.QueryExecModeCacheStatement, |
| 79 | pgx.QueryExecModeCacheDescribe, |
| 80 | pgx.QueryExecModeDescribeExec, |
| 81 | pgx.QueryExecModeExec, |
| 82 | } |
| 83 | for _, mode := range invalidModes { |
| 84 | rows, err := conn.Current.Query(ctx, combinedQueries, mode) |
| 85 | if mode == pgx.QueryExecModeExec { |
| 86 | // This mode requires reading from the returned rows to find the error, rather than erroring immediately |
| 87 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected