rename DBIx::Custom::SQLite last_insert_id to last_inse...
...rt_rowid
| ... | ... | 
                  @@ -1,10 +1,12 @@  | 
              
| 1 | 1 | 
                  package DBIx::Custom::SQLite;  | 
              
| 2 | 
                  -use base 'DBIx::Custom::Basic';  | 
              |
| 3 | 2 | 
                   | 
              
| 4 | 3 | 
                  use strict;  | 
              
| 5 | 4 | 
                  use warnings;  | 
              
| 5 | 
                  +  | 
              |
| 6 | 
                  +use base 'DBIx::Custom::Basic';  | 
              |
| 6 | 7 | 
                  use Carp 'croak';  | 
              
| 7 | 8 | 
                   | 
              
| 9 | 
                  +# Add format  | 
              |
| 8 | 10 | 
                  __PACKAGE__->add_format(  | 
              
| 9 | 11 | 
                       datetime => __PACKAGE__->formats->{SQL99_datetime},
                 | 
              
| 10 | 12 | 
                       date     => __PACKAGE__->formats->{SQL99_date},
                 | 
              
| ... | ... | 
                  @@ -14,6 +16,7 @@ __PACKAGE__->add_format(  | 
              
| 14 | 16 | 
                   sub connect {
                 | 
              
| 15 | 17 | 
                  my $self = shift;  | 
              
| 16 | 18 | 
                   | 
              
| 19 | 
                  + # Create data source  | 
              |
| 17 | 20 | 
                       if (!$self->data_source && (my $database = $self->database)) {
                 | 
              
| 18 | 21 | 
                           $self->data_source("dbi:SQLite:dbname=$database");
                 | 
              
| 19 | 22 | 
                  }  | 
              
| ... | ... | 
                  @@ -48,40 +51,38 @@ sub reconnect_memory {
                 | 
              
| 48 | 51 | 
                  return $self;  | 
              
| 49 | 52 | 
                  }  | 
              
| 50 | 53 | 
                   | 
              
| 51 | 
                  -sub last_insert_id {
                 | 
              |
| 54 | 
                  +sub last_insert_rowid {
                 | 
              |
| 52 | 55 | 
                  my $self = shift;  | 
              
| 53 | 56 | 
                   | 
              
| 57 | 
                  + # Not connected  | 
              |
| 54 | 58 | 
                  croak "Not yet connected" unless $self->connected;  | 
              
| 55 | 59 | 
                   | 
              
| 56 | 
                  -    my $last_insert_id = $self->dbh->func('last_insert_rowid');
                 | 
              |
| 60 | 
                  + # Get last insert row id  | 
              |
| 61 | 
                  +    my $last_insert_rowid = $self->dbh->func('last_insert_rowid');
                 | 
              |
| 57 | 62 | 
                   | 
              
| 58 | 
                  - return $last_insert_id;  | 
              |
| 63 | 
                  + return $last_insert_rowid;  | 
              |
| 59 | 64 | 
                  }  | 
              
| 60 | 65 | 
                   | 
              
| 61 | 66 | 
                  =head1 NAME  | 
              
| 62 | 67 | 
                   | 
              
| 63 | 68 | 
                  DBIx::Custom::SQLite - DBIx::Custom SQLite implementation  | 
              
| 64 | 69 | 
                   | 
              
| 65 | 
                  -=head1 Synopsys  | 
              |
| 70 | 
                  +=head1 SYNOPSYS  | 
              |
| 66 | 71 | 
                   | 
              
| 67 | 72 | 
                  use DBIx::Custom::SQLite;  | 
              
| 68 | 73 | 
                   | 
              
| 69 | 74 | 
                  # New  | 
              
| 70 | 
                  - my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@K',  | 
              |
| 75 | 
                  + my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kl&@K',  | 
              |
| 71 | 76 | 
                  database => 'sample');  | 
              
| 72 | 77 | 
                   | 
              
| 73 | 78 | 
                  # Connect memory database  | 
              
| 74 | 79 | 
                  my $dbi->connect_memory;  | 
              
| 75 | 80 | 
                   | 
              
| 76 | 
                  -=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first  | 
              |
| 77 | 81 | 
                   | 
              
| 78 | 
                  -This class is L<DBIx::Custom::Basic> subclass.  | 
              |
| 79 | 
                  -and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass  | 
              |
| 82 | 
                  +=head1 METHODS  | 
              |
| 80 | 83 | 
                   | 
              
| 81 | 
                  -You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom>  | 
              |
| 82 | 
                  -Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation  | 
              |
| 83 | 
                  -  | 
              |
| 84 | 
                  -=head1 Methods  | 
              |
| 84 | 
                  +This class is L<DBIx::Custom::Basic> subclass.  | 
              |
| 85 | 
                  +You can use all methods of L<DBIx::Custom::Basic>  | 
              |
| 85 | 86 | 
                   | 
              
| 86 | 87 | 
                  =head2 connect  | 
              
| 87 | 88 | 
                   | 
              
| ... | ... | 
                  @@ -103,33 +104,19 @@ Reconnect to memory databsse  | 
              
| 103 | 104 | 
                   | 
              
| 104 | 105 | 
                  $dbi->reconnect_memory;  | 
              
| 105 | 106 | 
                   | 
              
| 106 | 
                  -=head2 last_insert_id  | 
              |
| 107 | 
                  +=head2 last_insert_rowid  | 
              |
| 107 | 108 | 
                   | 
              
| 108 | 109 | 
                  Get last insert id  | 
              
| 109 | 110 | 
                   | 
              
| 110 | 
                  - $last_insert_id = $dbi->last_insert_id;  | 
              |
| 111 | 
                  + $last_insert_rowid = $dbi->last_insert_rowid;  | 
              |
| 111 | 112 | 
                   | 
              
| 112 | 
                  -The folloing is last_insert_id sample.  | 
              |
| 113 | 
                  +The folloing is last_insert_rowid sample.  | 
              |
| 113 | 114 | 
                   | 
              
| 114 | 115 | 
                       $dbi->insert('books', {title => 'Perl', author => 'taro'});
                 | 
              
| 115 | 
                  - $last_insert_id = $dbi->last_insert_id;  | 
              |
| 116 | 
                  + $last_insert_rowid = $dbi->last_insert_rowid;  | 
              |
| 116 | 117 | 
                   | 
              
| 117 | 118 | 
                  This is equal to SQLite function  | 
              
| 118 | 119 | 
                   | 
              
| 119 | 120 | 
                  last_insert_rowid()  | 
              
| 120 | 121 | 
                   | 
              
| 121 | 
                  -=head1 Author  | 
              |
| 122 | 
                  -  | 
              |
| 123 | 
                  -Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>  | 
              |
| 124 | 
                  -  | 
              |
| 125 | 
                  -Github L<http://github.com/yuki-kimoto>  | 
              |
| 126 | 
                  -  | 
              |
| 127 | 
                  -I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>  | 
              |
| 128 | 
                  -  | 
              |
| 129 | 
                  -=head1 Copyright & lisence  | 
              |
| 130 | 
                  -  | 
              |
| 131 | 
                  -Copyright 2009 Yuki Kimoto, all rights reserved.  | 
              |
| 132 | 
                  -  | 
              |
| 133 | 
                  -This program is free software; you can redistribute it and/or modify it  | 
              |
| 134 | 
                  -under the same terms as Perl itself.  | 
              |
| 135 | 
                  -  | 
              |
| 122 | 
                  +=cut  | 
              
| ... | ... | 
                  @@ -68,39 +68,29 @@ sub run {
                 | 
              
| 68 | 68 | 
                   | 
              
| 69 | 69 | 
                  =head1 NAME  | 
              
| 70 | 70 | 
                   | 
              
| 71 | 
                  -DBIx::Custom::TransactionScope - Transaction scope  | 
              |
| 71 | 
                  +DBIx::Custom::Transaction - Transaction  | 
              |
| 72 | 72 | 
                   | 
              
| 73 | 73 | 
                  =head1 SYNOPSYS  | 
              
| 74 | 
                  -  | 
              |
| 75 | 
                  - use DBIx::Custom::SQLite;  | 
              |
| 76 | 74 | 
                   | 
              
| 77 | 
                  - # New  | 
              |
| 78 | 
                  - my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@K',  | 
              |
| 79 | 
                  - database => 'sample');  | 
              |
| 75 | 
                  + use DBIx::Custom::Transaction  | 
              |
| 76 | 
                  + my $txn = DBIx::Custom::Transaction->new(dbi => DBIx::Custom->new);  | 
              |
| 77 | 
                  +    $txn->run(sub { ... });
                 | 
              |
| 80 | 78 | 
                   | 
              
| 81 | 
                  - # Connect memory database  | 
              |
| 82 | 
                  - my $dbi->connect_memory;  | 
              |
| 83 | 
                  -  | 
              |
| 84 | 79 | 
                  =head1 ATTRIBUTES  | 
              
| 85 | 80 | 
                   | 
              
| 86 | 81 | 
                  =head2 dbi  | 
              
| 87 | 82 | 
                   | 
              
| 83 | 
                  + $self = $txn->dbi($dbi);  | 
              |
| 84 | 
                  + $dbi = $txn->dbi;  | 
              |
| 85 | 
                  +  | 
              |
| 88 | 86 | 
                  =head1 METHODS  | 
              
| 89 | 87 | 
                   | 
              
| 90 | 88 | 
                  =head2 run  | 
              
| 89 | 
                  +  | 
              |
| 90 | 
                  + $txn->run(  | 
              |
| 91 | 
                  +        sub {
                 | 
              |
| 92 | 
                  + # Transaction  | 
              |
| 93 | 
                  + }  | 
              |
| 94 | 
                  + );  | 
              |
| 91 | 95 | 
                   | 
              
| 92 | 
                  -=head1 AUTHOR  | 
              |
| 93 | 
                  -  | 
              |
| 94 | 
                  -Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>  | 
              |
| 95 | 
                  -  | 
              |
| 96 | 
                  -Github L<http://github.com/yuki-kimoto>  | 
              |
| 97 | 
                  -  | 
              |
| 98 | 
                  -I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>  | 
              |
| 99 | 
                  -  | 
              |
| 100 | 
                  -=head1 Copyright & lisence  | 
              |
| 101 | 
                  -  | 
              |
| 102 | 
                  -Copyright 2009 Yuki Kimoto, all rights reserved.  | 
              |
| 103 | 
                  -  | 
              |
| 104 | 
                  -This program is free software; you can redistribute it and/or modify it  | 
              |
| 105 | 
                  -under the same terms as Perl itself.  | 
              |
| 106 | 
                  -  | 
              |
| 96 | 
                  +=cut  | 
              
| ... | ... | 
                  @@ -32,6 +32,7 @@ my $dbi;  | 
              
| 32 | 32 | 
                  my $ret_val;  | 
              
| 33 | 33 | 
                  my $rows;  | 
              
| 34 | 34 | 
                  my $db_file;  | 
              
| 35 | 
                  +my $id;  | 
              |
| 35 | 36 | 
                   | 
              
| 36 | 37 | 
                  test 'connect_memory';  | 
              
| 37 | 38 | 
                  $dbi = DBIx::Custom::SQLite->new;  | 
              
| ... | ... | 
                  @@ -67,3 +68,12 @@ ok(defined $ret_val, "$test : database");  | 
              
| 67 | 68 | 
                  $dbi->disconnect;  | 
              
| 68 | 69 | 
                  unlink $db_file if -f $db_file;  | 
              
| 69 | 70 | 
                   | 
              
| 71 | 
                  +test 'last_insert_rowid';  | 
              |
| 72 | 
                  +$dbi = DBIx::Custom::SQLite->new;  | 
              |
| 73 | 
                  +$dbi->connect_memory;  | 
              |
| 74 | 
                  +$ret_val = $dbi->do($CREATE_TABLE->{0});
                 | 
              |
| 75 | 
                  +$dbi->insert('table1', {key1 => 1, key2 => 2});
                 | 
              |
| 76 | 
                  +is($dbi->last_insert_rowid, 1, "$test: first");  | 
              |
| 77 | 
                  +$dbi->insert('table1', {key1 => 1, key2 => 2});
                 | 
              |
| 78 | 
                  +is($dbi->last_insert_rowid, 2, "$test: second");  | 
              |
| 79 | 
                  +$dbi->disconnect;  |