Howdy Listers,
I wanted to thank all of you once again for your tremendous help on
my earlier class project.
Now I have my final project/exam to do (and it's due in a week)...and
I don't even know where to begin...the book we have is no help
whatsoever. We are allowed to seek help for this final on the
internet so don't worry that I might be cheating here.
I am consulting other sources as well, but if anyone here has any
knowledge of this sort of stuff (SQL, text databases, etc.) I could
sure use the help. Once I grok how one of the subroutines (like
insert, update, etc) works I hope I will be better able to work on
the others
The final, in its entirety, is below...complete with lengthy comments.
Thanks in advance,
CTP
=================================================
$VERSION = 1.03;
######################################################
# Revision History
#
# 1.03 - Final Date posted
# 1.02 - fixed printRows AGAIN
# It should read: (thanks to Paul Gross)
# > foreach $field (@$row) {
# 1.01 - fixed printRows
# 1.00 - Initial creation
#
#######################################################
# TextDB.pm
#
# Perl Class Final
#
# DUE DATE: March 27, 2001
#
# Follow the instructions found in the comments of
# this file carefully. Do not just jump right on in!
# Know what you have to do - be sure to look at the
# subroutinues at the bottom which you could fill
# in, get credit for AND help out the other
# portions of this final. ;)
#
# You MUST MUST MUST have the output as I specify for
# each subroutine or other subroutines I have written
# will not work.
#
# The portions I thought were outside the scope of
# what you learned in class, I filled in for you.
# You should however go over this entire program with
# a fine tooth comb so that you understand everything
# that I have done. Trust me on this one folks.
#
# I have indicated the portions of code I expect you
# to fill in with the "FILL IN" comment inside the
# subroutine. There is a point value associated with
# each subroutine. If you wish for me to send you one
# of the subroutinues, I will do so, but you will not
# not get credit for completing it. There are enough
# points here to get well over a 100 points for the
# class, so complete what you can - and DON'T kill
# yourself on this ;)
#
# I realize that this will look daunting to many of
# you, but I honestly believe that having READ THE
# BOOK and been to every class and tried as hard as
# you can in class, you can easily pass this final.
# And considering I can help you out along the way,
# I know you can complete this.
#
# Good luck.
#
# PS. On the bright side, you will all be able to
# use this program YOU WROTE at work!
#
#######################################################
#
# Be sure to look at the sample files that have come
# with this:
# final.pl (the script you can run to test the textdb
# Users.sch (which defines a table)
# Users.dat (which contains the table data)
#
######################################################
#
# HINT:
#
# If it does not say "FILL IN" and you don't know
# what it does - leave it alone! ;) Remember, "blind
# faith."
#
# Look at past homeworks - for some you should be able
# to CUT AND PASTE your solutions and reuse them with
# a few modifications.
#
# Also, if you guys help each other, or find help
# outside (from the internet, a coworker, etc) that is
# OK! The most important thing is to get the darn thing
# to work!
#
# Also, I have been VERY vague about error handling.
# You should all know how I feel about this, so take
# care of it where you feel it is appropriate.
#
# Other caveats:
# This database you are implementing only performs
# equality constraints. Meaning, you can't select rows
# with arithmatic contraints like:
#
# SELECT FROM Users WHERE id > 10;
#
# You can only perform selects like:
#
# SELECT FROM Users WHERE id = 1;
#
# This should make this project much simpler. However,
# if you can get ANY constraint to work, you will get
# serious EXTRA CREDIT!
#
# If you have problems getting this perl module to even
# function at all, let me know ASAP! I will post
# updates on the website, so if you are experiencing
# problems look at the VERSION number on line 3 to
# see if your version matches the one on the web site!
#
# And finally, feel free to add any other subroutines,
# variables, etc. that will help you in completing this
# exam.
#
# And again, good luck.
#
#######################################################
#
# Total points available: 110 points! That is some
# serious points folks.
#
#######################################################
package TextDB;
# put any initialization code here if you need to
BEGIN {
# push @INC,"";
}
require Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION
%LOG_PATTERNS %FIELD_NAMES);
@ISA = qw(Exporter);
@EXPORT = qw(select update delete insert);
###################################################
# Local variables
###################################################
local %TABLES;
sub new {
my $classname = shift;
my $self = {};
bless($self,$classname);
$self->init();
if (@_) {
my %extra = @_;
my $key;
while (($key,$value) = each %extra) {
$self->{$key} = $extra{$key};
}
}
return $self;
}
################################################
# Public subroutines #
################################################
# select (20 points)
#
# select will return a list of rows, or in other
# words, a list of lists. It takes
# For example:
# If I call:
# $db->select("Users","id=1");
# Then select will return:
# (("1","reese","password","Byrne Reese"))
#
# Ok, that constraint part is hard, I admit, so I am
# going to ACTUALLY TELL YOU HOW TO DO IT, but you
# have to implement it.
#
# In order to implement:
# Convert the constraint into a pair, where the pair
# consists of the name of the field to test against,
# AND the value the field should have.
#
# Hint: Remember the syntax ${$varname} which allowed
# you to access a variable variable name (I
# demonstrated this in class)?
#
# Now you need to access the field names of the table.
# This information is stored in the hash %TABLES.
# Since you know the name of field, which corresponds
# directly to the value's location in each ROW, you
# should be able to evaluate this constraint.
#
# See subroutine at the bottom of this page called:
# evalConstraint
sub select {
my $self = shift;
my ($tableName,$constraint) = @_;
# FILL IN
}
# insert (20 points)
#
# This takes two parameters as arguments: the
# table name to insert into, and the values to
# enter into the table.
# For example:
# If I call:
# $db->insert("Users",("4","foo","somepassword","Foo Bar"));
# Then the file Users.dat will have the line:
# ROW 4::foo::somepassword::Foo Bar
# added to it at the end of the file.
sub insert {
my $self = shift;
my ($tableName,@fieldValues) = @_;
# FILL IN
}
# update (20 points)
#
# This takes four parameters: the table name to update,
# the constraint to limit the update to, the name of the
# field to update, and the value to assign to the field.
# For example:
# If I call:
# $db->update("Users","id=1","fullName","Reese, Byrne");
# Then the line in Users.dat that looked like this:
# ROW 1::reese::password::Byrne Reese
# will now look like this:
# ROW 1::reese::password::Reese, Byrne
#
sub update {
my $self = shift;
my ($tableName,$constraint,$fieldName,$fieldValue) = @_;
# FILL IN
}
# delete (20 points)
#
# This subroutine, provided the table name and
# constraint will delete any AND all rows that
# meet that constraint.
sub delete {
my $self = shift;
my ($tableName,$constaints) = @_;
# FILL IN
}
##############################################
# Private subroutines #
##############################################
# init (10 points)
#
# This subroutine initializes the text database
# It needs to open up all files in the working
# directory that end with the file extension
# '*.sch'. It then needs to parse each file
# initializing a global hash called "%TABLES"
# where the keys of that hash are the name of
# the table. The value associated with that key
# is a text string of all the field names of
# that table
#
# Example table definition file:
# TABLE NAME Users
# FIELD NAME id
# FIELD NAME username
# FIELD NAME password
# FIELD NAME fullName
#
# Parsing this table defintion file should produce
# a hash that looks like this:
# %TABLES{"Users"} = ("id","username","password","fullName");
sub init {
my $self = shift;
# FILL IN
}
# parseRow (10 points)
#
# This subroutine takes a parameter a string that looks like:
# ROW 3::john::foo::John Adams
# It returns a list that looks like:
# ("3","john","foo","John Adams")
sub parseRow {
my ($rowdata) = @_;
my @row;
# FILL IN
return @row;
}
# evalConstraint (10 points)
#
# The evalConstraint subroutine returns 1 (or true)
# if the provided row from the provided table name
# meets the following constraints. Otherwise, it
# returns 0 (or false).
#
# See notes I included on select() for help on this!
sub evalConstraint {
my ($tableName,$constraint,$rowdata) = @_;
# return 0;
# return 1;
}
1;