use vars qw( $connection ); # cached connection # DBI specification of the connection to the database my $DB_PATH = "DBI:Sybase:server=192.168.70.56"; # DB user my $DB_USER = 'user'; # DB user's password my $DB_PASS = 'password'; # TWiki ihook sub initPlugin { return 1; } # TWiki hook; this is run on the text being translated to HTML, and is # your opportunity to expand any tags in that text. sub commonTagsHandler { my($text, $topic, $web ) = @_; $_[0] =~ s/%CurrentReleases%/_show_releases($1)/ge; #substitution GREP command } # Connect to the DB sub _connect { my $this = shift; unless( $connection ) { $connection = DBI->connect( $DB_PATH, $DB_USER, $DB_PASS, { PrintError => 0, RaiseError => 1, }); } return $connection; } sub _show_releases { my $args = shift; my @headers = map { "*$_*" } qw/ Product Target_Feature_Freeze Target_CCRB Target_DEV_Release Target_RTM/; my $fmt = "| %s | %s | %s | %s | %s | \n"; _connect(); my $format = "DMY1_YYYY"; #my $sth->prepare( "set dateformat dmy" ); my $sth =$connection->prepare(my $sql = "SELECT Release, dtTargetFeatureFreeze, dtTargetCCRB, dtTargetReleaseFromDev, dtTargetRTM, TwikiURL, ReleaseNum, Display FROM ReleaseDates WHERE (Display = 1)"); #$sth->do( "set dateformat dmy" ) || die $sth->$errstr; $sth->execute; my $result = sprintf $fmt, @headers; while (my @rows = $sth->fetchrow_array() ) { $rows[0]="$rows[0]"; $result .= sprintf $fmt, @rows; } $sth->finish; return $result; } 1;