| ... | ... |
@@ -1,3 +1,5 @@ |
| 1 |
+0.1201 |
|
| 2 |
+ Changed many(not backword compatible) |
|
| 1 | 3 |
0.1101 |
| 2 | 4 |
rename DBIx::Custom::SQLite last_insert_id to last_insert_rowid |
| 3 | 5 |
0.1001 |
| ... | ... |
@@ -4,12 +4,13 @@ use strict; |
| 4 | 4 |
use warnings; |
| 5 | 5 |
|
| 6 | 6 |
use base 'Object::Simple'; |
| 7 |
+ |
|
| 7 | 8 |
use Carp 'croak'; |
| 8 | 9 |
use DBI; |
| 9 | 10 |
use DBIx::Custom::Result; |
| 10 | 11 |
use DBIx::Custom::SQL::Template; |
| 11 |
-use DBIx::Custom::Transaction; |
|
| 12 | 12 |
use DBIx::Custom::Query; |
| 13 |
+use DBIx::Custom::KeyInfo; |
|
| 13 | 14 |
|
| 14 | 15 |
__PACKAGE__->attr('dbh');
|
| 15 | 16 |
|
| ... | ... |
@@ -23,9 +24,6 @@ __PACKAGE__->dual_attr([qw/user password data_source/], inherit => 'scalar_copy' |
| 23 | 24 |
__PACKAGE__->dual_attr([qw/database host port/], inherit => 'scalar_copy'); |
| 24 | 25 |
__PACKAGE__->dual_attr([qw/bind_filter fetch_filter/], inherit => 'scalar_copy'); |
| 25 | 26 |
|
| 26 |
-__PACKAGE__->dual_attr([qw/no_bind_filters no_fetch_filters/], |
|
| 27 |
- default => sub { [] }, inherit => 'array_copy');
|
|
| 28 |
- |
|
| 29 | 27 |
__PACKAGE__->dual_attr([qw/options filters formats/], |
| 30 | 28 |
default => sub { {} }, inherit => 'hash_copy');
|
| 31 | 29 |
|
| ... | ... |
@@ -217,15 +215,9 @@ sub create_query {
|
| 217 | 215 |
# Set bind filter |
| 218 | 216 |
$query->bind_filter($self->bind_filter); |
| 219 | 217 |
|
| 220 |
- # Set no filter keys when binding |
|
| 221 |
- $query->no_bind_filters($self->no_bind_filters); |
|
| 222 |
- |
|
| 223 | 218 |
# Set fetch filter |
| 224 | 219 |
$query->fetch_filter($self->fetch_filter); |
| 225 | 220 |
|
| 226 |
- # Set no filter keys when fetching |
|
| 227 |
- $query->no_fetch_filters($self->no_fetch_filters); |
|
| 228 |
- |
|
| 229 | 221 |
return $query; |
| 230 | 222 |
} |
| 231 | 223 |
|
| ... | ... |
@@ -278,7 +270,6 @@ sub query{
|
| 278 | 270 |
_dbi => $self, |
| 279 | 271 |
sth => $sth, |
| 280 | 272 |
fetch_filter => $query->fetch_filter, |
| 281 |
- no_fetch_filters => $query->no_fetch_filters |
|
| 282 | 273 |
}); |
| 283 | 274 |
return $result; |
| 284 | 275 |
} |
| ... | ... |
@@ -301,9 +292,9 @@ sub _build_bind_values {
|
| 301 | 292 |
my $pos = $key_info->pos; |
| 302 | 293 |
|
| 303 | 294 |
# Value |
| 304 |
- my $value = $id && $pos ? $params->{$id}->{$column}->[$pos]
|
|
| 305 |
- : $id ? $params->{$id}->{$column}
|
|
| 306 |
- : $pos ? $params->{$column}->[$pos]
|
|
| 295 |
+ my $value = $id && defined $pos ? $params->{$id}->{$column}->[$pos]
|
|
| 296 |
+ : $id ? $params->{$id}->{$column}
|
|
| 297 |
+ : defined $pos ? $params->{$column}->[$pos]
|
|
| 307 | 298 |
: $params->{$column};
|
| 308 | 299 |
|
| 309 | 300 |
# Filter |
| ... | ... |
@@ -320,18 +311,15 @@ sub transaction { DBIx::Custom::Transaction->new(dbi => shift) }
|
| 320 | 311 |
sub run_transaction {
|
| 321 | 312 |
my ($self, $transaction) = @_; |
| 322 | 313 |
|
| 323 |
- # DBIx::Custom object |
|
| 324 |
- my $dbi = $self->dbi; |
|
| 325 |
- |
|
| 326 | 314 |
# Shorcut |
| 327 |
- return unless $dbi; |
|
| 315 |
+ return unless $self; |
|
| 328 | 316 |
|
| 329 | 317 |
# Check auto commit |
| 330 | 318 |
croak("AutoCommit must be true before transaction start")
|
| 331 |
- unless $dbi->_auto_commit; |
|
| 319 |
+ unless $self->_auto_commit; |
|
| 332 | 320 |
|
| 333 | 321 |
# Auto commit off |
| 334 |
- $dbi->_auto_commit(0); |
|
| 322 |
+ $self->_auto_commit(0); |
|
| 335 | 323 |
|
| 336 | 324 |
# Run transaction |
| 337 | 325 |
eval {$transaction->()};
|
| ... | ... |
@@ -342,13 +330,13 @@ sub run_transaction {
|
| 342 | 330 |
# Tranzaction is failed. |
| 343 | 331 |
if ($transaction_error) {
|
| 344 | 332 |
# Rollback |
| 345 |
- eval{$dbi->dbh->rollback};
|
|
| 333 |
+ eval{$self->dbh->rollback};
|
|
| 346 | 334 |
|
| 347 | 335 |
# Rollback error |
| 348 | 336 |
my $rollback_error = $@; |
| 349 | 337 |
|
| 350 | 338 |
# Auto commit on |
| 351 |
- $dbi->_auto_commit(1); |
|
| 339 |
+ $self->_auto_commit(1); |
|
| 352 | 340 |
|
| 353 | 341 |
if ($rollback_error) {
|
| 354 | 342 |
# Rollback is failed |
| ... | ... |
@@ -362,11 +350,11 @@ sub run_transaction {
|
| 362 | 350 |
# Tranzaction is success |
| 363 | 351 |
else {
|
| 364 | 352 |
# Commit |
| 365 |
- eval{$dbi->dbh->commit};
|
|
| 353 |
+ eval{$self->dbh->commit};
|
|
| 366 | 354 |
my $commit_error = $@; |
| 367 | 355 |
|
| 368 | 356 |
# Auto commit on |
| 369 |
- $dbi->_auto_commit(1); |
|
| 357 |
+ $self->_auto_commit(1); |
|
| 370 | 358 |
|
| 371 | 359 |
# Commit is failed |
| 372 | 360 |
croak($commit_error) if $commit_error; |
| ... | ... |
@@ -466,7 +454,13 @@ sub update {
|
| 466 | 454 |
if (@where_keys) {
|
| 467 | 455 |
$where_clause = 'where '; |
| 468 | 456 |
foreach my $where_key (@where_keys) {
|
| 469 |
- $where_clause .= "{= $where_key} and ";
|
|
| 457 |
+ my $key_info = DBIx::Custom::KeyInfo->new($where_key); |
|
| 458 |
+ |
|
| 459 |
+ my $table_new = $key_info->table || $table; |
|
| 460 |
+ my $column = $table_new . '.' . $key_info->column |
|
| 461 |
+ . '#@where'; |
|
| 462 |
+ |
|
| 463 |
+ $where_clause .= "{= $column} and ";
|
|
| 470 | 464 |
} |
| 471 | 465 |
$where_clause =~ s/ and $//; |
| 472 | 466 |
} |
| ... | ... |
@@ -486,7 +480,7 @@ sub update {
|
| 486 | 480 |
$query_edit_cb->($query) if $query_edit_cb; |
| 487 | 481 |
|
| 488 | 482 |
# Rearrange parammeters |
| 489 |
- my $params = {%$update_params, %$where_params};
|
|
| 483 |
+ my $params = {%$update_params, '@where' => $where_params};
|
|
| 490 | 484 |
|
| 491 | 485 |
# Execute query |
| 492 | 486 |
my $ret_val = $self->query($query, $params); |
| ... | ... |
@@ -618,11 +612,23 @@ sub select {
|
| 618 | 612 |
# Where clause keys |
| 619 | 613 |
my @where_keys = keys %$where_params; |
| 620 | 614 |
|
| 615 |
+ my $where_params_new = {};
|
|
| 616 |
+ |
|
| 621 | 617 |
# Join where clause |
| 622 | 618 |
if (@where_keys) {
|
| 623 | 619 |
$template .= 'where '; |
| 624 | 620 |
foreach my $where_key (@where_keys) {
|
| 625 |
- $template .= "{= $where_key} and ";
|
|
| 621 |
+ my $key_info = DBIx::Custom::KeyInfo->new($where_key); |
|
| 622 |
+ |
|
| 623 |
+ my $table_new = $key_info->table || $tables->[0]; |
|
| 624 |
+ my $column = $table_new . '.' . $key_info->column |
|
| 625 |
+ . '#' . $table_new; |
|
| 626 |
+ |
|
| 627 |
+ $template .= "{= $column} and ";
|
|
| 628 |
+ |
|
| 629 |
+ $where_params_new->{$table_new} ||= {};
|
|
| 630 |
+ $where_params_new->{$table_new}->{$key_info->column}
|
|
| 631 |
+ = $where_params->{$where_key};
|
|
| 626 | 632 |
} |
| 627 | 633 |
} |
| 628 | 634 |
$template =~ s/ and $//; |
| ... | ... |
@@ -647,7 +653,7 @@ sub select {
|
| 647 | 653 |
$query_edit_cb->($query) if $query_edit_cb; |
| 648 | 654 |
|
| 649 | 655 |
# Execute query |
| 650 |
- my $result = $self->query($query, $where_params); |
|
| 656 |
+ my $result = $self->query($query, $where_params_new); |
|
| 651 | 657 |
|
| 652 | 658 |
return $result; |
| 653 | 659 |
} |
| ... | ... |
@@ -692,11 +698,11 @@ DBIx::Custom - Customizable DBI |
| 692 | 698 |
|
| 693 | 699 |
=head1 VERSION |
| 694 | 700 |
|
| 695 |
-Version 0.1101 |
|
| 701 |
+Version 0.1201 |
|
| 696 | 702 |
|
| 697 | 703 |
=cut |
| 698 | 704 |
|
| 699 |
-our $VERSION = '0.1101'; |
|
| 705 |
+our $VERSION = '0.1201'; |
|
| 700 | 706 |
|
| 701 | 707 |
=head1 STATE |
| 702 | 708 |
|
| ... | ... |
@@ -869,20 +875,6 @@ Bind filter arguemts is |
| 869 | 875 |
3. $dbi : DBIx::Custom object |
| 870 | 876 |
4. $infos : {type => $table, sth => $sth, index => $index}
|
| 871 | 877 |
|
| 872 |
-=head2 no_bind_filters |
|
| 873 |
- |
|
| 874 |
-Key list which dose not have to bind filtering |
|
| 875 |
- |
|
| 876 |
- $dbi = $dbi->no_bind_filters(qw/title author/); |
|
| 877 |
- $no_bind_filters = $dbi->no_bind_filters; |
|
| 878 |
- |
|
| 879 |
-=head2 no_fetch_filters |
|
| 880 |
- |
|
| 881 |
-Key list which dose not have to fetch filtering |
|
| 882 |
- |
|
| 883 |
- $dbi = $dbi->no_fetch_filters(qw/title author/); |
|
| 884 |
- $no_fetch_filters = $dbi->no_fetch_filters; |
|
| 885 |
- |
|
| 886 | 878 |
=head2 result_class |
| 887 | 879 |
|
| 888 | 880 |
Resultset class |
| ... | ... |
@@ -23,7 +23,7 @@ sub parse {
|
| 23 | 23 |
my ($self, $key) = @_; |
| 24 | 24 |
|
| 25 | 25 |
# Parse |
| 26 |
- ($key || '') =~ /^(?:(.+?)\.)?(.+?)(?:@(.+))?$/; |
|
| 26 |
+ ($key || '') =~ /^(?:(.+?)\.)?(.+?)(?:#(.+))?$/; |
|
| 27 | 27 |
$self->table($1 || ''); |
| 28 | 28 |
$self->column($2 || ''); |
| 29 | 29 |
$self->id($3 || ''); |
| ... | ... |
@@ -6,35 +6,6 @@ use warnings; |
| 6 | 6 |
use base 'Object::Simple'; |
| 7 | 7 |
|
| 8 | 8 |
__PACKAGE__->attr([qw/sql key_infos bind_filter fetch_filter sth/]); |
| 9 |
-__PACKAGE__->attr(_no_bind_filters => sub { {} });
|
|
| 10 |
-__PACKAGE__->attr(no_fetch_filters => sub { [] });
|
|
| 11 |
- |
|
| 12 |
-sub new {
|
|
| 13 |
- my $self = shift->SUPER::new(@_); |
|
| 14 |
- |
|
| 15 |
- # Initialize attributes |
|
| 16 |
- $self->no_bind_filters($self->{no_bind_filters})
|
|
| 17 |
- if $self->{no_bind_filters};
|
|
| 18 |
- |
|
| 19 |
- return $self; |
|
| 20 |
-} |
|
| 21 |
- |
|
| 22 |
-sub no_bind_filters {
|
|
| 23 |
- my $self = shift; |
|
| 24 |
- |
|
| 25 |
- if (@_) {
|
|
| 26 |
- # Set |
|
| 27 |
- $self->{no_bind_filters} = $_[0];
|
|
| 28 |
- |
|
| 29 |
- # Cached |
|
| 30 |
- my %no_bind_filters = map { $_ => 1 } @{$self->{no_bind_filters}};
|
|
| 31 |
- $self->_no_bind_filters(\%no_bind_filters); |
|
| 32 |
- |
|
| 33 |
- return $self; |
|
| 34 |
- } |
|
| 35 |
- |
|
| 36 |
- return $self->{no_bind_filters};
|
|
| 37 |
-} |
|
| 38 | 9 |
|
| 39 | 10 |
1; |
| 40 | 11 |
|
| ... | ... |
@@ -50,12 +21,9 @@ DBIx::Custom::Query - DBIx::Custom query |
| 50 | 21 |
# Create by using create_query |
| 51 | 22 |
my $query = DBIx::Custom->create_query($template); |
| 52 | 23 |
|
| 53 |
- # Set attributes |
|
| 24 |
+ # Attributes |
|
| 54 | 25 |
$query->bind_filter($dbi->filters->{default_bind_filter});
|
| 55 |
- $query->no_bind_filters('title', 'author');
|
|
| 56 |
- |
|
| 57 | 26 |
$query->fetch_filter($dbi->filters->{default_fetch_filter});
|
| 58 |
- $query->no_fetch_filters('title', 'author');
|
|
| 59 | 27 |
|
| 60 | 28 |
=head1 ATTRIBUTES |
| 61 | 29 |
|
| ... | ... |
@@ -80,13 +48,6 @@ Filter excuted when value is bind |
| 80 | 48 |
$query = $query->bind_filter($bind_filter); |
| 81 | 49 |
$bind_filter = $query->bind_filter; |
| 82 | 50 |
|
| 83 |
-=head2 no_bind_filters |
|
| 84 |
- |
|
| 85 |
-Key list which dose not have to bind filtering |
|
| 86 |
- |
|
| 87 |
- $query = $query->no_bind_filters($no_filters); |
|
| 88 |
- $no_bind_filters = $query->no_bind_filters; |
|
| 89 |
- |
|
| 90 | 51 |
=head2 fetch_filter |
| 91 | 52 |
|
| 92 | 53 |
Filter excuted when data is fetched |
| ... | ... |
@@ -94,13 +55,6 @@ Filter excuted when data is fetched |
| 94 | 55 |
$query = $query->fetch_filter($fetch_filter); |
| 95 | 56 |
$fetch_filter = $query->fetch_filter; |
| 96 | 57 |
|
| 97 |
-=head2 no_fetch_filters |
|
| 98 |
- |
|
| 99 |
-Key list which dose not have to fetch filtering |
|
| 100 |
- |
|
| 101 |
- $query = $query->no_fetch_filters($no_filters); |
|
| 102 |
- $no_fetch_filters = $query->no_fetch_filters; |
|
| 103 |
- |
|
| 104 | 58 |
=head2 key_infos |
| 105 | 59 |
|
| 106 | 60 |
Key informations |
| ... | ... |
@@ -8,35 +8,6 @@ use base 'Object::Simple'; |
| 8 | 8 |
use Carp 'croak'; |
| 9 | 9 |
|
| 10 | 10 |
__PACKAGE__->attr([qw/_dbi sth fetch_filter/]); |
| 11 |
-__PACKAGE__->attr(_no_fetch_filters => sub { {} });
|
|
| 12 |
- |
|
| 13 |
-sub new {
|
|
| 14 |
- my $self = shift->SUPER::new(@_); |
|
| 15 |
- |
|
| 16 |
- # Initialize attributes |
|
| 17 |
- $self->no_fetch_filters($self->{no_fetch_filters})
|
|
| 18 |
- if exists $self->{no_fetch_filters};
|
|
| 19 |
- |
|
| 20 |
- return $self; |
|
| 21 |
-} |
|
| 22 |
- |
|
| 23 |
-sub no_fetch_filters {
|
|
| 24 |
- my $self = shift; |
|
| 25 |
- |
|
| 26 |
- if (@_) {
|
|
| 27 |
- |
|
| 28 |
- # Set |
|
| 29 |
- $self->{no_fetch_filters} = $_[0];
|
|
| 30 |
- |
|
| 31 |
- # Cached |
|
| 32 |
- my %no_fetch_filters = map {$_ => 1} @{$self->{no_fetch_filters}};
|
|
| 33 |
- $self->_no_fetch_filters(\%no_fetch_filters); |
|
| 34 |
- |
|
| 35 |
- return $self; |
|
| 36 |
- } |
|
| 37 |
- |
|
| 38 |
- return $self->{no_fetch_filters};
|
|
| 39 |
-} |
|
| 40 | 11 |
|
| 41 | 12 |
sub fetch {
|
| 42 | 13 |
my ($self, $type) = @_; |
| ... | ... |
@@ -54,7 +25,6 @@ sub fetch {
|
| 54 | 25 |
my $keys = $sth->{NAME_lc};
|
| 55 | 26 |
my $types = $sth->{TYPE};
|
| 56 | 27 |
for (my $i = 0; $i < @$keys; $i++) {
|
| 57 |
- next if $self->_no_fetch_filters->{$keys->[$i]};
|
|
| 58 | 28 |
$row->[$i]= $fetch_filter->($row->[$i], $keys->[$i], $self->_dbi, |
| 59 | 29 |
{type => $types->[$i], sth => $sth, index => $i});
|
| 60 | 30 |
} |
| ... | ... |
@@ -81,14 +51,9 @@ sub fetch_hash {
|
| 81 | 51 |
if ($fetch_filter) {
|
| 82 | 52 |
my $types = $sth->{TYPE};
|
| 83 | 53 |
for (my $i = 0; $i < @$keys; $i++) {
|
| 84 |
- if ($self->_no_fetch_filters->{$keys->[$i]}) {
|
|
| 85 |
- $row_hash->{$keys->[$i]} = $row->[$i];
|
|
| 86 |
- } |
|
| 87 |
- else {
|
|
| 88 |
- $row_hash->{$keys->[$i]}
|
|
| 89 |
- = $fetch_filter->($row->[$i], $keys->[$i], $self->_dbi, |
|
| 90 |
- {type => $types->[$i], sth => $sth, index => $i});
|
|
| 91 |
- } |
|
| 54 |
+ $row_hash->{$keys->[$i]}
|
|
| 55 |
+ = $fetch_filter->($row->[$i], $keys->[$i], $self->_dbi, |
|
| 56 |
+ {type => $types->[$i], sth => $sth, index => $i});
|
|
| 92 | 57 |
} |
| 93 | 58 |
} |
| 94 | 59 |
|
| ... | ... |
@@ -242,13 +207,6 @@ Filter excuted when data is fetched |
| 242 | 207 |
$result = $result->fetch_filter($sth); |
| 243 | 208 |
$fetch_filter = $result->fech_filter; |
| 244 | 209 |
|
| 245 |
-=head2 no_fetch_filters |
|
| 246 |
- |
|
| 247 |
-Key list which dose not have to fetch filtering |
|
| 248 |
- |
|
| 249 |
- $result = $result->no_fetch_filters($no_fetch_filters); |
|
| 250 |
- $no_fetch_filters = $result->no_fetch_filters; |
|
| 251 |
- |
|
| 252 | 210 |
=head1 METHODS |
| 253 | 211 |
|
| 254 | 212 |
This class is L<Object::Simple> subclass. |
| ... | ... |
@@ -237,14 +237,18 @@ sub expand_basic_tag {
|
| 237 | 237 |
croak("You must be pass key as argument to tag '{$tag_name }'")
|
| 238 | 238 |
unless $key; |
| 239 | 239 |
|
| 240 |
+ # Key info |
|
| 241 |
+ my $key_info = DBIx::Custom::KeyInfo->new($key); |
|
| 242 |
+ $key_info->table($table) unless $key_info->table; |
|
| 243 |
+ |
|
| 240 | 244 |
# Expanded tag |
| 245 |
+ my $column = $key_info->table |
|
| 246 |
+ ? $key_info->table . '.' . $key_info->column |
|
| 247 |
+ : $key_info->column; |
|
| 241 | 248 |
my $expand = $tag_name eq '?' |
| 242 | 249 |
? '?' |
| 243 |
- : "$key $tag_name ?"; |
|
| 244 |
- |
|
| 245 |
- my $key_info = DBIx::Custom::KeyInfo->new($key); |
|
| 246 |
- $key_info->table($table) unless $key_info->table; |
|
| 247 |
- |
|
| 250 |
+ : "$column $tag_name ?"; |
|
| 251 |
+ |
|
| 248 | 252 |
return ($expand, [$key_info]); |
| 249 | 253 |
} |
| 250 | 254 |
|
| ... | ... |
@@ -263,7 +267,12 @@ sub expand_in_tag {
|
| 263 | 267 |
if !$placeholder_count || $placeholder_count =~ /\D/; |
| 264 | 268 |
|
| 265 | 269 |
# Expand tag |
| 266 |
- my $expand = "$key $tag_name (";
|
|
| 270 |
+ my $key_info = DBIx::Custom::KeyInfo->new($key); |
|
| 271 |
+ my $column = $key_info->table |
|
| 272 |
+ ? $key_info->table . '.' . $key_info->column |
|
| 273 |
+ : $key_info->column; |
|
| 274 |
+ |
|
| 275 |
+ my $expand = "$column $tag_name (";
|
|
| 267 | 276 |
for (my $i = 0; $i < $placeholder_count; $i++) {
|
| 268 | 277 |
$expand .= '?, '; |
| 269 | 278 |
} |
| ... | ... |
@@ -25,7 +25,7 @@ my $CREATE_TABLE = {
|
| 25 | 25 |
2 => 'create table table2 (key1 char(255), key3 char(255));' |
| 26 | 26 |
}; |
| 27 | 27 |
|
| 28 |
-my $SELECT_TMPL = {
|
|
| 28 |
+my $SELECT_TMPLS = {
|
|
| 29 | 29 |
0 => 'select * from table1;' |
| 30 | 30 |
}; |
| 31 | 31 |
|
| ... | ... |
@@ -180,19 +180,17 @@ $insert_tmpl = "insert into table1 {insert key1 key2}";
|
| 180 | 180 |
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2}, sub {
|
| 181 | 181 |
my $query = shift; |
| 182 | 182 |
$query->bind_filter(sub {
|
| 183 |
- my ($value, $table, $column) = @_; |
|
| 184 |
- if ($column eq 'key2') {
|
|
| 183 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 184 |
+ if ($column eq 'key2' && $dbi->isa('DBIx::Custom')) {
|
|
| 185 | 185 |
return $value + 1; |
| 186 | 186 |
} |
| 187 | 187 |
return $value; |
| 188 | 188 |
}); |
| 189 | 189 |
}); |
| 190 |
-$result = $dbi->query(['table1', $SELECT_TMPL->{0}]);
|
|
| 190 |
+$result = $dbi->query(['table1', $SELECT_TMPLS->{0}]);
|
|
| 191 | 191 |
$rows = $result->fetch_hash_all; |
| 192 | 192 |
is_deeply($rows, [{key1 => 1, key2 => 3}], $test);
|
| 193 | 193 |
|
| 194 |
-__END__ |
|
| 195 |
- |
|
| 196 | 194 |
test 'Filter basic'; |
| 197 | 195 |
$dbi->do($DROP_TABLE->{0});
|
| 198 | 196 |
$dbi->do($CREATE_TABLE->{0});
|
| ... | ... |
@@ -200,7 +198,7 @@ $dbi->do($CREATE_TABLE->{0});
|
| 200 | 198 |
$insert_tmpl = "insert into table1 {insert key1 key2};";
|
| 201 | 199 |
$insert_query = $dbi->create_query($insert_tmpl); |
| 202 | 200 |
$insert_query->bind_filter(sub {
|
| 203 |
- my ($value, $table, $column) = @_; |
|
| 201 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 204 | 202 |
|
| 205 | 203 |
if ($table eq '' && $column eq 'key1') |
| 206 | 204 |
{
|
| ... | ... |
@@ -209,7 +207,7 @@ $insert_query->bind_filter(sub {
|
| 209 | 207 |
return $value; |
| 210 | 208 |
}); |
| 211 | 209 |
$dbi->query($insert_query, {key1 => 1, key2 => 2});
|
| 212 |
-$select_query = $dbi->create_query($SELECT_TMPL->{0});
|
|
| 210 |
+$select_query = $dbi->create_query($SELECT_TMPLS->{0});
|
|
| 213 | 211 |
$select_query->fetch_filter(sub {
|
| 214 | 212 |
my ($value, $key, $dbi, $infos) = @_; |
| 215 | 213 |
my ($type, $sth, $i) = @{$infos}{qw/type sth index/};
|
| ... | ... |
@@ -225,32 +223,23 @@ $result = $dbi->query($select_query); |
| 225 | 223 |
$rows = $result->fetch_hash_all; |
| 226 | 224 |
is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : bind_filter fetch_filter");
|
| 227 | 225 |
|
| 228 |
-$dbi->do("delete from table1;");
|
|
| 229 |
-$insert_query->no_bind_filters(['key1']); |
|
| 230 |
-$select_query->no_fetch_filters(['key2']); |
|
| 231 |
-$dbi->query($insert_query, {key1 => 1, key2 => 2});
|
|
| 232 |
-$result = $dbi->query($select_query); |
|
| 233 |
-$rows = $result->fetch_hash_all; |
|
| 234 |
-is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : no_fetch_filters no_bind_filters");
|
|
| 235 |
- |
|
| 236 | 226 |
$dbi->do($DROP_TABLE->{0});
|
| 237 | 227 |
$dbi->do($CREATE_TABLE->{0});
|
| 238 | 228 |
$insert_tmpl = "insert into table1 {insert table1.key1 table1.key2}";
|
| 239 | 229 |
$insert_query = $dbi->create_query($insert_tmpl); |
| 240 | 230 |
$insert_query->bind_filter(sub {
|
| 241 |
- my ($value, $key, $dbi, $infos) = @_; |
|
| 242 |
- my ($table, $column) = @{$infos}{qw/table column/};
|
|
| 231 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 243 | 232 |
|
| 244 |
- if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1') {
|
|
| 233 |
+ if ($table eq 'table1' && $column eq 'key1') {
|
|
| 245 | 234 |
return $value * 3; |
| 246 | 235 |
} |
| 247 | 236 |
return $value; |
| 248 | 237 |
}); |
| 249 |
-$dbi->query($insert_query, {table1 => {key1 => 1, key2 => 2}});
|
|
| 250 |
-$select_query = $dbi->create_query($SELECT_TMPL->{0});
|
|
| 238 |
+$dbi->query($insert_query, {key1 => 1, key2 => 2});
|
|
| 239 |
+$select_query = $dbi->create_query($SELECT_TMPLS->{0});
|
|
| 251 | 240 |
$result = $dbi->query($select_query); |
| 252 | 241 |
$rows = $result->fetch_hash_all; |
| 253 |
-is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with table name");
|
|
| 242 |
+is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : insert with id");
|
|
| 254 | 243 |
|
| 255 | 244 |
test 'Filter in'; |
| 256 | 245 |
$insert_tmpl = "insert into table1 {insert key1 key2};";
|
| ... | ... |
@@ -259,15 +248,14 @@ $dbi->query($insert_query, {key1 => 2, key2 => 4});
|
| 259 | 248 |
$select_tmpl = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
|
| 260 | 249 |
$select_query = $dbi->create_query($select_tmpl); |
| 261 | 250 |
$select_query->bind_filter(sub {
|
| 262 |
- my ($value, $key, $dbi, $infos) = @_; |
|
| 263 |
- my ($table, $column) = @{$infos}{qw/table column/};
|
|
| 251 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 264 | 252 |
|
| 265 |
- if ($key eq 'table1.key1' && $table eq 'table1' && $column eq 'key1' || $key eq 'table1.key2') {
|
|
| 253 |
+ if ($table eq 'table1' && $column eq 'key1') {
|
|
| 266 | 254 |
return $value * 2; |
| 267 | 255 |
} |
| 268 | 256 |
return $value; |
| 269 | 257 |
}); |
| 270 |
-$result = $dbi->query($select_query, {table1 => {key1 => [1,5], key2 => [2,5]}});
|
|
| 258 |
+$result = $dbi->query($select_query, {key1 => [1,5], key2 => [2,4]});
|
|
| 271 | 259 |
$rows = $result->fetch_hash_all; |
| 272 | 260 |
is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : bind_filter");
|
| 273 | 261 |
|
| ... | ... |
@@ -285,15 +273,15 @@ $result = $dbi->query($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5
|
| 285 | 273 |
$rows = $result->fetch_hash_all; |
| 286 | 274 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1");
|
| 287 | 275 |
|
| 288 |
-$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
|
|
| 276 |
+$tmpl = "select * from table1 where {= table1.key1#id} and {<> table1.key2#id} and {< table1.key3#id} and {> table1.key4#id} and {>= table1.key5#id};";
|
|
| 289 | 277 |
$query = $dbi->create_query($tmpl); |
| 290 |
-$result = $dbi->query($query, {table1 => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}});
|
|
| 278 |
+$result = $dbi->query($query, {id => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5}});
|
|
| 291 | 279 |
$rows = $result->fetch_hash_all; |
| 292 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table");
|
|
| 280 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with id");
|
|
| 293 | 281 |
|
| 294 | 282 |
$tmpl = "select * from table1 where {= table1.key1} and {<> table1.key2} and {< table1.key3} and {> table1.key4} and {>= table1.key5};";
|
| 295 | 283 |
$query = $dbi->create_query($tmpl); |
| 296 |
-$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => 3, 'table1.key3' => 4, 'table1.key4' => 3, 'table1.key5' => 5});
|
|
| 284 |
+$result = $dbi->query($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
|
| 297 | 285 |
$rows = $result->fetch_hash_all; |
| 298 | 286 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag1 with table dot");
|
| 299 | 287 |
|
| ... | ... |
@@ -303,15 +291,15 @@ $result = $dbi->query($query, {key1 => 1, key2 => '%2%'});
|
| 303 | 291 |
$rows = $result->fetch_hash_all; |
| 304 | 292 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
|
| 305 | 293 |
|
| 306 |
-$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
|
|
| 294 |
+$tmpl = "select * from table1 where {<= table1.key1#id} and {like table1.key2#id};";
|
|
| 307 | 295 |
$query = $dbi->create_query($tmpl); |
| 308 |
-$result = $dbi->query($query, {table1 => {key1 => 1, key2 => '%2%'}});
|
|
| 296 |
+$result = $dbi->query($query, {id => {key1 => 1, key2 => '%2%'}});
|
|
| 309 | 297 |
$rows = $result->fetch_hash_all; |
| 310 | 298 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table");
|
| 311 | 299 |
|
| 312 | 300 |
$tmpl = "select * from table1 where {<= table1.key1} and {like table1.key2};";
|
| 313 | 301 |
$query = $dbi->create_query($tmpl); |
| 314 |
-$result = $dbi->query($query, {'table1.key1' => 1, 'table1.key2' => '%2%'});
|
|
| 302 |
+$result = $dbi->query($query, {'key1' => 1, 'key2' => '%2%'});
|
|
| 315 | 303 |
$rows = $result->fetch_hash_all; |
| 316 | 304 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2 with table dot");
|
| 317 | 305 |
|
| ... | ... |
@@ -329,15 +317,15 @@ $result = $dbi->query($query, {key1 => [9, 1]});
|
| 329 | 317 |
$rows = $result->fetch_hash_all; |
| 330 | 318 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
|
| 331 | 319 |
|
| 332 |
-$tmpl = "select * from table1 where {in table1.key1 2};";
|
|
| 320 |
+$tmpl = "select * from table1 where {in table1.key1#id 2};";
|
|
| 333 | 321 |
$query = $dbi->create_query($tmpl); |
| 334 |
-$result = $dbi->query($query, {table1 => {key1 => [9, 1]}});
|
|
| 322 |
+$result = $dbi->query($query, {id => {key1 => [9, 1]}});
|
|
| 335 | 323 |
$rows = $result->fetch_hash_all; |
| 336 | 324 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table");
|
| 337 | 325 |
|
| 338 |
-$tmpl = "select * from table1 where {in table1.key1 2};";
|
|
| 326 |
+$tmpl = "select * from table1 where {in table1.key1#id 2};";
|
|
| 339 | 327 |
$query = $dbi->create_query($tmpl); |
| 340 |
-$result = $dbi->query($query, {'table1.key1' => [9, 1]});
|
|
| 328 |
+$result = $dbi->query($query, {id => {'key1' => [9, 1]}});
|
|
| 341 | 329 |
$rows = $result->fetch_hash_all; |
| 342 | 330 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table dot");
|
| 343 | 331 |
|
| ... | ... |
@@ -347,25 +335,17 @@ $dbi->do("delete from table1");
|
| 347 | 335 |
$insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
|
| 348 | 336 |
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 349 | 337 |
|
| 350 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 338 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 351 | 339 |
$rows = $result->fetch_hash_all; |
| 352 | 340 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
|
| 353 | 341 |
|
| 354 | 342 |
$dbi->do("delete from table1");
|
| 355 |
-$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
|
|
| 356 |
-$dbi->query($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
|
|
| 357 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 343 |
+$insert_tmpl = 'insert into table1 {insert table1.key1#id table1.key2#id table1.key3#id table1.key4#id table1.key5#id}';
|
|
| 344 |
+$dbi->query($insert_tmpl, {id => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
|
|
| 345 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 358 | 346 |
$rows = $result->fetch_hash_all; |
| 359 | 347 |
is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name");
|
| 360 | 348 |
|
| 361 |
-$dbi->do("delete from table1");
|
|
| 362 |
-$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
|
|
| 363 |
-$dbi->query($insert_tmpl, {'table1.key1' => 1, 'table1.key2' => 2, 'table1.key3' => 3, 'table1.key4' => 4, 'table1.key5' => 5});
|
|
| 364 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 365 |
-$rows = $result->fetch_hash_all; |
|
| 366 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : with table name dot");
|
|
| 367 |
- |
|
| 368 |
- |
|
| 369 | 349 |
test 'DBIx::Custom::SQL::Template update tag'; |
| 370 | 350 |
$dbi->do("delete from table1");
|
| 371 | 351 |
$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
|
| ... | ... |
@@ -375,25 +355,18 @@ $dbi->query($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 1
|
| 375 | 355 |
$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}';
|
| 376 | 356 |
$dbi->query($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
|
| 377 | 357 |
|
| 378 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 358 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 379 | 359 |
$rows = $result->fetch_hash_all; |
| 380 | 360 |
is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
|
| 381 | 361 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
|
| 382 | 362 |
|
| 383 |
-$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
|
|
| 384 |
-$dbi->query($update_tmpl, {table1 => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}});
|
|
| 385 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 363 |
+$update_tmpl = 'update table1 {update table1.key1#id table1.key2#id table1.key3#id table1.key4#id} where {= table1.key5#id}';
|
|
| 364 |
+$dbi->query($update_tmpl, {id => {key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5}});
|
|
| 365 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 386 | 366 |
$rows = $result->fetch_hash_all; |
| 387 | 367 |
is_deeply($rows, [{key1 => 3, key2 => 3, key3 => 3, key4 => 3, key5 => 5},
|
| 388 | 368 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name");
|
| 389 | 369 |
|
| 390 |
-$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4} where {= table1.key5}';
|
|
| 391 |
-$dbi->query($update_tmpl, {'table1.key1' => 4, 'table1.key2' => 4, 'table1.key3' => 4, 'table1.key4' => 4, 'table1.key5' => 5});
|
|
| 392 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 393 |
-$rows = $result->fetch_hash_all; |
|
| 394 |
-is_deeply($rows, [{key1 => 4, key2 => 4, key3 => 4, key4 => 4, key5 => 5},
|
|
| 395 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : with table name dot");
|
|
| 396 |
- |
|
| 397 | 370 |
test 'transaction'; |
| 398 | 371 |
$dbi->do($DROP_TABLE->{0});
|
| 399 | 372 |
$dbi->do($CREATE_TABLE->{0});
|
| ... | ... |
@@ -402,7 +375,7 @@ $dbi->run_transaction(sub {
|
| 402 | 375 |
$dbi->query($insert_tmpl, {key1 => 1, key2 => 2});
|
| 403 | 376 |
$dbi->query($insert_tmpl, {key1 => 3, key2 => 4});
|
| 404 | 377 |
}); |
| 405 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 378 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 406 | 379 |
$rows = $result->fetch_hash_all; |
| 407 | 380 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit");
|
| 408 | 381 |
|
| ... | ... |
@@ -419,7 +392,7 @@ eval{
|
| 419 | 392 |
}; |
| 420 | 393 |
like($@, qr/Fatal Error.*Rollback is success/ms, "$test : Rollback success message"); |
| 421 | 394 |
ok(!$dbi->dbh->{RaiseError}, "$test : restore RaiseError value");
|
| 422 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 395 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 423 | 396 |
$rows = $result->fetch_hash_all; |
| 424 | 397 |
is_deeply($rows, [], "$test : rollback"); |
| 425 | 398 |
|
| ... | ... |
@@ -455,20 +428,12 @@ $dbi = DBIx::Custom->new($NEW_ARGS->{0});
|
| 455 | 428 |
eval{$dbi->create_query("{p }")};
|
| 456 | 429 |
ok($@, "$test : create_query invalid SQL template"); |
| 457 | 430 |
|
| 458 |
-$dbi = DBIx::Custom->new($NEW_ARGS->{0});
|
|
| 459 |
-$dbi->do($CREATE_TABLE->{0});
|
|
| 460 |
-$query = $dbi->create_query("select * from table1 where {= key1}");
|
|
| 461 |
-eval{$dbi->query($query, {key2 => 1})};
|
|
| 462 |
-like($@, qr/Corresponding key is not found in your parameters/, |
|
| 463 |
- "$test : execute corresponding key not found"); |
|
| 464 |
- |
|
| 465 |
- |
|
| 466 | 431 |
test 'insert'; |
| 467 | 432 |
$dbi = DBIx::Custom->new($NEW_ARGS->{0});
|
| 468 | 433 |
$dbi->do($CREATE_TABLE->{0});
|
| 469 | 434 |
$dbi->insert('table1', {key1 => 1, key2 => 2});
|
| 470 | 435 |
$dbi->insert('table1', {key1 => 3, key2 => 4});
|
| 471 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 436 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 472 | 437 |
$rows = $result->fetch_hash_all; |
| 473 | 438 |
is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic");
|
| 474 | 439 |
|
| ... | ... |
@@ -476,14 +441,14 @@ $dbi->do('delete from table1');
|
| 476 | 441 |
$dbi->insert('table1', {key1 => 1, key2 => 2}, sub {
|
| 477 | 442 |
my $query = shift; |
| 478 | 443 |
$query->bind_filter(sub {
|
| 479 |
- my ($value, $key) = @_; |
|
| 480 |
- if ($key eq 'key1') {
|
|
| 444 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 445 |
+ if ($column eq 'key1') {
|
|
| 481 | 446 |
return $value * 3; |
| 482 | 447 |
} |
| 483 | 448 |
return $value; |
| 484 | 449 |
}); |
| 485 | 450 |
}); |
| 486 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 451 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 487 | 452 |
$rows = $result->fetch_hash_all; |
| 488 | 453 |
is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : edit_query_callback");
|
| 489 | 454 |
|
| ... | ... |
@@ -507,21 +472,21 @@ $dbi->do($CREATE_TABLE->{1});
|
| 507 | 472 |
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 508 | 473 |
$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
| 509 | 474 |
$dbi->update('table1', {key2 => 11}, {key1 => 1});
|
| 510 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 475 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 511 | 476 |
$rows = $result->fetch_hash_all; |
| 512 | 477 |
is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
| 513 | 478 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| 514 | 479 |
"$test : basic"); |
| 515 | 480 |
|
| 516 |
-#$dbi->do("delete from table1");
|
|
| 517 |
-#$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 518 |
-#$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 519 |
-#$dbi->update('table1', {key2 => 12}, {key2 => 2, key3 => 3});
|
|
| 520 |
-#$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 521 |
-#$rows = $result->fetch_hash_all; |
|
| 522 |
-#is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
|
| 523 |
-# {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 524 |
-# "$test : update key same as search key"); |
|
| 481 |
+$dbi->do("delete from table1");
|
|
| 482 |
+$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 483 |
+$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 484 |
+$dbi->update('table1', {key2 => 12}, {key2 => 2, key3 => 3});
|
|
| 485 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 486 |
+$rows = $result->fetch_hash_all; |
|
| 487 |
+is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
|
|
| 488 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 489 |
+ "$test : update key same as search key"); |
|
| 525 | 490 |
|
| 526 | 491 |
$dbi->do("delete from table1");
|
| 527 | 492 |
$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| ... | ... |
@@ -529,14 +494,14 @@ $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10})
|
| 529 | 494 |
$dbi->update('table1', {key2 => 11}, {key1 => 1}, sub {
|
| 530 | 495 |
my $query = shift; |
| 531 | 496 |
$query->bind_filter(sub {
|
| 532 |
- my ($value, $key) = @_; |
|
| 533 |
- if ($key eq 'key2') {
|
|
| 497 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 498 |
+ if ($column eq 'key2') {
|
|
| 534 | 499 |
return $value * 2; |
| 535 | 500 |
} |
| 536 | 501 |
return $value; |
| 537 | 502 |
}); |
| 538 | 503 |
}); |
| 539 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 504 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 540 | 505 |
$rows = $result->fetch_hash_all; |
| 541 | 506 |
is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
|
| 542 | 507 |
{key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -544,7 +509,7 @@ is_deeply($rows, [{key1 => 1, key2 => 22, key3 => 3, key4 => 4, key5 => 5},
|
| 544 | 509 |
|
| 545 | 510 |
$dbi->update('table1', {key2 => 11}, {key1 => 1}, ' ', sub {
|
| 546 | 511 |
my $query = shift; |
| 547 |
- is($query->sql, 'update table1 set key2 = ? where key1 = ? ;', |
|
| 512 |
+ is($query->sql, 'update table1 set key2 = ? where table1.key1 = ? ;', |
|
| 548 | 513 |
"$test: append statement"); |
| 549 | 514 |
}); |
| 550 | 515 |
|
| ... | ... |
@@ -573,11 +538,11 @@ $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10})
|
| 573 | 538 |
$dbi->update_all('table1', {key2 => 10}, sub {
|
| 574 | 539 |
my $query = shift; |
| 575 | 540 |
$query->bind_filter(sub {
|
| 576 |
- my ($value, $key) = @_; |
|
| 541 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 577 | 542 |
return $value * 2; |
| 578 | 543 |
}) |
| 579 | 544 |
}); |
| 580 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 545 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 581 | 546 |
$rows = $result->fetch_hash_all; |
| 582 | 547 |
is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
|
| 583 | 548 |
{key1 => 6, key2 => 20, key3 => 8, key4 => 9, key5 => 10}],
|
| ... | ... |
@@ -590,7 +555,7 @@ $dbi->do($CREATE_TABLE->{0});
|
| 590 | 555 |
$dbi->insert('table1', {key1 => 1, key2 => 2});
|
| 591 | 556 |
$dbi->insert('table1', {key1 => 3, key2 => 4});
|
| 592 | 557 |
$dbi->delete('table1', {key1 => 1});
|
| 593 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 558 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 594 | 559 |
$rows = $result->fetch_hash_all; |
| 595 | 560 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
|
| 596 | 561 |
|
| ... | ... |
@@ -600,17 +565,17 @@ $dbi->insert('table1', {key1 => 3, key2 => 4});
|
| 600 | 565 |
$dbi->delete('table1', {key2 => 1}, sub {
|
| 601 | 566 |
my $query = shift; |
| 602 | 567 |
$query->bind_filter(sub {
|
| 603 |
- my ($value, $key) = @_; |
|
| 568 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 604 | 569 |
return $value * 2; |
| 605 | 570 |
}); |
| 606 | 571 |
}); |
| 607 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 572 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 608 | 573 |
$rows = $result->fetch_hash_all; |
| 609 | 574 |
is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : query edit callback");
|
| 610 | 575 |
|
| 611 | 576 |
$dbi->delete('table1', {key1 => 1}, ' ', sub {
|
| 612 | 577 |
my $query = shift; |
| 613 |
- is($query->sql, 'delete from table1 where key1 = ? ;', |
|
| 578 |
+ is($query->sql, 'delete from table1 where table1.key1 = ? ;', |
|
| 614 | 579 |
"$test: append statement"); |
| 615 | 580 |
}); |
| 616 | 581 |
|
| ... | ... |
@@ -641,7 +606,7 @@ $dbi->do($CREATE_TABLE->{0});
|
| 641 | 606 |
$dbi->insert('table1', {key1 => 1, key2 => 2});
|
| 642 | 607 |
$dbi->insert('table1', {key1 => 3, key2 => 4});
|
| 643 | 608 |
$dbi->delete_all('table1');
|
| 644 |
-$result = $dbi->query($SELECT_TMPL->{0});
|
|
| 609 |
+$result = $dbi->query($SELECT_TMPLS->{0});
|
|
| 645 | 610 |
$rows = $result->fetch_hash_all; |
| 646 | 611 |
is_deeply($rows, [], "$test : basic"); |
| 647 | 612 |
|
| ... | ... |
@@ -670,8 +635,8 @@ is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : append statement");
|
| 670 | 635 |
$rows = $dbi->select('table1', {key1 => 2}, sub {
|
| 671 | 636 |
my $query = shift; |
| 672 | 637 |
$query->bind_filter(sub {
|
| 673 |
- my ($value, $key) = @_; |
|
| 674 |
- if ($key eq 'key1') {
|
|
| 638 |
+ my ($value, $table, $column, $dbi) = @_; |
|
| 639 |
+ if ($column eq 'key1') {
|
|
| 675 | 640 |
return $value - 1; |
| 676 | 641 |
} |
| 677 | 642 |
return $value; |
| ... | ... |
@@ -215,9 +215,3 @@ test 'Accessor'; |
| 215 | 215 |
$dbi = DBIx::Custom->new; |
| 216 | 216 |
$dbi->options({opt1 => 1, opt2 => 2});
|
| 217 | 217 |
is_deeply(scalar $dbi->options, {opt1 => 1, opt2 => 2}, "$test : options");
|
| 218 |
- |
|
| 219 |
-$dbi->no_bind_filters(['a', 'b']); |
|
| 220 |
-is_deeply(scalar $dbi->no_bind_filters, ['a', 'b'], "$test: no_bind_filters"); |
|
| 221 |
- |
|
| 222 |
-$dbi->no_fetch_filters(['a', 'b']); |
|
| 223 |
-is_deeply(scalar $dbi->no_fetch_filters, ['a', 'b'], "$test: no_fetch_filters"); |
| ... | ... |
@@ -18,20 +18,12 @@ $query = DBIx::Custom::Query->new( |
| 18 | 18 |
sql => 'a', |
| 19 | 19 |
key_infos => 'b', |
| 20 | 20 |
bind_filter => 'c', |
| 21 |
- no_bind_filters => [qw/d e/], |
|
| 22 | 21 |
sth => 'e', |
| 23 | 22 |
fetch_filter => 'f', |
| 24 |
- no_fetch_filters => [qw/g h/], |
|
| 25 | 23 |
); |
| 26 | 24 |
|
| 27 | 25 |
is($query->sql, 'a', "$test : sql"); |
| 28 | 26 |
is($query->key_infos, 'b', "$test : key_infos "); |
| 29 | 27 |
is($query->bind_filter, 'c', "$test : bind_filter"); |
| 30 |
-is_deeply($query->no_bind_filters, [qw/d e/], "$test : no_bind_filters"); |
|
| 31 |
-is_deeply($query->_no_bind_filters, {d => 1, e => 1}, "$test : _no_bind_filters");
|
|
| 32 |
-is_deeply($query->no_fetch_filters, [qw/g h/], "$test : no_fetch_filters"); |
|
| 33 | 28 |
is($query->sth, 'e', "$test : sth"); |
| 34 | 29 |
|
| 35 |
-$query->no_bind_filters(undef); |
|
| 36 |
-is_deeply(scalar $query->_no_bind_filters, {}, "$test _no_bind_filters undef value");
|
|
| 37 |
- |
| ... | ... |
@@ -227,17 +227,6 @@ $result->fetch_filter($fetch_filter); |
| 227 | 227 |
$rows = $result->fetch_hash_all; |
| 228 | 228 |
is_deeply($rows, [{key1 => 3, key2 => 2}, {key1 => 3, key2 => 4}], "$test hash");
|
| 229 | 229 |
|
| 230 |
-$result = query($dbh, $sql); |
|
| 231 |
-$result->no_fetch_filters(['key1']); |
|
| 232 |
-$rows = $result->fetch_all; |
|
| 233 |
-is_deeply($rows, [[1, 2], [3, 4]], "$test array no filter keys"); |
|
| 234 |
- |
|
| 235 |
-$result = query($dbh, $sql); |
|
| 236 |
-$result->no_fetch_filters(['key1']); |
|
| 237 |
-$rows = $result->fetch_hash_all; |
|
| 238 |
-is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test hash no filter keys");
|
|
| 239 |
- |
|
| 240 |
- |
|
| 241 | 230 |
test 'finish'; |
| 242 | 231 |
$result = query($dbh, $sql); |
| 243 | 232 |
$result->fetch; |