Please help--thanks...if ($UserFile) { print start_html(); # reads the log file and creates a SQL string. The string holds th +e data to create each column # in the table... # This part reads one line of the file and creats a column in a table +for each space-separated item. CreateTable(); $dbh = open_dbi(); my $sth = $dbh->prepare("CREATE TABLE $TableName ($SQLString)") or + err_trap("Cannot prepare the load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to CREATE +TABLE"); open IN, "$UserFile"; $z = 0; $B = "\'"; Delimiter(); # I believe this is the problem, but not sure how to fix... while (<IN>) { $TheRec = $_; @NewItem = (); $SQLString = "\'"; $z = 0; chomp $TheRec; @NewItem = split(/$FileDelimiter/, $TheRec); #split the + line in records by space while ($NewItem[$z]) { $SQLString = $SQLString . $NewItem[$z] . "\',\'"; $z=$z + 1; } # removes the trailing comma from the end of the line $LineLength = length($SQLString); $LineLength = $LineLength -2; $SQLString = substr($SQLString,0,$LineLength); my $sth = $dbh->prepare("INSERT INTO $TableName VALUES($SQLSt +ring)") or err_trap("Cannot prepare the load_category_names query"); $sth->execute or err_trap("Cannot execute the SQL query to LOA +D DATA INFILE"); } close_dbi($dbh); } # In this section, I had the same problem, but I added if ($NewItem[$C +olumnNumber] eq 0) {$NewItem[$ColumnNumber] = O}; and the problem was + resolved--all required columns were created... sub CreateTable { $zzz=1; @NewItem = (); open LOGFILE, "$UserFile" or die "Cannot open file $UserFile"; Delimiter(); while (<LOGFILE>) { $TheRec = $_; chomp($TheRec); } $A =(); @NewItem = split(/$FileDelimiter/, $TheRec); #split the + line in records by space # sql code for each column is formed here $ColumnNumber=0; if ($NewItem[$ColumnNumber] eq 0) {$NewItem[$ColumnNumber] = O +}; while ($NewItem[$ColumnNumber]) { $SQLString = $SQLString . "$ColumnName[$ColumnNumber] CHAR +(255),"; $ColumnNumber = $ColumnNumber +1; } # removes the trailing comma from the end of the line $LineLength = length($SQLString); $LineLength = $LineLength -1; $SQLString = substr($SQLString,0,$LineLength); }
In reply to while(INFILE) terminating before finishing file. by sdyates
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |