Author: spadkins
Date: Sat Jan 7 19:27:33 2012
New Revision: 15076
Modified:
p5ee/trunk/App-Repository/bin/dbmetadata
p5ee/trunk/App-Repository/lib/App/Repository.pm
p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm
Log:
support metadata caching on disk. (reworked to store at the
App::Repository::DBI level) much more reliable.
Modified: p5ee/trunk/App-Repository/bin/dbmetadata
==============================================================================
--- p5ee/trunk/App-Repository/bin/dbmetadata (original)
+++ p5ee/trunk/App-Repository/bin/dbmetadata Sat Jan 7 19:27:33 2012
@@ -3,10 +3,11 @@
use Date::Format;
use App::Options (
- options => [ qw(dbhost dbname dbschema dbuser dbpass repository class
table tmpdir verbose) ],
+ options => [ qw(dbhost dbname dbschema dbuser dbpass repository class
table verbose) ],
option => {
repository => {
description => "Name of repository",
+ default => "default",
},
class => {
description => "The class of the Repository
(App::Repository::MySQL, App::Repository::Oracle) (if not as currently
defined)",
@@ -14,15 +15,22 @@
table => {
description => "List of table names (default is all)",
},
- tmpdir => {
- description => "Temporary directory used for writing out the
metadata",
- default => '${prefix}/tmp',
+ dbenv_option => {
+ description => "Specify which option determines the database
environment",
+ default => "db",
+ },
+ db => {
+ description => "Which environment to produce metadata for
(default, dev, test, prod, etc.)",
+ default => "default",
},
- force_metadata_reload => {
+ db_metadata_dir => {
+ description => "An alternative metadata directory",
+ },
+ db_metadata_load => {
description => "Activates the metadata loading from the database
regardless of whether the files exist",
default => 1,
},
- force_metadata_write => {
+ db_metadata_write => {
description => "Activates the metadata writing to the file system",
default => 1,
},
@@ -42,23 +50,27 @@
{
my $context = App->context();
my $options = $context->{options};
- my $repname = $options->{repository} || "default";
- my $realrep = $context->repository($repname);
+ my $name = $options->{repository} || "default";
+ my $realrep = $context->repository($name);
my $class = $options->{class};
+ my $prefix = $options->{prefix};
+ my $dbenv_option = $options->{dbenv_option} || "db";
+ my $dbenv = $options->{$dbenv_option} || "default";
+ my $metadata_dir = $options->{db_metadata_dir} ||
"$prefix/etc/app/Repository/$dbenv/$name";
my ($rep);
if ($realrep->isa("App::Repository::DBI")) {
my $class = ref($realrep);
my ($dbhost, $dbname, $dbschema, $dbuser, $dbpass);
- if ($options->{"$repname.dbhost"} ||
- $options->{"$repname.dbname"} ||
- $options->{"$repname.dbschema"} ||
- $options->{"$repname.dbuser"} ||
- $options->{"$repname.dbpass"}) {
- $dbhost = $options->{"$repname.dbhost"};
- $dbname = $options->{"$repname.dbname"};
- $dbschema = $options->{"$repname.dbschema"};
- $dbuser = $options->{"$repname.dbuser"};
- $dbpass = $options->{"$repname.dbpass"};
+ if ($options->{"$name.dbhost"} ||
+ $options->{"$name.dbname"} ||
+ $options->{"$name.dbschema"} ||
+ $options->{"$name.dbuser"} ||
+ $options->{"$name.dbpass"}) {
+ $dbhost = $options->{"$name.dbhost"};
+ $dbname = $options->{"$name.dbname"};
+ $dbschema = $options->{"$name.dbschema"};
+ $dbuser = $options->{"$name.dbuser"};
+ $dbpass = $options->{"$name.dbpass"};
}
else {
$dbhost = $options->{dbhost};
@@ -67,13 +79,7 @@
$dbuser = $options->{dbuser};
$dbpass = $options->{dbpass};
}
- $options->{"_meta.dbhost"} = $dbhost if ($dbhost);
- $options->{"_meta.dbname"} = $dbname if ($dbname);
- $options->{"_meta.dbschema"} = $dbschema if ($dbschema);
- $options->{"_meta.dbuser"} = $dbuser if ($dbuser);
- $options->{"_meta.dbpass"} = $dbpass if ($dbpass);
-
- $rep = $context->repository($repname, class => $class);
+ $rep = $context->repository($name, class => $class);
}
else {
$rep = $realrep;
@@ -89,28 +95,14 @@
else {
$tables = $rep->get_table_names();
}
+ print "Writing metadata...\n";
+ print "#############################################################\n";
+ printf("# Database: $name (--$dbenv_option=$dbenv)\n");
+ printf("# Directory: $metadata_dir\n");
+ print "#############################################################\n";
foreach my $tab (@$tables) {
$table_def = $rep->get_table_def($tab);
- print "Got table_def for $tab... : phys=[$table_def->{phys_table}]\n";
-# my $tabalias = $table_def->{alias} || &sym2abbr($tab);
-# my $column_defs = $table_def->{column};
-# print
"#######################################################################\n";
-# print Dumper $table_def;
-# print <<EOF;
-# $tab => {
-# alias => "$tabalias",
-# tablealias => {
-# $tabalias => {
-# table => "$tab",
-# },
-# },
-#EOF
-# foreach my $col (keys %$column_defs) {
-# printf(" %-30s => { dbexpr => \"$tabalias.$col\",
},\n", $col);
-# }
-# print <<EOF;
-# },
-#EOF
+ printf("Table: %-28s : phys=[%s]\n", $tab, $table_def->{phys_table});
}
}
Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm Sat Jan 7 19:27:33 2012
@@ -4228,40 +4228,10 @@
&App::sub_entry if ($App::trace);
my ($self) = @_;
- my ($table, $tables, $rep_def, $table_defs, $table_def, $native_table,
$idx, $label, @label);
+ my ($table, $tables, $table_defs, $table_def, $native_table, $idx, $label,
@label);
- my $context = $self->{context};
- my $options = $context->{options};
- my $prefix = $options->{prefix};
- my $rep_file = "$prefix/etc/app/Repository/$self->{name}/_META_.pl";
- #print $self->dump();
- #print STDERR "_load_rep_metadata(): checking $rep_file\n";
-
- if (! $options->{force_metadata_load} && -r $rep_file) {
- #print STDERR "_load_rep_metadata($table): checking $rep_file : found
AND {force_metadata_load}=[$options->{force_metadata_load}] is false\n";
- $rep_def = do $rep_file;
- if (!$rep_def) {
- die "Error: Syntax error in $rep_file: $@" if ($@);
- die "Error: Couldn't do $rep_file: $!" if (! defined $rep_def);
- die "Error: Couldn't run $rep_file" if (! $rep_def);
- }
- App::Reference->overlay($self, $rep_def);
- }
- else {
- #print STDERR "_load_rep_metadata($table): checking $rep_file : not
found OR {force_metadata_load}=[$options->{force_metadata_load}] is true\n";
- $self->_load_rep_metadata_from_source();
- if ($options->{force_metadata_write}) {
- if (! -d "$prefix/etc/app/Repository/$self->{name}") {
- $self->_mkdir_p("$prefix/etc/app/Repository/$self->{name}");
- }
- if (-f $rep_file) {
- $self->_write_rep_metadata("$rep_file.new");
- }
- else {
- $self->_write_rep_metadata($rep_file);
- }
- }
- }
+ # load up all possible information from the native metadata
+ $self->_load_rep_metadata_from_source();
# start with the list of tables that was configured (or the empty list)
$tables = $self->{tables};
@@ -4348,33 +4318,6 @@
&App::sub_exit() if ($App::trace);
}
-sub _write_rep_metadata {
- &App::sub_entry if ($App::trace);
- my ($self, $rep_file) = @_;
-
- open(my $fh, ">", $rep_file) || die "Can't open $rep_file for writing: $!";
-
- my $name = $self->{name};
- my $dump_name = "Repository__${name}";
- my $copy = { %$self };
- my ($key);
- foreach $key qw(context _repository name class table numrows error) {
- delete $copy->{$key};
- }
- foreach $key (keys %$copy) {
- delete $copy->{$key} if ($key =~ /^db/ || $key =~ /^$name.db/);
- }
-
- my $d = Data::Dumper->new([ $copy ], [ $dump_name ]);
- $d->Indent(1);
- $d->Purity(1);
- print $fh $d->Dump();
- print $fh "\$$dump_name;\n";
-
- close($fh);
- &App::sub_exit() if ($App::trace);
-}
-
#############################################################################
# _load_rep_metadata_from_source()
#############################################################################
@@ -4452,43 +4395,23 @@
$table_def = $self->{table}{$table} || {};
#print STDERR "_load_table_metadata($table): table_def=[$table_def] ",
($table_def ? "{".join("|", %$table_def)."}" : "undef"), "\n";
- #print STDERR $self->dump($table_def);
-
- my $context = $self->{context};
- my $options = $context->{options};
- my $prefix = $options->{prefix};
- my $table_file = "$prefix/etc/app/Repository/$self->{name}/$table.pl";
- #print STDERR "_load_table_metadata($table): checking $table_file\n";
- if (! $options->{force_metadata_load} && -r $table_file) {
- #print STDERR "_load_table_metadata($table): checking $table_file :
found\n";
- $table_def = do $table_file;
- if (!$table_def) {
- die "Error: Syntax error in $table_file: $@" if ($@);
- die "Error: Couldn't do $table_file: $!" if (! defined
$table_def);
- die "Error: Couldn't run $table_file" if (! $table_def);
- }
- if ($table_def->{overlay}) {
- delete $table_def->{overlay};
- # Caution. Overlays the entire conf, not just the table_def. Use
with care.
- App::Reference->overlay($self->{context}{conf}, $table_def);
- }
- else {
- # Normal. Replaces the table_def.
- $self->{table}{$table} = $table_def;
- }
- }
- else {
- # load up all additional information from the native metadata
- $self->_load_table_metadata_from_source($table);
- if ($options->{force_metadata_write}) {
- if (! -d "$prefix/etc/app/Repository/$self->{name}") {
- $self->_mkdir_p("$prefix/etc/app/Repository/$self->{name}");
- }
- if (-f $table_file) {
- $self->_write_table_metadata("$table_file.new", $table);
+ if (!$table_def->{column}) { # no columns are defined
+ my $context = $self->{context};
+ my $options = $context->{options};
+ my $prefix = $options->{prefix};
+ my $table_file = "$prefix/etc/app/Repository/$self->{name}/$table.pl";
+ #print STDERR "_load_table_metadata($table): checking $table_file\n";
+ if (-r $table_file) {
+ #print STDERR "_load_table_metadata($table): checking $table_file
: found\n";
+ $table_def = do $table_file;
+ if ($table_def->{overlay}) {
+ delete $table_def->{overlay};
+ # Caution. Overlays the entire conf, not just the table_def.
Use with care.
+ App::Reference->overlay($self->{context}{conf}, $table_def);
}
else {
- $self->_write_table_metadata($table_file, $table);
+ # Normal. Replaces the table_def.
+ $self->{table}{$table} = $table_def;
}
}
}
@@ -4500,6 +4423,9 @@
return;
}
+ # load up all additional information from the native metadata
+ $self->_load_table_metadata_from_source($table);
+
if ($table_def->{overlay_from_table}) {
#print STDERR "load_table_metadata($table) :
OVERLAY=[$table_def->{overlay_from_table}]\n";
@@ -4669,49 +4595,9 @@
}
}
}
-
- # NOTE: This must be only perl code without access to the database.
Otherwise the metadata caching doesn't work.
- $self->_load_table_metadata_from_source2($table);
-
- &App::sub_exit() if ($App::trace);
-}
-
-sub _mkdir_p {
- my ($self, $dir) = @_;
- if (-d $dir) {
- # do nothing. directory already exists
- }
- elsif (-f $dir) {
- die "Can't create a directory where a file already exists [$dir]";
- }
- else {
- my $parent_dir = $dir;
- $parent_dir =~ s!/[^/]+$!!;
- if ($parent_dir ne $dir && $parent_dir ne "." && $parent_dir ne "/") {
- $self->_mkdir_p($parent_dir)
- }
- mkdir($dir);
- }
-}
-
-sub _write_table_metadata {
- &App::sub_entry if ($App::trace);
- my ($self, $table_file, $table) = @_;
- open(my $fh, ">", $table_file) || die "Can't open $table_file for writing:
$!";
-
- my $name = $self->{name};
- my $dump_name = "Repository__${name}__${table}";
- my $table_def = $self->{table}{$table} || {};
- my $copy = { %$table_def };
-
- my $d = Data::Dumper->new([ $copy ], [ $dump_name ]);
- $d->Indent(1);
- $d->Purity(1);
- print $fh $d->Dump();
- print $fh "\$$dump_name;\n";
+ $self->_load_table_metadata_from_source2($table);
- close($fh);
&App::sub_exit() if ($App::trace);
}
@@ -4741,16 +4627,49 @@
=cut
-# NOTE: This generally will access the database. It does not get called if
cached metadata exists.
sub _load_table_metadata_from_source {
my ($self, $table) = @_;
}
-# NOTE: This must be only perl code without access to the database. Otherwise
the metadata caching doesn't work.
sub _load_table_metadata_from_source2 {
my ($self, $table) = @_;
}
+sub _dump_to_file {
+ &App::sub_entry if ($App::trace);
+ my ($self, $file, $data, $dump_name) = @_;
+
+ $dump_name ||= "data";
+ open(my $fh, ">", $file) || die "Can't open $file for writing: $!";
+
+ my $d = Data::Dumper->new([ $data ], [ $dump_name ]);
+ $d->Indent(1);
+ $d->Purity(1);
+ print $fh $d->Dump();
+ print $fh "\$$dump_name;\n";
+
+ close($fh);
+ &App::sub_exit() if ($App::trace);
+}
+
+sub _mkdir_p {
+ my ($self, $dir) = @_;
+ if (-d $dir) {
+ # do nothing. directory already exists
+ }
+ elsif (-f $dir) {
+ die "Can't create a directory where a file already exists [$dir]";
+ }
+ else {
+ my $parent_dir = $dir;
+ $parent_dir =~ s!/[^/]+$!!;
+ if ($parent_dir ne $dir && $parent_dir ne "." && $parent_dir ne "/") {
+ $self->_mkdir_p($parent_dir)
+ }
+ mkdir($dir);
+ }
+}
+
#############################################################################
# METHODS
#############################################################################
Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm Sat Jan 7 19:27:33 2012
@@ -15,6 +15,7 @@
@ISA = ( "App::Repository" );
use strict;
+use Data::Dumper;
=head1 NAME
@@ -2989,34 +2990,63 @@
&App::sub_entry if ($App::trace);
my ($self) = @_;
- my ($dbdriver, $dbh);
- $dbdriver = $self->{dbdriver};
- $dbh = $self->{dbh};
-
#####################################################
# TABLE DATA
#####################################################
- my ($table, @tables, $func);
+ my ($table, @tables, $rep_phys_data, $tables);
+ my ($ntype_attribute_idx, @ntype_attribute_values,
$ntype_attribute_values);
+
+ my $context = $self->{context};
+ my $options = $context->{options};
+ my $metadata_dir = $options->{db_metadata_dir};
+ my $name = $self->{name};
+ if (!$metadata_dir) {
+ my $prefix = $options->{prefix};
+ my $dbenv_option = $options->{dbenv_option} || "db";
+ my $dbenv = $options->{$dbenv_option} || "default";
+ $metadata_dir = "$prefix/etc/app/Repository/$dbenv/$name";
+ }
+ my $rep_file = "$metadata_dir/_DB_.dbi.pl";
+
+ if (! $options->{db_metadata_load} && -r $rep_file) {
+ $rep_phys_data = do $rep_file;
+ if (!$rep_phys_data) {
+ die "Error: Syntax error in $rep_file: $@" if ($@);
+ die "Error: Couldn't do $rep_file: $!" if (! defined
$rep_phys_data);
+ die "Error: Couldn't run $rep_file" if (! $rep_phys_data);
+ }
+ ($tables, $ntype_attribute_idx, $ntype_attribute_values) =
@$rep_phys_data;
+ }
+ else {
+ my $dbh = $self->{dbh};
+ @tables = $self->_get_tables_from_source() if (!
$self->{hide_physical});
+ ($ntype_attribute_idx, @ntype_attribute_values) =
@{$dbh->type_info_all||[]};
+ $tables = \@tables;
+ $ntype_attribute_values = \@ntype_attribute_values;
+
+ $rep_phys_data = [ $tables, $ntype_attribute_idx,
$ntype_attribute_values ];
+ if ($options->{db_metadata_write}) {
+ $self->_mkdir_p($metadata_dir) if (! -d $metadata_dir);
+ $self->_dump_to_file($rep_file, $rep_phys_data,
"Repository__${name}");
+ }
+ }
+
+ #print Dumper $rep_phys_data;
# if we are not hiding the physical tables, go get them
if (! $self->{hide_physical}) {
- # get a list of the physical tables from the database
- # in MySQL 4.0.13, the table names are surrounded by backticks (!?!)
- # so for safe measure, get rid of all quotes
- # Also, get rid of prepended schema names.
- @tables = $self->_get_tables_from_source();
-
# go through the list of native tables from the database
- foreach $table (@tables) {
+ foreach $table (@$tables) {
# if it has never been defined, then define it
if (!defined $self->{table}{$table}) {
$self->{table}{$table} = {
- "name" => $table,
+ name => $table,
};
}
+ $self->{table}{$table}{phys_table} = $table;
# if it has not been added to the list and it is not explicitly
hidden, add to list
if (!defined $self->{table}{$table}{idx} && !
$self->{table}{$table}{hide}) {
@@ -3031,10 +3061,6 @@
# note: these are native database types, whereas a Repository "type" is a
standard
#########################################################
- my ($ntype_attribute_idx, @ntype_attribute_values);
- ($ntype_attribute_idx,@ntype_attribute_values) =
@{$dbh->type_info_all||[]};
-
- # go through the list of native type info from the DBI handle
# MySQL
# TYPE: varchar
num|12|column_size|255||literal_prefix|'||literal_suffix|'|unsigned_attribute|0||auto_unique_value|0
# TYPE: decimal
num|3|column_size|15||literal_prefix|||literal_suffix||unsigned_attribute|0||auto_unique_value|0
@@ -3106,7 +3132,7 @@
# TYPE: CLOB
num|-1|column_size|2147483647||literal_prefix|'||literal_suffix|'|unsigned_attribute|||auto_unique_value|
my (@ntype_names);
- foreach my $ntype_attribute_values (@ntype_attribute_values) {
+ foreach my $ntype_attribute_values_row (@$ntype_attribute_values) {
my $ntype_def = {};
for (qw(TYPE_NAME DATA_TYPE COLUMN_SIZE LITERAL_PREFIX LITERAL_SUFFIX
@@ -3114,7 +3140,7 @@
{
my $key = lc($_);
$key =~ s/^type_name/name/; $key =~ s/^data_type/num/;
- $ntype_def->{$key} =
$ntype_attribute_values->[$ntype_attribute_idx->{$_}];
+ $ntype_def->{$key} =
$ntype_attribute_values_row->[$ntype_attribute_idx->{$_}];
}
my $ntype_name = lc($ntype_def->{name});
@@ -3141,7 +3167,6 @@
}
sub _repository_type {
- &App::sub_entry if ($App::trace);
my ($self, $ntype_name) = @_;
my $rep_type = "string";
$_ = lc($ntype_name);
@@ -3153,7 +3178,6 @@
elsif (/time/ ) { $rep_type =
"time"; }
elsif (/date/ ) { $rep_type =
"date"; }
elsif (/blob/ || /binary/ || /raw/ || /bfile/ ) { $rep_type =
"binary"; }
- &App::sub_exit() if ($App::trace);
return($rep_type);
}
@@ -3162,16 +3186,70 @@
my ($self, $table) = @_;
return if (! $table);
- my ($dbdriver, $dbh, $sth, $native_table, $table_def);
- my (@tables, $column, $func, $tablealias);
+ my ($dbh, $sth, $native_table, $table_def);
+ my (@tables, $column, $tablealias);
- $dbdriver = $self->{dbdriver};
$dbh = $self->{dbh};
$table_def = $self->{table}{$table};
return if (!defined $table_def);
- my $context = $self->{context};
- my $context_options = $context->{options};
+ # column info indexes
+ my $TABLE_CAT = 0; my $TABLE_SCHEM = 1;
+ my $TABLE_NAME = 2; my $COLUMN_NAME = 3;
+ my $DATA_TYPE = 4; my $TYPE_NAME = 5;
+ my $COLUMN_SIZE = 6; my $BUFFER_LENGTH = 7;
+ my $DECIMAL_DIGITS = 8; my $NUM_PREC_RADIX = 9;
+ my $NULLABLE = 10; my $REMARKS = 11;
+ my $COLUMN_DEF = 12; my $SQL_DATA_TYPE = 13;
+ my $SQL_DATETIME_SUB = 14; my $CHAR_OCTET_LENGTH = 15;
+ my $ORDINAL_POSITION = 16; my $IS_NULLABLE = 17;
+
+ my ($table_phys_data);
+ my ($columns_metadata, $primary_key, $alternate_key);
+
+ my $context = $self->{context};
+ my $options = $context->{options};
+ my $metadata_dir = $options->{db_metadata_dir};
+ my $name = $self->{name};
+ if (!$metadata_dir) {
+ my $prefix = $options->{prefix};
+ my $dbenv_option = $options->{dbenv_option} || "db";
+ my $dbenv = $options->{$dbenv_option} || "default";
+ $metadata_dir = "$prefix/etc/app/Repository/$dbenv/$name";
+ }
+ my $table_file = "$metadata_dir/$table.dbi.pl";
+
+ if (! $options->{db_metadata_load} && -r $table_file) {
+ $table_phys_data = do $table_file;
+ if (!$table_phys_data) {
+ die "Error: Syntax error in $table_file: $@" if ($@);
+ die "Error: Couldn't do $table_file: $!" if (! defined
$table_phys_data);
+ die "Error: Couldn't run $table_file" if (!
$table_phys_data);
+ }
+ ($columns_metadata, $primary_key, $alternate_key) = @$table_phys_data;
+ }
+ else {
+ eval {
+ my $dbh = $self->{dbh};
+ #$sth =
$dbh->column_info($self->_column_metadata_specifiers($table));
+ $sth =
$dbh->column_info($self->_column_metadata_specifiers($table));
+ $columns_metadata = $sth->fetchall_arrayref();
+ if ($#$columns_metadata) {
+ $table_def->{phys_table} = $table;
+ $columns_metadata = [ sort { $a->[$ORDINAL_POSITION] <=>
$b->[$ORDINAL_POSITION] } @$columns_metadata ];
+ $primary_key =
$self->_get_primary_key_from_source($table);
+ $alternate_key =
$self->_get_alternate_keys_from_source($table);
+ }
+ };
+
+ $table_phys_data = [ $columns_metadata, $primary_key, $alternate_key ];
+ if ($options->{db_metadata_write}) {
+ $self->_mkdir_p($metadata_dir) if (! -d $metadata_dir);
+ $self->_dump_to_file($table_file, $table_phys_data,
"Repository__${name}__${table}");
+ }
+ }
+
+ #print Dumper $table_phys_data;
$native_table = $table; # assume the table name is a physical one
$native_table = $table_def->{native_table} if ($table_def->{native_table});
@@ -3199,23 +3277,6 @@
my ($colnum, $data_type_names, $data_types, $columns, $column_def,
$phys_columns);
my ($native_type_name, $native_type_num, $native_type_def, $phys_table);
- my $TABLE_CAT = 0; my $TABLE_SCHEM = 1;
- my $TABLE_NAME = 2; my $COLUMN_NAME = 3;
- my $DATA_TYPE = 4; my $TYPE_NAME = 5;
- my $COLUMN_SIZE = 6; my $BUFFER_LENGTH = 7;
- my $DECIMAL_DIGITS = 8; my $NUM_PREC_RADIX = 9;
- my $NULLABLE = 10; my $REMARKS = 11;
- my $COLUMN_DEF = 12; my $SQL_DATA_TYPE = 13;
- my $SQL_DATETIME_SUB = 14; my $CHAR_OCTET_LENGTH = 15;
- my $ORDINAL_POSITION = 16; my $IS_NULLABLE = 17;
-
- my ($columns_metadata);
- eval {
- $sth = $dbh->column_info($self->_column_metadata_specifiers($table));
- $table_def->{phys_table} = $table;
- $columns_metadata = $sth->fetchall_arrayref();
- $columns_metadata = [ sort { $a->[$ORDINAL_POSITION] <=>
$b->[$ORDINAL_POSITION] } @$columns_metadata ];
- };
if (!$@ && $columns_metadata && $#$columns_metadata > -1) {
$phys_columns = [];
@@ -3287,8 +3348,8 @@
######################################################################
if ($table_def->{phys_table}) {
- $table_def->{primary_key} =
$self->_get_primary_key_from_source($table) if (!$table_def->{primary_key});
- $table_def->{alternate_key} =
$self->_get_alternate_keys_from_source($table) if
(!$table_def->{alternate_key});
+ $table_def->{primary_key} = $primary_key if ($primary_key &&
!$table_def->{primary_key});
+ $table_def->{alternate_key} = $alternate_key if ($alternate_key &&
!$table_def->{alternate_key});
}
$table_def->{primary_key_auto_increment} =
$self->_is_primary_key_auto_increment($table_def);
}
@@ -3349,7 +3410,7 @@
}
if ($tablealias_def->{table} && $tablealias_def->{table} =~
/[\{\}]/) {
- $tablealias_def->{table} =
$self->substitute($tablealias_def->{table}, $context_options);
+ $tablealias_def->{table} =
$self->substitute($tablealias_def->{table}, $options);
}
}
}
Modified: p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/MySQL.pm Sat Jan 7
19:27:33 2012
@@ -797,6 +797,11 @@
return($e =~ /duplicate entry/i);
}
+# get a list of the physical tables from the database
+# in MySQL 4.0.13, the table names are surrounded by backticks (!?!)
+# so for safe measure, get rid of all quotes
+# Also, get rid of prepended schema names.
+
sub _get_tables_from_source {
&App::sub_entry if ($App::trace);
my ($self) = @_;