| version 1.3, 2004/01/22 20:40:06 |
version 1.4, 2004/01/22 21:03:21 |
|
|
| #!/usr/bin/perl |
#!/usr/bin/perl |
| |
|
| # $Platon: scripts/perl/oracledump/oracledump,v 1.2 2004/01/22 20:38:13 nepto Exp $ |
# $Platon: scripts/perl/oracledump/oracledump,v 1.3 2004/01/22 20:40:06 nepto Exp $ |
| |
|
| use strict; |
use strict; |
| |
|
| Line 75 my $opt_fields_enclosed_by; # --fields-e |
|
| Line 75 my $opt_fields_enclosed_by; # --fields-e |
|
| my $opt_fields_optionally_enclosed_by; # --fields-optionally-enclosed-by |
my $opt_fields_optionally_enclosed_by; # --fields-optionally-enclosed-by |
| my $opt_fields_escaped_by; # --fields-escaped-by |
my $opt_fields_escaped_by; # --fields-escaped-by |
| my $opt_lines_terminated_by; # --lines-terminated-by |
my $opt_lines_terminated_by; # --lines-terminated-by |
| |
my $opt_mysql_compliant_dump; # --mysql-compliant-dump |
| |
|
| my $help = <<MARK; # help statement |
my $help = <<MARK; # help statement |
| |
|
| Line 134 Usage: oracledump [options] database [ta |
|
| Line 135 Usage: oracledump [options] database [ta |
|
| --lines-terminated-by=... |
--lines-terminated-by=... |
| Lines in the i.file are terminated by ... |
Lines in the i.file are terminated by ... |
| |
|
| |
--mysql-compliant-dump |
| |
Creates MySQL compliant SQL dump |
| |
|
| Possible variables for option --set-variable (-O) are: |
Possible variables for option --set-variable (-O) are: |
| <none> |
<none> |
| MARK |
MARK |
| Line 177 my $rc = GetOptions( |
|
| Line 181 my $rc = GetOptions( |
|
| "fields-optionally-enclosed-by=s" => \$opt_fields_optionally_enclosed_by, |
"fields-optionally-enclosed-by=s" => \$opt_fields_optionally_enclosed_by, |
| "fields-escaped-by=s" => \$opt_fields_escaped_by, |
"fields-escaped-by=s" => \$opt_fields_escaped_by, |
| "lines-terminated-by=s" => \$opt_lines_terminated_by, |
"lines-terminated-by=s" => \$opt_lines_terminated_by, |
| |
"mysql-compliant-dump" => \$opt_mysql_compliant_dump |
| ); |
); |
| |
|
| $opt_database = shift @ARGV; # grab database name |
$opt_database = shift @ARGV; # grab database name |
| Line 324 $sth->execute() || die $DBI::errstr; |
|
| Line 329 $sth->execute() || die $DBI::errstr; |
|
| |
|
| $sth->finish(); |
$sth->finish(); |
| |
|
| |
my $additional_header_info = ''; |
| |
|
| |
if ( defined $opt_mysql_compliant_dump ) { |
| |
|
| |
# |
| |
# Preparing NLS_DATE_FORMAT |
| |
# |
| |
$sth = $dbh->prepare('ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD HH24:MI:SS\'') |
| |
or die "DBI::prepare(): $DBI::errstr"; |
| |
|
| |
# |
| |
# Altering session |
| |
# |
| |
$sth->execute() or die "DBI::execute(): " . $sth->errstr; |
| |
$sth->finish(); |
| |
|
| |
$additional_header_info = ' (MySQL compliant dump)'; |
| |
} |
| |
|
| |
|
| |
|
| ## Print header |
## Print header |
| |
|
| print <<MARK; |
print <<MARK; |
| $CM Oracle dump $VERSION |
$CM Oracle dump $VERSION$additional_header_info |
| $CM |
$CM |
| $CM Host: $ORA_HOSTNAME Database: $opt_database |
$CM Host: $ORA_HOSTNAME Database: $opt_database |
| $CM ------------------------------------------------------------ |
$CM ------------------------------------------------------------ |
|
|
| my $c = 0; |
my $c = 0; |
| while (@row = $sth->fetchrow_array()) |
while (@row = $sth->fetchrow_array()) |
| { |
{ |
| $c++; |
$c++; |
| printf(" %1s%-22s%-15s%-21s%-8s\n", |
|
| ($c != 1 ? ',' : ' '), |
if ( !defined $opt_no_create_info ) { |
| lc($row[0]), |
if ($opt_mysql_compliant_dump) { |
| ($row[1] eq 'NUMBER' |
printf( " %1s%-22s%-15s%-21s%-8s\n", |
| ? $row[1].'('.$row[3].', '.$row[4].')' |
( $c != 1 ? ',' : ' ' ), |
| : ($row[1] eq 'VARCHAR2' |
lc( $row[0] ), |
| ? $row[1].'('.$row[2].')' |
( $row[1] eq 'NUMBER' |
| : $row[1])), |
? 'NUMERIC' . '(' . $row[3] . ', ' . $row[4] . ')' |
| (defined $row[5] |
: ( $row[1] eq 'VARCHAR2' |
| ? 'DEFAULT ' . $row[5] |
? ( $row[2] > 255 ? 'TEXT' : 'VARCHAR' . '(' . $row[2] . ')' ) |
| : ''), |
: $row[1] ) ), |
| ($row[6] eq 'Y' |
( defined $row[5] |
| ? '' |
? 'DEFAULT ' . $row[5] |
| : 'NOT NULL') |
: '' ), |
| ) |
( $row[6] eq 'Y' |
| if (! defined $opt_no_create_info); |
? '' |
| push(@column_types, $row[1]); |
: 'NOT NULL' ) |
| |
); |
| |
} else { |
| |
printf( " %1s%-22s%-15s%-21s%-8s\n", |
| |
( $c != 1 ? ',' : ' ' ), |
| |
lc( $row[0] ), |
| |
( $row[1] eq 'NUMBER' |
| |
? $row[1] . '(' . $row[3] . ', ' . $row[4] . ')' |
| |
: ( $row[1] eq 'VARCHAR2' |
| |
? $row[1] . '(' . $row[2] . ')' |
| |
: $row[1] ) ), |
| |
( defined $row[5] |
| |
? 'DEFAULT ' . $row[5] |
| |
: '' ), |
| |
( $row[6] eq 'Y' |
| |
? '' |
| |
: 'NOT NULL' ) |
| |
); |
| |
} |
| |
} |
| |
push ( @column_types, $row[1] ); |
| } |
} |
| |
|
| $sth->finish(); |
$sth->finish(); |