... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1717 |
|
2 |
+ - added EXPERIMENTAL find_tables |
|
1 | 3 |
0.1716 |
2 | 4 |
- fixed bugs when using DBD::Oracle. |
3 | 5 |
- added EXPERIMENTAL show_tables method. |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
use Object::Simple -base; |
3 | 3 |
|
4 |
-our $VERSION = '0.1716'; |
|
4 |
+our $VERSION = '0.1717'; |
|
5 | 5 |
use 5.008001; |
6 | 6 |
|
7 | 7 |
use Carp 'croak'; |
... | ... |
@@ -197,8 +197,9 @@ sub dbh { |
197 | 197 |
# Quote |
198 | 198 |
if (!defined $self->reserved_word_quote && !defined $self->quote) { |
199 | 199 |
my $driver = $self->_driver; |
200 |
- my $quote = $driver eq 'odbc' ? '[]' |
|
201 |
- :$driver eq 'mysql' ? '`' |
|
200 |
+ my $quote = $driver eq 'odbc' ? '[]' |
|
201 |
+ : $driver eq 'ado' ? '[]' |
|
202 |
+ : $driver eq 'mysql' ? '`' |
|
202 | 203 |
: '"'; |
203 | 204 |
$self->quote($quote); |
204 | 205 |
} |
... | ... |
@@ -320,9 +321,9 @@ sub each_column { |
320 | 321 |
} |
321 | 322 |
|
322 | 323 |
sub each_table { |
323 |
- my ($self, $cb) = @_; |
|
324 |
+ my ($self, $cb, %option) = @_; |
|
324 | 325 |
|
325 |
- my $re = $self->exclude_table; |
|
326 |
+ my $re = $self->exclude_table || $option{exclude}; |
|
326 | 327 |
|
327 | 328 |
# Iterate all tables |
328 | 329 |
my $sth_tables = $self->dbh->table_info; |
... | ... |
@@ -513,6 +514,18 @@ sub execute { |
513 | 514 |
else { return $affected } |
514 | 515 |
} |
515 | 516 |
|
517 |
+sub find_tables { |
|
518 |
+ my ($self, %args) = @_; |
|
519 |
+ |
|
520 |
+ my $exclude = delete $args{exclude}; |
|
521 |
+ croak qq/"$_" is wrong option/ for keys %args; |
|
522 |
+ |
|
523 |
+ my %tables; |
|
524 |
+ $self->each_table(sub { push $table{$_[1]}++ }, exclude => $exclude); |
|
525 |
+ |
|
526 |
+ return [sort keys %tables]; |
|
527 |
+} |
|
528 |
+ |
|
516 | 529 |
sub insert { |
517 | 530 |
my $self = shift; |
518 | 531 |
|
... | ... |
@@ -2185,6 +2198,101 @@ the module is also used from C<model> method. |
2185 | 2198 |
Get L<DBI> database handle. if C<connector> is set, you can get |
2186 | 2199 |
database handle through C<connector> object. |
2187 | 2200 |
|
2201 |
+=head2 C<delete> |
|
2202 |
+ |
|
2203 |
+ $dbi->delete(table => 'book', where => {title => 'Perl'}); |
|
2204 |
+ |
|
2205 |
+Execute delete statement. |
|
2206 |
+ |
|
2207 |
+The following opitons are available. |
|
2208 |
+ |
|
2209 |
+=over 4 |
|
2210 |
+ |
|
2211 |
+=item C<append> |
|
2212 |
+ |
|
2213 |
+Same as C<select> method's C<append> option. |
|
2214 |
+ |
|
2215 |
+=item C<filter> |
|
2216 |
+ |
|
2217 |
+Same as C<execute> method's C<filter> option. |
|
2218 |
+ |
|
2219 |
+=item C<id> |
|
2220 |
+ |
|
2221 |
+ id => 4 |
|
2222 |
+ id => [4, 5] |
|
2223 |
+ |
|
2224 |
+ID corresponding to C<primary_key>. |
|
2225 |
+You can delete rows by C<id> and C<primary_key>. |
|
2226 |
+ |
|
2227 |
+ $dbi->delete( |
|
2228 |
+ parimary_key => ['id1', 'id2'], |
|
2229 |
+ id => [4, 5], |
|
2230 |
+ table => 'book', |
|
2231 |
+ ); |
|
2232 |
+ |
|
2233 |
+The above is same as the followin one. |
|
2234 |
+ |
|
2235 |
+ $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book'); |
|
2236 |
+ |
|
2237 |
+=item C<prefix> |
|
2238 |
+ |
|
2239 |
+ prefix => 'some' |
|
2240 |
+ |
|
2241 |
+prefix before table name section. |
|
2242 |
+ |
|
2243 |
+ delete some from book |
|
2244 |
+ |
|
2245 |
+=item C<query> |
|
2246 |
+ |
|
2247 |
+Same as C<execute> method's C<query> option. |
|
2248 |
+ |
|
2249 |
+=item C<sqlfilter EXPERIMENTAL> |
|
2250 |
+ |
|
2251 |
+Same as C<execute> method's C<sqlfilter> option. |
|
2252 |
+ |
|
2253 |
+=item C<table> |
|
2254 |
+ |
|
2255 |
+ table => 'book' |
|
2256 |
+ |
|
2257 |
+Table name. |
|
2258 |
+ |
|
2259 |
+=item C<where> |
|
2260 |
+ |
|
2261 |
+Same as C<select> method's C<where> option. |
|
2262 |
+ |
|
2263 |
+=item C<primary_key> |
|
2264 |
+ |
|
2265 |
+See C<id> option. |
|
2266 |
+ |
|
2267 |
+=item C<bind_type> |
|
2268 |
+ |
|
2269 |
+Same as C<execute> method's C<bind_type> option. |
|
2270 |
+ |
|
2271 |
+=item C<type_rule_off> EXPERIMENTAL |
|
2272 |
+ |
|
2273 |
+Same as C<execute> method's C<type_rule_off> option. |
|
2274 |
+ |
|
2275 |
+=item C<type_rule1_off> EXPERIMENTAL |
|
2276 |
+ |
|
2277 |
+ type_rule1_off => 1 |
|
2278 |
+ |
|
2279 |
+Same as C<execute> method's C<type_rule1_off> option. |
|
2280 |
+ |
|
2281 |
+=item C<type_rule2_off> EXPERIMENTAL |
|
2282 |
+ |
|
2283 |
+ type_rule2_off => 1 |
|
2284 |
+ |
|
2285 |
+Same as C<execute> method's C<type_rule2_off> option. |
|
2286 |
+ |
|
2287 |
+=back |
|
2288 |
+ |
|
2289 |
+=head2 C<delete_all> |
|
2290 |
+ |
|
2291 |
+ $dbi->delete_all(table => $table); |
|
2292 |
+ |
|
2293 |
+Execute delete statement for all rows. |
|
2294 |
+Options is same as C<delete>. |
|
2295 |
+ |
|
2188 | 2296 |
=head2 C<each_column> |
2189 | 2297 |
|
2190 | 2298 |
$dbi->each_column( |
... | ... |
@@ -2402,100 +2510,11 @@ Turn C<into2> type rule off. |
2402 | 2510 |
|
2403 | 2511 |
=back |
2404 | 2512 |
|
2405 |
-=head2 C<delete> |
|
2406 |
- |
|
2407 |
- $dbi->delete(table => 'book', where => {title => 'Perl'}); |
|
2408 |
- |
|
2409 |
-Execute delete statement. |
|
2410 |
- |
|
2411 |
-The following opitons are available. |
|
2412 |
- |
|
2413 |
-=over 4 |
|
2414 |
- |
|
2415 |
-=item C<append> |
|
2416 |
- |
|
2417 |
-Same as C<select> method's C<append> option. |
|
2418 |
- |
|
2419 |
-=item C<filter> |
|
2420 |
- |
|
2421 |
-Same as C<execute> method's C<filter> option. |
|
2422 |
- |
|
2423 |
-=item C<id> |
|
2424 |
- |
|
2425 |
- id => 4 |
|
2426 |
- id => [4, 5] |
|
2427 |
- |
|
2428 |
-ID corresponding to C<primary_key>. |
|
2429 |
-You can delete rows by C<id> and C<primary_key>. |
|
2430 |
- |
|
2431 |
- $dbi->delete( |
|
2432 |
- parimary_key => ['id1', 'id2'], |
|
2433 |
- id => [4, 5], |
|
2434 |
- table => 'book', |
|
2435 |
- ); |
|
2436 |
- |
|
2437 |
-The above is same as the followin one. |
|
2438 |
- |
|
2439 |
- $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book'); |
|
2440 |
- |
|
2441 |
-=item C<prefix> |
|
2442 |
- |
|
2443 |
- prefix => 'some' |
|
2444 |
- |
|
2445 |
-prefix before table name section. |
|
2446 |
- |
|
2447 |
- delete some from book |
|
2448 |
- |
|
2449 |
-=item C<query> |
|
2450 |
- |
|
2451 |
-Same as C<execute> method's C<query> option. |
|
2452 |
- |
|
2453 |
-=item C<sqlfilter EXPERIMENTAL> |
|
2454 |
- |
|
2455 |
-Same as C<execute> method's C<sqlfilter> option. |
|
2456 |
- |
|
2457 |
-=item C<table> |
|
2458 |
- |
|
2459 |
- table => 'book' |
|
2460 |
- |
|
2461 |
-Table name. |
|
2462 |
- |
|
2463 |
-=item C<where> |
|
2464 |
- |
|
2465 |
-Same as C<select> method's C<where> option. |
|
2466 |
- |
|
2467 |
-=item C<primary_key> |
|
2468 |
- |
|
2469 |
-See C<id> option. |
|
2470 |
- |
|
2471 |
-=item C<bind_type> |
|
2472 |
- |
|
2473 |
-Same as C<execute> method's C<bind_type> option. |
|
2474 |
- |
|
2475 |
-=item C<type_rule_off> EXPERIMENTAL |
|
2476 |
- |
|
2477 |
-Same as C<execute> method's C<type_rule_off> option. |
|
2478 |
- |
|
2479 |
-=item C<type_rule1_off> EXPERIMENTAL |
|
2480 |
- |
|
2481 |
- type_rule1_off => 1 |
|
2482 |
- |
|
2483 |
-Same as C<execute> method's C<type_rule1_off> option. |
|
2484 |
- |
|
2485 |
-=item C<type_rule2_off> EXPERIMENTAL |
|
2486 |
- |
|
2487 |
- type_rule2_off => 1 |
|
2488 |
- |
|
2489 |
-Same as C<execute> method's C<type_rule2_off> option. |
|
2490 |
- |
|
2491 |
-=back |
|
2492 |
- |
|
2493 |
-=head2 C<delete_all> |
|
2513 |
+=head2 C<find_tables EXPERIMENTAL> |
|
2494 | 2514 |
|
2495 |
- $dbi->delete_all(table => $table); |
|
2515 |
+ my $tables = $self->find_tables(exclude => qr/^system_/); |
|
2496 | 2516 |
|
2497 |
-Execute delete statement for all rows. |
|
2498 |
-Options is same as C<delete>. |
|
2517 |
+Find tables except for one which match C<exclude> pattern. |
|
2499 | 2518 |
|
2500 | 2519 |
=head2 C<insert> |
2501 | 2520 |
|