The following code works fine on my local machine, but it inserts duplicate records on my shared server. I am starting with a CSV file that contains 40,000 records, of which I only want to insert 7,000--my stored procedure decides if a record gets inserted or not. The server is usually inserting about 10,000 records, 3,000 of which are duplicates. I am calling the perl script as a cgi script. This is a mystery to me. (Local machine: Vista/MS SQL 2k5/ODBC DSN, Server: MS Server 2K3/MS SQL 2K5/ODBC DSN). Thanks for your help.
use DBI;
my $dbh = DBI->connect( "$dbServer", "$dbUser", "$dbPass" ) or print "
+Could not make connection to database";
open(DAILY, "$updateDir/$fileName") || print "CAN'T OPEN DAILY";
while(<DAILY>){
chomp;
my ($field1,$field2,$field3,$field3,$field4,$field5,$field6,$field
+7,$field8) = split(/,/);
if ($field1 == 33){
my $spQuery = "exec my_sp ?,?,?,?,?,?,?";
$insert33 = $dbh->prepare( $spQuery ) or die ( "Cannot
+ prepare statement: ", $dbh->errstr(), "\n" );
$insert33->execute($field1,$field2,$field3,$field4,$fi
+eld5,$field6,$field7)
or die( "Cannot execute statement: ", $insert33->errst
+r(), "\n" );
$insert33->finish();
}
}
close(DAILY);
code for stored proc
@field1 AS INTEGER,
@field2 AS DATETIME,
@field3 AS MONEY,
@field4 AS MONEY,
@field5 AS MONEY,
@field6 AS MONEY,
@field7 AS INTEGER
AS
BEGIN
DECLARE @check1 INT
SET @check1 = 0
SELECT @check1 = col1 FROM tableX
WHERE col3 = @field1
IF @check1 > 0
BEGIN
INSERT INTO priceHistory
(col1,col2,col3,col4,col5,col6,col7)
VALUES
(@field1,@field2,@field3,@field4,@field5,@field6,@field7)
END
END
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.