| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
0.1622 |
| 2 | 2 |
deprecated DBIx::Custom::SQLite and DBIx::Custom::MySQL |
| 3 |
- |
|
| 3 |
+ added dbi_options attribute |
|
| 4 |
+ checked attributes passed to connect method |
|
| 4 | 5 |
0.1621 |
| 5 | 6 |
cleanup (removed undocumented features) |
| 6 | 7 |
0.1620 |
| ... | ... |
@@ -84,19 +84,6 @@ sub helper {
|
| 84 | 84 |
return $self; |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
-#sub new {
|
|
| 88 |
-# my $self = shift->SUPER::new(@_); |
|
| 89 |
-# |
|
| 90 |
-# # Check attribute names |
|
| 91 |
-# my @attrs = keys %$self; |
|
| 92 |
-# foreach my $attr (@attrs) {
|
|
| 93 |
-# croak qq{"$attr" is invalid attribute name"}
|
|
| 94 |
-# unless $self->can($attr); |
|
| 95 |
-# } |
|
| 96 |
-# |
|
| 97 |
-# return $self; |
|
| 98 |
-#} |
|
| 99 |
- |
|
| 100 | 87 |
sub connect {
|
| 101 | 88 |
my $proto = shift; |
| 102 | 89 |
|
| ... | ... |
@@ -111,6 +98,9 @@ sub connect {
|
| 111 | 98 |
|
| 112 | 99 |
my $user = $self->user; |
| 113 | 100 |
my $password = $self->password; |
| 101 |
+ my $dbi_options = $self->dbi_options || {};
|
|
| 102 |
+ |
|
| 103 |
+ $DB::single = 1; |
|
| 114 | 104 |
|
| 115 | 105 |
# Connect |
| 116 | 106 |
my $dbh = eval {DBI->connect(
|
| ... | ... |
@@ -121,6 +111,7 @@ sub connect {
|
| 121 | 111 |
RaiseError => 1, |
| 122 | 112 |
PrintError => 0, |
| 123 | 113 |
AutoCommit => 1, |
| 114 |
+ %$dbi_options |
|
| 124 | 115 |
} |
| 125 | 116 |
)}; |
| 126 | 117 |
|
| ... | ... |
@@ -317,6 +308,19 @@ sub insert {
|
| 317 | 308 |
return $ret_val; |
| 318 | 309 |
} |
| 319 | 310 |
|
| 311 |
+sub new {
|
|
| 312 |
+ my $self = shift->SUPER::new(@_); |
|
| 313 |
+ |
|
| 314 |
+ # Check attribute names |
|
| 315 |
+ my @attrs = keys %$self; |
|
| 316 |
+ foreach my $attr (@attrs) {
|
|
| 317 |
+ croak qq{"$attr" is invalid attribute name}
|
|
| 318 |
+ unless $self->can($attr); |
|
| 319 |
+ } |
|
| 320 |
+ |
|
| 321 |
+ return $self; |
|
| 322 |
+} |
|
| 323 |
+ |
|
| 320 | 324 |
sub register_filter {
|
| 321 | 325 |
my $invocant = shift; |
| 322 | 326 |
|
| ... | ... |
@@ -735,6 +739,14 @@ C<connect()> method use this value to connect the database. |
| 735 | 739 |
|
| 736 | 740 |
L<DBI> object. You can call all methods of L<DBI>. |
| 737 | 741 |
|
| 742 |
+=head2 C<dbi_options> |
|
| 743 |
+ |
|
| 744 |
+ my $dbi_options = $dbi->dbi_options; |
|
| 745 |
+ $dbi = $dbi->dbi_options($dbi_options); |
|
| 746 |
+ |
|
| 747 |
+DBI options. |
|
| 748 |
+C<connect()> method use this value to connect the database. |
|
| 749 |
+ |
|
| 738 | 750 |
=head2 C<default_bind_filter> |
| 739 | 751 |
|
| 740 | 752 |
my $default_bind_filter = $dbi->default_bind_filter |
| ... | ... |
@@ -960,6 +972,13 @@ B<Example:> |
| 960 | 972 |
append => "some statement", |
| 961 | 973 |
filter => {title => 'encode_utf8'})
|
| 962 | 974 |
|
| 975 |
+=head2 C<new> |
|
| 976 |
+ |
|
| 977 |
+ my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
| 978 |
+ user => 'ken', password => '!LFKD%$&'); |
|
| 979 |
+ |
|
| 980 |
+Create a new L<DBIx::Custom> object. |
|
| 981 |
+ |
|
| 963 | 982 |
=head2 C<register_filter> |
| 964 | 983 |
|
| 965 | 984 |
$dbi->register_filter(%filters); |
| ... | ... |
@@ -1,36 +1,50 @@ |
| 1 |
-use Test::More; |
|
| 2 |
-use strict; |
|
| 3 |
-use warnings; |
|
| 4 |
- |
|
| 5 |
-# user password database |
|
| 6 |
-our ($USER, $PASSWORD, $DATABASE) = connect_info(); |
|
| 7 |
- |
|
| 8 |
-plan skip_all => 'private MySQL test' unless $USER; |
|
| 9 |
- |
|
| 10 |
-plan 'no_plan'; |
|
| 11 |
- |
|
| 12 |
-use DBIx::Custom; |
|
| 13 |
-use Scalar::Util 'blessed'; |
|
| 14 |
-{
|
|
| 15 |
- my $dbi = DBIx::Custom->connect( |
|
| 16 |
- user => $USER, |
|
| 17 |
- password => $PASSWORD, |
|
| 18 |
- data_source => "dbi:mysql:dbname=$DATABASE" |
|
| 19 |
- ); |
|
| 20 |
- $dbi->connect; |
|
| 21 |
- |
|
| 22 |
- ok(blessed $dbi->dbh); |
|
| 23 |
- can_ok($dbi->dbh, qw/prepare/); |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-sub connect_info {
|
|
| 27 |
- my $file = 'password.tmp'; |
|
| 28 |
- open my $fh, '<', $file |
|
| 29 |
- or return; |
|
| 30 |
- |
|
| 31 |
- my ($user, $password, $database) = split(/\s/, (<$fh>)[0]); |
|
| 32 |
- |
|
| 33 |
- close $fh; |
|
| 34 |
- |
|
| 35 |
- return ($user, $password, $database); |
|
| 36 |
-} |
|
| 1 |
+use Test::More; |
|
| 2 |
+use strict; |
|
| 3 |
+use warnings; |
|
| 4 |
+ |
|
| 5 |
+# user password database |
|
| 6 |
+our ($USER, $PASSWORD, $DATABASE) = connect_info(); |
|
| 7 |
+ |
|
| 8 |
+plan skip_all => 'private MySQL test' unless $USER; |
|
| 9 |
+ |
|
| 10 |
+plan 'no_plan'; |
|
| 11 |
+ |
|
| 12 |
+use DBIx::Custom; |
|
| 13 |
+use Scalar::Util 'blessed'; |
|
| 14 |
+{
|
|
| 15 |
+ my $dbi = DBIx::Custom->connect( |
|
| 16 |
+ user => $USER, |
|
| 17 |
+ password => $PASSWORD, |
|
| 18 |
+ data_source => "dbi:mysql:dbname=$DATABASE" |
|
| 19 |
+ ); |
|
| 20 |
+ $dbi->connect; |
|
| 21 |
+ |
|
| 22 |
+ ok(blessed $dbi->dbh); |
|
| 23 |
+ can_ok($dbi->dbh, qw/prepare/); |
|
| 24 |
+ ok($dbi->dbh->{AutoCommit});
|
|
| 25 |
+ ok(!$dbi->dbh->{mysql_enable_utf8});
|
|
| 26 |
+} |
|
| 27 |
+ |
|
| 28 |
+{
|
|
| 29 |
+ my $dbi = DBIx::Custom->connect( |
|
| 30 |
+ user => $USER, |
|
| 31 |
+ password => $PASSWORD, |
|
| 32 |
+ data_source => "dbi:mysql:dbname=$DATABASE", |
|
| 33 |
+ dbi_options => {AutoCommit => 0, mysql_enable_utf8 => 1}
|
|
| 34 |
+ ); |
|
| 35 |
+ $dbi->connect; |
|
| 36 |
+ ok(!$dbi->dbh->{AutoCommit});
|
|
| 37 |
+ ok($dbi->dbh->{mysql_enable_utf8});
|
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+sub connect_info {
|
|
| 41 |
+ my $file = 'password.tmp'; |
|
| 42 |
+ open my $fh, '<', $file |
|
| 43 |
+ or return; |
|
| 44 |
+ |
|
| 45 |
+ my ($user, $password, $database) = split(/\s/, (<$fh>)[0]); |
|
| 46 |
+ |
|
| 47 |
+ close $fh; |
|
| 48 |
+ |
|
| 49 |
+ return ($user, $password, $database); |
|
| 50 |
+} |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-use Test::More tests => 11; |
|
| 1 |
+use Test::More tests => 12; |
|
| 2 | 2 |
use strict; |
| 3 | 3 |
use warnings; |
| 4 | 4 |
|
| ... | ... |
@@ -19,7 +19,6 @@ test 'Constructor'; |
| 19 | 19 |
$query_builder = DBIx::Custom::QueryBuilder->new; |
| 20 | 20 |
$dbi = DBIx::Custom->new( |
| 21 | 21 |
user => 'a', |
| 22 |
- database => 'a', |
|
| 23 | 22 |
password => 'b', |
| 24 | 23 |
data_source => 'c', |
| 25 | 24 |
filters => {
|
| ... | ... |
@@ -30,7 +29,7 @@ $dbi = DBIx::Custom->new( |
| 30 | 29 |
result_class => 'g', |
| 31 | 30 |
query_builder => $query_builder, |
| 32 | 31 |
); |
| 33 |
-is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c',
|
|
| 32 |
+is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c',
|
|
| 34 | 33 |
filters => {f => 3}, default_bind_filter => 'f',
|
| 35 | 34 |
default_fetch_filter => 'g', result_class => 'g', |
| 36 | 35 |
query_builder => $query_builder}, $test); |
| ... | ... |
@@ -101,3 +100,6 @@ test 'expand'; |
| 101 | 100 |
{'books.title' => 'Perl', 'books.author' => 'Ken'});
|
| 102 | 101 |
} |
| 103 | 102 |
|
| 103 |
+test 'invalid attribute name'; |
|
| 104 |
+eval {$dbi = DBIx::Custom->new(a => 1) };
|
|
| 105 |
+like ($@, qr/"a" is invalid attribute name/, $test); |