Bmdschema.pm functions
- new
- Creates an empty new schema object.
- Not meant for public usage:
$bmd->{"schemas"} = new Bmdschema; # From Bmd->readindexfile()
- destroy
- Removes specified table or field from both the schema data and the table
data structures.
- Not meant for public usage:
# Bmd->dropfield() uses it like this:
$bmd->{"schemas"}->destroy($bmd, "tablename", "fieldname");
# Bmd->droptable() uses it like this:
$bmd->{"schemas"}->destroy($bmd, "tablename");
# This works too:
$bmd->{"schemas"}->destroy();
- readschemafiles
- Parses those files typically named something.sch and records their info in
a hash of 2d arrays. It's also capable of making reject assignments.
- Not meant for public usage:
# Bmd->readindexfile()
uses it like this:
$bmd->{"schemas"}->readschemafiles($bmd, "filename1", "filename2", ...);
- savetest
- Tests for write access to supplied member directory and/or modified schema
files, and returns any errors in an array. You should run this before &saveallfiles() to
find problems ahead of time. A new member directory must be specified to
"Save As". &savetest() will assume the schema files are moving to the new
member directory. Note this does not actually save files.
- Not meant for public usage:
# Bmd->savetest uses it like this:
push @errs, $bmd->{"schemas"}->savetest($bmd, "new_mdir");
# This works too:
@errs = $bmd->{"schemas"}->savetest($bmd);
- saveallfiles
- This one saves all modified schema files. It's best to run &savetest() before. Supply a new
member directory name if you want to "Save As". Returns any errors in an array.
- Not meant for public usage:
# Bmd->saveallfiles
uses it both ways:
push @errs, $bmd->{"schemas"}->saveallfiles($bmd, "new_mdir"); # Save As
push @errs, $bmd->{"schemas"}->saveallfiles($bmd); # Normal save
- savefile
- Used by
&saveallfiles() to save each individual schema file. Supply a new name
if this is a Save As.
- Not meant for public usage:
#
&saveallfiles() uses it both ways:
push @errs, $self->savefile($bmd, "originalfilename", "newfilename");
push @errs, $self->savefile($bmd, "originalfilename");
- listtables
- Returns an array of all table names or just the tables in a specified
dataspace.
- Usage (Through Bmd->listtables()
wrapper):
my @tables = $bmd->listtables(); # Returns all tables
my @tables = $bmd->listtables("normal"); # Returns all normal tables
my @tables = $bmd->listtables("reject");
my @tables = $bmd->listtables("static");
- listfields
- Returns an array of all field names in a specified table.
- Usage (Through Bmd->listfields()
wrapper):
my @fields = $bmd->listtables("tablename");
- setprimarykey
- Used by
&readschemafiles() to assign primary keys to a table. It puts them
into an array referenced by $self->{" pk tablename"}. Note " pk " is just
prepended to whatever the table's name is. If no field list is provided,
then every field in the table is primary.
- Not meant for public usage:
#
&readschemafiles() uses it like this:
$self->setprimarykey("tablename", "primaryfld1", "primaryfld2", ...);
# This works too:
$self->setprimarykey("tablename");
- getprimarykey
- Returns an array of the field names in the specified table's primary key.
- Usage (Through Bmd->getprimarykey()
wrapper):
my @pkey = $bmd->getprimarykey("tablename");
- getfieldnum
- Returns the field number of the specified field in the specified table.
The field number is the array index you would use to find that field's
value in the Bmdtable data structure. Fields are numbered beginning with
zero like any other Perl array. Function returns a -1 if there is field
does not exist.
- Usage (Through Bmd->getfieldnum()
wrapper):
my $index = $bmd->getfieldnum("tablename", "fieldname");
- getfieldmap
- Returns an array of respective field numbers for a list of supplied field
names of a supplied table. Like
&getfieldnum(), it returns a -1 for every non-existent field.
- Usage (Through Bmd->getfieldmap()
wrapper):
my @fieldnums = $bmd->getfieldmap("tablename", "fld4", "fld2", "fld3", ...);
- getdataspace
- Returns either "normal", "reject", or "static" indicating the dataspace
of the supplied table.
- Usage (Through Bmd->getdataspace()
wrapper):
my $ds = $bmd->getdataspace("tablename");
- getschemaref
- Returns a reference to the 2D array that contains the schema info for a
specified table. This is a direct connection into the Bmdschema object
data structure. Use with caution.
- Usage (Through Bmd->getschemaref()
wrapper):
my $schema = $bmd->getschemaref("tablename");
- commontables
- This is actually a class method. It returns a list of table names that
are common to two supplied Bmd databases. You can specify a dataspace
to limit the search to the tables of that dataspace.
- Usage:
my @tables = Bmdschema->commontables($bmd1, $bmd2, "normal");
# Or this checks all tables:
my @tables = Bmdschema->commontables($bmd1, $bmd2);
- commonfields
- This is actually a class method. It returns a list of field names that
are common to two tables. Those tables do not have to be in the same
database, so you must specify two Bmd objects and two table names.
- Usage:
my @fields = Bmdschema->commonfields($bmd1, "tablename1", $bmd2, "tablename2");