Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Wednesday, October 14, 2026

Diff for scripts/perl/oracle/oracledump.pl between version 1.10 and 1.11

version 1.10, 2004/01/23 14:12:42 version 1.11, 2004/01/23 18:38:20
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
   
 # $Platon: scripts/perl/oracle/oracledump.pl,v 1.9 2004/01/23 14:09:08 nepto Exp $  # $Platon: scripts/perl/oracle/oracledump.pl,v 1.10 2004/01/23 14:12:42 nepto Exp $
   
 use strict;  use strict;
   
Line 32  my $VERSION = sprintf("%d.%02d", $MAJOR_
Line 32  my $VERSION = sprintf("%d.%02d", $MAJOR_
 my $dbh;                # database handle  my $dbh;                # database handle
 my $sth;                # statement handle  my $sth;                # statement handle
 my $table;              # foreach loop iterator  my $table;              # foreach loop iterator
   my $query;              # current query
   
 my $CM = '--';          # comment marker for output; default is '--'  my $CM = '--';          # comment marker for output; default is '--'
   
Line 59  my $opt_host;            # -h|--host
Line 60  my $opt_host;            # -h|--host
 my $opt_lock_tables;            # -l|--lock-tables  my $opt_lock_tables;            # -l|--lock-tables
 my $opt_no_create_info;         # -t|--no-create-info  my $opt_no_create_info;         # -t|--no-create-info
 my $opt_no_data;                # -d|--no-data  my $opt_no_data;                # -d|--no-data
   my $opt_owner;                  # -o|--owner
 my %opt_set_variable;           # -O|--set-variable  my %opt_set_variable;           # -O|--set-variable
 my $opt_opt;                    # --opt  my $opt_opt;                    # --opt
 my $opt_password;               # -p|--password  my $opt_password;               # -p|--password
Line 104  Usage: oracledump [options] database [ta
Line 106  Usage: oracledump [options] database [ta
   -l, --lock-tables     Lock all tables for read.    -l, --lock-tables     Lock all tables for read.
 * -t, --no-create-info  Don't write table creation info.  * -t, --no-create-info  Don't write table creation info.
 * -d, --no-data         No row information.  * -d, --no-data         No row information.
   * -o, --owner=#         Owner of tables if not user.
   -O, --set-variable var=option    -O, --set-variable var=option
                         give a variable an value. --help lists variables                          give a variable an value. --help lists variables
   --opt                 Same as --quick --add-drop-table --add-locks    --opt                 Same as --quick --add-drop-table --add-locks
Line 165  my $rc = GetOptions(
Line 168  my $rc = GetOptions(
                 "l|lock-tables"         => \$opt_lock_tables,                  "l|lock-tables"         => \$opt_lock_tables,
                 "t|no-create-info"      => \$opt_no_create_info,                  "t|no-create-info"      => \$opt_no_create_info,
                 "d|no-data"             => \$opt_no_data,                  "d|no-data"             => \$opt_no_data,
                   "o|owner=s"             => \$opt_owner,
                 "O|set-variable=s%"     => \%opt_set_variable,                  "O|set-variable=s%"     => \%opt_set_variable,
                 "opt"                   => \$opt_opt,                  "opt"                   => \$opt_opt,
                 "p|password:s"          => \$opt_password,                  "p|password:s"          => \$opt_password,
Line 223  if (! defined $opt_user)
Line 227  if (! defined $opt_user)
 }  }
   
   
   ## Alter $opt_owner
   
   if (defined $opt_owner)
   {
           $opt_owner = uc $opt_owner;
   }
   
   
 ## Read password into $opt_password if it wasn't set  ## Read password into $opt_password if it wasn't set
   
 if (! defined $opt_password || $opt_password eq "")  if (! defined $opt_password || $opt_password eq "")
Line 271  $dbh->do("set transaction read only")
Line 283  $dbh->do("set transaction read only")
 if (scalar @opt_tables < 1)  if (scalar @opt_tables < 1)
 {  {
     my @row;      my @row;
       my $query;
   
     $sth = $dbh->prepare("SELECT table_name FROM user_tables");      if ( defined $opt_owner ) {
           $query = 'SELECT table_name FROM all_tables'
             . ' WHERE owner = \'' . $opt_owner . '\'';
       } else {
           $query = 'SELECT table_name FROM user_tables';
       }
   
       $sth = $dbh->prepare($query);
     $sth->execute() || die $DBI::errstr;      $sth->execute() || die $DBI::errstr;
   
     while (@row =  $sth->fetchrow_array())      while ( @row = $sth->fetchrow_array() )
     {      {
         push(@opt_tables, @row);          push ( @opt_tables, @row );
     }      }
   
     $sth->finish();      $sth->finish();
Line 414  MARK
Line 433  MARK
   
     ## We always need this information to output data below      ## We always need this information to output data below
   
     $sth = $dbh->prepare("SELECT column_name,      if ( defined $opt_owner ) {
                                  data_type,                  $query = 'SELECT column_name,
                                  data_length,                                                   data_type,
                                  data_precision,                                                   data_length,
                                  data_scale,                                                   data_precision,
                                  data_default,                                                   data_scale,
                                  nullable                                                   data_default,
                             FROM user_tab_columns                                                   nullable
                            WHERE table_name = ?");                                          FROM all_tab_columns
                                      WHERE UPPER(table_name) = ?
                                        AND UPPER(owner) = \''.$opt_owner.'\'';
           } else {
                   $query = 'SELECT column_name,
                                                    data_type,
                                                    data_length,
                                                    data_precision,
                                                    data_scale,
                                                    data_default,
                                                    nullable
                                           FROM user_tab_columns
                                      WHERE UPPER(table_name) = ?';
           }
   
       $sth = $dbh->prepare($query);
     $sth->execute($table) || die $DBI::errstr;      $sth->execute($table) || die $DBI::errstr;
   
     my $c = 0;      my $c = 0;
Line 517  MARK
Line 550  MARK
   
         ## Generate list of column names          ## Generate list of column names
   
         $sth = $dbh->prepare("SELECT column_name      if ( defined $opt_owner ) {
                                 FROM user_tab_columns                  $query = 'SELECT column_name
                                WHERE table_name = ?");                                          FROM all_tab_columns
                                      WHERE UPPER(table_name) = ?
                                        AND UPPER(owner) = \''.$opt_owner.'\'';
           } else {
                   $query = 'SELECT column_name
                                           FROM user_tab_columns
                                      WHERE UPPER(table_name) = ?';
           }
   
           $sth = $dbh->prepare($query);
         $sth->execute($table) || die $DBI::errstr;          $sth->execute($table) || die $DBI::errstr;
   
         while (@row = $sth->fetchrow_array())          while (@row = $sth->fetchrow_array())
Line 533  MARK
Line 574  MARK
   
         ## Query for data then output SQL          ## Query for data then output SQL
   
         $sth = $dbh->prepare("SELECT @{[ join(',', @column_names) ]}      $query = sprintf( 'SELECT %s FROM %s',
                                 FROM $table          join ( ',', @column_names ), $table );
                               @{[ (scalar @opt_where > 0)      $query .= ' WHERE ' . join ( ' AND ', @opt_where ) if ( scalar @opt_where > 0 );
                                   ? ' WHERE ' . join(' AND ', @opt_where)  
                                   : '' ]}");  
   
           $sth = $dbh->prepare($query);
         $sth->execute() || die $DBI::errstr;          $sth->execute() || die $DBI::errstr;
   
         while (@row = $sth->fetchrow_array())          while (@row = $sth->fetchrow_array())

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top