... | ... |
@@ -1,3 +1,10 @@ |
1 |
+0.0901 |
|
2 |
+ DBIx::Basic filter 'encode_utf8' utf8::upgrade process is deleted |
|
3 |
+0.0801 |
|
4 |
+ add 'create_table', 'drop_table' methods |
|
5 |
+0.0701 |
|
6 |
+ rename sql_template to sql_tmpl (not backword compatible) |
|
7 |
+ rename dbi_options to options (not backword compatible) |
|
1 | 8 |
0.0605 |
2 | 9 |
fix encode_utf8 filter |
3 | 10 |
0.0604 |
... | ... |
@@ -3,7 +3,7 @@ use 5.008001; |
3 | 3 |
package DBIx::Custom; |
4 | 4 |
use Object::Simple; |
5 | 5 |
|
6 |
-our $VERSION = '0.0605'; |
|
6 |
+our $VERSION = '0.0901'; |
|
7 | 7 |
|
8 | 8 |
use Carp 'croak'; |
9 | 9 |
use DBI; |
... | ... |
@@ -15,17 +15,28 @@ use DBIx::Custom::SQL::Template; |
15 | 15 |
sub user : ClassObjectAttr { initialize => {clone => 'scalar'} } |
16 | 16 |
sub password : ClassObjectAttr { initialize => {clone => 'scalar'} } |
17 | 17 |
sub data_source : ClassObjectAttr { initialize => {clone => 'scalar'} } |
18 |
-sub dbi_options : ClassObjectAttr { initialize => {clone => 'hash', |
|
19 |
- default => sub { {} } } } |
|
20 |
-sub database : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
21 |
-sub host : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
22 |
-sub port : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
18 |
+ |
|
19 |
+sub options : ClassObjectAttr { |
|
20 |
+ type => 'hash', |
|
21 |
+ initialize => {clone => 'hash', default => sub { {} }} |
|
22 |
+} |
|
23 |
+ |
|
24 |
+sub database : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
25 |
+sub host : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
26 |
+sub port : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
23 | 27 |
|
24 | 28 |
sub bind_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
25 | 29 |
sub fetch_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
26 | 30 |
|
27 |
-sub no_bind_filters : ClassObjectAttr { initialize => {clone => 'array'} } |
|
28 |
-sub no_fetch_filters : ClassObjectAttr { initialize => {clone => 'array'} } |
|
31 |
+sub no_bind_filters : ClassObjectAttr { |
|
32 |
+ type => 'array', |
|
33 |
+ initialize => {clone => 'array', default => sub { [] }} |
|
34 |
+} |
|
35 |
+ |
|
36 |
+sub no_fetch_filters : ClassObjectAttr { |
|
37 |
+ type => 'array', |
|
38 |
+ initialize => {clone => 'array', default => sub { [] }} |
|
39 |
+} |
|
29 | 40 |
|
30 | 41 |
sub filters : ClassObjectAttr { |
31 | 42 |
type => 'hash', |
... | ... |
@@ -52,7 +63,7 @@ sub result_class : ClassObjectAttr { |
52 | 63 |
} |
53 | 64 |
} |
54 | 65 |
|
55 |
-sub sql_template : ClassObjectAttr { |
|
66 |
+sub sql_tmpl : ClassObjectAttr { |
|
56 | 67 |
initialize => { |
57 | 68 |
clone => sub {$_[0] ? $_[0]->clone : undef}, |
58 | 69 |
default => sub {DBIx::Custom::SQL::Template->new} |
... | ... |
@@ -64,7 +75,6 @@ sub dbh : Attr {} |
64 | 75 |
|
65 | 76 |
### Methods |
66 | 77 |
|
67 |
-# Add filter |
|
68 | 78 |
sub add_filter { |
69 | 79 |
my $invocant = shift; |
70 | 80 |
|
... | ... |
@@ -74,7 +84,6 @@ sub add_filter { |
74 | 84 |
return $invocant; |
75 | 85 |
} |
76 | 86 |
|
77 |
-# Add format |
|
78 | 87 |
sub add_format{ |
79 | 88 |
my $invocant = shift; |
80 | 89 |
|
... | ... |
@@ -84,7 +93,6 @@ sub add_format{ |
84 | 93 |
return $invocant; |
85 | 94 |
} |
86 | 95 |
|
87 |
-# Auto commit |
|
88 | 96 |
sub _auto_commit { |
89 | 97 |
my $self = shift; |
90 | 98 |
|
... | ... |
@@ -97,13 +105,12 @@ sub _auto_commit { |
97 | 105 |
return $self->dbh->{AutoCommit}; |
98 | 106 |
} |
99 | 107 |
|
100 |
-# Connect |
|
101 | 108 |
sub connect { |
102 | 109 |
my $self = shift; |
103 | 110 |
my $data_source = $self->data_source; |
104 | 111 |
my $user = $self->user; |
105 | 112 |
my $password = $self->password; |
106 |
- my $dbi_options = $self->dbi_options; |
|
113 |
+ my $options = $self->options; |
|
107 | 114 |
|
108 | 115 |
my $dbh = eval{DBI->connect( |
109 | 116 |
$data_source, |
... | ... |
@@ -113,7 +120,7 @@ sub connect { |
113 | 120 |
RaiseError => 1, |
114 | 121 |
PrintError => 0, |
115 | 122 |
AutoCommit => 1, |
116 |
- %{$dbi_options || {} } |
|
123 |
+ %{$options || {} } |
|
117 | 124 |
} |
118 | 125 |
)}; |
119 | 126 |
|
... | ... |
@@ -123,19 +130,16 @@ sub connect { |
123 | 130 |
return $self; |
124 | 131 |
} |
125 | 132 |
|
126 |
-# DESTROY |
|
127 | 133 |
sub DESTROY { |
128 | 134 |
my $self = shift; |
129 | 135 |
$self->disconnect if $self->connected; |
130 | 136 |
} |
131 | 137 |
|
132 |
-# Is connected? |
|
133 | 138 |
sub connected { |
134 | 139 |
my $self = shift; |
135 | 140 |
return ref $self->{dbh} eq 'DBI::db'; |
136 | 141 |
} |
137 | 142 |
|
138 |
-# Disconnect |
|
139 | 143 |
sub disconnect { |
140 | 144 |
my $self = shift; |
141 | 145 |
if ($self->connected) { |
... | ... |
@@ -144,14 +148,12 @@ sub disconnect { |
144 | 148 |
} |
145 | 149 |
} |
146 | 150 |
|
147 |
-# Reconnect |
|
148 | 151 |
sub reconnect { |
149 | 152 |
my $self = shift; |
150 | 153 |
$self->disconnect if $self->connected; |
151 | 154 |
$self->connect; |
152 | 155 |
} |
153 | 156 |
|
154 |
-# Prepare statement handle |
|
155 | 157 |
sub prepare { |
156 | 158 |
my ($self, $sql) = @_; |
157 | 159 |
|
... | ... |
@@ -167,7 +169,6 @@ sub prepare { |
167 | 169 |
return $sth; |
168 | 170 |
} |
169 | 171 |
|
170 |
-# Execute SQL directly |
|
171 | 172 |
sub do{ |
172 | 173 |
my ($self, $sql, @bind_values) = @_; |
173 | 174 |
|
... | ... |
@@ -175,7 +176,7 @@ sub do{ |
175 | 176 |
$self->connect unless $self->connected; |
176 | 177 |
|
177 | 178 |
# Do |
178 |
- my $ret_val = eval{$self->dbh->do($sql, @bind_values)}; |
|
179 |
+ my $affected = eval{$self->dbh->do($sql, @bind_values)}; |
|
179 | 180 |
|
180 | 181 |
# Error |
181 | 182 |
if ($@) { |
... | ... |
@@ -187,15 +188,16 @@ sub do{ |
187 | 188 |
|
188 | 189 |
croak("$error<Your SQL>\n$sql\n<Your bind values>\n$bind_value_dump\n"); |
189 | 190 |
} |
191 |
+ |
|
192 |
+ return $affected; |
|
190 | 193 |
} |
191 | 194 |
|
192 |
-# Create query |
|
193 | 195 |
sub create_query { |
194 | 196 |
my ($self, $template) = @_; |
195 | 197 |
my $class = ref $self; |
196 | 198 |
|
197 | 199 |
# Create query from SQL template |
198 |
- my $sql_template = $self->sql_template; |
|
200 |
+ my $sql_tmpl = $self->sql_tmpl; |
|
199 | 201 |
|
200 | 202 |
# Try to get cached query |
201 | 203 |
my $cached_query = $class->_query_caches->{$template}; |
... | ... |
@@ -207,7 +209,7 @@ sub create_query { |
207 | 209 |
key_infos => $cached_query->key_infos); |
208 | 210 |
} |
209 | 211 |
else { |
210 |
- $query = eval{$sql_template->create_query($template)}; |
|
212 |
+ $query = eval{$sql_tmpl->create_query($template)}; |
|
211 | 213 |
croak($@) if $@; |
212 | 214 |
|
213 | 215 |
$class->_add_query_cache($template, $query); |
... | ... |
@@ -237,8 +239,7 @@ sub create_query { |
237 | 239 |
return $query; |
238 | 240 |
} |
239 | 241 |
|
240 |
-# Execute query |
|
241 |
-sub execute { |
|
242 |
+sub query{ |
|
242 | 243 |
my ($self, $query, $params) = @_; |
243 | 244 |
$params ||= {}; |
244 | 245 |
|
... | ... |
@@ -254,8 +255,8 @@ sub execute { |
254 | 255 |
my $bind_values = $self->_build_bind_values($query, $params); |
255 | 256 |
|
256 | 257 |
# Execute |
257 |
- my $sth = $query->sth; |
|
258 |
- my $ret_val = eval{$sth->execute(@$bind_values)}; |
|
258 |
+ my $sth = $query->sth; |
|
259 |
+ my $affected = eval{$sth->execute(@$bind_values)}; |
|
259 | 260 |
|
260 | 261 |
# Execute error |
261 | 262 |
if (my $execute_error = $@) { |
... | ... |
@@ -284,10 +285,9 @@ sub execute { |
284 | 285 |
}); |
285 | 286 |
return $result; |
286 | 287 |
} |
287 |
- return $ret_val; |
|
288 |
+ return $affected; |
|
288 | 289 |
} |
289 | 290 |
|
290 |
-# Build binding values |
|
291 | 291 |
sub _build_bind_values { |
292 | 292 |
my ($self, $query, $params) = @_; |
293 | 293 |
my $key_infos = $query->key_infos; |
... | ... |
@@ -398,7 +398,6 @@ sub _build_bind_values { |
398 | 398 |
return \@bind_values; |
399 | 399 |
} |
400 | 400 |
|
401 |
-# Run transaction |
|
402 | 401 |
sub run_transaction { |
403 | 402 |
my ($self, $transaction) = @_; |
404 | 403 |
|
... | ... |
@@ -449,14 +448,42 @@ sub run_transaction { |
449 | 448 |
} |
450 | 449 |
} |
451 | 450 |
|
452 |
-# Get last insert id |
|
453 | 451 |
sub last_insert_id { |
454 | 452 |
my $self = shift; |
455 | 453 |
my $class = ref $self; |
456 | 454 |
croak "'$class' do not suppert 'last_insert_id'"; |
457 | 455 |
} |
458 | 456 |
|
459 |
-# Insert |
|
457 |
+ |
|
458 |
+sub create_table { |
|
459 |
+ my ($self, $table, @column_definitions) = @_; |
|
460 |
+ |
|
461 |
+ # Create table |
|
462 |
+ my $sql = "create table $table (\n"; |
|
463 |
+ |
|
464 |
+ # Column definitions |
|
465 |
+ foreach my $column_definition (@column_definitions) { |
|
466 |
+ $sql .= "\t$column_definition,\n"; |
|
467 |
+ } |
|
468 |
+ $sql =~ s/,\n$//; |
|
469 |
+ |
|
470 |
+ # End |
|
471 |
+ $sql .= "\n);"; |
|
472 |
+ |
|
473 |
+ # Do query |
|
474 |
+ return $self->do($sql); |
|
475 |
+} |
|
476 |
+ |
|
477 |
+sub drop_table { |
|
478 |
+ my ($self, $table) = @_; |
|
479 |
+ |
|
480 |
+ # Drop table |
|
481 |
+ my $sql = "drop table $table;"; |
|
482 |
+ |
|
483 |
+ # Do query |
|
484 |
+ return $self->do($sql); |
|
485 |
+} |
|
486 |
+ |
|
460 | 487 |
sub insert { |
461 | 488 |
my $self = shift; |
462 | 489 |
my $table = shift || ''; |
... | ... |
@@ -485,12 +512,11 @@ sub insert { |
485 | 512 |
$query_edit_cb->($query) if $query_edit_cb; |
486 | 513 |
|
487 | 514 |
# Execute query |
488 |
- my $ret_val = $self->execute($query, $insert_params); |
|
515 |
+ my $ret_val = $self->query($query, $insert_params); |
|
489 | 516 |
|
490 | 517 |
return $ret_val; |
491 | 518 |
} |
492 | 519 |
|
493 |
-# Update |
|
494 | 520 |
sub update { |
495 | 521 |
my $self = shift; |
496 | 522 |
my $table = shift || ''; |
... | ... |
@@ -545,12 +571,11 @@ sub update { |
545 | 571 |
my $params = {'#update' => $update_params, %$where_params}; |
546 | 572 |
|
547 | 573 |
# Execute query |
548 |
- my $ret_val = $self->execute($query, $params); |
|
574 |
+ my $ret_val = $self->query($query, $params); |
|
549 | 575 |
|
550 | 576 |
return $ret_val; |
551 | 577 |
} |
552 | 578 |
|
553 |
-# Update all rows |
|
554 | 579 |
sub update_all { |
555 | 580 |
my $self = shift; |
556 | 581 |
my $table = shift || ''; |
... | ... |
@@ -563,7 +588,6 @@ sub update_all { |
563 | 588 |
$query_edit_cb, $options); |
564 | 589 |
} |
565 | 590 |
|
566 |
-# Delete |
|
567 | 591 |
sub delete { |
568 | 592 |
my $self = shift; |
569 | 593 |
my $table = shift || ''; |
... | ... |
@@ -604,12 +628,11 @@ sub delete { |
604 | 628 |
$query_edit_cb->($query) if $query_edit_cb; |
605 | 629 |
|
606 | 630 |
# Execute query |
607 |
- my $ret_val = $self->execute($query, $where_params); |
|
631 |
+ my $ret_val = $self->query($query, $where_params); |
|
608 | 632 |
|
609 | 633 |
return $ret_val; |
610 | 634 |
} |
611 | 635 |
|
612 |
-# Delete all rows |
|
613 | 636 |
sub delete_all { |
614 | 637 |
my $self = shift; |
615 | 638 |
my $table = shift || ''; |
... | ... |
@@ -626,10 +649,10 @@ Your select arguments is wrong. |
626 | 649 |
select usage: |
627 | 650 |
$dbi->select( |
628 | 651 |
$table, # must be string or array ref |
629 |
- [@$columns], # must be array reference. this is optional |
|
630 |
- {%$where_params}, # must be hash reference. this is optional |
|
631 |
- $append_statement, # must be string. this is optional |
|
632 |
- $query_edit_callback # must be code reference. this is optional |
|
652 |
+ [@$columns], # must be array reference. this can be ommited |
|
653 |
+ {%$where_params}, # must be hash reference. this can be ommited |
|
654 |
+ $append_statement, # must be string. this can be ommited |
|
655 |
+ $query_edit_callback # must be code reference. this can be ommited |
|
633 | 656 |
); |
634 | 657 |
EOS |
635 | 658 |
|
... | ... |
@@ -704,7 +727,7 @@ sub select { |
704 | 727 |
$query_edit_cb->($query) if $query_edit_cb; |
705 | 728 |
|
706 | 729 |
# Execute query |
707 |
- my $result = $self->execute($query, $where_params); |
|
730 |
+ my $result = $self->query($query, $where_params); |
|
708 | 731 |
|
709 | 732 |
return $result; |
710 | 733 |
} |
... | ... |
@@ -717,7 +740,6 @@ sub _query_cache_keys : ClassAttr { type => 'array', |
717 | 740 |
|
718 | 741 |
sub query_cache_max : ClassAttr { auto_build => sub {shift->query_cache_max(50)} } |
719 | 742 |
|
720 |
-# Add query cahce |
|
721 | 743 |
sub _add_query_cache { |
722 | 744 |
my ($class, $template, $query) = @_; |
723 | 745 |
my $query_cache_keys = $class->_query_cache_keys; |
... | ... |
@@ -738,7 +760,6 @@ sub _add_query_cache { |
738 | 760 |
return $class; |
739 | 761 |
} |
740 | 762 |
|
741 |
-# Both bind_filter and fetch_filter off |
|
742 | 763 |
sub filter_off { |
743 | 764 |
my $self = shift; |
744 | 765 |
|
... | ... |
@@ -753,27 +774,40 @@ Object::Simple->build_class; |
753 | 774 |
|
754 | 775 |
=head1 NAME |
755 | 776 |
|
756 |
-DBIx::Custom - Customizable simple DBI |
|
757 |
- |
|
758 |
-=head1 Version |
|
759 |
- |
|
760 |
-Version 0.0601 |
|
761 |
- |
|
762 |
-=head1 Caution |
|
777 |
+DBIx::Custom - Customizable DBI |
|
763 | 778 |
|
764 |
-This module is now experimental stage. |
|
779 |
+=head1 VERSION |
|
765 | 780 |
|
766 |
-I want you to try this module |
|
767 |
-because I want this module stable, and not to damage your DB data by this module bug. |
|
781 |
+Version 0.0801 |
|
768 | 782 |
|
769 |
-Please tell me bug if you find |
|
770 |
- |
|
771 |
-=head1 Synopsys |
|
772 |
- |
|
773 |
- my $dbi = DBIx::Custom->new; |
|
774 |
- |
|
775 |
- my $query = $dbi->create_query($template); |
|
776 |
- $dbi->execute($query); |
|
783 |
+=head1 SYNOPSYS |
|
784 |
+ |
|
785 |
+ # New |
|
786 |
+ my $dbi = DBIx::Custom->new(data_source => "dbi:mysql:database=books" |
|
787 |
+ user => 'ken', password => '!LFKD%$&'); |
|
788 |
+ |
|
789 |
+ # Query |
|
790 |
+ $dbi->query("select title from books"); |
|
791 |
+ |
|
792 |
+ # Query with parameters |
|
793 |
+ $dbi->query("select id from books where {= author} && {like title}", |
|
794 |
+ {author => 'ken', title => '%Perl%'}); |
|
795 |
+ |
|
796 |
+ # Insert |
|
797 |
+ $dbi->insert('books', {title => 'perl', author => 'Ken'}); |
|
798 |
+ |
|
799 |
+ # Update |
|
800 |
+ $dbi->update('books', {title => 'aaa', author => 'Ken'}, {id => 5}); |
|
801 |
+ |
|
802 |
+ # Delete |
|
803 |
+ $dbi->delete('books', {author => 'Ken'}); |
|
804 |
+ |
|
805 |
+ # Select |
|
806 |
+ $dbi->select('books'); |
|
807 |
+ $dbi->select('books', {author => 'taro'}); |
|
808 |
+ $dbi->select('books', [qw/author title/], {author => 'Ken'}); |
|
809 |
+ $dbi->select('books', [qw/author title/], {author => 'Ken'}, |
|
810 |
+ 'order by id limit 1'); |
|
777 | 811 |
|
778 | 812 |
=head1 Accessors |
779 | 813 |
|
... | ... |
@@ -781,172 +815,99 @@ Please tell me bug if you find |
781 | 815 |
|
782 | 816 |
Set and get database user name |
783 | 817 |
|
784 |
- # For object |
|
785 |
- $self = $self->user($user); |
|
786 |
- $user = $self->user; |
|
787 |
- |
|
788 |
- # For class |
|
789 |
- $class = $class->user($user); |
|
790 |
- $user = $class->user; |
|
791 |
- |
|
792 |
- # Sample |
|
793 |
- $dbi->user('taro'); |
|
818 |
+ $dbi = $dbi->user('Ken'); |
|
819 |
+ $user = $dbi->user; |
|
794 | 820 |
|
795 | 821 |
=head2 password |
796 | 822 |
|
797 | 823 |
Set and get database password |
798 | 824 |
|
799 |
- # For object |
|
800 |
- $self = $self->password($password); |
|
801 |
- $password = $self->password; |
|
802 |
- |
|
803 |
- # For class |
|
804 |
- $class = $class->password($password); |
|
805 |
- $password = $class->password; |
|
806 |
- |
|
807 |
- # Sample |
|
808 |
- $dbi->password('lkj&le`@s'); |
|
825 |
+ $dbi = $dbi->password('lkj&le`@s'); |
|
826 |
+ $password = $dbi->password; |
|
809 | 827 |
|
810 | 828 |
=head2 data_source |
811 | 829 |
|
812 | 830 |
Set and get database data source |
813 | 831 |
|
814 |
- # For object |
|
815 |
- $self = $self->data_source($data_soruce); |
|
816 |
- $data_source = $self->data_source; |
|
817 |
- |
|
818 |
- # For class |
|
819 |
- $class = $class->data_source($data_soruce); |
|
820 |
- $data_source = $class->data_source; |
|
821 |
- |
|
822 |
- # Sample(SQLite) |
|
823 |
- $dbi->data_source(dbi:SQLite:dbname=$database); |
|
824 |
- |
|
825 |
- # Sample(MySQL); |
|
826 |
- $dbi->data_source("dbi:mysql:dbname=$database"); |
|
827 |
- |
|
828 |
- # Sample(PostgreSQL) |
|
829 |
- $dbi->data_source("dbi:Pg:dbname=$database"); |
|
832 |
+ $dbi = $dbi->data_source("dbi:mysql:dbname=$database"); |
|
833 |
+ $data_source = $dbi->data_source; |
|
830 | 834 |
|
835 |
+If you know data source more, See also L<DBI>. |
|
836 |
+ |
|
831 | 837 |
=head2 database |
832 | 838 |
|
833 | 839 |
Set and get database name |
834 | 840 |
|
835 |
- # For object |
|
836 |
- $self = $self->database($database); |
|
837 |
- $database = $self->database; |
|
838 |
- |
|
839 |
- # For class |
|
840 |
- $class = $class->database($database); |
|
841 |
- $database = $class->database; |
|
842 |
- |
|
843 |
- # Sample |
|
844 |
- $dbi->database('books'); |
|
841 |
+ $dbi = $dbi->database('books'); |
|
842 |
+ $database = $dbi->database; |
|
845 | 843 |
|
846 | 844 |
=head2 host |
847 | 845 |
|
848 | 846 |
Set and get host name |
849 | 847 |
|
850 |
- # For object |
|
851 |
- $self = $self->host($host); |
|
852 |
- $host = $self->host; |
|
848 |
+ $dbi = $dbi->host('somehost.com'); |
|
849 |
+ $host = $dbi->host; |
|
853 | 850 |
|
854 |
- # For class |
|
855 |
- $class = $class->host($host); |
|
856 |
- $host = $class->host; |
|
857 |
- |
|
858 |
- # Sample |
|
859 |
- $dbi->host('somehost.com'); |
|
860 |
- $dbi->host('127.1.2.3'); |
|
851 |
+You can also set IP address like '127.03.45.12'. |
|
861 | 852 |
|
862 | 853 |
=head2 port |
863 | 854 |
|
864 | 855 |
Set and get port |
865 | 856 |
|
866 |
- # For object |
|
867 |
- $self = $self->port($port); |
|
868 |
- $port = $self->port; |
|
857 |
+ $dbi = $dbi->port(1198); |
|
858 |
+ $port = $dbi->port; |
|
869 | 859 |
|
870 |
- # For class |
|
871 |
- $class = $class->port($port); |
|
872 |
- $port = $class->port; |
|
873 |
- |
|
874 |
- # Sample |
|
875 |
- $dbi->port(1198); |
|
876 |
- |
|
877 |
-=head2 dbi_options |
|
860 |
+=head2 options |
|
878 | 861 |
|
879 | 862 |
Set and get DBI option |
880 | 863 |
|
881 |
- # For object |
|
882 |
- $self = $self->dbi_options({$options => $value, ...}); |
|
883 |
- $dbi_options = $self->dbi_options; |
|
884 |
- |
|
885 |
- # For class |
|
886 |
- $class = $class->dbi_options({$options => $value, ...}); |
|
887 |
- $dbi_options = $class->dbi_options; |
|
888 |
- |
|
889 |
- # Sample |
|
890 |
- $dbi->dbi_options({PrintError => 0, RaiseError => 1}); |
|
864 |
+ $dbi = $dbi->options({PrintError => 0, RaiseError => 1}); |
|
865 |
+ $options = $dbi->options; |
|
891 | 866 |
|
892 |
-=head2 sql_template |
|
867 |
+=head2 sql_tmpl |
|
893 | 868 |
|
894 | 869 |
Set and get SQL::Template object |
895 | 870 |
|
896 |
- # For object |
|
897 |
- $self = $self->sql_template($sql_template); |
|
898 |
- $sql_template = $self->sql_template; |
|
871 |
+ $dbi = $dbi->sql_tmpl(DBIx::Cutom::SQL::Template->new); |
|
872 |
+ $sql_tmpl = $dbi->sql_tmpl; |
|
899 | 873 |
|
900 |
- # For class |
|
901 |
- $class = $class->sql_template($sql_template); |
|
902 |
- $sql_template = $class->sql_template; |
|
903 |
- |
|
904 |
- # Sample |
|
905 |
- $dbi->sql_template(DBI::Cutom::SQL::Template->new); |
|
874 |
+See also L<DBIx::Custom::SQL::Template>. |
|
906 | 875 |
|
907 | 876 |
=head2 filters |
908 | 877 |
|
909 | 878 |
Set and get filters |
910 | 879 |
|
911 |
- # For object |
|
912 |
- $self = $self->filters($filters); |
|
913 |
- $filters = $self->filters; |
|
914 |
- |
|
915 |
- # For class |
|
916 |
- $class = $class->filters($filters); |
|
917 |
- $filters = $class->filters; |
|
880 |
+ $dbi = $dbi->filters({filter1 => sub { }, filter2 => sub {}}); |
|
881 |
+ $filters = $dbi->filters; |
|
918 | 882 |
|
919 |
- # Sample |
|
920 |
- $ret = $dbi->filters->{encode_utf8}->($value); |
|
883 |
+This method is generally used to get a filter. |
|
884 |
+ |
|
885 |
+ $filter = $dbi->filters->{encode_utf8}; |
|
886 |
+ |
|
887 |
+If you add filter, use add_filter method. |
|
921 | 888 |
|
922 | 889 |
=head2 formats |
923 | 890 |
|
924 | 891 |
Set and get formats |
925 | 892 |
|
926 |
- # For object |
|
927 |
- $self = $self->formats($formats); |
|
928 |
- $formats = $self->formats; |
|
893 |
+ $dbi = $dbi->formats({format1 => sub { }, format2 => sub {}}); |
|
894 |
+ $formats = $dbi->formats; |
|
929 | 895 |
|
930 |
- # For class |
|
931 |
- $self = $self->formats($formats); |
|
932 |
- $formats = $self->formats; |
|
896 |
+This method is generally used to get a format. |
|
933 | 897 |
|
934 |
- # Sample |
|
935 |
- $datetime_format = $dbi->formats->{datetime}; |
|
898 |
+ $filter = $dbi->formats->{datetime}; |
|
899 |
+ |
|
900 |
+If you add format, use add_format method. |
|
936 | 901 |
|
937 | 902 |
=head2 bind_filter |
938 | 903 |
|
939 | 904 |
Set and get binding filter |
940 | 905 |
|
941 |
- # For object |
|
942 |
- $self = $self->bind_filter($bind_filter); |
|
943 |
- $bind_filter = $self->bind_filter |
|
906 |
+ $dbi = $dbi->bind_filter($bind_filter); |
|
907 |
+ $bind_filter = $dbi->bind_filter |
|
944 | 908 |
|
945 |
- # For object |
|
946 |
- $class = $class->bind_filter($bind_filter); |
|
947 |
- $bind_filter = $class->bind_filter |
|
909 |
+The following is bind filter sample |
|
948 | 910 |
|
949 |
- # Sample |
|
950 | 911 |
$dbi->bind_filter(sub { |
951 | 912 |
my ($value, $key, $dbi, $infos) = @_; |
952 | 913 |
|
... | ... |
@@ -955,19 +916,22 @@ Set and get binding filter |
955 | 916 |
return $value; |
956 | 917 |
}); |
957 | 918 |
|
919 |
+Bind filter arguemts is |
|
920 |
+ |
|
921 |
+ 1. $value : Value |
|
922 |
+ 2. $key : Key |
|
923 |
+ 3. $dbi : DBIx::Custom object |
|
924 |
+ 4. $infos : {table => $table, column => $column} |
|
925 |
+ |
|
958 | 926 |
=head2 fetch_filter |
959 | 927 |
|
960 | 928 |
Set and get Fetch filter |
961 | 929 |
|
962 |
- # For object |
|
963 |
- $self = $self->fetch_filter($fetch_filter); |
|
964 |
- $fetch_filter = $self->fetch_filter; |
|
930 |
+ $dbi = $dbi->fetch_filter($fetch_filter); |
|
931 |
+ $fetch_filter = $dbi->fetch_filter; |
|
965 | 932 |
|
966 |
- # For class |
|
967 |
- $class = $class->fetch_filter($fetch_filter); |
|
968 |
- $fetch_filter = $class->fetch_filter; |
|
933 |
+The following is fetch filter sample |
|
969 | 934 |
|
970 |
- # Sample |
|
971 | 935 |
$dbi->fetch_filter(sub { |
972 | 936 |
my ($value, $key, $dbi, $infos) = @_; |
973 | 937 |
|
... | ... |
@@ -976,74 +940,73 @@ Set and get Fetch filter |
976 | 940 |
return $value; |
977 | 941 |
}); |
978 | 942 |
|
943 |
+Bind filter arguemts is |
|
944 |
+ |
|
945 |
+ 1. $value : Value |
|
946 |
+ 2. $key : Key |
|
947 |
+ 3. $dbi : DBIx::Custom object |
|
948 |
+ 4. $infos : {type => $table, sth => $sth, index => $index} |
|
949 |
+ |
|
979 | 950 |
=head2 no_bind_filters |
980 | 951 |
|
981 | 952 |
Set and get no filter keys when binding |
982 | 953 |
|
983 |
- # For object |
|
984 |
- $self = $self->no_bind_filters($no_bind_filters); |
|
985 |
- $no_bind_filters = $self->no_bind_filters; |
|
986 |
- |
|
987 |
- # For class |
|
988 |
- $class = $class->no_bind_filters($no_bind_filters); |
|
989 |
- $no_bind_filters = $class->no_bind_filters; |
|
990 |
- |
|
991 |
- # Sample |
|
992 |
- $dbi->no_bind_filters(qw/title author/); |
|
954 |
+ $dbi = $dbi->no_bind_filters(qw/title author/); |
|
955 |
+ $no_bind_filters = $dbi->no_bind_filters; |
|
993 | 956 |
|
994 | 957 |
=head2 no_fetch_filters |
995 | 958 |
|
996 | 959 |
Set and get no filter keys when fetching |
997 | 960 |
|
998 |
- # For object |
|
999 |
- $self = $self->no_fetch_filters($no_fetch_filters); |
|
1000 |
- $no_fetch_filters = $self->no_fetch_filters; |
|
1001 |
- |
|
1002 |
- # For class |
|
1003 |
- $class = $class->no_fetch_filters($no_fetch_filters); |
|
1004 |
- $no_fetch_filters = $class->no_fetch_filters; |
|
1005 |
- |
|
1006 |
- # Sample |
|
1007 |
- $dbi->no_fetch_filters(qw/title author/); |
|
961 |
+ $dbi = $dbi->no_fetch_filters(qw/title author/); |
|
962 |
+ $no_fetch_filters = $dbi->no_fetch_filters; |
|
1008 | 963 |
|
1009 | 964 |
=head2 result_class |
1010 | 965 |
|
1011 | 966 |
Set and get resultset class |
1012 | 967 |
|
1013 |
- # For object |
|
1014 |
- $self = $dbi->result_class($result_class); |
|
968 |
+ $dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
1015 | 969 |
$result_class = $dbi->result_class; |
1016 |
- |
|
1017 |
- # For class |
|
1018 |
- $class = $class->result_class($result_class); |
|
1019 |
- $result_class = $class->result_class; |
|
1020 |
- |
|
1021 |
- # Sample |
|
1022 |
- $dbi->result_class('DBIx::Custom::Result'); |
|
1023 | 970 |
|
1024 | 971 |
=head2 dbh |
1025 | 972 |
|
1026 | 973 |
Get database handle |
1027 | 974 |
|
1028 |
- $self = $self->dbh($dbh); |
|
1029 |
- $dbh = $self->dbh; |
|
1030 |
- |
|
1031 |
- # Sample |
|
1032 |
- $table_info = $dbi->dbh->table_info |
|
975 |
+ $dbi = $dbi->dbh($dbh); |
|
976 |
+ $dbh = $dbi->dbh; |
|
1033 | 977 |
|
1034 | 978 |
=head2 query_cache_max |
1035 | 979 |
|
1036 | 980 |
Set and get query cache max |
1037 | 981 |
|
1038 |
- $class = $class->query_cache_max($query_cache_max); |
|
1039 |
- $query_cache_max = $class->query_cache_max; |
|
1040 |
- |
|
1041 |
- # Sample |
|
1042 |
- DBIx::Custom->query_cache_max(50); |
|
982 |
+ $class = DBIx::Custom->query_cache_max(50); |
|
983 |
+ $query_cache_max = DBIx::Custom->query_cache_max; |
|
984 |
+ |
|
985 |
+Default value is 50 |
|
986 |
+ |
|
987 |
+=head2 Accessor summary |
|
988 |
+ |
|
989 |
+ Accessor type Variable type |
|
990 |
+ user class and object scalar(string) |
|
991 |
+ password class and object scalar(string) |
|
992 |
+ data_source class and object scalar(string) |
|
993 |
+ database class and object scalar(string) |
|
994 |
+ host class and object scalar(string) |
|
995 |
+ |
|
996 |
+ port class and object scalar(int) |
|
997 |
+ options class and object hash(string) |
|
998 |
+ sql_tmpl class and object scalar(DBIx::Custom::SQL::Template) |
|
999 |
+ filters class and object hash(code ref) |
|
1000 |
+ formats class and object hash(string) |
|
1043 | 1001 |
|
1044 |
-DBIx::Custom cache queries for performance. |
|
1002 |
+ bind_filter class and object scalar(code ref) |
|
1003 |
+ fetch_filter class and object scalar(code ref) |
|
1004 |
+ no_bind_filters class and object array(string) |
|
1005 |
+ no_fetch_filters class and object array(string) |
|
1006 |
+ result_class class and object scalar(string) |
|
1045 | 1007 |
|
1046 |
-Default is 50 |
|
1008 |
+ dbh object scalar(DBI) |
|
1009 |
+ query_cache_max class scalar(int) |
|
1047 | 1010 |
|
1048 | 1011 |
=head1 Methods |
1049 | 1012 |
|
... | ... |
@@ -1051,52 +1014,35 @@ Default is 50 |
1051 | 1014 |
|
1052 | 1015 |
Connect to database |
1053 | 1016 |
|
1054 |
- $self = $dbi->connect; |
|
1055 |
- |
|
1056 |
- # Sample |
|
1057 |
- $dbi = DBIx::Custom->new(user => 'taro', password => 'lji8(', |
|
1058 |
- data_soruce => "dbi:mysql:dbname=$database"); |
|
1059 | 1017 |
$dbi->connect; |
1060 | 1018 |
|
1061 | 1019 |
=head2 disconnect |
1062 | 1020 |
|
1063 | 1021 |
Disconnect database |
1064 | 1022 |
|
1065 |
- $self = $dbi->disconnect; |
|
1066 |
- |
|
1067 |
- # Sample |
|
1068 | 1023 |
$dbi->disconnect; |
1069 | 1024 |
|
1070 |
-If database is already disconnected, this method do noting. |
|
1025 |
+If database is already disconnected, this method do nothing. |
|
1071 | 1026 |
|
1072 | 1027 |
=head2 reconnect |
1073 | 1028 |
|
1074 | 1029 |
Reconnect to database |
1075 | 1030 |
|
1076 |
- $self = $dbi->reconnect; |
|
1077 |
- |
|
1078 |
- # Sample |
|
1079 | 1031 |
$dbi->reconnect; |
1080 | 1032 |
|
1081 | 1033 |
=head2 connected |
1082 | 1034 |
|
1083 |
-Check connected |
|
1035 |
+Check if database is connected. |
|
1084 | 1036 |
|
1085 |
- $is_connected = $self->connected; |
|
1086 |
- |
|
1087 |
- # Sample |
|
1088 |
- if ($dbi->connected) { # do something } |
|
1037 |
+ $is_connected = $dbi->connected; |
|
1089 | 1038 |
|
1090 | 1039 |
=head2 filter_off |
1091 | 1040 |
|
1092 | 1041 |
bind_filter and fitch_filter off |
1093 | 1042 |
|
1094 |
- $self = $self->filter_off |
|
1095 |
- |
|
1096 |
- # Sample |
|
1097 |
- $dbi->filter_off; |
|
1043 |
+ $dbi->filter_off |
|
1098 | 1044 |
|
1099 |
-This is equeal to |
|
1045 |
+This method is equeal to |
|
1100 | 1046 |
|
1101 | 1047 |
$dbi->bind_filter(undef); |
1102 | 1048 |
$dbi->fetch_filter(undef); |
... | ... |
@@ -1105,11 +1051,10 @@ This is equeal to |
1105 | 1051 |
|
1106 | 1052 |
Resist filter |
1107 | 1053 |
|
1108 |
- $self = $self->add_filter({$name => $filter, ...}); |
|
1109 |
- # or |
|
1110 |
- $self = $self->add_filter($name => $filter, ...); |
|
1054 |
+ $dbi->add_filter($fname1 => $filter1, $fname => $filter2); |
|
1111 | 1055 |
|
1112 |
- # Sample (For example DBIx::Custom::Basic) |
|
1056 |
+The following is add_filter sample |
|
1057 |
+ |
|
1113 | 1058 |
$dbi->add_filter( |
1114 | 1059 |
encode_utf8 => sub { |
1115 | 1060 |
my ($value, $key, $dbi, $infos) = @_; |
... | ... |
@@ -1124,52 +1069,34 @@ Resist filter |
1124 | 1069 |
|
1125 | 1070 |
=head2 add_format |
1126 | 1071 |
|
1127 |
-Resist format |
|
1072 |
+Add format |
|
1128 | 1073 |
|
1129 |
- $self = $self->add_format({$name => $format, ...}); |
|
1130 |
- # or |
|
1131 |
- $self = $self->add_format($name => $format, ...); |
|
1074 |
+ $dbi->add_format($fname1 => $format, $fname2 => $format2); |
|
1132 | 1075 |
|
1133 |
- # Sample |
|
1134 |
- $dbi->add_format(date => '%Y:%m:%d', datetime => '%Y-%m-%d %H:%M:%S'); |
|
1135 |
- |
|
1136 |
-=head2 prepare |
|
1076 |
+The following is add_format sample. |
|
1137 | 1077 |
|
1138 |
-Prepare statement handle |
|
1078 |
+ $dbi->add_format(date => '%Y:%m:%d', datetime => '%Y-%m-%d %H:%M:%S'); |
|
1139 | 1079 |
|
1140 |
- $sth = $self->prepare($sql); |
|
1080 |
+=head2 create_query |
|
1141 | 1081 |
|
1142 |
- # Sample |
|
1143 |
- $sth = $dbi->prepare('select * from books;'); |
|
1082 |
+Create Query object parsing SQL template |
|
1144 | 1083 |
|
1145 |
-This method is same as DBI prepare method. |
|
1084 |
+ my $query = $dbi->create_query("select * from authors where {= name} and {= age}"); |
|
1146 | 1085 |
|
1147 |
-=head2 do |
|
1086 |
+$query is <DBIx::Query> object. This is executed by query method as the following |
|
1148 | 1087 |
|
1149 |
-Execute SQL |
|
1088 |
+ $dbi->query($query, $params); |
|
1150 | 1089 |
|
1151 |
- $ret_val = $self->do($sql, @bind_values); |
|
1152 |
- |
|
1153 |
- # Sample |
|
1154 |
- $ret_val = $dbi->do('insert into books (title, author) values (?, ?)', |
|
1155 |
- 'Perl', 'taro'); |
|
1090 |
+If you know SQL template, see also L<DBIx::Custom::SQL::Template>. |
|
1156 | 1091 |
|
1157 |
-This method is same as DBI do method. |
|
1092 |
+=head2 query |
|
1158 | 1093 |
|
1159 |
-=head2 create_query |
|
1160 |
- |
|
1161 |
-Create Query object from SQL template |
|
1094 |
+Query |
|
1162 | 1095 |
|
1163 |
- my $query = $dbi->create_query($template); |
|
1164 |
- |
|
1165 |
-=head2 execute |
|
1096 |
+ $result = $dbi->query($template, $params); |
|
1166 | 1097 |
|
1167 |
-Parse SQL template and execute SQL |
|
1098 |
+The following is query sample |
|
1168 | 1099 |
|
1169 |
- $result = $dbi->query($query, $params); |
|
1170 |
- $result = $dbi->query($template, $params); # Shortcut |
|
1171 |
- |
|
1172 |
- # Sample |
|
1173 | 1100 |
$result = $dbi->query("select * from authors where {= name} and {= age}", |
1174 | 1101 |
{author => 'taro', age => 19}); |
1175 | 1102 |
|
... | ... |
@@ -1177,7 +1104,11 @@ Parse SQL template and execute SQL |
1177 | 1104 |
# do something |
1178 | 1105 |
} |
1179 | 1106 |
|
1180 |
-See also L<DBIx::Custom::SQL::Template> |
|
1107 |
+If you now syntax of template, See also L<DBIx::Custom::SQL::Template> |
|
1108 |
+ |
|
1109 |
+Return value of query method is L<DBIx::Custom::Result> object |
|
1110 |
+ |
|
1111 |
+See also L<DBIx::Custom::Result>. |
|
1181 | 1112 |
|
1182 | 1113 |
=head2 run_transaction |
1183 | 1114 |
|
... | ... |
@@ -1192,74 +1123,113 @@ Run transaction |
1192 | 1123 |
If transaction is success, commit is execute. |
1193 | 1124 |
If tranzation is died, rollback is execute. |
1194 | 1125 |
|
1126 |
+=head2 create_table |
|
1127 |
+ |
|
1128 |
+Create table |
|
1129 |
+ |
|
1130 |
+ $dbi->create_table( |
|
1131 |
+ 'books', |
|
1132 |
+ 'name char(255)', |
|
1133 |
+ 'age int' |
|
1134 |
+ ); |
|
1135 |
+ |
|
1136 |
+First argument is table name. Rest arguments is column definition. |
|
1137 |
+ |
|
1138 |
+=head2 drop_table |
|
1139 |
+ |
|
1140 |
+Drop table |
|
1141 |
+ |
|
1142 |
+ $dbi->drop_table('books'); |
|
1143 |
+ |
|
1195 | 1144 |
=head2 insert |
1196 | 1145 |
|
1197 | 1146 |
Insert row |
1198 | 1147 |
|
1199 |
- $ret_val = $self->insert($table, \%$insert_params); |
|
1148 |
+ $affected = $dbi->insert($table, \%$insert_params); |
|
1149 |
+ $affected = $dbi->insert($table, \%$insert_params, $append); |
|
1200 | 1150 |
|
1201 |
-$ret_val is maybe affected rows count |
|
1151 |
+Retrun value is affected rows count |
|
1202 | 1152 |
|
1203 |
- # Sample |
|
1153 |
+The following is insert sample. |
|
1154 |
+ |
|
1204 | 1155 |
$dbi->insert('books', {title => 'Perl', author => 'Taro'}); |
1205 | 1156 |
|
1157 |
+You can add statement. |
|
1158 |
+ |
|
1159 |
+ $dbi->insert('books', {title => 'Perl', author => 'Taro'}, "some statement"); |
|
1160 |
+ |
|
1206 | 1161 |
=head2 update |
1207 | 1162 |
|
1208 | 1163 |
Update rows |
1209 | 1164 |
|
1210 |
- $self = $self->update($table, \%update_params, \%where); |
|
1165 |
+ $affected = $dbi->update($table, \%update_params, \%where); |
|
1166 |
+ $affected = $dbi->update($table, \%update_params, \%where, $append); |
|
1167 |
+ |
|
1168 |
+Retrun value is affected rows count |
|
1211 | 1169 |
|
1212 |
-$ret_val is maybe affected rows count |
|
1170 |
+The following is update sample. |
|
1213 | 1171 |
|
1214 |
- # Sample |
|
1215 | 1172 |
$dbi->update('books', {title => 'Perl', author => 'Taro'}, {id => 5}); |
1216 | 1173 |
|
1174 |
+You can add statement. |
|
1175 |
+ |
|
1176 |
+ $dbi->update('books', {title => 'Perl', author => 'Taro'}, |
|
1177 |
+ {id => 5}, "some statement"); |
|
1178 |
+ |
|
1217 | 1179 |
=head2 update_all |
1218 | 1180 |
|
1219 | 1181 |
Update all rows |
1220 | 1182 |
|
1221 |
- $ret_val = $self->update_all($table, \%updat_params); |
|
1183 |
+ $affected = $dbi->update_all($table, \%updat_params); |
|
1222 | 1184 |
|
1223 |
-$ret_val is maybe affected rows count |
|
1185 |
+Retrun value is affected rows count |
|
1186 |
+ |
|
1187 |
+The following is update_all sample. |
|
1224 | 1188 |
|
1225 |
- # Sample |
|
1226 | 1189 |
$dbi->update_all('books', {author => 'taro'}); |
1227 | 1190 |
|
1228 | 1191 |
=head2 delete |
1229 | 1192 |
|
1230 | 1193 |
Delete rows |
1231 | 1194 |
|
1232 |
- $ret_val = $self->delete($table, \%where); |
|
1195 |
+ $affected = $dbi->delete($table, \%where); |
|
1196 |
+ $affected = $dbi->delete($table, \%where, $append); |
|
1233 | 1197 |
|
1234 |
-$ret_val is maybe affected rows count |
|
1198 |
+Retrun value is affected rows count |
|
1235 | 1199 |
|
1236 |
- # Sample |
|
1200 |
+The following is delete sample. |
|
1201 |
+ |
|
1237 | 1202 |
$dbi->delete('books', {id => 5}); |
1238 | 1203 |
|
1204 |
+You can add statement. |
|
1205 |
+ |
|
1206 |
+ $dbi->delete('books', {id => 5}, "some statement"); |
|
1207 |
+ |
|
1239 | 1208 |
=head2 delete_all |
1240 | 1209 |
|
1241 | 1210 |
Delete all rows |
1242 | 1211 |
|
1243 |
- $ret_val = $self->delete_all($table); |
|
1212 |
+ $affected = $dbi->delete_all($table); |
|
1244 | 1213 |
|
1245 |
-$ret_val is maybe affected rows count |
|
1214 |
+Retrun value is affected rows count |
|
1246 | 1215 |
|
1247 |
- # Sample |
|
1248 |
- $dib->delete_all('books'); |
|
1216 |
+The following is delete_all sample. |
|
1217 |
+ |
|
1218 |
+ $dbi->delete_all('books'); |
|
1249 | 1219 |
|
1250 | 1220 |
=head2 select |
1251 | 1221 |
|
1252 | 1222 |
Select rows |
1253 | 1223 |
|
1254 |
- $resut = $self->select( |
|
1224 |
+ $resut = $dbi->select( |
|
1255 | 1225 |
$table, # must be string or array; |
1256 |
- \@$columns, # must be array reference. this is optional |
|
1257 |
- \%$where_params, # must be hash reference. this is optional |
|
1258 |
- $append_statement, # must be string. this is optional |
|
1259 |
- $query_edit_callback # must be code reference. this is optional |
|
1226 |
+ \@$columns, # must be array reference. this can be ommited |
|
1227 |
+ \%$where_params, # must be hash reference. this can be ommited |
|
1228 |
+ $append_statement, # must be string. this can be ommited |
|
1229 |
+ $query_edit_callback # must be code reference. this can be ommited |
|
1260 | 1230 |
); |
1261 | 1231 |
|
1262 |
-$reslt is L<DBI::Custom::Result> object |
|
1232 |
+$reslt is L<DBIx::Custom::Result> object |
|
1263 | 1233 |
|
1264 | 1234 |
The following is some select samples |
1265 | 1235 |
|
... | ... |
@@ -1308,7 +1278,30 @@ Get last insert id |
1308 | 1278 |
|
1309 | 1279 |
This method is implemented by subclass. |
1310 | 1280 |
|
1311 |
-=head1 Caution |
|
1281 |
+=head2 prepare |
|
1282 |
+ |
|
1283 |
+Prepare statement handle. |
|
1284 |
+ |
|
1285 |
+ $sth = $dbi->prepare('select * from books;'); |
|
1286 |
+ |
|
1287 |
+This method is same as DBI prepare method. |
|
1288 |
+ |
|
1289 |
+See also L<DBI>. |
|
1290 |
+ |
|
1291 |
+=head2 do |
|
1292 |
+ |
|
1293 |
+Execute SQL |
|
1294 |
+ |
|
1295 |
+ $affected = $dbi->do('insert into books (title, author) values (?, ?)', |
|
1296 |
+ 'Perl', 'taro'); |
|
1297 |
+ |
|
1298 |
+Retrun value is affected rows count. |
|
1299 |
+ |
|
1300 |
+This method is same as DBI do method. |
|
1301 |
+ |
|
1302 |
+See also L<DBI> |
|
1303 |
+ |
|
1304 |
+=head1 DBIx::Custom default configuration |
|
1312 | 1305 |
|
1313 | 1306 |
DBIx::Custom have DBI object. |
1314 | 1307 |
This module is work well in the following DBI condition. |
... | ... |
@@ -1323,12 +1316,27 @@ If you change these mode, |
1323 | 1316 |
you cannot get correct error message, |
1324 | 1317 |
or run_transaction may fail. |
1325 | 1318 |
|
1319 |
+=head1 Inheritance of DBIx::Custom |
|
1320 |
+ |
|
1321 |
+DBIx::Custom is customizable DBI. |
|
1322 |
+You can inherit DBIx::Custom and custumize attributes. |
|
1323 |
+ |
|
1324 |
+ package DBIx::Custom::Yours; |
|
1325 |
+ use base DBIx::Custom; |
|
1326 |
+ |
|
1327 |
+ my $class = __PACKAGE__; |
|
1328 |
+ |
|
1329 |
+ $class->user('your_name'); |
|
1330 |
+ $class->password('your_password'); |
|
1331 |
+ |
|
1326 | 1332 |
=head1 AUTHOR |
1327 | 1333 |
|
1328 | 1334 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
1329 | 1335 |
|
1330 | 1336 |
Github L<http://github.com/yuki-kimoto> |
1331 | 1337 |
|
1338 |
+I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1339 |
+ |
|
1332 | 1340 |
=head1 COPYRIGHT & LICENSE |
1333 | 1341 |
|
1334 | 1342 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
... | ... |
@@ -8,12 +8,7 @@ use Encode qw/decode encode/; |
8 | 8 |
my $class = __PACKAGE__; |
9 | 9 |
|
10 | 10 |
$class->add_filter( |
11 |
- encode_utf8 => sub { |
|
12 |
- my $value = shift; |
|
13 |
- return $value unless defined $value; |
|
14 |
- utf8::upgrade($value) unless Encode::is_utf8($value); |
|
15 |
- return encode('UTF-8', $value); |
|
16 |
- }, |
|
11 |
+ encode_utf8 => sub { encode('UTF-8', shift) }, |
|
17 | 12 |
decode_utf8 => sub { decode('UTF-8', shift) } |
18 | 13 |
); |
19 | 14 |
|
... | ... |
@@ -57,9 +52,6 @@ Please see L<DBIx::Custom> documentation |
57 | 52 |
|
58 | 53 |
Encode and decode utf8 filter on |
59 | 54 |
|
60 |
- $self = $self->utf8_filter_on; |
|
61 |
- |
|
62 |
- # Sample |
|
63 | 55 |
$dbi->utf8_filter_on; |
64 | 56 |
|
65 | 57 |
This equel to |
... | ... |
@@ -71,7 +63,9 @@ This equel to |
71 | 63 |
|
72 | 64 |
=head2 encode_utf8 |
73 | 65 |
|
74 |
- # Encode to UTF-8 byte stream (utf8::upgrade is done if need) |
|
66 |
+Encode internal string to UTF-8 byte stream |
|
67 |
+If need, utf8::upgrade is also done. |
|
68 |
+ |
|
75 | 69 |
$dbi->filters->{encode_utf8}->($value); |
76 | 70 |
|
77 | 71 |
This filter is generally used as bind filter |
... | ... |
@@ -80,7 +74,7 @@ This filter is generally used as bind filter |
80 | 74 |
|
81 | 75 |
=head2 decode_utf8 |
82 | 76 |
|
83 |
- # Decode to perl internal string |
|
77 |
+Decode UTF-8 byte stream to internal string |
|
84 | 78 |
$dbi->filters->{decode_utf8}->($value); |
85 | 79 |
|
86 | 80 |
This filter is generally used as fetch filter |
... | ... |
@@ -53,24 +53,9 @@ DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
53 | 53 |
|
54 | 54 |
# New |
55 | 55 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
56 |
- database => 'sample_db'); |
|
57 |
- # Insert |
|
58 |
- $dbi->insert('books', {title => 'perl', author => 'taro'}); |
|
59 |
- |
|
60 |
- # Update |
|
61 |
- # same as 'update books set title = 'aaa', author = 'ken' where id = 5; |
|
62 |
- $dbi->update('books', {title => 'aaa', author => 'ken'}, {id => 5}); |
|
63 |
- |
|
64 |
- # Delete |
|
65 |
- $dbi->delete('books', {author => 'taro'}); |
|
66 |
- |
|
67 |
- # select * from books; |
|
68 |
- $dbi->select('books'); |
|
69 |
- |
|
70 |
- # select * from books where ahthor = 'taro'; |
|
71 |
- $dbi->select('books', {author => 'taro'}); |
|
56 |
+ database => 'sample_db'); |
|
72 | 57 |
|
73 |
-=head1 See DBIx::Custom and DBI::Custom::Basic documentation at first |
|
58 |
+=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first |
|
74 | 59 |
|
75 | 60 |
This class is L<DBIx::Custom::Basic> subclass, |
76 | 61 |
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass. |
... | ... |
@@ -84,20 +69,18 @@ Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation. |
84 | 69 |
|
85 | 70 |
Connect to database |
86 | 71 |
|
87 |
- $self = $self->connect; |
|
88 |
- |
|
89 |
- # Sample |
|
90 |
- $dbi->connect; |
|
72 |
+ $self->connect; |
|
91 | 73 |
|
92 | 74 |
This override L<DBIx::Custom> connect. |
93 | 75 |
|
94 |
-If you set database, host, or port, data source is automatically created and connect |
|
76 |
+If you set database, host, or port, data source is automatically created. |
|
95 | 77 |
|
96 | 78 |
=head2 last_insert_id |
97 | 79 |
|
98 |
- $last_insert_id = $self->last_insert_id; |
|
99 |
- |
|
100 |
- # Sample |
|
80 |
+ $last_insert_id = $dbi->last_insert_id; |
|
81 |
+ |
|
82 |
+The folloing is last_insert_id sample. |
|
83 |
+ |
|
101 | 84 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
102 | 85 |
$last_insert_id = $dbi->last_insert_id; |
103 | 86 |
|
... | ... |
@@ -27,20 +27,19 @@ Object::Simple->build_class; |
27 | 27 |
DBIx::Custom::Query - DBIx::Custom query |
28 | 28 |
|
29 | 29 |
=head1 SYNOPSIS |
30 |
- |
|
31 |
- # Create query |
|
32 |
- my $dbi = DBIx::Custom->new; |
|
33 |
- my $query = $dbi->create_query($template); |
|
34 | 30 |
|
35 |
- # Set query attributes |
|
31 |
+ # New |
|
32 |
+ my $query = DBIx::Custom::Query->new; |
|
33 |
+ |
|
34 |
+ # Create by using create_query |
|
35 |
+ my $query = DBIx::Custom->create_query($template); |
|
36 |
+ |
|
37 |
+ # Set attributes |
|
36 | 38 |
$query->bind_filter($dbi->filters->{default_bind_filter}); |
37 | 39 |
$query->no_bind_filters('title', 'author'); |
38 | 40 |
|
39 | 41 |
$query->fetch_filter($dbi->filters->{default_fetch_filter}); |
40 | 42 |
$query->no_fetch_filters('title', 'author'); |
41 |
- |
|
42 |
- # Execute query |
|
43 |
- $dbi->execute($query, $params); |
|
44 | 43 |
|
45 | 44 |
=head1 Accessors |
46 | 45 |
|
... | ... |
@@ -48,50 +47,50 @@ DBIx::Custom::Query - DBIx::Custom query |
48 | 47 |
|
49 | 48 |
Set and get statement handle |
50 | 49 |
|
51 |
- $self = $self->sth($sql); |
|
52 |
- $sth = $self->sth; |
|
50 |
+ $query = $query->sth($sth); |
|
51 |
+ $sth = $query->sth; |
|
53 | 52 |
|
54 | 53 |
=head2 sql |
55 | 54 |
|
56 | 55 |
Set and get SQL |
57 | 56 |
|
58 |
- $self = $self->sql($sql); |
|
59 |
- $sql = $self->sql; |
|
57 |
+ $query = $query->sql($sql); |
|
58 |
+ $sql = $query->sql; |
|
60 | 59 |
|
61 | 60 |
=head2 bind_filter |
62 | 61 |
|
63 | 62 |
Set and get bind filter |
64 | 63 |
|
65 |
- $self = $self->bind_filter($bind_filter); |
|
66 |
- $bind_filter = $self->bind_filter; |
|
64 |
+ $query = $query->bind_filter($bind_filter); |
|
65 |
+ $bind_filter = $query->bind_filter; |
|
67 | 66 |
|
68 | 67 |
=head2 no_bind_filters |
69 | 68 |
|
70 | 69 |
Set and get keys of no filtering |
71 | 70 |
|
72 |
- $self = $self->no_bind_filters($no_filters); |
|
73 |
- $no_bind_filters = $self->no_bind_filters; |
|
71 |
+ $query = $query->no_bind_filters($no_filters); |
|
72 |
+ $no_bind_filters = $query->no_bind_filters; |
|
74 | 73 |
|
75 | 74 |
=head2 fetch_filter |
76 | 75 |
|
77 | 76 |
Set and get fetch filter |
78 | 77 |
|
79 |
- $self = $self->fetch_filter($fetch_filter); |
|
80 |
- $fetch_filter = $self->fetch_filter; |
|
78 |
+ $query = $query->fetch_filter($fetch_filter); |
|
79 |
+ $fetch_filter = $query->fetch_filter; |
|
81 | 80 |
|
82 | 81 |
=head2 no_fetch_filters |
83 | 82 |
|
84 | 83 |
Set and get keys of no filtering |
85 | 84 |
|
86 |
- $self = $self->no_fetch_filters($no_filters); |
|
87 |
- $no_fetch_filters = $self->no_fetch_filters; |
|
85 |
+ $query = $query->no_fetch_filters($no_filters); |
|
86 |
+ $no_fetch_filters = $query->no_fetch_filters; |
|
88 | 87 |
|
89 | 88 |
=head2 key_infos |
90 | 89 |
|
91 | 90 |
Set and get key informations |
92 | 91 |
|
93 |
- $self = $self->key_infos($key_infos); |
|
94 |
- $key_infos = $self->key_infos; |
|
92 |
+ $query = $query->key_infos($key_infos); |
|
93 |
+ $key_infos = $query->key_infos; |
|
95 | 94 |
|
96 | 95 |
=head1 AUTHOR |
97 | 96 |
|
... | ... |
@@ -201,12 +201,16 @@ DBIx::Custom::Result - DBIx::Custom Resultset |
201 | 201 |
|
202 | 202 |
=head1 Synopsis |
203 | 203 |
|
204 |
- # $result is DBIx::Custom::Result object |
|
205 |
- my $dbi = DBIx::Custom->new; |
|
206 |
- my $result = $dbi->query($sql_template, $param); |
|
204 |
+ my $result = $dbi->query($query); |
|
207 | 205 |
|
208 |
- while (my ($val1, $val2) = $result->fetch) { |
|
209 |
- # do something |
|
206 |
+ # Fetch |
|
207 |
+ while (my @row = $result->fetch) { |
|
208 |
+ # Do something |
|
209 |
+ } |
|
210 |
+ |
|
211 |
+ # Fetch hash |
|
212 |
+ while (my %row = $result->fetch_hash) { |
|
213 |
+ # Do something |
|
210 | 214 |
} |
211 | 215 |
|
212 | 216 |
=head1 Accessors |
... | ... |
@@ -215,24 +219,21 @@ DBIx::Custom::Result - DBIx::Custom Resultset |
215 | 219 |
|
216 | 220 |
Set and Get statement handle |
217 | 221 |
|
218 |
- $self = $result->sth($sth); |
|
219 |
- $sth = $reuslt->sth |
|
222 |
+ $result = $result->sth($sth); |
|
223 |
+ $sth = $reuslt->sth |
|
220 | 224 |
|
221 |
- # Sample |
|
222 |
- $dbi->sth->errstr |
|
223 |
- |
|
224 | 225 |
=head2 fetch_filter |
225 | 226 |
|
226 | 227 |
Set and Get fetch filter |
227 | 228 |
|
228 |
- $self = $result->fetch_filter($sth); |
|
229 |
- $fetch_filter = $result->fech_filter; |
|
229 |
+ $result = $result->fetch_filter($sth); |
|
230 |
+ $fetch_filter = $result->fech_filter; |
|
230 | 231 |
|
231 | 232 |
=head2 no_fetch_filters |
232 | 233 |
|
233 | 234 |
Set and Get no filter keys when fetching |
234 | 235 |
|
235 |
- $self = $result->no_fetch_filters($no_fetch_filters); |
|
236 |
+ $result = $result->no_fetch_filters($no_fetch_filters); |
|
236 | 237 |
$no_fetch_filters = $result->no_fetch_filters; |
237 | 238 |
|
238 | 239 |
=head1 Methods |
... | ... |
@@ -241,10 +242,11 @@ Set and Get no filter keys when fetching |
241 | 242 |
|
242 | 243 |
Fetch a row |
243 | 244 |
|
244 |
- $row = $self->fetch; # array reference |
|
245 |
- @row = $self->fecth; # array |
|
245 |
+ $row = $result->fetch; # array reference |
|
246 |
+ @row = $result->fecth; # array |
|
247 |
+ |
|
248 |
+The following is fetch sample |
|
246 | 249 |
|
247 |
- # Sample |
|
248 | 250 |
while (my $row = $result->fetch) { |
249 | 251 |
# do something |
250 | 252 |
my $val1 = $row->[0]; |
... | ... |
@@ -255,10 +257,11 @@ Fetch a row |
255 | 257 |
|
256 | 258 |
Fetch row as hash |
257 | 259 |
|
258 |
- $row = $self->fetch_hash; # hash reference |
|
259 |
- %row = $self->fetch_hash; # hash |
|
260 |
+ $row = $result->fetch_hash; # hash reference |
|
261 |
+ %row = $result->fetch_hash; # hash |
|
262 |
+ |
|
263 |
+The following is fetch_hash sample |
|
260 | 264 |
|
261 |
- # Sample |
|
262 | 265 |
while (my $row = $result->fetch_hash) { |
263 | 266 |
# do something |
264 | 267 |
my $val1 = $row->{key1}; |
... | ... |
@@ -269,10 +272,11 @@ Fetch row as hash |
269 | 272 |
|
270 | 273 |
Fetch only first row(Scalar context) |
271 | 274 |
|
272 |
- $row = $self->fetch_first; # array reference |
|
273 |
- @row = $self->fetch_first; # array |
|
275 |
+ $row = $result->fetch_first; # array reference |
|
276 |
+ @row = $result->fetch_first; # array |
|
274 | 277 |
|
275 |
- # Sample |
|
278 |
+The following is fetch_first sample |
|
279 |
+ |
|
276 | 280 |
$row = $result->fetch_first; |
277 | 281 |
|
278 | 282 |
This method fetch only first row and finish statement handle |
... | ... |
@@ -281,10 +285,11 @@ This method fetch only first row and finish statement handle |
281 | 285 |
|
282 | 286 |
Fetch only first row as hash |
283 | 287 |
|
284 |
- $row = $self->fetch_hash_first; # hash reference |
|
285 |
- %row = $self->fetch_hash_first; # hash |
|
288 |
+ $row = $result->fetch_hash_first; # hash reference |
|
289 |
+ %row = $result->fetch_hash_first; # hash |
|
286 | 290 |
|
287 |
- # Sample |
|
291 |
+The following is fetch_hash_first sample |
|
292 |
+ |
|
288 | 293 |
$row = $result->fetch_hash_first; |
289 | 294 |
|
290 | 295 |
This method fetch only first row and finish statement handle |
... | ... |
@@ -293,10 +298,11 @@ This method fetch only first row and finish statement handle |
293 | 298 |
|
294 | 299 |
Fetch rows |
295 | 300 |
|
296 |
- $rows = $self->fetch_rows($row_count); # array ref of array ref |
|
297 |
- @rows = $self->fetch_rows($row_count); # array of array ref |
|
301 |
+ $rows = $result->fetch_rows($row_count); # array ref of array ref |
|
302 |
+ @rows = $result->fetch_rows($row_count); # array of array ref |
|
298 | 303 |
|
299 |
- # Sample |
|
304 |
+The following is fetch_rows sample |
|
305 |
+ |
|
300 | 306 |
while(my $rows = $result->fetch_rows(10)) { |
301 | 307 |
# do someting |
302 | 308 |
} |
... | ... |
@@ -305,10 +311,11 @@ Fetch rows |
305 | 311 |
|
306 | 312 |
Fetch rows as hash |
307 | 313 |
|
308 |
- $rows = $self->fetch_hash_rows($row_count); # array ref of hash ref |
|
309 |
- @rows = $self->fetch_hash_rows($row_count); # array of hash ref |
|
314 |
+ $rows = $result->fetch_hash_rows($row_count); # array ref of hash ref |
|
315 |
+ @rows = $result->fetch_hash_rows($row_count); # array of hash ref |
|
310 | 316 |
|
311 |
- # Sample |
|
317 |
+The following is fetch_hash_rows sample |
|
318 |
+ |
|
312 | 319 |
while(my $rows = $result->fetch_hash_rows(10)) { |
313 | 320 |
# do someting |
314 | 321 |
} |
... | ... |
@@ -317,31 +324,31 @@ Fetch rows as hash |
317 | 324 |
|
318 | 325 |
Fetch all rows |
319 | 326 |
|
320 |
- $rows = $self->fetch_all; # array ref of array ref |
|
321 |
- @rows = $self->fecth_all; # array of array ref |
|
327 |
+ $rows = $result->fetch_all; # array ref of array ref |
|
328 |
+ @rows = $result->fecth_all; # array of array ref |
|
329 |
+ |
|
330 |
+The following is fetch_all sample |
|
322 | 331 |
|
323 |
- # Sample |
|
324 | 332 |
my $rows = $result->fetch_all; |
325 | 333 |
|
326 | 334 |
=head2 fetch_hash_all |
327 | 335 |
|
328 | 336 |
Fetch all row as array ref of hash ref (Scalar context) |
329 | 337 |
|
330 |
- $rows = $self->fetch_hash_all; # array ref of hash ref |
|
331 |
- @rows = $self->fecth_all_hash; # array of hash ref |
|
338 |
+ $rows = $result->fetch_hash_all; # array ref of hash ref |
|
339 |
+ @rows = $result->fecth_all_hash; # array of hash ref |
|
340 |
+ |
|
341 |
+The following is fetch_hash_all sample |
|
332 | 342 |
|
333 |
- # Sample |
|
334 | 343 |
my $rows = $result->fetch_hash_all; |
335 | 344 |
|
336 | 345 |
=head2 error |
337 | 346 |
|
338 | 347 |
Get error infomation |
339 | 348 |
|
340 |
- $error_messege = $self->error; |
|
341 |
- ($error_message, $error_number, $error_state) = $self->error; |
|
349 |
+ $error_messege = $result->error; |
|
350 |
+ ($error_message, $error_number, $error_state) = $result->error; |
|
342 | 351 |
|
343 |
- # Sample |
|
344 |
- $error = $result->error; |
|
345 | 352 |
|
346 | 353 |
You can get get information. This is same as the following. |
347 | 354 |
|
... | ... |
@@ -353,10 +360,6 @@ You can get get information. This is same as the following. |
353 | 360 |
|
354 | 361 |
Finish statement handle |
355 | 362 |
|
356 |
- $ret_val = $self->finish |
|
357 |
- |
|
358 |
- # Sample |
|
359 |
- my $row = $reuslt->fetch; # fetch a row |
|
360 | 363 |
$result->finish |
361 | 364 |
|
362 | 365 |
This is equel to |
... | ... |
@@ -486,19 +486,6 @@ DBIx::Custom::SQL::Template - DBIx::Custom SQL Template |
486 | 486 |
my $param = {k1 => 1, k2 => 2, k3 => 3}; |
487 | 487 |
|
488 | 488 |
my $query = $sql_template->create_query($tmpl); |
489 |
- |
|
490 |
- |
|
491 |
- # Using query from DBIx::Custom |
|
492 |
- use DBIx::Custom; |
|
493 |
- my $dbi = DBI->new( |
|
494 |
- data_source => $data_source, |
|
495 |
- user => $user, |
|
496 |
- password => $password, |
|
497 |
- dbi_options => {PrintError => 0, RaiseError => 1} |
|
498 |
- ); |
|
499 |
- |
|
500 |
- $query = $dbi->create_query($tmpl); # This is SQL::Template create_query |
|
501 |
- $dbi->query($query, $param); |
|
502 | 489 |
|
503 | 490 |
=head1 Accessors |
504 | 491 |
|
... | ... |
@@ -506,65 +493,34 @@ DBIx::Custom::SQL::Template - DBIx::Custom SQL Template |
506 | 493 |
|
507 | 494 |
Set and get tag processors |
508 | 495 |
|
509 |
- # For object |
|
510 |
- $self = $self->tag_processors($tag_processors); |
|
511 |
- $tag_processors = $self->tag_processors; |
|
512 |
- |
|
513 |
- # For class |
|
514 |
- $class = $class->tag_processors($tag_processors); |
|
515 |
- $tag_processors = $class->tag_processors; |
|
516 |
- |
|
517 |
- # Sample |
|
518 |
- $placeholder_tag_processor = $sql_tmpl->tag_processor->{'?'}; |
|
496 |
+ $sql_tmpl = $sql_tmpl->tag_processors($name1 => $tag_processor1 |
|
497 |
+ $name2 => $tag_processor2); |
|
498 |
+ $tag_processors = $sql_tmpl->tag_processors; |
|
519 | 499 |
|
520 | 500 |
=head2 tag_start |
521 | 501 |
|
522 | 502 |
Set and get start tag |
523 | 503 |
|
524 |
- # For object |
|
525 |
- $self = $self->tag_start($tag_start); |
|
526 |
- $tag_start = $self->tag_start; |
|
527 |
- |
|
528 |
- # For class |
|
529 |
- $class = $class->tag_start($tag_start); |
|
530 |
- $tag_start = $class->tag_start; |
|
531 |
- |
|
532 |
- # Sample |
|
533 |
- $sql_tmpl->tag_start('{'); |
|
504 |
+ $sql_tmpl = $sql_tmpl->tag_start('{'); |
|
505 |
+ $tag_start = $sql_tmpl->tag_start; |
|
534 | 506 |
|
535 |
-Default is '{' |
|
507 |
+tag_start default is '{' |
|
536 | 508 |
|
537 | 509 |
=head2 tag_end |
538 | 510 |
|
539 | 511 |
Set and get end tag |
540 | 512 |
|
541 |
- # For object |
|
542 |
- $self = $self->tag_start($tag_end); |
|
543 |
- $tag_end = $self->tag_start; |
|
544 |
- |
|
545 |
- # For class |
|
546 |
- $self = $self->tag_start($tag_end); |
|
547 |
- $tag_end = $self->tag_start; |
|
548 |
- |
|
549 |
- # Sample |
|
550 |
- $sql_tmpl->tag_start('}'); |
|
513 |
+ $sql_tmpl = $sql_tmpl->tag_start('}'); |
|
514 |
+ $tag_end = $sql_tmpl->tag_start; |
|
551 | 515 |
|
552 |
-Default is '}' |
|
516 |
+tag_start default is '}' |
|
553 | 517 |
|
554 | 518 |
=head2 tag_syntax |
555 | 519 |
|
556 | 520 |
Set and get tag syntax |
557 | 521 |
|
558 |
- # For object |
|
559 |
- $self = $self->tag_syntax($tag_syntax); |
|
560 |
- $tag_syntax = $self->tag_syntax; |
|
561 |
- |
|
562 |
- # For class |
|
563 |
- $class = $class->tag_syntax($tag_syntax); |
|
564 |
- $tag_syntax = $class->tag_syntax; |
|
565 |
- |
|
566 |
- # Sample |
|
567 |
- $syntax = $sql_tmpl->tag_syntax; |
|
522 |
+ $sql_tmpl = $sql_tmpl->tag_syntax($tag_syntax); |
|
523 |
+ $tag_syntax = $sql_tmpl->tag_syntax; |
|
568 | 524 |
|
569 | 525 |
=head1 Methods |
570 | 526 |
|
... | ... |
@@ -572,7 +528,7 @@ Set and get tag syntax |
572 | 528 |
|
573 | 529 |
Create L<DBIx::Custom::Query> object parsing SQL template |
574 | 530 |
|
575 |
- $query = $self->create_query($tmpl); |
|
531 |
+ $query = $sql_tmpl->create_query($tmpl); |
|
576 | 532 |
|
577 | 533 |
# Sample |
578 | 534 |
$query = $sql_tmpl->create_sql( |
... | ... |
@@ -603,13 +559,10 @@ query has two infomation |
603 | 559 |
|
604 | 560 |
Add tag processor |
605 | 561 |
|
606 |
- # For object |
|
607 |
- $self = $self->add_tag_processor($tag_processor); |
|
608 |
- |
|
609 |
- # For class |
|
610 |
- $class = $class->add_tag_processor($tag_processor); |
|
611 |
- |
|
612 |
- # Sample |
|
562 |
+ $sql_tmpl = $sql_tmpl->add_tag_processor($tag_processor); |
|
563 |
+ |
|
564 |
+The following is add_tag_processor sample |
|
565 |
+ |
|
613 | 566 |
$sql_tmpl->add_tag_processor( |
614 | 567 |
'?' => sub { |
615 | 568 |
my ($tag_name, $tag_args) = @_; |
... | ... |
@@ -646,7 +599,7 @@ If you want to know more, Please see DBIx::Custom::SQL::Template source code. |
646 | 599 |
|
647 | 600 |
Clone DBIx::Custom::SQL::Template object |
648 | 601 |
|
649 |
- $clone = $self->clone; |
|
602 |
+ $clone = $sql_tmpl->clone; |
|
650 | 603 |
|
651 | 604 |
=head1 Available Tags |
652 | 605 |
|
... | ... |
@@ -668,15 +621,18 @@ Available Tags |
668 | 621 |
{insert} (key1, key2, key3) values (?, ?, ?) |
669 | 622 |
{update} set key1 = ?, key2 = ?, key3 = ? |
670 | 623 |
|
671 |
- # Sample |
|
624 |
+ |
|
625 |
+The following is insert SQL sample |
|
626 |
+ |
|
672 | 627 |
$query = $sql_tmpl->create_sql( |
673 | 628 |
"insert into table {insert key1 key2}" |
674 | 629 |
); |
630 |
+ |
|
675 | 631 |
# Expanded |
676 | 632 |
$query->sql : "insert into table (key1, key2) values (?, ?)" |
633 |
+ |
|
634 |
+The following is update SQL sample |
|
677 | 635 |
|
678 |
- |
|
679 |
- # Sample |
|
680 | 636 |
$query = $sql_tmpl->create_sql( |
681 | 637 |
"update table {update key1 key2} where {= key3}" |
682 | 638 |
); |
... | ... |
@@ -72,30 +72,10 @@ DBIx::Custom::SQLite - DBIx::Custom SQLite implementation |
72 | 72 |
my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@K', |
73 | 73 |
database => 'sample'); |
74 | 74 |
|
75 |
- # Insert |
|
76 |
- $dbi->insert('books', {title => 'perl', author => 'taro'}); |
|
75 |
+ # Connect memory database |
|
76 |
+ my $dbi->connect_memory; |
|
77 | 77 |
|
78 |
- # Update |
|
79 |
- # same as 'update books set title = 'aaa', author = 'ken' where id = 5; |
|
80 |
- $dbi->update('books', {title => 'aaa', author => 'ken'}, {id => 5}); |
|
81 |
- |
|
82 |
- # Delete |
|
83 |
- $dbi->delete('books', {author => 'taro'}); |
|
84 |
- |
|
85 |
- # select * from books; |
|
86 |
- $dbi->select('books'); |
|
87 |
- |
|
88 |
- # select * from books where ahthor = 'taro'; |
|
89 |
- $dbi->select('books', {author => 'taro'}); |
|
90 |
- |
|
91 |
- # select author, title from books where author = 'taro' |
|
92 |
- $dbi->select('books', [qw/author title/], {author => 'taro'}); |
|
93 |
- |
|
94 |
- # select author, title from books where author = 'taro' order by id limit 1; |
|
95 |
- $dbi->select('books', [qw/author title/], {author => 'taro'}, |
|
96 |
- 'order by id limit 1'); |
|
97 |
- |
|
98 |
-=head1 See DBIx::Custom and DBI::Custom::Basic documentation at first |
|
78 |
+=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first |
|
99 | 79 |
|
100 | 80 |
This class is L<DBIx::Custom::Basic> subclass. |
101 | 81 |
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass |
... | ... |
@@ -103,46 +83,36 @@ and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass |
103 | 83 |
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom> |
104 | 84 |
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation |
105 | 85 |
|
106 |
-=head1 methods |
|
86 |
+=head1 Methods |
|
107 | 87 |
|
108 | 88 |
=head2 connect |
109 | 89 |
|
110 | 90 |
Connect to database |
111 | 91 |
|
112 |
- $self = $self->connect; |
|
113 |
- |
|
114 |
- # Sample |
|
115 | 92 |
$dbi->connect; |
116 | 93 |
|
117 |
-This override L<DBIx::Custom> connect. |
|
118 |
- |
|
119 |
-If you set database, data source is automatically created and connect |
|
94 |
+If you set database, host, or port, data source is automatically created. |
|
120 | 95 |
|
121 | 96 |
=head2 connect_memory |
122 | 97 |
|
123 | 98 |
Connect memory database |
124 | 99 |
|
125 |
- $self = $self->connect_memory; |
|
126 |
- |
|
127 |
- # Sample |
|
128 | 100 |
$dbi->connect_memory; |
129 | 101 |
|
130 | 102 |
=head2 reconnect_memory |
131 | 103 |
|
132 | 104 |
Reconnect to memory databsse |
133 | 105 |
|
134 |
- $self = $self->reconnect_memory; |
|
135 |
- |
|
136 |
- # Sample |
|
137 |
- $self = $dbi->reconnect_memory; |
|
106 |
+ $dbi->reconnect_memory; |
|
138 | 107 |
|
139 | 108 |
=head2 last_insert_id |
140 | 109 |
|
141 | 110 |
Get last insert id |
142 | 111 |
|
143 |
- $last_insert_id = $self->last_insert_id; |
|
112 |
+ $last_insert_id = $dbi->last_insert_id; |
|
144 | 113 |
|
145 |
- # Sample |
|
114 |
+The folloing is last_insert_id sample. |
|
115 |
+ |
|
146 | 116 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
147 | 117 |
$last_insert_id = $dbi->last_insert_id; |
148 | 118 |
|
... | ... |
@@ -88,6 +88,23 @@ ok(defined $ret_val, "$test : auto connect"); |
88 | 88 |
$ret_val = $dbi->do($DROP_TABLE->{0}); |
89 | 89 |
ok(defined $ret_val, "$test : basic"); |
90 | 90 |
|
91 |
+test 'create_table'; |
|
92 |
+$dbi = DBIx::Custom->new($NEW_ARGS->{0}); |
|
93 |
+$ret_val = $dbi->create_table( |
|
94 |
+ 'table1', |
|
95 |
+ 'key1 char(255)', |
|
96 |
+ 'key2 char(255)' |
|
97 |
+ ); |
|
98 |
+ok(defined $ret_val, "$test : create_table"); |
|
99 |
+ |
|
100 |
+eval{$dbi->insert('table1', {key1 => 1, key2 => 2})}; |
|
101 |
+ok(!$@, "$test : table exist"); |
|
102 |
+ |
|
103 |
+$ret_val = $dbi->drop_table('table1'); |
|
104 |
+ok(defined $ret_val, "$test : drop table"); |
|
105 |
+ |
|
106 |
+eval{$dbi->select('table1')}; |
|
107 |
+ok($@, "$test : table not exist"); |
|
91 | 108 |
|
92 | 109 |
# Prepare table |
93 | 110 |
$dbi = DBIx::Custom->new($NEW_ARGS->{0}); |
... | ... |
@@ -101,7 +118,7 @@ $sth->execute(3, 4); |
101 | 118 |
test 'DBIx::Custom::Result test'; |
102 | 119 |
$tmpl = "select key1, key2 from table1"; |
103 | 120 |
$query = $dbi->create_query($tmpl); |
104 |
-$result = $dbi->execute($query); |
|
121 |
+$result = $dbi->query($query); |
|
105 | 122 |
|
106 | 123 |
@rows = (); |
107 | 124 |
while (my $row = $result->fetch) { |
... | ... |
@@ -109,40 +126,40 @@ while (my $row = $result->fetch) { |
109 | 126 |
} |
110 | 127 |
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch scalar context"); |
111 | 128 |
|
112 |
-$result = $dbi->execute($query); |
|
129 |
+$result = $dbi->query($query); |
|
113 | 130 |
@rows = (); |
114 | 131 |
while (my @row = $result->fetch) { |
115 | 132 |
push @rows, [@row]; |
116 | 133 |
} |
117 | 134 |
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch list context"); |
118 | 135 |
|
119 |
-$result = $dbi->execute($query); |
|
136 |
+$result = $dbi->query($query); |
|
120 | 137 |
@rows = (); |
121 | 138 |
while (my $row = $result->fetch_hash) { |
122 | 139 |
push @rows, {%$row}; |
123 | 140 |
} |
124 | 141 |
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash scalar context"); |
125 | 142 |
|
126 |
-$result = $dbi->execute($query); |
|
143 |
+$result = $dbi->query($query); |
|
127 | 144 |
@rows = (); |
128 | 145 |
while (my %row = $result->fetch_hash) { |
129 | 146 |
push @rows, {%row}; |
130 | 147 |
} |
131 | 148 |
is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch hash list context"); |
132 | 149 |
|
133 |
-$result = $dbi->execute($query); |
|
150 |
+$result = $dbi->query($query); |
|
134 | 151 |
$rows = $result->fetch_all; |
135 | 152 |
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context"); |
136 | 153 |
|
137 |
-$result = $dbi->execute($query); |
|
154 |
+$result = $dbi->query($query); |
|
138 | 155 |
@rows = $result->fetch_all; |
139 | 156 |
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all list context"); |
140 | 157 |
|
141 |
-$result = $dbi->execute($query); |
|
158 |
+$result = $dbi->query($query); |
|
142 | 159 |
@rows = $result->fetch_hash_all; |
143 | 160 |
is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_hash_all scalar context"); |
144 | 161 |
|
145 |
-$result = $dbi->execute($query); |
|
162 |
+$result = $dbi->query($query); |
|
146 | 163 |
@rows = $result->fetch_all; |
147 | 164 |
is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_hash_all list context"); |
148 | 165 |
|
... | ... |
@@ -152,15 +169,15 @@ $dbi->do($DROP_TABLE->{0}); |
152 | 169 |
$dbi->do($CREATE_TABLE->{0}); |
153 | 170 |
$tmpl = "insert into table1 {insert key1 key2}"; |
154 | 171 |
$query = $dbi->create_query($tmpl); |
155 |
-$ret_val = $dbi->execute($query, {key1 => 1, key2 => 2}); |
|
172 |
+$ret_val = $dbi->query($query, {key1 => 1, key2 => 2}); |
|
156 | 173 |
ok($ret_val, $test); |
157 | 174 |
|
158 | 175 |
|
159 |
-test 'Direct execute'; |
|
176 |
+test 'Direct query'; |
|
160 | 177 |
$dbi->do($DROP_TABLE->{0}); |
161 | 178 |
$dbi->do($CREATE_TABLE->{0}); |
162 | 179 |
$insert_tmpl = "insert into table1 {insert key1 key2}"; |
163 |
-$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}, sub { |
|
180 |
+$dbi->query($insert_tmpl, {key1 => 1, key2 => 2}, sub { |
|
164 | 181 |
my $query = shift; |
165 | 182 |
$query->bind_filter(sub { |
166 | 183 |
my ($value, $key) = @_; |
... | ... |
@@ -170,7 +187,7 @@ $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}, sub { |
170 | 187 |
return $value; |
171 | 188 |
}); |
172 | 189 |
}); |
173 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
190 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
174 | 191 |
$rows = $result->fetch_hash_all; |
175 | 192 |
is_deeply($rows, [{key1 => 1, key2 => 3}], $test); |
176 | 193 |
|
... | ... |
@@ -192,7 +209,7 @@ $insert_query->bind_filter(sub { |
192 | 209 |
} |
193 | 210 |
return $value; |
194 | 211 |
}); |
195 |
-$dbi->execute($insert_query, {key1 => 1, key2 => 2}); |
|
212 |
+$dbi->query($insert_query, {key1 => 1, key2 => 2}); |
|
196 | 213 |
$select_query = $dbi->create_query($SELECT_TMPL->{0}); |
197 | 214 |
$select_query->fetch_filter(sub { |
198 | 215 |
my ($value, $key, $dbi, $infos) = @_; |
... | ... |
@@ -205,15 +222,15 @@ $select_query->fetch_filter(sub { |
205 | 222 |
} |
206 | 223 |
return $value; |
207 | 224 |
}); |
208 |
-$result = $dbi->execute($select_query); |
|
225 |
+$result = $dbi->query($select_query); |
|
209 | 226 |
$rows = $result->fetch_hash_all; |
210 | 227 |
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter"); |
211 | 228 |
|
212 | 229 |
$dbi->do("delete from table1;"); |
213 | 230 |
$insert_query->no_bind_filters('key1'); |
214 | 231 |
$select_query->no_fetch_filters('key2'); |
215 |
-$dbi->execute($insert_query, {key1 => 1, key2 => 2}); |
|
216 |
-$result = $dbi->execute($select_query); |
|
232 |
+$dbi->query($insert_query, {key1 => 1, key2 => 2}); |
|
233 |
+$result = $dbi->query($select_query); |
|
217 | 234 |
$rows = $result->fetch_hash_all; |
218 | 235 |
is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : no_fetch_filters no_bind_filters"); |
219 | 236 |
|
... | ... |
@@ -230,16 +247,16 @@ $insert_query->bind_filter(sub { |
230 | 247 |
} |
231 | 248 |
return $value; |
232 | 249 |
}); |
233 |
-$dbi->execute($insert_query, {table1 => {key1 => 1, key2 => 2}}); |
|
250 |
+$dbi->query($insert_query, {table1 => {key1 => 1, key2 => 2}}); |
|
234 | 251 |
$select_query = $dbi->create_query($SELECT_TMPL->{0}); |
235 |
-$result = $dbi->execute($select_query); |
|
252 |
+$result = $dbi->query($select_query); |
|
236 | 253 |
$rows = $result->fetch_hash_all; |
237 | 254 |
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name"); |
238 | 255 |
|
239 | 256 |
test 'Filter in'; |
240 | 257 |
$insert_tmpl = "insert into table1 {insert key1 key2};"; |
241 | 258 |
$insert_query = $dbi->create_query($insert_tmpl); |
242 |
-$dbi->execute($insert_query, {key1 => 2, key2 => 4}); |
|
259 |
+$dbi->query($insert_query, {key1 => 2, key2 => 4}); |
|
243 | 260 |
$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}"; |
244 | 261 |
$select_query = $dbi->create_query($select_tmpl); |
245 | 262 |
$select_query->bind_filter(sub { |
... | ... |
@@ -251,7 +268,7 @@ $select_query->bind_filter(sub { |
251 | 268 |
} |
252 | 269 |
return $value; |
253 | 270 |
}); |
254 |
-$result = $dbi->execute($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}}); |
|
271 |
+$result = $dbi->query($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}}); |
|
255 | 272 |
$rows = $result->fetch_hash_all; |
256 | 273 |
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : bind_filter"); |
257 | 274 |
|
... | ... |
@@ -265,37 +282,37 @@ $sth->execute(6, 7, 8, 9, 10); |
265 | 282 |
|
266 | 283 |
$tmpl = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};"; |
267 | 284 |
$query = $dbi->create_query($tmpl); |
268 |
-$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}); |
|
285 |
+$result = $dbi->query($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}); |
|
269 | 286 |
$rows = $result->fetch_hash_all; |
270 | 287 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1"); |
271 | 288 |
|
272 | 289 |
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};"; |
273 | 290 |
$query = $dbi->create_query($tmpl); |
274 |
-$result = $dbi->execute($query, {table1 => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}}); |
|
291 |
+$result = $dbi->query($query, {table1 => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}}); |
|
275 | 292 |
$rows = $result->fetch_hash_all; |
276 | 293 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table"); |
277 | 294 |
|
278 | 295 |
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};"; |
279 | 296 |
$query = $dbi->create_query($tmpl); |
280 |
-$result = $dbi->execute($query, {'table1.key1' => 1, 'table1.key2' => 3, 'table1.key3' => 4, 'table1.key4' => 3, 'table1.key5' => 5}); |
|
297 |
+$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => 3, 'table1.key3' => 4, 'table1.key4' => 3, 'table1.key5' => 5}); |
|
281 | 298 |
$rows = $result->fetch_hash_all; |
282 | 299 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table dot"); |
283 | 300 |
|
284 | 301 |
$tmpl = "select * from table1 where {<= key1} and {like key2};"; |
285 | 302 |
$query = $dbi->create_query($tmpl); |
286 |
-$result = $dbi->execute($query, {key1 => 1, key2 => '%2%'}); |
|
303 |
+$result = $dbi->query($query, {key1 => 1, key2 => '%2%'}); |
|
287 | 304 |
$rows = $result->fetch_hash_all; |
288 | 305 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2"); |
289 | 306 |
|
290 | 307 |
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};"; |
291 | 308 |
$query = $dbi->create_query($tmpl); |
292 |
-$result = $dbi->execute($query, {table1 => {key1 => 1, key2 => '%2%'}}); |
|
309 |
+$result = $dbi->query($query, {table1 => {key1 => 1, key2 => '%2%'}}); |
|
293 | 310 |
$rows = $result->fetch_hash_all; |
294 | 311 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table"); |
295 | 312 |
|
296 | 313 |
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};"; |
297 | 314 |
$query = $dbi->create_query($tmpl); |
298 |
-$result = $dbi->execute($query, {'table1.key1' => 1, 'table1.key2' => '%2%'}); |
|
315 |
+$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => '%2%'}); |
|
299 | 316 |
$rows = $result->fetch_hash_all; |
300 | 317 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table dot"); |
301 | 318 |
|
... | ... |
@@ -309,19 +326,19 @@ $sth->execute(6, 7, 8, 9, 10); |
309 | 326 |
|
310 | 327 |
$tmpl = "select * from table1 where {in key1 2};"; |
311 | 328 |
$query = $dbi->create_query($tmpl); |
312 |
-$result = $dbi->execute($query, {key1 => [9, 1]}); |
|
329 |
+$result = $dbi->query($query, {key1 => [9, 1]}); |
|
313 | 330 |
$rows = $result->fetch_hash_all; |
314 | 331 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic"); |
315 | 332 |
|
316 | 333 |
$tmpl = "select * from table1 where {in table1.key1 2};"; |
317 | 334 |
$query = $dbi->create_query($tmpl); |
318 |
-$result = $dbi->execute($query, {table1 => {key1 => [9, 1]}}); |
|
335 |
+$result = $dbi->query($query, {table1 => {key1 => [9, 1]}}); |
|
319 | 336 |
$rows = $result->fetch_hash_all; |
320 | 337 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table"); |
321 | 338 |
|
322 | 339 |
$tmpl = "select * from table1 where {in table1.key1 2};"; |
323 | 340 |
$query = $dbi->create_query($tmpl); |
324 |
-$result = $dbi->execute($query, {'table1.key1' => [9, 1]}); |
|
341 |
+$result = $dbi->query($query, {'table1.key1' => [9, 1]}); |
|
325 | 342 |
$rows = $result->fetch_hash_all; |
326 | 343 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table dot"); |
327 | 344 |
|
... | ... |
@@ -329,41 +346,41 @@ is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$te |
329 | 346 |
test 'DBIx::Custom::SQL::Template insert tag'; |
330 | 347 |
$dbi->do("delete from table1"); |
331 | 348 |
$insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}'; |
332 |
-$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
349 |
+$dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
333 | 350 |
|
334 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
351 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
335 | 352 |
$rows = $result->fetch_hash_all; |
336 | 353 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic"); |
337 | 354 |
|
338 | 355 |
$dbi->do("delete from table1"); |
339 |
-$dbi->execute($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}); |
|
340 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
356 |
+$dbi->query($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}); |
|
357 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
341 | 358 |
$rows = $result->fetch_hash_all; |
342 | 359 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert"); |
343 | 360 |
|
344 | 361 |
$dbi->do("delete from table1"); |
345 | 362 |
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}'; |
346 |
-$dbi->execute($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}); |
|
347 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
363 |
+$dbi->query($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}); |
|
364 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
348 | 365 |
$rows = $result->fetch_hash_all; |
349 | 366 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name"); |
350 | 367 |
|
351 | 368 |
$dbi->do("delete from table1"); |
352 | 369 |
$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}'; |
353 |
-$dbi->execute($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}); |
|
354 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
370 |
+$dbi->query($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}); |
|
371 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
355 | 372 |
$rows = $result->fetch_hash_all; |
356 | 373 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name dot"); |
357 | 374 |
|
358 | 375 |
$dbi->do("delete from table1"); |
359 |
-$dbi->execute($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}}); |
|
360 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
376 |
+$dbi->query($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}}); |
|
377 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
361 | 378 |
$rows = $result->fetch_hash_all; |
362 | 379 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name"); |
363 | 380 |
|
364 | 381 |
$dbi->do("delete from table1"); |
365 |
-$dbi->execute($insert_tmpl, {'#insert' => {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}}); |
|
366 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
382 |
+$dbi->query($insert_tmpl, {'#insert' => {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5}}); |
|
383 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
367 | 384 |
$rows = $result->fetch_hash_all; |
368 | 385 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : #insert with table name dot"); |
369 | 386 |
|
... | ... |
@@ -371,45 +388,45 @@ is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$te |
371 | 388 |
test 'DBIx::Custom::SQL::Template update tag'; |
372 | 389 |
$dbi->do("delete from table1"); |
373 | 390 |
$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}"; |
374 |
-$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
375 |
-$dbi->execute($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
391 |
+$dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
|
392 |
+$dbi->query($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
|
376 | 393 |
|
377 | 394 |
$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}'; |
378 |
-$dbi->execute($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
|
395 |
+$dbi->query($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
|
379 | 396 |
|
380 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
397 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
381 | 398 |
$rows = $result->fetch_hash_all; |
382 | 399 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}, |
383 | 400 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic"); |
384 | 401 |
|
385 |
-$dbi->execute($update_tmpl, {'#update' => {key1 => 2, key2 => 2, key3 => 2, key4 => 2}, key5 => 5}); |
|
386 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
402 |
+$dbi->query($update_tmpl, {'#update' => {key1 => 2, key2 => 2, key3 => 2, key4 => 2}, key5 => 5}); |
|
403 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
387 | 404 |
$rows = $result->fetch_hash_all; |
388 | 405 |
is_deeply($rows, [{key1 => 2, key2 => 2, key3 => 2, key4 => 2, key5 => 5}, |
389 | 406 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : #update"); |
390 | 407 |
|
391 | 408 |
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}'; |
392 |
-$dbi->execute($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}}); |
|
393 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
409 |
+$dbi->query($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}}); |
|
410 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
394 | 411 |
$rows = $result->fetch_hash_all; |
395 | 412 |
is_deeply($rows, [{key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}, |
396 | 413 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name"); |
397 | 414 |
|
398 | 415 |
$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}'; |
399 |
-$dbi->execute($update_tmpl, {'table1.key1' => 4, 'table1.key2' => 4, 'table1.key3' => 4, 'table1.key4' => 4, 'table1.key5' => 5}); |
|
400 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
416 |
+$dbi->query($update_tmpl, {'table1.key1' => 4, 'table1.key2' => 4, 'table1.key3' => 4, 'table1.key4' => 4, 'table1.key5' => 5}); |
|
417 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
401 | 418 |
$rows = $result->fetch_hash_all; |
402 | 419 |
is_deeply($rows, [{key1 => 4, key2 => 4, key3 => 4, key4 => 4, key5 => 5}, |
403 | 420 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name dot"); |
404 | 421 |
|
405 |
-$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3 => 5, key4 => 5}}, table1 => {key5 => 5}}); |
|
406 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
422 |
+$dbi->query($update_tmpl, {'#update' => {table1 => {key1 => 5, key2 => 5, key3 => 5, key4 => 5}}, table1 => {key5 => 5}}); |
|
423 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
407 | 424 |
$rows = $result->fetch_hash_all; |
408 | 425 |
is_deeply($rows, [{key1 => 5, key2 => 5, key3 => 5, key4 => 5, key5 => 5}, |
409 | 426 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name"); |
410 | 427 |
|
411 |
-$dbi->execute($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5}); |
|
412 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
428 |
+$dbi->query($update_tmpl, {'#update' => {'table1.key1' => 6, 'table1.key2' => 6, 'table1.key3' => 6, 'table1.key4' => 6}, 'table1.key5' => 5}); |
|
429 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
413 | 430 |
$rows = $result->fetch_hash_all; |
414 | 431 |
is_deeply($rows, [{key1 => 6, key2 => 6, key3 => 6, key4 => 6, key5 => 5}, |
415 | 432 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : update tag #update with table name dot"); |
... | ... |
@@ -421,10 +438,10 @@ $dbi->do($CREATE_TABLE->{0}); |
421 | 438 |
$dbi->run_transaction(sub { |
422 | 439 |
my $dbi = shift; |
423 | 440 |
$insert_tmpl = 'insert into table1 {insert key1 key2}'; |
424 |
- $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}); |
|
425 |
- $dbi->execute($insert_tmpl, {key1 => 3, key2 => 4}); |
|
441 |
+ $dbi->query($insert_tmpl, {key1 => 1, key2 => 2}); |
|
442 |
+ $dbi->query($insert_tmpl, {key1 => 3, key2 => 4}); |
|
426 | 443 |
}); |
427 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
444 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
428 | 445 |
$rows = $result->fetch_hash_all; |
429 | 446 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit"); |
430 | 447 |
|
... | ... |
@@ -435,14 +452,14 @@ eval{ |
435 | 452 |
$dbi->run_transaction(sub { |
436 | 453 |
my $dbi = shift; |
437 | 454 |
$insert_tmpl = 'insert into table1 {insert key1 key2}'; |
438 |
- $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2}); |
|
455 |
+ $dbi->query($insert_tmpl, {key1 => 1, key2 => 2}); |
|
439 | 456 |
die "Fatal Error"; |
440 |
- $dbi->execute($insert_tmpl, {key1 => 3, key2 => 4}); |
|
457 |
+ $dbi->query($insert_tmpl, {key1 => 3, key2 => 4}); |
|
441 | 458 |
}) |
442 | 459 |
}; |
443 | 460 |
like($@, qr/Fatal Error.*Rollback is success/ms, "$test : Rollback success message"); |
444 | 461 |
ok(!$dbi->dbh->{RaiseError}, "$test : restore RaiseError value"); |
445 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
462 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
446 | 463 |
$rows = $result->fetch_hash_all; |
447 | 464 |
is_deeply($rows, [], "$test : rollback"); |
448 | 465 |
|
... | ... |
@@ -480,7 +497,7 @@ ok($@, "$test : create_query invalid SQL template"); |
480 | 497 |
$dbi = DBIx::Custom->new($NEW_ARGS->{0}); |
481 | 498 |
$dbi->do($CREATE_TABLE->{0}); |
482 | 499 |
$query = $dbi->create_query("select * from table1 where {= key1}"); |
483 |
-eval{$dbi->execute($query, {key2 => 1})}; |
|
500 |
+eval{$dbi->query($query, {key2 => 1})}; |
|
484 | 501 |
like($@, qr/Corresponding key is not found in your parameters/, |
485 | 502 |
"$test : execute corresponding key not found"); |
486 | 503 |
|
... | ... |
@@ -490,7 +507,7 @@ $dbi = DBIx::Custom->new($NEW_ARGS->{0}); |
490 | 507 |
$dbi->do($CREATE_TABLE->{0}); |
491 | 508 |
$dbi->insert('table1', {key1 => 1, key2 => 2}); |
492 | 509 |
$dbi->insert('table1', {key1 => 3, key2 => 4}); |
493 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
510 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
494 | 511 |
$rows = $result->fetch_hash_all; |
495 | 512 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic"); |
496 | 513 |
|
... | ... |
@@ -505,7 +522,7 @@ $dbi->insert('table1', {key1 => 1, key2 => 2}, sub { |
505 | 522 |
return $value; |
506 | 523 |
}); |
507 | 524 |
}); |
508 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
525 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
509 | 526 |
$rows = $result->fetch_hash_all; |
510 | 527 |
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : edit_query_callback"); |
511 | 528 |
|
... | ... |
@@ -529,7 +546,7 @@ $dbi->do($CREATE_TABLE->{1}); |
529 | 546 |
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
530 | 547 |
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
531 | 548 |
$dbi->update('table1', {key2 => 11}, {key1 => 1}); |
532 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
549 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
533 | 550 |
$rows = $result->fetch_hash_all; |
534 | 551 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5}, |
535 | 552 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
... | ... |
@@ -539,7 +556,7 @@ $dbi->do("delete from table1"); |
539 | 556 |
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
540 | 557 |
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
541 | 558 |
$dbi->update('table1', {key2 => 12}, {key2 => 2, key3 => 3}); |
542 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
559 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
543 | 560 |
$rows = $result->fetch_hash_all; |
544 | 561 |
is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5}, |
545 | 562 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
... | ... |
@@ -558,7 +575,7 @@ $dbi->update('table1', {key2 => 11}, {key1 => 1}, sub { |
558 | 575 |
return $value; |
559 | 576 |
}); |
560 | 577 |
}); |
561 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
578 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
562 | 579 |
$rows = $result->fetch_hash_all; |
563 | 580 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5}, |
564 | 581 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], |
... | ... |
@@ -599,7 +616,7 @@ $dbi->update_all('table1', {key2 => 10}, sub { |
599 | 616 |
return $value * 2; |
600 | 617 |
}) |
601 | 618 |
}); |
602 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
619 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
603 | 620 |
$rows = $result->fetch_hash_all; |
604 | 621 |
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5}, |
605 | 622 |
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}], |
... | ... |
@@ -612,7 +629,7 @@ $dbi->do($CREATE_TABLE->{0}); |
612 | 629 |
$dbi->insert('table1', {key1 => 1, key2 => 2}); |
613 | 630 |
$dbi->insert('table1', {key1 => 3, key2 => 4}); |
614 | 631 |
$dbi->delete('table1', {key1 => 1}); |
615 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
632 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
616 | 633 |
$rows = $result->fetch_hash_all; |
617 | 634 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic"); |
618 | 635 |
|
... | ... |
@@ -626,7 +643,7 @@ $dbi->delete('table1', {key2 => 1}, sub { |
626 | 643 |
return $value * 2; |
627 | 644 |
}); |
628 | 645 |
}); |
629 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
646 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
630 | 647 |
$rows = $result->fetch_hash_all; |
631 | 648 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : query edit callback"); |
632 | 649 |
|
... | ... |
@@ -663,7 +680,7 @@ $dbi->do($CREATE_TABLE->{0}); |
663 | 680 |
$dbi->insert('table1', {key1 => 1, key2 => 2}); |
664 | 681 |
$dbi->insert('table1', {key1 => 3, key2 => 4}); |
665 | 682 |
$dbi->delete_all('table1'); |
666 |
-$result = $dbi->execute($SELECT_TMPL->{0}); |
|
683 |
+$result = $dbi->query($SELECT_TMPL->{0}); |
|
667 | 684 |
$rows = $result->fetch_hash_all; |
668 | 685 |
is_deeply($rows, [], "$test : basic"); |
669 | 686 |
|
... | ... |
@@ -26,19 +26,19 @@ $dbi = DBIx::Custom->new( |
26 | 26 |
database => 'a', |
27 | 27 |
password => 'b', |
28 | 28 |
data_source => 'c', |
29 |
- dbi_options => {d => 1, e => 2}, |
|
29 |
+ options => {d => 1, e => 2}, |
|
30 | 30 |
filters => { |
31 | 31 |
f => 3, |
32 | 32 |
}, |
33 | 33 |
bind_filter => 'f', |
34 | 34 |
fetch_filter => 'g', |
35 | 35 |
result_class => 'g', |
36 |
- sql_template => $SQL_TMPL->{0}, |
|
36 |
+ sql_tmpl => $SQL_TMPL->{0}, |
|
37 | 37 |
); |
38 | 38 |
is_deeply($dbi,{user => 'a', database => 'a', password => 'b', data_source => 'c', |
39 |
- dbi_options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f', |
|
39 |
+ options => {d => 1, e => 2}, filters => {f => 3}, bind_filter => 'f', |
|
40 | 40 |
fetch_filter => 'g', result_class => 'g', |
41 |
- sql_template => $SQL_TMPL->{0}}, $test); |
|
41 |
+ sql_tmpl => $SQL_TMPL->{0}}, $test); |
|
42 | 42 |
isa_ok($dbi, 'DBIx::Custom'); |
43 | 43 |
|
44 | 44 |
|
... | ... |
@@ -52,7 +52,7 @@ test 'Sub class constructor'; |
52 | 52 |
->database('a') |
53 | 53 |
->password('b') |
54 | 54 |
->data_source('c') |
55 |
- ->dbi_options({d => 1, e => 2}) |
|
55 |
+ ->options({d => 1, e => 2}) |
|
56 | 56 |
->filters( |
57 | 57 |
f => 3 |
58 | 58 |
) |
... | ... |
@@ -62,7 +62,7 @@ test 'Sub class constructor'; |
62 | 62 |
->bind_filter('f') |
63 | 63 |
->fetch_filter('g') |
64 | 64 |
->result_class('DBIx::Custom::Result') |
65 |
- ->sql_template($SQL_TMPL->{0}) |
|
65 |
+ ->sql_tmpl($SQL_TMPL->{0}) |
|
66 | 66 |
; |
67 | 67 |
} |
68 | 68 |
$dbi = DBIx::Custom::T1->new( |
... | ... |
@@ -70,7 +70,7 @@ $dbi = DBIx::Custom::T1->new( |
70 | 70 |
database => 'ao', |
71 | 71 |
password => 'bo', |
72 | 72 |
data_source => 'co', |
73 |
- dbi_options => {do => 10, eo => 20}, |
|
73 |
+ options => {do => 10, eo => 20}, |
|
74 | 74 |
filters => { |
75 | 75 |
fo => 30, |
76 | 76 |
}, |
... | ... |
@@ -80,19 +80,19 @@ $dbi = DBIx::Custom::T1->new( |
80 | 80 |
bind_filter => 'fo', |
81 | 81 |
fetch_filter => 'go', |
82 | 82 |
result_class => 'ho', |
83 |
- sql_template => $SQL_TMPL->{0}, |
|
83 |
+ sql_tmpl => $SQL_TMPL->{0}, |
|
84 | 84 |
); |
85 | 85 |
is($dbi->user, 'ao', "$test : user"); |
86 | 86 |
is($dbi->database, 'ao', "$test : database"); |
87 | 87 |
is($dbi->password, 'bo', "$test : passowr"); |
88 | 88 |
is($dbi->data_source, 'co', "$test : data_source"); |
89 |
-is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); |
|
89 |
+is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options"); |
|
90 | 90 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
91 | 91 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
92 | 92 |
is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
93 | 93 |
is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
94 | 94 |
is($dbi->result_class, 'ho', "$test : result_class"); |
95 |
-is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
95 |
+is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl"); |
|
96 | 96 |
isa_ok($dbi, 'DBIx::Custom::T1'); |
97 | 97 |
|
98 | 98 |
test 'Sub class constructor default'; |
... | ... |
@@ -101,13 +101,13 @@ is($dbi->user, 'a', "$test : user"); |
101 | 101 |
is($dbi->database, 'a', "$test : database"); |
102 | 102 |
is($dbi->password, 'b', "$test : password"); |
103 | 103 |
is($dbi->data_source, 'c', "$test : data_source"); |
104 |
-is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
104 |
+is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
105 | 105 |
is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); |
106 | 106 |
is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); |
107 | 107 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
108 | 108 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
109 | 109 |
is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class"); |
110 |
-is($dbi->sql_template->tag_start, 0, "$test : sql_template"); |
|
110 |
+is($dbi->sql_tmpl->tag_start, 0, "$test : sql_tmpl"); |
|
111 | 111 |
isa_ok($dbi, 'DBIx::Custom::T1'); |
112 | 112 |
|
113 | 113 |
|
... | ... |
@@ -121,13 +121,13 @@ is($dbi->user, 'a', "$test : user"); |
121 | 121 |
is($dbi->database, 'a', "$test : database"); |
122 | 122 |
is($dbi->password, 'b', "$test : passowrd"); |
123 | 123 |
is($dbi->data_source, 'c', "$test : data_source"); |
124 |
-is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
124 |
+is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
125 | 125 |
is_deeply(scalar $dbi->filters, {f => 3}, "$test : filters"); |
126 | 126 |
is_deeply(scalar $dbi->formats, {f => 3}, "$test : formats"); |
127 | 127 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
128 | 128 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
129 | 129 |
is($dbi->result_class, 'DBIx::Custom::Result', "$test : result_class"); |
130 |
-is($dbi->sql_template->tag_start, 0, "$test sql_template"); |
|
130 |
+is($dbi->sql_tmpl->tag_start, 0, "$test sql_tmpl"); |
|
131 | 131 |
isa_ok($dbi, 'DBIx::Custom::T1_2'); |
132 | 132 |
|
133 | 133 |
|
... | ... |
@@ -141,7 +141,7 @@ test 'Customized sub class constructor default'; |
141 | 141 |
->database('ao') |
142 | 142 |
->password('bo') |
143 | 143 |
->data_source('co') |
144 |
- ->dbi_options({do => 10, eo => 20}) |
|
144 |
+ ->options({do => 10, eo => 20}) |
|
145 | 145 |
->filters( |
146 | 146 |
fo => 30 |
147 | 147 |
) |
... | ... |
@@ -151,7 +151,7 @@ test 'Customized sub class constructor default'; |
151 | 151 |
->bind_filter('fo') |
152 | 152 |
->fetch_filter('go') |
153 | 153 |
->result_class('ho') |
154 |
- ->sql_template($SQL_TMPL->{1}) |
|
154 |
+ ->sql_tmpl($SQL_TMPL->{1}) |
|
155 | 155 |
; |
156 | 156 |
} |
157 | 157 |
$dbi = DBIx::Custom::T1_3->new; |
... | ... |
@@ -159,13 +159,13 @@ is($dbi->user, 'ao', "$test : user"); |
159 | 159 |
is($dbi->database, 'ao', "$test : database"); |
160 | 160 |
is($dbi->password, 'bo', "$test : password"); |
161 | 161 |
is($dbi->data_source, 'co', "$test : data_source"); |
162 |
-is_deeply($dbi->dbi_options, {do => 10, eo => 20}, "$test : dbi_options"); |
|
162 |
+is_deeply($dbi->options, {do => 10, eo => 20}, "$test : options"); |
|
163 | 163 |
is_deeply(scalar $dbi->filters, {fo => 30}, "$test : filters"); |
164 | 164 |
is_deeply(scalar $dbi->formats, {fo => 30}, "$test : formats"); |
165 | 165 |
is($dbi->bind_filter, 'fo', "$test : bind_filter"); |
166 | 166 |
is($dbi->fetch_filter, 'go', "$test : fetch_filter"); |
167 | 167 |
is($dbi->result_class, 'ho', "$test : result_class"); |
168 |
-is($dbi->sql_template->tag_start, 1, "$test : sql_template"); |
|
168 |
+is($dbi->sql_tmpl->tag_start, 1, "$test : sql_tmpl"); |
|
169 | 169 |
isa_ok($dbi, 'DBIx::Custom::T1_3'); |
170 | 170 |
|
171 | 171 |
|
... | ... |
@@ -175,7 +175,7 @@ $dbi = DBIx::Custom::T1_3->new( |
175 | 175 |
database => 'a', |
176 | 176 |
password => 'b', |
177 | 177 |
data_source => 'c', |
178 |
- dbi_options => {d => 1, e => 2}, |
|
178 |
+ options => {d => 1, e => 2}, |
|
179 | 179 |
filters => { |
180 | 180 |
f => 3, |
181 | 181 |
}, |
... | ... |
@@ -185,19 +185,19 @@ $dbi = DBIx::Custom::T1_3->new( |
185 | 185 |
bind_filter => 'f', |
186 | 186 |
fetch_filter => 'g', |
187 | 187 |
result_class => 'h', |
188 |
- sql_template => $SQL_TMPL->{2}, |
|
188 |
+ sql_tmpl => $SQL_TMPL->{2}, |
|
189 | 189 |
); |
190 | 190 |
is($dbi->user, 'a', "$test : user"); |
191 | 191 |
is($dbi->database, 'a', "$test : database"); |
192 | 192 |
is($dbi->password, 'b', "$test : password"); |
193 | 193 |
is($dbi->data_source, 'c', "$test : data_source"); |
194 |
-is_deeply($dbi->dbi_options, {d => 1, e => 2}, "$test : dbi_options"); |
|
194 |
+is_deeply($dbi->options, {d => 1, e => 2}, "$test : options"); |
|
195 | 195 |
is_deeply({$dbi->filters}, {f => 3}, "$test : filters"); |
196 | 196 |
is_deeply({$dbi->formats}, {f => 3}, "$test : formats"); |
197 | 197 |
is($dbi->bind_filter, 'f', "$test : bind_filter"); |
198 | 198 |
is($dbi->fetch_filter, 'g', "$test : fetch_filter"); |
199 | 199 |
is($dbi->result_class, 'h', "$test : result_class"); |
200 |
-is($dbi->sql_template->tag_start, 2, "$test : sql_template"); |
|
200 |
+is($dbi->sql_tmpl->tag_start, 2, "$test : sql_tmpl"); |
|
201 | 201 |
isa_ok($dbi, 'DBIx::Custom'); |
202 | 202 |
|
203 | 203 |
|
... | ... |
@@ -218,3 +218,15 @@ $dbi->fetch_filter('b'); |
218 | 218 |
$dbi->filter_off; |
219 | 219 |
ok(!$dbi->bind_filter, "$test : bind_filter off"); |
220 | 220 |
ok(!$dbi->fetch_filter, "$test : fetch_filter off"); |
221 |
+ |
|
222 |
+__END__ |
|
223 |
+test 'Accessor'; |
|
224 |
+$dbi = DBIx::Custom->new; |
|
225 |
+$dbi->options(opt1 => 1, opt2 => 2); |
|
226 |
+is_deeply(scalar $dbi->options, {opt1 => 1, opt2 => 2}, "$test : options"); |
|
227 |
+ |
|
228 |
+$dbi->no_bind_filters('a', 'b'); |
|
229 |
+is_deeply(scalar $dbi->no_bind_filters, ['a', 'b'], "$test: no_bind_filters"); |
|
230 |
+ |
|
231 |
+$dbi->no_fetch_filters('a', 'b'); |
|
232 |
+is_deeply(scalar $dbi->no_fetch_filters, ['a', 'b'], "$test: no_fetch_filters"); |