:: File:Test.cmd
:: Set up the database name
set DbName=CAS_DEV
:: Set up the run folder where the perl script is executing
set RunFolder=D:\cas\sfw\perl
:: Set up the full path to the Perl script
set PerlScript=%RunFolder%\Generate_SelectAll.1.1.pl
:: Set up the input folder where the input file residues
set InputFolder=D:\cas\sfw\perl\input
:: Set up the full path the MetaFile
set InputMetaFile=%InputFolder%\%DbName%.txt
:: Set up the full path to Perl
set PerlBin=C:\Perl\bin\perl.exe
:: Set up the output folder
set FolderOutput=D:\cas\sfw\perl\output\SelectAll
:: remove the contents of the %FolderOutput%
rmdir /f %FolderOutput%
:: CREATE THE DIRECTORY IF IT DOES NOT EXIST
mkdir %FolderOutput%
:: Action !!!
%PerlBin% %PerlScript% %InputMetaFile% %FolderOutput%
::debug
pause
:: VersionHistory:
:: 1.0.20101001_213742 --- Yordan Georgiev -- Initial creation. Input meta data parsing and debugging
:: 1.1.20101001_221209 --- Yordan Georgiev --- Print Select All per table with Schema . OK
:: END ================== Generate_SelectAll.1.1.cmd
:: START ===== Generate_SelectAll.1.1.pl
use strict ;
package Test ;
my $FileInputForMetaData = $ARGV[0] ;
my $FolderOutput = $ARGV [1] ;
sub main
{
#read the input metadata file
my @ArrayInputFile = ReadInputMetaDataFile();
#FOREACH LINE OF THE FILE DO SOMETHING
my $OldTableName = '' ;
my $ColList = '' ;
foreach my $line ( @ArrayInputFile )
{
#debug print "$line" ;
my ( $DbName , $SchemaName , $TableName , $ColName ) = split("\t" , $line ) ;
chop ( $ColName ) ;
#debug print " \$DbName , \$SchemaName , \$TableName , \$ColName \n" ;
#debug print " $DbName , $SchemaName , $TableName , $ColName \n " ;
if ( $TableName eq $OldTableName )
{
#debug print "old Table " ;
$ColList = $ColList . ' , ' . "[$ColName]" ;
} #eof if
else
{
GenerateSql($DbName , $SchemaName , $OldTableName , $ColList);
#debug print "New Table ! \n " ;
$ColList= '' ;
$ColList = "[$ColName]" ;
} #eof else
$OldTableName = $TableName ;
} #eof foreach line
# END FOREACH LINE
}
# =========================================== eof sub main
sub ReadInputMetaDataFile
{
#READ ALL ROWS OF A FILE TO ALIST
open (FILEINPUTFORMETADATA, "<$FileInputForMetaData") || print "could not open the \$FileInputForMetaData $FileInputForMetaData!\n"; my @arrayInputFile =
close FILEINPUTFORMETADATA;
return @arrayInputFile ;
}
# =========================================== eof sub ReadInputMetaDataFile
sub GenerateSql
{
my $DbName = shift ;
my $SchemaName = shift ;
my $TableName = shift ;
my $ColList = shift ;
if ( trim($TableName) eq '' )
{ return ; }
#$ColList= substr( $ColList , 0 , length($ColList ) - 2 ) ;
my $SqlString =
"SELECT $ColList FROM $DbName\.$SchemaName\.[$TableName] ;\n " ;
my $FileOutput="$FolderOutput/$DbName\.$SchemaName\.$TableName\.SelectAll\.Script\.sql" ;
#READ ALL ROWS OF A FILE TO ALIST
open (FILEOUTPUT, ">$FileOutput") ||
print "could not open the \$FileOutput $FileOutput!\n";
print FILEOUTPUT $SqlString ;
close FILEOUTPUT ;
#debug print $SqlString ;
}
# =========================================== eof sub GenerateSql
sub trim
{
my $string = shift ;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string ;
}
# =========================================== eof sub trim
# Action !!!
main() ;
1 ;
__END__
# VersionHistory:
# 1.1.20101001_222618 --- Yordan Georgiev --- Generates Select All with full [] column list from Table
:: END ================== Generate_SelectAll.1.1.pl
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!