... | ... |
@@ -1,6 +1,10 @@ |
1 | 1 |
0.1717 |
2 |
- - added EXPERIMEfNTAL get_table_info |
|
3 |
- - added user_table_info attribute and each_table find in user_tables if set. |
|
2 |
+ - added EXPERIMENTAL get_table_info |
|
3 |
+ - added EXPERIMETNAL user_table_info attribute |
|
4 |
+ and each_table find table info in user_table_info if set. |
|
5 |
+ - added EXPERIMENTAL get_column_info |
|
6 |
+ - added EXPERIMENTAL user_column_info attribute |
|
7 |
+ and each_column find column info in user_column_info if set. |
|
4 | 8 |
0.1716 |
5 | 9 |
- fixed bugs when using DBD::Oracle. |
6 | 10 |
- added EXPERIMENTAL show_tables method. |
... | ... |
@@ -20,7 +20,8 @@ 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 user_table_info/], |
|
23 |
+has [qw/connector dsn password quote user exclude_table user_table_info |
|
24 |
+ user_column_info/], |
|
24 | 25 |
cache => 0, |
25 | 26 |
cache_method => sub { |
26 | 27 |
sub { |
... | ... |
@@ -298,26 +299,33 @@ sub create_model { |
298 | 299 |
} |
299 | 300 |
|
300 | 301 |
sub each_column { |
301 |
- my ($self, $cb) = @_; |
|
302 |
+ my ($self, $cb, %options) = @_; |
|
302 | 303 |
|
303 |
- my $re = $self->exclude_table; |
|
304 |
+ my $user_column_info = $self->user_column_info; |
|
304 | 305 |
|
305 |
- # Tables |
|
306 |
- my %tables; |
|
307 |
- $self->each_table(sub { $tables{$_[1]}++ }); |
|
306 |
+ if ($user_column_info) { |
|
307 |
+ $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info; |
|
308 |
+ } |
|
309 |
+ else { |
|
310 |
+ |
|
311 |
+ my $re = $self->exclude_table || $options{exclude_table}; |
|
312 |
+ # Tables |
|
313 |
+ my %tables; |
|
314 |
+ $self->each_table(sub { $tables{$_[1]}++ }); |
|
308 | 315 |
|
309 |
- # Iterate all tables |
|
310 |
- my @tables = sort keys %tables; |
|
311 |
- for (my $i = 0; $i < @tables; $i++) { |
|
312 |
- my $table = $tables[$i]; |
|
313 |
- |
|
314 |
- # Iterate all columns |
|
315 |
- my $sth_columns; |
|
316 |
- eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')}; |
|
317 |
- next if $@; |
|
318 |
- while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
319 |
- my $column = $column_info->{COLUMN_NAME}; |
|
320 |
- $self->$cb($table, $column, $column_info); |
|
316 |
+ # Iterate all tables |
|
317 |
+ my @tables = sort keys %tables; |
|
318 |
+ for (my $i = 0; $i < @tables; $i++) { |
|
319 |
+ my $table = $tables[$i]; |
|
320 |
+ |
|
321 |
+ # Iterate all columns |
|
322 |
+ my $sth_columns; |
|
323 |
+ eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')}; |
|
324 |
+ next if $@; |
|
325 |
+ while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
326 |
+ my $column = $column_info->{COLUMN_NAME}; |
|
327 |
+ $self->$cb($table, $column, $column_info); |
|
328 |
+ } |
|
321 | 329 |
} |
322 | 330 |
} |
323 | 331 |
} |
... | ... |
@@ -537,6 +545,23 @@ sub get_table_info { |
537 | 545 |
return [sort {$a->{table} cmp $b->{table} } @$table_info]; |
538 | 546 |
} |
539 | 547 |
|
548 |
+sub get_column_info { |
|
549 |
+ my ($self, %args) = @_; |
|
550 |
+ |
|
551 |
+ my $exclude_table = delete $args{exclude_table}; |
|
552 |
+ croak qq/"$_" is wrong option/ for keys %args; |
|
553 |
+ |
|
554 |
+ my $column_info = []; |
|
555 |
+ $self->each_column( |
|
556 |
+ sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } }, |
|
557 |
+ exclude_table => $exclude_table |
|
558 |
+ ); |
|
559 |
+ |
|
560 |
+ return [ |
|
561 |
+ sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} } |
|
562 |
+ @$$column_info]; |
|
563 |
+} |
|
564 |
+ |
|
540 | 565 |
sub insert { |
541 | 566 |
my $self = shift; |
542 | 567 |
|
... | ... |
@@ -2119,6 +2144,27 @@ If you want to disable tag parsing functionality, set to 0. |
2119 | 2144 |
|
2120 | 2145 |
User name, used when C<connect> method is executed. |
2121 | 2146 |
|
2147 |
+=head2 C<user_column_info EXPERIMENTAL> |
|
2148 |
+ |
|
2149 |
+ my $user_column_info = $dbi->user_column_info; |
|
2150 |
+ $dbi = $dbi->user_column_info($user_column_info); |
|
2151 |
+ |
|
2152 |
+You can set the following data. |
|
2153 |
+ |
|
2154 |
+ [ |
|
2155 |
+ {table => 'book', column => 'title', info => {...}}, |
|
2156 |
+ {table => 'author', column => 'name', info => {...}} |
|
2157 |
+ ] |
|
2158 |
+ |
|
2159 |
+Usually, you can set return value of C<get_column_info>. |
|
2160 |
+ |
|
2161 |
+ my $user_column_info |
|
2162 |
+ = $dbi->get_column_info(exclude_table => qr/^system/); |
|
2163 |
+ $dbi->user_column_info($user_column_info); |
|
2164 |
+ |
|
2165 |
+If C<user_column_info> is set, C<each_column> use C<user_column_info> |
|
2166 |
+to find column info. |
|
2167 |
+ |
|
2122 | 2168 |
=head2 C<user_table_info EXPERIMENTAL> |
2123 | 2169 |
|
2124 | 2170 |
my $user_table_info = $dbi->user_table_info; |
... | ... |
@@ -2541,6 +2587,17 @@ Turn C<into2> type rule off. |
2541 | 2587 |
|
2542 | 2588 |
=back |
2543 | 2589 |
|
2590 |
+=head2 C<get_column_info EXPERIMENTAL> |
|
2591 |
+ |
|
2592 |
+ my $tables = $self->get_column_info(exclude_table => qr/^system_/); |
|
2593 |
+ |
|
2594 |
+get column infomation except for one which match C<exclude_table> pattern. |
|
2595 |
+ |
|
2596 |
+ [ |
|
2597 |
+ {table => 'book', column => 'title', info => {...}}, |
|
2598 |
+ {table => 'author', column => 'name' info => {...}} |
|
2599 |
+ ] |
|
2600 |
+ |
|
2544 | 2601 |
=head2 C<get_table_info EXPERIMENTAL> |
2545 | 2602 |
|
2546 | 2603 |
my $tables = $self->get_table_info(exclude => qr/^system_/); |