@@ -156,6 +156,13 @@ sub wait_connect
156156 # See query() for details about why/how the banner is used.
157157 my $banner = " background_psql: ready" ;
158158 my $banner_match = qr / (^|\n )$banner \r ?\n / ;
159+
160+ # See comment on similar check in query()
161+ if (!defined ($ENV {with_readline }) || $ENV {with_readline } ne ' yes' )
162+ {
163+ $banner_match = qr / postgres=# $banner \r ?\n / ;
164+ }
165+
159166 $self -> {stdin } .= " \\ echo $banner \n\\ warn $banner \n " ;
160167 $self -> {run }-> pump()
161168 until ($self -> {stdout } =~ / $banner_match /
@@ -265,14 +272,22 @@ sub query
265272 # to be careful that we don't e.g. match the echoed \echo command, rather
266273 # than its output.
267274 my $banner = " background_psql: QUERY_SEPARATOR $query_cnt :" ;
268- my $banner_match = qr / (^|\n )$banner \r ?\n / ;
275+ my $banner_match_stdout = qr / (^|\n )$banner \r ?\n / ;
276+ my $banner_match_stderr = $banner_match_stdout ;
277+ # If we are built without readline, normal regex doesn't work, since stdout
278+ # is read all at once, and the banner is preceeded by "postgres#= ".
279+ # stderr still contains only the banner.
280+ if (!defined ($ENV {with_readline }) || $ENV {with_readline } ne ' yes' )
281+ {
282+ $banner_match_stdout = qr / postgres=# $banner \r ?\n / ;
283+ }
269284 $self -> {stdin } .= " $query \n ;\n\\ echo $banner \n\\ warn $banner \n " ;
270285 pump_until(
271286 $self -> {run }, $self -> {timeout },
272- \$self -> {stdout }, qr /$banner_match / );
287+ \$self -> {stdout }, qr /$banner_match_stdout / );
273288 pump_until(
274289 $self -> {run }, $self -> {timeout },
275- \$self -> {stderr }, qr /$banner_match / );
290+ \$self -> {stderr }, qr /$banner_match_stderr / );
276291
277292 die " psql query timed out" if $self -> {timeout }-> is_expired;
278293
@@ -286,8 +301,8 @@ sub query
286301 # first newline is optional, as there would not be one if consuming an
287302 # empty query result.
288303 $output = $self -> {stdout };
289- $output =~ s / $banner_match // ;
290- $self -> {stderr } =~ s / $banner_match // ;
304+ $output =~ s / $banner_match_stdout // ;
305+ $self -> {stderr } =~ s / $banner_match_stdout // ;
291306
292307 # clear out output for the next query
293308 $self -> {stdout } = ' ' ;
0 commit comments