| ... | ... |
@@ -1,3 +1,7 @@ |
| 1 |
+0.1604 |
|
| 2 |
+ removed DESTROY method(not backword compatible) |
|
| 3 |
+ removed disconnect method(not backword compatible) |
|
| 4 |
+ fixed DBIx::Custom::MySQL connect_memory |
|
| 1 | 5 |
0.1603 |
| 2 | 6 |
removed DBIx::Custom commit method (not backword compatible) |
| 3 | 7 |
removed DBIx::Custom rollback method (not backword compatible) |
| ... | ... |
@@ -74,15 +74,14 @@ sub connect {
|
| 74 | 74 |
return $self; |
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 |
-sub disconnect {
|
|
| 78 |
- my $self = shift; |
|
| 77 |
+sub register_filter {
|
|
| 78 |
+ my $invocant = shift; |
|
| 79 | 79 |
|
| 80 |
- # Disconnect |
|
| 81 |
- my $ret = eval { $self->dbh->disconnect };
|
|
| 82 |
- croak $@ if $@; |
|
| 83 |
- $self->dbh(undef); |
|
| 80 |
+ # Add filter |
|
| 81 |
+ my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
|
|
| 82 |
+ $invocant->filters({%{$invocant->filters}, %$filters});
|
|
| 84 | 83 |
|
| 85 |
- return $ret; |
|
| 84 |
+ return $invocant; |
|
| 86 | 85 |
} |
| 87 | 86 |
|
| 88 | 87 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append filter/;
|
| ... | ... |
@@ -110,7 +109,8 @@ sub insert {
|
| 110 | 109 |
unless @insert_keys; |
| 111 | 110 |
|
| 112 | 111 |
# Templte for insert |
| 113 |
- my $template = "insert into $table {insert " . join(' ', @insert_keys) . '}';
|
|
| 112 |
+ my $template = "insert into $table {insert "
|
|
| 113 |
+ . join(' ', @insert_keys) . '}';
|
|
| 114 | 114 |
$template .= " $append" if $append; |
| 115 | 115 |
|
| 116 | 116 |
# Execute query |
| ... | ... |
@@ -444,7 +444,8 @@ sub _build_bind_values {
|
| 444 | 444 |
} |
| 445 | 445 |
else {
|
| 446 | 446 |
my $filters = $self->filters; |
| 447 |
- croak "Not exists filter \"$fname\"" unless exists $filters->{$fname};
|
|
| 447 |
+ croak "Not exists filter \"$fname\"" |
|
| 448 |
+ unless exists $filters->{$fname};
|
|
| 448 | 449 |
$filter_func = $filters->{$fname};
|
| 449 | 450 |
} |
| 450 | 451 |
} |
| ... | ... |
@@ -460,44 +461,23 @@ sub _build_bind_values {
|
| 460 | 461 |
return \@bind_values; |
| 461 | 462 |
} |
| 462 | 463 |
|
| 463 |
-sub register_filter {
|
|
| 464 |
- my $invocant = shift; |
|
| 465 |
- |
|
| 466 |
- # Add filter |
|
| 467 |
- my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
|
|
| 468 |
- $invocant->filters({%{$invocant->filters}, %$filters});
|
|
| 469 |
- |
|
| 470 |
- return $invocant; |
|
| 471 |
-} |
|
| 472 |
- |
|
| 473 |
-sub DESTROY {
|
|
| 474 |
- my $self = shift; |
|
| 475 |
- |
|
| 476 |
- # Disconnect |
|
| 477 |
- $self->disconnect if $self->dbh; |
|
| 478 |
-} |
|
| 479 |
- |
|
| 480 | 464 |
=head1 NAME |
| 481 | 465 |
|
| 482 | 466 |
DBIx::Custom - DBI with hash parameter binding and filtering system |
| 483 | 467 |
|
| 484 | 468 |
=cut |
| 485 | 469 |
|
| 486 |
-our $VERSION = '0.1603'; |
|
| 470 |
+our $VERSION = '0.1604'; |
|
| 487 | 471 |
|
| 488 | 472 |
=head1 STABILITY |
| 489 | 473 |
|
| 490 |
-This module is not stable. Method name and implementations will be change. |
|
| 474 |
+This module is not stable. Method name and implementations will be changed. |
|
| 491 | 475 |
|
| 492 | 476 |
=head1 SYNOPSYS |
| 493 | 477 |
|
| 494 | 478 |
# Connect |
| 495 | 479 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
| 496 | 480 |
user => 'ken', password => '!LFKD%$&'); |
| 497 |
- |
|
| 498 |
- # Disconnect |
|
| 499 |
- $dbi->disconnect |
|
| 500 |
- |
|
| 501 | 481 |
# Insert |
| 502 | 482 |
$dbi->insert(table => 'books', |
| 503 | 483 |
param => {title => 'perl', author => 'Ken'},
|
| ... | ... |
@@ -569,7 +549,7 @@ This module is not stable. Method name and implementations will be change. |
| 569 | 549 |
|
| 570 | 550 |
} |
| 571 | 551 |
|
| 572 |
- # DBI instance |
|
| 552 |
+ # Get DBI object |
|
| 573 | 553 |
my $dbh = $dbi->dbh; |
| 574 | 554 |
|
| 575 | 555 |
=head1 DESCRIPTION |
| ... | ... |
@@ -590,11 +570,17 @@ And have useful method such as insert(), update(), delete(), and select(). |
| 590 | 570 |
|
| 591 | 571 |
=over 4 |
| 592 | 572 |
|
| 593 |
-=item 1. Hash parameter binding. |
|
| 573 |
+=item * |
|
| 594 | 574 |
|
| 595 |
-=item 2. Value filtering. |
|
| 575 |
+Hash parameter binding. |
|
| 596 | 576 |
|
| 597 |
-=item 3. Useful methos such as insert(), update(), delete(), and select(). |
|
| 577 |
+=item * |
|
| 578 |
+ |
|
| 579 |
+Value filtering. |
|
| 580 |
+ |
|
| 581 |
+=item * |
|
| 582 |
+ |
|
| 583 |
+Provide suger methods, such as insert(), update(), delete(), and select(). |
|
| 598 | 584 |
|
| 599 | 585 |
=back |
| 600 | 586 |
|
| ... | ... |
@@ -602,82 +588,83 @@ And have useful method such as insert(), update(), delete(), and select(). |
| 602 | 588 |
|
| 603 | 589 |
=head2 C<user> |
| 604 | 590 |
|
| 605 |
-Database user name. |
|
| 606 |
- |
|
| 607 | 591 |
$dbi = $dbi->user('Ken');
|
| 608 | 592 |
$user = $dbi->user; |
| 593 |
+ |
|
| 594 |
+Database user name. |
|
| 595 |
+This is used for connect(). |
|
| 609 | 596 |
|
| 610 | 597 |
=head2 C<password> |
| 611 | 598 |
|
| 612 |
-Database password. |
|
| 613 |
- |
|
| 614 | 599 |
$dbi = $dbi->password('lkj&le`@s');
|
| 615 | 600 |
$password = $dbi->password; |
| 616 | 601 |
|
| 602 |
+Database password. |
|
| 603 |
+This is used for connect(). |
|
| 604 |
+ |
|
| 617 | 605 |
=head2 C<data_source> |
| 618 | 606 |
|
| 619 |
-Database data source. |
|
| 620 |
- |
|
| 621 | 607 |
$dbi = $dbi->data_source("dbi:mysql:dbname=$database");
|
| 622 | 608 |
$data_source = $dbi->data_source; |
| 623 |
- |
|
| 609 |
+ |
|
| 610 |
+Database data source. |
|
| 611 |
+This is used for connect(). |
|
| 612 |
+ |
|
| 624 | 613 |
=head2 C<dbh> |
| 625 | 614 |
|
| 626 |
-Database handle. This is the innstance of L<DBI> |
|
| 627 |
- |
|
| 628 | 615 |
$dbi = $dbi->dbh($dbh); |
| 629 | 616 |
$dbh = $dbi->dbh; |
| 630 | 617 |
|
| 631 |
-You can use all methods of L<DBI> |
|
| 618 |
+Database handle. This is a L<DBI> object. |
|
| 619 |
+You can call all methods of L<DBI> |
|
| 632 | 620 |
|
| 633 | 621 |
my $sth = $dbi->dbh->prepare("...");
|
| 634 | 622 |
my $errstr = $dbi->dbh->errstr; |
| 623 |
+ $dbi->dbh->begin_work; |
|
| 624 |
+ $dbi->dbh->commit; |
|
| 625 |
+ $dbi->dbh->rollback; |
|
| 635 | 626 |
|
| 636 | 627 |
=head2 C<filters> |
| 637 | 628 |
|
| 638 |
-Filters |
|
| 639 |
- |
|
| 640 | 629 |
$dbi = $dbi->filters({%filters});
|
| 641 | 630 |
$filters = $dbi->filters; |
| 642 | 631 |
|
| 643 |
-encode_utf8 and decode_utf8 is set to this attribute by default. |
|
| 632 |
+Filter functions. |
|
| 633 |
+By default, "encode_utf8" and "decode_utf8" is registered. |
|
| 644 | 634 |
|
| 645 | 635 |
$encode_utf8 = $dbi->filters->{encode_utf8};
|
| 646 | 636 |
$decode_utf8 = $dbi->filters->{decode_utf8};
|
| 647 | 637 |
|
| 648 | 638 |
=head2 C<default_query_filter> |
| 649 | 639 |
|
| 650 |
-Default query filter. |
|
| 651 |
- |
|
| 652 | 640 |
$dbi = $dbi->default_query_filter('encode_utf8');
|
| 653 | 641 |
$default_query_filter = $dbi->default_query_filter |
| 654 | 642 |
|
| 655 |
-=head2 C<default_fetch_filter> |
|
| 643 |
+Default filter for value binding |
|
| 656 | 644 |
|
| 657 |
-Fetching filter. |
|
| 645 |
+=head2 C<default_fetch_filter> |
|
| 658 | 646 |
|
| 659 | 647 |
$dbi = $dbi->default_fetch_filter('decode_utf8');
|
| 660 | 648 |
$default_fetch_filter = $dbi->default_fetch_filter; |
| 661 | 649 |
|
| 662 |
-=head2 C<result_class> |
|
| 650 |
+Default filter for fetching. |
|
| 663 | 651 |
|
| 664 |
-Result class. |
|
| 652 |
+=head2 C<result_class> |
|
| 665 | 653 |
|
| 666 | 654 |
$dbi = $dbi->result_class('DBIx::Custom::Result');
|
| 667 | 655 |
$result_class = $dbi->result_class; |
| 668 | 656 |
|
| 669 |
-L<DBIx::Custom::Result> is set to this attribute by default. |
|
| 657 |
+Result class for select statement. |
|
| 658 |
+Default to L<DBIx::Custom::Result> |
|
| 670 | 659 |
|
| 671 | 660 |
=head2 C<sql_template> |
| 672 | 661 |
|
| 673 |
-SQLTemplate instance. sql_template attribute must be |
|
| 674 |
-the instance of L<DBIx::Cutom::SQLTemplate> subclass. |
|
| 675 |
- |
|
| 676 | 662 |
$dbi = $dbi->sql_template(DBIx::Cutom::SQLTemplate->new); |
| 677 | 663 |
$sql_template = $dbi->sql_template; |
| 678 | 664 |
|
| 679 |
-the instance of DBIx::Cutom::SQLTemplate is set to |
|
| 680 |
-this attribute by default. |
|
| 665 |
+SQLTemplate instance. sql_template attribute must be |
|
| 666 |
+the instance of L<DBIx::Cutom::SQLTemplate> subclass. |
|
| 667 |
+Default to DBIx::Cutom::SQLTemplate object |
|
| 681 | 668 |
|
| 682 | 669 |
=head1 METHODS |
| 683 | 670 |
|
| ... | ... |
@@ -686,36 +673,25 @@ You can use all methods of L<Object::Simple> |
| 686 | 673 |
|
| 687 | 674 |
=head2 C<connect> |
| 688 | 675 |
|
| 689 |
-Connect to database. |
|
| 690 |
- |
|
| 691 | 676 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=books", |
| 692 | 677 |
user => 'ken', password => '!LFKD%$&'); |
| 693 | 678 |
|
| 679 |
+Connect to database. |
|
| 694 | 680 |
"AutoCommit" and "RaiseError" option is true, |
| 695 |
-and "PrintError" option is false by dfault. |
|
| 696 |
- |
|
| 697 |
-=head2 C<disconnect> |
|
| 698 |
- |
|
| 699 |
-Disconnect database. |
|
| 700 |
- |
|
| 701 |
- $dbi->disconnect; |
|
| 702 |
- |
|
| 703 |
-If database is already disconnected, this method do nothing. |
|
| 681 |
+and "PrintError" option is false by default. |
|
| 704 | 682 |
|
| 705 | 683 |
=head2 C<insert> |
| 706 | 684 |
|
| 707 |
-Insert row. |
|
| 708 |
- |
|
| 709 | 685 |
$affected = $dbi->insert(table => $table, |
| 710 | 686 |
param => {%param},
|
| 711 | 687 |
append => $append, |
| 712 | 688 |
filter => {%filter});
|
| 713 | 689 |
|
| 714 |
-Retruned value is affected rows count. |
|
| 690 |
+Insert row. |
|
| 691 |
+Retrun value is the count of affected rows. |
|
| 715 | 692 |
|
| 716 |
-Example: |
|
| 693 |
+B<Example:> |
|
| 717 | 694 |
|
| 718 |
- # insert |
|
| 719 | 695 |
$dbi->insert(table => 'books', |
| 720 | 696 |
param => {title => 'Perl', author => 'Taro'},
|
| 721 | 697 |
append => "some statement", |
| ... | ... |
@@ -723,19 +699,17 @@ Example: |
| 723 | 699 |
|
| 724 | 700 |
=head2 C<update> |
| 725 | 701 |
|
| 726 |
-Update rows. |
|
| 727 |
- |
|
| 728 | 702 |
$affected = $dbi->update(table => $table, |
| 729 | 703 |
param => {%params},
|
| 730 | 704 |
where => {%where},
|
| 731 | 705 |
append => $append, |
| 732 | 706 |
filter => {%filter})
|
| 733 | 707 |
|
| 734 |
-Retruned value is affected rows count |
|
| 708 |
+Update rows. |
|
| 709 |
+Retrun value is the count of affected rows. |
|
| 735 | 710 |
|
| 736 |
-Example: |
|
| 711 |
+B<Example:> |
|
| 737 | 712 |
|
| 738 |
- #update |
|
| 739 | 713 |
$dbi->update(table => 'books', |
| 740 | 714 |
param => {title => 'Perl', author => 'Taro'},
|
| 741 | 715 |
where => {id => 5},
|
| ... | ... |
@@ -744,36 +718,32 @@ Example: |
| 744 | 718 |
|
| 745 | 719 |
=head2 C<update_all> |
| 746 | 720 |
|
| 747 |
-Update all rows. |
|
| 748 |
- |
|
| 749 | 721 |
$affected = $dbi->update_all(table => $table, |
| 750 | 722 |
param => {%params},
|
| 751 | 723 |
filter => {%filter},
|
| 752 | 724 |
append => $append); |
| 753 | 725 |
|
| 754 |
-Retruned value is affected rows count. |
|
| 726 |
+Update all rows. |
|
| 727 |
+Retrun value is the count of affected rows. |
|
| 755 | 728 |
|
| 756 |
-Example: |
|
| 729 |
+B<Example:> |
|
| 757 | 730 |
|
| 758 |
- # update_all |
|
| 759 | 731 |
$dbi->update_all(table => 'books', |
| 760 | 732 |
param => {author => 'taro'},
|
| 761 | 733 |
filter => {author => 'encode_utf8'});
|
| 762 | 734 |
|
| 763 | 735 |
=head2 C<delete> |
| 764 | 736 |
|
| 765 |
-Delete rows. |
|
| 766 |
- |
|
| 767 | 737 |
$affected = $dbi->delete(table => $table, |
| 768 | 738 |
where => {%where},
|
| 769 | 739 |
append => $append, |
| 770 | 740 |
filter => {%filter});
|
| 771 | 741 |
|
| 772 |
-Retrun value is affected rows count |
|
| 742 |
+Delete rows. |
|
| 743 |
+Retrun value is the count of affected rows. |
|
| 773 | 744 |
|
| 774 |
-Example: |
|
| 745 |
+B<Example:> |
|
| 775 | 746 |
|
| 776 |
- # delete |
|
| 777 | 747 |
$dbi->delete(table => 'books', |
| 778 | 748 |
where => {id => 5},
|
| 779 | 749 |
append => 'some statement', |
| ... | ... |
@@ -781,21 +751,17 @@ Example: |
| 781 | 751 |
|
| 782 | 752 |
=head2 C<delete_all> |
| 783 | 753 |
|
| 784 |
-Delete all rows. |
|
| 785 |
- |
|
| 786 | 754 |
$affected = $dbi->delete_all(table => $table); |
| 787 | 755 |
|
| 788 |
-Retruned value is affected rows count. |
|
| 756 |
+Delete all rows. |
|
| 757 |
+Retrun value is the count of affected rows. |
|
| 789 | 758 |
|
| 790 |
-Example: |
|
| 759 |
+B<Example:> |
|
| 791 | 760 |
|
| 792 |
- # delete_all |
|
| 793 | 761 |
$dbi->delete_all(table => 'books'); |
| 794 | 762 |
|
| 795 | 763 |
=head2 C<select> |
| 796 | 764 |
|
| 797 |
-Select rows. |
|
| 798 |
- |
|
| 799 | 765 |
$result = $dbi->select(table => $table, |
| 800 | 766 |
column => [@column], |
| 801 | 767 |
where => {%where},
|
| ... | ... |
@@ -803,9 +769,10 @@ Select rows. |
| 803 | 769 |
relation => {%relation},
|
| 804 | 770 |
filter => {%filter});
|
| 805 | 771 |
|
| 772 |
+Select rows. |
|
| 806 | 773 |
Return value is the instance of L<DBIx::Custom::Result>. |
| 807 | 774 |
|
| 808 |
-Example: |
|
| 775 |
+B<Example:> |
|
| 809 | 776 |
|
| 810 | 777 |
# select * from books; |
| 811 | 778 |
$result = $dbi->select(table => 'books'); |
| ... | ... |
@@ -861,6 +828,7 @@ See also L<DBIx::Custom::SQLTemplate> to know how to write SQL template. |
| 861 | 828 |
=head2 C<register_filter> |
| 862 | 829 |
|
| 863 | 830 |
$dbi->register_filter(%filters); |
| 831 |
+ $dbi->register_filter(\%filters); |
|
| 864 | 832 |
|
| 865 | 833 |
Resister filter. |
| 866 | 834 |
|
| ... | ... |
@@ -915,6 +883,14 @@ B<Example:> |
| 915 | 883 |
} |
| 916 | 884 |
); |
| 917 | 885 |
|
| 886 |
+=head1 BUGS |
|
| 887 |
+ |
|
| 888 |
+Please tell me bugs. |
|
| 889 |
+ |
|
| 890 |
+C<< <kimoto.yuki at gmail.com> >> |
|
| 891 |
+ |
|
| 892 |
+L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
| 893 |
+ |
|
| 918 | 894 |
=head1 AUTHOR |
| 919 | 895 |
|
| 920 | 896 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
package DBIx::Custom::MySQL; |
| 2 | 2 |
|
| 3 |
-use warnings; |
|
| 4 | 3 |
use strict; |
| 4 |
+use warnings; |
|
| 5 | 5 |
|
| 6 | 6 |
use base 'DBIx::Custom'; |
| 7 | 7 |
|
| ... | ... |
@@ -36,16 +36,16 @@ sub last_insert_id { shift->dbh->{mysql_insertid} }
|
| 36 | 36 |
|
| 37 | 37 |
=head1 NAME |
| 38 | 38 |
|
| 39 |
-DBIx::Custom::MySQL - a MySQL implementation of DBIx::Custom |
|
| 39 |
+DBIx::Custom::MySQL - Implementation for MySQL |
|
| 40 | 40 |
|
| 41 | 41 |
=head1 SYNOPSYS |
| 42 | 42 |
|
| 43 |
- # Connect |
|
| 44 |
- my $dbi = DBIx::Custom::MySQL->connect(user => 'taro', |
|
| 43 |
+ # Connect to database |
|
| 44 |
+ my $dbi = DBIx::Custom::MySQL->connect(user => 'taro', |
|
| 45 | 45 |
password => 'kliej&@K', |
| 46 |
- database => 'your_database'); |
|
| 46 |
+ database => 'your_database'); |
|
| 47 | 47 |
|
| 48 |
- # Last insert id |
|
| 48 |
+ # Get last insert id |
|
| 49 | 49 |
my $id = $dbi->last_insert_id; |
| 50 | 50 |
|
| 51 | 51 |
=head1 ATTRIBUTES |
| ... | ... |
@@ -55,29 +55,30 @@ You can use all attributes of L<DBIx::Custom> |
| 55 | 55 |
|
| 56 | 56 |
=head2 C<database> |
| 57 | 57 |
|
| 58 |
-Database name |
|
| 59 |
- |
|
| 60 | 58 |
$dbi = $dbi->database('your_database');
|
| 61 | 59 |
$database = $dbi->database; |
| 62 | 60 |
|
| 63 |
-=head2 C<host> |
|
| 61 |
+Database name. |
|
| 62 |
+This is used for connect(). |
|
| 64 | 63 |
|
| 65 |
-Database host name. |
|
| 64 |
+=head2 C<host> |
|
| 66 | 65 |
|
| 67 | 66 |
$dbi = $dbi->host('somehost.com');
|
| 68 | 67 |
$host = $dbi->host; |
| 69 | 68 |
|
| 70 |
-IP address can be set to host attribute. |
|
| 69 |
+Database host name. |
|
| 70 |
+You can also set IP address, instead of host name. |
|
| 71 |
+This is used for connect(). |
|
| 71 | 72 |
|
| 72 | 73 |
$dbi->host('127.03.45.12');
|
| 73 | 74 |
|
| 74 | 75 |
=head2 C<port> |
| 75 | 76 |
|
| 76 |
-Database port. |
|
| 77 |
- |
|
| 78 | 77 |
$dbi = $dbi->port(1198); |
| 79 | 78 |
$port = $dbi->port; |
| 80 | 79 |
|
| 80 |
+Database port. This is used for connect(). |
|
| 81 |
+ |
|
| 81 | 82 |
=head1 METHODS |
| 82 | 83 |
|
| 83 | 84 |
This class is L<DBIx::Custom> subclass. |
| ... | ... |
@@ -85,20 +86,24 @@ You can use all methods of L<DBIx::Custom>. |
| 85 | 86 |
|
| 86 | 87 |
=head2 C<connect (overridden)> |
| 87 | 88 |
|
| 88 |
-Connect to database. |
|
| 89 |
+ $dbi = DBIx::Custom::MySQL->connect( |
|
| 90 |
+ data_source => "dbi:mysql:database=books;host=somehost;port=2000" |
|
| 91 |
+ ); |
|
| 92 |
+ |
|
| 93 |
+ $dbi = DBIx::Custom::MySQL->connect(user => 'taro', |
|
| 94 |
+ password => 'kliej&@K', |
|
| 95 |
+ database => 'your_database', |
|
| 96 |
+ host => 'somehost', |
|
| 97 |
+ port => 2000); |
|
| 89 | 98 |
|
| 90 |
- # Connect |
|
| 91 |
- my $dbi = DBIx::Custom::MySQL->connect(user => 'taro', |
|
| 92 |
- password => 'kliej&@K', |
|
| 93 |
- database => 'your_database'); |
|
| 99 |
+Connect to database. You can also specify database, host, and port |
|
| 100 |
+(instead of data soruce). |
|
| 94 | 101 |
|
| 95 | 102 |
=head2 C<last_insert_id> |
| 96 | 103 |
|
| 97 |
-Last insert ID. |
|
| 98 |
- |
|
| 99 | 104 |
$last_insert_id = $dbi->last_insert_id; |
| 100 | 105 |
|
| 106 |
+Get last insert id. |
|
| 101 | 107 |
This is equal to MySQL last_insert_id() function. |
| 102 | 108 |
|
| 103 |
- |
|
| 104 | 109 |
=cut |
| ... | ... |
@@ -11,50 +11,49 @@ __PACKAGE__->attr([qw/sql columns default_filter filter sth/]); |
| 11 | 11 |
|
| 12 | 12 |
=head1 NAME |
| 13 | 13 |
|
| 14 |
-DBIx::Custom::Query - query used by DBIx::Custom |
|
| 14 |
+DBIx::Custom::Query - Query |
|
| 15 | 15 |
|
| 16 | 16 |
=head1 SYNOPSIS |
| 17 | 17 |
|
| 18 |
- # New |
|
| 19 | 18 |
my $query = DBIx::Custom::Query->new; |
| 20 | 19 |
|
| 21 | 20 |
=head1 ATTRIBUTES |
| 22 | 21 |
|
| 23 | 22 |
=head2 C<sql> |
| 24 | 23 |
|
| 25 |
-SQL statement. |
|
| 26 |
- |
|
| 27 | 24 |
$query = $query->sql($sql); |
| 28 | 25 |
$sql = $query->sql; |
| 29 | 26 |
|
| 30 |
-=head2 C<columns> |
|
| 27 |
+SQL statement. |
|
| 31 | 28 |
|
| 32 |
-Column names. |
|
| 29 |
+=head2 C<columns> |
|
| 33 | 30 |
|
| 34 | 31 |
$query = $query->columns([@columns]); |
| 35 | 32 |
$columns = $query->columns; |
| 36 | 33 |
|
| 37 |
-=head2 C<default_filter> |
|
| 34 |
+Column names. |
|
| 38 | 35 |
|
| 39 |
-Default filter. |
|
| 36 |
+=head2 C<default_filter> |
|
| 40 | 37 |
|
| 41 | 38 |
$query = $query->default_filter($filter); |
| 42 | 39 |
$default_filter = $query->default_filter; |
| 43 | 40 |
|
| 44 |
-=head2 C<filter> |
|
| 41 |
+Default filter for value binding. |
|
| 45 | 42 |
|
| 46 |
-Filter. |
|
| 43 |
+=head2 C<filter> |
|
| 47 | 44 |
|
| 48 | 45 |
$query = $query->filter({%filter});
|
| 49 | 46 |
$filter = $query->filter; |
| 50 | 47 |
|
| 51 |
-=head2 C<sth> |
|
| 48 |
+Filters for value binding |
|
| 52 | 49 |
|
| 53 |
-Statement handle. |
|
| 50 |
+=head2 C<sth> |
|
| 54 | 51 |
|
| 55 | 52 |
$query = $query->sth($sth); |
| 56 | 53 |
$sth = $query->sth; |
| 57 | 54 |
|
| 55 |
+Statement handle. |
|
| 56 |
+ |
|
| 58 | 57 |
=head1 METHODS |
| 59 | 58 |
|
| 60 | 59 |
This class is L<Object::Simple> subclass. |
| ... | ... |
@@ -166,7 +166,7 @@ sub fetch_hash_all {
|
| 166 | 166 |
|
| 167 | 167 |
=head1 NAME |
| 168 | 168 |
|
| 169 |
-DBIx::Custom::Result - DBIx::Custom Resultset |
|
| 169 |
+DBIx::Custom::Result - Manipulate the result of select statement |
|
| 170 | 170 |
|
| 171 | 171 |
=head1 SYNOPSIS |
| 172 | 172 |
|
| ... | ... |
@@ -215,25 +215,25 @@ DBIx::Custom::Result - DBIx::Custom Resultset |
| 215 | 215 |
|
| 216 | 216 |
=head2 C<sth> |
| 217 | 217 |
|
| 218 |
-Statement handle. |
|
| 219 |
- |
|
| 220 | 218 |
$result = $result->sth($sth); |
| 221 | 219 |
$sth = $reuslt->sth |
| 222 |
- |
|
| 223 |
-=head2 C<default_filter> |
|
| 224 | 220 |
|
| 225 |
-Default filter. |
|
| 221 |
+Statement handle. |
|
| 222 |
+ |
|
| 223 |
+=head2 C<default_filter> |
|
| 226 | 224 |
|
| 227 | 225 |
$result = $result->default_filter('decode_utf8');
|
| 228 | 226 |
$default_filter = $result->default_filter; |
| 229 | 227 |
|
| 230 |
-=head2 C<filter> |
|
| 228 |
+Default filter for fetching. |
|
| 231 | 229 |
|
| 232 |
-Filter |
|
| 230 |
+=head2 C<filter> |
|
| 233 | 231 |
|
| 234 | 232 |
$result = $result->filter({title => 'decode_utf8'});
|
| 235 | 233 |
$filter = $result->filter; |
| 236 | 234 |
|
| 235 |
+Filters for fetching. |
|
| 236 |
+ |
|
| 237 | 237 |
=head1 METHODS |
| 238 | 238 |
|
| 239 | 239 |
This class is L<Object::Simple> subclass. |
| ... | ... |
@@ -241,11 +241,9 @@ You can use all methods of L<Object::Simple> |
| 241 | 241 |
|
| 242 | 242 |
=head2 C<fetch> |
| 243 | 243 |
|
| 244 |
-Fetch a row into array |
|
| 245 |
- |
|
| 246 | 244 |
$row = $result->fetch; |
| 247 | 245 |
|
| 248 |
-Example: |
|
| 246 |
+Fetch a row into array |
|
| 249 | 247 |
|
| 250 | 248 |
while (my $row = $result->fetch) {
|
| 251 | 249 |
# do something |
| ... | ... |
@@ -255,17 +253,15 @@ Example: |
| 255 | 253 |
|
| 256 | 254 |
=head2 C<fetch_first> |
| 257 | 255 |
|
| 258 |
-Fetch only first row into array and finish statment handle. |
|
| 259 |
- |
|
| 260 | 256 |
$row = $result->fetch_first; |
| 261 | 257 |
|
| 262 |
-=head2 C<fetch_multi> |
|
| 258 |
+Fetch only first row into array and finish statment handle. |
|
| 263 | 259 |
|
| 264 |
-Fetch multiple rows into array of array. |
|
| 260 |
+=head2 C<fetch_multi> |
|
| 265 | 261 |
|
| 266 | 262 |
$rows = $result->fetch_multi($count); |
| 267 | 263 |
|
| 268 |
-Example: |
|
| 264 |
+Fetch multiple rows into array of array. |
|
| 269 | 265 |
|
| 270 | 266 |
while(my $rows = $result->fetch_multi(10)) {
|
| 271 | 267 |
# do someting |
| ... | ... |
@@ -273,17 +269,15 @@ Example: |
| 273 | 269 |
|
| 274 | 270 |
=head2 C<fetch_all> |
| 275 | 271 |
|
| 276 |
-Fetch all rows into array of array. |
|
| 277 |
- |
|
| 278 | 272 |
$rows = $result->fetch_all; |
| 279 | 273 |
|
| 280 |
-=head2 C<fetch_hash> |
|
| 274 |
+Fetch all rows into array of array. |
|
| 281 | 275 |
|
| 282 |
-Fetch a row into hash |
|
| 276 |
+=head2 C<fetch_hash> |
|
| 283 | 277 |
|
| 284 | 278 |
$row = $result->fetch_hash; |
| 285 | 279 |
|
| 286 |
-Example: |
|
| 280 |
+Fetch a row into hash |
|
| 287 | 281 |
|
| 288 | 282 |
while (my $row = $result->fetch_hash) {
|
| 289 | 283 |
my $val1 = $row->{title};
|
| ... | ... |
@@ -294,17 +288,15 @@ Example: |
| 294 | 288 |
|
| 295 | 289 |
=head2 C<fetch_hash_first> |
| 296 | 290 |
|
| 297 |
-Fetch only first row into hash and finish statment handle. |
|
| 298 |
- |
|
| 299 | 291 |
$row = $result->fetch_hash_first; |
| 300 | 292 |
|
| 301 |
-=head2 C<fetch_hash_multi> |
|
| 293 |
+Fetch only first row into hash and finish statment handle. |
|
| 302 | 294 |
|
| 303 |
-Fetch multiple rows into array of hash |
|
| 295 |
+=head2 C<fetch_hash_multi> |
|
| 304 | 296 |
|
| 305 | 297 |
$rows = $result->fetch_hash_multi($count); |
| 306 | 298 |
|
| 307 |
-Example: |
|
| 299 |
+Fetch multiple rows into array of hash |
|
| 308 | 300 |
|
| 309 | 301 |
while(my $rows = $result->fetch_hash_multi(10)) {
|
| 310 | 302 |
# do someting |
| ... | ... |
@@ -312,8 +304,8 @@ Example: |
| 312 | 304 |
|
| 313 | 305 |
=head2 C<fetch_hash_all> |
| 314 | 306 |
|
| 315 |
-Fetch all rows into array of hash. |
|
| 316 |
- |
|
| 317 | 307 |
$rows = $result->fetch_hash_all; |
| 318 | 308 |
|
| 309 |
+Fetch all rows into array of hash. |
|
| 310 |
+ |
|
| 319 | 311 |
=cut |
| ... | ... |
@@ -209,7 +209,7 @@ sub _placeholder_count {
|
| 209 | 209 |
|
| 210 | 210 |
=head1 NAME |
| 211 | 211 |
|
| 212 |
-DBIx::Custom::SQLTemplate - DBIx::Custom SQL Template |
|
| 212 |
+DBIx::Custom::SQLTemplate - SQL template system |
|
| 213 | 213 |
|
| 214 | 214 |
=head1 SYNOPSIS |
| 215 | 215 |
|
| ... | ... |
@@ -121,11 +121,11 @@ DBIx::Custom::SQLTemplate::TagProcessor - Tag processor |
| 121 | 121 |
|
| 122 | 122 |
=head1 FUNCTIONS |
| 123 | 123 |
|
| 124 |
-=head2 expand_basic_tag |
|
| 124 |
+=head2 C<expand_basic_tag> |
|
| 125 | 125 |
|
| 126 |
-=head2 expand_in_tag |
|
| 126 |
+=head2 C<expand_in_tag> |
|
| 127 | 127 |
|
| 128 |
-=head2 expand_insert_tag |
|
| 128 |
+=head2 C<expand_insert_tag> |
|
| 129 | 129 |
|
| 130 |
-=head2 expand_update_tag |
|
| 130 |
+=head2 C<expand_update_tag> |
|
| 131 | 131 |
|
| ... | ... |
@@ -24,7 +24,7 @@ sub connect {
|
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 | 26 |
sub connect_memory {
|
| 27 |
- my $self = shift; |
|
| 27 |
+ my $self = shift->new(@_); |
|
| 28 | 28 |
|
| 29 | 29 |
# Data source for memory database |
| 30 | 30 |
$self->data_source('dbi:SQLite:dbname=:memory:');
|
| ... | ... |
@@ -41,21 +41,19 @@ sub last_insert_rowid { shift->dbh->func('last_insert_rowid') }
|
| 41 | 41 |
|
| 42 | 42 |
=head1 NAME |
| 43 | 43 |
|
| 44 |
-DBIx::Custom::SQLite - a SQLite implementation of DBIx::Custom |
|
| 44 |
+DBIx::Custom::SQLite - Implementation for SQLite |
|
| 45 | 45 |
|
| 46 | 46 |
=head1 SYNOPSYS |
| 47 | 47 |
|
| 48 | 48 |
use DBIx::Custom::SQLite; |
| 49 | 49 |
|
| 50 |
- # Connect |
|
| 51 |
- my $dbi = DBIx::Custom::SQLite->connect(user => 'taro', |
|
| 52 |
- password => 'kl&@K', |
|
| 53 |
- database => 'your_database'); |
|
| 50 |
+ # Connect to database |
|
| 51 |
+ my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
|
| 54 | 52 |
|
| 55 |
- # Connect memory database |
|
| 53 |
+ # Connect to memory database |
|
| 56 | 54 |
my $dbi = DBIx::Custom::SQLite->connect_memory; |
| 57 | 55 |
|
| 58 |
- # Last insert row ID |
|
| 56 |
+ # Get last insert row id |
|
| 59 | 57 |
my $id = $dbi->last_insert_rowid; |
| 60 | 58 |
|
| 61 | 59 |
=head1 ATTRIBUTES |
| ... | ... |
@@ -65,36 +63,39 @@ You can use all attributes of L<DBIx::Custom>. |
| 65 | 63 |
|
| 66 | 64 |
=head2 C<database> |
| 67 | 65 |
|
| 68 |
-Database name |
|
| 69 |
- |
|
| 70 | 66 |
$dbi = $dbi->database('your_database');
|
| 71 | 67 |
$database = $dbi->database; |
| 72 | 68 |
|
| 69 |
+Database name. |
|
| 70 |
+This is used for connect(). |
|
| 71 |
+ |
|
| 73 | 72 |
=head1 METHODS |
| 74 | 73 |
|
| 75 | 74 |
This class is L<DBIx::Custom> subclass. |
| 76 | 75 |
You can use all methods of L<DBIx::Custom>. |
| 77 | 76 |
|
| 78 | 77 |
=head2 C<connect (overridden)> |
| 78 |
+ |
|
| 79 |
+ $dbi = DBIx::Custom::SQLite->connect( |
|
| 80 |
+ data_source => "dbi:SQLite:dbname=your_db" |
|
| 81 |
+ ); |
|
| 82 |
+ |
|
| 83 |
+ $dbi = DBIx::Custom::SQLite->connect(database => 'your_db'); |
|
| 79 | 84 |
|
| 80 | 85 |
Connect to database. |
| 81 |
- |
|
| 82 |
- $dbi->connect; |
|
| 83 |
- |
|
| 84 |
-If you set database, host, or port, data source is automatically created. |
|
| 86 |
+You can also specify database name, instead of data source. |
|
| 85 | 87 |
|
| 86 | 88 |
=head2 C<connect_memory> |
| 87 | 89 |
|
| 88 |
-Connect memory database. |
|
| 89 |
- |
|
| 90 | 90 |
$dbi->connect_memory; |
| 91 | 91 |
|
| 92 |
-=head2 C<last_insert_rowid> |
|
| 92 |
+Connect to memory database. |
|
| 93 | 93 |
|
| 94 |
-Last insert row ID. |
|
| 94 |
+=head2 C<last_insert_rowid> |
|
| 95 | 95 |
|
| 96 | 96 |
$last_insert_rowid = $dbi->last_insert_rowid; |
| 97 |
- |
|
| 97 |
+ |
|
| 98 |
+Get last insert row id. |
|
| 98 | 99 |
This is equal to SQLite last_insert_rowid() function. |
| 99 | 100 |
|
| 100 | 101 |
=cut |
| ... | ... |
@@ -62,11 +62,6 @@ my $update_query; |
| 62 | 62 |
my $ret_val; |
| 63 | 63 |
|
| 64 | 64 |
|
| 65 |
-test 'disconnect'; |
|
| 66 |
-$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
|
| 67 |
-$dbi->disconnect; |
|
| 68 |
-ok(!$dbi->dbh, $test); |
|
| 69 |
- |
|
| 70 | 65 |
# Prepare table |
| 71 | 66 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 72 | 67 |
$dbi->execute($CREATE_TABLE->{0});
|
| ... | ... |
@@ -35,7 +35,7 @@ my $db_file; |
| 35 | 35 |
my $id; |
| 36 | 36 |
|
| 37 | 37 |
test 'connect_memory'; |
| 38 |
-$dbi = DBIx::Custom::SQLite->connect(database => ':memory:'); |
|
| 38 |
+$dbi = DBIx::Custom::SQLite->connect_memory; |
|
| 39 | 39 |
$ret_val = $dbi->execute($CREATE_TABLE->{0});
|
| 40 | 40 |
ok(defined $ret_val, $test); |
| 41 | 41 |
$dbi->insert(table => 'table1', param => {key1 => 'a', key2 => 2});
|
| ... | ... |
@@ -50,15 +50,14 @@ $dbi->connect; |
| 50 | 50 |
ok(-f $db_file, "$test : database file"); |
| 51 | 51 |
$ret_val = $dbi->execute($CREATE_TABLE->{0});
|
| 52 | 52 |
ok(defined $ret_val, "$test : database"); |
| 53 |
-$dbi->disconnect; |
|
| 53 |
+$dbi->dbh->disconnect; |
|
| 54 | 54 |
unlink $db_file if -f $db_file; |
| 55 | 55 |
|
| 56 | 56 |
test 'last_insert_rowid'; |
| 57 |
-$dbi = DBIx::Custom::SQLite->new; |
|
| 58 |
-$dbi->connect_memory; |
|
| 57 |
+$dbi = DBIx::Custom::SQLite->connect_memory; |
|
| 59 | 58 |
$ret_val = $dbi->execute($CREATE_TABLE->{0});
|
| 60 | 59 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 61 | 60 |
is($dbi->last_insert_rowid, 1, "$test: first"); |
| 62 | 61 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 63 | 62 |
is($dbi->last_insert_rowid, 2, "$test: second"); |
| 64 |
-$dbi->disconnect; |
|
| 63 |
+$dbi->dbh->disconnect; |