[erlang-questions] Parametrized queries in mysql-otp

Hynek Vychodil vychodil.hynek@REDACTED
Tue Jun 9 13:50:51 CEST 2015


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, C]);

Doesn't work?

On Tue, Jun 9, 2015 at 11:42 AM, Fabio Souto <Fabio.Souto@REDACTED>
wrote:

> 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*
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150609/eb86bb97/attachment.htm>


More information about the erlang-questions mailing list