Friday, August 22, 2014

How do you execute PostgreSQL scripts whose names start with 'p_'?

my $path = 'C:\TestSQL';

my @scripts = `dir /B /s $path`;

foreach my $psqlfile (@scripts) {
   if ( $psqlfile =~ /^(.+\\p\_[^\\]+\.sql)\s*$/i ) {
        `psql -q -h <Hostname> -p <Port> -d <Database> -U <Username> -f $psqlfile.sql -o outputfile`;
   }
}

How do you execute all sql files in a directory?

my $path = 'C:\TestSQL';

my @scripts = `dir /B /s $path`;

foreach my $sqlfile (@scripts) {
   if ( $sqlfile =~ /^(.+\.sql)\s*$/i ) {
       `mysql <db_name> -u <user_name> -p <password> < $sqlfile.sql`;
   }
}

Wednesday, August 20, 2014

How do you add path of perl to environment variable on command prompt?

1. Open "cmd.exe" with Administrator Privilege (on right click on app) and type the command below.
     setx path "%path%;C:\Perl64\bin;"
2. Restart "cmd.exe".