... | ... |
@@ -1,3 +1,7 @@ |
1 |
+0.1611 |
|
2 |
+ renamed update tag to update_param |
|
3 |
+ renamed insert tag to insert_param |
|
4 |
+ renamed sql_builder to query_builder |
|
1 | 5 |
0.1610 |
2 | 6 |
added filter_check attribute. |
3 | 7 |
0.1609 |
... | ... |
@@ -24,7 +24,7 @@ __PACKAGE__->register_filter( |
24 | 24 |
); |
25 | 25 |
|
26 | 26 |
__PACKAGE__->attr(result_class => 'DBIx::Custom::Result'); |
27 |
-__PACKAGE__->attr(sql_builder => sub {DBIx::Custom::QueryBuilder->new}); |
|
27 |
+__PACKAGE__->attr(query_builder => sub {DBIx::Custom::QueryBuilder->new}); |
|
28 | 28 |
|
29 | 29 |
__PACKAGE__->attr(cache => 1); |
30 | 30 |
__PACKAGE__->attr(cache_method => sub { |
... | ... |
@@ -107,7 +107,7 @@ sub insert { |
107 | 107 |
my @insert_keys = keys %$param; |
108 | 108 |
|
109 | 109 |
# Templte for insert |
110 |
- my $source = "insert into $table {insert " |
|
110 |
+ my $source = "insert into $table {insert_param " |
|
111 | 111 |
. join(' ', @insert_keys) . '}'; |
112 | 112 |
$source .= " $append" if $append; |
113 | 113 |
|
... | ... |
@@ -149,7 +149,7 @@ sub update { |
149 | 149 |
if !@where_keys && !$allow_update_all; |
150 | 150 |
|
151 | 151 |
# Update clause |
152 |
- my $update_clause = '{update ' . join(' ', @update_keys) . '}'; |
|
152 |
+ my $update_clause = '{update_param ' . join(' ', @update_keys) . '}'; |
|
153 | 153 |
|
154 | 154 |
# Where clause |
155 | 155 |
my $where_clause = ''; |
... | ... |
@@ -339,7 +339,7 @@ sub create_query { |
339 | 339 |
unless ($query) { |
340 | 340 |
|
341 | 341 |
# Create SQL object |
342 |
- my $builder = $self->sql_builder; |
|
342 |
+ my $builder = $self->query_builder; |
|
343 | 343 |
|
344 | 344 |
# Create query |
345 | 345 |
$query = eval{$builder->build_query($source)}; |
... | ... |
@@ -489,7 +489,7 @@ DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
489 | 489 |
|
490 | 490 |
=cut |
491 | 491 |
|
492 |
-our $VERSION = '0.1610'; |
|
492 |
+our $VERSION = '0.1611'; |
|
493 | 493 |
|
494 | 494 |
=head1 STABILITY |
495 | 495 |
|
... | ... |
@@ -501,25 +501,25 @@ Method name and implementations will be changed for a while. |
501 | 501 |
Connect to the database. |
502 | 502 |
|
503 | 503 |
use DBIx::Custom; |
504 |
- my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
|
504 |
+ my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
505 | 505 |
user => 'ken', password => '!LFKD%$&'); |
506 | 506 |
|
507 | 507 |
Insert, update, and delete |
508 | 508 |
|
509 | 509 |
# Insert |
510 | 510 |
$dbi->insert(table => 'books', |
511 |
- param => {title => 'perl', author => 'Ken'}, |
|
511 |
+ param => {title => 'Perl', author => 'Ken'}, |
|
512 | 512 |
filter => {title => 'encode_utf8'}); |
513 | 513 |
|
514 | 514 |
# Update |
515 | 515 |
$dbi->update(table => 'books', |
516 |
- param => {title => 'aaa', author => 'Ken'}, |
|
516 |
+ param => {title => 'Perl', author => 'Ken'}, |
|
517 | 517 |
where => {id => 5}, |
518 | 518 |
filter => {title => 'encode_utf8'}); |
519 | 519 |
|
520 | 520 |
# Update all |
521 | 521 |
$dbi->update_all(table => 'books', |
522 |
- param => {title => 'aaa'}, |
|
522 |
+ param => {title => 'Perl'}, |
|
523 | 523 |
filter => {title => 'encode_utf8'}); |
524 | 524 |
|
525 | 525 |
# Delete |
... | ... |
@@ -595,7 +595,7 @@ Fetch row. |
595 | 595 |
|
596 | 596 |
} |
597 | 597 |
|
598 |
-=head1 DESCRIPTION |
|
598 |
+=head1 DESCRIPTIONS |
|
599 | 599 |
|
600 | 600 |
=head2 1. Features |
601 | 601 |
|
... | ... |
@@ -616,33 +616,37 @@ to execute SQL easily. |
616 | 616 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
617 | 617 |
but de-facto standard, |
618 | 618 |
so all people learing database know it. |
619 |
-If you know SQL, |
|
620 |
-you learn a little thing to do your works, using L<DBIx::Custom> |
|
619 |
+If you already know SQL, |
|
620 |
+you learn a little thing to use L<DBIx::Custom>. |
|
621 | 621 |
|
622 |
-=head2 1. Connect to the database |
|
622 |
+=head2 2. Connect to the database |
|
623 | 623 |
|
624 | 624 |
C<connect()> method create a new L<DBIx::Custom> |
625 | 625 |
object and connect to the database. |
626 | 626 |
|
627 | 627 |
use DBIx::Custom; |
628 |
- my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
|
628 |
+ my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
629 | 629 |
user => 'ken', password => '!LFKD%$&'); |
630 | 630 |
|
631 |
-If database is SQLite, use L<DBIx::Custom::SQLite>. you connect database easy way. |
|
631 |
+If database is SQLite, use L<DBIx::Custom::SQLite> instead. |
|
632 |
+you connect database easily. |
|
632 | 633 |
|
633 | 634 |
use DBIx::Custom::SQLite; |
634 |
- my $dbi = DBIx::Custom->connect(database => 'books'); |
|
635 |
+ my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
|
635 | 636 |
|
636 | 637 |
If database is MySQL, use L<DBIx::Costom::MySQL>. |
637 | 638 |
|
638 | 639 |
use DBIx::Custom::MySQL; |
639 |
- my $dbi = DBIx::Custom->connect(database => 'books', |
|
640 |
- user => 'ken', password => '!LFKD%$&'); |
|
640 |
+ my $dbi = DBIx::Custom::MySQL->connect( |
|
641 |
+ database => 'dbname', |
|
642 |
+ user => 'ken', |
|
643 |
+ password => '!LFKD%$&' |
|
644 |
+ ); |
|
641 | 645 |
|
642 |
-=head2 2. Suger methods |
|
646 |
+=head2 3. Suger methods |
|
643 | 647 |
|
644 | 648 |
L<DBIx::Custom> has suger methods, such as C<insert()>, C<update()>, |
645 |
-C<delete()> and C<select()>. If you want to do small works, |
|
649 |
+C<delete()> or C<select()>. If you want to do small works, |
|
646 | 650 |
You don't have to create SQL statements. |
647 | 651 |
|
648 | 652 |
=head3 insert() |
... | ... |
@@ -650,35 +654,35 @@ You don't have to create SQL statements. |
650 | 654 |
Execute insert statement. |
651 | 655 |
|
652 | 656 |
$dbi->insert(table => 'books', |
653 |
- param => {title => 'perl', author => 'Ken'}); |
|
657 |
+ param => {title => 'Perl', author => 'Ken'}); |
|
654 | 658 |
|
655 | 659 |
The following SQL is executed. |
656 | 660 |
|
657 | 661 |
insert into (title, author) values (?, ?); |
658 | 662 |
|
659 |
-The values of C<title> and C<author> is embedded into placeholders. |
|
663 |
+The values of C<title> and C<author> is embedded into the placeholders. |
|
660 | 664 |
|
661 |
-C<append> and C<filter> argument can be specified |
|
662 |
-to C<insert()> method if you need. |
|
665 |
+C<append> and C<filter> argument can be specified. |
|
666 |
+See also "METHODS" section. |
|
663 | 667 |
|
664 | 668 |
=head3 update() |
665 | 669 |
|
666 | 670 |
Execute update statement. |
667 | 671 |
|
668 | 672 |
$dbi->update(table => 'books', |
669 |
- param => {title => 'aaa', author => 'Ken'}, |
|
673 |
+ param => {title => 'Perl', author => 'Ken'}, |
|
670 | 674 |
where => {id => 5}); |
671 | 675 |
|
672 | 676 |
The following SQL is executed. |
673 | 677 |
|
674 | 678 |
update books set title = ?, author = ?; |
675 | 679 |
|
676 |
-The values of C<title> and C<author> is embedded into placeholders. |
|
680 |
+The values of C<title> and C<author> is embedded into the placeholders. |
|
677 | 681 |
|
678 |
-C<append> and C<filter> argument can be specified |
|
679 |
-to C<update()> method if you need. |
|
682 |
+C<append> and C<filter> argument can be specified. |
|
683 |
+See also "METHOD" section. |
|
680 | 684 |
|
681 |
-If you want to update all rows, use C<update_all()> method instead. |
|
685 |
+If you want to update all rows, use C<update_all()> method. |
|
682 | 686 |
|
683 | 687 |
=head3 delete() |
684 | 688 |
|
... | ... |
@@ -693,10 +697,10 @@ The following SQL is executed. |
693 | 697 |
|
694 | 698 |
The value of C<id> is embedded into the placehodler. |
695 | 699 |
|
696 |
-C<append> and C<filter> argument can be specified |
|
697 |
-to C<delete()> method if you need. |
|
700 |
+C<append> and C<filter> argument can be specified. |
|
701 |
+see also "METHODS" section. |
|
698 | 702 |
|
699 |
-If you want to delete all rows, use C<delete_all()> method instead. |
|
703 |
+If you want to delete all rows, use C<delete_all()> method. |
|
700 | 704 |
|
701 | 705 |
=head3 select() |
702 | 706 |
|
... | ... |
@@ -709,7 +713,7 @@ The following SQL is executed. |
709 | 713 |
select * from books; |
710 | 714 |
|
711 | 715 |
the result of C<select()> method is L<DBIx::Custom::Result> object. |
712 |
-You can fetch row. |
|
716 |
+You can fetch a row by C<fetch()> method. |
|
713 | 717 |
|
714 | 718 |
while (my $row = $result->fetch) { |
715 | 719 |
my $title = $row->[0]; |
... | ... |
@@ -717,20 +721,21 @@ You can fetch row. |
717 | 721 |
} |
718 | 722 |
|
719 | 723 |
L<DBIx::Custom::Result> has various methods to fetch row. |
720 |
-See "3. Fetch row". |
|
724 |
+See "4. Fetch row". |
|
721 | 725 |
|
722 |
-Specify C<column> and C<where> arguments. |
|
726 |
+C<column> and C<where> arguments specified. |
|
723 | 727 |
|
724 | 728 |
my $result = $dbi->select( |
725 | 729 |
table => 'books', |
726 | 730 |
column => [qw/author title/], |
727 |
- where => {author => 'Ken'}); |
|
731 |
+ where => {author => 'Ken'} |
|
732 |
+ ); |
|
728 | 733 |
|
729 | 734 |
The following SQL is executed. |
730 | 735 |
|
731 | 736 |
select author, title from books where author = ?; |
732 | 737 |
|
733 |
-the value of C<author> is embdded into placeholder. |
|
738 |
+the value of C<author> is embdded into the placeholder. |
|
734 | 739 |
|
735 | 740 |
If you want to join tables, specify C<relation> argument. |
736 | 741 |
|
... | ... |
@@ -742,13 +747,12 @@ If you want to join tables, specify C<relation> argument. |
742 | 747 |
|
743 | 748 |
The following SQL is executed. |
744 | 749 |
|
745 |
- select books.name as book_name from books |
|
750 |
+ select books.name as book_name from books, rental |
|
746 | 751 |
where books.id = rental.book_id; |
747 | 752 |
|
748 |
-C<append> argument add a string to the end of SQL statement. |
|
749 |
-You can add "order by" or "limit" cluase. |
|
753 |
+If you want to add some string to the end of SQL statement, |
|
754 |
+use C<append> argument. |
|
750 | 755 |
|
751 |
- # Select, more complex |
|
752 | 756 |
my $result = $dbi->select( |
753 | 757 |
table => 'books', |
754 | 758 |
where => {author => 'Ken'}, |
... | ... |
@@ -759,13 +763,15 @@ The following SQL is executed. |
759 | 763 |
|
760 | 764 |
select * books where author = ? order by price limit 5; |
761 | 765 |
|
762 |
-C<filter> argument can be specified to filter parameters |
|
763 |
-if you need. |
|
766 |
+C<filter> argument can be specified. |
|
767 |
+see also "METHODS" section. |
|
764 | 768 |
|
765 |
-=head2 3. Fetch row |
|
769 |
+=head2 4. Fetch row |
|
766 | 770 |
|
767 | 771 |
C<select()> method return L<DBIx::Custom::Result> object. |
768 | 772 |
You can fetch row by various methods. |
773 |
+Note that in this section, array means array reference, |
|
774 |
+and hash meanse hash reference. |
|
769 | 775 |
|
770 | 776 |
Fetch row into array. |
771 | 777 |
|
... | ... |
@@ -820,15 +826,15 @@ Fetch all rows into array of hash |
820 | 826 |
|
821 | 827 |
my $rows = $result->fetch_hash_all; |
822 | 828 |
|
823 |
-If you want to access raw statement handle of L<DBI>, use C<sth()> attribute. |
|
829 |
+If you want to access statement handle of L<DBI>, use C<sth()> attribute. |
|
824 | 830 |
|
825 | 831 |
my $sth = $result->sth; |
826 | 832 |
|
827 |
-=head2 4. Hash parameter binding |
|
833 |
+=head2 5. Hash parameter binding |
|
828 | 834 |
|
829 | 835 |
L<DBIx::Custom> provides hash parameter binding. |
830 | 836 |
|
831 |
-At frist, I show normal way of parameter binding. |
|
837 |
+At frist, I show normal parameter binding. |
|
832 | 838 |
|
833 | 839 |
use DBI; |
834 | 840 |
my $dbh = DBI->connect(...); |
... | ... |
@@ -838,10 +844,10 @@ At frist, I show normal way of parameter binding. |
838 | 844 |
$sth->execute('Ken', '%Perl%'); |
839 | 845 |
|
840 | 846 |
This is very good way because database system can enable SQL caching, |
841 |
-and parameter is quoted automatically, it is secure. |
|
847 |
+and parameter is quoted automatically. this is secure. |
|
842 | 848 |
|
843 | 849 |
L<DBIx::Custom> hash parameter binding system improve |
844 |
-normal parameter binding way to specify hash parameter. |
|
850 |
+normal parameter binding to use hash parameter. |
|
845 | 851 |
|
846 | 852 |
my $result = $dbi->execute( |
847 | 853 |
"select * from books where {= author} and {like title};" |
... | ... |
@@ -849,15 +855,12 @@ normal parameter binding way to specify hash parameter. |
849 | 855 |
); |
850 | 856 |
|
851 | 857 |
This is same as the normal way, execpt that the parameter is hash. |
852 |
-{= author} is called C<tag>. tag is expand to placeholder string internally. |
|
858 |
+{= author} and {like title} is called C<tag>. |
|
859 |
+tag is expand to placeholder string internally. |
|
853 | 860 |
|
854 | 861 |
select * from books where {= author} and {like title} |
855 | 862 |
-> select * from books where author = ? and title like ?; |
856 | 863 |
|
857 |
-The following tags is available. |
|
858 |
- |
|
859 |
-=head1 Tags |
|
860 |
- |
|
861 | 864 |
The following tags is available. |
862 | 865 |
|
863 | 866 |
[TAG] [REPLACED] |
... | ... |
@@ -873,8 +876,8 @@ The following tags is available. |
873 | 876 |
{like NAME} -> NAME like ? |
874 | 877 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
875 | 878 |
|
876 |
- {insert NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
877 |
- {update NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
879 |
+ {insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
880 |
+ {update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
878 | 881 |
|
879 | 882 |
See also L<DBIx::Custom::QueryBuilder>. |
880 | 883 |
|
... | ... |
@@ -884,7 +887,7 @@ You can change this tag. |
884 | 887 |
$dbi->query_builder->start_tag('|'); |
885 | 888 |
$dbi->query_builder->end_tag('|'); |
886 | 889 |
|
887 |
-=head2 5. Filtering |
|
890 |
+=head2 6. Filtering |
|
888 | 891 |
|
889 | 892 |
Usually, Perl string is kept as internal string. |
890 | 893 |
If you want to save the string to database, You must encode the string. |
... | ... |
@@ -910,13 +913,16 @@ You can specify these filters to C<filter> argument of C<execute()> method. |
910 | 913 |
filter => {author => 'to_upper_case, title => 'encode_utf8'} |
911 | 914 |
); |
912 | 915 |
|
913 |
-you can also specify filter in suger methods, such as select(), update(), update_all, |
|
914 |
-delete(), delete_all(), select(). |
|
916 |
+C<filter> argument can be specified to suger methods, such as |
|
917 |
+C<insert()>, C<update()>, C<update_all>, |
|
918 |
+C<delete()>, C<delete_all()>, C<select()>. |
|
915 | 919 |
|
920 |
+ # insert(), having filter argument |
|
916 | 921 |
$dbi->insert(table => 'books', |
917 |
- param => {title => 'perl', author => 'Ken'}, |
|
922 |
+ param => {title => 'Perl', author => 'Ken'}, |
|
918 | 923 |
filter => {title => 'encode_utf8'}); |
919 |
- |
|
924 |
+ |
|
925 |
+ # select(), having filter argument |
|
920 | 926 |
my $result = $dbi->select( |
921 | 927 |
table => 'books', |
922 | 928 |
column => [qw/author title/], |
... | ... |
@@ -929,20 +935,20 @@ Filter works each parmeter, but you prepare default filter for all parameters. |
929 | 935 |
|
930 | 936 |
$dbi->default_bind_filter('encode_utf8'); |
931 | 937 |
|
932 |
-C<filter()> argument overwrites the filter specified by C<default_bind_filter()>. |
|
938 |
+C<filter()> argument overwrites this default filter. |
|
933 | 939 |
|
934 | 940 |
$dbi->default_bind_filter('encode_utf8'); |
935 | 941 |
$dbi->insert( |
936 | 942 |
table => 'books', |
937 |
- param => {title => 'perl', author => 'Ken', price => 1000}, |
|
943 |
+ param => {title => 'Perl', author => 'Ken', price => 1000}, |
|
938 | 944 |
filter => {author => 'to_upper_case', price => undef} |
939 | 945 |
); |
940 | 946 |
|
941 |
-This is same as the following one. |
|
947 |
+This is same as the following example. |
|
942 | 948 |
|
943 | 949 |
$dbi->insert( |
944 | 950 |
table => 'books', |
945 |
- param => {title => 'perl', author => 'Ken', price => 1000}, |
|
951 |
+ param => {title => 'Perl', author => 'Ken', price => 1000}, |
|
946 | 952 |
filter => {title => 'encode_uft8' author => 'to_upper_case'} |
947 | 953 |
); |
948 | 954 |
|
... | ... |
@@ -951,12 +957,13 @@ You can also specify filter when the row is fetched. This is reverse of bind fil |
951 | 957 |
my $result = $dbi->select(table => 'books'); |
952 | 958 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
953 | 959 |
|
954 |
-you can specify C<default_fetch_filter()>. |
|
960 |
+Filter works each column value, but you prepare a default filter |
|
961 |
+for all clumn value. |
|
955 | 962 |
|
956 | 963 |
$dbi->default_fetch_filter('decode_utf8'); |
957 | 964 |
|
958 |
-C<DBIx::Custom::Result::filter()> overwrites the filter specified |
|
959 |
-by C<default_fetch_filter()> |
|
965 |
+C<filter()> method of L<DBIx::Custom::Result> |
|
966 |
+overwrites this default filter. |
|
960 | 967 |
|
961 | 968 |
$dbi->default_fetch_filter('decode_utf8'); |
962 | 969 |
my $result = $dbi->select( |
... | ... |
@@ -973,21 +980,27 @@ This is same as the following one. |
973 | 980 |
); |
974 | 981 |
$result->filter({title => 'decode_utf8', author => 'to_upper_case'}); |
975 | 982 |
|
976 |
-In fetch filter, column name must be lower case even if column conatain upper case charactor. This is requirment not to depend database systems. |
|
983 |
+Note that in fetch filter, column names must be lower case |
|
984 |
+even if the column name conatains upper case charactors. |
|
985 |
+This is requirment not to depend database systems. |
|
977 | 986 |
|
978 |
-=head2 6. Performance |
|
987 |
+=head2 7. Performance |
|
979 | 988 |
|
980 | 989 |
=head3 Disable filter checking |
981 | 990 |
|
982 |
-C<filter_check> is 1 by defaut. This is useful in debug. |
|
991 |
+Filter checking is executed by default. |
|
992 |
+This is done to check right filter name is specified, |
|
993 |
+but sometimes damage performance. |
|
983 | 994 |
|
984 |
-This filter check maybe damege performance. |
|
985 |
-If you require performance, set C<filter_check> to 0. |
|
995 |
+If you disable this filter checking, |
|
996 |
+Set C<filter_check> attribute to 0. |
|
986 | 997 |
|
987 |
-=head3 Using execute() method instead suger methods |
|
998 |
+ $dbi->filter_check(0); |
|
988 | 999 |
|
989 |
-If you execute insert statement by using select() method, |
|
990 |
-you sometimes can't meet performance requirment. |
|
1000 |
+=head3 Use execute() method instead suger methods |
|
1001 |
+ |
|
1002 |
+If you execute insert statement by C<insert()> method, |
|
1003 |
+you sometimes can't get required performance. |
|
991 | 1004 |
|
992 | 1005 |
C<insert()> method is a little slow because SQL statement and statement handle |
993 | 1006 |
is created every time. |
... | ... |
@@ -995,14 +1008,9 @@ is created every time. |
995 | 1008 |
In that case, you can prepare a query by C<create_query()> method. |
996 | 1009 |
|
997 | 1010 |
my $query = $dbi->create_query( |
998 |
- "insert into books {insert title author};" |
|
1011 |
+ "insert into books {insert_param title author};" |
|
999 | 1012 |
); |
1000 | 1013 |
|
1001 |
- # (In the case of update statement) |
|
1002 |
- my $query = $dbi->create_query( |
|
1003 |
- "update books {update author};"; |
|
1004 |
- ); |
|
1005 |
- |
|
1006 | 1014 |
Execute query repeatedly |
1007 | 1015 |
|
1008 | 1016 |
my $inputs = [ |
... | ... |
@@ -1051,7 +1059,7 @@ otherwise, called to get cache. |
1051 | 1059 |
} |
1052 | 1060 |
}); |
1053 | 1061 |
|
1054 |
-=head2 7. More features |
|
1062 |
+=head2 8. More features |
|
1055 | 1063 |
|
1056 | 1064 |
=head3 Get DBI object |
1057 | 1065 |
|
... | ... |
@@ -1155,12 +1163,12 @@ Default filter when row is fetched. |
1155 | 1163 |
Result class for select statement. |
1156 | 1164 |
Default to L<DBIx::Custom::Result>. |
1157 | 1165 |
|
1158 |
-=head2 C<sql_builder> |
|
1166 |
+=head2 C<query_builder> |
|
1159 | 1167 |
|
1160 |
- my $sql_class = $dbi->sql_builder; |
|
1161 |
- $dbi = $dbi->sql_builder(DBIx::Custom::QueryBuilder->new); |
|
1168 |
+ my $sql_class = $dbi->query_builder; |
|
1169 |
+ $dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
1162 | 1170 |
|
1163 |
-SQL builder. sql_builder must be |
|
1171 |
+SQL builder. C<query_builder()> must be |
|
1164 | 1172 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1165 | 1173 |
Default to L<DBIx::Custom::QueryBuilder> object. |
1166 | 1174 |
|
... | ... |
@@ -1359,7 +1367,7 @@ B<Example:> |
1359 | 1367 |
appned => 'for update' |
1360 | 1368 |
); |
1361 | 1369 |
|
1362 |
- # select books.name as book_name from books, rental |
|
1370 |
+ # select books.name as book_name from books, rental |
|
1363 | 1371 |
# where books.id = rental.book_id; |
1364 | 1372 |
my $result = $dbi->select( |
1365 | 1373 |
table => ['books', 'rental'], |
... | ... |
@@ -11,17 +11,17 @@ use DBIx::Custom::QueryBuilder::TagProcessors; |
11 | 11 |
|
12 | 12 |
__PACKAGE__->dual_attr('tag_processors', default => sub { {} }, inherit => 'hash_copy'); |
13 | 13 |
__PACKAGE__->register_tag_processor( |
14 |
- '?' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_placeholder_tag, |
|
15 |
- '=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_equal_tag, |
|
16 |
- '<>' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_not_equal_tag, |
|
17 |
- '>' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_greater_than_tag, |
|
18 |
- '<' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_lower_than_tag, |
|
19 |
- '>=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_greater_than_equal_tag, |
|
20 |
- '<=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_lower_than_equal_tag, |
|
21 |
- 'like' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_like_tag, |
|
22 |
- 'in' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_in_tag, |
|
23 |
- 'insert' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_insert_tag, |
|
24 |
- 'update' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_update_tag |
|
14 |
+ '?' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_placeholder_tag, |
|
15 |
+ '=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_equal_tag, |
|
16 |
+ '<>' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_not_equal_tag, |
|
17 |
+ '>' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_greater_than_tag, |
|
18 |
+ '<' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_lower_than_tag, |
|
19 |
+ '>=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_greater_than_equal_tag, |
|
20 |
+ '<=' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_lower_than_equal_tag, |
|
21 |
+ 'like' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_like_tag, |
|
22 |
+ 'in' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_in_tag, |
|
23 |
+ 'insert_param' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_insert_param_tag, |
|
24 |
+ 'update_param' => \&DBIx::Custom::QueryBuilder::TagProcessors::expand_update_param_tag |
|
25 | 25 |
); |
26 | 26 |
|
27 | 27 |
__PACKAGE__->attr(tag_start => '{'); |
... | ... |
@@ -324,12 +324,12 @@ In tag. |
324 | 324 |
|
325 | 325 |
=head2 C<insert> |
326 | 326 |
|
327 |
-Insert tag. |
|
327 |
+Insert parameter tag. |
|
328 | 328 |
|
329 |
- {insert NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
329 |
+ {insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
330 | 330 |
|
331 | 331 |
=head2 C<update> |
332 | 332 |
|
333 |
-Updata tag. |
|
333 |
+Updata parameter tag. |
|
334 | 334 |
|
335 |
- {update NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
335 |
+ {update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
... | ... |
@@ -55,10 +55,10 @@ sub expand_in_tag { |
55 | 55 |
return [$s, $columns]; |
56 | 56 |
} |
57 | 57 |
|
58 |
-sub expand_insert_tag { |
|
58 |
+sub expand_insert_param_tag { |
|
59 | 59 |
my @columns = @_; |
60 | 60 |
|
61 |
- # Part of insert statement |
|
61 |
+ # Insert parameters |
|
62 | 62 |
my $s = '('; |
63 | 63 |
$s .= "$_, " for @columns; |
64 | 64 |
$s =~ s/, $//; |
... | ... |
@@ -71,10 +71,10 @@ sub expand_insert_tag { |
71 | 71 |
return [$s, \@columns]; |
72 | 72 |
} |
73 | 73 |
|
74 |
-sub expand_update_tag { |
|
74 |
+sub expand_update_param_tag { |
|
75 | 75 |
my @columns = @_; |
76 | 76 |
|
77 |
- # Part of update statement |
|
77 |
+ # Update paramters |
|
78 | 78 |
my $s = 'set '; |
79 | 79 |
$s .= "$_ = ?, " for @columns; |
80 | 80 |
$s =~ s/, $//; |
... | ... |
@@ -148,12 +148,12 @@ same as the count of column names. |
148 | 148 |
|
149 | 149 |
('NAME', 3) -> ['NAME in (?, ?, ?)', ['NAME', 'NAME', 'NAME']] |
150 | 150 |
|
151 |
-=head2 C<expand_insert_tag> |
|
151 |
+=head2 C<expand_insert_param_tag> |
|
152 | 152 |
|
153 | 153 |
('NAME1', 'NAME2') |
154 | 154 |
-> ['(NAME1, NAME2) values (?, ?, ?)', ['NAME1', 'NAME2']] |
155 | 155 |
|
156 |
-=head2 C<expand_update_tag> |
|
156 |
+=head2 C<expand_update_param_tag> |
|
157 | 157 |
|
158 | 158 |
('NAME1', 'NAME2') |
159 | 159 |
-> ['set NAME1 = ?, NAME2 = ?', ['NAME1', 'NAME2']] |
... | ... |
@@ -97,7 +97,7 @@ is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetc |
97 | 97 |
test 'Insert query return value'; |
98 | 98 |
$dbi->execute($DROP_TABLE->{0}); |
99 | 99 |
$dbi->execute($CREATE_TABLE->{0}); |
100 |
-$source = "insert into table1 {insert key1 key2}"; |
|
100 |
+$source = "insert into table1 {insert_param key1 key2}"; |
|
101 | 101 |
$query = $dbi->create_query($source); |
102 | 102 |
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2}); |
103 | 103 |
ok($ret_val, $test); |
... | ... |
@@ -106,7 +106,7 @@ ok($ret_val, $test); |
106 | 106 |
test 'Direct query'; |
107 | 107 |
$dbi->execute($DROP_TABLE->{0}); |
108 | 108 |
$dbi->execute($CREATE_TABLE->{0}); |
109 |
-$insert_tmpl = "insert into table1 {insert key1 key2}"; |
|
109 |
+$insert_tmpl = "insert into table1 {insert_param key1 key2}"; |
|
110 | 110 |
$dbi->execute($insert_tmpl, param => {key1 => 1, key2 => 2}); |
111 | 111 |
$result = $dbi->execute($SELECT_TMPLS->{0}); |
112 | 112 |
$rows = $result->fetch_hash_all; |
... | ... |
@@ -118,7 +118,7 @@ $dbi->execute($CREATE_TABLE->{0}); |
118 | 118 |
$dbi->register_filter(twice => sub { $_[0] * 2}, |
119 | 119 |
three_times => sub { $_[0] * 3}); |
120 | 120 |
|
121 |
-$insert_tmpl = "insert into table1 {insert key1 key2};"; |
|
121 |
+$insert_tmpl = "insert into table1 {insert_param key1 key2};"; |
|
122 | 122 |
$insert_query = $dbi->create_query($insert_tmpl); |
123 | 123 |
$insert_query->filter({key1 => 'twice'}); |
124 | 124 |
$dbi->execute($insert_query, param => {key1 => 1, key2 => 2}); |
... | ... |
@@ -129,7 +129,7 @@ $dbi->execute($DROP_TABLE->{0}); |
129 | 129 |
|
130 | 130 |
test 'Filter in'; |
131 | 131 |
$dbi->execute($CREATE_TABLE->{0}); |
132 |
-$insert_tmpl = "insert into table1 {insert key1 key2};"; |
|
132 |
+$insert_tmpl = "insert into table1 {insert_param key1 key2};"; |
|
133 | 133 |
$insert_query = $dbi->create_query($insert_tmpl); |
134 | 134 |
$dbi->execute($insert_query, param => {key1 => 2, key2 => 4}); |
135 | 135 |
$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}"; |
... | ... |
@@ -171,7 +171,7 @@ is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$te |
171 | 171 |
|
172 | 172 |
test 'DBIx::Custom::SQLTemplate insert tag'; |
173 | 173 |
$dbi->execute("delete from table1"); |
174 |
-$insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}'; |
|
174 |
+$insert_tmpl = 'insert into table1 {insert_param key1 key2 key3 key4 key5}'; |
|
175 | 175 |
$dbi->execute($insert_tmpl, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
176 | 176 |
|
177 | 177 |
$result = $dbi->execute($SELECT_TMPLS->{0}); |
... | ... |
@@ -180,11 +180,11 @@ is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$te |
180 | 180 |
|
181 | 181 |
test 'DBIx::Custom::SQLTemplate update tag'; |
182 | 182 |
$dbi->execute("delete from table1"); |
183 |
-$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}"; |
|
183 |
+$insert_tmpl = "insert into table1 {insert_param key1 key2 key3 key4 key5}"; |
|
184 | 184 |
$dbi->execute($insert_tmpl, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}); |
185 | 185 |
$dbi->execute($insert_tmpl, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}); |
186 | 186 |
|
187 |
-$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}'; |
|
187 |
+$update_tmpl = 'update table1 {update_param key1 key2 key3 key4} where {= key5}'; |
|
188 | 188 |
$dbi->execute($update_tmpl, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5}); |
189 | 189 |
|
190 | 190 |
$result = $dbi->execute($SELECT_TMPLS->{0}); |