1062 |
# Push the result into the field list. |
# Push the result into the field list. |
1063 |
push @fieldList, $fieldString; |
push @fieldList, $fieldString; |
1064 |
} |
} |
|
# If this is a root table, add the "new_record" flag. It defaults to 0, so |
|
|
if ($rootFlag) { |
|
|
push @fieldList, "new_record $TypeTable{boolean}->{sqlType} NOT NULL DEFAULT 0"; |
|
|
} |
|
1065 |
# Convert the field list into a comma-delimited string. |
# Convert the field list into a comma-delimited string. |
1066 |
my $fieldThing = join(', ', @fieldList); |
my $fieldThing = join(', ', @fieldList); |
1067 |
# Insure the table is not already there. |
# Insure the table is not already there. |
1528 |
return sort keys %{$entityList}; |
return sort keys %{$entityList}; |
1529 |
} |
} |
1530 |
|
|
1531 |
|
=head3 GetConnectingRelationships |
1532 |
|
|
1533 |
|
my @list = $erdb->GetConnectingRelationships($entityName); |
1534 |
|
|
1535 |
|
Return a list of the relationships connected to the specified entity. |
1536 |
|
|
1537 |
|
=over 4 |
1538 |
|
|
1539 |
|
=item entityName |
1540 |
|
|
1541 |
|
Entity whose connected relationships are desired. |
1542 |
|
|
1543 |
|
=item RETURN |
1544 |
|
|
1545 |
|
Returns a list of the relationships that originate from the entity. |
1546 |
|
If the entity is on the from end, it will return the relationship |
1547 |
|
name. If the entity is on the to end it will return the converse of |
1548 |
|
the relationship name. |
1549 |
|
|
1550 |
|
=back |
1551 |
|
|
1552 |
|
=cut |
1553 |
|
|
1554 |
|
sub GetConnectingRelationships { |
1555 |
|
# Get the parameters. |
1556 |
|
my ($self, $entityName) = @_; |
1557 |
|
# Declare the return variable. |
1558 |
|
my @retVal; |
1559 |
|
# Get the relationship list. |
1560 |
|
my $relationships = $self->{_metaData}->{Relationships}; |
1561 |
|
# Find the entity. |
1562 |
|
my $entity = $self->{_metaData}->{Entities}->{$entityName}; |
1563 |
|
# Only proceed if the entity exists. |
1564 |
|
if (! defined $entity) { |
1565 |
|
Trace("Entity $entityName not found.") if T(3); |
1566 |
|
} else { |
1567 |
|
# Loop through the relationships. |
1568 |
|
my @rels = keys %$relationships; |
1569 |
|
Trace(scalar(@rels) . " relationships found in connection search.") if T(3); |
1570 |
|
for my $relationshipName (@rels) { |
1571 |
|
my $relationship = $relationships->{$relationshipName}; |
1572 |
|
if ($relationship->{from} eq $entityName) { |
1573 |
|
# Here we have a forward relationship. |
1574 |
|
push @retVal, $relationshipName; |
1575 |
|
} elsif ($relationship->{to} eq $entityName) { |
1576 |
|
# Here we have a backward relationship. In this case, the |
1577 |
|
# converse relationship name is preferred if it exists. |
1578 |
|
my $converse = $relationship->{converse} || $relationshipName; |
1579 |
|
push @retVal, $converse; |
1580 |
|
} |
1581 |
|
} |
1582 |
|
} |
1583 |
|
# Return the result. |
1584 |
|
return @retVal; |
1585 |
|
} |
1586 |
|
|
1587 |
|
|
1588 |
|
|
1589 |
|
|
1590 |
=head3 GetDataTypes |
=head3 GetDataTypes |
1591 |
|
|
1592 |
my %types = ERDB::GetDataTypes(); |
my %types = ERDB::GetDataTypes(); |
2371 |
} |
} |
2372 |
# Now we parse the key names into sort parameters. First, we prime the return |
# Now we parse the key names into sort parameters. First, we prime the return |
2373 |
# string. |
# string. |
2374 |
my $retVal = "sort -t\"\t\" "; |
my $retVal = "sort -T\"$FIG_Config::temp\" -t\"\t\" "; |
2375 |
# Get the relation's field list. |
# Get the relation's field list. |
2376 |
my @fields = @{$relationData->{Fields}}; |
my @fields = @{$relationData->{Fields}}; |
2377 |
# Loop through the keys. |
# Loop through the keys. |
2401 |
# will stop the inner loop. Note that the field number is |
# will stop the inner loop. Note that the field number is |
2402 |
# 1-based in the sort command, so we have to increment the |
# 1-based in the sort command, so we have to increment the |
2403 |
# index. |
# index. |
2404 |
$fieldSpec = ($i + 1) . $modifier; |
my $realI = $i + 1; |
2405 |
|
$fieldSpec = "$realI,$realI$modifier"; |
2406 |
} |
} |
2407 |
} |
} |
2408 |
# Add this field to the sort command. |
# Add this field to the sort command. |
2793 |
push @missing, $fieldName; |
push @missing, $fieldName; |
2794 |
} |
} |
2795 |
} |
} |
|
# If we are the primary relation, add the new-record flag. |
|
|
if ($relationName eq $newObjectType) { |
|
|
push @valueList, 1; |
|
|
push @fieldNameList, "new_record"; |
|
|
} |
|
2796 |
# Only proceed if there are no missing fields. |
# Only proceed if there are no missing fields. |
2797 |
if (@missing > 0) { |
if (@missing > 0) { |
2798 |
Trace("Relation $relationName for $newObjectType skipped due to missing fields: " . |
Trace("Relation $relationName for $newObjectType skipped due to missing fields: " . |
3022 |
# Analyze the table to improve performance. |
# Analyze the table to improve performance. |
3023 |
if (! $options{partial}) { |
if (! $options{partial}) { |
3024 |
Trace("Analyzing and compacting $relationName.") if T(3); |
Trace("Analyzing and compacting $relationName.") if T(3); |
3025 |
$dbh->vacuum_it($relationName); |
$self->Analyze($relationName); |
3026 |
} |
} |
3027 |
Trace("$relationName load completed.") if T(3); |
Trace("$relationName load completed.") if T(3); |
3028 |
# Return the statistics. |
# Return the statistics. |
3029 |
return $retVal; |
return $retVal; |
3030 |
} |
} |
3031 |
|
|
3032 |
|
=head3 Analyze |
3033 |
|
|
3034 |
|
$erdb->Analyze($tableName); |
3035 |
|
|
3036 |
|
Analyze and compact a table in the database. This is useful after a load |
3037 |
|
to improve the performance of the indexes. |
3038 |
|
|
3039 |
|
=over 4 |
3040 |
|
|
3041 |
|
=item tableName |
3042 |
|
|
3043 |
|
Name of the table to be analyzed and compacted. |
3044 |
|
|
3045 |
|
=back |
3046 |
|
|
3047 |
|
=cut |
3048 |
|
|
3049 |
|
sub Analyze { |
3050 |
|
# Get the parameters. |
3051 |
|
my ($self, $tableName) = @_; |
3052 |
|
# Analyze the table. |
3053 |
|
$self->{_dbh}->vacuum_it($tableName); |
3054 |
|
} |
3055 |
|
|
3056 |
|
=head3 TruncateTable |
3057 |
|
|
3058 |
|
$erdb->TruncateTable($table); |
3059 |
|
|
3060 |
|
Delete all rows from a table quickly. This uses the built-in SQL |
3061 |
|
C<TRUNCATE> statement, which effectively drops and re-creates a table |
3062 |
|
with all its settings intact. |
3063 |
|
|
3064 |
|
=over 4 |
3065 |
|
|
3066 |
|
=item table |
3067 |
|
|
3068 |
|
Name of the table to be cleared. |
3069 |
|
|
3070 |
|
=back |
3071 |
|
|
3072 |
|
=cut |
3073 |
|
|
3074 |
|
sub TruncateTable { |
3075 |
|
# Get the parameters. |
3076 |
|
my ($self, $table) = @_; |
3077 |
|
# Get the database handle. |
3078 |
|
my $dbh = $self->{_dbh}; |
3079 |
|
# Execute a truncation comment. |
3080 |
|
$dbh->SQL("TRUNCATE TABLE $table"); |
3081 |
|
} |
3082 |
|
|
3083 |
|
|
3084 |
=head3 CreateSearchIndex |
=head3 CreateSearchIndex |
3085 |
|
|
3086 |
$erdb->CreateSearchIndex($objectName); |
$erdb->CreateSearchIndex($objectName); |