| ... | ... |
@@ -240,7 +240,7 @@ sub create_query {
|
| 240 | 240 |
} |
| 241 | 241 |
|
| 242 | 242 |
our %VALID_DELETE_ARGS |
| 243 |
- = map { $_ => 1 } qw/table where append filter allow_delete_all/;
|
|
| 243 |
+ = map { $_ => 1 } qw/table where append filter allow_delete_all query/;
|
|
| 244 | 244 |
|
| 245 | 245 |
sub delete {
|
| 246 | 246 |
my ($self, %args) = @_; |
| ... | ... |
@@ -278,9 +278,13 @@ sub delete {
|
| 278 | 278 |
my $source = "delete from $table $where_clause"; |
| 279 | 279 |
$source .= " $append" if $append; |
| 280 | 280 |
|
| 281 |
+ # Create query |
|
| 282 |
+ my $query = $self->create_query($source); |
|
| 283 |
+ return $query if $args{query};
|
|
| 284 |
+ |
|
| 281 | 285 |
# Execute query |
| 282 | 286 |
my $ret_val = $self->execute( |
| 283 |
- $source, param => $where, filter => $filter, |
|
| 287 |
+ $query, param => $where, filter => $filter, |
|
| 284 | 288 |
table => $table); |
| 285 | 289 |
|
| 286 | 290 |
return $ret_val; |
| ... | ... |
@@ -386,7 +390,7 @@ sub expand {
|
| 386 | 390 |
} |
| 387 | 391 |
|
| 388 | 392 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
|
| 389 |
- filter/; |
|
| 393 |
+ filter query/; |
|
| 390 | 394 |
sub insert {
|
| 391 | 395 |
my ($self, %args) = @_; |
| 392 | 396 |
|
| ... | ... |
@@ -410,9 +414,13 @@ sub insert {
|
| 410 | 414 |
. join(' ', @insert_keys) . '}';
|
| 411 | 415 |
$source .= " $append" if $append; |
| 412 | 416 |
|
| 417 |
+ # Create query |
|
| 418 |
+ my $query = $self->create_query($source); |
|
| 419 |
+ return $query if $args{query};
|
|
| 420 |
+ |
|
| 413 | 421 |
# Execute query |
| 414 | 422 |
my $ret_val = $self->execute( |
| 415 |
- $source, |
|
| 423 |
+ $query, |
|
| 416 | 424 |
param => $param, |
| 417 | 425 |
filter => $filter, |
| 418 | 426 |
table => $table |
| ... | ... |
@@ -464,7 +472,7 @@ sub register_filter {
|
| 464 | 472 |
} |
| 465 | 473 |
|
| 466 | 474 |
our %VALID_SELECT_ARGS |
| 467 |
- = map { $_ => 1 } qw/table column where append relation filter/;
|
|
| 475 |
+ = map { $_ => 1 } qw/table column where append relation filter query/;
|
|
| 468 | 476 |
|
| 469 | 477 |
sub select {
|
| 470 | 478 |
my ($self, %args) = @_; |
| ... | ... |
@@ -546,9 +554,13 @@ sub select {
|
| 546 | 554 |
# Append some statement |
| 547 | 555 |
$source .= " $append" if $append; |
| 548 | 556 |
|
| 557 |
+ # Create query |
|
| 558 |
+ my $query = $self->create_query($source); |
|
| 559 |
+ return $query if $args{query};
|
|
| 560 |
+ |
|
| 549 | 561 |
# Execute query |
| 550 | 562 |
my $result = $self->execute( |
| 551 |
- $source, param => $param, filter => $filter, |
|
| 563 |
+ $query, param => $param, filter => $filter, |
|
| 552 | 564 |
table => $tables); |
| 553 | 565 |
|
| 554 | 566 |
return $result; |
| ... | ... |
@@ -591,7 +603,7 @@ sub txn_scope {
|
| 591 | 603 |
|
| 592 | 604 |
our %VALID_UPDATE_ARGS |
| 593 | 605 |
= map { $_ => 1 } qw/table param
|
| 594 |
- where append filter allow_update_all/; |
|
| 606 |
+ where append filter allow_update_all query/; |
|
| 595 | 607 |
|
| 596 | 608 |
sub update {
|
| 597 | 609 |
my ($self, %args) = @_; |
| ... | ... |
@@ -652,8 +664,12 @@ sub update {
|
| 652 | 664 |
} |
| 653 | 665 |
} |
| 654 | 666 |
|
| 667 |
+ # Create query |
|
| 668 |
+ my $query = $self->create_query($source); |
|
| 669 |
+ return $query if $args{query};
|
|
| 670 |
+ |
|
| 655 | 671 |
# Execute query |
| 656 |
- my $ret_val = $self->execute($source, param => $param, |
|
| 672 |
+ my $ret_val = $self->execute($query, param => $param, |
|
| 657 | 673 |
filter => $filter, |
| 658 | 674 |
table => $table); |
| 659 | 675 |
|
| ... | ... |
@@ -1085,7 +1101,8 @@ This is used in C<select()> |
| 1085 | 1101 |
$dbi->delete(table => $table, |
| 1086 | 1102 |
where => \%where, |
| 1087 | 1103 |
append => $append, |
| 1088 |
- filter => \%filter); |
|
| 1104 |
+ filter => \%filter, |
|
| 1105 |
+ query => 1); |
|
| 1089 | 1106 |
|
| 1090 | 1107 |
Execute delete statement. |
| 1091 | 1108 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
| ... | ... |
@@ -1093,6 +1110,8 @@ C<table> is a table name. |
| 1093 | 1110 |
C<where> is where clause. this must be hash reference. |
| 1094 | 1111 |
C<append> is a string added at the end of the SQL statement. |
| 1095 | 1112 |
C<filter> is filters when parameter binding is executed. |
| 1113 |
+C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
|
| 1114 |
+default to 0. This is experimental. |
|
| 1096 | 1115 |
Return value of C<delete()> is the count of affected rows. |
| 1097 | 1116 |
|
| 1098 | 1117 |
B<Example:> |
| ... | ... |
@@ -1138,7 +1157,8 @@ Register helper methods. These method is called from L<DBIx::Custom> object dire |
| 1138 | 1157 |
$dbi->insert(table => $table, |
| 1139 | 1158 |
param => \%param, |
| 1140 | 1159 |
append => $append, |
| 1141 |
- filter => \%filter); |
|
| 1160 |
+ filter => \%filter, |
|
| 1161 |
+ query => 1); |
|
| 1142 | 1162 |
|
| 1143 | 1163 |
Execute insert statement. |
| 1144 | 1164 |
C<insert> method have C<table>, C<param>, C<append> |
| ... | ... |
@@ -1147,6 +1167,8 @@ C<table> is a table name. |
| 1147 | 1167 |
C<param> is the pairs of column name value. this must be hash reference. |
| 1148 | 1168 |
C<append> is a string added at the end of the SQL statement. |
| 1149 | 1169 |
C<filter> is filters when parameter binding is executed. |
| 1170 |
+C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
|
| 1171 |
+default to 0. This is experimental. |
|
| 1150 | 1172 |
This is overwrites C<default_bind_filter>. |
| 1151 | 1173 |
Return value of C<insert()> is the count of affected rows. |
| 1152 | 1174 |
|
| ... | ... |
@@ -1240,7 +1262,8 @@ This is same as L<DBI>'s C<rollback>. |
| 1240 | 1262 |
where => \%where, |
| 1241 | 1263 |
append => $append, |
| 1242 | 1264 |
relation => \%relation, |
| 1243 |
- filter => \%filter); |
|
| 1265 |
+ filter => \%filter, |
|
| 1266 |
+ query => 1); |
|
| 1244 | 1267 |
|
| 1245 | 1268 |
Execute select statement. |
| 1246 | 1269 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
| ... | ... |
@@ -1249,6 +1272,8 @@ C<table> is a table name. |
| 1249 | 1272 |
C<where> is where clause. this is normally hash reference. |
| 1250 | 1273 |
C<append> is a string added at the end of the SQL statement. |
| 1251 | 1274 |
C<filter> is filters when parameter binding is executed. |
| 1275 |
+C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
|
| 1276 |
+default to 0. This is experimental. |
|
| 1252 | 1277 |
|
| 1253 | 1278 |
B<Example:> |
| 1254 | 1279 |
|
| ... | ... |
@@ -1294,7 +1319,8 @@ Second element is paramters. |
| 1294 | 1319 |
param => \%params, |
| 1295 | 1320 |
where => \%where, |
| 1296 | 1321 |
append => $append, |
| 1297 |
- filter => \%filter) |
|
| 1322 |
+ filter => \%filter, |
|
| 1323 |
+ query => 1) |
|
| 1298 | 1324 |
|
| 1299 | 1325 |
Execute update statement. |
| 1300 | 1326 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
| ... | ... |
@@ -1304,6 +1330,8 @@ C<param> is column-value pairs. this must be hash reference. |
| 1304 | 1330 |
C<where> is where clause. this must be hash reference. |
| 1305 | 1331 |
C<append> is a string added at the end of the SQL statement. |
| 1306 | 1332 |
C<filter> is filters when parameter binding is executed. |
| 1333 |
+C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
|
| 1334 |
+default to 0. This is experimental. |
|
| 1307 | 1335 |
This is overwrites C<default_bind_filter>. |
| 1308 | 1336 |
Return value of C<update()> is the count of affected rows. |
| 1309 | 1337 |
|
| ... | ... |
@@ -799,3 +799,18 @@ is_deeply($row, {key1 => 1, key2 => 2});
|
| 799 | 799 |
$result = $dbi->select(table => 'table1', where => [' ', {}]);
|
| 800 | 800 |
$row = $result->fetch_hash_first; |
| 801 | 801 |
is_deeply($row, {key1 => 1, key2 => 2});
|
| 802 |
+ |
|
| 803 |
+ |
|
| 804 |
+test 'select query option'; |
|
| 805 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
|
| 806 |
+$dbi->execute($CREATE_TABLE->{0});
|
|
| 807 |
+$query = $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}, query => 1);
|
|
| 808 |
+is(ref $query, 'DBIx::Custom::Query'); |
|
| 809 |
+$query = $dbi->update(table => 'table1', where => {key1 => 1}, param => {key2 => 2}, query => 1);
|
|
| 810 |
+is(ref $query, 'DBIx::Custom::Query'); |
|
| 811 |
+$query = $dbi->delete(table => 'table1', where => {key1 => 1}, query => 1);
|
|
| 812 |
+is(ref $query, 'DBIx::Custom::Query'); |
|
| 813 |
+$query = $dbi->select(table => 'table1', where => {key1 => 1, key2 => 2}, query => 1);
|
|
| 814 |
+is(ref $query, 'DBIx::Custom::Query'); |
|
| 815 |
+ |
|
| 816 |
+1; |