... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1736 |
|
2 |
+ - micro optimization |
|
1 | 3 |
0.1735 |
2 | 4 |
- added EXPERIMENTAL reuse_query option to execute method |
3 | 5 |
0.1734 |
... | ... |
@@ -123,27 +123,28 @@ sub assign_clause { |
123 | 123 |
my ($self, $param, $opts) = @_; |
124 | 124 |
|
125 | 125 |
my $wrap = $opts->{wrap} || {}; |
126 |
- |
|
126 |
+ my $safety = $self->{safety_character} || $self->safety_character; |
|
127 | 127 |
my $qp = $self->_q(''); |
128 | 128 |
my $q = substr($qp, 0, 1) || ''; |
129 | 129 |
my $p = substr($qp, 1, 1) || ''; |
130 | 130 |
|
131 |
- # Create set tag |
|
132 |
- my @params; |
|
133 |
- my $safety = $self->safety_character; |
|
134 |
- for my $column (sort keys %$param) { |
|
135 |
- croak qq{"$column" is not safety column name } . _subname |
|
136 |
- unless $column =~ /^[$safety\.]+$/; |
|
137 |
- my $column_quote = "$q$column$p"; |
|
138 |
- $column_quote =~ s/\./$p.$q/; |
|
139 |
- my $func = $wrap->{$column} || sub { $_[0] }; |
|
140 |
- push @params, |
|
141 |
- ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}} |
|
142 |
- : "$column_quote = " . $func->(":$column"); |
|
143 |
- } |
|
144 |
- my $tag = join(', ', @params); |
|
131 |
+ # Check unsafety keys |
|
132 |
+ unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) { |
|
133 |
+ for my $column (keys %$param) { |
|
134 |
+ croak qq{"$column" is not safety column name } . _subname |
|
135 |
+ unless $column =~ /^[$safety\.]+$/; |
|
136 |
+ } |
|
137 |
+ } |
|
145 | 138 |
|
146 |
- return $tag; |
|
139 |
+ # Create set tag |
|
140 |
+ join( |
|
141 |
+ ', ', |
|
142 |
+ map { |
|
143 |
+ ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}} |
|
144 |
+ : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_") |
|
145 |
+ : "$q$_$p = :$_"; |
|
146 |
+ } sort keys %$param |
|
147 |
+ ); |
|
147 | 148 |
} |
148 | 149 |
|
149 | 150 |
sub column { |
... | ... |
@@ -1089,8 +1090,6 @@ sub values_clause { |
1089 | 1090 |
|
1090 | 1091 |
# Create insert parameter tag |
1091 | 1092 |
my $safety = $self->{safety_character} || $self->safety_character; |
1092 |
- my @columns; |
|
1093 |
- my @placeholders; |
|
1094 | 1093 |
my $qp = $self->_q(''); |
1095 | 1094 |
my $q = substr($qp, 0, 1) || ''; |
1096 | 1095 |
my $p = substr($qp, 1, 1) || ''; |
... | ... |
@@ -1102,17 +1101,23 @@ sub values_clause { |
1102 | 1101 |
unless $column =~ /^[$safety\.]+$/; |
1103 | 1102 |
} |
1104 | 1103 |
} |
1105 |
- |
|
1106 |
- for my $column (sort keys %$param) { |
|
1107 |
- push @columns, "$q$column$p"; |
|
1108 |
- push @placeholders, |
|
1109 |
- ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}} : |
|
1110 |
- $wrap->{$column} ? $wrap->{$column}->(":$column") : |
|
1111 |
- ":$column" |
|
1112 |
- } |
|
1113 | 1104 |
|
1114 |
- '(' . join(', ', @columns) . ') ' . 'values ' . |
|
1115 |
- '(' . join(', ', @placeholders) . ')' |
|
1105 |
+ # Assign clause(performance is important) |
|
1106 |
+ '(' . |
|
1107 |
+ join( |
|
1108 |
+ ', ', |
|
1109 |
+ map { "$q$_$p" } sort keys %$param |
|
1110 |
+ ) . |
|
1111 |
+ ') values (' . |
|
1112 |
+ join( |
|
1113 |
+ ', ', |
|
1114 |
+ map { |
|
1115 |
+ ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} : |
|
1116 |
+ $wrap->{$_} ? $wrap->{$_}->(":$_") : |
|
1117 |
+ ":$_"; |
|
1118 |
+ } sort keys %$param |
|
1119 |
+ ) . |
|
1120 |
+ ')' |
|
1116 | 1121 |
} |
1117 | 1122 |
|
1118 | 1123 |
sub where { DBIx::Custom::Where->new(dbi => shift, @_) } |
... | ... |
@@ -1658,7 +1663,7 @@ sub assign_param { |
1658 | 1663 |
sub update_param { |
1659 | 1664 |
my ($self, $param, $opts) = @_; |
1660 | 1665 |
|
1661 |
- warn "update_param is DEPRECATED! use assing_clause instead."; |
|
1666 |
+ warn "update_param is DEPRECATED! use assign_clause instead."; |
|
1662 | 1667 |
|
1663 | 1668 |
# Create update parameter tag |
1664 | 1669 |
my $tag = $self->assign_clause($param, $opts); |