Showing 3 changed files with 58 additions and 16 deletions
+2
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.1681
2
+    - added EXPERIMENTAL assign_tag() method
1 3
 0.1680
2 4
     - DEPRECATED select() param option, this is renamed to where_param
3 5
     - added select(), update(), and delete() where_param option
+34 -15
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1680';
3
+our $VERSION = '0.1681';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -151,6 +151,26 @@ sub apply_filter {
151 151
     return $self;
152 152
 }
153 153
 
154
+
155
+sub assign_tag {
156
+    my ($self, $param) = @_;
157
+    
158
+    # Create set tag
159
+    my @params;
160
+    my $safety = $self->safety_character;
161
+    my $q = $self->reserved_word_quote;
162
+    foreach my $column (keys %$param) {
163
+        croak qq{"$column" is not safety column name } . _subname
164
+          unless $column =~ /^[$safety\.]+$/;
165
+        my $column = "$q$column$q";
166
+        $column =~ s/\./$q.$q/;
167
+        push @params, "$column = {? $column}";
168
+    }
169
+    my $tag = join(', ', @params);
170
+    
171
+    return $tag;
172
+}
173
+
154 174
 sub column {
155 175
     my ($self, $table, $columns) = @_;
156 176
     
... ...
@@ -1084,20 +1104,9 @@ sub update_param_tag {
1084 1104
     my ($self, $param, $opt) = @_;
1085 1105
     
1086 1106
     # Create update parameter tag
1087
-    my @params;
1088
-    my $safety = $self->safety_character;
1089
-    my $q = $self->reserved_word_quote;
1090
-    foreach my $column (keys %$param) {
1091
-        croak qq{"$column" is not safety column name } . _subname
1092
-          unless $column =~ /^[$safety\.]+$/;
1093
-        my $column = "$q$column$q";
1094
-        $column =~ s/\./$q.$q/;
1095
-        push @params, "$column = {? $column}";
1096
-    }
1097
-    my $tag;
1098
-    $tag .= 'set ' unless $opt->{no_set};
1099
-    $tag .= join(', ', @params);
1100
-    
1107
+    my $tag = $self->assign_tag($param);
1108
+    $tag = "set $tag" unless $opt->{no_set};
1109
+
1101 1110
     return $tag;
1102 1111
 }
1103 1112
 
... ...
@@ -1732,6 +1741,16 @@ You can set multiple filters at once.
1732 1741
         }
1733 1742
     );
1734 1743
 
1744
+=head2 C<assign_tag> EXPERIMENTAL
1745
+
1746
+    my $assign_tag = $dbi->assign_tag({title => 'a', age => 2});
1747
+
1748
+Create assign tag.
1749
+
1750
+    title = {? title}, author = {? author}
1751
+
1752
+This is equal to C<update_param_tag> exept that set is not added.
1753
+
1735 1754
 =head2 C<connect>
1736 1755
 
1737 1756
     my $dbi = DBIx::Custom->connect(
+22 -1
t/dbix-custom-core-sqlite.t
... ...
@@ -1792,7 +1792,7 @@ $result = $model->select(
1792 1792
 is_deeply($result->fetch_hash_first,
1793 1793
           {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
1794 1794
 
1795
-test 'update_param';
1795
+test 'update_param_tag';
1796 1796
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1797 1797
 $dbi->execute($CREATE_TABLE->{1});
1798 1798
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
... ...
@@ -1853,6 +1853,27 @@ eval { $dbi->update_param_tag({";" => 1}) };
1853 1853
 like($@, qr/not safety/);
1854 1854
 
1855 1855
 
1856
+test 'set_tag';
1857
+test 'update_param_tag';
1858
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1859
+$dbi->execute($CREATE_TABLE->{1});
1860
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
1861
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
1862
+
1863
+$param = {key2 => 11};
1864
+$update_param = $dbi->assign_tag($param);
1865
+$sql = <<"EOS";
1866
+update {table table1} set $update_param
1867
+where key1 = 1
1868
+EOS
1869
+$dbi->execute($sql, param => $param);
1870
+$result = $dbi->execute($SELECT_SOURCES->{0});
1871
+$rows   = $result->fetch_hash_all;
1872
+is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
1873
+                  {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
1874
+                  "basic");
1875
+
1876
+
1856 1877
 test 'insert_param';
1857 1878
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1858 1879
 $dbi->execute($CREATE_TABLE->{1});