eval 'exec /home/jsoc/bin/$JSOC_MACHINE/perl -S $0 "$@"' if 0; use DBI; #Return date in form for a label e.g. 1998.01.07_14:42:04 sub labeldate { local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date,$sec2,$min2,$hour2,$mday2,$year2); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $sec2 = sprintf("%02d", $sec); $min2 = sprintf("%02d", $min); $hour2 = sprintf("%02d", $hour); $mday2 = sprintf("%02d", $mday); $mon2 = sprintf("%02d", $mon+1); $year4 = sprintf("%04d", $year+1900); $date = $year4.".".$mon2.".".$mday2._.$hour2.":".$min2.":".$sec2; return($date); } $DB = "jsoc_sums"; $HOST = "solarweb"; #host where the cgi runs $user = "apache"; $user = "production"; $hostdb = "hmidb"; #host where Postgres runs $PID = getppid; $ldate = &labeldate(); $ext = "$ldate"."_$PID"; $querylog = "/tmp/q_$ext.rdb"; #$query = new CGI; #print $query->header; #TEST sql cmd echo to psql #$table = "sum_tape"; #$cmd = "echo '\\d $table' | psql -h hmidb -p 5434 jsoc_sums"; #print "$cmd\n"; #@tblfields = `$cmd`; #print "@tblfields\n"; #exit; #$sqlcmd = $query->param('w'); $sqlcmd = "select * from sum_partn_avail"; print "

The query is: $sqlcmd

"; #!!TEMP $dbh = DBI->connect("dbi:Pg:dbname=$DB;host=$hostdb;port=5434", "$user", ""); if ( !defined $dbh ) { die "Cannot do \$dbh->connect: $DBI::errstr\n"; } $sqltable = "SELECT c.oid FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relname ~ '^(sum_partn_avail)\$' AND n.nspname ~ '^(public)\$' ORDER BY c.oid"; $sth = $dbh->prepare($sqltable); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $found = 0; while(@sresult = $sth->fetchrow()) { #get each row from the DB if(!$found++) { #print "

The query result is:

"; } $id = pop(@sresult); } $sqltable = "SELECT a.attname as COLUMN FROM pg_catalog.pg_attribute a WHERE a.attrelid = '$id' AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum"; $sth = $dbh->prepare($sqltable); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $found = 0; while(@sresult = $sth->fetchrow()) { #get each row from the DB if(!$found++) { #print "

The query result is:

"; } print "@sresult

"; } $sth = $dbh->prepare($sqlcmd); if ( !defined $sth ) { die "Cannot prepare statement: $DBI::errstr\n"; } # Execute the statement at the database level $sth->execute; $found = 0; while(@sresult = $sth->fetchrow()) { #get each row from the DB if(!$found++) { print "

The query result is:

"; } print "@sresult

"; } if(!$found) { print "
sum_partn_avail ($DB): !! No Row Found !!
"; } $sth->finish; $dbh->disconnect(); #$remotehost = $query->remote_host(); #print "

The secret word is $secretword and your IP is $remotehost.

"; #print "

The query result is: $sresult

"; #print "

your IP is $remotehost.

";