@@ -6,7 +6,7 @@ use 5.006;
66use strict;
77use warnings;
88use Data::Dumper;
9- use Test::More tests => 12 ;
9+ use Test::More tests => 14 ;
1010use lib ' t' ,' .' ;
1111use CP_Testing;
1212
@@ -43,9 +43,11 @@ if ($ver < 80100) {
4343
4444
4545my $seqname = ' cp_test_sequence' ;
46+ my $testtbl = ' sequence_test' ;
4647$cp -> drop_sequence_if_exists($seqname );
4748$cp -> drop_sequence_if_exists(" ${seqname} 2" );
4849$cp -> drop_sequence_if_exists(" ${seqname} '\" evil" );
50+ $cp -> drop_table_if_exists(" $testtbl " );
4951
5052$t =qq{ $S works when no sequences exist} ;
5153like ($cp -> run(' ' ), qr { OK:.+No sequences found} , $t );
@@ -96,4 +98,28 @@ $dbh->commit();
9698$t =qq{ $S handles SQL quoting} ;
9799like ($cp -> run(' ' ), qr { OK:.+'public."${seqname} ''""evil"'} , $t ); # extra " and ' because name is both identifier+literal quoted
98100
101+ $dbh -> do(" DROP SEQUENCE ${seqname} " );
102+ $dbh -> do(" DROP SEQUENCE ${seqname} 2" );
103+ $dbh -> do(qq{ DROP SEQUENCE "${seqname} '""evil"} );
104+
105+ # test integer column where the datatype range is smaller than the serial range
106+ $dbh -> do(" CREATE TABLE $testtbl (id serial)" );
107+ $dbh -> do(" SELECT setval('${testtbl} _id_seq',2000000000)" );
108+ $dbh -> commit;
109+ $t =qq{ $S handles "serial" column} ;
110+ like ($cp -> run(' ' ), qr { WARNING:.+public.sequence_test_id_seq=93% \( calls left=147483647\) } , $t );
111+
112+ if ($ver >= 90200) {
113+ # test smallint column where the datatype range is even smaller (and while we are at it, test --exclude)
114+ $dbh -> do(" ALTER TABLE $testtbl ADD COLUMN smallid smallserial" );
115+ $dbh -> do(" SELECT setval('${testtbl} _smallid_seq',30000)" );
116+ $dbh -> commit;
117+ $t =qq{ $S handles "smallserial" column} ;
118+ like ($cp -> run(' --exclude=sequence_test_id_seq' ), qr { WARNING:.+public.sequence_test_smallid_seq=92% \( calls left=2767\) } , $t );
119+ } else {
120+ SKIP: {
121+ skip ' "smallserial" needs PostgreSQL 9.2 or later' , 2;
122+ }
123+ }
124+
99125exit ;
0 commit comments