[erlang-questions] Parametrized queries in mysql-otp

Fabio Souto Fabio.Souto@REDACTED
Tue Jun 9 11:42:02 CEST 2015


Hello fellows,

I’m implementing a project that uses mysql-otp for some of its components.
At one point, I have to do an INSERT statement with an ON DUPLICATE KEY clause.
What happens is that on the ON DUPLICATE KEY statement, I only want to use the last parameter of the parameter list I provide in the query() call.
I can’t find a way to name parameters in the parametrized query.  Was wondering if anyone had similar experience before.

Below follows a generic example of what I’m trying to achieve.

ok = mysql_poolboy:query(?DB_POOL_NAME, 
"INSERT INTO `X` (`a`, `b`, `c`, `d`, `e`) VALUES (?, ?, 1, 0, ?) 
 ON DUPLICATE KEY 
 UPDATE c = c + 1, d = 0, e = ?", 
[A, B, C]);

I want e = C, in the duplicate key statement. Right now, as it is, I’m not sure of what the behaviour will be, but e will probably be e = A.

Cheers,
-- 
Fábio S.

Team Rocket

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150609/d72f0361/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4287 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150609/d72f0361/attachment.bin>


More information about the erlang-questions mailing list