... | ... |
@@ -1,3 +1,10 @@ |
1 |
+0.1101 |
|
2 |
+ rename DBIx::Custom::SQLite last_insert_id to last_insert_rowid |
|
3 |
+0.1001 |
|
4 |
+ remove run_transaction(). |
|
5 |
+ add transaction() and DBIx::Custom::Transaction |
|
6 |
+ rename fetch_first to fetch_single |
|
7 |
+ rename fetch_hash_first to fetch_hash_single |
|
1 | 8 |
0.0906 |
2 | 9 |
fix some bug |
3 | 10 |
0.0905 |
... | ... |
@@ -37,6 +37,7 @@ __PACKAGE__->dual_attr('sql_tmpl', default => sub {DBIx::Custom::SQL::Template-> |
37 | 37 |
sub add_filter { |
38 | 38 |
my $invocant = shift; |
39 | 39 |
|
40 |
+ # Add filter |
|
40 | 41 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
41 | 42 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
42 | 43 |
|
... | ... |
@@ -46,6 +47,7 @@ sub add_filter { |
46 | 47 |
sub add_format{ |
47 | 48 |
my $invocant = shift; |
48 | 49 |
|
50 |
+ # Add format |
|
49 | 51 |
my $formats = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
50 | 52 |
$invocant->formats({%{$invocant->formats}, %$formats}); |
51 | 53 |
|
... | ... |
@@ -55,10 +57,14 @@ sub add_format{ |
55 | 57 |
sub _auto_commit { |
56 | 58 |
my $self = shift; |
57 | 59 |
|
60 |
+ # Not connected |
|
58 | 61 |
croak("Not yet connect to database") unless $self->dbh; |
59 | 62 |
|
60 | 63 |
if (@_) { |
64 |
+ |
|
65 |
+ # Set AutoCommit |
|
61 | 66 |
$self->dbh->{AutoCommit} = $_[0]; |
67 |
+ |
|
62 | 68 |
return $self; |
63 | 69 |
} |
64 | 70 |
return $self->dbh->{AutoCommit}; |
... | ... |
@@ -66,11 +72,14 @@ sub _auto_commit { |
66 | 72 |
|
67 | 73 |
sub connect { |
68 | 74 |
my $self = shift; |
75 |
+ |
|
76 |
+ # Information |
|
69 | 77 |
my $data_source = $self->data_source; |
70 | 78 |
my $user = $self->user; |
71 | 79 |
my $password = $self->password; |
72 | 80 |
my $options = $self->options; |
73 | 81 |
|
82 |
+ # Connect |
|
74 | 83 |
my $dbh = eval{DBI->connect( |
75 | 84 |
$data_source, |
76 | 85 |
$user, |
... | ... |
@@ -83,34 +92,45 @@ sub connect { |
83 | 92 |
} |
84 | 93 |
)}; |
85 | 94 |
|
95 |
+ # Connect error |
|
86 | 96 |
croak $@ if $@; |
87 | 97 |
|
98 |
+ # Database handle |
|
88 | 99 |
$self->dbh($dbh); |
100 |
+ |
|
89 | 101 |
return $self; |
90 | 102 |
} |
91 | 103 |
|
92 | 104 |
sub DESTROY { |
93 | 105 |
my $self = shift; |
106 |
+ |
|
107 |
+ # Disconnect |
|
94 | 108 |
$self->disconnect if $self->connected; |
95 | 109 |
} |
96 | 110 |
|
97 |
-sub connected { |
|
98 |
- my $self = shift; |
|
99 |
- return ref $self->{dbh} eq 'DBI::db'; |
|
100 |
-} |
|
111 |
+sub connected { ref shift->{dbh} eq 'DBI::db' } |
|
101 | 112 |
|
102 | 113 |
sub disconnect { |
103 | 114 |
my $self = shift; |
115 |
+ |
|
104 | 116 |
if ($self->connected) { |
117 |
+ |
|
118 |
+ # Disconnect |
|
105 | 119 |
$self->dbh->disconnect; |
106 | 120 |
delete $self->{dbh}; |
107 | 121 |
} |
122 |
+ |
|
123 |
+ return $self; |
|
108 | 124 |
} |
109 | 125 |
|
110 | 126 |
sub reconnect { |
111 | 127 |
my $self = shift; |
128 |
+ |
|
129 |
+ # Reconnect |
|
112 | 130 |
$self->disconnect if $self->connected; |
113 | 131 |
$self->connect; |
132 |
+ |
|
133 |
+ return $self; |
|
114 | 134 |
} |
115 | 135 |
|
116 | 136 |
sub prepare { |
... | ... |
@@ -359,13 +379,6 @@ sub _build_bind_values { |
359 | 379 |
|
360 | 380 |
sub transaction { DBIx::Custom::Transaction->new(dbi => shift) } |
361 | 381 |
|
362 |
-sub last_insert_id { |
|
363 |
- my $self = shift; |
|
364 |
- my $class = ref $self; |
|
365 |
- croak "'$class' do not suppert 'last_insert_id'"; |
|
366 |
-} |
|
367 |
- |
|
368 |
- |
|
369 | 382 |
sub create_table { |
370 | 383 |
my ($self, $table, @column_definitions) = @_; |
371 | 384 |
|
... | ... |
@@ -495,6 +508,7 @@ sub update_all { |
495 | 508 |
my $query_edit_cb = shift; |
496 | 509 |
my $options = {allow_update_all => 1}; |
497 | 510 |
|
511 |
+ # Update all rows |
|
498 | 512 |
return $self->update($table, $update_params, {}, $append_statement, |
499 | 513 |
$query_edit_cb, $options); |
500 | 514 |
} |
... | ... |
@@ -551,6 +565,7 @@ sub delete_all { |
551 | 565 |
my $query_edit_cb = shift; |
552 | 566 |
my $options = {allow_delete_all => 1}; |
553 | 567 |
|
568 |
+ # Delete all rows |
|
554 | 569 |
return $self->delete($table, {}, $append_statement, $query_edit_cb, |
555 | 570 |
$options); |
556 | 571 |
} |
... | ... |
@@ -645,16 +660,20 @@ sub select { |
645 | 660 |
|
646 | 661 |
sub _add_query_cache { |
647 | 662 |
my ($class, $template, $query) = @_; |
663 |
+ |
|
664 |
+ # Query information |
|
648 | 665 |
my $query_cache_keys = $class->_query_cache_keys; |
649 | 666 |
my $query_caches = $class->_query_caches; |
650 | 667 |
|
668 |
+ # Already cached |
|
651 | 669 |
return $class if $query_caches->{$template}; |
652 | 670 |
|
671 |
+ # Cache |
|
653 | 672 |
$query_caches->{$template} = $query; |
654 | 673 |
push @$query_cache_keys, $template; |
655 | 674 |
|
675 |
+ # Check cache overflow |
|
656 | 676 |
my $overflow = @$query_cache_keys - $class->query_cache_max; |
657 |
- |
|
658 | 677 |
for (my $i = 0; $i < $overflow; $i++) { |
659 | 678 |
my $template = shift @$query_cache_keys; |
660 | 679 |
delete $query_caches->{$template}; |
... | ... |
@@ -666,7 +685,7 @@ sub _add_query_cache { |
666 | 685 |
sub filter_off { |
667 | 686 |
my $self = shift; |
668 | 687 |
|
669 |
- # filter off |
|
688 |
+ # Filter off |
|
670 | 689 |
$self->bind_filter(undef); |
671 | 690 |
$self->fetch_filter(undef); |
672 | 691 |
|
... | ... |
@@ -679,11 +698,11 @@ DBIx::Custom - Customizable DBI |
679 | 698 |
|
680 | 699 |
=head1 VERSION |
681 | 700 |
|
682 |
-Version 0.1001 |
|
701 |
+Version 0.1101 |
|
683 | 702 |
|
684 | 703 |
=cut |
685 | 704 |
|
686 |
-our $VERSION = '0.1001'; |
|
705 |
+our $VERSION = '0.1101'; |
|
687 | 706 |
|
688 | 707 |
=head1 SYNOPSYS |
689 | 708 |
|
... | ... |
@@ -714,25 +733,25 @@ our $VERSION = '0.1001'; |
714 | 733 |
$dbi->select('books', [qw/author title/], {author => 'Ken'}, |
715 | 734 |
'order by id limit 1'); |
716 | 735 |
|
717 |
-=head1 Accessors |
|
736 |
+=head1 ATTRIBUTES |
|
718 | 737 |
|
719 | 738 |
=head2 user |
720 | 739 |
|
721 |
-Set and get database user name |
|
740 |
+Database user name |
|
722 | 741 |
|
723 | 742 |
$dbi = $dbi->user('Ken'); |
724 | 743 |
$user = $dbi->user; |
725 | 744 |
|
726 | 745 |
=head2 password |
727 | 746 |
|
728 |
-Set and get database password |
|
747 |
+Database password |
|
729 | 748 |
|
730 | 749 |
$dbi = $dbi->password('lkj&le`@s'); |
731 | 750 |
$password = $dbi->password; |
732 | 751 |
|
733 | 752 |
=head2 data_source |
734 | 753 |
|
735 |
-Set and get database data source |
|
754 |
+Database data source |
|
736 | 755 |
|
737 | 756 |
$dbi = $dbi->data_source("dbi:mysql:dbname=$database"); |
738 | 757 |
$data_source = $dbi->data_source; |
... | ... |
@@ -741,14 +760,14 @@ If you know data source more, See also L<DBI>. |
741 | 760 |
|
742 | 761 |
=head2 database |
743 | 762 |
|
744 |
-Set and get database name |
|
763 |
+Database name |
|
745 | 764 |
|
746 | 765 |
$dbi = $dbi->database('books'); |
747 | 766 |
$database = $dbi->database; |
748 | 767 |
|
749 | 768 |
=head2 host |
750 | 769 |
|
751 |
-Set and get host name |
|
770 |
+Host name |
|
752 | 771 |
|
753 | 772 |
$dbi = $dbi->host('somehost.com'); |
754 | 773 |
$host = $dbi->host; |
... | ... |
@@ -757,21 +776,21 @@ You can also set IP address like '127.03.45.12'. |
757 | 776 |
|
758 | 777 |
=head2 port |
759 | 778 |
|
760 |
-Set and get port |
|
779 |
+Port number |
|
761 | 780 |
|
762 | 781 |
$dbi = $dbi->port(1198); |
763 | 782 |
$port = $dbi->port; |
764 | 783 |
|
765 | 784 |
=head2 options |
766 | 785 |
|
767 |
-Set and get DBI option |
|
786 |
+DBI options |
|
768 | 787 |
|
769 | 788 |
$dbi = $dbi->options({PrintError => 0, RaiseError => 1}); |
770 | 789 |
$options = $dbi->options; |
771 | 790 |
|
772 | 791 |
=head2 sql_tmpl |
773 | 792 |
|
774 |
-Set and get SQL::Template object |
|
793 |
+SQL::Template object |
|
775 | 794 |
|
776 | 795 |
$dbi = $dbi->sql_tmpl(DBIx::Cutom::SQL::Template->new); |
777 | 796 |
$sql_tmpl = $dbi->sql_tmpl; |
... | ... |
@@ -780,7 +799,7 @@ See also L<DBIx::Custom::SQL::Template>. |
780 | 799 |
|
781 | 800 |
=head2 filters |
782 | 801 |
|
783 |
-Set and get filters |
|
802 |
+Filters |
|
784 | 803 |
|
785 | 804 |
$dbi = $dbi->filters({filter1 => sub { }, filter2 => sub {}}); |
786 | 805 |
$filters = $dbi->filters; |
... | ... |
@@ -793,7 +812,7 @@ If you add filter, use add_filter method. |
793 | 812 |
|
794 | 813 |
=head2 formats |
795 | 814 |
|
796 |
-Set and get formats |
|
815 |
+Formats |
|
797 | 816 |
|
798 | 817 |
$dbi = $dbi->formats({format1 => sub { }, format2 => sub {}}); |
799 | 818 |
$formats = $dbi->formats; |
... | ... |
@@ -806,7 +825,7 @@ If you add format, use add_format method. |
806 | 825 |
|
807 | 826 |
=head2 bind_filter |
808 | 827 |
|
809 |
-Set and get binding filter |
|
828 |
+Binding filter |
|
810 | 829 |
|
811 | 830 |
$dbi = $dbi->bind_filter($bind_filter); |
812 | 831 |
$bind_filter = $dbi->bind_filter |
... | ... |
@@ -830,7 +849,7 @@ Bind filter arguemts is |
830 | 849 |
|
831 | 850 |
=head2 fetch_filter |
832 | 851 |
|
833 |
-Set and get Fetch filter |
|
852 |
+Fetching filter |
|
834 | 853 |
|
835 | 854 |
$dbi = $dbi->fetch_filter($fetch_filter); |
836 | 855 |
$fetch_filter = $dbi->fetch_filter; |
... | ... |
@@ -854,42 +873,47 @@ Bind filter arguemts is |
854 | 873 |
|
855 | 874 |
=head2 no_bind_filters |
856 | 875 |
|
857 |
-Set and get no filter keys when binding |
|
876 |
+Key list which dose not have to bind filtering |
|
858 | 877 |
|
859 | 878 |
$dbi = $dbi->no_bind_filters(qw/title author/); |
860 | 879 |
$no_bind_filters = $dbi->no_bind_filters; |
861 | 880 |
|
862 | 881 |
=head2 no_fetch_filters |
863 | 882 |
|
864 |
-Set and get no filter keys when fetching |
|
883 |
+Key list which dose not have to fetch filtering |
|
865 | 884 |
|
866 | 885 |
$dbi = $dbi->no_fetch_filters(qw/title author/); |
867 | 886 |
$no_fetch_filters = $dbi->no_fetch_filters; |
868 | 887 |
|
869 | 888 |
=head2 result_class |
870 | 889 |
|
871 |
-Set and get resultset class |
|
890 |
+Resultset class |
|
872 | 891 |
|
873 | 892 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
874 | 893 |
$result_class = $dbi->result_class; |
875 | 894 |
|
895 |
+Default is L<DBIx::Custom::Result> |
|
896 |
+ |
|
876 | 897 |
=head2 dbh |
877 | 898 |
|
878 |
-Get database handle |
|
899 |
+Database handle |
|
879 | 900 |
|
880 | 901 |
$dbi = $dbi->dbh($dbh); |
881 | 902 |
$dbh = $dbi->dbh; |
882 | 903 |
|
883 | 904 |
=head2 query_cache_max |
884 | 905 |
|
885 |
-Set and get query cache max |
|
906 |
+Query cache max |
|
886 | 907 |
|
887 | 908 |
$class = DBIx::Custom->query_cache_max(50); |
888 | 909 |
$query_cache_max = DBIx::Custom->query_cache_max; |
889 | 910 |
|
890 | 911 |
Default value is 50 |
891 | 912 |
|
892 |
-=head1 Methods |
|
913 |
+=head1 METHODS |
|
914 |
+ |
|
915 |
+This class is L<Object::Simple> subclass. |
|
916 |
+You can use all methods of L<Object::Simple> |
|
893 | 917 |
|
894 | 918 |
=head2 connect |
895 | 919 |
|
... | ... |
@@ -1150,15 +1174,6 @@ You can also edit query |
1150 | 1174 |
} |
1151 | 1175 |
} |
1152 | 1176 |
|
1153 |
- |
|
1154 |
-=head2 last_insert_id |
|
1155 |
- |
|
1156 |
-Get last insert id |
|
1157 |
- |
|
1158 |
- $last_insert_id = $dbi->last_insert_id; |
|
1159 |
- |
|
1160 |
-This method is implemented by subclass. |
|
1161 |
- |
|
1162 | 1177 |
=head2 prepare |
1163 | 1178 |
|
1164 | 1179 |
Prepare statement handle. |
... | ... |
@@ -1,8 +1,9 @@ |
1 | 1 |
package DBIx::Custom::Basic; |
2 |
-use base 'DBIx::Custom'; |
|
3 | 2 |
|
4 | 3 |
use warnings; |
5 | 4 |
use strict; |
5 |
+ |
|
6 |
+use base 'DBIx::Custom'; |
|
6 | 7 |
use Encode qw/decode encode/; |
7 | 8 |
|
8 | 9 |
__PACKAGE__->add_filter( |
... | ... |
@@ -19,7 +20,6 @@ __PACKAGE__->add_format( |
19 | 20 |
'ISO-8601_time' => '%H:%M:%S', |
20 | 21 |
); |
21 | 22 |
|
22 |
-# Methods |
|
23 | 23 |
sub utf8_filter_on { |
24 | 24 |
my $self = shift; |
25 | 25 |
|
... | ... |
@@ -36,15 +36,19 @@ sub utf8_filter_on { |
36 | 36 |
|
37 | 37 |
DBIx::Custom::Basic - DBIx::Custom basic implementation |
38 | 38 |
|
39 |
-=head1 See DBIx::Custom documentation |
|
40 |
- |
|
41 |
-This class is L<DBIx::Custom> subclass. |
|
39 |
+=head1 SYNOPSYS |
|
42 | 40 |
|
43 |
-You can use all methods of L<DBIx::Custom> |
|
41 |
+ # New |
|
42 |
+ my $dbi = DBIx::Custom::Basic->new( |
|
43 |
+ data_source => "dbi:mysql:database=books", |
|
44 |
+ user => 'ken', |
|
45 |
+ password => '!LFKD%$&' |
|
46 |
+ ); |
|
44 | 47 |
|
45 |
-Please see L<DBIx::Custom> documentation |
|
48 |
+=head1 METHODS |
|
46 | 49 |
|
47 |
-=head1 Methods |
|
50 |
+This class is L<DBIx::Custom> subclass. |
|
51 |
+You can use all methods of L<DBIx::Custom> |
|
48 | 52 |
|
49 | 53 |
=head2 utf8_filter_on |
50 | 54 |
|
... | ... |
@@ -57,7 +61,7 @@ This equel to |
57 | 61 |
$dbi->bind_filter($dbi->filters->{encode_utf8}); |
58 | 62 |
$dbi->fetch_filter($dbi->filters->{decode_utf8}); |
59 | 63 |
|
60 |
-=head1 Available filters |
|
64 |
+=head1 FILTERS |
|
61 | 65 |
|
62 | 66 |
=head2 encode_utf8 |
63 | 67 |
|
... | ... |
@@ -79,7 +83,7 @@ This filter is generally used as fetch filter |
79 | 83 |
|
80 | 84 |
$dbi->fetch_filter($dbi->filters->{decode_utf8}); |
81 | 85 |
|
82 |
-=head2 Available formats |
|
86 |
+=head1 DATE FORMATS |
|
83 | 87 |
|
84 | 88 |
strptime formats is available |
85 | 89 |
|
... | ... |
@@ -95,19 +99,4 @@ You get format as the following |
95 | 99 |
|
96 | 100 |
my $format = $dbi->formats->{$format_name}; |
97 | 101 |
|
98 |
-=head1 AUTHOR |
|
99 |
- |
|
100 |
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
101 |
- |
|
102 |
-Github L<http://github.com/yuki-kimoto> |
|
103 |
- |
|
104 |
-I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
105 |
- |
|
106 |
-=head1 COPYRIGHT & LICENSE |
|
107 |
- |
|
108 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
109 |
- |
|
110 |
-This program is free software; you can redistribute it and/or modify it |
|
111 |
-under the same terms as Perl itself. |
|
112 |
- |
|
113 | 102 |
=cut |
... | ... |
@@ -1,8 +1,9 @@ |
1 | 1 |
package DBIx::Custom::MySQL; |
2 |
-use base 'DBIx::Custom::Basic'; |
|
3 | 2 |
|
4 | 3 |
use warnings; |
5 | 4 |
use strict; |
5 |
+ |
|
6 |
+use base 'DBIx::Custom::Basic'; |
|
6 | 7 |
use Carp 'croak'; |
7 | 8 |
|
8 | 9 |
__PACKAGE__->add_format( |
... | ... |
@@ -11,21 +12,19 @@ __PACKAGE__->add_format( |
11 | 12 |
time => __PACKAGE__->formats->{SQL99_time}, |
12 | 13 |
); |
13 | 14 |
|
14 |
- |
|
15 | 15 |
sub connect { |
16 | 16 |
my $self = shift; |
17 | 17 |
|
18 |
+ # Create data source |
|
18 | 19 |
if (!$self->data_source) { |
19 | 20 |
my $database = $self->database; |
20 | 21 |
my $host = $self->host; |
21 | 22 |
my $port = $self->port; |
22 |
- |
|
23 | 23 |
my $data_source = "dbi:mysql:"; |
24 | 24 |
my $data_source_original = $data_source; |
25 | 25 |
$data_source .= "database=$database;" if $database; |
26 | 26 |
$data_source .= "host=$host;" if $host; |
27 | 27 |
$data_source .= "port=$port;" if $port; |
28 |
- |
|
29 | 28 |
$data_source =~ s/:$// if $data_source eq $data_source_original; |
30 | 29 |
$self->data_source($data_source); |
31 | 30 |
} |
... | ... |
@@ -36,8 +35,10 @@ sub connect { |
36 | 35 |
sub last_insert_id { |
37 | 36 |
my $self = shift; |
38 | 37 |
|
38 |
+ # Not connected |
|
39 | 39 |
croak "Not yet connected" unless $self->connected; |
40 | 40 |
|
41 |
+ # Get last insert id |
|
41 | 42 |
my $last_insert_id = $self->dbh->{mysql_insertid}; |
42 | 43 |
|
43 | 44 |
return $last_insert_id; |
... | ... |
@@ -47,21 +48,16 @@ sub last_insert_id { |
47 | 48 |
|
48 | 49 |
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
49 | 50 |
|
50 |
-=head1 Synopsys |
|
51 |
+=head1 SYNOPSYS |
|
51 | 52 |
|
52 | 53 |
# New |
53 | 54 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
54 | 55 |
database => 'sample_db'); |
55 | 56 |
|
56 |
-=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first |
|
57 |
+=head1 METHODS |
|
57 | 58 |
|
58 |
-This class is L<DBIx::Custom::Basic> subclass, |
|
59 |
-and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass. |
|
60 |
- |
|
61 |
-You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom> |
|
62 |
-Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation. |
|
63 |
- |
|
64 |
-=head1 Object methods |
|
59 |
+This class is L<DBIx::Custom::Basic> subclass. |
|
60 |
+You can use all methods of L<DBIx::Custom::Basic> |
|
65 | 61 |
|
66 | 62 |
=head2 connect |
67 | 63 |
|
... | ... |
@@ -69,8 +65,6 @@ Connect to database |
69 | 65 |
|
70 | 66 |
$self->connect; |
71 | 67 |
|
72 |
-This override L<DBIx::Custom> connect. |
|
73 |
- |
|
74 | 68 |
If you set database, host, or port, data source is automatically created. |
75 | 69 |
|
76 | 70 |
=head2 last_insert_id |
... | ... |
@@ -86,19 +80,4 @@ This is equal to MySQL function |
86 | 80 |
|
87 | 81 |
last_insert_id() |
88 | 82 |
|
89 |
-=head1 Author |
|
90 |
- |
|
91 |
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
92 |
- |
|
93 |
-Github L<http://github.com/yuki-kimoto> |
|
94 |
- |
|
95 |
-I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
96 |
- |
|
97 |
-=head1 Copyright & license |
|
98 |
- |
|
99 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
100 |
- |
|
101 |
-This program is free software; you can redistribute it and/or modify it |
|
102 |
-under the same terms as Perl itself. |
|
103 |
- |
|
104 |
- |
|
83 |
+=cut |
... | ... |
@@ -1,9 +1,10 @@ |
1 | 1 |
package DBIx::Custom::Query; |
2 |
-use base 'Object::Simple'; |
|
3 | 2 |
|
4 | 3 |
use strict; |
5 | 4 |
use warnings; |
6 | 5 |
|
6 |
+use base 'Object::Simple'; |
|
7 |
+ |
|
7 | 8 |
__PACKAGE__->attr([qw/sql key_infos bind_filter fetch_filter sth/]); |
8 | 9 |
__PACKAGE__->attr(_no_bind_filters => sub { {} }); |
9 | 10 |
__PACKAGE__->attr(no_fetch_filters => sub { [] }); |
... | ... |
@@ -11,6 +12,7 @@ __PACKAGE__->attr(no_fetch_filters => sub { [] }); |
11 | 12 |
sub new { |
12 | 13 |
my $self = shift->SUPER::new(@_); |
13 | 14 |
|
15 |
+ # Initialize attributes |
|
14 | 16 |
$self->no_bind_filters($self->{no_bind_filters}) |
15 | 17 |
if $self->{no_bind_filters}; |
16 | 18 |
|
... | ... |
@@ -21,10 +23,11 @@ sub no_bind_filters { |
21 | 23 |
my $self = shift; |
22 | 24 |
|
23 | 25 |
if (@_) { |
26 |
+ # Set |
|
24 | 27 |
$self->{no_bind_filters} = $_[0]; |
25 | 28 |
|
29 |
+ # Cached |
|
26 | 30 |
my %no_bind_filters = map { $_ => 1 } @{$self->{no_bind_filters}}; |
27 |
- |
|
28 | 31 |
$self->_no_bind_filters(\%no_bind_filters); |
29 | 32 |
|
30 | 33 |
return $self; |
... | ... |
@@ -33,6 +36,8 @@ sub no_bind_filters { |
33 | 36 |
return $self->{no_bind_filters}; |
34 | 37 |
} |
35 | 38 |
|
39 |
+1; |
|
40 |
+ |
|
36 | 41 |
=head1 NAME |
37 | 42 |
|
38 | 43 |
DBIx::Custom::Query - DBIx::Custom query |
... | ... |
@@ -52,76 +57,64 @@ DBIx::Custom::Query - DBIx::Custom query |
52 | 57 |
$query->fetch_filter($dbi->filters->{default_fetch_filter}); |
53 | 58 |
$query->no_fetch_filters('title', 'author'); |
54 | 59 |
|
55 |
-=head1 Accessors |
|
60 |
+=head1 ATTRIBUTES |
|
56 | 61 |
|
57 | 62 |
=head2 sth |
58 | 63 |
|
59 |
-Set and get statement handle |
|
64 |
+Statement handle |
|
60 | 65 |
|
61 | 66 |
$query = $query->sth($sth); |
62 | 67 |
$sth = $query->sth; |
63 | 68 |
|
64 | 69 |
=head2 sql |
65 | 70 |
|
66 |
-Set and get SQL |
|
71 |
+SQL |
|
67 | 72 |
|
68 | 73 |
$query = $query->sql($sql); |
69 | 74 |
$sql = $query->sql; |
70 | 75 |
|
71 | 76 |
=head2 bind_filter |
72 | 77 |
|
73 |
-Set and get bind filter |
|
78 |
+Filter excuted when value is bind |
|
74 | 79 |
|
75 | 80 |
$query = $query->bind_filter($bind_filter); |
76 | 81 |
$bind_filter = $query->bind_filter; |
77 | 82 |
|
78 | 83 |
=head2 no_bind_filters |
79 | 84 |
|
80 |
-Set and get keys of no filtering |
|
85 |
+Key list which dose not have to bind filtering |
|
81 | 86 |
|
82 | 87 |
$query = $query->no_bind_filters($no_filters); |
83 | 88 |
$no_bind_filters = $query->no_bind_filters; |
84 | 89 |
|
85 | 90 |
=head2 fetch_filter |
86 | 91 |
|
87 |
-Set and get fetch filter |
|
92 |
+Filter excuted when data is fetched |
|
88 | 93 |
|
89 | 94 |
$query = $query->fetch_filter($fetch_filter); |
90 | 95 |
$fetch_filter = $query->fetch_filter; |
91 | 96 |
|
92 | 97 |
=head2 no_fetch_filters |
93 | 98 |
|
94 |
-Set and get keys of no filtering |
|
99 |
+Key list which dose not have to fetch filtering |
|
95 | 100 |
|
96 | 101 |
$query = $query->no_fetch_filters($no_filters); |
97 | 102 |
$no_fetch_filters = $query->no_fetch_filters; |
98 | 103 |
|
99 | 104 |
=head2 key_infos |
100 | 105 |
|
101 |
-Set and get key informations |
|
106 |
+Key informations |
|
102 | 107 |
|
103 | 108 |
$query = $query->key_infos($key_infos); |
104 | 109 |
$key_infos = $query->key_infos; |
105 | 110 |
|
106 |
-=head1 Methods |
|
111 |
+=head1 METHODS |
|
112 |
+ |
|
113 |
+This class is L<Object::Simple> subclass. |
|
114 |
+You can use all methods of L<Object::Simple> |
|
107 | 115 |
|
108 | 116 |
=head2 new |
109 | 117 |
|
110 | 118 |
my $query = DBIx::Custom::Query->new; |
111 |
- |
|
112 |
-=head1 AUTHOR |
|
113 |
- |
|
114 |
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
115 |
- |
|
116 |
-Github L<http://github.com/yuki-kimoto> |
|
117 |
- |
|
118 |
-=head1 COPYRIGHT & LICENSE |
|
119 |
- |
|
120 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
121 |
- |
|
122 |
-This program is free software; you can redistribute it and/or modify it |
|
123 |
-under the same terms as Perl itself. |
|
124 | 119 |
|
125 | 120 |
=cut |
126 |
- |
|
127 |
-1; |
... | ... |
@@ -1,8 +1,9 @@ |
1 | 1 |
package DBIx::Custom::Result; |
2 |
-use base 'Object::Simple'; |
|
3 | 2 |
|
4 | 3 |
use strict; |
5 | 4 |
use warnings; |
5 |
+ |
|
6 |
+use base 'Object::Simple'; |
|
6 | 7 |
use Carp 'croak'; |
7 | 8 |
|
8 | 9 |
__PACKAGE__->attr([qw/_dbi sth fetch_filter/]); |
... | ... |
@@ -11,6 +12,7 @@ __PACKAGE__->attr(_no_fetch_filters => sub { {} }); |
11 | 12 |
sub new { |
12 | 13 |
my $self = shift->SUPER::new(@_); |
13 | 14 |
|
15 |
+ # Initialize attributes |
|
14 | 16 |
$self->no_fetch_filters($self->{no_fetch_filters}) |
15 | 17 |
if exists $self->{no_fetch_filters}; |
16 | 18 |
|
... | ... |
@@ -22,10 +24,11 @@ sub no_fetch_filters { |
22 | 24 |
|
23 | 25 |
if (@_) { |
24 | 26 |
|
27 |
+ # Set |
|
25 | 28 |
$self->{no_fetch_filters} = $_[0]; |
26 | 29 |
|
30 |
+ # Cached |
|
27 | 31 |
my %no_fetch_filters = map {$_ => 1} @{$self->{no_fetch_filters}}; |
28 |
- |
|
29 | 32 |
$self->_no_fetch_filters(\%no_fetch_filters); |
30 | 33 |
|
31 | 34 |
return $self; |
... | ... |
@@ -172,6 +175,7 @@ sub fetch_hash_rows { |
172 | 175 |
sub fetch_all { |
173 | 176 |
my $self = shift; |
174 | 177 |
|
178 |
+ # Fetch all rows |
|
175 | 179 |
my $rows = []; |
176 | 180 |
while(my @row = $self->fetch) { |
177 | 181 |
push @$rows, [@row]; |
... | ... |
@@ -182,6 +186,7 @@ sub fetch_all { |
182 | 186 |
sub fetch_hash_all { |
183 | 187 |
my $self = shift; |
184 | 188 |
|
189 |
+ # Fetch all rows as hash |
|
185 | 190 |
my $rows = []; |
186 | 191 |
while(my %row = $self->fetch_hash) { |
187 | 192 |
push @$rows, {%row}; |
... | ... |
@@ -193,15 +198,20 @@ sub finish { shift->sth->finish } |
193 | 198 |
|
194 | 199 |
sub error { |
195 | 200 |
my $self = shift; |
201 |
+ |
|
202 |
+ # Statement handle |
|
196 | 203 |
my $sth = $self->sth; |
204 |
+ |
|
197 | 205 |
return wantarray ? ($sth->errstr, $sth->err, $sth->state) : $sth->errstr; |
198 | 206 |
} |
199 | 207 |
|
208 |
+1; |
|
209 |
+ |
|
200 | 210 |
=head1 NAME |
201 | 211 |
|
202 | 212 |
DBIx::Custom::Result - DBIx::Custom Resultset |
203 | 213 |
|
204 |
-=head1 Synopsis |
|
214 |
+=head1 SYNOPSIS |
|
205 | 215 |
|
206 | 216 |
my $result = $dbi->query($query); |
207 | 217 |
|
... | ... |
@@ -215,30 +225,33 @@ DBIx::Custom::Result - DBIx::Custom Resultset |
215 | 225 |
# Do something |
216 | 226 |
} |
217 | 227 |
|
218 |
-=head1 Accessors |
|
228 |
+=head1 ATTRIBUTES |
|
219 | 229 |
|
220 | 230 |
=head2 sth |
221 | 231 |
|
222 |
-Set and Get statement handle |
|
232 |
+Statement handle |
|
223 | 233 |
|
224 | 234 |
$result = $result->sth($sth); |
225 | 235 |
$sth = $reuslt->sth |
226 | 236 |
|
227 | 237 |
=head2 fetch_filter |
228 | 238 |
|
229 |
-Set and Get fetch filter |
|
239 |
+Filter excuted when data is fetched |
|
230 | 240 |
|
231 | 241 |
$result = $result->fetch_filter($sth); |
232 | 242 |
$fetch_filter = $result->fech_filter; |
233 | 243 |
|
234 | 244 |
=head2 no_fetch_filters |
235 | 245 |
|
236 |
-Set and Get no filter keys when fetching |
|
246 |
+Key list which dose not have to fetch filtering |
|
237 | 247 |
|
238 | 248 |
$result = $result->no_fetch_filters($no_fetch_filters); |
239 | 249 |
$no_fetch_filters = $result->no_fetch_filters; |
240 | 250 |
|
241 |
-=head1 Methods |
|
251 |
+=head1 METHODS |
|
252 |
+ |
|
253 |
+This class is L<Object::Simple> subclass. |
|
254 |
+You can use all methods of L<Object::Simple> |
|
242 | 255 |
|
243 | 256 |
=head2 new |
244 | 257 |
|
... | ... |
@@ -372,23 +385,4 @@ This is equel to |
372 | 385 |
|
373 | 386 |
$result->sth->finish; |
374 | 387 |
|
375 |
-=head1 See also |
|
376 |
- |
|
377 |
-L<DBIx::Custom> |
|
378 |
- |
|
379 |
-=head1 Author |
|
380 |
- |
|
381 |
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
382 |
- |
|
383 |
-Github L<http://github.com/yuki-kimoto> |
|
384 |
- |
|
385 |
-=head1 Copyright & licence |
|
386 |
- |
|
387 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
388 |
- |
|
389 |
-This program is free software; you can redistribute it and/or modify it |
|
390 |
-under the same terms as Perl itself. |
|
391 |
- |
|
392 | 388 |
=cut |
393 |
- |
|
394 |
-1; |
... | ... |
@@ -1,10 +1,10 @@ |
1 | 1 |
package DBIx::Custom::SQL::Template; |
2 |
-use base 'Object::Simple'; |
|
3 | 2 |
|
4 | 3 |
use strict; |
5 | 4 |
use warnings; |
6 |
-use Carp 'croak'; |
|
7 | 5 |
|
6 |
+use base 'Object::Simple'; |
|
7 |
+use Carp 'croak'; |
|
8 | 8 |
use DBIx::Custom::Query; |
9 | 9 |
|
10 | 10 |
__PACKAGE__->dual_attr('tag_processors', default => sub { {} }, |
... | ... |
@@ -48,7 +48,6 @@ __PACKAGE__->tag_syntax(<< 'EOS'); |
48 | 48 |
EOS |
49 | 49 |
|
50 | 50 |
|
51 |
-# Add Tag processor |
|
52 | 51 |
sub add_tag_processor { |
53 | 52 |
my $invocant = shift; |
54 | 53 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
... | ... |
@@ -56,7 +55,6 @@ sub add_tag_processor { |
56 | 55 |
return $invocant; |
57 | 56 |
} |
58 | 57 |
|
59 |
-# Clone |
|
60 | 58 |
sub clone { |
61 | 59 |
my $self = shift; |
62 | 60 |
my $new = $self->new; |
... | ... |
@@ -69,10 +67,6 @@ sub clone { |
69 | 67 |
return $new; |
70 | 68 |
} |
71 | 69 |
|
72 |
- |
|
73 |
-### Object Methods |
|
74 |
- |
|
75 |
-# Create Query |
|
76 | 70 |
sub create_query { |
77 | 71 |
my ($self, $template) = @_; |
78 | 72 |
|
... | ... |
@@ -85,7 +79,6 @@ sub create_query { |
85 | 79 |
return $query; |
86 | 80 |
} |
87 | 81 |
|
88 |
-# Parse template |
|
89 | 82 |
sub _parse_template { |
90 | 83 |
my ($self, $template) = @_; |
91 | 84 |
$template ||= ''; |
... | ... |
@@ -142,7 +135,6 @@ sub _parse_template { |
142 | 135 |
return $tree; |
143 | 136 |
} |
144 | 137 |
|
145 |
-# Build SQL from parsing tree |
|
146 | 138 |
sub _build_query { |
147 | 139 |
my ($self, $tree) = @_; |
148 | 140 |
|
... | ... |
@@ -206,7 +198,6 @@ sub _build_query { |
206 | 198 |
return $query; |
207 | 199 |
} |
208 | 200 |
|
209 |
-# Get placeholder count |
|
210 | 201 |
sub _placeholder_count { |
211 | 202 |
my ($self, $expand) = @_; |
212 | 203 |
$expand ||= ''; |
... | ... |
@@ -221,7 +212,6 @@ sub _placeholder_count { |
221 | 212 |
|
222 | 213 |
1; |
223 | 214 |
|
224 |
- |
|
225 | 215 |
package DBIx::Custom::SQL::Template::TagProcessors; |
226 | 216 |
|
227 | 217 |
use strict; |
... | ... |
@@ -457,13 +447,15 @@ sub expand_update_tag { |
457 | 447 |
return ($expand, $key_infos); |
458 | 448 |
} |
459 | 449 |
|
450 |
+package DBIx::Custom::SQL::Template; |
|
451 |
+ |
|
460 | 452 |
1; |
461 | 453 |
|
462 | 454 |
=head1 NAME |
463 | 455 |
|
464 | 456 |
DBIx::Custom::SQL::Template - DBIx::Custom SQL Template |
465 | 457 |
|
466 |
-=head1 Synopsis |
|
458 |
+=head1 SYNOPSIS |
|
467 | 459 |
|
468 | 460 |
my $sql_tmpl = DBIx::Custom::SQL::Template->new; |
469 | 461 |
|
... | ... |
@@ -472,42 +464,37 @@ DBIx::Custom::SQL::Template - DBIx::Custom SQL Template |
472 | 464 |
|
473 | 465 |
my $query = $sql_template->create_query($tmpl); |
474 | 466 |
|
475 |
-=head1 Accessors |
|
467 |
+=head1 ATTRIBUTES |
|
476 | 468 |
|
477 | 469 |
=head2 tag_processors |
478 | 470 |
|
479 |
-Set and get tag processors |
|
480 |
- |
|
481 | 471 |
$sql_tmpl = $sql_tmpl->tag_processors($name1 => $tag_processor1 |
482 | 472 |
$name2 => $tag_processor2); |
483 | 473 |
$tag_processors = $sql_tmpl->tag_processors; |
484 | 474 |
|
485 | 475 |
=head2 tag_start |
486 |
- |
|
487 |
-Set and get start tag |
|
488 | 476 |
|
489 | 477 |
$sql_tmpl = $sql_tmpl->tag_start('{'); |
490 | 478 |
$tag_start = $sql_tmpl->tag_start; |
491 | 479 |
|
492 |
-tag_start default is '{' |
|
480 |
+Default is '{' |
|
493 | 481 |
|
494 | 482 |
=head2 tag_end |
495 |
- |
|
496 |
-Set and get end tag |
|
497 | 483 |
|
498 | 484 |
$sql_tmpl = $sql_tmpl->tag_start('}'); |
499 | 485 |
$tag_end = $sql_tmpl->tag_start; |
500 | 486 |
|
501 |
-tag_start default is '}' |
|
487 |
+Default is '}' |
|
502 | 488 |
|
503 | 489 |
=head2 tag_syntax |
504 | 490 |
|
505 |
-Set and get tag syntax |
|
506 |
- |
|
507 | 491 |
$sql_tmpl = $sql_tmpl->tag_syntax($tag_syntax); |
508 | 492 |
$tag_syntax = $sql_tmpl->tag_syntax; |
509 | 493 |
|
510 |
-=head1 Methods |
|
494 |
+=head1 METHODS |
|
495 |
+ |
|
496 |
+This class is L<Object::Simple> subclass. |
|
497 |
+You can use all methods of L<Object::Simple> |
|
511 | 498 |
|
512 | 499 |
=head2 create_query |
513 | 500 |
|
... | ... |
@@ -625,25 +612,4 @@ The following is update SQL sample |
625 | 612 |
# Expanded |
626 | 613 |
$query->sql : "update table set key1 = ?, key2 = ? where key3 = ?;" |
627 | 614 |
|
628 |
-=head1 AUTHOR |
|
629 |
- |
|
630 |
-Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
631 |
- |
|
632 |
-Github |
|
633 |
-L<http://github.com/yuki-kimoto> |
|
634 |
-L<http://github.com/yuki-kimoto/DBIx-Custom-SQL-Template> |
|
635 |
- |
|
636 |
-Please let know me bag if you find |
|
637 |
-Please request me if you want to do something |
|
638 |
- |
|
639 |
-=head1 COPYRIGHT & LICENSE |
|
640 |
- |
|
641 |
-Copyright 2009 Yuki Kimoto, all rights reserved. |
|
642 |
- |
|
643 |
-This program is free software; you can redistribute it and/or modify it |
|
644 |
-under the same terms as Perl itself. |
|
645 |
- |
|
646 |
- |
|
647 | 615 |
=cut |
648 |
- |
|
649 |
-1; # End of DBIx::Custom::SQL::Template |