All I'm having a problem with my while loop. It reads the data out of the file and displays the first record of the array for until the end-of-file.
However, I cannot get it to insert this value into the table. Any guidence would be helpful.
Thanks,
Bobby
#!/usr/bin/perl
#
#Connects to a Sybase Database
use DBI; #Loads DBI module
#Connect using ARSAMSDBA....
my $dbh = DBI->connect("dbi:ODBC:usamma", "arsamsdba", "arsamssql", {
PrintError => 0,
RaiseError => 0
}) or die "Can't connect to database: $DBI::errstr\n";
#Prepare Create Parser Table statement....
my $sth = $dbh->prepare("CREATE TABLE PARSER_TABLE
(
NIIN char(9) NOT NULL,
FSC char(4) NOT NULL,
PRIME_NSN varchar(16) NULL,
MATCAT char(5) NULL,
SOS char(3) NULL,
DML char(1) NULL,
EC char(1) NULL,
RICC char(1) NULL,
ARC char(1) NULL,
SCIC char(1) NULL,
AAC char(1) NULL,
LCC char(1) NULL,
PHC varchar(1) NULL,
RC char(1) NULL,
SCMC char(2) NULL,
AMDF_PRICE varchar(20) NULL,
CRED_SERV varchar(20) NULL,
CRED_UNSERV varchar(20) NULL,
UI char(2) NULL,
UM char(2) NULL,
MEAS_QTY varchar(20) NULL,
ARI char(1) NULL,
MR char(1) NULL,
Nomen char(21) NULL,
EIC char(3) NULL,
CIIC char(1) NULL,
LIN char(6) NULL,
smr_cd varchar(5) NULL,
WRTY char(1) NULL,
WSC char(3) NULL,
model varchar(50) NULL,
Notes varchar(128) NULL,
DEMIL char(1) NULL
)"
) or die "Can't prepare SQL statement: $DBI::errstr\n";
#Excute Create Table statement....
$sth->execute or die "Can't execute SQL statment: $DBI::errstr\n";
#Disconnect ARSAMSDBA.....
$dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n";
#Connect using DBA (Opens DB Handle)....
$dbh = DBI->connect("dbi:ODBC:usamma", "dba", "sql", {
PrintError => 0,
RaiseError => 0
}) or die "Can't connect to database: $DBI::errstr\n";
#Execute to delete records from arsamsdba.parser_table....
my $sth0 = $dbh->do("DELETE arsamsdba.PARSER_TABLE") or die "Can't pre
+pare SQL statement: $DBI::errstr\n";
#Prepare for input into arsamsdba.parser_table....
my $sth1 = $dbh->prepare("INSERT INTO ARSAMSDBA.PARSER_TABLE (NIIN) VA
+LUES (?)");
my $sth2 = $dbh->prepare("commit");
open AFH, "D:/WorkingFiles/Scripts/perl/amdfdata.txt" or die "Can't op
+en D:/WorkingFiles/Scripts/perl/amdfdata.txt: $!\n";
while(!eof AFH)
{
my $line = <AFH>; #take in new line
chomp;
#trim leading (and trailing) quotes
$line =~ s/^\"//;
@row=split(/\"[^\"]\"\,{0,1}/,$line);
print "$row[0]\n";
$sth1->bind_param(1, $niin);
$sth1->execute($row[0]);
}
$sth2->execute();
close AFH or warn "Can't close D:/WorkingFiles/Scripts/perl/amdfdata.t
+xt: $!\n";
$dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n";
exit;
#, FSC, PRIME_NSN, MATCAT, SOS, DML, EC, RICC, ARC, SCIC, AAC, LCC,PHC
+, RC, SCMC, AMDF_PRICE, CRED_SERV, CRED_UNSERV, UI, UM, MEAS_QTY, AR
+I, MR, #NOMEN, EIC, CIIC, #LIN, DEMIL)
# VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
+,?,?,?,?)");
#$niin, $fsc, $prime_nsn, $matcat, $sos, $dml, $ec, $ricc, $arc, $scic
+, $aac, $lcc, $phc, $rc, $scmc, $amdf_price, $cred_serv,
#$cred_unserv, $ui, $um, $meas_qty, #$ari, $mr, $nomen, $eic, $ciic, $
+lin, $demil);