[Bio] / Sprout / ERDB.pm Repository:
ViewVC logotype

Diff of /Sprout/ERDB.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Sun Jan 23 16:12:29 2005 UTC revision 1.18, Sun Aug 14 23:32:08 2005 UTC
# Line 1  Line 1 
1  package ERDB;  package ERDB;
2    
3          use strict;          use strict;
         use Carp;  
4          use Tracer;          use Tracer;
5          use DBKernel;      use DBrtns;
6          use Data::Dumper;          use Data::Dumper;
7          use XML::Simple;          use XML::Simple;
8          use DBQuery;          use DBQuery;
# Line 33  Line 32 
32  relation that contains two fields-- the feature ID (C<id>) and the alias name (C<alias>).  relation that contains two fields-- the feature ID (C<id>) and the alias name (C<alias>).
33  The B<FEATURE> entity also contains an optional virulence number. This is implemented  The B<FEATURE> entity also contains an optional virulence number. This is implemented
34  as a separate relation C<FeatureVirulence> which contains an ID (C<id>) and a virulence number  as a separate relation C<FeatureVirulence> which contains an ID (C<id>) and a virulence number
35  (C<virulence>). If the virulence of a feature I<ABC> is known to be 6, there will be one row in the  (C<virulence>). If the virulence of a feature I<ABC> is known to be 6, there will be one row in
36  C<FeatureVirulence> relation possessing the value I<ABC> as its ID and 6 as its virulence number.  the C<FeatureVirulence> relation possessing the value I<ABC> as its ID and 6 as its virulence
37  If the virulence of I<ABC> is not known, there will not be any rows for it in C<FeatureVirulence>.  number. If the virulence of I<ABC> is not known, there will not be any rows for it in
38    C<FeatureVirulence>.
39    
40  Entities are connected by binary relationships implemented using single relations possessing the  Entities are connected by binary relationships implemented using single relations possessing the
41  same name as the relationship itself and that has an I<arity> of 1-to-1 (C<11>), 1-to-many (C<1M>),  same name as the relationship itself and that has an I<arity> of 1-to-1 (C<11>), 1-to-many (C<1M>),
# Line 67  Line 67 
67  was inserted by the L</InsertObject> method.  was inserted by the L</InsertObject> method.
68    
69  To facilitate testing, the ERDB module supports automatic generation of test data. This process  To facilitate testing, the ERDB module supports automatic generation of test data. This process
70  is described in the L</GenerateEntity> and L</GenerateConnection> methods.  is described in the L</GenerateEntity> and L</GenerateConnection> methods, though it is not yet
71    fully implemented.
72    
73    =head2 XML Database Description
74    
75    =head3 Data Types
76    
77    The ERDB system supports the following data types. Note that there are numerous string
78    types depending on the maximum length. Some database packages limit the total number of
79    characters you have in an index key; to insure the database works in all environments,
80    the type of string should be the shortest one possible that supports all the known values.
81    
82    =over 4
83    
84    =item char
85    
86    single ASCII character
87    
88    =item int
89    
90    32-bit signed integer
91    
92    =item date
93    
94    64-bit unsigned integer, representing a PERL date/time value
95    
96    =item text
97    
98    long string; Text fields cannot be used in indexes or sorting and do not support the
99    normal syntax of filter clauses, but can be up to a billion character in length
100    
101    =item float
102    
103    double-precision floating-point number
104    
105    =item boolean
106    
107    single-bit numeric value; The value is stored as a 16-bit signed integer (for
108    compatability with certain database packages), but the only values supported are
109    0 and 1.
110    
111    =item key-string
112    
113    variable-length string, maximum 40 characters
114    
115    =item name-string
116    
117    variable-length string, maximum 80 characters
118    
119    =item medium-string
120    
121    variable-length string, maximum 160 characters
122    
123    =item string
124    
125    variable-length string, maximum 255 characters
126    
127    =back
128    
129    =head3 Global Tags
130    
131    The entire database definition must be inside a B<Database> tag. The display name of
132    the database is given by the text associated with the B<Title> tag. The display name
133    is only used in the automated documentation. It has no other effect. The entities and
134    relationships are listed inside the B<Entities> and B<Relationships> tags,
135    respectively. None of these tags have attributes.
136    
137        <Database>
138            <Title>... display title here...</Title>
139            <Entities>
140                ... entity definitions here ...
141            </Entities>
142            <Relationships>
143                ... relationship definitions here...
144            </Relationships>
145        </Database>
146    
147    Entities, relationships, indexes, and fields all allow a text tag called B<Notes>.
148    The text inside the B<Notes> tag contains comments that will appear when the database
149    documentation is generated. Within a B<Notes> tag, you may use C<[i]> and C<[/i]> for
150    italics, C<[b]> and C<[/b]> for bold, and C<[p]> for a new paragraph.
151    
152    =head3 Fields
153    
154    Both entities and relationships have fields described by B<Field> tags. A B<Field>
155    tag can have B<Notes> associated with it. The complete set of B<Field> tags for an
156    object mus be inside B<Fields> tags.
157    
158        <Entity ... >
159            <Fields>
160                ... Field tags ...
161            </Fields>
162        </Entity>
163    
164    The attributes for the B<Field> tag are as follows.
165    
166    =over 4
167    
168    =item name
169    
170    Name of the field. The field name should contain only letters, digits, and hyphens (C<->),
171    and the first character should be a letter. Most underlying databases are case-insensitive
172    with the respect to field names, so a best practice is to use lower-case letters only.
173    
174    =item type
175    
176    Data type of the field. The legal data types are given above.
177    
178    =item relation
179    
180    Name of the relation containing the field. This should only be specified for entity
181    fields. The ERDB system does not support optional fields or multi-occurring fields
182    in the primary relation of an entity. Instead, they are put into secondary relations.
183    So, for example, in the C<Genome> entity, the C<group-name> field indicates a special
184    grouping used to select a subset of the genomes. A given genome may not be in any
185    groups or may be in multiple groups. Therefore, C<group-name> specifies a relation
186    value. The relation name specified must be a valid table name. By convention, it is
187    usually the entity name followed by a qualifying word (e.g. C<GenomeGroup>). In an
188    entity, the fields without a relation attribute are said to belong to the
189    I<primary relation>. This relation has the same name as the entity itself.
190    
191    =back
192    
193    =head3 Indexes
194    
195    An entity can have multiple alternate indexes associated with it. The fields must
196    be from the primary relation. The alternate indexes assist in ordering results
197    from a query. A relationship can have up to two indexes-- a I<to-index> and a
198    I<from-index>. These order the results when crossing the relationship. For
199    example, in the relationship C<HasContig> from C<Genome> to C<Contig>, the
200    from-index would order the contigs of a ganome, and the to-index would order
201    the genomes of a contig. A relationship's index must specify only fields in
202    the relationship.
203    
204    The indexes for an entity must be listed inside the B<Indexes> tag. The from-index
205    of a relationship is specified using the B<FromIndex> tag; the to-index is specified
206    using the B<ToIndex> tag.
207    
208    Each index can contain a B<Notes> tag. In addition, it will have an B<IndexFields>
209    tag containing the B<IndexField> tags. These specify, in order, the fields used in
210    the index. The attributes of an B<IndexField> tag are as follows.
211    
212    =over 4
213    
214    =item name
215    
216    Name of the field.
217    
218    =item order
219    
220    Sort order of the field-- C<ascending> or C<descending>.
221    
222    =back
223    
224    The B<Index>, B<FromIndex>, and B<ToIndex> tags themselves have no attributes.
225    
226    =head3 Object and Field Names
227    
228    By convention entity and relationship names use capital casing (e.g. C<Genome> or
229    C<HasRegionsIn>. Most underlying databases, however, are aggressively case-insensitive
230    with respect to relation names, converting them internally to all-upper case or
231    all-lower case.
232    
233    If syntax or parsing errors occur when you try to load or use an ERDB database, the
234    most likely reason is that one of your objects has an SQL reserved word as its name.
235    The list of SQL reserved words keeps increasing; however, most are unlikely to show
236    up as a noun or declarative verb phrase. The exceptions are C<Group>, C<User>,
237    C<Table>, C<Index>, C<Object>, C<Date>, C<Number>, C<Update>, C<Time>, C<Percent>,
238    C<Memo>, C<Order>, and C<Sum>. This problem can crop up in field names as well.
239    
240    Every entity has a field called C<id> that acts as its primary key. Every relationship
241    has fields called C<from-link> and C<to-link> that contain copies of the relevant
242    entity IDs. These are essentially ERDB's reserved words, and should not be used
243    for user-defined field names.
244    
245    =head3 Entities
246    
247    An entity is described by the B<Entity> tag. The entity can contain B<Notes>, an
248    B<Indexes> tag containing one or more secondary indexes, and a B<Fields> tag
249    containing one or more fields. The attributes of the B<Entity> tag are as follows.
250    
251    =over 4
252    
253    =item name
254    
255    Name of the entity. The entity name, by convention, uses capital casing (e.g. C<Genome>
256    or C<GroupBlock>) and should be a noun or noun phrase.
257    
258    =item keyType
259    
260    Data type of the primary key. The primary key is always named C<id>.
261    
262    =back
263    
264    =head3 Relationships
265    
266    A relationship is described by the C<Relationship> tag. Within a relationship,
267    there can be a C<Notes> tag, a C<Fields> tag containing the intersection data
268    fields, a C<FromIndex> tag containing the from-index, and a C<ToIndex> tag containing
269    the to-index.
270    
271    The C<Relationship> tag has the following attributes.
272    
273    =over 4
274    
275    =item name
276    
277    Name of the relationship. The relationship name, by convention, uses capital casing
278    (e.g. C<ContainsRegionIn> or C<HasContig>), and should be a declarative verb
279    phrase, designed to fit between the from-entity and the to-entity (e.g.
280    Block C<ContainsRegionIn> Genome).
281    
282    =item from
283    
284    Name of the entity from which the relationship starts.
285    
286    =item to
287    
288    Name of the entity to which the relationship proceeds.
289    
290    =item arity
291    
292    Relationship type: C<1M> for one-to-many and C<MM> for many-to-many.
293    
294    =back
295    
296  =cut  =cut
297    
# Line 76  Line 300 
300  # Table of information about our datatypes. "sqlType" is the corresponding SQL datatype string.  # Table of information about our datatypes. "sqlType" is the corresponding SQL datatype string.
301  # "maxLen" is the maximum permissible length of the incoming string data used to populate a field  # "maxLen" is the maximum permissible length of the incoming string data used to populate a field
302  # of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation  # of the specified type. "dataGen" is PERL string that will be evaluated if no test data generation
303   #string is specified in the field definition.  # string is specified in the field definition. "avgLen" is the average byte length for estimating
304  my %TypeTable = ( char =>        { sqlType => 'CHAR(1)',                        maxLen => 1,                    dataGen => "StringGen('A')" },  # record sizes.
305                                    int =>         { sqlType => 'INTEGER',                        maxLen => 20,                   dataGen => "IntGen(0, 99999999)" },  my %TypeTable = ( char =>    { sqlType => 'CHAR(1)',            maxLen => 1,            avgLen =>   1, dataGen => "StringGen('A')" },
306                                    string =>  { sqlType => 'VARCHAR(255)',               maxLen => 255,                  dataGen => "StringGen(IntGen(10,250))" },                    int =>     { sqlType => 'INTEGER',            maxLen => 20,           avgLen =>   4, dataGen => "IntGen(0, 99999999)" },
307                                    text =>        { sqlType => 'TEXT',                           maxLen => 1000000000,   dataGen => "StringGen(IntGen(80,1000))" },                    string =>  { sqlType => 'VARCHAR(255)',       maxLen => 255,          avgLen => 100, dataGen => "StringGen(IntGen(10,250))" },
308                                    date =>        { sqlType => 'BIGINT',                         maxLen => 80,                   dataGen => "DateGen(-7, 7, IntGen(0,1400))" },                    text =>    { sqlType => 'TEXT',               maxLen => 1000000000,   avgLen => 500, dataGen => "StringGen(IntGen(80,1000))" },
309                                    float =>       { sqlType => 'DOUBLE PRECISION',       maxLen => 40,                   dataGen => "FloatGen(0.0, 100.0)" },                    date =>    { sqlType => 'BIGINT',             maxLen => 80,           avgLen =>   8, dataGen => "DateGen(-7, 7, IntGen(0,1400))" },
310                                    boolean => { sqlType => 'SMALLINT',                   maxLen => 1,                    dataGen => "IntGen(0, 1)" },                    float =>   { sqlType => 'DOUBLE PRECISION',   maxLen => 40,           avgLen =>   8, dataGen => "FloatGen(0.0, 100.0)" },
311                      boolean => { sqlType => 'SMALLINT',           maxLen => 1,            avgLen =>   2, dataGen => "IntGen(0, 1)" },
312                               'key-string' =>                               'key-string' =>
313                                                           { sqlType => 'VARCHAR(40)',            maxLen => 40,                   dataGen => "StringGen(IntGen(10,40))" },                               { sqlType => 'VARCHAR(40)',        maxLen => 40,           avgLen =>  10, dataGen => "StringGen(IntGen(10,40))" },
314                                   'name-string' =>                                   'name-string' =>
315                                                           { sqlType => 'VARCHAR(80)',            maxLen => 80,                   dataGen => "StringGen(IntGen(10,80))" },                               { sqlType => 'VARCHAR(80)',        maxLen => 80,           avgLen =>  40, dataGen => "StringGen(IntGen(10,80))" },
316                                   'medium-string' =>                                   'medium-string' =>
317                                                           { sqlType => 'VARCHAR(160)',           maxLen => 160,                  dataGen => "StringGen(IntGen(10,160))" },                               { sqlType => 'VARCHAR(160)',       maxLen => 160,          avgLen =>  40, dataGen => "StringGen(IntGen(10,160))" },
318                                  );                                  );
319    
320  # Table translating arities into natural language.  # Table translating arities into natural language.
# Line 111  Line 336 
336    
337  =head3 new  =head3 new
338    
339  C<< my $database = ERDB::new($dbh, $metaFileName); >>  C<< my $database = ERDB->new($dbh, $metaFileName); >>
340    
341  Create a new ERDB object.  Create a new ERDB object.
342    
# Line 136  Line 361 
361          my $metaData = _LoadMetaData($metaFileName);          my $metaData = _LoadMetaData($metaFileName);
362          # Create the object.          # Create the object.
363          my $self = { _dbh => $dbh,          my $self = { _dbh => $dbh,
364                                   _metaData => $metaData,                   _metaData => $metaData
                                  _options => $options,  
365                             };                             };
366          # Bless and return it.          # Bless and return it.
367          bless $self;      bless $self, $class;
368          return $self;          return $self;
369  }  }
370    
371  =head3 ShowMetaData  =head3 ShowMetaData
372    
373  C<< $database->ShowMetaData($fileName); >>  C<< $erdb->ShowMetaData($fileName); >>
374    
375  This method outputs a description of the database. This description can be used to help users create  This method outputs a description of the database. This description can be used to help users create
376  the data to be loaded into the relations.  the data to be loaded into the relations.
# Line 163  Line 387 
387    
388  sub ShowMetaData {  sub ShowMetaData {
389          # Get the parameters.          # Get the parameters.
390          my $self = shift @_;      my ($self, $filename) = @_;
         my ($filename) = @_;  
391          # Get the metadata and the title string.          # Get the metadata and the title string.
392          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
393          # Get the title string.          # Get the title string.
# Line 174  Line 397 
397          my $relationshipList = $metadata->{Relationships};          my $relationshipList = $metadata->{Relationships};
398          # Open the output file.          # Open the output file.
399          open(HTMLOUT, ">$filename") || Confess("Could not open MetaData display file $filename: $!");          open(HTMLOUT, ">$filename") || Confess("Could not open MetaData display file $filename: $!");
400        Trace("Building MetaData table of contents.") if T(4);
401          # Write the HTML heading stuff.          # Write the HTML heading stuff.
402          print HTMLOUT "<html>\n<head>\n<title>$title</title>\n";          print HTMLOUT "<html>\n<head>\n<title>$title</title>\n";
403          print HTMLOUT "</head>\n<body>\n";          print HTMLOUT "</head>\n<body>\n";
# Line 201  Line 425 
425          print HTMLOUT "<a name=\"EntitiesSection\"></a><h2>Entities</h2>\n";          print HTMLOUT "<a name=\"EntitiesSection\"></a><h2>Entities</h2>\n";
426          # Loop through the entities.          # Loop through the entities.
427          for my $key (sort keys %{$entityList}) {          for my $key (sort keys %{$entityList}) {
428            Trace("Building MetaData entry for $key entity.") if T(4);
429                  # Create the entity header. It contains a bookmark and the entity name.                  # Create the entity header. It contains a bookmark and the entity name.
430                  print HTMLOUT "<a name=\"$key\"></a><h3>$key</h3>\n";                  print HTMLOUT "<a name=\"$key\"></a><h3>$key</h3>\n";
431                  # Get the entity data.                  # Get the entity data.
# Line 239  Line 464 
464          print HTMLOUT "<a name=\"RelationshipsSection\"></a><h2>Relationships</h2>\n";          print HTMLOUT "<a name=\"RelationshipsSection\"></a><h2>Relationships</h2>\n";
465          # Loop through the relationships.          # Loop through the relationships.
466          for my $key (sort keys %{$relationshipList}) {          for my $key (sort keys %{$relationshipList}) {
467            Trace("Building MetaData entry for $key relationship.") if T(4);
468                  # Get the relationship's structure.                  # Get the relationship's structure.
469                  my $relationshipStructure = $relationshipList->{$key};                  my $relationshipStructure = $relationshipList->{$key};
470                  # Create the relationship header.                  # Create the relationship header.
# Line 269  Line 495 
495                  my $htmlString = _ShowRelationTable($key, $relationshipStructure->{Relations}->{$key});                  my $htmlString = _ShowRelationTable($key, $relationshipStructure->{Relations}->{$key});
496                  print HTMLOUT $htmlString;                  print HTMLOUT $htmlString;
497          }          }
498        Trace("Building MetaData join table.") if T(4);
499          # Denote we're starting the join table.          # Denote we're starting the join table.
500          print HTMLOUT "<a name=\"JoinTable\"></a><h3>Join Table</h3>\n";          print HTMLOUT "<a name=\"JoinTable\"></a><h3>Join Table</h3>\n";
501          # Create a table header.          # Create a table header.
502          print HTMLOUT _OpenTable("Join Table", "Source", "Target", "Join Condition");          print HTMLOUT _OpenTable("Join Table", "Source", "Target", "Join Condition");
503          # Loop through the joins.          # Loop through the joins.
504          my $joinTable = $metadata->{Joins};          my $joinTable = $metadata->{Joins};
505          for my $joinKey (sort keys %{$joinTable}) {      my @joinKeys = keys %{$joinTable};
506        for my $joinKey (sort @joinKeys) {
507                  # Separate out the source, the target, and the join clause.                  # Separate out the source, the target, and the join clause.
508                  $joinKey =~ m!([^/]*)/(.*)$!;          $joinKey =~ m!^([^/]+)/(.+)$!;
509                  my ($source, $target, $clause) = ($self->ComputeObjectSentence($1),          my ($sourceRelation, $targetRelation) = ($1, $2);
510                                                                                    $self->ComputeObjectSentence($2),          Trace("Join with key $joinKey is from $sourceRelation to $targetRelation.") if T(4);
511                                                                                    $joinTable->{$joinKey});          my $source = $self->ComputeObjectSentence($sourceRelation);
512            my $target = $self->ComputeObjectSentence($targetRelation);
513            my $clause = $joinTable->{$joinKey};
514                  # Display them in a table row.                  # Display them in a table row.
515                  print HTMLOUT "<tr><td>$source</td><td>$target</td><td>$clause</td></tr>\n";                  print HTMLOUT "<tr><td>$source</td><td>$target</td><td>$clause</td></tr>\n";
516          }          }
# Line 290  Line 520 
520          print HTMLOUT "</body>\n</html>\n";          print HTMLOUT "</body>\n</html>\n";
521          # Close the file.          # Close the file.
522          close HTMLOUT;          close HTMLOUT;
523        Trace("Built MetaData web page.") if T(3);
524  }  }
525    
526  =head3 DumpMetaData  =head3 DumpMetaData
527    
528  C<< $database->DumpMetaData(); >>  C<< $erdb->DumpMetaData(); >>
529    
530  Return a dump of the metadata structure.  Return a dump of the metadata structure.
531    
# Line 302  Line 533 
533    
534  sub DumpMetaData {  sub DumpMetaData {
535          # Get the parameters.          # Get the parameters.
536          my $self = shift @_;      my ($self) = @_;
537          # Dump the meta-data.          # Dump the meta-data.
538          return Data::Dumper::Dumper($self->{_metaData});          return Data::Dumper::Dumper($self->{_metaData});
539  }  }
540    
541  =head3 CreateTables  =head3 CreateTables
542    
543  C<< $datanase->CreateTables(); >>  C<< $erdb->CreateTables(); >>
544    
545  This method creates the tables for the database from the metadata structure loaded by the  This method creates the tables for the database from the metadata structure loaded by the
546  constructor. It is expected this function will only be used on rare occasions, when the  constructor. It is expected this function will only be used on rare occasions, when the
# Line 320  Line 551 
551    
552  sub CreateTables {  sub CreateTables {
553          # Get the parameters.          # Get the parameters.
554          my $self = shift @_;      my ($self) = @_;
555          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
556          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
557          # Loop through the entities.          # Loop through the entities.
558          while (my ($entityName, $entityData) = each %{$metadata->{Entities}}) {      my $entityHash = $metadata->{Entities};
559        for my $entityName (keys %{$entityHash}) {
560            my $entityData = $entityHash->{$entityName};
561                  # Tell the user what we're doing.                  # Tell the user what we're doing.
562                  Trace("Creating relations for entity $entityName.") if T(1);                  Trace("Creating relations for entity $entityName.") if T(1);
563                  # Loop through the entity's relations.                  # Loop through the entity's relations.
# Line 345  Line 578 
578    
579  =head3 CreateTable  =head3 CreateTable
580    
581  C<< $database->CreateTable($tableName, $indexFlag); >>  C<< $erdb->CreateTable($tableName, $indexFlag, $estimatedRows); >>
582    
583  Create the table for a relation and optionally create its indexes.  Create the table for a relation and optionally create its indexes.
584    
# Line 355  Line 588 
588    
589  Name of the relation (which will also be the table name).  Name of the relation (which will also be the table name).
590    
591  =item $indexFlag  =item indexFlag
592    
593  TRUE if the indexes for the relation should be created, else FALSE. If FALSE,  TRUE if the indexes for the relation should be created, else FALSE. If FALSE,
594  L</CreateIndexes> must be called later to bring the indexes into existence.  L</CreateIndexes> must be called later to bring the indexes into existence.
595    
596    =item estimatedRows (optional)
597    
598    If specified, the estimated maximum number of rows for the relation. This
599    information allows the creation of tables using storage engines that are
600    faster but require size estimates, such as MyISAM.
601    
602  =back  =back
603    
604  =cut  =cut
605    
606  sub CreateTable {  sub CreateTable {
607          # Get the parameters.          # Get the parameters.
608          my $self = shift @_;      my ($self, $relationName, $indexFlag, $estimatedRows) = @_;
         my ($relationName, $indexFlag) = @_;  
609          # Get the database handle.          # Get the database handle.
610          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
611          # Get the relation data and determine whether or not the relation is primary.          # Get the relation data and determine whether or not the relation is primary.
# Line 391  Line 629 
629          # Insure the table is not already there.          # Insure the table is not already there.
630          $dbh->drop_table(tbl => $relationName);          $dbh->drop_table(tbl => $relationName);
631          Trace("Table $relationName dropped.") if T(2);          Trace("Table $relationName dropped.") if T(2);
632        # If there are estimated rows, create an estimate so we can take advantage of
633        # faster DB technologies.
634        my $estimation = undef;
635        if ($estimatedRows) {
636            $estimation = [$self->EstimateRowSize($relationName), $estimatedRows];
637        }
638          # Create the table.          # Create the table.
639          Trace("Creating table $relationName: $fieldThing") if T(2);          Trace("Creating table $relationName: $fieldThing") if T(2);
640          $dbh->create_table(tbl => $relationName, flds => $fieldThing);      $dbh->create_table(tbl => $relationName, flds => $fieldThing, estimates => $estimation);
641          Trace("Relation $relationName created in database.") if T(2);          Trace("Relation $relationName created in database.") if T(2);
642          # If we want to build the indexes, we do it here.          # If we want to build the indexes, we do it here.
643          if ($indexFlag) {          if ($indexFlag) {
# Line 403  Line 647 
647    
648  =head3 CreateIndex  =head3 CreateIndex
649    
650  C<< $database->CreateIndex($relationName); >>  C<< $erdb->CreateIndex($relationName); >>
651    
652  Create the indexes for a relation. If a table is being loaded from a large source file (as  Create the indexes for a relation. If a table is being loaded from a large source file (as
653  is the case in L</LoadTable>), it is best to create the indexes after the load. If that is  is the case in L</LoadTable>), it is sometimes best to create the indexes after the load.
654  the case, then L</CreateTable> should be called with the index flag set to FALSE, and this  If that is the case, then L</CreateTable> should be called with the index flag set to
655  method used after the load to create the indexes for the table.  FALSE, and this method used after the load to create the indexes for the table.
656    
657  =cut  =cut
658    
659  sub CreateIndex {  sub CreateIndex {
660          # Get the parameters.          # Get the parameters.
661          my $self = shift @_;      my ($self, $relationName) = @_;
         my ($relationName) = @_;  
662          # Get the relation's descriptor.          # Get the relation's descriptor.
663          my $relationData = $self->_FindRelation($relationName);          my $relationData = $self->_FindRelation($relationName);
664          # Get the database handle.          # Get the database handle.
665          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
666          # Now we need to create this relation's indexes. We do this by looping through its index table.          # Now we need to create this relation's indexes. We do this by looping through its index table.
667          while (my ($indexName, $indexData) = each %{$relationData->{Indexes}}) {      my $indexHash = $relationData->{Indexes};
668        for my $indexName (keys %{$indexHash}) {
669            my $indexData = $indexHash->{$indexName};
670                  # Get the index's field list.                  # Get the index's field list.
671                  my @fieldList = _FixNames(@{$indexData->{IndexFields}});                  my @fieldList = _FixNames(@{$indexData->{IndexFields}});
672                  my $flds = join(', ', @fieldList);                  my $flds = join(', ', @fieldList);
# Line 435  Line 680 
680    
681  =head3 LoadTables  =head3 LoadTables
682    
683  C<< my $stats = $database->LoadTables($directoryName, $rebuild); >>  C<< my $stats = $erdb->LoadTables($directoryName, $rebuild); >>
684    
685  This method will load the database tables from a directory. The tables must already have been created  This method will load the database tables from a directory. The tables must already have been created
686  in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name;  in the database. (This can be done by calling L</CreateTables>.) The caller passes in a directory name;
# Line 471  Line 716 
716    
717  sub LoadTables {  sub LoadTables {
718          # Get the parameters.          # Get the parameters.
719          my $self = shift @_;      my ($self, $directoryName, $rebuild) = @_;
         my ($directoryName, $rebuild) = @_;  
720          # Start the timer.          # Start the timer.
721          my $startTime = gettimeofday;          my $startTime = gettimeofday;
722          # Clean any trailing slash from the directory name.          # Clean any trailing slash from the directory name.
# Line 506  Line 750 
750    
751  =head3 GetTableNames  =head3 GetTableNames
752    
753  C<< my @names = $database->GetTableNames; >>  C<< my @names = $erdb->GetTableNames; >>
754    
755  Return a list of the relations required to implement this database.  Return a list of the relations required to implement this database.
756    
# Line 514  Line 758 
758    
759  sub GetTableNames {  sub GetTableNames {
760          # Get the parameters.          # Get the parameters.
761          my $self = shift @_;      my ($self) = @_;
762          # Get the relation list from the metadata.          # Get the relation list from the metadata.
763          my $relationTable = $self->{_metaData}->{RelationTable};          my $relationTable = $self->{_metaData}->{RelationTable};
764          # Return the relation names.          # Return the relation names.
# Line 523  Line 767 
767    
768  =head3 GetEntityTypes  =head3 GetEntityTypes
769    
770  C<< my @names = $database->GetEntityTypes; >>  C<< my @names = $erdb->GetEntityTypes; >>
771    
772  Return a list of the entity type names.  Return a list of the entity type names.
773    
# Line 531  Line 775 
775    
776  sub GetEntityTypes {  sub GetEntityTypes {
777          # Get the database object.          # Get the database object.
778          my $self = shift @_;      my ($self) = @_;
779          # Get the entity list from the metadata object.          # Get the entity list from the metadata object.
780          my $entityList = $self->{_metaData}->{Entities};          my $entityList = $self->{_metaData}->{Entities};
781          # Return the list of entity names in alphabetical order.          # Return the list of entity names in alphabetical order.
# Line 540  Line 784 
784    
785  =head3 Get  =head3 Get
786    
787  C<< my $query = $database->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >>  C<< my $query = $erdb->Get(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >>
788    
789  This method returns a query object for entities of a specified type using a specified filter.  This method returns a query object for entities of a specified type using a specified filter.
790  The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each  The filter is a standard WHERE/ORDER BY clause with question marks as parameter markers and each
# Line 548  Line 792 
792  following call requests all B<Genome> objects for the genus specified in the variable  following call requests all B<Genome> objects for the genus specified in the variable
793  $genus.  $genus.
794    
795  C<< $query = $sprout->Get(['Genome'], "Genome(genus) = ?", $genus); >>  C<< $query = $erdb->Get(['Genome'], "Genome(genus) = ?", $genus); >>
796    
797  The WHERE clause contains a single question mark, so there is a single additional  The WHERE clause contains a single question mark, so there is a single additional
798  parameter representing the parameter value. It would also be possible to code  parameter representing the parameter value. It would also be possible to code
799    
800  C<< $query = $sprout->Get(['Genome'], "Genome(genus) = \'$genus\'"); >>  C<< $query = $erdb->Get(['Genome'], "Genome(genus) = \'$genus\'"); >>
801    
802  however, this version of the call would generate a syntax error if there were any quote  however, this version of the call would generate a syntax error if there were any quote
803  characters inside the variable C<$genus>.  characters inside the variable C<$genus>.
# Line 565  Line 809 
809  It is possible to specify multiple entity and relationship names in order to retrieve more than  It is possible to specify multiple entity and relationship names in order to retrieve more than
810  one object's data at the same time, which allows highly complex joined queries. For example,  one object's data at the same time, which allows highly complex joined queries. For example,
811    
812  C<< $query = $sprout->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", $genus); >>  C<< $query = $erdb->Get(['Genome', 'ComesFrom', 'Source'], "Genome(genus) = ?", $genus); >>
813    
814  If multiple names are specified, then the query processor will automatically determine a  If multiple names are specified, then the query processor will automatically determine a
815  join path between the entities and relationships. The algorithm used is very simplistic.  join path between the entities and relationships. The algorithm used is very simplistic.
# Line 616  Line 860 
860    
861  sub Get {  sub Get {
862          # Get the parameters.          # Get the parameters.
863          my $self = shift @_;      my ($self, $objectNames, $filterClause, @params) = @_;
         my ($objectNames, $filterClause, @params) = @_;  
864          # Construct the SELECT statement. The general pattern is          # Construct the SELECT statement. The general pattern is
865          #          #
866          # SELECT name1.*, name2.*, ... nameN.* FROM name1, name2, ... nameN          # SELECT name1.*, name2.*, ... nameN.* FROM name1, name2, ... nameN
# Line 729  Line 972 
972                          $command .= " ORDER BY $orderClause";                          $command .= " ORDER BY $orderClause";
973                  }                  }
974          }          }
975          Trace("SQL query: $command") if T(2);      Trace("SQL query: $command") if T(3);
976          Trace("PARMS: '" . (join "', '", @params) . "'") if (T(3) && (@params > 0));      Trace("PARMS: '" . (join "', '", @params) . "'") if (T(4) && (@params > 0));
977          my $sth = $dbh->prepare_command($command);          my $sth = $dbh->prepare_command($command);
978          # Execute it with the parameters bound in.          # Execute it with the parameters bound in.
979          $sth->execute(@params) || Confess("SELECT error" . $sth->errstr());          $sth->execute(@params) || Confess("SELECT error" . $sth->errstr());
# Line 739  Line 982 
982          return $retVal;          return $retVal;
983  }  }
984    
985    =head3 GetList
986    
987    C<< my @dbObjects = $erdb->GetList(\@objectNames, $filterClause, $param1, $param2, ..., $paramN); >>
988    
989    Return a list of object descriptors for the specified objects as determined by the
990    specified filter clause.
991    
992    This method is essentially the same as L</Get> except it returns a list of objects rather
993    than a query object that can be used to get the results one record at a time.
994    
995    =over 4
996    
997    =item objectNames
998    
999    List containing the names of the entity and relationship objects to be retrieved.
1000    
1001    =item filterClause
1002    
1003    WHERE clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can
1004    be parameterized with parameter markers (C<?>). Each field used in the WHERE clause must be
1005    specified in the standard form B<I<objectName>(I<fieldName>)>. Any parameters specified
1006    in the filter clause should be added to the parameter list as additional parameters. The
1007    fields in a filter clause can come from primary entity relations, relationship relations,
1008    or secondary entity relations; however, all of the entities and relationships involved must
1009    be included in the list of object names.
1010    
1011    The filter clause can also specify a sort order. To do this, simply follow the filter string
1012    with an ORDER BY clause. For example, the following filter string gets all genomes for a
1013    particular genus and sorts them by species name.
1014    
1015    C<< "Genome(genus) = ? ORDER BY Genome(species)" >>
1016    
1017    The rules for field references in a sort order are the same as those for field references in the
1018    filter clause in general; however, odd things may happen if a sort field is from a secondary
1019    relation.
1020    
1021    =item param1, param2, ..., paramN
1022    
1023    Parameter values to be substituted into the filter clause.
1024    
1025    =item RETURN
1026    
1027    Returns a list of B<DBObject>s that satisfy the query conditions.
1028    
1029    =back
1030    
1031    =cut
1032    #: Return Type @%
1033    sub GetList {
1034        # Get the parameters.
1035        my ($self, $objectNames, $filterClause, @params) = @_;
1036        # Declare the return variable.
1037        my @retVal = ();
1038        # Perform the query.
1039        my $query = $self->Get($objectNames, $filterClause, @params);
1040        # Loop through the results.
1041        while (my $object = $query->Fetch) {
1042            push @retVal, $object;
1043        }
1044        # Return the result.
1045        return @retVal;
1046    }
1047    
1048  =head3 ComputeObjectSentence  =head3 ComputeObjectSentence
1049    
1050  C<< my $sentence = $database->ComputeObjectSentence($objectName); >>  C<< my $sentence = $erdb->ComputeObjectSentence($objectName); >>
1051    
1052  Check an object name, and if it is a relationship convert it to a relationship sentence.  Check an object name, and if it is a relationship convert it to a relationship sentence.
1053    
# Line 761  Line 1067 
1067    
1068  sub ComputeObjectSentence {  sub ComputeObjectSentence {
1069          # Get the parameters.          # Get the parameters.
1070          my $self = shift @_;      my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1071          # Set the default return value.          # Set the default return value.
1072          my $retVal = $objectName;          my $retVal = $objectName;
1073          # Look for the object as a relationship.          # Look for the object as a relationship.
# Line 777  Line 1082 
1082    
1083  =head3 DumpRelations  =head3 DumpRelations
1084    
1085  C<< $database->DumpRelations($outputDirectory); >>  C<< $erdb->DumpRelations($outputDirectory); >>
1086    
1087  Write the contents of all the relations to tab-delimited files in the specified directory.  Write the contents of all the relations to tab-delimited files in the specified directory.
1088  Each file will have the same name as the relation dumped, with an extension of DTX.  Each file will have the same name as the relation dumped, with an extension of DTX.
# Line 794  Line 1099 
1099    
1100  sub DumpRelations {  sub DumpRelations {
1101          # Get the parameters.          # Get the parameters.
1102          my $self = shift @_;      my ($self, $outputDirectory) = @_;
         my ($outputDirectory) = @_;  
1103          # Now we need to run through all the relations. First, we loop through the entities.          # Now we need to run through all the relations. First, we loop through the entities.
1104          my $metaData = $self->{_metaData};          my $metaData = $self->{_metaData};
1105          my $entities = $metaData->{Entities};          my $entities = $metaData->{Entities};
1106          while (my ($entityName, $entityStructure) = each %{$entities}) {      for my $entityName (keys %{$entities}) {
1107            my $entityStructure = $entities->{$entityName};
1108                  # Get the entity's relations.                  # Get the entity's relations.
1109                  my $relationList = $entityStructure->{Relations};                  my $relationList = $entityStructure->{Relations};
1110                  # Loop through the relations, dumping them.                  # Loop through the relations, dumping them.
1111                  while (my ($relationName, $relation) = each %{$relationList}) {          for my $relationName (keys %{$relationList}) {
1112                my $relation = $relationList->{$relationName};
1113                          $self->_DumpRelation($outputDirectory, $relationName, $relation);                          $self->_DumpRelation($outputDirectory, $relationName, $relation);
1114                  }                  }
1115          }          }
1116          # Next, we loop through the relationships.          # Next, we loop through the relationships.
1117          my $relationships = $metaData->{Relationships};          my $relationships = $metaData->{Relationships};
1118          while (my ($relationshipName, $relationshipStructure) = each %{$relationships}) {      for my $relationshipName (keys %{$relationships}) {
1119            my $relationshipStructure = $relationships->{$relationshipName};
1120                  # Dump this relationship's relation.                  # Dump this relationship's relation.
1121                  $self->_DumpRelation($outputDirectory, $relationshipName, $relationshipStructure->{Relations}->{$relationshipName});                  $self->_DumpRelation($outputDirectory, $relationshipName, $relationshipStructure->{Relations}->{$relationshipName});
1122          }          }
# Line 817  Line 1124 
1124    
1125  =head3 InsertObject  =head3 InsertObject
1126    
1127  C<< my $ok = $database->InsertObject($objectType, \%fieldHash); >>  C<< my $ok = $erdb->InsertObject($objectType, \%fieldHash); >>
1128    
1129  Insert an object into the database. The object is defined by a type name and then a hash  Insert an object into the database. The object is defined by a type name and then a hash
1130  of field names to values. Field values in the primary relation are represented by scalars.  of field names to values. Field values in the primary relation are represented by scalars.
# Line 826  Line 1133 
1133  example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases  example, the following line inserts an inactive PEG feature named C<fig|188.1.peg.1> with aliases
1134  C<ZP_00210270.1> and C<gi|46206278>.  C<ZP_00210270.1> and C<gi|46206278>.
1135    
1136  C<< $database->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>  C<< $erdb->InsertObject('Feature', { id => 'fig|188.1.peg.1', active => 0, feature-type => 'peg', alias => ['ZP_00210270.1', 'gi|46206278']}); >>
1137    
1138  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and  The next statement inserts a C<HasProperty> relationship between feature C<fig|158879.1.peg.1> and
1139  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.  property C<4> with an evidence URL of C<http://seedu.uchicago.edu/query.cgi?article_id=142>.
1140    
1141  C<< $database->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>  C<< $erdb->InsertObject('HasProperty', { 'from-link' => 'fig|158879.1.peg.1', 'to-link' => 4, evidence = 'http://seedu.uchicago.edu/query.cgi?article_id=142'}); >>
1142    
1143  =over 4  =over 4
1144    
# Line 853  Line 1160 
1160    
1161  sub InsertObject {  sub InsertObject {
1162          # Get the parameters.          # Get the parameters.
1163          my $self = shift @_;      my ($self, $newObjectType, $fieldHash) = @_;
         my ($newObjectType, $fieldHash) = @_;  
1164          # Denote that so far we appear successful.          # Denote that so far we appear successful.
1165          my $retVal = 1;          my $retVal = 1;
1166          # Get the database handle.          # Get the database handle.
# Line 864  Line 1170 
1170          # Loop through the relations. We'll build insert statements for each one. If a relation is          # Loop through the relations. We'll build insert statements for each one. If a relation is
1171          # secondary, we may end up generating multiple insert statements. If an error occurs, we          # secondary, we may end up generating multiple insert statements. If an error occurs, we
1172          # stop the loop.          # stop the loop.
1173          while ($retVal && (my ($relationName, $relationDefinition) = each %{$relationTable})) {      my @relationList = keys %{$relationTable};
1174        for (my $i = 0; $retVal && $i <= $#relationList; $i++) {
1175            my $relationName = $relationList[$i];
1176            my $relationDefinition = $relationTable->{$relationName};
1177                  # Get the relation's fields. For each field we will collect a value in the corresponding                  # Get the relation's fields. For each field we will collect a value in the corresponding
1178                  # position of the @valueList array. If one of the fields is missing, we will add it to the                  # position of the @valueList array. If one of the fields is missing, we will add it to the
1179                  # @missing list.                  # @missing list.
# Line 954  Line 1263 
1263    
1264  =head3 LoadTable  =head3 LoadTable
1265    
1266  C<< my %results = $database->LoadTable($fileName, $relationName, $truncateFlag); >>  C<< my %results = $erdb->LoadTable($fileName, $relationName, $truncateFlag); >>
1267    
1268  Load data from a tab-delimited file into a specified table, optionally re-creating the table first.  Load data from a tab-delimited file into a specified table, optionally re-creating the table
1269    first.
1270    
1271  =over 4  =over 4
1272    
# Line 974  Line 1284 
1284    
1285  =item RETURN  =item RETURN
1286    
1287  Returns a statistical object containing the number of records read and a list of the error messages.  Returns a statistical object containing the number of records read and a list of
1288    the error messages.
1289    
1290  =back  =back
1291    
1292  =cut  =cut
1293  sub LoadTable {  sub LoadTable {
1294          # Get the parameters.          # Get the parameters.
1295          my $self = shift @_;      my ($self, $fileName, $relationName, $truncateFlag) = @_;
         my ($fileName, $relationName, $truncateFlag) = @_;  
1296          # Create the statistical return object.          # Create the statistical return object.
1297          my $retVal = _GetLoadStats();          my $retVal = _GetLoadStats();
1298          # Trace the fact of the load.          # Trace the fact of the load.
1299          Trace("Loading table $relationName from $fileName") if T(1);      Trace("Loading table $relationName from $fileName") if T(2);
1300          # Get the database handle.          # Get the database handle.
1301          my $dbh = $self->{_dbh};          my $dbh = $self->{_dbh};
1302          # Get the relation data.          # Get the relation data.
1303          my $relation = $self->_FindRelation($relationName);          my $relation = $self->_FindRelation($relationName);
1304          # Check the truncation flag.          # Check the truncation flag.
1305          if ($truncateFlag) {          if ($truncateFlag) {
1306                  Trace("Creating table $relationName") if T(1);          Trace("Creating table $relationName") if T(2);
1307                  # Re-create the table without its index.                  # Re-create the table without its index.
1308                  $self->CreateTable($relationName, 0);                  $self->CreateTable($relationName, 0);
1309            # If this is a pre-index DBMS, create the index here.
1310            if ($dbh->{_preIndex}) {
1311                eval {
1312                    $self->CreateIndex($relationName);
1313                };
1314                if ($@) {
1315                    $retVal->AddMessage($@);
1316                }
1317            }
1318          }          }
1319          # Determine whether or not this is a primary relation. Primary relations have an extra          # Determine whether or not this is a primary relation. Primary relations have an extra
1320          # field indicating whether or not a given object is new or was loaded from the flat files.          # field indicating whether or not a given object is new or was loaded from the flat files.
# Line 1003  Line 1322 
1322          # Get the number of fields in this relation.          # Get the number of fields in this relation.
1323          my @fieldList = @{$relation->{Fields}};          my @fieldList = @{$relation->{Fields}};
1324          my $fieldCount = @fieldList;          my $fieldCount = @fieldList;
         # Record the number of expected fields.  
         my $expectedFields = $fieldCount + ($primary ? 1 : 0);  
1325          # Start a database transaction.          # Start a database transaction.
1326          $dbh->begin_tran;          $dbh->begin_tran;
1327          # Open the relation file. We need to create a cleaned-up copy before loading.          # Open the relation file. We need to create a cleaned-up copy before loading.
1328          open TABLEIN, '<', $fileName;          open TABLEIN, '<', $fileName;
1329          my $tempName = "$fileName.tbl";          my $tempName = "$fileName.tbl";
1330          open TABLEOUT, '>', $tempName;          open TABLEOUT, '>', $tempName;
1331        my $inputCount = 0;
1332          # Loop through the file.          # Loop through the file.
1333          while (<TABLEIN>) {          while (<TABLEIN>) {
1334            $inputCount++;
1335                  # Chop off the new-line character.                  # Chop off the new-line character.
1336                  my $record = $_;          my $record = Tracer::Strip($_);
1337                  chomp $record;          # Only proceed if the record is non-blank.
1338            if ($record) {
1339                  # Escape all the backslashes found in the line.                  # Escape all the backslashes found in the line.
1340                  $record =~ s/\\/\\\\/g;                  $record =~ s/\\/\\\\/g;
1341                # Insure the number of fields is correct.
1342                my @fields = split /\t/, $record;
1343                while (@fields > $fieldCount) {
1344                    my $extraField = $fields[$#fields];
1345                    delete $fields[$#fields];
1346                    if ($extraField) {
1347                        Trace("Nonblank extra field value \"$extraField\" deleted from record $inputCount of $fileName.") if T(1);
1348                    }
1349                }
1350                while (@fields < $fieldCount) {
1351                    push @fields, "";
1352                }
1353                  # If this is a primary relation, add a 0 for the new-record flag (indicating that                  # If this is a primary relation, add a 0 for the new-record flag (indicating that
1354                  # this record is not new, but part of the original load).                  # this record is not new, but part of the original load).
1355                  if ($primary) {                  if ($primary) {
1356                          $record .= "\t0";                  push @fields, "0";
1357                  }                  }
1358                  # Write the record.                  # Write the record.
1359                $record = join "\t", @fields;
1360                  print TABLEOUT "$record\n";                  print TABLEOUT "$record\n";
1361                  # Count the record read.              # Count the record written.
1362                  my $count = $retVal->Add('records');                  my $count = $retVal->Add('records');
1363                my $len = length $record;
1364                Trace("Record $count written with $len characters.") if T(4);
1365            } else {
1366                # Here we have a blank record.
1367                $retVal->Add('skipped');
1368            }
1369          }          }
1370          # Close the files.          # Close the files.
1371          close TABLEIN;          close TABLEIN;
1372          close TABLEOUT;          close TABLEOUT;
1373        Trace("Temporary file $tempName created.") if T(2);
1374          # Load the table.          # Load the table.
1375          my $rv;          my $rv;
1376          eval {          eval {
1377                  $rv = $dbh->load_table(file => $tempName, tbl => $relationName);                  $rv = $dbh->load_table(file => $tempName, tbl => $relationName);
1378          };          };
1379          if (!defined $rv) {          if (!defined $rv) {
1380                  $retVal->AddMessage("Table load failed for $relationName.");          $retVal->AddMessage($@) if ($@);
1381            $retVal->AddMessage("Table load failed for $relationName using $tempName.");
1382                  Trace("Table load failed for $relationName.") if T(1);                  Trace("Table load failed for $relationName.") if T(1);
1383          } else {          } else {
1384                  # Here we successfully loaded the table. Trace the number of records loaded.                  # Here we successfully loaded the table. Trace the number of records loaded.
1385                  Trace("$retVal->{records} records read for $relationName.") if T(1);          Trace("$retVal->{records} records read for $relationName.") if T(2);
1386                  # If we're rebuilding, we need to create the table indexes.                  # If we're rebuilding, we need to create the table indexes.
1387                  if ($truncateFlag) {          if ($truncateFlag && ! $dbh->{_preIndex}) {
1388                          eval {                          eval {
1389                                  $self->CreateIndex($relationName);                                  $self->CreateIndex($relationName);
1390                          };                          };
# Line 1051  Line 1392 
1392                                  $retVal->AddMessage($@);                                  $retVal->AddMessage($@);
1393                          }                          }
1394                  }                  }
1395            # Analyze the table to help optimize tables.
1396          }          }
1397          # Commit the database changes.          # Commit the database changes.
1398          $dbh->commit_tran;          $dbh->commit_tran;
1399        $dbh->vacuum_it($relationName);
1400          # Delete the temporary file.          # Delete the temporary file.
1401          unlink $tempName;          unlink $tempName;
1402          # Return the statistics.          # Return the statistics.
# Line 1062  Line 1405 
1405    
1406  =head3 GenerateEntity  =head3 GenerateEntity
1407    
1408  C<< my $fieldHash = $database->GenerateEntity($id, $type, \%values); >>  C<< my $fieldHash = $erdb->GenerateEntity($id, $type, \%values); >>
1409    
1410  Generate the data for a new entity instance. This method creates a field hash suitable for  Generate the data for a new entity instance. This method creates a field hash suitable for
1411  passing as a parameter to L</InsertObject>. The ID is specified by the callr, but the rest  passing as a parameter to L</InsertObject>. The ID is specified by the callr, but the rest
# Line 1100  Line 1443 
1443    
1444  sub GenerateEntity {  sub GenerateEntity {
1445          # Get the parameters.          # Get the parameters.
1446          my $self = shift @_;      my ($self, $id, $type, $values) = @_;
         my ($id, $type, $values) = @_;  
1447          # Create the return hash.          # Create the return hash.
1448          my $this = { id => $id };          my $this = { id => $id };
1449          # Get the metadata structure.          # Get the metadata structure.
# Line 1119  Line 1461 
1461          return $this;          return $this;
1462  }  }
1463    
1464    =head3 GetEntity
1465    
1466    C<< my $entityObject = $erdb->GetEntity($entityType, $ID); >>
1467    
1468    Return an object describing the entity instance with a specified ID.
1469    
1470    =over 4
1471    
1472    =item entityType
1473    
1474    Entity type name.
1475    
1476    =item ID
1477    
1478    ID of the desired entity.
1479    
1480    =item RETURN
1481    
1482    Returns a B<DBObject> representing the desired entity instance, or an undefined value if no
1483    instance is found with the specified key.
1484    
1485    =back
1486    
1487    =cut
1488    
1489    sub GetEntity {
1490        # Get the parameters.
1491        my ($self, $entityType, $ID) = @_;
1492        # Create a query.
1493        my $query = $self->Get([$entityType], "$entityType(id) = ?", $ID);
1494        # Get the first (and only) object.
1495        my $retVal = $query->Fetch();
1496        # Return the result.
1497        return $retVal;
1498    }
1499    
1500    =head3 GetEntityValues
1501    
1502    C<< my @values = $erdb->GetEntityValues($entityType, $ID, \@fields); >>
1503    
1504    Return a list of values from a specified entity instance.
1505    
1506    =over 4
1507    
1508    =item entityType
1509    
1510    Entity type name.
1511    
1512    =item ID
1513    
1514    ID of the desired entity.
1515    
1516    =item fields
1517    
1518    List of field names, each of the form I<objectName>C<(>I<fieldName>C<)>.
1519    
1520    =item RETURN
1521    
1522    Returns a flattened list of the values of the specified fields for the specified entity.
1523    
1524    =back
1525    
1526    =cut
1527    
1528    sub GetEntityValues {
1529        # Get the parameters.
1530        my ($self, $entityType, $ID, $fields) = @_;
1531        # Get the specified entity.
1532        my $entity = $self->GetEntity($entityType, $ID);
1533        # Declare the return list.
1534        my @retVal = ();
1535        # If we found the entity, push the values into the return list.
1536        if ($entity) {
1537            push @retVal, $entity->Values($fields);
1538        }
1539        # Return the result.
1540        return @retVal;
1541    }
1542    
1543    =head3 GetAll
1544    
1545    C<< my @list = $erdb->GetAll(\@objectNames, $filterClause, \@parameters, \@fields, $count); >>
1546    
1547    Return a list of values taken from the objects returned by a query. The first three
1548    parameters correspond to the parameters of the L</Get> method. The final parameter is
1549    a list of the fields desired from each record found by the query. The field name
1550    syntax is the standard syntax used for fields in the B<ERDB> system--
1551    B<I<objectName>(I<fieldName>)>-- where I<objectName> is the name of the relevant entity
1552    or relationship and I<fieldName> is the name of the field.
1553    
1554    The list returned will be a list of lists. Each element of the list will contain
1555    the values returned for the fields specified in the fourth parameter. If one of the
1556    fields specified returns multiple values, they are flattened in with the rest. For
1557    example, the following call will return a list of the features in a particular
1558    spreadsheet cell, and each feature will be represented by a list containing the
1559    feature ID followed by all of its aliases.
1560    
1561    C<< $query = $erdb->Get(['ContainsFeature', 'Feature'], "ContainsFeature(from-link) = ?", [$ssCellID], ['Feature(id)', 'Feature(alias)']); >>
1562    
1563    =over 4
1564    
1565    =item objectNames
1566    
1567    List containing the names of the entity and relationship objects to be retrieved.
1568    
1569    =item filterClause
1570    
1571    WHERE/ORDER BY clause (without the WHERE) to be used to filter and sort the query. The WHERE clause can
1572    be parameterized with parameter markers (C<?>). Each field used must be specified in the standard form
1573    B<I<objectName>(I<fieldName>)>. Any parameters specified in the filter clause should be added to the
1574    parameter list as additional parameters. The fields in a filter clause can come from primary
1575    entity relations, relationship relations, or secondary entity relations; however, all of the
1576    entities and relationships involved must be included in the list of object names.
1577    
1578    =item parameterList
1579    
1580    List of the parameters to be substituted in for the parameters marks in the filter clause.
1581    
1582    =item fields
1583    
1584    List of the fields to be returned in each element of the list returned.
1585    
1586    =item count
1587    
1588    Maximum number of records to return. If omitted or 0, all available records will be returned.
1589    
1590    =item RETURN
1591    
1592    Returns a list of list references. Each element of the return list contains the values for the
1593    fields specified in the B<fields> parameter.
1594    
1595    =back
1596    
1597    =cut
1598    #: Return Type @@;
1599    sub GetAll {
1600        # Get the parameters.
1601        my ($self, $objectNames, $filterClause, $parameterList, $fields, $count) = @_;
1602        # Translate the parameters from a list reference to a list. If the parameter
1603        # list is a scalar we convert it into a singleton list.
1604        my @parmList = ();
1605        if (ref $parameterList eq "ARRAY") {
1606            @parmList = @{$parameterList};
1607        } else {
1608            push @parmList, $parameterList;
1609        }
1610        # Create the query.
1611        my $query = $self->Get($objectNames, $filterClause, @parmList);
1612        # Set up a counter of the number of records read.
1613        my $fetched = 0;
1614        # Insure the counter has a value.
1615        if (!defined $count) {
1616            $count = 0;
1617        }
1618        # Loop through the records returned, extracting the fields. Note that if the
1619        # counter is non-zero, we stop when the number of records read hits the count.
1620        my @retVal = ();
1621        while (($count == 0 || $fetched < $count) && (my $row = $query->Fetch())) {
1622            my @rowData = $row->Values($fields);
1623            push @retVal, \@rowData;
1624            $fetched++;
1625        }
1626        # Return the resulting list.
1627        return @retVal;
1628    }
1629    
1630    =head3 EstimateRowSize
1631    
1632    C<< my $rowSize = $erdb->EstimateRowSize($relName); >>
1633    
1634    Estimate the row size of the specified relation. The estimated row size is computed by adding
1635    up the average length for each data type.
1636    
1637    =over 4
1638    
1639    =item relName
1640    
1641    Name of the relation whose estimated row size is desired.
1642    
1643    =item RETURN
1644    
1645    Returns an estimate of the row size for the specified relation.
1646    
1647    =back
1648    
1649    =cut
1650    #: Return Type $;
1651    sub EstimateRowSize {
1652        # Get the parameters.
1653        my ($self, $relName) = @_;
1654        # Declare the return variable.
1655        my $retVal = 0;
1656        # Find the relation descriptor.
1657        my $relation = $self->_FindRelation($relName);
1658        # Get the list of fields.
1659        for my $fieldData (@{$relation->{Fields}}) {
1660            # Get the field type and add its length.
1661            my $fieldLen = $TypeTable{$fieldData->{type}}->{avgLen};
1662            $retVal += $fieldLen;
1663        }
1664        # Return the result.
1665        return $retVal;
1666    }
1667    
1668  =head2 Internal Utility Methods  =head2 Internal Utility Methods
1669    
# Line 1234  Line 1779 
1779    
1780  sub _DumpRelation {  sub _DumpRelation {
1781          # Get the parameters.          # Get the parameters.
1782          my $self = shift @_;      my ($self, $outputDirectory, $relationName, $relation) = @_;
         my ($outputDirectory, $relationName, $relation) = @_;  
1783          # Open the output file.          # Open the output file.
1784          my $fileName = "$outputDirectory/$relationName.dtx";          my $fileName = "$outputDirectory/$relationName.dtx";
1785          open(DTXOUT, ">$fileName") || Confess("Could not open dump file $fileName: $!");          open(DTXOUT, ">$fileName") || Confess("Could not open dump file $fileName: $!");
# Line 1281  Line 1825 
1825    
1826  sub _GetStructure {  sub _GetStructure {
1827          # Get the parameters.          # Get the parameters.
1828          my $self = shift @_;      my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1829          # Get the metadata structure.          # Get the metadata structure.
1830          my $metadata = $self->{_metaData};          my $metadata = $self->{_metaData};
1831          # Declare the variable to receive the descriptor.          # Declare the variable to receive the descriptor.
# Line 1321  Line 1864 
1864    
1865  sub _GetRelationTable {  sub _GetRelationTable {
1866          # Get the parameters.          # Get the parameters.
1867          my $self = shift @_;      my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1868          # Get the descriptor from the metadata.          # Get the descriptor from the metadata.
1869          my $objectData = $self->_GetStructure($objectName);          my $objectData = $self->_GetStructure($objectName);
1870          # Return the object's relation list.          # Return the object's relation list.
# Line 1351  Line 1893 
1893    
1894  sub _GetFieldTable {  sub _GetFieldTable {
1895          # Get the parameters.          # Get the parameters.
1896          my $self = shift @_;      my ($self, $objectName) = @_;
         my ($objectName) = @_;  
1897          # Get the descriptor from the metadata.          # Get the descriptor from the metadata.
1898          my $objectData = $self->_GetStructure($objectName);          my $objectData = $self->_GetStructure($objectName);
1899          # Return the object's field table.          # Return the object's field table.
# Line 1449  Line 1990 
1990    
1991  sub _LoadRelation {  sub _LoadRelation {
1992          # Get the parameters.          # Get the parameters.
1993          my $self = shift @_;      my ($self, $directoryName, $relationName, $rebuild) = @_;
         my ($directoryName, $relationName, $rebuild) = @_;  
1994          # Create the file name.          # Create the file name.
1995          my $fileName = "$directoryName/$relationName";          my $fileName = "$directoryName/$relationName";
1996          # If the file doesn't exist, try adding the .dtx suffix.          # If the file doesn't exist, try adding the .dtx suffix.
# Line 1500  Line 2040 
2040  sub _LoadMetaData {  sub _LoadMetaData {
2041          # Get the parameters.          # Get the parameters.
2042          my ($filename) = @_;          my ($filename) = @_;
2043        Trace("Reading Sprout DBD from $filename.") if T(2);
2044          # Slurp the XML file into a variable. Extensive use of options is used to insure we          # Slurp the XML file into a variable. Extensive use of options is used to insure we
2045          # get the exact structure we want.          # get the exact structure we want.
2046          my $metadata = XML::Simple::XMLin($filename,          my $metadata = XML::Simple::XMLin($filename,
# Line 1524  Line 2065 
2065          my %masterRelationTable = ();          my %masterRelationTable = ();
2066          # Loop through the entities.          # Loop through the entities.
2067          my $entityList = $metadata->{Entities};          my $entityList = $metadata->{Entities};
2068          while (my ($entityName, $entityStructure) = each %{$entityList}) {      for my $entityName (keys %{$entityList}) {
2069            my $entityStructure = $entityList->{$entityName};
2070                  #                  #
2071                  # The first step is to run creating all the entity's default values. For C<Field> elements,          # The first step is to create all the entity's default values. For C<Field> elements,
2072                  # the relation name must be added where it is not specified. For relationships,                  # the relation name must be added where it is not specified. For relationships,
2073                  # the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id>                  # the B<from-link> and B<to-link> fields must be inserted, and for entities an B<id>
2074                  # field must be added to each relation. Finally, each field will have a C<PrettySort> attribute                  # field must be added to each relation. Finally, each field will have a C<PrettySort> attribute
# Line 1572  Line 2114 
2114                  # to a list of fields. First, we need the ID field itself.                  # to a list of fields. First, we need the ID field itself.
2115                  my $idField = $fieldList->{id};                  my $idField = $fieldList->{id};
2116                  # Loop through the relations.                  # Loop through the relations.
2117                  while (my ($relationName, $relation) = each %{$relationTable}) {          for my $relationName (keys %{$relationTable}) {
2118                my $relation = $relationTable->{$relationName};
2119                          # Get the relation's field list.                          # Get the relation's field list.
2120                          my $relationFieldList = $relation->{Fields};                          my $relationFieldList = $relation->{Fields};
2121                          # Add the ID field to it. If the field's already there, it will not make any                          # Add the ID field to it. If the field's already there, it will not make any
# Line 1622  Line 2165 
2165                  # The next step is to insure that each relation has at least one index that begins with the ID field.                  # The next step is to insure that each relation has at least one index that begins with the ID field.
2166                  # After that, we convert each relation's index list to an index table. We first need to loop through                  # After that, we convert each relation's index list to an index table. We first need to loop through
2167                  # the relations.                  # the relations.
2168                  while (my ($relationName, $relation) = each %{$relationTable}) {          for my $relationName (keys %{$relationTable}) {
2169                my $relation = $relationTable->{$relationName};
2170                          # Get the relation's index list.                          # Get the relation's index list.
2171                          my $indexList = $relation->{Indexes};                          my $indexList = $relation->{Indexes};
2172                          # Insure this relation has an ID index.                          # Insure this relation has an ID index.
# Line 1653  Line 2197 
2197          # Loop through the relationships. Relationships actually turn out to be much simpler than entities.          # Loop through the relationships. Relationships actually turn out to be much simpler than entities.
2198          # For one thing, there is only a single constituent relation.          # For one thing, there is only a single constituent relation.
2199          my $relationshipList = $metadata->{Relationships};          my $relationshipList = $metadata->{Relationships};
2200          while (my ($relationshipName, $relationshipStructure) = each %{$relationshipList}) {      for my $relationshipName (keys %{$relationshipList}) {
2201            my $relationshipStructure = $relationshipList->{$relationshipName};
2202                  # Fix up this relationship.                  # Fix up this relationship.
2203                  _FixupFields($relationshipStructure, $relationshipName, 2, 3);                  _FixupFields($relationshipStructure, $relationshipName, 2, 3);
2204                  # Format a description for the FROM field.                  # Format a description for the FROM field.
# Line 1702  Line 2247 
2247                  my @fromList = ();                  my @fromList = ();
2248                  my @toList = ();                  my @toList = ();
2249                  my @bothList = ();                  my @bothList = ();
2250                  while (my ($relationshipName, $relationship) = each %{$relationshipList}) {          Trace("Join table build for $entityName.") if T(4);
2251            for my $relationshipName (keys %{$relationshipList}) {
2252                my $relationship = $relationshipList->{$relationshipName};
2253                          # Determine if this relationship has our entity in one of its link fields.                          # Determine if this relationship has our entity in one of its link fields.
2254                          if ($relationship->{from} eq $entityName) {              my $fromEntity = $relationship->{from};
2255                                  if ($relationship->{to} eq $entityName) {              my $toEntity = $relationship->{to};
2256                Trace("Join check for relationship $relationshipName from $fromEntity to $toEntity.") if T(4);
2257                if ($fromEntity eq $entityName) {
2258                    if ($toEntity eq $entityName) {
2259                                          # Here the relationship is recursive.                                          # Here the relationship is recursive.
2260                                          push @bothList, $relationshipName;                                          push @bothList, $relationshipName;
2261                        Trace("Relationship $relationshipName put in both-list.") if T(4);
2262                                  } else {                                  } else {
2263                                          # Here the relationship comes from the entity.                                          # Here the relationship comes from the entity.
2264                                          push @fromList, $relationshipName;                                          push @fromList, $relationshipName;
2265                        Trace("Relationship $relationshipName put in from-list.") if T(4);
2266                                  }                                  }
2267                          } elsif ($relationship->{to} eq $entityName) {              } elsif ($toEntity eq $entityName) {
2268                                  # Here the relationship goes to the entity.                                  # Here the relationship goes to the entity.
2269                                  push @toList, $relationshipName;                                  push @toList, $relationshipName;
2270                    Trace("Relationship $relationshipName put in to-list.") if T(4);
2271                          }                          }
2272                  }                  }
2273                  # Create the nonrecursive joins. Note that we build two hashes for running                  # Create the nonrecursive joins. Note that we build two hashes for running
# Line 1723  Line 2276 
2276                  # hash table at the same time.                  # hash table at the same time.
2277                  my %directRelationships = ( from => \@fromList, to => \@toList );                  my %directRelationships = ( from => \@fromList, to => \@toList );
2278                  my %otherRelationships = ( from => \@fromList, to => \@toList );                  my %otherRelationships = ( from => \@fromList, to => \@toList );
2279                  while (my ($linkType, $relationships) = each %directRelationships) {          for my $linkType (keys %directRelationships) {
2280                my $relationships = $directRelationships{$linkType};
2281                          # Loop through all the relationships.                          # Loop through all the relationships.
2282                          for my $relationshipName (@{$relationships}) {                          for my $relationshipName (@{$relationships}) {
2283                                  # Create joins between the entity and this relationship.                                  # Create joins between the entity and this relationship.
2284                                  my $linkField = "$relationshipName.${linkType}_link";                                  my $linkField = "$relationshipName.${linkType}_link";
2285                                  my $joinClause = "$entityName.id = $linkField";                                  my $joinClause = "$entityName.id = $linkField";
2286                    Trace("Entity join clause is $joinClause for $entityName and $relationshipName.") if T(4);
2287                                  $joinTable{"$entityName/$relationshipName"} = $joinClause;                                  $joinTable{"$entityName/$relationshipName"} = $joinClause;
2288                                  $joinTable{"$relationshipName/$entityName"} = $joinClause;                                  $joinTable{"$relationshipName/$entityName"} = $joinClause;
2289                                  # Create joins between this relationship and the other relationships.                                  # Create joins between this relationship and the other relationships.
2290                                  while (my ($otherType, $otherships) = each %otherRelationships) {                  for my $otherType (keys %otherRelationships) {
2291                        my $otherships = $otherRelationships{$otherType};
2292                                          for my $otherName (@{$otherships}) {                                          for my $otherName (@{$otherships}) {
2293                                                  # Get the key for this join.                                                  # Get the key for this join.
2294                                                  my $joinKey = "$otherName/$relationshipName";                                                  my $joinKey = "$otherName/$relationshipName";
# Line 1742  Line 2298 
2298                                                          # path is ambiguous. We delete the join from the join                                                          # path is ambiguous. We delete the join from the join
2299                                                          # table to prevent it from being used.                                                          # table to prevent it from being used.
2300                                                          delete $joinTable{$joinKey};                                                          delete $joinTable{$joinKey};
2301                                Trace("Deleting ambiguous join $joinKey.") if T(4);
2302                                                  } elsif ($otherName ne $relationshipName) {                                                  } elsif ($otherName ne $relationshipName) {
2303                                                          # Here we have a valid join. Note that joins between a                                                          # Here we have a valid join. Note that joins between a
2304                                                          # relationship and itself are prohibited.                                                          # relationship and itself are prohibited.
2305                                                          $joinTable{$joinKey} = "$otherName.${otherType}_link = $linkField";                              my $relJoinClause = "$otherName.${otherType}_link = $linkField";
2306                                $joinTable{$joinKey} = $relJoinClause;
2307                                Trace("Relationship join clause is $relJoinClause for $joinKey.") if T(4);
2308                                                  }                                                  }
2309                                          }                                          }
2310                                  }                                  }
# Line 1754  Line 2313 
2313                                  # relationship can only be ambiguous with another recursive relationship,                                  # relationship can only be ambiguous with another recursive relationship,
2314                                  # and the incoming relationship from the outer loop is never recursive.                                  # and the incoming relationship from the outer loop is never recursive.
2315                                  for my $otherName (@bothList) {                                  for my $otherName (@bothList) {
2316                        Trace("Setting up relationship joins to recursive relationship $otherName with $relationshipName.") if T(4);
2317                                          # Join from the left.                                          # Join from the left.
2318                                          $joinTable{"$relationshipName/$otherName"} =                                          $joinTable{"$relationshipName/$otherName"} =
2319                                                  "$linkField = $otherName.from_link";                                                  "$linkField = $otherName.from_link";
# Line 1768  Line 2328 
2328                  # rise to situations where we can't create the path we want; however, it is always                  # rise to situations where we can't create the path we want; however, it is always
2329                  # possible to get the same effect using multiple queries.                  # possible to get the same effect using multiple queries.
2330                  for my $relationshipName (@bothList) {                  for my $relationshipName (@bothList) {
2331                Trace("Setting up entity joins to recursive relationship $relationshipName with $entityName.") if T(4);
2332                          # Join to the entity from each direction.                          # Join to the entity from each direction.
2333                          $joinTable{"$entityName/$relationshipName"} =                          $joinTable{"$entityName/$relationshipName"} =
2334                                  "$entityName.id = $relationshipName.from_link";                                  "$entityName.id = $relationshipName.from_link";
# Line 1818  Line 2379 
2379          # index descriptor does not exist, it will be created automatically so we can add          # index descriptor does not exist, it will be created automatically so we can add
2380          # the field to it.          # the field to it.
2381          unshift @{$newIndex->{IndexFields}}, $firstField;          unshift @{$newIndex->{IndexFields}}, $firstField;
2382        # If this is a one-to-many relationship, the "To" index is unique.
2383        if ($relationshipStructure->{arity} eq "1M" && $indexKey eq "To") {
2384            $newIndex->{Unique} = 'true';
2385        }
2386          # Add the index to the relation.          # Add the index to the relation.
2387          _AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex);          _AddIndex("idx$relationshipName$indexKey", $relationStructure, $newIndex);
2388  }  }
# Line 1907  Line 2472 
2472                  $structure->{Fields} = { };                  $structure->{Fields} = { };
2473          } else {          } else {
2474                  # Here we have a field list. Loop through its fields.                  # Here we have a field list. Loop through its fields.
2475                  while (my ($fieldName, $fieldData) = each %{$structure->{Fields}}) {          my $fieldStructures = $structure->{Fields};
2476            for my $fieldName (keys %{$fieldStructures}) {
2477                Trace("Processing field $fieldName of $defaultRelationName.") if T(4);
2478                my $fieldData = $fieldStructures->{$fieldName};
2479                          # Get the field type.                          # Get the field type.
2480                          my $type = $fieldData->{type};                          my $type = $fieldData->{type};
2481                          # Plug in a relation name if it is needed.                          # Plug in a relation name if it is needed.
# Line 2104  Line 2672 
2672    
2673  sub _IsPrimary {  sub _IsPrimary {
2674          # Get the parameters.          # Get the parameters.
2675          my $self = shift @_;      my ($self, $relationName) = @_;
         my ($relationName) = @_;  
2676          # Check for the relation in the entity table.          # Check for the relation in the entity table.
2677          my $entityTable = $self->{_metaData}->{Entities};          my $entityTable = $self->{_metaData}->{Entities};
2678          my $retVal = exists $entityTable->{$relationName};          my $retVal = exists $entityTable->{$relationName};
# Line 2139  Line 2706 
2706  =cut  =cut
2707  sub _FindRelation {  sub _FindRelation {
2708          # Get the parameters.          # Get the parameters.
2709          my $self = shift @_;      my ($self, $relationName) = @_;
         my ($relationName) = @_;  
2710          # Get the relation's structure from the master relation table in the metadata structure.          # Get the relation's structure from the master relation table in the metadata structure.
2711          my $metaData = $self->{_metaData};          my $metaData = $self->{_metaData};
2712          my $retVal = $metaData->{RelationTable}->{$relationName};          my $retVal = $metaData->{RelationTable}->{$relationName};
# Line 2268  Line 2834 
2834                  my $indexData = $indexTable->{$indexName};                  my $indexData = $indexTable->{$indexName};
2835                  # Determine whether or not the index is unique.                  # Determine whether or not the index is unique.
2836                  my $fullName = $indexName;                  my $fullName = $indexName;
2837                  if ($indexData->{Unique} eq "true") {          if (exists $indexData->{Unique} && $indexData->{Unique} eq "true") {
2838                          $fullName .= " (unique)";                          $fullName .= " (unique)";
2839                  }                  }
2840                  # Start an HTML list item for this index.                  # Start an HTML list item for this index.

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.18

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3