I grappled with a similar problem, helped by monks. The first thread of interesting advice is
here. At the end of that my conclusion was to use the following sledgehammer:
$dbh->do("LOCK TABLES tbl WRITE");
$dbh->do("$various_sql_stuff_without_getting_tangled");
$dbh->do("UNLOCK TABLES");
to crack a nut. Which I found works.
Then I mentioned this in
another thread and
htoug said some very interesting things, which to my shame I have not yet followed up; but when I revisit the MySQL aspects of my current project I shall try to slim them down, using his advice.
When I do that, I shall of course return to this thread too, where I confidently expect to find the optimal synthesis of former wisdom.
§
George Sherston