Showing 4 changed files with 345 additions and 370 deletions
+2
Changes
... ...
@@ -1,4 +1,6 @@
1 1
 0.1696
2
+    - added new argument format update, delete, select method where option
3
+    - create_query is DEPRECATED! use query option of each method instead.
2 4
     - added EXPERIMENTAL insert, update, and select method prefix option
3 5
     - fixed small insert, update, delete, select method id option bug
4 6
 0.1695
+257 -324
lib/DBIx/Custom.pm
... ...
@@ -133,69 +133,6 @@ sub connect {
133 133
     return $self;
134 134
 }
135 135
 
136
-sub create_query {
137
-    my ($self, $source) = @_;
138
-    
139
-    # Cache
140
-    my $cache = $self->cache;
141
-    
142
-    # Query
143
-    my $query;
144
-    
145
-    # Get cached query
146
-    if ($cache) {
147
-        
148
-        # Get query
149
-        my $q = $self->cache_method->($self, $source);
150
-        
151
-        # Create query
152
-        if ($q) {
153
-            $query = DBIx::Custom::Query->new($q);
154
-            $query->filters($self->filters);
155
-        }
156
-    }
157
-    
158
-    # Create query
159
-    unless ($query) {
160
-
161
-        # Create query
162
-        my $builder = $self->query_builder;
163
-        $query = $builder->build_query($source);
164
-
165
-        # Remove reserved word quote
166
-        if (my $q = $self->_quote) {
167
-            $_ =~ s/$q//g for @{$query->columns}
168
-        }
169
-
170
-        # Save query to cache
171
-        $self->cache_method->(
172
-            $self, $source,
173
-            {
174
-                sql     => $query->sql, 
175
-                columns => $query->columns,
176
-                tables  => $query->tables
177
-            }
178
-        ) if $cache;
179
-    }
180
-    
181
-    # Prepare statement handle
182
-    my $sth;
183
-    eval { $sth = $self->dbh->prepare($query->{sql})};
184
-    
185
-    if ($@) {
186
-        $self->_croak($@, qq{. Following SQL is executed.\n}
187
-                        . qq{$query->{sql}\n} . _subname);
188
-    }
189
-    
190
-    # Set statement handle
191
-    $query->sth($sth);
192
-    
193
-    # Set filters
194
-    $query->filters($self->filters);
195
-    
196
-    return $query;
197
-}
198
-
199 136
 sub dbh {
200 137
     my $self = shift;
201 138
     
... ...
@@ -261,7 +198,11 @@ sub delete {
261 198
     # Where
262 199
     $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
263 200
     my $where_clause = '';
264
-    if (ref $where) {
201
+    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
202
+        $where_clause = "where " . $where->[0];
203
+        $where_param = $where->[1];
204
+    }
205
+    elsif (ref $where) {
265 206
         $where = $self->_where_to_obj($where);
266 207
         $where_param = keys %$where_param
267 208
                      ? $self->merge_param($where_param, $where->param)
... ...
@@ -284,12 +225,7 @@ sub delete {
284 225
     my $sql = join(' ', @sql);
285 226
     
286 227
     # Execute query
287
-    return $self->execute(
288
-        $sql,
289
-        param => $where_param,
290
-        table => $table,
291
-        %args
292
-    );
228
+    return $self->execute($sql, $where_param, table => $table, %args);
293 229
 }
294 230
 
295 231
 sub delete_all { shift->delete(allow_delete_all => 1, @_) }
... ...
@@ -377,7 +313,7 @@ sub execute {
377 313
     }
378 314
     
379 315
     # Create query
380
-    $query = $self->create_query($query) unless ref $query;
316
+    $query = $self->_create_query($query) unless ref $query;
381 317
     return $query if $query_return;
382 318
     $filter ||= $query->filter;
383 319
     
... ...
@@ -565,12 +501,7 @@ sub insert {
565 501
     my $sql = join (' ', @sql);
566 502
     
567 503
     # Execute query
568
-    return $self->execute(
569
-        $sql,
570
-        param => $param,
571
-        table => $table,
572
-        %args
573
-    );
504
+    return $self->execute($sql, $param, table => $table, %args);
574 505
 }
575 506
 
576 507
 sub insert_param {
... ...
@@ -857,7 +788,11 @@ sub select {
857 788
     # Where
858 789
     my $where_clause = '';
859 790
     $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
860
-    if (ref $where) {
791
+    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
792
+        $where_clause = "where " . $where->[0];
793
+        $where_param = $where->[1];
794
+    }
795
+    elsif (ref $where) {
861 796
         $where = $self->_where_to_obj($where);
862 797
         $where_param = keys %$where_param
863 798
                      ? $self->merge_param($where_param, $where->param)
... ...
@@ -895,12 +830,7 @@ sub select {
895 830
     my $sql = join (' ', @sql);
896 831
     
897 832
     # Execute query
898
-    my $result = $self->execute(
899
-        $sql,
900
-        param => $where_param, 
901
-        table => $tables,
902
-        %args
903
-    );
833
+    my $result = $self->execute($sql, $where_param, table => $tables, %args);
904 834
     
905 835
     return $result;
906 836
 }
... ...
@@ -1066,7 +996,11 @@ sub update {
1066 996
     # Where
1067 997
     $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
1068 998
     my $where_clause = '';
1069
-    if (ref $where) {
999
+    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1000
+        $where_clause = "where " . $where->[0];
1001
+        $where_param = $where->[1];
1002
+    }
1003
+    elsif (ref $where) {
1070 1004
         $where = $self->_where_to_obj($where);
1071 1005
         $where_param = keys %$where_param
1072 1006
                      ? $self->merge_param($where_param, $where->param)
... ...
@@ -1094,14 +1028,7 @@ sub update {
1094 1028
     my $sql = join(' ', @sql);
1095 1029
     
1096 1030
     # Execute query
1097
-    my $ret_val = $self->execute(
1098
-        $sql,
1099
-        param  => $param, 
1100
-        table => $table,
1101
-        %args
1102
-    );
1103
-    
1104
-    return $ret_val;
1031
+    return $self->execute($sql, $param, table => $table, %args);
1105 1032
 }
1106 1033
 
1107 1034
 sub update_all { shift->update(allow_update_all => 1, @_) };
... ...
@@ -1128,73 +1055,68 @@ sub where {
1128 1055
     );
1129 1056
 }
1130 1057
 
1131
-sub _apply_filter {
1132
-    my ($self, $table, @cinfos) = @_;
1133
-
1134
-    # Initialize filters
1135
-    $self->{filter} ||= {};
1136
-    $self->{filter}{out} ||= {};
1137
-    $self->{filter}{in} ||= {};
1138
-    $self->{filter}{end} ||= {};
1058
+sub _create_query {
1139 1059
     
1140
-    # Usage
1141
-    my $usage = "Usage: \$dbi->apply_filter(" .
1142
-                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1143
-                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1060
+    my ($self, $source) = @_;
1144 1061
     
1145
-    # Apply filter
1146
-    for (my $i = 0; $i < @cinfos; $i += 2) {
1062
+    # Cache
1063
+    my $cache = $self->cache;
1064
+    
1065
+    # Query
1066
+    my $query;
1067
+    
1068
+    # Get cached query
1069
+    if ($cache) {
1147 1070
         
1148
-        # Column
1149
-        my $column = $cinfos[$i];
1150
-        if (ref $column eq 'ARRAY') {
1151
-            foreach my $c (@$column) {
1152
-                push @cinfos, $c, $cinfos[$i + 1];
1153
-            }
1154
-            next;
1155
-        }
1071
+        # Get query
1072
+        my $q = $self->cache_method->($self, $source);
1156 1073
         
1157
-        # Filter infomation
1158
-        my $finfo = $cinfos[$i + 1] || {};
1159
-        croak "$usage (table: $table) " . _subname
1160
-          unless  ref $finfo eq 'HASH';
1161
-        foreach my $ftype (keys %$finfo) {
1162
-            croak "$usage (table: $table) " . _subname
1163
-              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1074
+        # Create query
1075
+        if ($q) {
1076
+            $query = DBIx::Custom::Query->new($q);
1077
+            $query->filters($self->filters);
1164 1078
         }
1165
-        
1166
-        # Set filters
1167
-        foreach my $way (qw/in out end/) {
1168
-        
1169
-            # Filter
1170
-            my $filter = $finfo->{$way};
1171
-            
1172
-            # Filter state
1173
-            my $state = !exists $finfo->{$way} ? 'not_exists'
1174
-                      : !defined $filter        ? 'not_defined'
1175
-                      : ref $filter eq 'CODE'   ? 'code'
1176
-                      : 'name';
1177
-            
1178
-            # Filter is not exists
1179
-            next if $state eq 'not_exists';
1180
-            
1181
-            # Check filter name
1182
-            croak qq{Filter "$filter" is not registered } . _subname
1183
-              if  $state eq 'name'
1184
-               && ! exists $self->filters->{$filter};
1185
-            
1186
-            # Set filter
1187
-            my $f = $state eq 'not_defined' ? undef
1188
-                  : $state eq 'code'        ? $filter
1189
-                  : $self->filters->{$filter};
1190
-            $self->{filter}{$way}{$table}{$column} = $f;
1191
-            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1192
-            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1193
-            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1079
+    }
1080
+    
1081
+    # Create query
1082
+    unless ($query) {
1083
+
1084
+        # Create query
1085
+        my $builder = $self->query_builder;
1086
+        $query = $builder->build_query($source);
1087
+
1088
+        # Remove reserved word quote
1089
+        if (my $q = $self->_quote) {
1090
+            $_ =~ s/$q//g for @{$query->columns}
1194 1091
         }
1092
+
1093
+        # Save query to cache
1094
+        $self->cache_method->(
1095
+            $self, $source,
1096
+            {
1097
+                sql     => $query->sql, 
1098
+                columns => $query->columns,
1099
+                tables  => $query->tables
1100
+            }
1101
+        ) if $cache;
1195 1102
     }
1196 1103
     
1197
-    return $self;
1104
+    # Prepare statement handle
1105
+    my $sth;
1106
+    eval { $sth = $self->dbh->prepare($query->{sql})};
1107
+    
1108
+    if ($@) {
1109
+        $self->_croak($@, qq{. Following SQL is executed.\n}
1110
+                        . qq{$query->{sql}\n} . _subname);
1111
+    }
1112
+    
1113
+    # Set statement handle
1114
+    $query->sth($sth);
1115
+    
1116
+    # Set filters
1117
+    $query->filters($self->filters);
1118
+    
1119
+    return $query;
1198 1120
 }
1199 1121
 
1200 1122
 sub _create_bind_values {
... ...
@@ -1432,11 +1354,8 @@ sub _where_to_obj {
1432 1354
         $obj = $where;
1433 1355
     }
1434 1356
     
1435
-    # Array(DEPRECATED!)
1357
+    # Array
1436 1358
     elsif (ref $where eq 'ARRAY') {
1437
-        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1438
-             "use \$dbi->select(where => \$dbi->where(clause => " .
1439
-             "CLAUSE, where_param => PARAMETER));";
1440 1359
         $obj = $self->where(
1441 1360
             clause => $where->[0],
1442 1361
             param  => $where->[1]
... ...
@@ -1452,6 +1371,82 @@ sub _where_to_obj {
1452 1371
     return $obj;
1453 1372
 }
1454 1373
 
1374
+# DEPRECATED!
1375
+sub _apply_filter {
1376
+    my ($self, $table, @cinfos) = @_;
1377
+
1378
+    # Initialize filters
1379
+    $self->{filter} ||= {};
1380
+    $self->{filter}{out} ||= {};
1381
+    $self->{filter}{in} ||= {};
1382
+    $self->{filter}{end} ||= {};
1383
+    
1384
+    # Usage
1385
+    my $usage = "Usage: \$dbi->apply_filter(" .
1386
+                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1387
+                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1388
+    
1389
+    # Apply filter
1390
+    for (my $i = 0; $i < @cinfos; $i += 2) {
1391
+        
1392
+        # Column
1393
+        my $column = $cinfos[$i];
1394
+        if (ref $column eq 'ARRAY') {
1395
+            foreach my $c (@$column) {
1396
+                push @cinfos, $c, $cinfos[$i + 1];
1397
+            }
1398
+            next;
1399
+        }
1400
+        
1401
+        # Filter infomation
1402
+        my $finfo = $cinfos[$i + 1] || {};
1403
+        croak "$usage (table: $table) " . _subname
1404
+          unless  ref $finfo eq 'HASH';
1405
+        foreach my $ftype (keys %$finfo) {
1406
+            croak "$usage (table: $table) " . _subname
1407
+              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1408
+        }
1409
+        
1410
+        # Set filters
1411
+        foreach my $way (qw/in out end/) {
1412
+        
1413
+            # Filter
1414
+            my $filter = $finfo->{$way};
1415
+            
1416
+            # Filter state
1417
+            my $state = !exists $finfo->{$way} ? 'not_exists'
1418
+                      : !defined $filter        ? 'not_defined'
1419
+                      : ref $filter eq 'CODE'   ? 'code'
1420
+                      : 'name';
1421
+            
1422
+            # Filter is not exists
1423
+            next if $state eq 'not_exists';
1424
+            
1425
+            # Check filter name
1426
+            croak qq{Filter "$filter" is not registered } . _subname
1427
+              if  $state eq 'name'
1428
+               && ! exists $self->filters->{$filter};
1429
+            
1430
+            # Set filter
1431
+            my $f = $state eq 'not_defined' ? undef
1432
+                  : $state eq 'code'        ? $filter
1433
+                  : $self->filters->{$filter};
1434
+            $self->{filter}{$way}{$table}{$column} = $f;
1435
+            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1436
+            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1437
+            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1438
+        }
1439
+    }
1440
+    
1441
+    return $self;
1442
+}
1443
+
1444
+# DEPRECATED!
1445
+sub create_query {
1446
+    warn "create_query is DEPRECATED! use query option of each method";
1447
+    shift->_create_query(@_);
1448
+}
1449
+
1455 1450
 # DEPRECATED!
1456 1451
 sub apply_filter {
1457 1452
     my $self = shift;
... ...
@@ -1711,30 +1706,18 @@ DBIx::Custom - Useful database access, respecting SQL!
1711 1706
     );
1712 1707
 
1713 1708
     # Insert 
1714
-    $dbi->insert(
1715
-        table  => 'book',
1716
-        param  => {title => 'Perl', author => 'Ken'}
1717
-    );
1709
+    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
1718 1710
     
1719 1711
     # Update 
1720
-    $dbi->update(
1721
-        table  => 'book', 
1722
-        param  => {title => 'Perl', author => 'Ken'}, 
1723
-        where  => {id => 5},
1724
-    );
1712
+    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1713
+      where  => {id => 5});
1725 1714
     
1726 1715
     # Delete
1727
-    $dbi->delete(
1728
-        table  => 'book',
1729
-        where  => {author => 'Ken'},
1730
-    );
1716
+    $dbi->delete(table  => 'book', where => {author => 'Ken'});
1731 1717
 
1732 1718
     # Select
1733
-    my $result = $dbi->select(
1734
-        table  => 'book',
1735
-        column => ['title', 'author'],
1736
-        where  => {author => 'Ken'},
1737
-    );
1719
+    my $result = $dbi->select(table  => 'book',
1720
+      column => ['title', 'author'], where  => {author => 'Ken'});
1738 1721
 
1739 1722
     # Select, more complex
1740 1723
     my $result = $dbi->select(
... ...
@@ -1761,7 +1744,7 @@ DBIx::Custom - Useful database access, respecting SQL!
1761 1744
     # Execute SQL with parameter.
1762 1745
     $dbi->execute(
1763 1746
         "select id from book where author = :author and title like :title",
1764
-        param  => {author => 'ken', title => '%Perl%'}
1747
+        {author => 'ken', title => '%Perl%'}
1765 1748
     );
1766 1749
     
1767 1750
 =head1 DESCRIPTIONS
... ...
@@ -1770,34 +1753,20 @@ L<DBIx::Custom> is L<DBI> wrapper module.
1770 1753
 
1771 1754
 =head1 FEATURES
1772 1755
 
1773
-=over 4
1774
-
1775
-=item *
1776
-
1777
-There are many basic methods to execute various queries.
1778
-C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1779
-C<delete_all()>, C<select()>,
1780
-C<execute()>
1781
-
1782
-=item *
1783
-
1784
-Filter when data is send or receive.
1756
+L<DBIx::Custom> is the wrapper class of L<DBI> to execute SQL easily.
1757
+This module have the following features.
1785 1758
 
1786
-=item *
1787
-
1788
-Data filtering system
1789
-
1790
-=item *
1759
+=over 4
1791 1760
 
1792
-Model support.
1761
+=item * Execute INSERT, UPDATE, DELETE, SELECT statement easily
1793 1762
 
1794
-=item *
1763
+=item * You can specify bind values by hash reference
1795 1764
 
1796
-Generate where clause dinamically.
1765
+=item * Filtering by data type. and you can set filter to any column
1797 1766
 
1798
-=item *
1767
+=item * Creating where clause flexibly
1799 1768
 
1800
-Generate join clause dinamically.
1769
+=item * Support model
1801 1770
 
1802 1771
 =back
1803 1772
 
... ...
@@ -1816,11 +1785,11 @@ L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
1816 1785
     my $connector = $dbi->connector;
1817 1786
     $dbi = $dbi->connector(DBIx::Connector->new(...));
1818 1787
 
1819
-Connection manager object. if connector is set, you can get C<dbh()>
1820
-from connection manager. conection manager object must have dbh() mehtod.
1788
+Connection manager object. if connector is set, you can get C<dbh>
1789
+through connection manager. conection manager object must have C<dbh> mehtod.
1821 1790
 
1822 1791
 This is L<DBIx::Connector> example. Please pass
1823
-C<default_dbi_option> to L<DBIx::Connector>.
1792
+C<default_dbi_option> to L<DBIx::Connector> C<new> method.
1824 1793
 
1825 1794
     my $connector = DBIx::Connector->new(
1826 1795
         "dbi:mysql:database=$DATABASE",
... ...
@@ -1829,21 +1798,21 @@ C<default_dbi_option> to L<DBIx::Connector>.
1829 1798
         DBIx::Custom->new->default_dbi_option
1830 1799
     );
1831 1800
     
1832
-    my $dbi = DBIx::Custom->new(connector => $connector);
1801
+    my $dbi = DBIx::Custom->connect(connector => $connector);
1833 1802
 
1834 1803
 =head2 C<dsn>
1835 1804
 
1836 1805
     my $dsn = $dbi->dsn;
1837 1806
     $dbi = $dbi->dsn("DBI:mysql:database=dbname");
1838 1807
 
1839
-Data source name, used when C<connect()> is executed.
1808
+Data source name, used when C<connect> method is executed.
1840 1809
 
1841 1810
 =head2 C<dbi_option>
1842 1811
 
1843 1812
     my $dbi_option = $dbi->dbi_option;
1844 1813
     $dbi = $dbi->dbi_option($dbi_option);
1845 1814
 
1846
-L<DBI> option, used when C<connect()> is executed.
1815
+L<DBI> option, used when C<connect> method is executed.
1847 1816
 Each value in option override the value of C<default_dbi_option>.
1848 1817
 
1849 1818
 =head2 C<default_dbi_option>
... ...
@@ -1851,7 +1820,7 @@ Each value in option override the value of C<default_dbi_option>.
1851 1820
     my $default_dbi_option = $dbi->default_dbi_option;
1852 1821
     $dbi = $dbi->default_dbi_option($default_dbi_option);
1853 1822
 
1854
-L<DBI> default option, used when C<connect()> is executed,
1823
+L<DBI> default option, used when C<connect> method is executed,
1855 1824
 default to the following values.
1856 1825
 
1857 1826
     {
... ...
@@ -1860,29 +1829,26 @@ default to the following values.
1860 1829
         AutoCommit => 1,
1861 1830
     }
1862 1831
 
1863
-You should not change C<AutoCommit> value directly,
1864
-the value is used to check if the process is in transaction.
1865
-
1866 1832
 =head2 C<filters>
1867 1833
 
1868 1834
     my $filters = $dbi->filters;
1869 1835
     $dbi = $dbi->filters(\%filters);
1870 1836
 
1871
-Filters, registered by C<register_filter()>.
1837
+Filters, registered by C<register_filter> method.
1872 1838
 
1873 1839
 =head2 C<models>
1874 1840
 
1875 1841
     my $models = $dbi->models;
1876 1842
     $dbi = $dbi->models(\%models);
1877 1843
 
1878
-Models, included by C<include_model()>.
1844
+Models, included by C<include_model> method.
1879 1845
 
1880 1846
 =head2 C<password>
1881 1847
 
1882 1848
     my $password = $dbi->password;
1883 1849
     $dbi = $dbi->password('lkj&le`@s');
1884 1850
 
1885
-Password, used when C<connect()> is executed.
1851
+Password, used when C<connect> method is executed.
1886 1852
 
1887 1853
 =head2 C<query_builder>
1888 1854
 
... ...
@@ -1920,7 +1886,7 @@ Note that you don't have to specify like '[\w]'.
1920 1886
     my $user = $dbi->user;
1921 1887
     $dbi = $dbi->user('Ken');
1922 1888
 
1923
-User name, used when C<connect()> is executed.
1889
+User name, used when C<connect> method is executed.
1924 1890
 
1925 1891
 =head1 METHODS
1926 1892
 
... ...
@@ -1933,14 +1899,14 @@ and implements the following new ones.
1933 1899
     print $dbi->available_data_type;
1934 1900
 
1935 1901
 Get available data types. You can use these data types
1936
-in C<type rule>'s C<from> section.
1902
+in C<type rule>'s C<from1> and C<from2> section.
1937 1903
 
1938 1904
 =head2 C<available_type_name> EXPERIMENTAL
1939 1905
 
1940 1906
     print $dbi->available_type_name;
1941 1907
 
1942 1908
 Get available type names. You can use these type names in
1943
-C<type_rule>'s C<into> section.
1909
+C<type_rule>'s C<into1> and C<into2> section.
1944 1910
 
1945 1911
 =head2 C<assign_param> EXPERIMENTAL
1946 1912
 
... ...
@@ -1998,40 +1964,19 @@ and C<PrintError> option is false by default.
1998 1964
         join => [
1999 1965
             'inner join company on book.comparny_id = company.id'
2000 1966
         ],
2001
-        filter => {
2002
-            publish_date => {
2003
-                out => 'tp_to_date',
2004
-                in => 'date_to_tp',
2005
-                end => 'tp_to_displaydate'
2006
-            }
2007
-        }
2008 1967
     );
2009 1968
 
2010 1969
 Create L<DBIx::Custom::Model> object and initialize model.
2011
-the module is also used from model() method.
1970
+the module is also used from C<model> method.
2012 1971
 
2013 1972
    $dbi->model('book')->select(...);
2014 1973
 
2015
-=head2 C<create_query>
2016
-    
2017
-    my $query = $dbi->create_query(
2018
-        "insert into book {insert_param title author};";
2019
-    );
2020
-
2021
-Create L<DBIx::Custom::Query> object.
2022
-
2023
-If you want to get high performance,
2024
-create L<DBIx::Custom::Query> object and execute the query by C<execute()>
2025
-instead of other methods, such as C<insert>, C<update>.
2026
-
2027
-    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
2028
-
2029 1974
 =head2 C<dbh>
2030 1975
 
2031 1976
     my $dbh = $dbi->dbh;
2032 1977
 
2033 1978
 Get L<DBI> database handle. if C<connector> is set, you can get
2034
-database handle from C<connector>.
1979
+database handle through C<connector> object.
2035 1980
 
2036 1981
 =head2 C<each_column>
2037 1982
 
... ...
@@ -2055,13 +2000,20 @@ column name and column information.
2055 2000
 =head2 C<execute>
2056 2001
 
2057 2002
     my $result = $dbi->execute(
2058
-        "select * from book where title = :title and author like :author",
2059
-        {title => 'Perl', author => '%Ken%'}
2003
+      "select * from book where title = :title and author like :author",
2004
+      {title => 'Perl', author => '%Ken%'}
2005
+    );
2006
+
2007
+    my $result = $dbi->execute(
2008
+      "select * from book where title = :book.title and author like :book.author",
2009
+      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
2060 2010
     );
2061 2011
 
2062
-Execute SQL. SQL can contain parameter such as :author.
2063
-Return value is L<DBIx::Custom::Result> when select statement is executed,
2064
-or the count of affected rows in insert, update, delete statement is executed.
2012
+Execute SQL. SQL can contain column parameter such as :author and :title.
2013
+You can append table name to column name such as :book.title and :book.author.
2014
+Second argunet is data, embedded into column parameter.
2015
+Return value is L<DBIx::Custom::Result> object when select statement is executed,
2016
+or the count of affected rows when insert, update, delete statement is executed.
2065 2017
 
2066 2018
 Parameter is replaced by placeholder C<?>.
2067 2019
 
... ...
@@ -2090,7 +2042,7 @@ The following opitons are available.
2090 2042
     ]
2091 2043
 
2092 2044
 Filter. You can set subroutine or filter name
2093
-registered by by C<register_filter()>.
2045
+registered by by C<register_filter>.
2094 2046
 This filter is executed before data is saved into database.
2095 2047
 and before type rule filter is executed.
2096 2048
 
... ...
@@ -2099,30 +2051,37 @@ and before type rule filter is executed.
2099 2051
     query => 1
2100 2052
 
2101 2053
 C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
2054
+You can check executed SQL and columns order.
2055
+
2056
+    my $sql = $query->sql;
2057
+    my $columns = $query->columns;
2102 2058
 
2103 2059
 =item C<table>
2104 2060
     
2105 2061
     table => 'author'
2106
-    table => ['author', 'book']
2107 2062
 
2108
-Table names for filtering.
2063
+If you want to omit table name in column name
2064
+and enable C<into1> and C<into2> type filter,
2065
+You must set C<table> option.
2109 2066
 
2110
-Filtering by C<apply_filter> is off in C<execute> method,
2111
-because we don't know what filter is applied.
2067
+    $dbi->execute("select * from book where title = :title and author = :author",
2068
+        {title => 'Perl', author => 'Ken', table => 'book');
2112 2069
 
2113
-=item C<type>
2070
+    # Same
2071
+    $dbi->execute(
2072
+      "select * from book where title = :book.title and author = :book.author",
2073
+      {title => 'Perl', author => 'Ken');
2114 2074
 
2115
-Specify database data type.
2075
+=item C<bind_type>
2116 2076
 
2117
-    type => [image => DBI::SQL_BLOB]
2118
-    type => [[qw/image audio/] => DBI::SQL_BLOB]
2077
+Specify database bind data type.
2119 2078
 
2120
-This is used to bind parameter by C<bind_param()> of statment handle.
2079
+    bind_type => [image => DBI::SQL_BLOB]
2080
+    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2121 2081
 
2122
-    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2082
+This is used to bind parameter by C<bind_param> of statment handle.
2123 2083
 
2124
-C<type> option is also available
2125
-by C<insert()>, C<update()>, C<delete()>, C<select()>.
2084
+    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2126 2085
 
2127 2086
 =item C<type_rule_off> EXPERIMENTAL
2128 2087
 
... ...
@@ -2196,6 +2155,8 @@ Same as C<execute> method's C<query> option.
2196 2155
 
2197 2156
     table => 'book'
2198 2157
 
2158
+Table name.
2159
+
2199 2160
 =item C<where>
2200 2161
 
2201 2162
 Same as C<select> method's C<where> option.
... ...
@@ -2204,9 +2165,9 @@ Same as C<select> method's C<where> option.
2204 2165
 
2205 2166
 See C<id> option.
2206 2167
 
2207
-=item C<type>
2168
+=item C<bind_type>
2208 2169
 
2209
-Same as C<execute> method's C<type> option.
2170
+Same as C<execute> method's C<bind_type> option.
2210 2171
 
2211 2172
 =item C<type_rule_off> EXPERIMENTAL
2212 2173
 
... ...
@@ -2231,13 +2192,14 @@ Same as C<execute> method's C<type_rule2_off> option.
2231 2192
     $dbi->delete_all(table => $table);
2232 2193
 
2233 2194
 Execute delete statement for all rows.
2234
-Options is same as C<delete()>.
2195
+Options is same as C<delete>.
2235 2196
 
2236 2197
 =head2 C<insert>
2237 2198
 
2238 2199
     $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
2239 2200
 
2240
-Execute insert statement.
2201
+Execute insert statement. First argument is row data. Return value is
2202
+affected row count.
2241 2203
 
2242 2204
 The following opitons are available.
2243 2205
 
... ...
@@ -2288,17 +2250,6 @@ prefix before table name section
2288 2250
 
2289 2251
 Primary key. This is used by C<id> option.
2290 2252
 
2291
-=item C<param>
2292
-
2293
-    param => {title => 'Perl', author => 'Ken'}
2294
-
2295
-Insert data.
2296
-
2297
-If C<insert> method's arguments is odd numbers,
2298
-first argument is received as C<param>.
2299
-
2300
-    $dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book');
2301
-
2302 2253
 =item C<query>
2303 2254
 
2304 2255
 Same as C<execute> method's C<query> option.
... ...
@@ -2309,9 +2260,9 @@ Same as C<execute> method's C<query> option.
2309 2260
 
2310 2261
 Table name.
2311 2262
 
2312
-=item C<type>
2263
+=item C<bind_type>
2313 2264
 
2314
-Same as C<execute> method's C<type> option.
2265
+Same as C<execute> method's C<bind_type> option.
2315 2266
 
2316 2267
 =item C<type_rule_off> EXPERIMENTAL
2317 2268
 
... ...
@@ -2357,8 +2308,7 @@ Name space module, extending L<DBIx::Custom::Model>.
2357 2308
 B<MyModel.pm>
2358 2309
 
2359 2310
     package MyModel;
2360
-    
2361
-    use base 'DBIx::Custom::Model';
2311
+    use DBIx::Custom::Model -base;
2362 2312
     
2363 2313
     1;
2364 2314
 
... ...
@@ -2367,24 +2317,22 @@ Model modules, extending name space module.
2367 2317
 B<MyModel/book.pm>
2368 2318
 
2369 2319
     package MyModel::book;
2370
-    
2371
-    use base 'MyModel';
2320
+    use MyModel -base;
2372 2321
     
2373 2322
     1;
2374 2323
 
2375 2324
 B<MyModel/company.pm>
2376 2325
 
2377 2326
     package MyModel::company;
2378
-    
2379
-    use base 'MyModel';
2327
+    use MyModel -base;
2380 2328
     
2381 2329
     1;
2382 2330
     
2383
-MyModel::book and MyModel::company is included by C<include_model()>.
2331
+MyModel::book and MyModel::company is included by C<include_model>.
2384 2332
 
2385
-You can get model object by C<model()>.
2333
+You can get model object by C<model>.
2386 2334
 
2387
-    my $book_model    = $dbi->model('book');
2335
+    my $book_model = $dbi->model('book');
2388 2336
     my $company_model = $dbi->model('company');
2389 2337
 
2390 2338
 See L<DBIx::Custom::Model> to know model features.
... ...
@@ -2395,8 +2343,6 @@ See L<DBIx::Custom::Model> to know model features.
2395 2343
 
2396 2344
 Merge parameters.
2397 2345
 
2398
-$param:
2399
-
2400 2346
     {key1 => [1, 1], key2 => 2}
2401 2347
 
2402 2348
 =head2 C<method>
... ...
@@ -2421,14 +2367,9 @@ Register method. These method is called directly from L<DBIx::Custom> object.
2421 2367
 
2422 2368
 =head2 C<model>
2423 2369
 
2424
-    $dbi->model('book')->method(
2425
-        insert => sub { ... },
2426
-        update => sub { ... }
2427
-    );
2428
-    
2429 2370
     my $model = $dbi->model('book');
2430 2371
 
2431
-Set and get a L<DBIx::Custom::Model> object,
2372
+Get a L<DBIx::Custom::Model> object,
2432 2373
 
2433 2374
 =head2 C<mycolumn>
2434 2375
 
... ...
@@ -2506,11 +2447,11 @@ In C<into1> and C<into2> you can specify
2506 2447
 type name as same as type name defined
2507 2448
 by create table, such as C<DATETIME> or C<DATE>.
2508 2449
 
2509
-C<into2> is executed after C<into1>.
2510
-
2511 2450
 Note that type name and data type don't contain upper case.
2512 2451
 If these contain upper case charactor, you convert it to lower case.
2513 2452
 
2453
+C<into2> is executed after C<into1>.
2454
+
2514 2455
 Type rule of C<into1> and C<into2> is enabled on the following
2515 2456
 column name.
2516 2457
 
... ...
@@ -2521,6 +2462,8 @@ column name.
2521 2462
     issue_date
2522 2463
     issue_datetime
2523 2464
 
2465
+This need C<table> option in each method.
2466
+
2524 2467
 =item 2. table name and column name, separator is dot
2525 2468
 
2526 2469
     book.issue_date
... ...
@@ -2532,7 +2475,7 @@ You get all type name used in database by C<available_type_name>.
2532 2475
 
2533 2476
     print $dbi->available_type_name;
2534 2477
 
2535
-In C<from1> and C<from2> you data type, not type name.
2478
+In C<from1> and C<from2> you specify data type, not type name.
2536 2479
 C<from2> is executed after C<from1>.
2537 2480
 You get all data type by C<available_data_type>.
2538 2481
 
... ...
@@ -2577,21 +2520,21 @@ if C<column> is not specified, '*' is set.
2577 2520
 
2578 2521
     column => '*'
2579 2522
 
2580
-You can specify hash reference in array reference. This is EXPERIMENTAL.
2523
+You can specify hash of array reference. This is EXPERIMENTAL.
2581 2524
 
2582 2525
     column => [
2583 2526
         {book => [qw/author title/]},
2584 2527
         {person => [qw/name age/]}
2585 2528
     ]
2586 2529
 
2587
-This is expanded to the following one by using C<col> method.
2530
+This is expanded to the following one by using C<colomn> method.
2588 2531
 
2589 2532
     book.author as "book.author",
2590 2533
     book.title as "book.title",
2591 2534
     person.name as "person.name",
2592 2535
     person.age as "person.age"
2593 2536
 
2594
-You can specify array reference in array reference.
2537
+You can specify array of array reference.
2595 2538
 
2596 2539
     column => [
2597 2540
         ['date(book.register_datetime)', as => 'book.register_date']
... ...
@@ -2685,7 +2628,7 @@ Primary key. This is used by C<id> option.
2685 2628
 
2686 2629
 Same as C<execute> method's C<query> option.
2687 2630
 
2688
-=item C<type>
2631
+=item C<bind_type>
2689 2632
 
2690 2633
 Same as C<execute> method's C<type> option.
2691 2634
 
... ...
@@ -2721,10 +2664,21 @@ Same as C<execute> method's C<type_rule2_off> option.
2721 2664
         clause => ['and', 'author = :author', 'title like :title'],
2722 2665
         param  => {author => 'Ken', title => '%Perl%'}
2723 2666
     );
2724
-
2725
-    # String(with where_param option)
2726
-    where => 'title like :title',
2727
-    where_param => {title => '%Perl%'}
2667
+    
2668
+    # Array reference 1 (array reference, hash referenc). same as above
2669
+    where => [
2670
+        ['and', 'author = :author', 'title like :title'],
2671
+        {author => 'Ken', title => '%Perl%'}
2672
+    ];    
2673
+    
2674
+    # Array reference 2 (String, hash reference)
2675
+    where => [
2676
+        'title like :title',
2677
+        {title => '%Perl%'}
2678
+    ]
2679
+    
2680
+    # String
2681
+    where => 'title is null'
2728 2682
 
2729 2683
 Where clause.
2730 2684
     
... ...
@@ -2742,7 +2696,7 @@ This option is for Oracle and SQL Server paging process.
2742 2696
 
2743 2697
     $dbi->update({title => 'Perl'}, table  => 'book', where  => {id => 4});
2744 2698
 
2745
-Execute update statement.
2699
+Execute update statement. First argument is update data.
2746 2700
 
2747 2701
 The following opitons are available.
2748 2702
 
... ...
@@ -2779,16 +2733,6 @@ The above is same as the followin one.
2779 2733
         table => 'book'
2780 2734
     );
2781 2735
 
2782
-=item C<param>
2783
-
2784
-    param => {title => 'Perl'}
2785
-
2786
-Update data.
2787
-
2788
-If C<update> method's arguments is odd numbers, first argument is received as C<param>.
2789
-
2790
-    $dbi->update({title => 'Perl'}, table => 'book', where => {id => 2});
2791
-
2792 2736
 =item C<prefix> EXPERIMENTAL
2793 2737
 
2794 2738
     prefix => 'or replace'
... ...
@@ -2818,7 +2762,7 @@ Table name.
2818 2762
 
2819 2763
 Same as C<select> method's C<where> option.
2820 2764
 
2821
-=item C<type>
2765
+=item C<bind_type>
2822 2766
 
2823 2767
 Same as C<execute> method's C<type> option.
2824 2768
 
... ...
@@ -2842,10 +2786,10 @@ Same as C<execute> method's C<type_rule2_off> option.
2842 2786
 
2843 2787
 =head2 C<update_all>
2844 2788
 
2845
-    $dbi->update_all(table => 'book', param => {title => 'Perl'});
2789
+    $dbi->update_all({title => 'Perl'}, table => 'book', );
2846 2790
 
2847 2791
 Execute update statement for all rows.
2848
-Options is same as C<update()>.
2792
+Options is same as C<update> method.
2849 2793
 
2850 2794
 =head2 C<update_param>
2851 2795
 
... ...
@@ -2871,17 +2815,6 @@ Create a new L<DBIx::Custom::Where> object.
2871 2815
 Setup all model objects.
2872 2816
 C<columns> of model object is automatically set, parsing database information.
2873 2817
 
2874
-=head1 Parameter
2875
-
2876
-Parameter start at ':'. This is replaced to place holoder
2877
-
2878
-    $dbi->execute(
2879
-        "select * from book where title = :title and author = :author"
2880
-        param => {title => 'Perl', author => 'Ken'}
2881
-    );
2882
-
2883
-    "select * from book where title = ? and author = ?"
2884
-
2885 2818
 =head1 ENVIRONMENT VARIABLE
2886 2819
 
2887 2820
 =head2 C<DBIX_CUSTOM_DEBUG>
+1 -1
lib/DBIx/Custom/Guide.pod
... ...
@@ -19,7 +19,7 @@ This module have the following features.
19 19
 
20 20
 =item * Creating where clause flexibly
21 21
 
22
-=imte * Support model
22
+=item * Support model
23 23
 
24 24
 =back
25 25
 
+85 -45
t/dbix-custom-core-sqlite.t
... ...
@@ -110,7 +110,7 @@ test 'Insert query return value';
110 110
 $dbi->execute($DROP_TABLE->{0});
111 111
 $dbi->execute($CREATE_TABLE->{0});
112 112
 $source = "insert into table1 {insert_param key1 key2}";
113
-$query = $dbi->create_query($source);
113
+$query = $dbi->execute($source, {}, query => 1);
114 114
 $ret_val = $dbi->execute($query, param => {key1 => 1, key2 => 2});
115 115
 ok($ret_val);
116 116
 
... ...
@@ -131,7 +131,7 @@ $dbi->register_filter(twice       => sub { $_[0] * 2},
131 131
                     three_times => sub { $_[0] * 3});
132 132
 
133 133
 $insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
134
-$insert_query = $dbi->create_query($insert_SOURCE);
134
+$insert_query = $dbi->execute($insert_SOURCE, {}, query => 1);
135 135
 $insert_query->filter({key1 => 'twice'});
136 136
 $dbi->execute($insert_query, param => {key1 => 1, key2 => 2});
137 137
 $result = $dbi->execute($SELECT_SOURCES->{0});
... ...
@@ -142,10 +142,10 @@ $dbi->execute($DROP_TABLE->{0});
142 142
 test 'Filter in';
143 143
 $dbi->execute($CREATE_TABLE->{0});
144 144
 $insert_SOURCE  = "insert into table1 {insert_param key1 key2};";
145
-$insert_query = $dbi->create_query($insert_SOURCE);
145
+$insert_query = $dbi->execute($insert_SOURCE, {}, query => 1);
146 146
 $dbi->execute($insert_query, param => {key1 => 2, key2 => 4});
147 147
 $select_SOURCE = "select * from table1 where {in table1.key1 2} and {in table1.key2 2}";
148
-$select_query = $dbi->create_query($select_SOURCE);
148
+$select_query = $dbi->execute($select_SOURCE,{}, query => 1);
149 149
 $select_query->filter({'table1.key1' => 'twice'});
150 150
 $result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1.key2' => [2,4]});
151 151
 $rows = $result->all;
... ...
@@ -157,20 +157,20 @@ $dbi->execute($CREATE_TABLE->{1});
157 157
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
158 158
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
159 159
 
160
-$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
161
-$query = $dbi->create_query($source);
160
+$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
161
+$query = $dbi->execute($source, {}, query => 1);
162 162
 $result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
163 163
 $rows = $result->all;
164 164
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
165 165
 
166
-$source = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
167
-$query = $dbi->create_query($source);
166
+$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
167
+$query = $dbi->execute($source, {}, query => 1);
168 168
 $result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
169 169
 $rows = $result->all;
170 170
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
171 171
 
172 172
 $source = "select * from table1 where {<= key1} and {like key2};";
173
-$query = $dbi->create_query($source);
173
+$query = $dbi->execute($source, {}, query => 1);
174 174
 $result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
175 175
 $rows = $result->all;
176 176
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
... ...
@@ -182,7 +182,7 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4
182 182
 $dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
183 183
 
184 184
 $source = "select * from table1 where {in key1 2};";
185
-$query = $dbi->create_query($source);
185
+$query = $dbi->execute($source, {}, query => 1);
186 186
 $result = $dbi->execute($query, param => {key1 => [9, 1]});
187 187
 $rows = $result->all;
188 188
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
... ...
@@ -246,7 +246,7 @@ eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')};
246 246
 ok($@, "connect error");
247 247
 
248 248
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
249
-eval{$dbi->create_query("{p }")};
249
+eval{$dbi->execute("{p }", {}, query => 1)};
250 250
 ok($@, "create_query invalid SQL template");
251 251
 
252 252
 test 'insert';
... ...
@@ -373,7 +373,7 @@ $dbi->update(
373 373
     table => 'table1',
374 374
     param => {key1 => 3},
375 375
     where => [
376
-        ['and', '{= key1}', '{= key2}'],
376
+        ['and', 'key1 = :key1', 'key2 = :key2'],
377 377
         {key1 => 1, key2 => 2}
378 378
     ]
379 379
 );
... ...
@@ -384,7 +384,7 @@ $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
384 384
 $dbi->execute($CREATE_TABLE->{0});
385 385
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
386 386
 $where = $dbi->where;
387
-$where->clause(['and', '{= key2}']);
387
+$where->clause(['and', 'key2 = :key2']);
388 388
 $where->param({key2 => 2});
389 389
 $dbi->update(table => 'table1', param => {key1 => 3}, where => $where);
390 390
 $result = $dbi->select(table => 'table1');
... ...
@@ -491,7 +491,7 @@ $dbi->execute($CREATE_TABLE->{0});
491 491
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
492 492
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
493 493
 $where = $dbi->where;
494
-$where->clause(['and', '{= key1}', '{= key2}']);
494
+$where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
495 495
 $where->param({ke1 => 1, key2 => 2});
496 496
 $dbi->delete(table => 'table1', where => $where);
497 497
 $result = $dbi->select(table => 'table1');
... ...
@@ -504,7 +504,7 @@ $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
504 504
 $dbi->delete(
505 505
     table => 'table1',
506 506
     where => [
507
-        ['and', '{= key1}', '{= key2}'],
507
+        ['and', 'key1 = :key1', 'key2 = :key2'],
508 508
         {ke1 => 1, key2 => 2}
509 509
     ]
510 510
 );
... ...
@@ -652,8 +652,8 @@ test 'cache';
652 652
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
653 653
 $dbi->cache(1);
654 654
 $dbi->execute($CREATE_TABLE->{0});
655
-$source = 'select * from table1 where {= key1} and {= key2};';
656
-$dbi->create_query($source);
655
+$source = 'select * from table1 where key1 = :key1 and key2 = :key2;';
656
+$dbi->execute($source, {}, query => 1);
657 657
 is_deeply($dbi->{_cached}->{$source}, 
658 658
           {sql => "select * from table1 where key1 = ? and key2 = ?;", columns => ['key1', 'key2'], tables => []}, "cache");
659 659
 
... ...
@@ -682,19 +682,19 @@ $dbi->execute($CREATE_TABLE->{0});
682 682
 eval{$dbi->execute('select * from table1', no_exists => 1)};
683 683
 like($@, qr/wrong/, "invald SQL");
684 684
 
685
-$query = $dbi->create_query('select * from table1 where {= key1}');
685
+$query = $dbi->execute('select * from table1 where key1 = :key1', {}, query => 1);
686 686
 $dbi->dbh->disconnect;
687 687
 eval{$dbi->execute($query, param => {key1 => {a => 1}})};
688 688
 ok($@, "execute fail");
689 689
 
690 690
 {
691 691
     local $Carp::Verbose = 0;
692
-    eval{$dbi->create_query('select * from table1 where {0 key1}')};
692
+    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
693 693
     like($@, qr/\Q.t /, "caller spec : not vebose");
694 694
 }
695 695
 {
696 696
     local $Carp::Verbose = 1;
697
-    eval{$dbi->create_query('select * from table1 where {0 key1}')};
697
+    eval{$dbi->execute('select * from table1 where {0 key1}', {}, query => 1)};
698 698
     like($@, qr/QueryBuilder.*\.t /s, "caller spec : not vebose");
699 699
 }
700 700
 
... ...
@@ -832,7 +832,7 @@ $dbi->apply_filter(
832 832
     'table1', 'key1' => {out => 'twice', in => 'twice'}
833 833
 );
834 834
 $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
835
-$result = $dbi->execute("select * from table1 where {= key1} and {= key2};",
835
+$result = $dbi->execute("select * from table1 where key1 = :key1 and key2 = :key2;",
836 836
                         param => {key1 => 1, key2 => 2},
837 837
                         table => ['table1']);
838 838
 $rows   = $result->all;
... ...
@@ -845,7 +845,7 @@ $dbi->apply_filter(
845 845
     'table1', 'key1' => {out => 'twice', in => 'twice'}
846 846
 );
847 847
 $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 2}, filter => {key1 => undef});
848
-$result = $dbi->execute("select * from {table table1} where {= key1} and {= key2};",
848
+$result = $dbi->execute("select * from {table table1} where key1 = :key1 and key2 = :key2;",
849 849
                         param => {key1 => 1, key2 => 2});
850 850
 $rows   = $result->all;
851 851
 is_deeply($rows, [{key1 => 4, key2 => 2}], "execute table tag");
... ...
@@ -1083,11 +1083,11 @@ $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1083 1083
 $dbi->execute($CREATE_TABLE->{0});
1084 1084
 $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1085 1085
 $dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
1086
-$where = $dbi->where->clause(['and', '{= key1}', '{= key2}']);
1087
-is("$where", "where ( {= key1} and {= key2} )", 'no param');
1086
+$where = $dbi->where->clause(['and', 'key1 = :key1', 'key2 = :key2']);
1087
+is("$where", "where ( key1 = :key1 and key2 = :key2 )", 'no param');
1088 1088
 
1089 1089
 $where = $dbi->where
1090
-             ->clause(['and', '{= key1}', '{= key2}'])
1090
+             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
1091 1091
              ->param({key1 => 1});
1092 1092
 
1093 1093
 $result = $dbi->select(
... ...
@@ -1100,7 +1100,7 @@ is_deeply($row, [{key1 => 1, key2 => 2}]);
1100 1100
 $result = $dbi->select(
1101 1101
     table => 'table1',
1102 1102
     where => [
1103
-        ['and', '{= key1}', '{= key2}'],
1103
+        ['and', 'key1 = :key1', 'key2 = :key2'],
1104 1104
         {key1 => 1}
1105 1105
     ]
1106 1106
 );
... ...
@@ -1108,7 +1108,7 @@ $row = $result->all;
1108 1108
 is_deeply($row, [{key1 => 1, key2 => 2}]);
1109 1109
 
1110 1110
 $where = $dbi->where
1111
-             ->clause(['and', '{= key1}', '{= key2}'])
1111
+             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
1112 1112
              ->param({key1 => 1, key2 => 2});
1113 1113
 $result = $dbi->select(
1114 1114
     table => 'table1',
... ...
@@ -1118,7 +1118,7 @@ $row = $result->all;
1118 1118
 is_deeply($row, [{key1 => 1, key2 => 2}]);
1119 1119
 
1120 1120
 $where = $dbi->where
1121
-             ->clause(['and', '{= key1}', '{= key2}'])
1121
+             ->clause(['and', 'key1 = :key1', 'key2 = :key2'])
1122 1122
              ->param({});
1123 1123
 $result = $dbi->select(
1124 1124
     table => 'table1',
... ...
@@ -1159,7 +1159,7 @@ $where = $dbi->where;
1159 1159
 is("$where", '');
1160 1160
 
1161 1161
 $where = $dbi->where
1162
-             ->clause(['or', ('{= key1}') x 2])
1162
+             ->clause(['or', ('key1 = :key1') x 2])
1163 1163
              ->param({key1 => [1, 3]});
1164 1164
 $result = $dbi->select(
1165 1165
     table => 'table1',
... ...
@@ -1169,7 +1169,7 @@ $row = $result->all;
1169 1169
 is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}]);
1170 1170
 
1171 1171
 $where = $dbi->where
1172
-             ->clause(['or', ('{= key1}') x 2])
1172
+             ->clause(['or', ('key1 = :key1') x 2])
1173 1173
              ->param({key1 => [1]});
1174 1174
 $result = $dbi->select(
1175 1175
     table => 'table1',
... ...
@@ -1179,7 +1179,7 @@ $row = $result->all;
1179 1179
 is_deeply($row, [{key1 => 1, key2 => 2}]);
1180 1180
 
1181 1181
 $where = $dbi->where
1182
-             ->clause(['or', ('{= key1}') x 2])
1182
+             ->clause(['or', ('key1 = :key1') x 2])
1183 1183
              ->param({key1 => 1});
1184 1184
 $result = $dbi->select(
1185 1185
     table => 'table1',
... ...
@@ -1189,7 +1189,7 @@ $row = $result->all;
1189 1189
 is_deeply($row, [{key1 => 1, key2 => 2}]);
1190 1190
 
1191 1191
 $where = $dbi->where
1192
-             ->clause('{= key1}')
1192
+             ->clause('key1 = :key1')
1193 1193
              ->param({key1 => 1});
1194 1194
 $result = $dbi->select(
1195 1195
     table => 'table1',
... ...
@@ -1199,19 +1199,19 @@ $row = $result->all;
1199 1199
 is_deeply($row, [{key1 => 1, key2 => 2}]);
1200 1200
 
1201 1201
 $where = $dbi->where
1202
-             ->clause('{= key1} {= key2}')
1202
+             ->clause('key1 = :key1 key2 = :key2')
1203 1203
              ->param({key1 => 1});
1204 1204
 eval{$where->to_string};
1205 1205
 like($@, qr/one column/);
1206 1206
 
1207 1207
 $where = $dbi->where
1208
-             ->clause('{= key1}')
1208
+             ->clause('key1 = :key1')
1209 1209
              ->param([]);
1210 1210
 eval{$where->to_string};
1211 1211
 like($@, qr/Parameter/);
1212 1212
 
1213 1213
 $where = $dbi->where
1214
-             ->clause(['or', ('{= key1}') x 3])
1214
+             ->clause(['or', ('key1 = :key1') x 3])
1215 1215
              ->param({key1 => [$dbi->not_exists, 1, 3]});
1216 1216
 $result = $dbi->select(
1217 1217
     table => 'table1',
... ...
@@ -1221,7 +1221,7 @@ $row = $result->all;
1221 1221
 is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1222 1222
 
1223 1223
 $where = $dbi->where
1224
-             ->clause(['or', ('{= key1}') x 3])
1224
+             ->clause(['or', ('key1 = :key1') x 3])
1225 1225
              ->param({key1 => [1, $dbi->not_exists, 3]});
1226 1226
 $result = $dbi->select(
1227 1227
     table => 'table1',
... ...
@@ -1231,7 +1231,7 @@ $row = $result->all;
1231 1231
 is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1232 1232
 
1233 1233
 $where = $dbi->where
1234
-             ->clause(['or', ('{= key1}') x 3])
1234
+             ->clause(['or', ('key1 = :key1') x 3])
1235 1235
              ->param({key1 => [1, 3, $dbi->not_exists]});
1236 1236
 $result = $dbi->select(
1237 1237
     table => 'table1',
... ...
@@ -1241,7 +1241,7 @@ $row = $result->all;
1241 1241
 is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1242 1242
 
1243 1243
 $where = $dbi->where
1244
-             ->clause(['or', ('{= key1}') x 3])
1244
+             ->clause(['or', ('key1 = :key1') x 3])
1245 1245
              ->param({key1 => [1, $dbi->not_exists, $dbi->not_exists]});
1246 1246
 $result = $dbi->select(
1247 1247
     table => 'table1',
... ...
@@ -1251,7 +1251,7 @@ $row = $result->all;
1251 1251
 is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1252 1252
 
1253 1253
 $where = $dbi->where
1254
-             ->clause(['or', ('{= key1}') x 3])
1254
+             ->clause(['or', ('key1 = :key1') x 3])
1255 1255
              ->param({key1 => [$dbi->not_exists, 1, $dbi->not_exists]});
1256 1256
 $result = $dbi->select(
1257 1257
     table => 'table1',
... ...
@@ -1261,7 +1261,7 @@ $row = $result->all;
1261 1261
 is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1262 1262
 
1263 1263
 $where = $dbi->where
1264
-             ->clause(['or', ('{= key1}') x 3])
1264
+             ->clause(['or', ('key1 = :key1') x 3])
1265 1265
              ->param({key1 => [$dbi->not_exists, $dbi->not_exists, 1]});
1266 1266
 $result = $dbi->select(
1267 1267
     table => 'table1',
... ...
@@ -1271,7 +1271,7 @@ $row = $result->all;
1271 1271
 is_deeply($row, [{key1 => 1, key2 => 2}], 'not_exists');
1272 1272
 
1273 1273
 $where = $dbi->where
1274
-             ->clause(['or', ('{= key1}') x 3])
1274
+             ->clause(['or', ('key1 = :key1') x 3])
1275 1275
              ->param({key1 => [$dbi->not_exists, $dbi->not_exists, $dbi->not_exists]});
1276 1276
 $result = $dbi->select(
1277 1277
     table => 'table1',
... ...
@@ -1281,7 +1281,7 @@ $row = $result->all;
1281 1281
 is_deeply($row, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'not_exists');
1282 1282
 
1283 1283
 $where = $dbi->where
1284
-             ->clause(['or', ('{= key1}') x 3])
1284
+             ->clause(['or', ('key1 = :key1') x 3])
1285 1285
              ->param({key1 => []});
1286 1286
 $result = $dbi->select(
1287 1287
     table => 'table1',
... ...
@@ -2410,11 +2410,24 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2410 2410
 $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2411 2411
 $rows = $dbi->select(
2412 2412
     table => 'table1',
2413
-    where => '{= key1} and {= key2}',
2413
+    where => 'key1 = :key1 and key2 = :key2',
2414 2414
     where_param => {key1 => 1, key2 => 2}
2415 2415
 )->all;
2416 2416
 is_deeply($rows, [{key1 => 1, key2 => 2}]);
2417 2417
 
2418
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2419
+$dbi->execute($CREATE_TABLE->{0});
2420
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2421
+$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2422
+$rows = $dbi->select(
2423
+    table => 'table1',
2424
+    where => [
2425
+        'key1 = :key1 and key2 = :key2',
2426
+        {key1 => 1, key2 => 2}
2427
+    ]
2428
+)->all;
2429
+is_deeply($rows, [{key1 => 1, key2 => 2}]);
2430
+
2418 2431
 test 'delete() string where';
2419 2432
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2420 2433
 $dbi->execute($CREATE_TABLE->{0});
... ...
@@ -2422,12 +2435,26 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2422 2435
 $dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2423 2436
 $dbi->delete(
2424 2437
     table => 'table1',
2425
-    where => '{= key1} and {= key2}',
2438
+    where => 'key1 = :key1 and key2 = :key2',
2426 2439
     where_param => {key1 => 1, key2 => 2}
2427 2440
 );
2428 2441
 $rows = $dbi->select(table => 'table1')->all;
2429 2442
 is_deeply($rows, [{key1 => 2, key2 => 3}]);
2430 2443
 
2444
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2445
+$dbi->execute($CREATE_TABLE->{0});
2446
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2447
+$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
2448
+$dbi->delete(
2449
+    table => 'table1',
2450
+    where => [
2451
+        'key1 = :key1 and key2 = :key2',
2452
+         {key1 => 1, key2 => 2}
2453
+    ]
2454
+);
2455
+$rows = $dbi->select(table => 'table1')->all;
2456
+is_deeply($rows, [{key1 => 2, key2 => 3}]);
2457
+
2431 2458
 
2432 2459
 test 'update() string where';
2433 2460
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
... ...
@@ -2436,12 +2463,25 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2436 2463
 $dbi->update(
2437 2464
     table => 'table1',
2438 2465
     param => {key1 => 5},
2439
-    where => '{= key1} and {= key2}',
2466
+    where => 'key1 = :key1 and key2 = :key2',
2440 2467
     where_param => {key1 => 1, key2 => 2}
2441 2468
 );
2442 2469
 $rows = $dbi->select(table => 'table1')->all;
2443 2470
 is_deeply($rows, [{key1 => 5, key2 => 2}]);
2444 2471
 
2472
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
2473
+$dbi->execute($CREATE_TABLE->{0});
2474
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2475
+$dbi->update(
2476
+    table => 'table1',
2477
+    param => {key1 => 5},
2478
+    where => [
2479
+        'key1 = :key1 and key2 = :key2',
2480
+        {key1 => 1, key2 => 2}
2481
+    ]
2482
+);
2483
+$rows = $dbi->select(table => 'table1')->all;
2484
+is_deeply($rows, [{key1 => 5, key2 => 2}]);
2445 2485
 
2446 2486
 test 'insert id and primary_key option';
2447 2487
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});