Home > Archive > MySQL ODBC Connector > January 2006 > insert...on duplicate key update...help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author insert...on duplicate key update...help
Jonathan Mangin

2006-01-26, 4:56 pm

I'm trying to change a couple of replace statements to
insert...on duplicate key update (using Perl/DBI).

foreach my $key (keys %e_items) {
my $sql = "insert table1
(id, date, time, uid, type, seq, value)
values
(?, ?, ?, ?, ?, ?, ?)
on duplicate key update";
my $sth = $dbh->prepare($sql);
$sth->execute($e_items{$key}->[0], $date, $e_items{$key}->[3],
$uid, $e_items{$key}->[1], $e_items{$key}->[2],
$e_items{$key}->[4]) || die $sth->errstr;
}

The manual says more is needed at the end of my sql, but
I'm not sure of the syntax. (Looks to me like all required
info is present ;) id is primary key and the only unique
index.

Thanks,
Jon


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql? unsub...sie.nctu.edu.tw

Gleb Paharenko

2006-01-26, 4:56 pm

Hello.

Perhaps you have forgotten to add col_name=expr to the end of your
query. See:
http://dev.mysql.com/doc/refman/5.0/en/insert.html



Jonathan Mangin wrote:
> I'm trying to change a couple of replace statements to
> insert...on duplicate key update (using Perl/DBI).
>
> foreach my $key (keys %e_items) {
> my $sql = "insert table1
> (id, date, time, uid, type, seq, value)
> values
> (?, ?, ?, ?, ?, ?, ?)
> on duplicate key update";
> my $sth = $dbh->prepare($sql);
> $sth->execute($e_items{$key}->[0], $date, $e_items{$key}->[3],
> $uid, $e_items{$key}->[1], $e_items{$key}->[2],
> $e_items{$key}->[4]) || die $sth->errstr;
> }
>
> The manual says more is needed at the end of my sql, but
> I'm not sure of the syntax. (Looks to me like all required
> info is present ;) id is primary key and the only unique
> index.
>
> Thanks,
> Jon
>



--
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.NET http://www.ensita.net/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Gleb Paharenko
/ /|_/ / // /\ \/ /_/ / /__ Gleb.Paharenko@stripped
/_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.NET
<___/ www.mysql.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql? unsub...sie.nctu.edu.tw

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com