... | ... |
@@ -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 user_tables/], |
|
23 |
+has [qw/connector dsn password quote user exclude_table user_table_info/], |
|
24 | 24 |
cache => 0, |
25 | 25 |
cache_method => sub { |
26 | 26 |
sub { |
... | ... |
@@ -312,7 +312,9 @@ sub each_column { |
312 | 312 |
my $table = $tables[$i]; |
313 | 313 |
|
314 | 314 |
# Iterate all columns |
315 |
- my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
315 |
+ my $sth_columns; |
|
316 |
+ eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')}; |
|
317 |
+ next if $@; |
|
316 | 318 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
317 | 319 |
my $column = $column_info->{COLUMN_NAME}; |
318 | 320 |
$self->$cb($table, $column, $column_info); |
... | ... |
@@ -323,7 +325,7 @@ sub each_column { |
323 | 325 |
sub each_table { |
324 | 326 |
my ($self, $cb, %option) = @_; |
325 | 327 |
|
326 |
- my $user_table_infos = $self->user_tables; |
|
328 |
+ my $user_table_infos = $self->user_table_info; |
|
327 | 329 |
|
328 | 330 |
# Iterate tables |
329 | 331 |
if ($user_table_infos) { |
... | ... |
@@ -532,7 +534,7 @@ sub get_table_info { |
532 | 534 |
exclude => $exclude |
533 | 535 |
); |
534 | 536 |
|
535 |
- return $table_info; |
|
537 |
+ return [sort {$a->{table} cmp $b->{table} } @$table_info]; |
|
536 | 538 |
} |
537 | 539 |
|
538 | 540 |
sub insert { |
... | ... |
@@ -2038,11 +2038,13 @@ is($row->{$key3}, 3); |
2038 | 2038 |
|
2039 | 2039 |
test 'mycolumn and column'; |
2040 | 2040 |
$dbi = MyDBI7->connect; |
2041 |
+$dbi->user_table_info($user_table_info); |
|
2041 | 2042 |
eval { $dbi->execute("drop table $table1") }; |
2042 | 2043 |
eval { $dbi->execute("drop table $table2") }; |
2043 | 2044 |
$dbi->execute($create_table1); |
2044 | 2045 |
$dbi->execute($create_table2); |
2045 | 2046 |
$dbi->separator('__'); |
2047 |
+$DB::single = 1; |
|
2046 | 2048 |
$dbi->setup_model; |
2047 | 2049 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
2048 | 2050 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3}); |
... | ... |
@@ -2084,6 +2086,7 @@ like($@, qr/not safety/); |
2084 | 2086 |
|
2085 | 2087 |
test 'mycolumn'; |
2086 | 2088 |
$dbi = MyDBI8->connect; |
2089 |
+$dbi->user_table_info($user_table_info); |
|
2087 | 2090 |
eval { $dbi->execute("drop table $table1") }; |
2088 | 2091 |
eval { $dbi->execute("drop table $table2") }; |
2089 | 2092 |
$dbi->execute($create_table1); |
... | ... |
@@ -2476,6 +2479,7 @@ is($row->{$key3}, 3); |
2476 | 2479 |
|
2477 | 2480 |
test 'column separator is default .'; |
2478 | 2481 |
$dbi = MyDBI7->connect; |
2482 |
+$dbi->user_table_info($user_table_info); |
|
2479 | 2483 |
eval { $dbi->execute("drop table $table1") }; |
2480 | 2484 |
eval { $dbi->execute("drop table $table2") }; |
2481 | 2485 |
$dbi->execute($create_table1); |
... | ... |
@@ -2500,6 +2504,7 @@ is_deeply($result->one, |
2500 | 2504 |
|
2501 | 2505 |
test 'separator'; |
2502 | 2506 |
$dbi = DBIx::Custom->connect; |
2507 |
+$dbi->user_table_info($user_table_info); |
|
2503 | 2508 |
eval { $dbi->execute("drop table $table1") }; |
2504 | 2509 |
eval { $dbi->execute("drop table $table2") }; |
2505 | 2510 |
$dbi->execute($create_table1); |
... | ... |
@@ -2559,6 +2564,7 @@ is_deeply($model2->select->one, {$key1 => 1, $key3 => 3}); |
2559 | 2564 |
|
2560 | 2565 |
test 'filter_off'; |
2561 | 2566 |
$dbi = DBIx::Custom->connect; |
2567 |
+$dbi->user_table_info($user_table_info); |
|
2562 | 2568 |
eval { $dbi->execute("drop table $table1") }; |
2563 | 2569 |
eval { $dbi->execute("drop table $table2") }; |
2564 | 2570 |
$dbi->execute($create_table1); |
... | ... |
@@ -2976,6 +2982,7 @@ like($@, qr/array/); |
2976 | 2982 |
|
2977 | 2983 |
test 'select() sqlfilter option'; |
2978 | 2984 |
$dbi = DBIx::Custom->connect; |
2985 |
+$dbi->user_table_info($user_table_info); |
|
2979 | 2986 |
eval { $dbi->execute("drop table $table1") }; |
2980 | 2987 |
$dbi->execute($create_table1); |
2981 | 2988 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2}); |
... | ... |
@@ -3002,6 +3009,7 @@ ok(!$@); |
3002 | 3009 |
|
3003 | 3010 |
test 'column table option'; |
3004 | 3011 |
$dbi = MyDBI9->connect; |
3012 |
+$dbi->user_table_info($user_table_info); |
|
3005 | 3013 |
eval { $dbi->execute("drop table $table1") }; |
3006 | 3014 |
$dbi->execute($create_table1); |
3007 | 3015 |
eval { $dbi->execute("drop table $table2") }; |
... | ... |
@@ -3041,6 +3049,7 @@ is_deeply($result->one, |
3041 | 3049 |
|
3042 | 3050 |
test 'create_model'; |
3043 | 3051 |
$dbi = DBIx::Custom->connect; |
3052 |
+$dbi->user_table_info($user_table_info); |
|
3044 | 3053 |
eval { $dbi->execute("drop table $table1") }; |
3045 | 3054 |
eval { $dbi->execute("drop table $table2") }; |
3046 | 3055 |
$dbi->execute($create_table1); |
... | ... |
@@ -3222,6 +3231,7 @@ is_deeply($model->columns, [$key1, $key2]); |
3222 | 3231 |
|
3223 | 3232 |
test 'setup_model'; |
3224 | 3233 |
$dbi = MyDBI1->connect; |
3234 |
+$dbi->user_table_info($user_table_info); |
|
3225 | 3235 |
eval { $dbi->execute("drop table $table1") }; |
3226 | 3236 |
eval { $dbi->execute("drop table $table2") }; |
3227 | 3237 |
|
... | ... |
@@ -3259,6 +3269,7 @@ is_deeply($infos, |
3259 | 3269 |
] |
3260 | 3270 |
|
3261 | 3271 |
); |
3272 |
+ |
|
3262 | 3273 |
test 'each_table'; |
3263 | 3274 |
$dbi = DBIx::Custom->connect; |
3264 | 3275 |
eval { $dbi->execute("drop table $table1") }; |
... | ... |
@@ -3283,10 +3294,36 @@ is_deeply($infos, |
3283 | 3294 |
] |
3284 | 3295 |
); |
3285 | 3296 |
|
3297 |
+$dbi = DBIx::Custom->connect; |
|
3298 |
+eval { $dbi->execute("drop table $table1") }; |
|
3299 |
+eval { $dbi->execute("drop table $table2") }; |
|
3300 |
+$dbi->execute($create_table2); |
|
3301 |
+$dbi->execute($create_table1_type); |
|
3302 |
+ |
|
3303 |
+$infos = []; |
|
3304 |
+$dbi->user_table_info($user_table_info); |
|
3305 |
+$dbi->each_table(sub { |
|
3306 |
+ my ($self, $table, $table_info) = @_; |
|
3307 |
+ |
|
3308 |
+ if ($table =~ /^table\d/i) { |
|
3309 |
+ my $info = [$table, $table_info->{TABLE_NAME}]; |
|
3310 |
+ push @$infos, $info; |
|
3311 |
+ } |
|
3312 |
+}); |
|
3313 |
+$infos = [sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$infos]; |
|
3314 |
+is_deeply($infos, |
|
3315 |
+ [ |
|
3316 |
+ [$table1, $table1], |
|
3317 |
+ [$table2, $table2], |
|
3318 |
+ [$table3, $table3], |
|
3319 |
+ ] |
|
3320 |
+); |
|
3321 |
+ |
|
3286 | 3322 |
test 'type_rule into'; |
3287 | 3323 |
eval { $dbi->execute("drop table $table1") }; |
3288 | 3324 |
$dbi->execute($create_table1_type); |
3289 | 3325 |
$dbi = DBIx::Custom->connect; |
3326 |
+$dbi->user_table_info($user_table_info); |
|
3290 | 3327 |
eval { $dbi->execute("drop table $table1") }; |
3291 | 3328 |
$dbi->execute($create_table1_type); |
3292 | 3329 |
|
... | ... |
@@ -3300,6 +3337,7 @@ $result = $dbi->select(table => $table1); |
3300 | 3337 |
like($result->one->{$key1}, qr/^2010-01-01/); |
3301 | 3338 |
|
3302 | 3339 |
$dbi = DBIx::Custom->connect; |
3340 |
+$dbi->user_table_info($user_table_info); |
|
3303 | 3341 |
eval { $dbi->execute("drop table $table1") }; |
3304 | 3342 |
$dbi->execute($create_table1_type); |
3305 | 3343 |
$dbi->type_rule( |
... | ... |
@@ -3318,6 +3356,7 @@ like($row->{$key1}, qr/^2010-01-03/); |
3318 | 3356 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
3319 | 3357 |
|
3320 | 3358 |
$dbi = DBIx::Custom->connect; |
3359 |
+$dbi->user_table_info($user_table_info); |
|
3321 | 3360 |
eval { $dbi->execute("drop table $table1") }; |
3322 | 3361 |
$dbi->execute($create_table1_type); |
3323 | 3362 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
... | ... |
@@ -3339,6 +3378,7 @@ like($row->{$key1}, qr/^2010-01-03/); |
3339 | 3378 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
3340 | 3379 |
|
3341 | 3380 |
$dbi = DBIx::Custom->connect; |
3381 |
+$dbi->user_table_info($user_table_info); |
|
3342 | 3382 |
eval { $dbi->execute("drop table $table1") }; |
3343 | 3383 |
$dbi->execute($create_table1_type); |
3344 | 3384 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1); |
... | ... |
@@ -3361,6 +3401,7 @@ like($row->{$key1}, qr/^2010-01-03/); |
3361 | 3401 |
like($row->{$key2}, qr/2010-01-01 01:01:03/); |
3362 | 3402 |
|
3363 | 3403 |
$dbi = DBIx::Custom->connect; |
3404 |
+$dbi->user_table_info($user_table_info); |
|
3364 | 3405 |
eval { $dbi->execute("drop table $table1") }; |
3365 | 3406 |
$dbi->execute($create_table1_type); |
3366 | 3407 |
$dbi->register_filter(convert => sub { |
... | ... |
@@ -3382,6 +3423,7 @@ like($result->fetch->[0], qr/^2010-03-03/); |
3382 | 3423 |
|
3383 | 3424 |
test 'type_rule and filter order'; |
3384 | 3425 |
$dbi = DBIx::Custom->connect; |
3426 |
+$dbi->user_table_info($user_table_info); |
|
3385 | 3427 |
eval { $dbi->execute("drop table $table1") }; |
3386 | 3428 |
$dbi->execute($create_table1_type); |
3387 | 3429 |
$dbi->type_rule( |
... | ... |
@@ -3406,6 +3448,7 @@ like($result->fetch_first->[0], qr/^2010-01-09/); |
3406 | 3448 |
|
3407 | 3449 |
|
3408 | 3450 |
$dbi = DBIx::Custom->connect; |
3451 |
+$dbi->user_table_info($user_table_info); |
|
3409 | 3452 |
eval { $dbi->execute("drop table $table1") }; |
3410 | 3453 |
$dbi->execute($create_table1_type); |
3411 | 3454 |
$dbi->type_rule( |
... | ... |
@@ -3431,6 +3474,7 @@ like($result->fetch_first->[0], qr/^2010-01-09/); |
3431 | 3474 |
|
3432 | 3475 |
test 'type_rule_off'; |
3433 | 3476 |
$dbi = DBIx::Custom->connect; |
3477 |
+$dbi->user_table_info($user_table_info); |
|
3434 | 3478 |
eval { $dbi->execute("drop table $table1") }; |
3435 | 3479 |
$dbi->execute($create_table1_type); |
3436 | 3480 |
$dbi->type_rule( |
... | ... |
@@ -3446,6 +3490,7 @@ $result = $dbi->select(table => $table1, type_rule_off => 1); |
3446 | 3490 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
3447 | 3491 |
|
3448 | 3492 |
$dbi = DBIx::Custom->connect; |
3493 |
+$dbi->user_table_info($user_table_info); |
|
3449 | 3494 |
eval { $dbi->execute("drop table $table1") }; |
3450 | 3495 |
$dbi->execute($create_table1_type); |
3451 | 3496 |
$dbi->type_rule( |
... | ... |
@@ -3461,6 +3506,7 @@ $result = $dbi->select(table => $table1, type_rule_off => 1); |
3461 | 3506 |
like($result->one->{$key1}, qr/^2010-01-04/); |
3462 | 3507 |
|
3463 | 3508 |
$dbi = DBIx::Custom->connect; |
3509 |
+$dbi->user_table_info($user_table_info); |
|
3464 | 3510 |
eval { $dbi->execute("drop table $table1") }; |
3465 | 3511 |
$dbi->execute($create_table1_type); |
3466 | 3512 |
$dbi->type_rule( |
... | ... |
@@ -3476,6 +3522,7 @@ $result = $dbi->select(table => $table1); |
3476 | 3522 |
like($result->one->{$key1}, qr/^2010-01-05/); |
3477 | 3523 |
|
3478 | 3524 |
$dbi = DBIx::Custom->connect; |
3525 |
+$dbi->user_table_info($user_table_info); |
|
3479 | 3526 |
eval { $dbi->execute("drop table $table1") }; |
3480 | 3527 |
$dbi->execute($create_table1_type); |
3481 | 3528 |
$dbi->type_rule( |
... | ... |
@@ -3491,6 +3538,7 @@ $result = $dbi->select(table => $table1); |
3491 | 3538 |
like($result->fetch->[0], qr/2010-01-05/); |
3492 | 3539 |
|
3493 | 3540 |
$dbi = DBIx::Custom->connect; |
3541 |
+$dbi->user_table_info($user_table_info); |
|
3494 | 3542 |
eval { $dbi->execute("drop table $table1") }; |
3495 | 3543 |
$dbi->execute($create_table1_type); |
3496 | 3544 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }); |
... | ... |
@@ -3511,6 +3559,7 @@ eval{$dbi->type_rule( |
3511 | 3559 |
like($@, qr/not registered/); |
3512 | 3560 |
|
3513 | 3561 |
$dbi = DBIx::Custom->connect; |
3562 |
+$dbi->user_table_info($user_table_info); |
|
3514 | 3563 |
eval { $dbi->execute("drop table $table1") }; |
3515 | 3564 |
$dbi->execute($create_table1_type); |
3516 | 3565 |
eval { |
... | ... |
@@ -3532,6 +3581,7 @@ eval { |
3532 | 3581 |
like($@, qr/lower/); |
3533 | 3582 |
|
3534 | 3583 |
$dbi = DBIx::Custom->connect; |
3584 |
+$dbi->user_table_info($user_table_info); |
|
3535 | 3585 |
eval { $dbi->execute("drop table $table1") }; |
3536 | 3586 |
$dbi->execute($create_table1_type); |
3537 | 3587 |
$dbi->type_rule( |
... | ... |
@@ -3548,6 +3598,7 @@ $result->type_rule_off; |
3548 | 3598 |
like($result->one->{$key1}, qr/^2010-01-04/); |
3549 | 3599 |
|
3550 | 3600 |
$dbi = DBIx::Custom->connect; |
3601 |
+$dbi->user_table_info($user_table_info); |
|
3551 | 3602 |
eval { $dbi->execute("drop table $table1") }; |
3552 | 3603 |
$dbi->execute($create_table1_type); |
3553 | 3604 |
$dbi->type_rule( |
... | ... |
@@ -3613,6 +3664,7 @@ like($row->{$key1}, qr/^2010-01-03/); |
3613 | 3664 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/); |
3614 | 3665 |
|
3615 | 3666 |
$dbi = DBIx::Custom->connect; |
3667 |
+$dbi->user_table_info($user_table_info); |
|
3616 | 3668 |
eval { $dbi->execute("drop table $table1") }; |
3617 | 3669 |
$dbi->execute($create_table1_type); |
3618 | 3670 |
$dbi->type_rule( |
... | ... |
@@ -3626,6 +3678,7 @@ $result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
3626 | 3678 |
like($result->one->{$key1}, qr/^2010-01-05/); |
3627 | 3679 |
|
3628 | 3680 |
$dbi = DBIx::Custom->connect; |
3681 |
+$dbi->user_table_info($user_table_info); |
|
3629 | 3682 |
eval { $dbi->execute("drop table $table1") }; |
3630 | 3683 |
$dbi->execute($create_table1_type); |
3631 | 3684 |
$dbi->type_rule( |
... | ... |
@@ -3639,6 +3692,7 @@ $result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }); |
3639 | 3692 |
like($result->fetch->[0], qr/^2010-01-05/); |
3640 | 3693 |
|
3641 | 3694 |
$dbi = DBIx::Custom->connect; |
3695 |
+$dbi->user_table_info($user_table_info); |
|
3642 | 3696 |
eval { $dbi->execute("drop table $table1") }; |
3643 | 3697 |
$dbi->execute($create_table1_type); |
3644 | 3698 |
$dbi->type_rule( |
... | ... |
@@ -3662,6 +3716,7 @@ $result = $dbi->select(table => $table1); |
3662 | 3716 |
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/); |
3663 | 3717 |
|
3664 | 3718 |
$dbi = DBIx::Custom->connect; |
3719 |
+$dbi->user_table_info($user_table_info); |
|
3665 | 3720 |
eval { $dbi->execute("drop table $table1") }; |
3666 | 3721 |
$dbi->execute($create_table1_type); |
3667 | 3722 |
$dbi->type_rule( |
... | ... |
@@ -3685,6 +3740,7 @@ $result = $dbi->select(table => $table1); |
3685 | 3740 |
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/); |
3686 | 3741 |
|
3687 | 3742 |
$dbi = DBIx::Custom->connect; |
3743 |
+$dbi->user_table_info($user_table_info); |
|
3688 | 3744 |
eval { $dbi->execute("drop table $table1") }; |
3689 | 3745 |
$dbi->execute($create_table1_type); |
3690 | 3746 |
$dbi->type_rule( |