... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
|
3 |
-our $VERSION = '0.1643'; |
|
3 |
+our $VERSION = '0.1644'; |
|
4 | 4 |
|
5 | 5 |
use 5.008001; |
6 | 6 |
use strict; |
... | ... |
@@ -355,7 +355,7 @@ This is used to specify column names and table names at once |
355 | 355 |
Note that you can't use where clause in C<selection>. |
356 | 356 |
use clause like "inner join". |
357 | 357 |
|
358 |
-=head3 C<execute()> SQL |
|
358 |
+=head3 C<execute()> |
|
359 | 359 |
|
360 | 360 |
use C<execute()> to execute SQL |
361 | 361 |
|
... | ... |
@@ -385,7 +385,7 @@ You don't have to wirte last semicolon in C<execute()>. |
385 | 385 |
Return value of C<select()> is L<DBIx::Custom::Result> object. |
386 | 386 |
There are many methods to fetch row. |
387 | 387 |
|
388 |
-=head3 Fetch a row (array) C<fetch()> |
|
388 |
+=head3 Fetch a row (array) : C<fetch()> |
|
389 | 389 |
|
390 | 390 |
use C<fetch()> to fetch a row and assign it into array reference. |
391 | 391 |
|
... | ... |
@@ -398,7 +398,7 @@ You can get all rows. |
398 | 398 |
my $author = $row->[1]; |
399 | 399 |
} |
400 | 400 |
|
401 |
-=head3 Fetch only first row (array) C<fetch_first()> |
|
401 |
+=head3 Fetch only first row (array) : C<fetch_first()> |
|
402 | 402 |
|
403 | 403 |
use C<fetch_first()> to fetch only first row. |
404 | 404 |
|
... | ... |
@@ -407,7 +407,7 @@ use C<fetch_first()> to fetch only first row. |
407 | 407 |
You can't fetch rest rows |
408 | 408 |
because statement handle C<finish()> is executed. |
409 | 409 |
|
410 |
-=head3 Fetch rows (array) C<fetch_multi()> |
|
410 |
+=head3 Fetch rows (array) : C<fetch_multi()> |
|
411 | 411 |
|
412 | 412 |
use C<fetch_multi()> to fetch rows and assign it into |
413 | 413 |
array reference which has array references as element. |
... | ... |
@@ -429,7 +429,7 @@ You can get the following data. |
429 | 429 |
['Ruby', 'Mark'] |
430 | 430 |
] |
431 | 431 |
|
432 |
-=head3 Fetch all rows (array) C<fetch_all> |
|
432 |
+=head3 Fetch all rows (array) : C<fetch_all> |
|
433 | 433 |
|
434 | 434 |
use C<fetch_all()> to fetch all rows and assign it into |
435 | 435 |
array reference which has array reference as element. |
... | ... |
@@ -443,7 +443,7 @@ You can get the following data. |
443 | 443 |
['Ruby', 'Mark'] |
444 | 444 |
] |
445 | 445 |
|
446 |
-=head3 Fetch a row (hash) C<fetch_hash()> |
|
446 |
+=head3 Fetch a row (hash) : C<fetch_hash()> |
|
447 | 447 |
|
448 | 448 |
use C<fetch_hash()> to fetch a row and assign it into hash reference. |
449 | 449 |
|
... | ... |
@@ -452,7 +452,7 @@ use C<fetch_hash()> to fetch a row and assign it into hash reference. |
452 | 452 |
my $author = $row->{author}; |
453 | 453 |
} |
454 | 454 |
|
455 |
-=head3 Fetch only first row (hash) C<fetch_hash_first()> |
|
455 |
+=head3 Fetch only first row (hash) : C<fetch_hash_first()> |
|
456 | 456 |
|
457 | 457 |
use C<fetch_hash_first()> to fetch only first row |
458 | 458 |
and assign it into hash reference. |
... | ... |
@@ -462,7 +462,7 @@ and assign it into hash reference. |
462 | 462 |
You can't fetch rest rows |
463 | 463 |
because statement handle C<finish()> is executed. |
464 | 464 |
|
465 |
-=head3 Fetch rows (hash) C<fetch_hash_multi()> |
|
465 |
+=head3 Fetch rows (hash) : C<fetch_hash_multi()> |
|
466 | 466 |
|
467 | 467 |
use C<fetch_hash_multi()> to fetch rows and |
468 | 468 |
assign it into array reference which has hash references as element. |
... | ... |
@@ -483,7 +483,7 @@ You can get the following data. |
483 | 483 |
{title => 'Ruby', author => 'Mark'} |
484 | 484 |
] |
485 | 485 |
|
486 |
-=head3 Fetch all rows (hash) C<fetch_hash_all()> |
|
486 |
+=head3 Fetch all rows (hash) : C<fetch_hash_all()> |
|
487 | 487 |
|
488 | 488 |
use C<fetch_hash_all()> to fetch all rows and |
489 | 489 |
assign it into array reference which has hash |
... | ... |
@@ -498,7 +498,7 @@ You can get the following data. |
498 | 498 |
{title => 'Ruby', author => 'Mark'} |
499 | 499 |
] |
500 | 500 |
|
501 |
-=head3 Statement handle C<sth()> |
|
501 |
+=head3 Statement handle : C<sth()> |
|
502 | 502 |
|
503 | 503 |
use <sth()> to get statement handle. |
504 | 504 |
|
... | ... |
@@ -512,7 +512,7 @@ database date format when register data into database. |
512 | 512 |
and convert database date fromat to L<Time::Piece> object |
513 | 513 |
when get data from database. |
514 | 514 |
|
515 |
-=head3 Register filter C<register_filter()> |
|
515 |
+=head3 Register filter : C<register_filter()> |
|
516 | 516 |
|
517 | 517 |
use C<register_filter() to register filter. |
518 | 518 |
|
... | ... |
@@ -536,7 +536,7 @@ use C<register_filter() to register filter. |
536 | 536 |
|
537 | 537 |
Registered filter is used by C<apply_filter()> or etc. |
538 | 538 |
|
539 |
-=head3 Apply filter C<apply_filter()> |
|
539 |
+=head3 Apply filter : C<apply_filter()> |
|
540 | 540 |
|
541 | 541 |
use C<apply_filter()> to apply registered filter. |
542 | 542 |
|
... | ... |
@@ -641,7 +641,7 @@ use C<end_filter()> to add end filter. |
641 | 641 |
|
642 | 642 |
In this example, L<Time::Piece> object is converted to readable format. |
643 | 643 |
|
644 |
-=head3 Automate applying filter C<each_column()> |
|
644 |
+=head3 Automate applying filter : C<each_column()> |
|
645 | 645 |
|
646 | 646 |
It is useful to apply filter automatically at date type columns. |
647 | 647 |
You can use C<each_column()> to process all column infos. |
... | ... |
@@ -712,8 +712,6 @@ You have to use C<table> tag in SQL |
712 | 712 |
|
713 | 713 |
=head3 Tag list |
714 | 714 |
|
715 |
-L<DBIx::Custom>�ł͎��̃^�O���g�p�\�ł��B |
|
716 |
- |
|
717 | 715 |
The following tag is available. |
718 | 716 |
|
719 | 717 |
=head4 C<table> |
... | ... |
@@ -779,7 +777,7 @@ In this case, You specify paramter values as array reference. |
779 | 777 |
|
780 | 778 |
my $dbi->execute($sql, param => {date => ['2010-10-01', '2012-02-10']}); |
781 | 779 |
|
782 |
-=head3 Register Tag C<register_tag()> |
|
780 |
+=head3 Register Tag : C<register_tag()> |
|
783 | 781 |
|
784 | 782 |
You can register custom tag. |
785 | 783 |
use C<register_tag()> to register tag. |
... | ... |
@@ -827,116 +825,107 @@ You return the following array reference. |
827 | 825 |
|
828 | 826 |
See source of L<DBIx::Custom::Tag> to see many implementation. |
829 | 827 |
|
830 |
-=head2 6. Where��̓��I�Ȑ��� |
|
828 |
+=head2 6. Dinamically create where clause |
|
831 | 829 |
|
832 |
-=head3 Where��̓��I�Ȑ��� where() |
|
830 |
+=head3 Dinamically create where clause : where() |
|
833 | 831 |
|
834 |
-�����̌�����w�肵�āA�����s�������ꍇ������܂��B |
|
835 |
-����3�̃P�[�X��where���l���Ă݂܂��傤�B |
|
836 |
-���L�̂悤��where�傪�K�v�ɂȂ�܂��B |
|
832 |
+You want to search multiple conditions in many times. |
|
833 |
+Let's think the following three cases. |
|
837 | 834 |
|
838 |
-title�̒l�����Ō�������ꍇ |
|
835 |
+Case1: Search only C<title> |
|
839 | 836 |
|
840 | 837 |
where {= title} |
841 | 838 |
|
842 |
-author�̒l�����Ō�������ꍇ |
|
839 |
+Case2: Search only C<author> |
|
843 | 840 |
|
844 | 841 |
where {= author} |
845 | 842 |
|
846 |
-title��author�̗���̒l�Ō�������ꍇ |
|
843 |
+Case3: Search C<title> and C<author> |
|
847 | 844 |
|
848 | 845 |
where {= title} and {=author} |
849 | 846 |
|
850 |
-L<DBIx::Custom>�ł͓��I��Where��̐�����T�|�[�g���Ă��܂��B |
|
851 |
-�܂�C<where()>��L<DBIx::Custom::Where>�I�u�W�F�N�g�����܂��B |
|
847 |
+L<DBIx::Custom> support dinamic where clause creating. |
|
848 |
+At first, create L<DBIx::Custom::Where> object by C<where()>. |
|
852 | 849 |
|
853 | 850 |
my $where = $dbi->where; |
854 | 851 |
|
855 |
-����C<clause()>��g�p����where���L�q���܂��B |
|
852 |
+Set clause by C<clause()> |
|
856 | 853 |
|
857 | 854 |
$where->clause( |
858 | 855 |
['and', '{= title'}, '{= author}'] |
859 | 856 |
); |
860 | 857 |
|
861 |
-clause�̎w���@�͎��̂悤�ɂȂ�܂��B |
|
858 |
+C<clause> is the following format. |
|
862 | 859 |
|
863 |
- ['or' ���邢�� 'and', �^�O1, �^�O2, �^�O3] |
|
860 |
+ ['or' or 'and', TAG1, TAG2, TAG3] |
|
864 | 861 |
|
865 |
-����ɂ�or���邢��and��w�肵�܂��B����ȍ~�ɂ� |
|
866 |
-������^�O��g��ċL�q���܂��B |
|
862 |
+First argument is 'or' or 'and'. |
|
863 |
+Later than first argument are tag names. |
|
867 | 864 |
|
868 |
-C<clause>�̎w��͓��q�ɂ��邱�Ƃ�ł��A����ɕ��G�ȏ� |
|
869 |
-��L�q���邱�Ƃ�ł��܂��B |
|
865 |
+You can write more complex format. |
|
870 | 866 |
|
871 | 867 |
['and', |
872 | 868 |
'{= title}', |
873 | 869 |
['or', '{= author}', '{like date}'] |
874 | 870 |
] |
875 | 871 |
|
876 |
-���̂悤��C<clause>��ݒ肵�����C<param>�Ƀp�����[�^��w�肵�܂��B |
|
872 |
+This mean "{=title} and ( {=author} or {like date} )". |
|
873 |
+ |
|
874 |
+After setting C<clause>, set C<param>. |
|
877 | 875 |
|
878 |
- my $param => {title => 'Perl'}; |
|
879 |
- $where->param($param); |
|
876 |
+ $where->param({title => 'Perl'}); |
|
880 | 877 |
|
881 |
-���̗�ł�title�������p�����[�^�Ɋ܂܂�Ă��܂��B |
|
878 |
+In this example, parameter contains only title. |
|
882 | 879 |
|
883 |
-���̌�C<to_string()>���s�����$param�Ɋ܂܂��p�����[�^���� |
|
884 |
-where������邱�Ƃ��ł��܂��B |
|
880 |
+If you execute C<string_to()>, you can get where clause |
|
881 |
+which contain only parameter name. |
|
885 | 882 |
|
886 | 883 |
my $where_clause = $where->to_string; |
887 | 884 |
|
888 |
-�p�����[�^��title�����ł��̂ŁA���̂悤��where�傪��������܂��B |
|
885 |
+Parameter name is only title, the following where clause is created. |
|
889 | 886 |
|
890 | 887 |
where {= title} |
891 | 888 |
|
892 |
-�܂�L<DBIx::Custom>�͕�����̕]����I�[�o�[���[�h���āAC<to_string()> |
|
893 |
-��Ăяo���悤�ɂ��Ă��܂��̂ŁA���̂悤�ɂ���where������邱�Ƃ� |
|
894 |
-�ł��܂��B |
|
889 |
+You can also create where clause by stringification. |
|
895 | 890 |
|
896 | 891 |
my $where_clause = "$where"; |
897 | 892 |
|
898 |
-�����SQL�̒���where��ߍ��ނƂ��ɂƂĂ�𗧂@�\�ł��B |
|
893 |
+This is useful to embbed it into SQL. |
|
899 | 894 |
|
900 |
-=head3 ����̗�܂ޏꍇ |
|
895 |
+=head3 In case where clause contains same name columns |
|
901 | 896 |
|
902 |
-�^�O�̒��ɓ���̖��O���̂����݂����ꍇ�ł��I�� |
|
903 |
-where���쐬���邱�Ƃ��ł��܂��B |
|
904 |
- |
|
905 |
-���Ƃ��A�p�����[�^�Ƃ��ĊJ�n��t�ƏI����t��������Ƃ� |
|
906 |
-�l���Ă݂Ă��������B |
|
897 |
+Even if same name tags exists, you can create where clause. |
|
898 |
+Let's think that there are starting date and ending date. |
|
907 | 899 |
|
908 | 900 |
my $param = {start_date => '2010-11-15', end_date => '2011-11-21'}; |
909 | 901 |
|
910 |
-�܂��J�n��t�ƏI����t�̕Е���A�ǂ������Ȃ��ꍇ���邩����܂���B |
|
911 |
- |
|
912 |
-���̏ꍇ�͎��̂悤�ȃp�����[�^�ɕϊ����邱�ƂőΉ����邱�Ƃ��ł��܂��B |
|
902 |
+In this case, you set parameter value as array reference. |
|
913 | 903 |
|
914 | 904 |
my $p = {date => ['2010-11-15', '2011-11-21']}; |
915 | 905 |
|
916 |
-�l���z��̃��t�@�����X�ɂȂ�Ă��邱�Ƃɒ��ڂ��Ă��������B���̂悤�ɂ���� |
|
917 |
-�����̗��܂ރ^�O�ɏ��Ԃɖ��ߍ��ނ��Ƃ��ł��܂��B |
|
906 |
+You can embbed these values into same name tags. |
|
918 | 907 |
|
919 | 908 |
$where->clause( |
920 | 909 |
['and', '{> date}', '{< date}'] |
921 | 910 |
); |
922 | 911 |
$where->param($p); |
923 | 912 |
|
924 |
-�܂��J�n��t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
913 |
+If starting date isn't exists, create the following parameter. |
|
925 | 914 |
|
926 | 915 |
my $p = {date => [$dbi->not_exists, '2011-11-21']}; |
927 | 916 |
|
928 |
-L<DBIx::Custom>��C<not_exists>��DBIx::Custom::NotExists�I�u�W�F�N�g�� |
|
929 |
-�擾�ł��܂��B����͑Ή�����l�����݂��Ȃ����Ƃ�����߂̂�̂ł��B |
|
917 |
+You can get DBIx::Custom::NotExists object by C<not_exists()> |
|
918 |
+This mean correnspondinf value isn't exists. |
|
930 | 919 |
|
931 |
-�܂��I����t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
920 |
+If ending date isn't exists, create the following parameter. |
|
932 | 921 |
|
933 | 922 |
my $p = {date => ['2010-11-15']}; |
934 | 923 |
|
935 |
-�ǂ�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B |
|
924 |
+If both date isn't exists, create the following parameter. |
|
936 | 925 |
|
937 | 926 |
my $p = {date => []}; |
938 | 927 |
|
939 |
-��������̂ň�ԊȒP�ɍ쐬�ł��郍�W�b�N����Ă����܂��B |
|
928 |
+This logic is a little difficut. See the following ones. |
|
940 | 929 |
|
941 | 930 |
my @date; |
942 | 931 |
push @date, exists $param->{start_date} ? $param->{start_date} |
... | ... |
@@ -944,30 +933,27 @@ L<DBIx::Custom> |
944 | 933 |
push @date, $param->{end_date} if exists $param->{end_date}; |
945 | 934 |
my $p = {date => \@date}; |
946 | 935 |
|
947 |
-=head3 C<select()>�Ƃ̘A�g |
|
936 |
+=head3 With C<select()> |
|
948 | 937 |
|
949 |
-L<DBIx::Custom::Where>�I�u�W�F�N�g�� |
|
950 |
-C<select()>��C<where>�ɒ��ړn�����Ƃ� |
|
951 |
-�ł��܂��B |
|
938 |
+You can pass L<DBIx::Custom::Where> object to C<where> of C<select()>. |
|
952 | 939 |
|
953 | 940 |
my $where = $dbi->where; |
954 |
- $where->clause(...); |
|
955 |
- $where->param($param); |
|
941 |
+ $where->clause(['and', '{= title}', '{= author}']); |
|
942 |
+ $where->param({title => 'Perl'}); |
|
956 | 943 |
my $result = $dbi->select(table => 'book', where => $where); |
957 | 944 |
|
958 |
-���邢��C<update()>�AC<delete()>��where�Ɏw�肷�邱�Ƃ�\�ł��B |
|
959 |
- |
|
960 |
-=head3 C<execute()>�Ƃ̘A�g |
|
945 |
+You can also pass it to C<where> of C<update()>�AC<delete()> |
|
961 | 946 |
|
962 |
-C<execute()>�Ƃ̘A�g�ł��BSQL��쐬����Ƃ��ɖ��ߍ��ނ��Ƃ��ł��܂��B |
|
947 |
+=head3 With C<execute()> |
|
963 | 948 |
|
949 |
+L<DBIx::Custom::Where> object is embedded into SQL. |
|
964 | 950 |
|
965 | 951 |
my $where = $dbi->where; |
966 |
- $where->clause(...); |
|
967 |
- $where->param($param); |
|
952 |
+ $where->clause(['and', '{= title}', '{= author}']); |
|
953 |
+ $where->param({title => 'Perl'}); |
|
968 | 954 |
|
969 |
- my $sql = <<"EOS" |
|
970 |
- select * from book; |
|
955 |
+ my $sql = <<"EOS"; |
|
956 |
+ select * from {table book}; |
|
971 | 957 |
$where |
972 | 958 |
EOS |
973 | 959 |
|
... | ... |
@@ -1153,7 +1139,7 @@ You can change result class. By default it is L<DBIx::Custom::Result>. |
1153 | 1139 |
my $dbi = DBIx::Custom->connect(...); |
1154 | 1140 |
$dbi->result_class('MyResult'); |
1155 | 1141 |
|
1156 |
-=head3 �L���b�V���O |
|
1142 |
+=head3 Caching |
|
1157 | 1143 |
|
1158 | 1144 |
SQL after parsing tag is cached for performance. |
1159 | 1145 |
You can set C<cache()>. By default, chaching is true. |
... | ... |
@@ -849,7 +849,6 @@ C<=>タグの場合は |
849 | 849 |
|
850 | 850 |
複数の検索条件を指定して、検索を行いたい場合があります。 |
851 | 851 |
次の3つのケースのwhere句を考えてみましょう。 |
852 |
-下記のようなwhere句が必要になります。 |
|
853 | 852 |
|
854 | 853 |
titleの値だけで検索したい場合 |
855 | 854 |
|
... | ... |
@@ -889,10 +888,11 @@ C<clause>の指定は入れ子にすることもでき、さらに複雑な条 |
889 | 888 |
['or', '{= author}', '{like date}'] |
890 | 889 |
] |
891 | 890 |
|
892 |
-このようにC<clause>を設定した後にC<param>にパラメータを指定します。 |
|
891 |
+これは "{=title} and ( {=author} or {like date} )" 意味しています。 |
|
892 |
+ |
|
893 |
+C<clause>を設定した後にC<param>にパラメータを指定します。 |
|
893 | 894 |
|
894 |
- my $param => {title => 'Perl'}; |
|
895 |
- $where->param($param); |
|
895 |
+ $where->param({title => 'Perl'}); |
|
896 | 896 |
|
897 | 897 |
この例ではtitleだけがパラメータに含まれています。 |
898 | 898 |
|
... | ... |
@@ -923,13 +923,10 @@ where句を作成することができます。 |
923 | 923 |
|
924 | 924 |
my $param = {start_date => '2010-11-15', end_date => '2011-11-21'}; |
925 | 925 |
|
926 |
-また開始日付と終了日付の片方だけや、どちらも受け取らない場合もあるかもしれません。 |
|
927 |
- |
|
928 |
-この場合は次のようなパラメータに変換することで対応することができます。 |
|
926 |
+この場合はパラメータの値を配列のリファレンスにしてください。 |
|
929 | 927 |
|
930 | 928 |
my $p = {date => ['2010-11-15', '2011-11-21']}; |
931 | 929 |
|
932 |
-値が配列のリファレンスになっていることに注目してください。このようにすれば |
|
933 | 930 |
同名の列を含むタグに順番に埋め込むことができます。 |
934 | 931 |
|
935 | 932 |
$where->clause( |
... | ... |
@@ -941,7 +938,7 @@ where句を作成することができます。 |
941 | 938 |
|
942 | 939 |
my $p = {date => [$dbi->not_exists, '2011-11-21']}; |
943 | 940 |
|
944 |
-L<DBIx::Custom>のC<not_exists>でDBIx::Custom::NotExistsオブジェクトを |
|
941 |
+C<not_exists()>でDBIx::Custom::NotExistsオブジェクトを |
|
945 | 942 |
取得できます。これは対応する値が存在しないことを示すためのものです。 |
946 | 943 |
|
947 | 944 |
また終了日付が存在しない場合は次のようなデータを作成します。 |
... | ... |
@@ -982,7 +979,7 @@ C<execute()>との連携です。SQLを作成するときに埋め込むこと |
982 | 979 |
$where->clause(...); |
983 | 980 |
$where->param($param); |
984 | 981 |
|
985 |
- my $sql = <<"EOS" |
|
982 |
+ my $sql = <<"EOS"; |
|
986 | 983 |
select * from book; |
987 | 984 |
$where |
988 | 985 |
EOS |