<commit_before>#!/usr/bin/env perl

use strict;
use warnings;
use Unison;
use Unison::Exceptions;

my $u = new Unison();

print("$u: (", 
	  join(',',map {defined $u->{$_} ? $u->{$_} : 'undef'}
		   (qw(dbname host username password))),
	  ")\n");


select(STDERR); $|++;
select(STDOUT); $|++;

try {
  foreach my $sql ('select count(*) from porigin',
				   'select * from v_run_history where pseq_id=5',
				   'select from bogus') {
	my (@r) = map { defined $_ ? $_ : 'undef'} $u->selectrow_array($sql);
	print("$sql returns <",join(',',@r),">\n");
  }
} catch Unison::Exception::DBIError with {
  warn("======= caught a DBI error:\n", $_[0]);
} catch Unison::Exception with {
  warn("======= caught this error:\n", $_[0]);
};




__END__

foreach my $h (undef,$ENV{PGHOST}) {
foreach my $u (undef,'PUBLIC',$ENV{PGUSER}) {
foreach my $p (undef,$ENV{PGPASSWORD}) {
  printf("%-10s %-10s %-10s: %s\n",
		 $h, $u, $p, try_connection($h,$u,$p) ? 'success' : 'failure');
}}}


sub try_connection {
  my ($h,$u,$p) = @_;
  return new Unison(host=>$h, username=>$u, password=>$p);
}<commit_msg>* added a few rules * checked for these combinations: 1) no user/pw opts; 2) PGPASSWORD/-U; 3)   PGPASSWORD/PGUSER<commit_after>#!/usr/bin/env perl

use strict;
use warnings;
use Unison;
use Unison::Exceptions;

my $u = new Unison();

select(STDERR); $|++;
select(STDOUT); $|++;


print("* Unison object $u =\n  ", 
	  join(',',map {defined $u->{$_} ? $u->{$_} : 'undef'}
		   (qw(dbname host username password))),
	  "\n\n");

try {
  foreach my $sql 
	(
	 'select version()',
	 'select current_user',
	 'select count(*) from porigin',
	 'select * from v_run_history where pseq_id=12',

	 # EXPECT errors for the following:
	 "select 'EXPECT ERRORS FOR THE FOLLOWING SQL:'",
	 'select from bogus'
	) {
	  my (@rall) = @{ $u->selectall_arrayref($sql) };
	  my (@r) = map { defined $_ ? $_ : 'undef'} @{$rall[0]};
	  print("* $sql returns ", $#rall+1, " rows; first row:\n  ",join(',',@r),"\n");
	}
} catch Unison::Exception::DBIError with {
  warn("======= caught a DBI error:\n", $_[0]);
} catch Unison::Exception with {
  warn("======= caught this error:\n", $_[0]);
};
{'fraction_non_alphanumeric': 0.23507635354002776, 'fraction_numerical': 0.008329477093937991, 'mean_word_length': 4.159904534606206, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6500360', 'n_tokens_mistral': 872, 'n_tokens_neox': 812, 'n_words': 214}