| ... | ... |
@@ -1,5 +1,6 @@ |
| 1 | 1 |
0.1717 |
| 2 |
- - added EXPERIMENTAL find_tables |
|
| 2 |
+ - added EXPERIMEfNTAL get_table_info |
|
| 3 |
+ - added user_table_info attribute and each_table find in user_tables if set. |
|
| 3 | 4 |
0.1716 |
| 4 | 5 |
- fixed bugs when using DBD::Oracle. |
| 5 | 6 |
- added EXPERIMENTAL show_tables method. |
| ... | ... |
@@ -20,7 +20,7 @@ use Scalar::Util qw/weaken/; |
| 20 | 20 |
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
|
| 21 | 21 |
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
|
| 22 | 22 |
|
| 23 |
-has [qw/connector dsn password quote user exclude_table/], |
|
| 23 |
+has [qw/connector dsn password quote user exclude_table user_tables/], |
|
| 24 | 24 |
cache => 0, |
| 25 | 25 |
cache_method => sub {
|
| 26 | 26 |
sub {
|
| ... | ... |
@@ -323,16 +323,22 @@ sub each_column {
|
| 323 | 323 |
sub each_table {
|
| 324 | 324 |
my ($self, $cb, %option) = @_; |
| 325 | 325 |
|
| 326 |
- my $re = $self->exclude_table || $option{exclude};
|
|
| 326 |
+ my $user_table_infos = $self->user_tables; |
|
| 327 | 327 |
|
| 328 |
- # Iterate all tables |
|
| 329 |
- my $sth_tables = $self->dbh->table_info; |
|
| 330 |
- while (my $table_info = $sth_tables->fetchrow_hashref) {
|
|
| 331 |
- |
|
| 332 |
- # Table |
|
| 333 |
- my $table = $table_info->{TABLE_NAME};
|
|
| 334 |
- next if defined $re && $table =~ /$re/; |
|
| 335 |
- $self->$cb($table, $table_info); |
|
| 328 |
+ # Iterate tables |
|
| 329 |
+ if ($user_table_infos) {
|
|
| 330 |
+ $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
|
|
| 331 |
+ } |
|
| 332 |
+ else {
|
|
| 333 |
+ my $re = $self->exclude_table || $option{exclude};
|
|
| 334 |
+ my $sth_tables = $self->dbh->table_info; |
|
| 335 |
+ while (my $table_info = $sth_tables->fetchrow_hashref) {
|
|
| 336 |
+ |
|
| 337 |
+ # Table |
|
| 338 |
+ my $table = $table_info->{TABLE_NAME};
|
|
| 339 |
+ next if defined $re && $table =~ /$re/; |
|
| 340 |
+ $self->$cb($table, $table_info); |
|
| 341 |
+ } |
|
| 336 | 342 |
} |
| 337 | 343 |
} |
| 338 | 344 |
|
| ... | ... |
@@ -514,16 +520,19 @@ sub execute {
|
| 514 | 520 |
else { return $affected }
|
| 515 | 521 |
} |
| 516 | 522 |
|
| 517 |
-sub find_tables {
|
|
| 523 |
+sub get_table_info {
|
|
| 518 | 524 |
my ($self, %args) = @_; |
| 519 | 525 |
|
| 520 | 526 |
my $exclude = delete $args{exclude};
|
| 521 | 527 |
croak qq/"$_" is wrong option/ for keys %args; |
| 522 | 528 |
|
| 523 |
- my %tables; |
|
| 524 |
- $self->each_table(sub { push $table{$_[1]}++ }, exclude => $exclude);
|
|
| 529 |
+ my $table_info = []; |
|
| 530 |
+ $self->each_table( |
|
| 531 |
+ sub { push @$table_info, {table => $_[1], info => $_[2] } },
|
|
| 532 |
+ exclude => $exclude |
|
| 533 |
+ ); |
|
| 525 | 534 |
|
| 526 |
- return [sort keys %tables]; |
|
| 535 |
+ return $table_info; |
|
| 527 | 536 |
} |
| 528 | 537 |
|
| 529 | 538 |
sub insert {
|
| ... | ... |
@@ -2108,6 +2117,26 @@ If you want to disable tag parsing functionality, set to 0. |
| 2108 | 2117 |
|
| 2109 | 2118 |
User name, used when C<connect> method is executed. |
| 2110 | 2119 |
|
| 2120 |
+=head2 C<user_table_info EXPERIMENTAL> |
|
| 2121 |
+ |
|
| 2122 |
+ my $user_table_info = $dbi->user_table_info; |
|
| 2123 |
+ $dbi = $dbi->user_table_info($user_table_info); |
|
| 2124 |
+ |
|
| 2125 |
+You can set the following data. |
|
| 2126 |
+ |
|
| 2127 |
+ [ |
|
| 2128 |
+ {table => 'book', info => {...}},
|
|
| 2129 |
+ {table => 'author', info => {...}}
|
|
| 2130 |
+ ] |
|
| 2131 |
+ |
|
| 2132 |
+Usually, you can set return value of C<get_table_info>. |
|
| 2133 |
+ |
|
| 2134 |
+ my $user_table_info = $dbi->get_table_info(exclude => qr/^system/); |
|
| 2135 |
+ $dbi->user_table_info($user_table_info); |
|
| 2136 |
+ |
|
| 2137 |
+If C<user_table_info> is set, C<each_table> use C<user_table_info> |
|
| 2138 |
+to find table info. |
|
| 2139 |
+ |
|
| 2111 | 2140 |
=head1 METHODS |
| 2112 | 2141 |
|
| 2113 | 2142 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
| ... | ... |
@@ -2510,11 +2539,18 @@ Turn C<into2> type rule off. |
| 2510 | 2539 |
|
| 2511 | 2540 |
=back |
| 2512 | 2541 |
|
| 2513 |
-=head2 C<find_tables EXPERIMENTAL> |
|
| 2542 |
+=head2 C<get_table_info EXPERIMENTAL> |
|
| 2543 |
+ |
|
| 2544 |
+ my $tables = $self->get_table_info(exclude => qr/^system_/); |
|
| 2514 | 2545 |
|
| 2515 |
- my $tables = $self->find_tables(exclude => qr/^system_/); |
|
| 2546 |
+get table infomation except for one which match C<exclude> pattern. |
|
| 2547 |
+ |
|
| 2548 |
+ [ |
|
| 2549 |
+ {table => 'book', info => {...}},
|
|
| 2550 |
+ {table => 'author', info => {...}}
|
|
| 2551 |
+ ] |
|
| 2516 | 2552 |
|
| 2517 |
-Find tables except for one which match C<exclude> pattern. |
|
| 2553 |
+You can set this value to C<user_table_info>. |
|
| 2518 | 2554 |
|
| 2519 | 2555 |
=head2 C<insert> |
| 2520 | 2556 |
|
| ... | ... |
@@ -76,6 +76,7 @@ my $update_param; |
| 76 | 76 |
my $insert_param; |
| 77 | 77 |
my $join; |
| 78 | 78 |
my $binary; |
| 79 |
+my $user_table_info; |
|
| 79 | 80 |
|
| 80 | 81 |
require MyDBI1; |
| 81 | 82 |
{
|
| ... | ... |
@@ -233,6 +234,16 @@ require MyDBI1; |
| 233 | 234 |
} |
| 234 | 235 |
} |
| 235 | 236 |
|
| 237 |
+# Get user table info |
|
| 238 |
+$dbi = DBIx::Custom->connect; |
|
| 239 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 240 |
+eval { $dbi->execute("drop table $table2") };
|
|
| 241 |
+eval { $dbi->execute("drop table $table3") };
|
|
| 242 |
+$dbi->execute($create_table1); |
|
| 243 |
+$dbi->execute($create_table2); |
|
| 244 |
+$dbi->execute($create_table3); |
|
| 245 |
+$user_table_info = $dbi->get_table_info(exclude => $dbi->exclude_table); |
|
| 246 |
+ |
|
| 236 | 247 |
# Create table |
| 237 | 248 |
$dbi = DBIx::Custom->connect; |
| 238 | 249 |
eval { $dbi->execute("drop table $table1") };
|