- update_param is DEPRECATED, use assing_clause...
...instead.
... | ... |
@@ -1,3 +1,9 @@ |
1 |
+0.1728 |
|
2 |
+ - update_param is DEPRECATED, use assing_clause instead. |
|
3 |
+ - assing_param is renamed to assing_clause, assing_param is DEPRECATED! |
|
4 |
+ - insert_param is renamed to values_clause, insert_param is DEPRECATED! |
|
5 |
+0.1727 |
|
6 |
+ - improved join clause parsing |
|
1 | 7 |
0.1726 |
2 | 8 |
- improved join clause parsing |
3 | 9 |
0.1725 |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.1726'; |
|
4 |
+our $VERSION = '0.1728'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -119,7 +119,7 @@ sub AUTOLOAD { |
119 | 119 |
} |
120 | 120 |
} |
121 | 121 |
|
122 |
-sub assign_param { |
|
122 |
+sub assign_clause { |
|
123 | 123 |
my ($self, $param, $opts) = @_; |
124 | 124 |
|
125 | 125 |
my $wrap = $opts->{wrap} || {}; |
... | ... |
@@ -636,14 +636,14 @@ sub insert { |
636 | 636 |
$sql .= "insert "; |
637 | 637 |
$sql .= "$prefix " if defined $prefix; |
638 | 638 |
$sql .= "into " . $self->_q($table) . " " |
639 |
- . $self->insert_param($param, {wrap => $wrap}) . " "; |
|
639 |
+ . $self->values_clause($param, {wrap => $wrap}) . " "; |
|
640 | 640 |
$sql .= $append if defined $append; |
641 | 641 |
|
642 | 642 |
# Execute query |
643 | 643 |
return $self->execute($sql, $param, table => $table, %args); |
644 | 644 |
} |
645 | 645 |
|
646 |
-sub insert_param { |
|
646 |
+sub values_clause { |
|
647 | 647 |
my ($self, $param, $opts) = @_; |
648 | 648 |
|
649 | 649 |
my $wrap = $opts->{wrap} || {}; |
... | ... |
@@ -1138,7 +1138,7 @@ sub update { |
1138 | 1138 |
} |
1139 | 1139 |
|
1140 | 1140 |
# Update clause |
1141 |
- my $update_clause = $self->update_param($param, {wrap => $wrap}); |
|
1141 |
+ my $assign_clause = $self->assign_clause($param, {wrap => $wrap}); |
|
1142 | 1142 |
|
1143 | 1143 |
# Where |
1144 | 1144 |
$where = $self->_create_param_from_id($id, $primary_key) if defined $id; |
... | ... |
@@ -1167,7 +1167,7 @@ sub update { |
1167 | 1167 |
my $sql; |
1168 | 1168 |
$sql .= "update "; |
1169 | 1169 |
$sql .= "$prefix " if defined $prefix; |
1170 |
- $sql .= $self->_q($table) . " $update_clause $where_clause "; |
|
1170 |
+ $sql .= $self->_q($table) . " set $assign_clause $where_clause "; |
|
1171 | 1171 |
$sql .= $append if defined $append; |
1172 | 1172 |
|
1173 | 1173 |
# Execute query |
... | ... |
@@ -1176,16 +1176,6 @@ sub update { |
1176 | 1176 |
|
1177 | 1177 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
1178 | 1178 |
|
1179 |
-sub update_param { |
|
1180 |
- my ($self, $param, $opts) = @_; |
|
1181 |
- |
|
1182 |
- # Create update parameter tag |
|
1183 |
- my $tag = $self->assign_param($param, $opts); |
|
1184 |
- $tag = "set $tag" unless $opts->{no_set}; |
|
1185 |
- |
|
1186 |
- return $tag; |
|
1187 |
-} |
|
1188 |
- |
|
1189 | 1179 |
sub update_timestamp { |
1190 | 1180 |
my $self = shift; |
1191 | 1181 |
|
... | ... |
@@ -1452,7 +1442,7 @@ sub _push_join { |
1452 | 1442 |
|
1453 | 1443 |
my @j_clauses = reverse split /\s(and|on)\s/, $j_clause; |
1454 | 1444 |
my $c = $self->safety_character; |
1455 |
- my $join_re = qr/(?:^|\s)($c+)\.$c+[^$c]+($c+)\.$c+/; |
|
1445 |
+ my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm; |
|
1456 | 1446 |
for my $clause (@j_clauses) { |
1457 | 1447 |
if ($clause =~ $join_re) { |
1458 | 1448 |
$table1 = $1; |
... | ... |
@@ -1663,6 +1653,32 @@ sub _apply_filter { |
1663 | 1653 |
return $self; |
1664 | 1654 |
} |
1665 | 1655 |
|
1656 |
+# DEPRECATED! |
|
1657 |
+has 'data_source'; |
|
1658 |
+has dbi_options => sub { {} }; |
|
1659 |
+has filter_check => 1; |
|
1660 |
+has 'reserved_word_quote'; |
|
1661 |
+ |
|
1662 |
+# DEPRECATED! |
|
1663 |
+sub assign_param { |
|
1664 |
+ my $self = shift; |
|
1665 |
+ warn "assing_param is DEPRECATED! use assign_clause instead"; |
|
1666 |
+ return $self->assign_clause(@_); |
|
1667 |
+} |
|
1668 |
+ |
|
1669 |
+# DEPRECATED |
|
1670 |
+sub update_param { |
|
1671 |
+ my ($self, $param, $opts) = @_; |
|
1672 |
+ |
|
1673 |
+ warn "update_param is DEPRECATED! use assing_clause instead."; |
|
1674 |
+ |
|
1675 |
+ # Create update parameter tag |
|
1676 |
+ my $tag = $self->assign_clause($param, $opts); |
|
1677 |
+ $tag = "set $tag" unless $opts->{no_set}; |
|
1678 |
+ |
|
1679 |
+ return $tag; |
|
1680 |
+} |
|
1681 |
+ |
|
1666 | 1682 |
# DEPRECATED! |
1667 | 1683 |
sub create_query { |
1668 | 1684 |
warn "create_query is DEPRECATED! use query option of each method"; |
... | ... |
@@ -1813,12 +1829,6 @@ sub register_tag_processor { |
1813 | 1829 |
return $self; |
1814 | 1830 |
} |
1815 | 1831 |
|
1816 |
-# DEPRECATED! |
|
1817 |
-has 'data_source'; |
|
1818 |
-has dbi_options => sub { {} }; |
|
1819 |
-has filter_check => 1; |
|
1820 |
-has 'reserved_word_quote'; |
|
1821 |
- |
|
1822 | 1832 |
# DEPRECATED! |
1823 | 1833 |
sub default_bind_filter { |
1824 | 1834 |
my $self = shift; |
... | ... |
@@ -1868,6 +1878,13 @@ sub default_fetch_filter { |
1868 | 1878 |
return $self->{default_in_filter}; |
1869 | 1879 |
} |
1870 | 1880 |
|
1881 |
+# DEPRECATED! |
|
1882 |
+sub insert_param { |
|
1883 |
+ my $self = shift; |
|
1884 |
+ warn "insert_param is DEPRECATED! use values_clause instead"; |
|
1885 |
+ return $self->values_clause(@_); |
|
1886 |
+} |
|
1887 |
+ |
|
1871 | 1888 |
# DEPRECATED! |
1872 | 1889 |
sub insert_param_tag { |
1873 | 1890 |
warn "insert_param_tag is DEPRECATED! " . |
... | ... |
@@ -2253,15 +2270,17 @@ in C<type rule>'s C<from1> and C<from2> section. |
2253 | 2270 |
Get available type names. You can use these type names in |
2254 | 2271 |
C<type_rule>'s C<into1> and C<into2> section. |
2255 | 2272 |
|
2256 |
-=head2 C<assign_param> |
|
2273 |
+=head2 C<assign_clause> |
|
2257 | 2274 |
|
2258 |
- my $assign_param = $dbi->assign_param({title => 'a', age => 2}); |
|
2275 |
+ my $assign_clause = $dbi->assign_clause({title => 'a', age => 2}); |
|
2259 | 2276 |
|
2260 |
-Create assign parameter. |
|
2277 |
+Create assign clause |
|
2261 | 2278 |
|
2262 | 2279 |
title = :title, author = :author |
2263 | 2280 |
|
2264 |
-This is equal to C<update_param> exept that set is not added. |
|
2281 |
+This is used to create update clause. |
|
2282 |
+ |
|
2283 |
+ "update book set " . $dbi->assign_clause({title => 'a', age => 2}); |
|
2265 | 2284 |
|
2266 | 2285 |
=head2 C<column> |
2267 | 2286 |
|
... | ... |
@@ -2812,11 +2831,11 @@ is executed, the following SQL is executed. |
2812 | 2831 |
|
2813 | 2832 |
=over 4 |
2814 | 2833 |
|
2815 |
-=head2 C<insert_param> |
|
2834 |
+=head2 C<values_clause> |
|
2816 | 2835 |
|
2817 |
- my $insert_param = $dbi->insert_param({title => 'a', age => 2}); |
|
2836 |
+ my $values_clause = $dbi->values_clause({title => 'a', age => 2}); |
|
2818 | 2837 |
|
2819 |
-Create insert parameters. |
|
2838 |
+Create values clause. |
|
2820 | 2839 |
|
2821 | 2840 |
(title, author) values (title = :title, age = :age); |
2822 | 2841 |
|
... | ... |
@@ -3477,6 +3496,9 @@ L<DBIx::Custom> |
3477 | 3496 |
cache_method # will be removed at 2017/1/1 |
3478 | 3497 |
|
3479 | 3498 |
# Methods |
3499 |
+ assign_param # will be removed at 2017/1/1 |
|
3500 |
+ update_param # will be removed at 2017/1/1 |
|
3501 |
+ insert_param # will be removed at 2017/1/1 |
|
3480 | 3502 |
create_query # will be removed at 2017/1/1 |
3481 | 3503 |
apply_filter # will be removed at 2017/1/1 |
3482 | 3504 |
select_at # will be removed at 2017/1/1 |
... | ... |
@@ -3561,8 +3583,6 @@ I extend one year each time he tell me it. |
3561 | 3583 |
|
3562 | 3584 |
EXPERIMENTAL functionality will be changed without warnings. |
3563 | 3585 |
|
3564 |
-This policy was changed at 2011/6/28 |
|
3565 |
- |
|
3566 | 3586 |
=head1 BUGS |
3567 | 3587 |
|
3568 | 3588 |
Please tell me bugs if found. |
... | ... |
@@ -13,7 +13,7 @@ plan skip_all => $ENV{DBIX_CUSTOM_SKIP_MESSAGE} || 'common.t is always skipped' |
13 | 13 |
|
14 | 14 |
plan 'no_plan'; |
15 | 15 |
|
16 |
-$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/}; |
|
16 |
+#$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/}; |
|
17 | 17 |
sub test { print "# $_[0]\n" } |
18 | 18 |
|
19 | 19 |
# Constant |
... | ... |
@@ -78,6 +78,8 @@ my $join; |
78 | 78 |
my $binary; |
79 | 79 |
my $user_table_info; |
80 | 80 |
my $user_column_info; |
81 |
+my $values_clause; |
|
82 |
+my $assign_clause; |
|
81 | 83 |
|
82 | 84 |
require MyDBI1; |
83 | 85 |
{ |
... | ... |
@@ -2004,14 +2006,14 @@ $result = $model->select( |
2004 | 2006 |
is_deeply($result->one, |
2005 | 2007 |
{$key1 => 1, $key2 => 2, "${table2}__$key1" => 1, "${table2}__$key3" => 3}); |
2006 | 2008 |
|
2007 |
-test 'insert_param'; |
|
2009 |
+test 'values_clause'; |
|
2008 | 2010 |
$dbi = DBIx::Custom->connect; |
2009 | 2011 |
eval { $dbi->execute("drop table $table1") }; |
2010 | 2012 |
$dbi->execute($create_table1_2); |
2011 | 2013 |
$param = {$key1 => 1, $key2 => 2}; |
2012 |
-$insert_param = $dbi->insert_param($param); |
|
2014 |
+$values_clause = $dbi->values_clause($param); |
|
2013 | 2015 |
$sql = <<"EOS"; |
2014 |
-insert into $table1 $insert_param |
|
2016 |
+insert into $table1 $values_clause |
|
2015 | 2017 |
EOS |
2016 | 2018 |
$dbi->execute($sql, param => $param, table => $table1); |
2017 | 2019 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
... | ... |
@@ -2021,15 +2023,15 @@ $dbi = DBIx::Custom->connect; |
2021 | 2023 |
eval { $dbi->execute("drop table $table1") }; |
2022 | 2024 |
$dbi->execute($create_table1_2); |
2023 | 2025 |
$param = {$key1 => 1, $key2 => 2}; |
2024 |
-$insert_param = $dbi->insert_param($param); |
|
2026 |
+$values_clause = $dbi->insert_param($param); |
|
2025 | 2027 |
$sql = <<"EOS"; |
2026 |
-insert into $table1 $insert_param |
|
2028 |
+insert into $table1 $values_clause |
|
2027 | 2029 |
EOS |
2028 | 2030 |
$dbi->execute($sql, param => $param, table => $table1); |
2029 | 2031 |
is($dbi->select(table => $table1)->one->{$key1}, 1); |
2030 | 2032 |
is($dbi->select(table => $table1)->one->{$key2}, 2); |
2031 | 2033 |
|
2032 |
-eval { $dbi->insert_param({";" => 1}) }; |
|
2034 |
+eval { $dbi->values_clause({";" => 1}) }; |
|
2033 | 2035 |
like($@, qr/not safety/); |
2034 | 2036 |
|
2035 | 2037 |
test 'mycolumn'; |
... | ... |
@@ -3208,7 +3210,7 @@ $model = $dbi->create_model( |
3208 | 3210 |
$model->method(foo => sub { shift->select(@_) }); |
3209 | 3211 |
is_deeply($model->foo->one, {$key1 => 1, $key3 => 3}); |
3210 | 3212 |
|
3211 |
-test 'update_param'; |
|
3213 |
+test 'assign_clause'; |
|
3212 | 3214 |
$dbi = DBIx::Custom->connect; |
3213 | 3215 |
eval { $dbi->execute("drop table $table1") }; |
3214 | 3216 |
$dbi->execute($create_table1_2); |
... | ... |
@@ -3216,9 +3218,9 @@ $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $ke |
3216 | 3218 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
3217 | 3219 |
|
3218 | 3220 |
$param = {$key2 => 11}; |
3219 |
-$update_param = $dbi->update_param($param); |
|
3221 |
+$assign_clause = $dbi->assign_clause($param); |
|
3220 | 3222 |
$sql = <<"EOS"; |
3221 |
-update $table1 $update_param |
|
3223 |
+update $table1 set $assign_clause |
|
3222 | 3224 |
where $key1 = 1 |
3223 | 3225 |
EOS |
3224 | 3226 |
$dbi->execute($sql, param => $param); |
... | ... |
@@ -3236,9 +3238,9 @@ $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $ke |
3236 | 3238 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
3237 | 3239 |
|
3238 | 3240 |
$param = {$key2 => 11, $key3 => 33}; |
3239 |
-$update_param = $dbi->update_param($param); |
|
3241 |
+$assign_clause = $dbi->assign_clause($param); |
|
3240 | 3242 |
$sql = <<"EOS"; |
3241 |
-update $table1 $update_param |
|
3243 |
+update $table1 set $assign_clause |
|
3242 | 3244 |
where $key1 = 1 |
3243 | 3245 |
EOS |
3244 | 3246 |
$dbi->execute($sql, param => $param); |
... | ... |
@@ -3255,9 +3257,9 @@ $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $ke |
3255 | 3257 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
3256 | 3258 |
|
3257 | 3259 |
$param = {$key2 => 11, $key3 => 33}; |
3258 |
-$update_param = $dbi->update_param($param, {no_set => 1}); |
|
3260 |
+$assign_clause = $dbi->update_param($param, {no_set => 1}); |
|
3259 | 3261 |
$sql = <<"EOS"; |
3260 |
-update $table1 set $update_param |
|
3262 |
+update $table1 set $assign_clause |
|
3261 | 3263 |
where $key1 = 1 |
3262 | 3264 |
EOS |
3263 | 3265 |
$dbi->execute($sql, param => $param); |
... | ... |
@@ -3268,11 +3270,9 @@ is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 33, $key4 => 4, $key5 => 5} |
3268 | 3270 |
"update param no_set"); |
3269 | 3271 |
|
3270 | 3272 |
|
3271 |
-eval { $dbi->update_param({";" => 1}) }; |
|
3273 |
+eval { $dbi->assign_clause({";" => 1}) }; |
|
3272 | 3274 |
like($@, qr/not safety/); |
3273 | 3275 |
|
3274 |
- |
|
3275 |
-test 'update_param'; |
|
3276 | 3276 |
$dbi = DBIx::Custom->connect; |
3277 | 3277 |
eval { $dbi->execute("drop table $table1") }; |
3278 | 3278 |
$dbi->execute($create_table1_2); |
... | ... |
@@ -3280,9 +3280,22 @@ $dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2, $key3 => 3, $ke |
3280 | 3280 |
$dbi->insert(table => $table1, param => {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}); |
3281 | 3281 |
|
3282 | 3282 |
$param = {$key2 => 11}; |
3283 |
-$update_param = $dbi->assign_param($param); |
|
3283 |
+$assign_clause = $dbi->assign_param($param); |
|
3284 |
+$sql = <<"EOS"; |
|
3285 |
+update $table1 set $assign_clause |
|
3286 |
+where $key1 = 1 |
|
3287 |
+EOS |
|
3288 |
+$dbi->execute($sql, param => $param, table => $table1); |
|
3289 |
+$result = $dbi->execute("select * from $table1 order by $key1"); |
|
3290 |
+$rows = $result->all; |
|
3291 |
+is_deeply($rows, [{$key1 => 1, $key2 => 11, $key3 => 3, $key4 => 4, $key5 => 5}, |
|
3292 |
+ {$key1 => 6, $key2 => 7, $key3 => 8, $key4 => 9, $key5 => 10}], |
|
3293 |
+ "basic"); |
|
3294 |
+ |
|
3295 |
+$param = {$key2 => 11}; |
|
3296 |
+$assign_clause = $dbi->assign_clause($param); |
|
3284 | 3297 |
$sql = <<"EOS"; |
3285 |
-update $table1 set $update_param |
|
3298 |
+update $table1 set $assign_clause |
|
3286 | 3299 |
where $key1 = 1 |
3287 | 3300 |
EOS |
3288 | 3301 |
$dbi->execute($sql, param => $param, table => $table1); |
... | ... |
@@ -282,7 +282,24 @@ $result = $dbi->select( |
282 | 282 |
table => 'table1', |
283 | 283 |
column => [{table2 => ['key3']}], |
284 | 284 |
join => [ |
285 |
- "left outer join table2 on coalesce(table2.key3, 0) > '3' and table1.key1 = table2.key1" |
|
285 |
+ "left outer join table2 on coalesce(table1.key1, 0) = coalesce(table2.key1, 0) and table2.key3 > '3'" |
|
286 | 286 |
] |
287 | 287 |
); |
288 |
-is_deeply($result->all, [{"table2.key3" => 4}]); |
|
288 |
+is_deeply($result->all, [{"table2.key3" => 4}]); |
|
289 |
+ |
|
290 |
+$dbi = DBIx::Custom->connect; |
|
291 |
+eval { $dbi->execute("drop table table1") }; |
|
292 |
+eval { $dbi->execute("drop table table2") }; |
|
293 |
+$dbi->execute($create_table1); |
|
294 |
+$dbi->execute("create table table2 (key1, key3)"); |
|
295 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
296 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4}); |
|
297 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 1}); |
|
298 |
+$result = $dbi->select( |
|
299 |
+ table => 'table1', |
|
300 |
+ column => [{table2 => ['key3']}], |
|
301 |
+ join => [ |
|
302 |
+ "left outer join table2 on table2.key3 > '3' and coalesce(table1.key1, 0) = coalesce(table2.key1, 0)" |
|
303 |
+ ] |
|
304 |
+); |
|
305 |
+is_deeply($result->all, [{"table2.key3" => 4}]); |