C
Cheez
Hi there, I am using a pretty basic Perl script to read data from a
file into a mysql table. I have no provisions in my SQL statement to
deal with duplicate entries. In this situation, I want to increment a
frequency counter.
#My main SQL syntax is this:
INSERT INTO mytable (wherefound, sequence)
VALUES (?, ?)
# I would like to do this (but doesn't work):
INSERT INTO mytable (wherefound, sequence) VALUES (?,?)
-> ON DUPLICATE KEY UPDATE frequency=frequency+1
The 'sequence' field is the one that I want to check for duplicates
and then increment the 'frequency' field by one. If someone could
offer up any pointers I would be very much obliged.
Thanks,
Cheez
#code below:
print "\nINSERTER_SEQUENCE: insert processed sequence data into
sequence5 table\n";
use DBI;
my $dbh = DBI->connect("dbi:mysql:mydatabase", "", "");
my $sth = $dbh->prepare(<<SQL);
INSERT INTO mytable (wherefound, sequence)
VALUES (?, ?)
SQL
open(FILE, "seqparsed.txt");
while (my $data = <FILE>) {
my ($wherefound,$sequence) = split /\t/, $data;
$sth->execute($wherefound,$sequence);
}
close (FILE);
file into a mysql table. I have no provisions in my SQL statement to
deal with duplicate entries. In this situation, I want to increment a
frequency counter.
#My main SQL syntax is this:
INSERT INTO mytable (wherefound, sequence)
VALUES (?, ?)
# I would like to do this (but doesn't work):
INSERT INTO mytable (wherefound, sequence) VALUES (?,?)
-> ON DUPLICATE KEY UPDATE frequency=frequency+1
The 'sequence' field is the one that I want to check for duplicates
and then increment the 'frequency' field by one. If someone could
offer up any pointers I would be very much obliged.
Thanks,
Cheez
#code below:
print "\nINSERTER_SEQUENCE: insert processed sequence data into
sequence5 table\n";
use DBI;
my $dbh = DBI->connect("dbi:mysql:mydatabase", "", "");
my $sth = $dbh->prepare(<<SQL);
INSERT INTO mytable (wherefound, sequence)
VALUES (?, ?)
SQL
open(FILE, "seqparsed.txt");
while (my $data = <FILE>) {
my ($wherefound,$sequence) = split /\t/, $data;
$sth->execute($wherefound,$sequence);
}
close (FILE);