Oct 16 lecture notes 1. Go over homework : see code/registrar_db/ 2. Perl/DBI : see code/registrar_db/queries.pl 3. catching errors in perl: eval { ... code ... } 4. transactions in SQL : committing and rolling back 5. walk through perldoc DBI 6. if time allows, discuss packaging database stuff into a another file. Or continue this on Thursday (Review object oriented programming, modules, and all that.) 7. Homework for Thurs: * Read about Perl/DBI; at least perldoc DBI * Review object oriented perl * Coming up : putting it all together... * After that: Class::DBI -- MyData.pm --------------------- package MyData; sub new { my $class = shift; my $dbh = DBI->connect(...); my $self = { dbh => $dbh }; bless($self,$class); return $self; } sub set_data { # insert data into database my $self = shift; my ($arg1, $arg2) = @_; my $dbh->do(" ... sql goes here ... ", ...); } sub get_data { # get data from database my $self = shift; my $answer = ''; my ($this, $that) = shift; eval { my $sth=$dbh->prepare(...); $sth->execute(...); $answer = $sth->fetch... } return $answer; } sub do_tests { # ... make sure all this stuff works... } --- myCGI.cgi (or Mason file) ------------------ use CGI; use MyData; # ***** All SQL is hidden in here. **** my $database = new MyData; my $from_user = ... # get stuff from form $database->set_data( $from_user ...); # or to get stuff from database my $stuff_from_db = $database->get_data( ... ); # print HTML page, or whatever