[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.78, Tue Nov 28 01:02:42 2006 UTC revision 1.84, Wed Jan 24 10:22:22 2007 UTC
# Line 548  Line 548 
548          if (my $notes = $entityData->{Notes}) {          if (my $notes = $entityData->{Notes}) {
549              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";
550          }          }
551          # Now we want a list of the entity's relationships. First, we set up the relationship subsection.          # See if we need a list of the entity's relationships.
552            my $relCount = keys %{$relationshipList};
553            if ($relCount > 0) {
554                # First, we set up the relationship subsection.
555          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";
556          # Loop through the relationships.          # Loop through the relationships.
557          for my $relationship (sort keys %{$relationshipList}) {          for my $relationship (sort keys %{$relationshipList}) {
# Line 564  Line 567 
567          }          }
568          # Close off the relationship list.          # Close off the relationship list.
569          $retVal .= "</ul>\n";          $retVal .= "</ul>\n";
570            }
571          # Get the entity's relations.          # Get the entity's relations.
572          my $relationList = $entityData->{Relations};          my $relationList = $entityData->{Relations};
573          # Create a header for the relation subsection.          # Create a header for the relation subsection.
# Line 1493  Line 1497 
1497          my $actualKeywords = $self->CleanKeywords($searchExpression);          my $actualKeywords = $self->CleanKeywords($searchExpression);
1498          # Prefix a "+" to each uncontrolled word. This converts the default          # Prefix a "+" to each uncontrolled word. This converts the default
1499          # search mode from OR to AND.          # search mode from OR to AND.
1500          $actualKeywords =~ s/(^|\s)(\w)/$1\+$2/g;          $actualKeywords =~ s/(^|\s)(\w|")/$1\+$2/g;
1501          Trace("Actual keywords for search are\n$actualKeywords") if T(3);          Trace("Actual keywords for search are\n$actualKeywords") if T(3);
1502          # We need two match expressions, one for the filter clause and one in the          # We need two match expressions, one for the filter clause and one in the
1503          # query itself. Both will use a parameter mark, so we need to push the          # query itself. Both will use a parameter mark, so we need to push the
# Line 1841  Line 1845 
1845          for my $dir ('from', 'to') {          for my $dir ('from', 'to') {
1846              if ($structure->{$dir} eq $originEntityName) {              if ($structure->{$dir} eq $originEntityName) {
1847                  # Delete all relationship instances on this side of the entity instance.                  # Delete all relationship instances on this side of the entity instance.
1848                    Trace("Disconnecting in $dir direction with ID \"$originEntityID\".");
1849                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);
1850                  $found = 1;                  $found = 1;
1851              }              }
# Line 1852  Line 1857 
1857      }      }
1858  }  }
1859    
1860    =head3 DeleteRow
1861    
1862    C<< $erdb->DeleteRow($relationshipName, $fromLink, $toLink, \%values); >>
1863    
1864    Delete a row from a relationship. In most cases, only the from-link and to-link are
1865    needed; however, for relationships with intersection data values can be specified
1866    for the other fields using a hash.
1867    
1868    =over 4
1869    
1870    =item relationshipName
1871    
1872    Name of the relationship from which the row is to be deleted.
1873    
1874    =item fromLink
1875    
1876    ID of the entity instance in the From direction.
1877    
1878    =item toLink
1879    
1880    ID of the entity instance in the To direction.
1881    
1882    =item values
1883    
1884    Reference to a hash of other values to be used for filtering the delete.
1885    
1886    =back
1887    
1888    =cut
1889    
1890    sub DeleteRow {
1891        # Get the parameters.
1892        my ($self, $relationshipName, $fromLink, $toLink, $values) = @_;
1893        # Create a hash of all the filter information.
1894        my %filter = ('from-link' => $fromLink, 'to-link' => $toLink);
1895        if (defined $values) {
1896            for my $key (keys %{$values}) {
1897                $filter{$key} = $values->{$key};
1898            }
1899        }
1900        # Build an SQL statement out of the hash.
1901        my @filters = ();
1902        my @parms = ();
1903        for my $key (keys %filter) {
1904            push @filters, _FixName($key) . " = ?";
1905            push @parms, $filter{$key};
1906        }
1907        Trace("Parms for delete row are " . join(", ", map { "\"$_\"" } @parms) . ".") if T(SQL => 4);
1908        my $command = "DELETE FROM $relationshipName WHERE " .
1909                      join(" AND ", @filters);
1910        # Execute it.
1911        my $dbh = $self->{_dbh};
1912        $dbh->SQL($command, undef, @parms);
1913    }
1914    
1915  =head3 SortNeeded  =head3 SortNeeded
1916    
1917  C<< my $parms = $erdb->SortNeeded($relationName); >>  C<< my $parms = $erdb->SortNeeded($relationName); >>
# Line 2530  Line 2590 
2590              # The full-text index (if any) is always built last, even for MySQL.              # The full-text index (if any) is always built last, even for MySQL.
2591              # First we need to see if this table has a full-text index. Only              # First we need to see if this table has a full-text index. Only
2592              # primary relations are allowed that privilege.              # primary relations are allowed that privilege.
2593                Trace("Checking for full-text index on $relationName.") if T(2);
2594              if ($self->_IsPrimary($relationName)) {              if ($self->_IsPrimary($relationName)) {
2595                  # Get the relation's entity/relationship structure.                  $self->CreateSearchIndex($relationName);
                 my $structure = $self->_GetStructure($relationName);  
                 # Check for a searchable fields list.  
                 if (exists $structure->{searchFields}) {  
                     # Here we know that we need to create a full-text search index.  
                     # Get an SQL-formatted field name list.  
                     my $fields = join(", ", $self->_FixNames(@{$structure->{searchFields}}));  
                     # Create the index.  
                     $dbh->create_index(tbl => $relationName, idx => "search_idx",  
                                        flds => $fields, kind => 'fulltext');  
                 }  
2596              }              }
2597          }          }
2598      }      }
# Line 2553  Line 2604 
2604      return $retVal;      return $retVal;
2605  }  }
2606    
2607    =head3 CreateSearchIndex
2608    
2609    C<< $erdb->CreateSearchIndex($objectName); >>
2610    
2611    Check for a full-text search index on the specified entity or relationship object, and
2612    if one is required, rebuild it.
2613    
2614    =over 4
2615    
2616    =item objectName
2617    
2618    Name of the entity or relationship to be indexed.
2619    
2620    =back
2621    
2622    =cut
2623    
2624    sub CreateSearchIndex {
2625        # Get the parameters.
2626        my ($self, $objectName) = @_;
2627        # Get the relation's entity/relationship structure.
2628        my $structure = $self->_GetStructure($objectName);
2629        # Get the database handle.
2630        my $dbh = $self->{_dbh};
2631        Trace("Checking for search fields in $objectName.") if T(3);
2632        # Check for a searchable fields list.
2633        if (exists $structure->{searchFields}) {
2634            # Here we know that we need to create a full-text search index.
2635            # Get an SQL-formatted field name list.
2636            my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));
2637            # Create the index. If it already exists, it will be dropped.
2638            $dbh->create_index(tbl => $objectName, idx => "search_idx",
2639                               flds => $fields, kind => 'fulltext');
2640            Trace("Index created for $fields in $objectName.") if T(2);
2641        }
2642    }
2643    
2644  =head3 DropRelation  =head3 DropRelation
2645    
2646  C<< $erdb->DropRelation($relationName); >>  C<< $erdb->DropRelation($relationName); >>
# Line 3239  Line 3327 
3327      # Substitute the bulletin board codes.      # Substitute the bulletin board codes.
3328      $retVal =~ s!\[(/?[bi])\]!<$1>!g;      $retVal =~ s!\[(/?[bi])\]!<$1>!g;
3329      $retVal =~ s!\[p\]!</p><p>!g;      $retVal =~ s!\[p\]!</p><p>!g;
3330        $retVal =~ s!\[link\s+([^\]]+)\]!<a href="$1">!g;
3331        $retVal =~ s!\[/link\]!</a>!g;
3332      # Return the result.      # Return the result.
3333      return $retVal;      return $retVal;
3334  }  }
# Line 4183  Line 4273 
4273          _FixupFields($relationshipStructure, $relationshipName, 2, 3);          _FixupFields($relationshipStructure, $relationshipName, 2, 3);
4274          # Format a description for the FROM field.          # Format a description for the FROM field.
4275          my $fromEntity = $relationshipStructure->{from};          my $fromEntity = $relationshipStructure->{from};
4276          my $fromComment = "<b>id</b> of the source <b><a href=\"#$fromEntity\">$fromEntity</a></b>.";          my $fromComment = "[b]id[/b] of the source [b][link #$fromEntity]$fromEntity\[/link][/b].";
4277          # Get the FROM entity's key type.          # Get the FROM entity's key type.
4278          my $fromType = $entityList->{$fromEntity}->{keyType};          my $fromType = $entityList->{$fromEntity}->{keyType};
4279          # Add the FROM field.          # Add the FROM field.
# Line 4193  Line 4283 
4283                                                      PrettySort => 1});                                                      PrettySort => 1});
4284          # Format a description for the TO field.          # Format a description for the TO field.
4285          my $toEntity = $relationshipStructure->{to};          my $toEntity = $relationshipStructure->{to};
4286          my $toComment = "<b>id</b> of the target <b><a href=\"#$toEntity\">$toEntity</a></b>.";          my $toComment = "[b]id[/b] of the target [b][link #$toEntity]$toEntity\[/link][/b].";
4287          # Get the TO entity's key type.          # Get the TO entity's key type.
4288          my $toType = $entityList->{$toEntity}->{keyType};          my $toType = $entityList->{$toEntity}->{keyType};
4289          # Add the TO field.          # Add the TO field.
# Line 4896  Line 4986 
4986      # Compute the number of columns.      # Compute the number of columns.
4987      my $colCount = @colNames;      my $colCount = @colNames;
4988      # Generate the title row.      # Generate the title row.
4989      my $htmlString = "<p><table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";      my $htmlString = "<table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";
4990      # Loop through the columns, adding the column header rows.      # Loop through the columns, adding the column header rows.
4991      $htmlString .= "<tr>";      $htmlString .= "<tr>";
4992      for my $colName (@colNames) {      for my $colName (@colNames) {
# Line 4915  Line 5005 
5005  =cut  =cut
5006    
5007  sub _CloseTable {  sub _CloseTable {
5008      return "</table></p>\n";      return "</table>\n";
5009  }  }
5010    
5011  =head3 _ShowField  =head3 _ShowField

Legend:
Removed from v.1.78  
changed lines
  Added in v.1.84

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3