diff options
Diffstat (limited to 'src/bin/psql/t/001_basic.pl')
-rw-r--r-- | src/bin/psql/t/001_basic.pl | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl index 44997467bf2..57486ceffdb 100644 --- a/src/bin/psql/t/001_basic.pl +++ b/src/bin/psql/t/001_basic.pl @@ -204,6 +204,8 @@ like( # query result. my $tempdir = PostgreSQL::Test::Utils::tempdir; $node->safe_psql('postgres', "CREATE TABLE tab_psql_single (a int);"); + +# Tests with ON_ERROR_STOP. $node->command_ok( [ 'psql', '-X', @@ -212,11 +214,12 @@ $node->command_ok( 'INSERT INTO tab_psql_single VALUES (1)', '-c', 'INSERT INTO tab_psql_single VALUES (2)' ], - '--single-transaction and multiple -c switches'); + 'ON_ERROR_STOP, --single-transaction and multiple -c switches'); my $row_count = $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); is($row_count, '2', - '--single-transaction commits transaction, multiple -c switches'); + '--single-transaction commits transaction, ON_ERROR_STOP and multiple -c switches' +); $node->command_fails( [ @@ -226,11 +229,12 @@ $node->command_fails( 'INSERT INTO tab_psql_single VALUES (3)', '-c', "\\copy tab_psql_single FROM '$tempdir/nonexistent'" ], - '--single-transaction and multiple -c switches, error'); + 'ON_ERROR_STOP, --single-transaction and multiple -c switches, error'); $row_count = $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); is($row_count, '2', - 'client-side error rolls back transaction, multiple -c switches'); + 'client-side error rolls back transaction, ON_ERROR_STOP and multiple -c switches' +); # Tests mixing files and commands. my $copy_sql_file = "$tempdir/tab_copy.sql"; @@ -244,11 +248,12 @@ $node->command_ok( 'ON_ERROR_STOP=1', '-f', $insert_sql_file, '-f', $insert_sql_file ], - '--single-transaction and multiple -f switches'); + 'ON_ERROR_STOP, --single-transaction and multiple -f switches'); $row_count = $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); is($row_count, '4', - '--single-transaction commits transaction, multiple -f switches'); + '--single-transaction commits transaction, ON_ERROR_STOP and multiple -f switches' +); $node->command_fails( [ @@ -256,10 +261,61 @@ $node->command_fails( 'ON_ERROR_STOP=1', '-f', $insert_sql_file, '-f', $copy_sql_file ], - '--single-transaction and multiple -f switches, error'); + 'ON_ERROR_STOP, --single-transaction and multiple -f switches, error'); $row_count = $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); is($row_count, '4', - 'client-side error rolls back transaction, multiple -f switches'); + 'client-side error rolls back transaction, ON_ERROR_STOP and multiple -f switches' +); + +# Tests without ON_ERROR_STOP. +# The last switch fails on \copy. The command returns a failure and the +# transaction commits. +$node->command_fails( + [ + 'psql', '-X', + '--single-transaction', '-f', + $insert_sql_file, '-f', + $insert_sql_file, '-c', + "\\copy tab_psql_single FROM '$tempdir/nonexistent'" + ], + 'no ON_ERROR_STOP, --single-transaction and multiple -f/-c switches'); +$row_count = + $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); +is($row_count, '6', + 'client-side error commits transaction, no ON_ERROR_STOP and multiple -f/-c switches' +); + +# The last switch fails on \copy coming from an input file. The command +# returns a success and the transaction commits. +$node->command_ok( + [ + 'psql', '-X', '--single-transaction', '-f', + $insert_sql_file, '-f', $insert_sql_file, '-f', + $copy_sql_file + ], + 'no ON_ERROR_STOP, --single-transaction and multiple -f switches'); +$row_count = + $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); +is($row_count, '8', + 'client-side error commits transaction, no ON_ERROR_STOP and multiple -f switches' +); + +# The last switch makes the command return a success, and the contents of +# the transaction commit even if there is a failure in-between. +$node->command_ok( + [ + 'psql', '-X', + '--single-transaction', '-c', + 'INSERT INTO tab_psql_single VALUES (5)', '-f', + $copy_sql_file, '-c', + 'INSERT INTO tab_psql_single VALUES (6)' + ], + 'no ON_ERROR_STOP, --single-transaction and multiple -c switches'); +$row_count = + $node->safe_psql('postgres', 'SELECT count(*) FROM tab_psql_single'); +is($row_count, '10', + 'client-side error commits transaction, no ON_ERROR_STOP and multiple -c switches' +); done_testing(); |