Showing 4 changed files with 42 additions and 1 deletions
+2
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.1701
2
+    - added EXPERIMENTAL last_sql attribute method
1 3
 0.1700
2 4
     - fixed end_filter DEPRECATED warnings bug
3 5
 0.1699
+16 -1
lib/DBIx/Custom.pm
... ...
@@ -1,7 +1,7 @@
1 1
 package DBIx::Custom;
2 2
 use Object::Simple -base;
3 3
 
4
-our $VERSION = '0.1700';
4
+our $VERSION = '0.1701';
5 5
 use 5.008001;
6 6
 
7 7
 use Carp 'croak';
... ...
@@ -52,6 +52,7 @@ has [qw/connector dsn password quote user/],
52 52
             decode_utf8 => sub { decode_utf8($_[0]) }
53 53
         }
54 54
     },
55
+    last_sql => '',
55 56
     models => sub { {} },
56 57
     query_builder => sub { DBIx::Custom::QueryBuilder->new },
57 58
     result_class  => 'DBIx::Custom::Result',
... ...
@@ -317,6 +318,10 @@ sub execute {
317 318
     
318 319
     # Create query
319 320
     $query = $self->_create_query($query) unless ref $query;
321
+    
322
+    # Save query
323
+    $self->last_sql($query->sql);
324
+
320 325
     return $query if $query_return;
321 326
     $filter ||= $query->filter;
322 327
     
... ...
@@ -1158,6 +1163,9 @@ sub _create_query {
1158 1163
         ) if $cache;
1159 1164
     }
1160 1165
     
1166
+    # Save sql
1167
+    $self->last_sql($query->sql);
1168
+    
1161 1169
     # Prepare statement handle
1162 1170
     my $sth;
1163 1171
     eval { $sth = $self->dbh->prepare($query->{sql})};
... ...
@@ -1889,6 +1897,13 @@ default to the following values.
1889 1897
 
1890 1898
 Filters, registered by C<register_filter> method.
1891 1899
 
1900
+=head2 C<last_sql> EXPERIMENTAL
1901
+
1902
+    my $last_sql = $dbi->last_sql;
1903
+    $dbi = $dbi->last_sql($last_sql);
1904
+
1905
+Get last successed SQL executed by C<execute> method.
1906
+
1892 1907
 =head2 C<models>
1893 1908
 
1894 1909
     my $models = $dbi->models;
+13
lib/DBIx/Custom/Guide/Ja.pod
... ...
@@ -0,0 +1,13 @@
1
+=encoding utf8
2
+
3
+=head1 NAME
4
+
5
+DBIx::Custom::Guide - DBIx::Customガイド
6
+
7
+=head1 LINK
8
+
9
+ドキュメントは以下のリンクに移動しました。
10
+
11
+L<http://d.hatena.ne.jp/perlcodesample/20110401/1305597081>
12
+
13
+=cut
+11
t/dbix-custom-core-sqlite.t
... ...
@@ -3316,4 +3316,15 @@ $dbi->tag_parse(0);
3316 3316
     ok($@);
3317 3317
 }
3318 3318
 
3319
+test 'last_sql';
3320
+{
3321
+    my $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
3322
+    $dbi->execute("create table table1 (key1, key2)");
3323
+    $dbi->execute('select * from table1');
3324
+    is($dbi->last_sql, 'select * from table1;');
3325
+    
3326
+    eval{$dbi->execute("aaa")};
3327
+    is($dbi->last_sql, 'aaa;');
3328
+    
3329
+}
3319 3330
 =cut