slayedbylucifer has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I ma trying to uplaod a CSV into Oracle Databse, the problem is, my script gets stuck and I have to kill it with CTRL+C.. Here is hte csv:
# cat test.csv vm,farm,dmz name1,farm1,z1 name2,farm2,z2 name3,farm3,z3
and here is the code:
#!/usr/bin/perl -w use strict; use DBI; open (my $FH, '<', "test.csv") or die "Cannot open test.csv: $! \n"; my $dbh = DBI->connect ("dbi:Oracle:host=<hostname>;sid=<SID>", '<user +name>', ',password.', { RaiseError => 1, AutoCommit => 1, TraceLevel +=> 4}) or die "Canot create Databse Handle: $DBI::err +str() \n"; my $table = "CLUSTER_MAPPING"; my @array = <$FH> ; close $FH; shift @array; ### this is to remove the column headers my $sth = $dbh->prepare ("INSERT INTO $table (name, farm, dmz) VALUES +(?,?,?)"); while (<@array>) { my @row = split /,/; my $col1_value = $row[0]; my $var1 = $row[1]; $var1 =~ s/"//g; $var1 =~ s/^ //g; my $col2_value = $var1; my $col3_value = $row[2]; $sth->execute ($col1_value, $col2_value, $col3_value); } $sth->finish(); $dbh->disconnect();
here is the debug output from the script ( i have used level 2 as seen in AutoCommit => 2):
DBI::db=HASH(0x228e560) trace level set to 0x0/2 (DBI @ 0x0/0) in +DBI 1.622-ithread (pid 15876) -> STORE for DBD::Oracle::db (DBI::db=HASH(0x228e560)~INNER 'Usern +ame' '<username>') thr#21f5010 <- STORE= 1 at DBI.pm line 713 -> connected in DBD::_::db for DBD::Oracle::db (DBI::db=HASH(0x228 +e5f0)~0x228e560 'dbi:Oracle:host=<hostname>;sid=<SID>' '<username>' * +*** HASH(0x2401778)) thr#21f5010 <- connected= undef at DBI.pm line 720 -> STORE for DBD::Oracle::db (DBI::db=HASH(0x228e560)~INNER 'dbi_c +onnect_closure' CODE(0x228de28)) thr#21f5010 <- STORE= 1 at DBI.pm line 729 -> prepare for DBD::Oracle::db (DBI::db=HASH(0x228e5f0)~0x228e560 +'INSERT INTO CLUSTER_MAPPING (name, farm, dmz) VALUES (?,?,?)') thr#2 +1f5010 dbd_preparse scanned 3 distinct placeholders <- prepare= DBI::st=HASH(0x228e938) at upload.pl line 17 -> execute for DBD::Oracle::st (DBI::st=HASH(0x228e938)~0x228e980 +'name1' 'farm1' 'z1') thr#21f5010 dbd_bind_ph(1): bind :p1 <== 'name1' (type 0 (DEFAULT (varchar))) dbd_rebind_ph_char() (1): bind :p1 <== 'name1' (size 28/32/0, ptype 5( +VARCHAR), otype 1 ) dbd_bind_ph(1): bind :p2 <== 'farm1' (type 0 (DEFAULT (varchar))) dbd_rebind_ph_char() (1): bind :p2 <== 'farm1' (size 25/32/0, ptype 5( +VARCHAR), otype 1 ) dbd_bind_ph(1): bind :p3 <== 'z1' (type 0 (DEFAULT (varchar))) dbd_rebind_ph_char() (1): bind :p3 <== 'z1' (size 24/32/0, ptype 5(VAR +CHAR), otype 1 ) dbd_st_execute INSERT (out0, lob0)... Statement Execute Mode is 32 (COMMIT_ON_SUCCESS)
After this, the script gets stuck at inserting the 1st record and then I have to kill it.
Could you tell me what I am doing wrong here. I think I have missed something obvious but not able to figure out that.
-Thanks.
|
|---|