11 if ($cmdpath eq "") { $cmdpath="./"; }
12 unshift(@INC,$cmdpath."lib");
18 print "USAGE: wizard.pl dsn user passwd table dir\n";
22 $dsn=shift(@ARGV) || &USAGE;
23 if (($dsn eq "-h") || ($dsn eq "--help")) { &USAGE; }
24 $user=shift(@ARGV) || &USAGE;
25 $passwd=shift(@ARGV) || &USAGE;
26 if ($passwd eq "-") { $passwd=""; }
27 $table=shift(@ARGV) || &USAGE;
28 $dir=shift(@ARGV) || &USAGE;
30 $dbh=DBI->connect($dsn,$user,$passwd);
32 print "Error: cannot connect $dsn\n";
36 $tables=$dbh->table_info;
37 while ($hash=$tables->fetchrow_hashref) {
38 #print $$hash{'TABLE_NAME'}."\n";
40 if ($$hash{'TABLE_NAME'} eq $table) {
42 $sth=$dbh->prepare("show fields from ".$$hash{'TABLE_NAME'});
44 while ($fieldhash=$sth->fetchrow_hashref) {
45 #print "\t".$$fieldhash{'Field'}.":".$$fieldhash{'Type'}."\n";
46 push(@data,[$$fieldhash{'Field'},$$fieldhash{'Type'}]);
52 $$env{'fields'}{'_data'}=\@data;
53 $$env{'fields'}{'_pos'}=0;
54 $$env{'fields'}{'_size'}=scalar(@data);
56 $$env{'tablename'}=$table;
58 print "prosessing files in $dir\n";
62 if (opendir(DIR,".")) {
63 while ($file=readdir(DIR)) {
64 next unless (-f $file);
65 if ($file=~/\.template$/) {
67 print "\t$file -> $newfile\n";
69 if (open(OUT,">$newfile")) {
70 &Subst::process(*IN,*OUT,$env);