同时生成许多表格的程序

戻る

# make_ptables.pl # 生成零件Tables use strict; use DBI; my(%t,$n,@fld); print "This is make_ptables.pl.\n"; # 打开主机名文件 open(IN,"main_type1_tmp.txt") or die "Can't open the file main_type1_tmp.txt.\n"; while(<IN>){ chop; @fld = split(/==>/); next unless $fld[1]; $t{NO5} = sprintf("%06d",$fld[0]); push(@{ $t{ID} },$t{NO5}); } close(IN); # 连接数据库 $t{dsn} = "DBI:mysql:host=localhost;database=cookbook"; $t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n"; $t{dbh}->do("SET NAMES utf8"); if(!$t{dbh}){ print "SQL read ERROR!\n"; exit; } for $n ( 0 .. $#{ $t{ID} } ) { #for $n ( 0 .. 0 ) { $t{NO5} = $t{ID}[$n]; # # $t{table1} = 'a' . $t{NO5}; # $t{sql} = 'DROP TABLE IF EXISTS ' . $t{table1} . ';'; # $t{dbh}->do($t{sql}); # $t{sql} = 'CREATE TABLE ' . $t{table1}; # $t{sql} .= ' ('; # $t{sql} .= 'id INT AUTO_INCREMENT,'; # $t{sql} .= 'series VARCHAR(100),'; # $t{sql} .= 'group1 VARCHAR(100),'; # $t{sql} .= 'dwg1 VARCHAR(100),'; # $t{sql} .= 'memo TEXT,'; # $t{sql} .= 'PRIMARY KEY (id));'; # $t{dbh}->do($t{sql}); # $t{table2} = 'a' . $t{NO5}; $t{sql} = 'DROP TABLE IF EXISTS ' . $t{table2} . ';'; $t{dbh}->do($t{sql}); $t{sql} = 'CREATE TABLE ' . $t{table2}; $t{sql} .= ' ('; $t{sql} .= 'id INT AUTO_INCREMENT,'; $t{sql} .= 'name VARCHAR(50),'; $t{sql} .= 'code VARCHAR(50),'; $t{sql} .= 'group_id INT,'; $t{sql} .= 'dwg_id INT,'; $t{sql} .= 'price TEXT,'; $t{sql} .= 'oem TEXT,'; $t{sql} .= 'memo TEXT,'; $t{sql} .= 'PRIMARY KEY (id));'; $t{dbh}->do($t{sql}); print "The table $t{table2} is created.\n"; # print "The tables $t{table1} and $t{table2} are created.\n"; # print "The tables $t{table1} and $t{table2} are deleted.\n"; } $t{dbh}->disconnect; __END__;
戻る