[open-ils-commits] r9977 - trunk/Open-ILS/src/support-scripts

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jul 6 21:53:50 EDT 2008


Author: dbs
Date: 2008-07-06 21:53:48 -0400 (Sun, 06 Jul 2008)
New Revision: 9977

Modified:
   trunk/Open-ILS/src/support-scripts/settings-tester.pl
Log:
Check for expected database procedural languages


Modified: trunk/Open-ILS/src/support-scripts/settings-tester.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/settings-tester.pl	2008-07-07 00:00:56 UTC (rev 9976)
+++ trunk/Open-ILS/src/support-scripts/settings-tester.pl	2008-07-07 01:53:48 UTC (rev 9977)
@@ -212,34 +212,78 @@
 
 	my $dsn = "dbi:Pg:dbname=$db_name;host=$db_host;port=$db_port";
 	my $de = undef;
-	my ($dbh, $encoding);
+	my ($dbh, $encoding, $langs);
 	try {
 		$dbh = DBI->connect($dsn, $db_user, $db_pw);
 		unless($dbh) {
 			$de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
 			warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
 		}
-		my $sth = $dbh->prepare("show server_encoding");
+
+		# Get server encoding
+		my $sth = $dbh->prepare("SHOW server_encoding");
 		$sth->execute;
 		$sth->bind_col(1, \$encoding);
 		$sth->fetch;
 		$sth->finish;
+
+		# Get list of server languages
+		$sth = $dbh->prepare("SELECT lanname FROM pg_catalog.pg_language");
+		$sth->execute;
+		$langs = $sth->fetchall_arrayref([0]);
+		$sth->finish;
+
 		$dbh->disconnect;
 	} catch Error with {
 		$de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n" . shift() . "\n";
 		warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n" . shift() . "\n";
 	};
 	print "* $osrf_xpath :: Successfully connected to database $dsn\n" unless ($de);
+
+	# Check encoding
 	if ($encoding !~ m/(utf-?8|unicode)/i) {
 		$de .= "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
 		warn "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
 	} else {
 		print "  * Database has the expected server encoding $encoding.\n";
 	}
+
+	my $result = check_db_langs($langs);
+	if ($result) {
+		$de .= $result;
+		warn $result;
+	}
+
 	return ($de) ? $de : "* $osrf_xpath :: Successfully connected to database $dsn with encoding $encoding\n";
 
 }
 
+sub check_db_langs {
+	my $langs = shift;
+
+	my $errors;
+
+	# Ensure the following PostgreSQL languages have been enabled
+	my %languages = (
+		'plperl' => 0,
+		'plperlu' => 0,
+		'plpgsql' => 0,
+	);
+
+	foreach my $lang (@$langs) {
+		my $lower = lc($$lang[0]);
+		$languages{$lower} = 1;
+	}
+	
+	foreach my $lang (keys %languages) {
+		if (!$languages{$lang}) {
+			$errors .= "  * ERROR: Language '$lang' is not enabled in the target database\n";
+		}
+	}
+
+	return $errors;
+}
+
 sub check_libdbd {
 	my $results = '';
 	my @location = `locate libdbdpgsql.so | grep -v home | grep -v .libs`; # simple(ton) attempt to filter out build versions



More information about the open-ils-commits mailing list