| ... | ... |
@@ -5,6 +5,8 @@ |
| 5 | 5 |
- added EXPERIMENTAL get_column_info |
| 6 | 6 |
- added EXPERIMENTAL user_column_info attribute |
| 7 | 7 |
and each_column find column info in user_column_info if set. |
| 8 |
+ - connector is automatically set to DBDx::Connector object |
|
| 9 |
+ if connector is set to 1 when connect method is called. |
|
| 8 | 10 |
0.1716 |
| 9 | 11 |
- fixed bugs when using DBD::Oracle. |
| 10 | 12 |
- added EXPERIMENTAL show_tables method. |
| ... | ... |
@@ -164,7 +164,21 @@ sub column {
|
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
sub connect {
|
| 167 |
- my $self = ref $_[0] ? shift : shift->new(@_);; |
|
| 167 |
+ my $self = ref $_[0] ? shift : shift->new(@_); |
|
| 168 |
+ |
|
| 169 |
+ my $connector = $self->connector; |
|
| 170 |
+ |
|
| 171 |
+ if (!ref $connector && $connector) {
|
|
| 172 |
+ require DBIx::Connector; |
|
| 173 |
+ |
|
| 174 |
+ my $dsn = $self->dsn; |
|
| 175 |
+ my $user = $self->user; |
|
| 176 |
+ my $password = $self->password; |
|
| 177 |
+ my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
|
|
| 178 |
+ my $connector = DBIx::Connector->new($dsn, $user, $password, |
|
| 179 |
+ {%{$self->default_dbi_option} , %$dbi_option});
|
|
| 180 |
+ $self->connector($connector); |
|
| 181 |
+ } |
|
| 168 | 182 |
|
| 169 | 183 |
# Connect |
| 170 | 184 |
$self->dbh; |
| ... | ... |
@@ -559,7 +573,7 @@ sub get_column_info {
|
| 559 | 573 |
|
| 560 | 574 |
return [ |
| 561 | 575 |
sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
|
| 562 |
- @$$column_info]; |
|
| 576 |
+ @$column_info]; |
|
| 563 | 577 |
} |
| 564 | 578 |
|
| 565 | 579 |
sub insert {
|
| ... | ... |
@@ -1038,6 +1052,7 @@ sub type_rule {
|
| 1038 | 1052 |
# Into |
| 1039 | 1053 |
foreach my $i (1 .. 2) {
|
| 1040 | 1054 |
my $into = "into$i"; |
| 1055 |
+ my $exists_into = exists $type_rule->{$into};
|
|
| 1041 | 1056 |
$type_rule->{$into} = _array_to_hash($type_rule->{$into});
|
| 1042 | 1057 |
$self->{type_rule} = $type_rule;
|
| 1043 | 1058 |
$self->{"_$into"} = {};
|
| ... | ... |
@@ -1045,6 +1060,7 @@ sub type_rule {
|
| 1045 | 1060 |
croak qq{type name of $into section must be lower case}
|
| 1046 | 1061 |
if $type_name =~ /[A-Z]/; |
| 1047 | 1062 |
} |
| 1063 |
+ |
|
| 1048 | 1064 |
$self->each_column(sub {
|
| 1049 | 1065 |
my ($dbi, $table, $column, $column_info) = @_; |
| 1050 | 1066 |
|
| ... | ... |
@@ -1330,16 +1346,18 @@ sub _connect {
|
| 1330 | 1346 |
warn "dbi_options is DEPRECATED! use dbi_option instead\n" |
| 1331 | 1347 |
if keys %{$self->dbi_options};
|
| 1332 | 1348 |
|
| 1349 |
+ $dbi_option = {%{$self->default_dbi_option}, %$dbi_option};
|
|
| 1350 |
+ |
|
| 1333 | 1351 |
# Connect |
| 1334 |
- my $dbh = eval {DBI->connect(
|
|
| 1335 |
- $dsn, |
|
| 1336 |
- $user, |
|
| 1337 |
- $password, |
|
| 1338 |
- {
|
|
| 1339 |
- %{$self->default_dbi_option},
|
|
| 1340 |
- %$dbi_option |
|
| 1341 |
- } |
|
| 1342 |
- )}; |
|
| 1352 |
+ my $dbh; |
|
| 1353 |
+ eval {
|
|
| 1354 |
+ $dbh = DBI->connect( |
|
| 1355 |
+ $dsn, |
|
| 1356 |
+ $user, |
|
| 1357 |
+ $password, |
|
| 1358 |
+ $dbi_option |
|
| 1359 |
+ ); |
|
| 1360 |
+ }; |
|
| 1343 | 1361 |
|
| 1344 | 1362 |
# Connect error |
| 1345 | 1363 |
croak "$@ " . _subname if $@; |
| ... | ... |
@@ -2010,14 +2028,24 @@ This is L<DBIx::Connector> example. Please pass |
| 2010 | 2028 |
C<default_dbi_option> to L<DBIx::Connector> C<new> method. |
| 2011 | 2029 |
|
| 2012 | 2030 |
my $connector = DBIx::Connector->new( |
| 2013 |
- "dbi:mysql:database=$DATABASE", |
|
| 2014 |
- $USER, |
|
| 2015 |
- $PASSWORD, |
|
| 2031 |
+ "dbi:mysql:database=$database", |
|
| 2032 |
+ $user, |
|
| 2033 |
+ $password, |
|
| 2016 | 2034 |
DBIx::Custom->new->default_dbi_option |
| 2017 | 2035 |
); |
| 2018 | 2036 |
|
| 2019 | 2037 |
my $dbi = DBIx::Custom->connect(connector => $connector); |
| 2020 | 2038 |
|
| 2039 |
+If C<connector> is set to 1 when connect method is called, |
|
| 2040 |
+L<DBIx::Connector> is automatically set to C<connector> |
|
| 2041 |
+ |
|
| 2042 |
+ my $dbi = DBIx::Custom->connect( |
|
| 2043 |
+ dsn => $dsn, user => $user, password => $password, connector => 1); |
|
| 2044 |
+ |
|
| 2045 |
+ my $connector = $dbi->connector; # DBIx::Connector |
|
| 2046 |
+ |
|
| 2047 |
+Note that L<DBIx::Connector> must be installed. |
|
| 2048 |
+ |
|
| 2021 | 2049 |
=head2 C<dsn> |
| 2022 | 2050 |
|
| 2023 | 2051 |
my $dsn = $dbi->dsn; |
| ... | ... |
@@ -77,6 +77,7 @@ my $insert_param; |
| 77 | 77 |
my $join; |
| 78 | 78 |
my $binary; |
| 79 | 79 |
my $user_table_info; |
| 80 |
+my $user_column_info; |
|
| 80 | 81 |
|
| 81 | 82 |
require MyDBI1; |
| 82 | 83 |
{
|
| ... | ... |
@@ -2044,7 +2045,6 @@ eval { $dbi->execute("drop table $table2") };
|
| 2044 | 2045 |
$dbi->execute($create_table1); |
| 2045 | 2046 |
$dbi->execute($create_table2); |
| 2046 | 2047 |
$dbi->separator('__');
|
| 2047 |
-$DB::single = 1; |
|
| 2048 | 2048 |
$dbi->setup_model; |
| 2049 | 2049 |
$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
|
| 2050 | 2050 |
$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 3});
|
| ... | ... |
@@ -3322,11 +3322,14 @@ is_deeply($infos, |
| 3322 | 3322 |
test 'type_rule into'; |
| 3323 | 3323 |
eval { $dbi->execute("drop table $table1") };
|
| 3324 | 3324 |
$dbi->execute($create_table1_type); |
| 3325 |
+$user_column_info = $dbi->get_column_info(exclude_table => $dbi->exclude_table); |
|
| 3326 |
+ |
|
| 3327 |
+ |
|
| 3325 | 3328 |
$dbi = DBIx::Custom->connect; |
| 3326 |
-$dbi->user_table_info($user_table_info); |
|
| 3327 | 3329 |
eval { $dbi->execute("drop table $table1") };
|
| 3328 | 3330 |
$dbi->execute($create_table1_type); |
| 3329 | 3331 |
|
| 3332 |
+$dbi->user_column_info($user_column_info); |
|
| 3330 | 3333 |
$dbi->type_rule( |
| 3331 | 3334 |
into1 => {
|
| 3332 | 3335 |
$date_typename => sub { '2010-' . $_[0] }
|
| ... | ... |
@@ -3337,9 +3340,9 @@ $result = $dbi->select(table => $table1); |
| 3337 | 3340 |
like($result->one->{$key1}, qr/^2010-01-01/);
|
| 3338 | 3341 |
|
| 3339 | 3342 |
$dbi = DBIx::Custom->connect; |
| 3340 |
-$dbi->user_table_info($user_table_info); |
|
| 3341 | 3343 |
eval { $dbi->execute("drop table $table1") };
|
| 3342 | 3344 |
$dbi->execute($create_table1_type); |
| 3345 |
+$dbi->user_column_info($user_column_info); |
|
| 3343 | 3346 |
$dbi->type_rule( |
| 3344 | 3347 |
into1 => [ |
| 3345 | 3348 |
[$date_typename, $datetime_typename] => sub {
|
| ... | ... |
@@ -3356,10 +3359,10 @@ like($row->{$key1}, qr/^2010-01-03/);
|
| 3356 | 3359 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
|
| 3357 | 3360 |
|
| 3358 | 3361 |
$dbi = DBIx::Custom->connect; |
| 3359 |
-$dbi->user_table_info($user_table_info); |
|
| 3360 | 3362 |
eval { $dbi->execute("drop table $table1") };
|
| 3361 | 3363 |
$dbi->execute($create_table1_type); |
| 3362 | 3364 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
|
| 3365 |
+$dbi->user_column_info($user_column_info); |
|
| 3363 | 3366 |
$dbi->type_rule( |
| 3364 | 3367 |
into1 => [ |
| 3365 | 3368 |
[$date_typename, $datetime_typename] => sub {
|
| ... | ... |
@@ -3378,10 +3381,10 @@ like($row->{$key1}, qr/^2010-01-03/);
|
| 3378 | 3381 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
|
| 3379 | 3382 |
|
| 3380 | 3383 |
$dbi = DBIx::Custom->connect; |
| 3381 |
-$dbi->user_table_info($user_table_info); |
|
| 3382 | 3384 |
eval { $dbi->execute("drop table $table1") };
|
| 3383 | 3385 |
$dbi->execute($create_table1_type); |
| 3384 | 3386 |
$dbi->insert({$key1 => '2010-01-03', $key2 => '2010-01-01 01:01:03'}, table => $table1);
|
| 3387 |
+$dbi->user_column_info($user_column_info); |
|
| 3385 | 3388 |
$dbi->type_rule( |
| 3386 | 3389 |
into1 => [ |
| 3387 | 3390 |
[$date_typename, $datetime_typename] => sub {
|
| ... | ... |
@@ -3401,7 +3404,6 @@ like($row->{$key1}, qr/^2010-01-03/);
|
| 3401 | 3404 |
like($row->{$key2}, qr/2010-01-01 01:01:03/);
|
| 3402 | 3405 |
|
| 3403 | 3406 |
$dbi = DBIx::Custom->connect; |
| 3404 |
-$dbi->user_table_info($user_table_info); |
|
| 3405 | 3407 |
eval { $dbi->execute("drop table $table1") };
|
| 3406 | 3408 |
$dbi->execute($create_table1_type); |
| 3407 | 3409 |
$dbi->register_filter(convert => sub {
|
| ... | ... |
@@ -3409,6 +3411,7 @@ $dbi->register_filter(convert => sub {
|
| 3409 | 3411 |
$value =~ s/02/03/; |
| 3410 | 3412 |
return $value; |
| 3411 | 3413 |
}); |
| 3414 |
+$dbi->user_column_info($user_column_info); |
|
| 3412 | 3415 |
$dbi->type_rule( |
| 3413 | 3416 |
from1 => {
|
| 3414 | 3417 |
$date_datatype => 'convert', |
| ... | ... |
@@ -3423,9 +3426,9 @@ like($result->fetch->[0], qr/^2010-03-03/); |
| 3423 | 3426 |
|
| 3424 | 3427 |
test 'type_rule and filter order'; |
| 3425 | 3428 |
$dbi = DBIx::Custom->connect; |
| 3426 |
-$dbi->user_table_info($user_table_info); |
|
| 3427 | 3429 |
eval { $dbi->execute("drop table $table1") };
|
| 3428 | 3430 |
$dbi->execute($create_table1_type); |
| 3431 |
+$dbi->user_column_info($user_column_info); |
|
| 3429 | 3432 |
$dbi->type_rule( |
| 3430 | 3433 |
into1 => {
|
| 3431 | 3434 |
$date_typename => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
|
| ... | ... |
@@ -3448,9 +3451,9 @@ like($result->fetch_first->[0], qr/^2010-01-09/); |
| 3448 | 3451 |
|
| 3449 | 3452 |
|
| 3450 | 3453 |
$dbi = DBIx::Custom->connect; |
| 3451 |
-$dbi->user_table_info($user_table_info); |
|
| 3452 | 3454 |
eval { $dbi->execute("drop table $table1") };
|
| 3453 | 3455 |
$dbi->execute($create_table1_type); |
| 3456 |
+$dbi->user_column_info($user_column_info); |
|
| 3454 | 3457 |
$dbi->type_rule( |
| 3455 | 3458 |
from1 => {
|
| 3456 | 3459 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
|
| ... | ... |
@@ -3461,6 +3464,7 @@ $dbi->type_rule( |
| 3461 | 3464 |
); |
| 3462 | 3465 |
$dbi->insert({$key1 => '2010-01-03'}, table => $table1);
|
| 3463 | 3466 |
$result = $dbi->select(table => $table1); |
| 3467 |
+$dbi->user_column_info($user_column_info); |
|
| 3464 | 3468 |
$result->type_rule( |
| 3465 | 3469 |
from1 => {
|
| 3466 | 3470 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/6/; return $v }
|
| ... | ... |
@@ -3474,9 +3478,9 @@ like($result->fetch_first->[0], qr/^2010-01-09/); |
| 3474 | 3478 |
|
| 3475 | 3479 |
test 'type_rule_off'; |
| 3476 | 3480 |
$dbi = DBIx::Custom->connect; |
| 3477 |
-$dbi->user_table_info($user_table_info); |
|
| 3478 | 3481 |
eval { $dbi->execute("drop table $table1") };
|
| 3479 | 3482 |
$dbi->execute($create_table1_type); |
| 3483 |
+$dbi->user_column_info($user_column_info); |
|
| 3480 | 3484 |
$dbi->type_rule( |
| 3481 | 3485 |
from1 => {
|
| 3482 | 3486 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
|
| ... | ... |
@@ -3490,9 +3494,9 @@ $result = $dbi->select(table => $table1, type_rule_off => 1); |
| 3490 | 3494 |
like($result->type_rule_off->fetch->[0], qr/^2010-01-03/); |
| 3491 | 3495 |
|
| 3492 | 3496 |
$dbi = DBIx::Custom->connect; |
| 3493 |
-$dbi->user_table_info($user_table_info); |
|
| 3494 | 3497 |
eval { $dbi->execute("drop table $table1") };
|
| 3495 | 3498 |
$dbi->execute($create_table1_type); |
| 3499 |
+$dbi->user_column_info($user_column_info); |
|
| 3496 | 3500 |
$dbi->type_rule( |
| 3497 | 3501 |
from1 => {
|
| 3498 | 3502 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
|
| ... | ... |
@@ -3506,9 +3510,9 @@ $result = $dbi->select(table => $table1, type_rule_off => 1); |
| 3506 | 3510 |
like($result->one->{$key1}, qr/^2010-01-04/);
|
| 3507 | 3511 |
|
| 3508 | 3512 |
$dbi = DBIx::Custom->connect; |
| 3509 |
-$dbi->user_table_info($user_table_info); |
|
| 3510 | 3513 |
eval { $dbi->execute("drop table $table1") };
|
| 3511 | 3514 |
$dbi->execute($create_table1_type); |
| 3515 |
+$dbi->user_column_info($user_column_info); |
|
| 3512 | 3516 |
$dbi->type_rule( |
| 3513 | 3517 |
from1 => {
|
| 3514 | 3518 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
|
| ... | ... |
@@ -3522,9 +3526,9 @@ $result = $dbi->select(table => $table1); |
| 3522 | 3526 |
like($result->one->{$key1}, qr/^2010-01-05/);
|
| 3523 | 3527 |
|
| 3524 | 3528 |
$dbi = DBIx::Custom->connect; |
| 3525 |
-$dbi->user_table_info($user_table_info); |
|
| 3526 | 3529 |
eval { $dbi->execute("drop table $table1") };
|
| 3527 | 3530 |
$dbi->execute($create_table1_type); |
| 3531 |
+$dbi->user_column_info($user_column_info); |
|
| 3528 | 3532 |
$dbi->type_rule( |
| 3529 | 3533 |
from1 => {
|
| 3530 | 3534 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
|
| ... | ... |
@@ -3538,10 +3542,10 @@ $result = $dbi->select(table => $table1); |
| 3538 | 3542 |
like($result->fetch->[0], qr/2010-01-05/); |
| 3539 | 3543 |
|
| 3540 | 3544 |
$dbi = DBIx::Custom->connect; |
| 3541 |
-$dbi->user_table_info($user_table_info); |
|
| 3542 | 3545 |
eval { $dbi->execute("drop table $table1") };
|
| 3543 | 3546 |
$dbi->execute($create_table1_type); |
| 3544 | 3547 |
$dbi->register_filter(ppp => sub { my $v = shift || ''; $v =~ s/3/4/; return $v });
|
| 3548 |
+$dbi->user_column_info($user_column_info); |
|
| 3545 | 3549 |
$dbi->type_rule( |
| 3546 | 3550 |
into1 => {
|
| 3547 | 3551 |
$date_typename => 'ppp' |
| ... | ... |
@@ -3559,7 +3563,6 @@ eval{$dbi->type_rule(
|
| 3559 | 3563 |
like($@, qr/not registered/); |
| 3560 | 3564 |
|
| 3561 | 3565 |
$dbi = DBIx::Custom->connect; |
| 3562 |
-$dbi->user_table_info($user_table_info); |
|
| 3563 | 3566 |
eval { $dbi->execute("drop table $table1") };
|
| 3564 | 3567 |
$dbi->execute($create_table1_type); |
| 3565 | 3568 |
eval {
|
| ... | ... |
@@ -3581,9 +3584,9 @@ eval {
|
| 3581 | 3584 |
like($@, qr/lower/); |
| 3582 | 3585 |
|
| 3583 | 3586 |
$dbi = DBIx::Custom->connect; |
| 3584 |
-$dbi->user_table_info($user_table_info); |
|
| 3585 | 3587 |
eval { $dbi->execute("drop table $table1") };
|
| 3586 | 3588 |
$dbi->execute($create_table1_type); |
| 3589 |
+$dbi->user_column_info($user_column_info); |
|
| 3587 | 3590 |
$dbi->type_rule( |
| 3588 | 3591 |
from1 => {
|
| 3589 | 3592 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/4/5/; return $v }
|
| ... | ... |
@@ -3598,9 +3601,9 @@ $result->type_rule_off; |
| 3598 | 3601 |
like($result->one->{$key1}, qr/^2010-01-04/);
|
| 3599 | 3602 |
|
| 3600 | 3603 |
$dbi = DBIx::Custom->connect; |
| 3601 |
-$dbi->user_table_info($user_table_info); |
|
| 3602 | 3604 |
eval { $dbi->execute("drop table $table1") };
|
| 3603 | 3605 |
$dbi->execute($create_table1_type); |
| 3606 |
+$dbi->user_column_info($user_column_info); |
|
| 3604 | 3607 |
$dbi->type_rule( |
| 3605 | 3608 |
from1 => {
|
| 3606 | 3609 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
|
| ... | ... |
@@ -3664,9 +3667,9 @@ like($row->{$key1}, qr/^2010-01-03/);
|
| 3664 | 3667 |
like($row->{$key2}, qr/^2010-01-01 01:01:03/);
|
| 3665 | 3668 |
|
| 3666 | 3669 |
$dbi = DBIx::Custom->connect; |
| 3667 |
-$dbi->user_table_info($user_table_info); |
|
| 3668 | 3670 |
eval { $dbi->execute("drop table $table1") };
|
| 3669 | 3671 |
$dbi->execute($create_table1_type); |
| 3672 |
+$dbi->user_column_info($user_column_info); |
|
| 3670 | 3673 |
$dbi->type_rule( |
| 3671 | 3674 |
from1 => {
|
| 3672 | 3675 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v },
|
| ... | ... |
@@ -3678,9 +3681,9 @@ $result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
|
| 3678 | 3681 |
like($result->one->{$key1}, qr/^2010-01-05/);
|
| 3679 | 3682 |
|
| 3680 | 3683 |
$dbi = DBIx::Custom->connect; |
| 3681 |
-$dbi->user_table_info($user_table_info); |
|
| 3682 | 3684 |
eval { $dbi->execute("drop table $table1") };
|
| 3683 | 3685 |
$dbi->execute($create_table1_type); |
| 3686 |
+$dbi->user_column_info($user_column_info); |
|
| 3684 | 3687 |
$dbi->type_rule( |
| 3685 | 3688 |
from1 => {
|
| 3686 | 3689 |
$date_datatype => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
|
| ... | ... |
@@ -3692,9 +3695,9 @@ $result->filter($key1 => sub { my $v = shift || ''; $v =~ s/4/5/; return $v });
|
| 3692 | 3695 |
like($result->fetch->[0], qr/^2010-01-05/); |
| 3693 | 3696 |
|
| 3694 | 3697 |
$dbi = DBIx::Custom->connect; |
| 3695 |
-$dbi->user_table_info($user_table_info); |
|
| 3696 | 3698 |
eval { $dbi->execute("drop table $table1") };
|
| 3697 | 3699 |
$dbi->execute($create_table1_type); |
| 3700 |
+$dbi->user_column_info($user_column_info); |
|
| 3698 | 3701 |
$dbi->type_rule( |
| 3699 | 3702 |
into1 => {
|
| 3700 | 3703 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
|
| ... | ... |
@@ -3716,9 +3719,9 @@ $result = $dbi->select(table => $table1); |
| 3716 | 3719 |
like($result->type_rule_on->fetch_first->[0], qr/^2010-01-07/); |
| 3717 | 3720 |
|
| 3718 | 3721 |
$dbi = DBIx::Custom->connect; |
| 3719 |
-$dbi->user_table_info($user_table_info); |
|
| 3720 | 3722 |
eval { $dbi->execute("drop table $table1") };
|
| 3721 | 3723 |
$dbi->execute($create_table1_type); |
| 3724 |
+$dbi->user_column_info($user_column_info); |
|
| 3722 | 3725 |
$dbi->type_rule( |
| 3723 | 3726 |
into1 => {
|
| 3724 | 3727 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/4/; return $v }
|
| ... | ... |
@@ -3740,9 +3743,9 @@ $result = $dbi->select(table => $table1); |
| 3740 | 3743 |
like($result->type_rule1_on->fetch_first->[0], qr/^2010-01-07/); |
| 3741 | 3744 |
|
| 3742 | 3745 |
$dbi = DBIx::Custom->connect; |
| 3743 |
-$dbi->user_table_info($user_table_info); |
|
| 3744 | 3746 |
eval { $dbi->execute("drop table $table1") };
|
| 3745 | 3747 |
$dbi->execute($create_table1_type); |
| 3748 |
+$dbi->user_column_info($user_column_info); |
|
| 3746 | 3749 |
$dbi->type_rule( |
| 3747 | 3750 |
into1 => {
|
| 3748 | 3751 |
$date_typename => sub { my $v = shift || ''; $v =~ s/3/5/; return $v }
|
| ... | ... |
@@ -1,21 +1,27 @@ |
| 1 | 1 |
use Test::More; |
| 2 | 2 |
use strict; |
| 3 | 3 |
use warnings; |
| 4 |
+use utf8; |
|
| 4 | 5 |
|
| 5 | 6 |
use FindBin; |
| 6 | 7 |
use DBIx::Custom; |
| 7 | 8 |
|
| 8 | 9 |
my $dbi; |
| 10 |
+my $dsn; |
|
| 11 |
+my $args; |
|
| 12 |
+my $user = 'dbix_custom'; |
|
| 13 |
+my $password = 'dbix_custom'; |
|
| 14 |
+my $database = 'dbix_custom'; |
|
| 9 | 15 |
|
| 10 |
-plan skip_all => 'mysql private test' unless -f "$FindBin::Bin/run/mysql.run" |
|
| 11 |
- && eval { $dbi = DBIx::Custom->connect; 1 };
|
|
| 16 |
+$dsn = "dbi:mysql:database=$database"; |
|
| 17 |
+$args = {dsn => $dsn, user => $user, password => $password,};
|
|
| 18 |
+ |
|
| 19 |
+plan skip_all => 'mysql private test' unless -f "$FindBin::Bin/run/mysql2.run" |
|
| 20 |
+ && eval { $dbi = DBIx::Custom->connect($args); 1 };
|
|
| 12 | 21 |
plan 'no_plan'; |
| 13 | 22 |
|
| 14 | 23 |
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
|
| 15 | 24 |
|
| 16 |
-# user password database |
|
| 17 |
-our ($user, $password, $database) = qw/appuser 123456 usertest/; |
|
| 18 |
- |
|
| 19 | 25 |
require DBIx::Connector; |
| 20 | 26 |
|
| 21 | 27 |
# Function for test name |
| ... | ... |
@@ -44,8 +50,8 @@ for (1 .. 200) {
|
| 44 | 50 |
password => $password |
| 45 | 51 |
); |
| 46 | 52 |
$dbi->query_builder; |
| 47 |
- $dbi->create_model(table => $table1); |
|
| 48 |
- $dbi->create_model(table => $table2); |
|
| 53 |
+ $dbi->create_model(table => 'table1'); |
|
| 54 |
+ $dbi->create_model(table => 'table2'); |
|
| 49 | 55 |
} |
| 50 | 56 |
|
| 51 | 57 |
test 'limit'; |
| ... | ... |
@@ -104,62 +110,6 @@ $rows = $dbi->select( |
| 104 | 110 |
is_deeply($rows, [{key1 => 1, key2 => 4}]);
|
| 105 | 111 |
$dbi->delete_all(table => 'table1'); |
| 106 | 112 |
|
| 107 |
-test 'type_rule'; |
|
| 108 |
-$dbi = DBIx::Custom->connect( |
|
| 109 |
- dsn => "dbi:mysql:database=$database", |
|
| 110 |
- user => $user, |
|
| 111 |
- password => $password |
|
| 112 |
-); |
|
| 113 |
-eval{$dbi->execute("create table date_test (date DATE, datetime DATETIME)")};
|
|
| 114 |
-$dbi->each_column( |
|
| 115 |
- sub {
|
|
| 116 |
- my ($self, $table, $column, $column_info) = @_; |
|
| 117 |
- } |
|
| 118 |
-); |
|
| 119 |
- |
|
| 120 |
-$dbi->type_rule( |
|
| 121 |
- into1 => {
|
|
| 122 |
- date=> sub {
|
|
| 123 |
- my $date = shift; |
|
| 124 |
- $date =~ s/aaaaa//g; |
|
| 125 |
- return $date; |
|
| 126 |
- }, |
|
| 127 |
- datetime => sub {
|
|
| 128 |
- my $date = shift; |
|
| 129 |
- $date =~ s/ccccc//g; |
|
| 130 |
- return $date; |
|
| 131 |
- }, |
|
| 132 |
- }, |
|
| 133 |
- from1 => {
|
|
| 134 |
- # DATE |
|
| 135 |
- 9 => sub {
|
|
| 136 |
- my $date = shift; |
|
| 137 |
- $date .= 'bbbbb'; |
|
| 138 |
- return $date; |
|
| 139 |
- }, |
|
| 140 |
- # DATETIME or TIMPESTANM |
|
| 141 |
- 11 => sub {
|
|
| 142 |
- my $date = shift; |
|
| 143 |
- $date .= 'ddddd'; |
|
| 144 |
- return $date; |
|
| 145 |
- } |
|
| 146 |
- } |
|
| 147 |
-); |
|
| 148 |
- |
|
| 149 |
-$dbi->insert( |
|
| 150 |
- {
|
|
| 151 |
- date => 'aaaaa2010-aaaaa11-12aaaaa', |
|
| 152 |
- datetime => '2010-11ccccc-12 10:ccccc55:56' |
|
| 153 |
- }, |
|
| 154 |
- table => 'date_test' |
|
| 155 |
-); |
|
| 156 |
-is_deeply( |
|
| 157 |
- $dbi->select(table => 'date_test')->fetch, |
|
| 158 |
- ['2010-11-12bbbbb', '2010-11-12 10:55:56ddddd'] |
|
| 159 |
-); |
|
| 160 |
- |
|
| 161 |
-$dbi->execute("drop table date_test");
|
|
| 162 |
- |
|
| 163 | 113 |
test 'dbh'; |
| 164 | 114 |
{
|
| 165 | 115 |
my $connector = DBIx::Connector->new( |
| ... | ... |
@@ -0,0 +1,65 @@ |
| 1 |
+use Test::More; |
|
| 2 |
+use strict; |
|
| 3 |
+use warnings; |
|
| 4 |
+use utf8; |
|
| 5 |
+ |
|
| 6 |
+use FindBin; |
|
| 7 |
+use DBIx::Custom; |
|
| 8 |
+ |
|
| 9 |
+my $dbi; |
|
| 10 |
+my $dsn; |
|
| 11 |
+my $args; |
|
| 12 |
+my $user = 'dbix_custom'; |
|
| 13 |
+my $password = 'dbix_custom'; |
|
| 14 |
+my $database = 'dbix_custom'; |
|
| 15 |
+ |
|
| 16 |
+$dsn = "dbi:mysql:database=$database"; |
|
| 17 |
+$args = {dsn => $dsn, user => $user, password => $password,};
|
|
| 18 |
+ |
|
| 19 |
+plan skip_all => 'mysql private test' unless -f "$FindBin::Bin/run/mysql2.run" |
|
| 20 |
+ && eval { $dbi = DBIx::Custom->connect($args); 1 };
|
|
| 21 |
+plan 'no_plan'; |
|
| 22 |
+ |
|
| 23 |
+$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
|
|
| 24 |
+ |
|
| 25 |
+ |
|
| 26 |
+require DBIx::Connector; |
|
| 27 |
+ |
|
| 28 |
+# Function for test name |
|
| 29 |
+sub test { print "# $_[0]\n" }
|
|
| 30 |
+ |
|
| 31 |
+# Varialbes for tests |
|
| 32 |
+my $dbname; |
|
| 33 |
+my $rows; |
|
| 34 |
+my $result; |
|
| 35 |
+ |
|
| 36 |
+$dbi = DBIx::Custom->connect( |
|
| 37 |
+ dsn => "dbi:mysql:database=$database", |
|
| 38 |
+ user => $user, |
|
| 39 |
+ password => $password |
|
| 40 |
+); |
|
| 41 |
+eval { $dbi->execute('drop table table1') };
|
|
| 42 |
+$dbi->execute('create table table1 (key1 varchar(255), key2 varchar(255))');
|
|
| 43 |
+ |
|
| 44 |
+test 'connector => 1'; |
|
| 45 |
+{
|
|
| 46 |
+ my $dbi = DBIx::Custom->connect(dsn => $dsn, user => $user, password => $password, |
|
| 47 |
+ dbi_option => {PrintError => 1}, connector => 1);
|
|
| 48 |
+ is(ref $dbi->connector, 'DBIx::Connector'); |
|
| 49 |
+ ok($dbi->dbh->{PrintError});
|
|
| 50 |
+ $dbi->delete_all(table => 'table1'); |
|
| 51 |
+ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 52 |
+ die "Can't fork" unless defined (my $pid = fork); |
|
| 53 |
+ |
|
| 54 |
+ if ($pid) {
|
|
| 55 |
+ # Parent |
|
| 56 |
+ my $result = $dbi->select(table => 'table1'); |
|
| 57 |
+ is_deeply($result->fetch_hash_first, {key1 => 1, key2 => 2});
|
|
| 58 |
+ } |
|
| 59 |
+ else {
|
|
| 60 |
+ # Child |
|
| 61 |
+ my $result = $dbi->select(table => 'table1'); |
|
| 62 |
+ die "Not OK" unless $result->fetch_hash_first->{key1} == 1;
|
|
| 63 |
+ } |
|
| 64 |
+} |
|
| 65 |
+ |