Revert my previous changes (rev 1722 reverted back to rev 1721)
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / Dumper.pm
index 6d46d25..b24b78b 100644 (file)
@@ -1,9 +1,7 @@
 package SQL::Translator::Producer::Dumper;
 
 # -------------------------------------------------------------------
-# $Id: Dumper.pm,v 1.2 2004-03-09 19:35:40 kycl4rk Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
+# Copyright (C) 2002-2006 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -61,7 +59,7 @@ use vars qw($VERSION);
 
 use Data::Dumper;
 
-$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 
 sub produce {
     my $t              = shift;
@@ -143,7 +141,8 @@ use DBI;
 use Getopt::Long;
 use File::Spec::Functions 'catfile';
 
-my ( $help, $add_truncate, $skip, $skiplike, $no_comments, $mysql_loadfile );
+my ( $help, $add_truncate, $skip, $skiplike, $no_comments, 
+    $takelike, $mysql_loadfile );
 GetOptions(
     'add-truncate'   => \$add_truncate,
     'h|help'         => \$help,
@@ -151,12 +150,13 @@ GetOptions(
     'mysql-loadfile' => \$mysql_loadfile,
     'skip:s'         => \$skip,
     'skiplike:s'     => \$skiplike,
+    'takelike:s'     => \$takelike,
 );
 
 if ( $help ) {
     print <<"USAGE";
 Usage:
-  $0 [options]
+  $0 [options] > dump.sql
 
   Options:
     -h|--help          Show help and exit
@@ -164,7 +164,8 @@ Usage:
     --mysql-loadfile   Create MySQL's LOAD FILE syntax, not INSERTs
     --no-comments      Suppress comments
     --skip=t1[,t2]     Comma-separated list of tables to skip
-    --skiplike=regex   Comma-separated list of tables to skip
+    --skiplike=regex   Regular expression of table names to skip
+    --takelike=regex   Regular expression of table names to take
 
 USAGE
     exit(0);
@@ -187,7 +188,7 @@ FOREACH table IN schema.get_tables;
         field_name = field.name;
         fname_len  = field.name.length;
         max_field  = fname_len > max_field ? fname_len : max_field;
-        types.$field_name = field.data_type.match( '(char|str|long|text)' )
+        types.$field_name = field.data_type.match( '(char|str|long|text|enum|date)' )
             ? 'string' : 'number';
         field_names.push( field_name );
     END;
@@ -225,6 +226,7 @@ for my $table ( @tables ) {
     my $table_name = $table->{'table_name'};
     next if $skip{ $table_name };
     next if $skiplike && $table_name =~ qr/$skiplike/;
+    next if $takelike && $table_name !~ qr/$takelike/;
 
     my ( $out_fh, $outfile );
     if ( $mysql_loadfile ) {
@@ -239,12 +241,13 @@ for my $table ( @tables ) {
         print "TRUNCATE TABLE $table_name;\n";
     }
 
-    my $data = $db->selectall_arrayref(
-        'select ' . join(', ', @{ $table->{'fields'} } ) . " from $table_name",
-        { Columns => {} }
-    );
+    my $sql =
+        'select ' . join(', ', @{ $table->{'fields'} } ) . " from $table_name"
+    ;
+    my $sth = $db->prepare( $sql );
+    $sth->execute;
 
-    for my $rec ( @{ $data } ) {
+    while ( my $rec = $sth->fetchrow_hashref ) {
         my @vals;
         for my $fld ( @{ $table->{'fields'} } ) {
             my $val = $rec->{ $fld };
@@ -269,7 +272,7 @@ for my $table ( @tables ) {
         else {
             print "INSERT INTO $table_name (".
                 join(', ', @{ $table->{'fields'} }) . 
-                ' VALUES (', join(', ', @vals), ");\n";
+                ') VALUES (', join(', ', @vals), ");\n";
         }
     }
 
@@ -296,6 +299,6 @@ EOF
 
 =head1 AUTHOR
 
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
+Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
 
 =cut