#!/usr/local/bin/perl # Dilip Barman, http://www.cs.unc.edu/Courses/wwwp-f97/members/barman # Sep 20-21 1997 # # dbRetrieve2.pl.cgi: As part of my perl programming project, described # at www.cs.unc.edu/Courses/wwwp-f97/members/barman/perlProjectProposal.html, # this perl cgi-bin script is called from the HTML form perlDatabase2.html # to retrieve existing records. It doesn't need to look at any input # and just builds a table of record values. # # Sep 22: It wasn't quite working but it was because I was trying to open # the database with its full name, not just the name up to the extension. # Now it seems to work fine! Now I'm going to add delete capability so # a record can be deleted. If I wanted, I could add update capability # so that a selected record would have its fields loaded into an Add Record # form, but I don't think I'll implement that. require "/afs/cs.unc.edu/project/courses/190-25f97/programs/perl/lib/cgi-lib.pl"; # GLOBAL VARIABLES $FALSE = 0; $TRUE = 1; # $DBFILENAME = "../musicDatabase/musicDB2"; $DBFILENAME = "/afs/cs.unc.edu/project/courses/190-25f97/members/barman/musicDatabase/musicDB2"; $ROACCESS = "0555"; # Read-Only open: RWX, so U=101, G=101, O=101 $RWACCESS = "0777"; # Read-Write open: 111 111 111 # Remember to set AFS directory permissions so system:anyuser (a web # client, for example) has write privilege to this directory -- # fs setat ../musicDatabase system:anyuser write $RECDELIMSTART = "\*\$\["; # delimit record entries: *$[ ... ]$* $RECDELIMEND = "\]\$\*"; # * * * T O P L E V E L H T M L S T U F F * * * print &PrintHeader; print ""; print "\nDilip's Music Database: Review Entries"; print "\n

Music Database: Review Entries

"; # * * * D A T A B A S E L O G I C * * * $actualfilename = $DBFILENAME . ".pag"; # DB file type if (-e $actualfilename) { print "\n

Database Contents

"; &printDB; } else { print "\n

ERROR: Database File Does Not Exist

"; print "\n

The database file, \"$DBFILENAME\", could not be found."; print "\nAre you sure it already has data in it? Drop"; print "\nDilip a note"; print "\nif you continue to have problems."; } # * * * W R A P U P H T M L * * * # Give option to return to try again or return home print "\n

Go back to main screen"; print "\n
"; print "\n

Read"; print "\n"; print "\nproject proposal or system"; print "\n"; print "\nimplementation notes

"; print "\n

Return to Dilip's course "; print""; print "home page

"; print "\n
Background courtesy of "; print "\nMoyra's Web Jewels
"; # End HTML page print "\n "; # * * * S U B R O U T I N E S * * * sub printDB { # # printDB subroutine # Sep 21 1997 # Generate a table and print out the database contents # # $title is the key and since DBM databases are 1-key 1-value # structured, we built the value as a concatenation # of the individual values with a delimiter of ~ (tilde). # For example, a record might look like: # # key="The Eagle's Greatest Hits" # value="Eagles~Rock~CD~48~A great CD from early 70s!" # Open DB - remember to use octal access value # (Thanks to Guy Decoux, decoux@moulon.inra.fr, for that hint!) dbmopen(%RECORDS, $DBFILENAME, oct($ROACCESS)); # || die "

Error! Can't open $DBFILENAME : $!

"; #$! is dbmopen() error msg # Define a form just for the purpose of putting DELETE buttons for each record print "\n
"; print "\n

Click on the Delete button for a row to delete that entry"; print "\n"; print "\n"; # last column for delete buttons while ( ($key, $value) = each(%RECORDS) ) { $title = $key; # Now parse to get other fields ($artist,$genre,$format,$time,$comments) = split (/~/, $value); # That was slick! I got the trick from LearningPerl, pg. 97! print "\n"; print "\n "; print "\n "; print "\n "; print "\n "; print "\n "; print "\n "; print "\n "; } print "\n
Title Artist Genre Format Time Comments
$title$artist$genre$format$time$comments

"; dbmclose(%RECORDS); } # End printDB subroutine