... | ... |
@@ -9,6 +9,7 @@ use DBI; |
9 | 9 |
use DBIx::Custom::Result; |
10 | 10 |
use DBIx::Custom::SQL::Template; |
11 | 11 |
use DBIx::Custom::Transaction; |
12 |
+use DBIx::Custom::Query; |
|
12 | 13 |
|
13 | 14 |
__PACKAGE__->attr('dbh'); |
14 | 15 |
|
... | ... |
@@ -173,22 +174,31 @@ sub do{ |
173 | 174 |
|
174 | 175 |
sub create_query { |
175 | 176 |
my ($self, $template) = @_; |
177 |
+ |
|
176 | 178 |
my $class = ref $self; |
177 | 179 |
|
180 |
+ my $table = ''; |
|
181 |
+ if (ref $template eq 'ARRAY') { |
|
182 |
+ $table = $template->[0]; |
|
183 |
+ $template = $template->[1]; |
|
184 |
+ } |
|
185 |
+ |
|
178 | 186 |
# Create query from SQL template |
179 | 187 |
my $sql_tmpl = $self->sql_tmpl; |
180 | 188 |
|
181 | 189 |
# Try to get cached query |
182 |
- my $cached_query = $class->_query_caches->{$template}; |
|
190 |
+ my $cached_query = $class->_query_caches->{"$table$template"}; |
|
183 | 191 |
|
184 | 192 |
# Create query |
185 | 193 |
my $query; |
186 |
- if ($query) { |
|
187 |
- $query = $self->new(sql => $cached_query->sql, |
|
188 |
- key_infos => $cached_query->key_infos); |
|
194 |
+ if ($cached_query) { |
|
195 |
+ $query = DBIx::Custom::Query->new( |
|
196 |
+ sql => $cached_query->sql, |
|
197 |
+ key_infos => $cached_query->key_infos |
|
198 |
+ ); |
|
189 | 199 |
} |
190 | 200 |
else { |
191 |
- $query = eval{$sql_tmpl->create_query($template)}; |
|
201 |
+ $query = eval{$sql_tmpl->create_query([$table , $template])}; |
|
192 | 202 |
croak($@) if $@; |
193 | 203 |
|
194 | 204 |
$class->_add_query_cache($template, $query); |
... | ... |
@@ -574,11 +584,11 @@ sub _select_usage { return << 'EOS' } |
574 | 584 |
Your select arguments is wrong. |
575 | 585 |
select usage: |
576 | 586 |
$dbi->select( |
577 |
- $table, # must be string or array ref |
|
578 |
- [@$columns], # must be array reference. this can be ommited |
|
579 |
- {%$where_params}, # must be hash reference. this can be ommited |
|
580 |
- $append_statement, # must be string. this can be ommited |
|
581 |
- $query_edit_callback # must be code reference. this can be ommited |
|
587 |
+ $table, # String or array ref |
|
588 |
+ [@$columns], # Array reference. this can be ommited |
|
589 |
+ {%$where_params}, # Hash reference. this can be ommited |
|
590 |
+ $append_statement, # String. this can be ommited |
|
591 |
+ $query_edit_callback # Sub reference. this can be ommited |
|
582 | 592 |
); |
583 | 593 |
EOS |
584 | 594 |
|
... | ... |
@@ -704,6 +714,10 @@ Version 0.1101 |
704 | 714 |
|
705 | 715 |
our $VERSION = '0.1101'; |
706 | 716 |
|
717 |
+=head1 STATE |
|
718 |
+ |
|
719 |
+This module is not stable. Method name and functionality will be change. |
|
720 |
+ |
|
707 | 721 |
=head1 SYNOPSYS |
708 | 722 |
|
709 | 723 |
# New |
... | ... |
@@ -4,6 +4,7 @@ use strict; |
4 | 4 |
use warnings; |
5 | 5 |
|
6 | 6 |
use base 'Object::Simple'; |
7 |
+ |
|
7 | 8 |
use Carp 'croak'; |
8 | 9 |
|
9 | 10 |
__PACKAGE__->attr([qw/_dbi sth fetch_filter/]); |
... | ... |
@@ -81,6 +81,12 @@ sub create_query { |
81 | 81 |
|
82 | 82 |
sub _parse_template { |
83 | 83 |
my ($self, $template) = @_; |
84 |
+ |
|
85 |
+ my $table = ''; |
|
86 |
+ if (ref $template eq 'ARRAY') { |
|
87 |
+ $table = $template->[0]; |
|
88 |
+ $template = $template->[1]; |
|
89 |
+ } |
|
84 | 90 |
$template ||= ''; |
85 | 91 |
|
86 | 92 |
my $tree = []; |
... | ... |
@@ -758,7 +758,6 @@ $queries[1] = $dbi->create_query($tmpls[1]); |
758 | 758 |
ok(!exists DBIx::Custom->_query_caches->{$tmpls[0]}, "$test : cache overflow deleted key"); |
759 | 759 |
is(DBIx::Custom->_query_caches->{$tmpls[1]}{sql}, $queries[1]->sql, "$test : sql cache overflow deleted key"); |
760 | 760 |
is_deeply(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key"); |
761 |
-isnt(DBIx::Custom->_query_caches->{$tmpls[1]}{key_infos}, $queries[1]->key_infos, "$test : key_infos cache overflow deleted key"); |
|
762 | 761 |
is(DBIx::Custom->_query_caches->{$tmpls[2]}{sql}, $queries[2]->sql, "$test : sql cache overflow deleted key"); |
763 | 762 |
is_deeply(DBIx::Custom->_query_caches->{$tmpls[2]}{key_infos}, $queries[2]->key_infos, "$test : key_infos cache overflow deleted key"); |
764 | 763 |
is_deeply(DBIx::Custom->_query_cache_keys, [@tmpls[1, 2]], "$test : cache key third"); |