| ... | ... |
@@ -1,3 +1,7 @@ |
| 1 |
+0.1607 |
|
| 2 |
+ renamed build_query to create_query(not backword compatible) |
|
| 3 |
+0.1606 |
|
| 4 |
+ fix testing bug |
|
| 1 | 5 |
0.1605 |
| 2 | 6 |
remove DBIx::Custom::QueryBuilder::tag_syntax() (not backword compatible) |
| 3 | 7 |
renamed DBIx::Custom::TagProcessor to DBIx::Custom::TagProcessors (not backword compatible) |
| ... | ... |
@@ -310,7 +310,7 @@ sub select {
|
| 310 | 310 |
return $result; |
| 311 | 311 |
} |
| 312 | 312 |
|
| 313 |
-sub build_query {
|
|
| 313 |
+sub create_query {
|
|
| 314 | 314 |
my ($self, $source) = @_; |
| 315 | 315 |
|
| 316 | 316 |
# Cache |
| ... | ... |
@@ -367,7 +367,7 @@ sub execute{
|
| 367 | 367 |
my $params = $args{param} || {};
|
| 368 | 368 |
|
| 369 | 369 |
# First argument is SQL template |
| 370 |
- $query = $self->build_query($query) |
|
| 370 |
+ $query = $self->create_query($query) |
|
| 371 | 371 |
unless ref $query; |
| 372 | 372 |
|
| 373 | 373 |
my $filter = $args{filter} || $query->filter || {};
|
| ... | ... |
@@ -446,25 +446,26 @@ sub _build_bind_values {
|
| 446 | 446 |
|
| 447 | 447 |
=head1 NAME |
| 448 | 448 |
|
| 449 |
-DBIx::Custom - DBI with hash parameter binding and filtering system |
|
| 449 |
+DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
|
| 450 | 450 |
|
| 451 | 451 |
=cut |
| 452 | 452 |
|
| 453 |
-our $VERSION = '0.1605'; |
|
| 453 |
+our $VERSION = '0.1606'; |
|
| 454 | 454 |
|
| 455 | 455 |
=head1 STABILITY |
| 456 | 456 |
|
| 457 |
-This module is not stable. Method name and implementations will be changed. |
|
| 457 |
+B<This module is not stable>. |
|
| 458 |
+Method name and implementations will be changed for a while. |
|
| 458 | 459 |
|
| 459 | 460 |
=head1 SYNOPSYS |
| 460 | 461 |
|
| 461 |
-Connect to database. |
|
| 462 |
- |
|
| 463 |
- # Connect |
|
| 462 |
+Connect to the database. |
|
| 463 |
+ |
|
| 464 |
+ use DBIx::Custom; |
|
| 464 | 465 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
| 465 | 466 |
user => 'ken', password => '!LFKD%$&'); |
| 466 | 467 |
|
| 467 |
-Insert, update, delete statement. |
|
| 468 |
+Insert, update, and delete |
|
| 468 | 469 |
|
| 469 | 470 |
# Insert |
| 470 | 471 |
$dbi->insert(table => 'books', |
| ... | ... |
@@ -490,39 +491,39 @@ Insert, update, delete statement. |
| 490 | 491 |
# Delete all |
| 491 | 492 |
$dbi->delete_all(table => 'books'); |
| 492 | 493 |
|
| 493 |
-Select statement. |
|
| 494 |
+Select |
|
| 494 | 495 |
|
| 495 | 496 |
# Select |
| 496 | 497 |
my $result = $dbi->select(table => 'books'); |
| 497 | 498 |
|
| 498 |
- # Select(more complex) |
|
| 499 |
+ # Select, more complex |
|
| 499 | 500 |
my $result = $dbi->select( |
| 500 | 501 |
table => 'books', |
| 501 | 502 |
column => [qw/author title/], |
| 502 | 503 |
where => {author => 'Ken'},
|
| 503 | 504 |
append => 'order by id limit 1', |
| 504 |
- filter => {tilte => 'encode_utf8'}
|
|
| 505 |
+ filter => {title => 'encode_utf8'}
|
|
| 505 | 506 |
); |
| 506 | 507 |
|
| 507 |
- # Select(Join table) |
|
| 508 |
+ # Select, join table |
|
| 508 | 509 |
my $result = $dbi->select( |
| 509 |
- table => ['books', 'rental'], |
|
| 510 |
- column => ['books.name as book_name'] |
|
| 510 |
+ table => ['books', 'rental'], |
|
| 511 |
+ column => ['books.name as book_name'] |
|
| 511 | 512 |
relation => {'books.id' => 'rental.book_id'}
|
| 512 | 513 |
); |
| 513 | 514 |
|
| 514 |
-Execute SQL source. |
|
| 515 |
+Execute SQL |
|
| 515 | 516 |
|
| 516 |
- # Execute from SQL source |
|
| 517 |
+ # Execute SQL |
|
| 517 | 518 |
$dbi->execute("select title from books");
|
| 518 | 519 |
|
| 519 |
- # Execute SQL with parameters and filter |
|
| 520 |
+ # Execute SQL with hash binding and filtering |
|
| 520 | 521 |
$dbi->execute("select id from books where {= author} && {like title}",
|
| 521 | 522 |
param => {author => 'ken', title => '%Perl%'},
|
| 522 |
- filter => {tilte => 'encode_utf8'});
|
|
| 523 |
+ filter => {title => 'encode_utf8'});
|
|
| 523 | 524 |
|
| 524 | 525 |
# Create query and execute it |
| 525 |
- my $query = $dbi->build_query( |
|
| 526 |
+ my $query = $dbi->create_query( |
|
| 526 | 527 |
"select id from books where {= author} && {like title}"
|
| 527 | 528 |
); |
| 528 | 529 |
$dbi->execute($query, param => {author => 'ken', title => '%Perl%'})
|
| ... | ... |
@@ -551,35 +552,49 @@ Fetch row. |
| 551 | 552 |
|
| 552 | 553 |
=head1 DESCRIPTION |
| 553 | 554 |
|
| 554 |
-L<DBIx::Custom> is useful L<DBI> extention. |
|
| 555 |
-This module have hash parameter binding and filtering system. |
|
| 555 |
+=head2 1. Features |
|
| 556 | 556 |
|
| 557 |
-Normally, binding parameter is array. |
|
| 558 |
-L<DBIx::Custom> enable you to pass binding parameter as hash. |
|
| 557 |
+L<DBIx::Custom> is one of L<DBI> interface modules, |
|
| 558 |
+such as L<DBIx::Class>, L<DBIx::Simple>. |
|
| 559 | 559 |
|
| 560 |
-This module also provide filtering system. |
|
| 561 |
-You can filter the binding parameter |
|
| 562 |
-or the value of fetching row. |
|
| 560 |
+This module is not O/R mapper. O/R mapper is useful, |
|
| 561 |
+but you must learn many syntax of the O/R mapper, |
|
| 562 |
+which is almost another language |
|
| 563 |
+Create SQL statement is offten not effcient and damage SQL performance. |
|
| 564 |
+so you have to execute raw SQL in the end. |
|
| 563 | 565 |
|
| 564 |
-And have useful method such as insert(), update(), delete(), and select(). |
|
| 566 |
+L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
|
| 567 |
+L<DBIx::Custom> provide flexible hash parameter binding adn filtering system, |
|
| 568 |
+and suger method, such as C<select()>, C<update()>, C<delete()>, C<select()> |
|
| 569 |
+to execute a query easily. |
|
| 565 | 570 |
|
| 566 |
-=head2 Features |
|
| 571 |
+L<DBIx::Custom> respects SQL. SQL is not beautiful, but de-facto standard, |
|
| 572 |
+so all people learing database system know it. |
|
| 573 |
+If you know SQL statement, |
|
| 574 |
+you learn a little thing about L<DBIx::Custom> to do your works. |
|
| 567 | 575 |
|
| 568 |
-=over 4 |
|
| 576 |
+=head2 2. Basic usage |
|
| 569 | 577 |
|
| 570 |
-=item * |
|
| 578 |
+=head3 connect to the database |
|
| 571 | 579 |
|
| 572 |
-Hash parameter binding. |
|
| 580 |
+C<connect()> method create a new L<DBIx::Custom> |
|
| 581 |
+object and connect to the database. |
|
| 573 | 582 |
|
| 574 |
-=item * |
|
| 583 |
+ use DBIx::Custom; |
|
| 584 |
+ my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
|
| 585 |
+ user => 'ken', password => '!LFKD%$&'); |
|
| 586 |
+ |
|
| 587 |
+=head3 Suger methods |
|
| 588 |
+ |
|
| 589 |
+L<DBIx::Custom> has suger methods, such as C<insert()>, C<update()>, |
|
| 590 |
+C<delete()> and C<select()>. If you want to do simple works, |
|
| 591 |
+You don't have to create SQL statement. |
|
| 592 |
+ |
|
| 593 |
+B<Execute insert statement:> |
|
| 575 | 594 |
|
| 576 |
-Value filtering. |
|
| 577 | 595 |
|
| 578 |
-=item * |
|
| 579 | 596 |
|
| 580 |
-Provide suger methods, such as insert(), update(), delete(), and select(). |
|
| 581 | 597 |
|
| 582 |
-=back |
|
| 583 | 598 |
|
| 584 | 599 |
=head1 ATTRIBUTES |
| 585 | 600 |
|
| ... | ... |
@@ -614,19 +629,13 @@ C<connect()> method use this value to connect the database. |
| 614 | 629 |
|
| 615 | 630 |
L<DBI> object. You can call all methods of L<DBI>. |
| 616 | 631 |
|
| 617 |
- my $sth = $dbi->dbh->prepare("...");
|
|
| 618 |
- my $errstr = $dbi->dbh->errstr; |
|
| 619 |
- $dbi->dbh->begin_work; |
|
| 620 |
- $dbi->dbh->commit; |
|
| 621 |
- $dbi->dbh->rollback; |
|
| 622 |
- |
|
| 623 | 632 |
=head2 C<filters> |
| 624 | 633 |
|
| 625 | 634 |
my $filters = $dbi->filters; |
| 626 | 635 |
$dbi = $dbi->filters(\%filters); |
| 627 | 636 |
|
| 628 | 637 |
Filter functions. |
| 629 |
-By default, "encode_utf8" and "decode_utf8" is registered. |
|
| 638 |
+"encode_utf8" and "decode_utf8" is registered by default. |
|
| 630 | 639 |
|
| 631 | 640 |
=head2 C<default_bind_filter> |
| 632 | 641 |
|
| ... | ... |
@@ -656,15 +665,15 @@ Default to L<DBIx::Custom::Result>. |
| 656 | 665 |
$dbi = $dbi->sql_builder(DBIx::Custom::QueryBuilder->new); |
| 657 | 666 |
|
| 658 | 667 |
SQL builder. sql_builder must be |
| 659 |
-the instance of L<DBIx::Custom::QueryBuilder> subclass |
|
| 660 |
-Default to L<DBIx::Custom::QueryBuilder>. |
|
| 668 |
+the instance of L<DBIx::Custom::QueryBuilder> subclass. |
|
| 669 |
+Default to L<DBIx::Custom::QueryBuilder> object. |
|
| 661 | 670 |
|
| 662 | 671 |
=head2 C<cache> |
| 663 | 672 |
|
| 664 | 673 |
my $cache = $dbi->cache; |
| 665 | 674 |
$dbi = $dbi->cache(1); |
| 666 | 675 |
|
| 667 |
-Enable cache of the query after parsing SQL source. |
|
| 676 |
+Enable parsed L<DBIx::Custom::Query> object caching. |
|
| 668 | 677 |
Default to 1. |
| 669 | 678 |
|
| 670 | 679 |
=head2 C<cache_method> |
| ... | ... |
@@ -672,7 +681,7 @@ Default to 1. |
| 672 | 681 |
$dbi = $dbi->cache_method(\&cache_method); |
| 673 | 682 |
$cache_method = $dbi->cache_method |
| 674 | 683 |
|
| 675 |
-Method for cache. |
|
| 684 |
+Method to set and get caches. |
|
| 676 | 685 |
|
| 677 | 686 |
B<Example:> |
| 678 | 687 |
|
| ... | ... |
@@ -702,8 +711,9 @@ and implements the following new ones. |
| 702 | 711 |
user => 'ken', password => '!LFKD%$&'); |
| 703 | 712 |
|
| 704 | 713 |
Create a new L<DBIx::Custom> object and connect to the database. |
| 705 |
-By default, "AutoCommit" and "RaiseError" option is true, |
|
| 706 |
-and "PrintError" option is false. |
|
| 714 |
+L<DBIx::Custom> is a wrapper of L<DBI>. |
|
| 715 |
+C<AutoCommit> and C<RaiseError> option is true, |
|
| 716 |
+and C<PrintError> option is false by default. |
|
| 707 | 717 |
|
| 708 | 718 |
=head2 C<insert> |
| 709 | 719 |
|
| ... | ... |
@@ -712,9 +722,16 @@ and "PrintError" option is false. |
| 712 | 722 |
append => $append, |
| 713 | 723 |
filter => \%filter); |
| 714 | 724 |
|
| 715 |
-Insert row. |
|
| 716 |
-Retrun value is the count of affected rows. |
|
| 717 |
- |
|
| 725 |
+Execute insert statement. |
|
| 726 |
+C<insert> method have C<table>, C<param>, C<append> |
|
| 727 |
+and C<filter> arguments. |
|
| 728 |
+C<table> is a table name. |
|
| 729 |
+C<param> is column-value pairs. this must be hash reference. |
|
| 730 |
+C<append> is a string added at the end of the SQL statement. |
|
| 731 |
+C<filter> is filters when parameter binding is executed. |
|
| 732 |
+This is overwrites C<default_bind_filter>. |
|
| 733 |
+Return value of C<insert> is the count of affected rows. |
|
| 734 |
+ |
|
| 718 | 735 |
B<Example:> |
| 719 | 736 |
|
| 720 | 737 |
$dbi->insert(table => 'books', |
| ... | ... |
@@ -730,15 +747,23 @@ B<Example:> |
| 730 | 747 |
append => $append, |
| 731 | 748 |
filter => \%filter) |
| 732 | 749 |
|
| 733 |
-Update rows. |
|
| 734 |
-Retrun value is the count of affected rows. |
|
| 750 |
+Execute update statement. |
|
| 751 |
+C<update> method have C<table>, C<param>, C<where>, C<append> |
|
| 752 |
+and C<filter> arguments. |
|
| 753 |
+C<table> is a table name. |
|
| 754 |
+C<param> is column-value pairs. this must be hash reference. |
|
| 755 |
+C<where> is where clause. this must be hash reference. |
|
| 756 |
+C<append> is a string added at the end of the SQL statement. |
|
| 757 |
+C<filter> is filters when parameter binding is executed. |
|
| 758 |
+This is overwrites C<default_bind_filter>. |
|
| 759 |
+Return value of C<update> is the count of affected rows. |
|
| 735 | 760 |
|
| 736 | 761 |
B<Example:> |
| 737 | 762 |
|
| 738 | 763 |
$dbi->update(table => 'books', |
| 739 | 764 |
param => {title => 'Perl', author => 'Taro'},
|
| 740 | 765 |
where => {id => 5},
|
| 741 |
- append => "some statement", |
|
| 766 |
+ append => "for update", |
|
| 742 | 767 |
filter => {title => 'encode_utf8'});
|
| 743 | 768 |
|
| 744 | 769 |
=head2 C<update_all> |
| ... | ... |
@@ -748,8 +773,10 @@ B<Example:> |
| 748 | 773 |
filter => \%filter, |
| 749 | 774 |
append => $append); |
| 750 | 775 |
|
| 751 |
-Update all rows. |
|
| 752 |
-Retrun value is the count of affected rows. |
|
| 776 |
+Execute update statement to update all rows. |
|
| 777 |
+Arguments is same as C<update> method, |
|
| 778 |
+except that C<update_all> don't have C<where> argument. |
|
| 779 |
+Return value of C<update_all> is the count of affected rows. |
|
| 753 | 780 |
|
| 754 | 781 |
B<Example:> |
| 755 | 782 |
|
| ... | ... |
@@ -764,9 +791,14 @@ B<Example:> |
| 764 | 791 |
append => $append, |
| 765 | 792 |
filter => \%filter); |
| 766 | 793 |
|
| 767 |
-Delete rows. |
|
| 768 |
-Retrun value is the count of affected rows. |
|
| 769 |
- |
|
| 794 |
+Execute delete statement. |
|
| 795 |
+C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
| 796 |
+C<table> is a table name. |
|
| 797 |
+C<where> is where clause. this must be hash reference. |
|
| 798 |
+C<append> is a string added at the end of the SQL statement. |
|
| 799 |
+C<filter> is filters when parameter binding is executed. |
|
| 800 |
+Return value of C<delete> is the count of affected rows. |
|
| 801 |
+ |
|
| 770 | 802 |
B<Example:> |
| 771 | 803 |
|
| 772 | 804 |
$dbi->delete(table => 'books', |
| ... | ... |
@@ -778,8 +810,10 @@ B<Example:> |
| 778 | 810 |
|
| 779 | 811 |
$dbi->delete_all(table => $table); |
| 780 | 812 |
|
| 781 |
-Delete all rows. |
|
| 782 |
-Retrun value is the count of affected rows. |
|
| 813 |
+Execute delete statement to delete all rows. |
|
| 814 |
+Arguments is same as C<delete> method, |
|
| 815 |
+except that C<delete_all> don't have C<where> argument. |
|
| 816 |
+Return value of C<delete_all> is the count of affected rows. |
|
| 783 | 817 |
|
| 784 | 818 |
B<Example:> |
| 785 | 819 |
|
| ... | ... |
@@ -794,18 +828,24 @@ B<Example:> |
| 794 | 828 |
relation => \%relation, |
| 795 | 829 |
filter => \%filter); |
| 796 | 830 |
|
| 797 |
-Select rows. |
|
| 798 |
-Return value is the instance of L<DBIx::Custom::Result>. |
|
| 831 |
+Execute select statement. |
|
| 832 |
+C<select> method have C<table>, C<column>, C<where>, C<append> |
|
| 833 |
+C<relation> and C<filter> arguments. |
|
| 834 |
+C<table> is a table name. |
|
| 835 |
+C<where> is where clause. this must be hash reference |
|
| 836 |
+or a string containing such tags as "{= title} or {= author}".
|
|
| 837 |
+C<append> is a string added at the end of the SQL statement. |
|
| 838 |
+C<filter> is filters when parameter binding is executed. |
|
| 799 | 839 |
|
| 800 | 840 |
B<Example:> |
| 801 | 841 |
|
| 802 | 842 |
# select * from books; |
| 803 | 843 |
my $result = $dbi->select(table => 'books'); |
| 804 | 844 |
|
| 805 |
- # select * from books where title = 'Perl'; |
|
| 806 |
- my $result = $dbi->select(table => 'books', where => {title => 1});
|
|
| 845 |
+ # select * from books where title = ?; |
|
| 846 |
+ my $result = $dbi->select(table => 'books', where => {title => 'Perl'});
|
|
| 807 | 847 |
|
| 808 |
- # select title, author from books where id = 1 for update; |
|
| 848 |
+ # select title, author from books where id = ? for update; |
|
| 809 | 849 |
my $result = $dbi->select( |
| 810 | 850 |
table => 'books', |
| 811 | 851 |
column => ['title', 'author'], |
| ... | ... |
@@ -821,23 +861,22 @@ B<Example:> |
| 821 | 861 |
relation => {'books.id' => 'rental.book_id'}
|
| 822 | 862 |
); |
| 823 | 863 |
|
| 824 |
-=head2 C<build_query> |
|
| 864 |
+=head2 C<create_query> |
|
| 825 | 865 |
|
| 826 |
- my $query = $dbi->build_query( |
|
| 866 |
+ my $query = $dbi->create_query( |
|
| 827 | 867 |
"select * from authors where {= name} and {= age};"
|
| 828 | 868 |
); |
| 829 | 869 |
|
| 830 |
-Build the instance of L<DBIx::Custom::Query> |
|
| 831 |
-using L<DBIx::Custom::QueryBuilder>. |
|
| 870 |
+Create the instance of L<DBIx::Custom::Query> from SQL source. |
|
| 832 | 871 |
|
| 833 | 872 |
=head2 C<execute> |
| 834 | 873 |
|
| 835 | 874 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
| 836 | 875 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
| 837 | 876 |
|
| 838 |
-Execute the instace of L<DBIx::Custom::Query> or |
|
| 839 |
-the string written by SQL template. |
|
| 840 |
-Return value is the instance of L<DBIx::Custom::Result>. |
|
| 877 |
+Execute query or SQL source. Query is L<DBIx::Csutom::Query> object. |
|
| 878 |
+Return value is L<DBIx::Custom::Result> in select statement, |
|
| 879 |
+or the count of affected rows in insert, update, delete statement. |
|
| 841 | 880 |
|
| 842 | 881 |
B<Example:> |
| 843 | 882 |
|
| ... | ... |
@@ -853,7 +892,42 @@ B<Example:> |
| 853 | 892 |
$dbi->register_filter(%filters); |
| 854 | 893 |
$dbi->register_filter(\%filters); |
| 855 | 894 |
|
| 856 |
-Resister filter. |
|
| 895 |
+Register filter. Registered filters is available in the following methods |
|
| 896 |
+or arguments. |
|
| 897 |
+ |
|
| 898 |
+=over 4 |
|
| 899 |
+ |
|
| 900 |
+=item * |
|
| 901 |
+ |
|
| 902 |
+C<default_bind_filter()> |
|
| 903 |
+ |
|
| 904 |
+=item * |
|
| 905 |
+ |
|
| 906 |
+C<default_fetch_filter()> |
|
| 907 |
+ |
|
| 908 |
+=item * |
|
| 909 |
+ |
|
| 910 |
+C<filter> argument of C<insert()>, C<update()>, |
|
| 911 |
+C<update_all()>, C<delete()>, C<delete_all()>, C<select()>, |
|
| 912 |
+C<execute> method. |
|
| 913 |
+ |
|
| 914 |
+=item * |
|
| 915 |
+ |
|
| 916 |
+C<DBIx::Custom::Query::default_filter()> |
|
| 917 |
+ |
|
| 918 |
+=item * |
|
| 919 |
+ |
|
| 920 |
+C<DBIx::Csutom::Query::filter()> |
|
| 921 |
+ |
|
| 922 |
+=item * |
|
| 923 |
+ |
|
| 924 |
+C<DBIx::Custom::Result::default_filter()> |
|
| 925 |
+ |
|
| 926 |
+=item * |
|
| 927 |
+ |
|
| 928 |
+C<DBIx::Custom::Result::filter()> |
|
| 929 |
+ |
|
| 930 |
+=back |
|
| 857 | 931 |
|
| 858 | 932 |
B<Example:> |
| 859 | 933 |
|
| ... | ... |
@@ -876,7 +950,7 @@ B<Example:> |
| 876 | 950 |
|
| 877 | 951 |
=head1 BUGS |
| 878 | 952 |
|
| 879 |
-Please tell me bugs. |
|
| 953 |
+Please tell me bugs if found. |
|
| 880 | 954 |
|
| 881 | 955 |
C<< <kimoto.yuki at gmail.com> >> |
| 882 | 956 |
|
| ... | ... |
@@ -255,7 +255,7 @@ Query |
| 255 | 255 |
|
| 256 | 256 |
Register tag processor. |
| 257 | 257 |
|
| 258 |
-B<Examples:> |
|
| 258 |
+B<Example:> |
|
| 259 | 259 |
|
| 260 | 260 |
$builder->register_tag_processor( |
| 261 | 261 |
'?' => sub {
|
| ... | ... |
@@ -265,11 +265,11 @@ B<Examples:> |
| 265 | 265 |
} |
| 266 | 266 |
); |
| 267 | 267 |
|
| 268 |
-See L<DBIx::Custom::QueryBuilder::TagProcessors> about tag processor. |
|
| 268 |
+See also L<DBIx::Custom::QueryBuilder::TagProcessors> to know tag processor. |
|
| 269 | 269 |
|
| 270 | 270 |
=head1 Tags |
| 271 | 271 |
|
| 272 |
-You can use the following tags in SQL source. |
|
| 272 |
+The following tags is available. |
|
| 273 | 273 |
|
| 274 | 274 |
[Tags] [Replaced] |
| 275 | 275 |
{? NAME} -> ?
|
| ... | ... |
@@ -88,9 +88,9 @@ sub update {
|
| 88 | 88 |
|
| 89 | 89 |
DBIx::Custom::SQLBuilder::TagProcessors - Tag processors |
| 90 | 90 |
|
| 91 |
-=head1 Processors |
|
| 91 |
+=head1 Tag processors |
|
| 92 | 92 |
|
| 93 |
-Processor is function, |
|
| 93 |
+Tag processor is function, |
|
| 94 | 94 |
which receive arguments and return a part of SQL statment |
| 95 | 95 |
and column names. |
| 96 | 96 |
The part of SQL statment contains placeholders. |
| ... | ... |
@@ -252,7 +252,7 @@ This overwrites C<default_filter>. |
| 252 | 252 |
|
| 253 | 253 |
=head1 METHODS |
| 254 | 254 |
|
| 255 |
-L<DBIx::Custom::Resutl> inherits all methods from L<Object::Simple> |
|
| 255 |
+L<DBIx::Custom::Result> inherits all methods from L<Object::Simple> |
|
| 256 | 256 |
and implements the following new ones. |
| 257 | 257 |
|
| 258 | 258 |
=head2 C<fetch> |
| ... | ... |
@@ -1,14 +1,9 @@ |
| 1 | 1 |
#!perl -T |
| 2 | 2 |
|
| 3 |
-use Test::More tests => 6; |
|
| 3 |
+use Test::More tests => 1; |
|
| 4 | 4 |
|
| 5 | 5 |
BEGIN {
|
| 6 |
- use_ok( 'DBIx::Custom' ); |
|
| 7 |
- use_ok( 'DBIx::Custom::MySQL' ); |
|
| 8 |
- use_ok( 'DBIx::Custom::Query' ); |
|
| 9 |
- use_ok( 'DBIx::Custom::Result' ); |
|
| 10 |
- use_ok( 'DBIx::Custom::SQLTemplate' ); |
|
| 11 |
- use_ok( 'DBIx::Custom::SQLite' ); |
|
| 6 |
+ use_ok('DBIx::Custom' );
|
|
| 12 | 7 |
} |
| 13 | 8 |
|
| 14 | 9 |
diag( "Testing DBIx::Custom $DBIx::Custom::VERSION, Perl $], $^X" ); |
| ... | ... |
@@ -43,8 +43,8 @@ my $NEW_ARGS = {
|
| 43 | 43 |
# Variables |
| 44 | 44 |
my $dbi; |
| 45 | 45 |
my $sth; |
| 46 |
-my $tmpl; |
|
| 47 |
-my @tmpls; |
|
| 46 |
+my $source; |
|
| 47 |
+my @sources; |
|
| 48 | 48 |
my $select_tmpl; |
| 49 | 49 |
my $insert_tmpl; |
| 50 | 50 |
my $update_tmpl; |
| ... | ... |
@@ -69,8 +69,8 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 69 | 69 |
$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
|
| 70 | 70 |
|
| 71 | 71 |
test 'DBIx::Custom::Result test'; |
| 72 |
-$tmpl = "select key1, key2 from table1"; |
|
| 73 |
-$query = $dbi->build_query($tmpl); |
|
| 72 |
+$source = "select key1, key2 from table1"; |
|
| 73 |
+$query = $dbi->create_query($source); |
|
| 74 | 74 |
$result = $dbi->execute($query); |
| 75 | 75 |
|
| 76 | 76 |
@rows = (); |
| ... | ... |
@@ -97,8 +97,8 @@ 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 |
-$tmpl = "insert into table1 {insert key1 key2}";
|
|
| 101 |
-$query = $dbi->build_query($tmpl); |
|
| 100 |
+$source = "insert into table1 {insert key1 key2}";
|
|
| 101 |
+$query = $dbi->create_query($source); |
|
| 102 | 102 |
$ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
|
| 103 | 103 |
ok($ret_val, $test); |
| 104 | 104 |
|
| ... | ... |
@@ -119,7 +119,7 @@ $dbi->register_filter(twice => sub { $_[0] * 2},
|
| 119 | 119 |
three_times => sub { $_[0] * 3});
|
| 120 | 120 |
|
| 121 | 121 |
$insert_tmpl = "insert into table1 {insert key1 key2};";
|
| 122 |
-$insert_query = $dbi->build_query($insert_tmpl); |
|
| 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});
|
| 125 | 125 |
$result = $dbi->execute($SELECT_TMPLS->{0});
|
| ... | ... |
@@ -130,10 +130,10 @@ $dbi->execute($DROP_TABLE->{0});
|
| 130 | 130 |
test 'Filter in'; |
| 131 | 131 |
$dbi->execute($CREATE_TABLE->{0});
|
| 132 | 132 |
$insert_tmpl = "insert into table1 {insert key1 key2};";
|
| 133 |
-$insert_query = $dbi->build_query($insert_tmpl); |
|
| 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}";
|
| 136 |
-$select_query = $dbi->build_query($select_tmpl); |
|
| 136 |
+$select_query = $dbi->create_query($select_tmpl); |
|
| 137 | 137 |
$select_query->filter({'table1.key1' => 'twice'});
|
| 138 | 138 |
$result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
|
| 139 | 139 |
$rows = $result->fetch_hash_all; |
| ... | ... |
@@ -145,14 +145,14 @@ $dbi->execute($CREATE_TABLE->{1});
|
| 145 | 145 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 146 | 146 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 147 | 147 |
|
| 148 |
-$tmpl = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 149 |
-$query = $dbi->build_query($tmpl); |
|
| 148 |
+$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 149 |
+$query = $dbi->create_query($source); |
|
| 150 | 150 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
| 151 | 151 |
$rows = $result->fetch_hash_all; |
| 152 | 152 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
|
| 153 | 153 |
|
| 154 |
-$tmpl = "select * from table1 where {<= key1} and {like key2};";
|
|
| 155 |
-$query = $dbi->build_query($tmpl); |
|
| 154 |
+$source = "select * from table1 where {<= key1} and {like key2};";
|
|
| 155 |
+$query = $dbi->create_query($source); |
|
| 156 | 156 |
$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
|
| 157 | 157 |
$rows = $result->fetch_hash_all; |
| 158 | 158 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
|
| ... | ... |
@@ -163,8 +163,8 @@ $dbi->execute($CREATE_TABLE->{1});
|
| 163 | 163 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 164 | 164 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 165 | 165 |
|
| 166 |
-$tmpl = "select * from table1 where {in key1 2};";
|
|
| 167 |
-$query = $dbi->build_query($tmpl); |
|
| 166 |
+$source = "select * from table1 where {in key1 2};";
|
|
| 167 |
+$query = $dbi->create_query($source); |
|
| 168 | 168 |
$result = $dbi->execute($query, param => {key1 => [9, 1]});
|
| 169 | 169 |
$rows = $result->fetch_hash_all; |
| 170 | 170 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
|
| ... | ... |
@@ -197,8 +197,8 @@ eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
|
| 197 | 197 |
ok($@, "$test : connect error"); |
| 198 | 198 |
|
| 199 | 199 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 200 |
-eval{$dbi->build_query("{p }")};
|
|
| 201 |
-ok($@, "$test : build_query invalid SQL template"); |
|
| 200 |
+eval{$dbi->create_query("{p }")};
|
|
| 201 |
+ok($@, "$test : create_query invalid SQL template"); |
|
| 202 | 202 |
|
| 203 | 203 |
test 'insert'; |
| 204 | 204 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| ... | ... |
@@ -431,9 +431,9 @@ ok(! $result->fetch_first, "$test: rollback"); |
| 431 | 431 |
test 'cache'; |
| 432 | 432 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 433 | 433 |
$dbi->execute($CREATE_TABLE->{0});
|
| 434 |
-$tmpl = 'select * from table1 where {= key1} and {= key2};';
|
|
| 435 |
-$dbi->build_query($tmpl); |
|
| 436 |
-is_deeply($dbi->{_cached}->{$tmpl},
|
|
| 434 |
+$source = 'select * from table1 where {= key1} and {= key2};';
|
|
| 435 |
+$dbi->create_query($source); |
|
| 436 |
+is_deeply($dbi->{_cached}->{$source},
|
|
| 437 | 437 |
{sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2']}, "$test : cache");
|
| 438 | 438 |
|
| 439 | 439 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|