| ... | ... |
@@ -21,7 +21,8 @@ sub dbi_options : ClassObjectAttr { initialize => {clone => 'hash',
|
| 21 | 21 |
sub bind_filter : ClassObjectAttr { initialize => {clone => 'scalar'} }
|
| 22 | 22 |
sub fetch_filter : ClassObjectAttr { initialize => {clone => 'scalar'} }
|
| 23 | 23 |
|
| 24 |
-sub no_filters : ClassObjectAttr { initialize => {clone => 'array'} }
|
|
| 24 |
+sub no_bind_filters : ClassObjectAttr { initialize => {clone => 'array'} }
|
|
| 25 |
+sub no_fetch_filters : ClassObjectAttr { initialize => {clone => 'array'} }
|
|
| 25 | 26 |
|
| 26 | 27 |
sub filters : ClassObjectAttr {
|
| 27 | 28 |
type => 'hash', |
| ... | ... |
@@ -163,8 +164,21 @@ sub create_query {
|
| 163 | 164 |
# Prepare statement handle |
| 164 | 165 |
my $sth = $self->dbh->prepare($query->{sql});
|
| 165 | 166 |
|
| 167 |
+ # Set statement handle |
|
| 166 | 168 |
$query->sth($sth); |
| 167 | 169 |
|
| 170 |
+ # Set bind filter |
|
| 171 |
+ $query->bind_filter($self->bind_filter); |
|
| 172 |
+ |
|
| 173 |
+ # Set no filter keys when binding |
|
| 174 |
+ $query->no_bind_filters($self->no_bind_filters); |
|
| 175 |
+ |
|
| 176 |
+ # Set fetch filter |
|
| 177 |
+ $query->fetch_filter($self->fetch_filter); |
|
| 178 |
+ |
|
| 179 |
+ # Set no filter keys when fetching |
|
| 180 |
+ $query->no_fetch_filters($self->no_fetch_filters); |
|
| 181 |
+ |
|
| 168 | 182 |
return $query; |
| 169 | 183 |
} |
| 170 | 184 |
|
| ... | ... |
@@ -172,18 +186,6 @@ sub execute {
|
| 172 | 186 |
my ($self, $query, $params) = @_; |
| 173 | 187 |
$params ||= {};
|
| 174 | 188 |
|
| 175 |
- # Create query if First argument is template |
|
| 176 |
- if (!ref $query) {
|
|
| 177 |
- my $template = $query; |
|
| 178 |
- $query = $self->create_query($template); |
|
| 179 |
- } |
|
| 180 |
- |
|
| 181 |
- # Set bind filter |
|
| 182 |
- $query->bind_filter($self->bind_filter) unless $query->bind_filter; |
|
| 183 |
- |
|
| 184 |
- # Set no filter keys |
|
| 185 |
- $query->no_filters($self->no_filters) unless $query->no_filters; |
|
| 186 |
- |
|
| 187 | 189 |
# Create bind value |
| 188 | 190 |
my $bind_values = $self->_build_bind_values($query, $params); |
| 189 | 191 |
|
| ... | ... |
@@ -195,8 +197,9 @@ sub execute {
|
| 195 | 197 |
if ($sth->{NUM_OF_FIELDS}) {
|
| 196 | 198 |
my $result_class = $self->result_class; |
| 197 | 199 |
my $result = $result_class->new({
|
| 198 |
- sth => $sth, |
|
| 199 |
- fetch_filter => $self->fetch_filter |
|
| 200 |
+ sth => $sth, |
|
| 201 |
+ fetch_filter => $query->fetch_filter, |
|
| 202 |
+ no_fetch_filters => $query->no_fetch_filters |
|
| 200 | 203 |
}); |
| 201 | 204 |
return $result; |
| 202 | 205 |
} |
| ... | ... |
@@ -206,9 +209,9 @@ sub execute {
|
| 206 | 209 |
sub _build_bind_values {
|
| 207 | 210 |
my ($self, $query, $params) = @_; |
| 208 | 211 |
|
| 209 |
- my $key_infos = $query->key_infos; |
|
| 210 |
- my $bind_filter = $query->bind_filter; |
|
| 211 |
- my $no_filters_map = $query->_no_filters_map || {};
|
|
| 212 |
+ my $key_infos = $query->key_infos; |
|
| 213 |
+ my $bind_filter = $query->bind_filter; |
|
| 214 |
+ my $no_bind_filters_map = $query->_no_bind_filters_map || {};
|
|
| 212 | 215 |
|
| 213 | 216 |
# binding values |
| 214 | 217 |
my @bind_values; |
| ... | ... |
@@ -233,8 +236,10 @@ sub _build_bind_values {
|
| 233 | 236 |
|
| 234 | 237 |
if ($i == @$access_key - 1) {
|
| 235 | 238 |
if (ref $key eq 'ARRAY') {
|
| 236 |
- if ($bind_filter && !$no_filters_map->{$original_key}) {
|
|
| 237 |
- push @bind_values, $bind_filter->($root_params->[$key->[0]], $original_key, $table, $column); |
|
| 239 |
+ if ($bind_filter && !$no_bind_filters_map->{$original_key}) {
|
|
| 240 |
+ push @bind_values, |
|
| 241 |
+ $bind_filter->($root_params->[$key->[0]], |
|
| 242 |
+ $original_key, $table, $column); |
|
| 238 | 243 |
} |
| 239 | 244 |
else {
|
| 240 | 245 |
push @bind_values, scalar $root_params->[$key->[0]]; |
| ... | ... |
@@ -242,8 +247,10 @@ sub _build_bind_values {
|
| 242 | 247 |
} |
| 243 | 248 |
else {
|
| 244 | 249 |
next ACCESS_KEYS unless exists $root_params->{$key};
|
| 245 |
- if ($bind_filter && !$no_filters_map->{$original_key}) {
|
|
| 246 |
- push @bind_values, scalar $bind_filter->($root_params->{$key}, $original_key, $table, $column);
|
|
| 250 |
+ if ($bind_filter && !$no_bind_filters_map->{$original_key}) {
|
|
| 251 |
+ push @bind_values, |
|
| 252 |
+ $bind_filter->($root_params->{$key},
|
|
| 253 |
+ $original_key, $table, $column); |
|
| 247 | 254 |
} |
| 248 | 255 |
else {
|
| 249 | 256 |
push @bind_values, scalar $root_params->{$key};
|
| ... | ... |
@@ -373,11 +380,17 @@ you can get DBI database handle if you need. |
| 373 | 380 |
# Sample |
| 374 | 381 |
$dbi->fetch_filter($self->filters->{default_fetch_filter});
|
| 375 | 382 |
|
| 376 |
-=head2 no_filters |
|
| 383 |
+=head2 no_bind_filters |
|
| 384 |
+ |
|
| 385 |
+ # Set and get no filter keys when binding |
|
| 386 |
+ $self = $dbi->no_bind_filters($no_bind_filters); |
|
| 387 |
+ $no_bind_filters = $dbi->no_bind_filters; |
|
| 388 |
+ |
|
| 389 |
+=head2 no_fetch_filters |
|
| 377 | 390 |
|
| 378 |
- # Set and get no filter keys |
|
| 379 |
- $self = $dbi->no_filters($no_filters); |
|
| 380 |
- $no_filters = $dbi->no_filters; |
|
| 391 |
+ # Set and get no filter keys when fetching |
|
| 392 |
+ $self = $dbi->no_fetch_filters($no_fetch_filters); |
|
| 393 |
+ $no_fetch_filters = $dbi->no_fetch_filters; |
|
| 381 | 394 |
|
| 382 | 395 |
=head2 result_class |
| 383 | 396 |
|