On Tuesday, July 5, 2016 at 7:07:09 AM UTC, Andrey Stepnov wrote:
>
> Hi Ivar!
>
> There is no documentation about transactions for MySQL.jl. I understand 
> that it wrap C libs but it's not clear how to call transaction mechanism 
> from julia.
>

I do not know for sure about MySQL, as I'm a PostgreSQL guy, but it (as 
most databases, but not the standard?) starts in autocommit mode.

To start a transaction you do (these commands as any "other" query, not 
like INSERT is a query..):

BEGIN; -- OR BEGIN WORK; -- that may be in the standard way..

Then do your INSERTs (prepared statments can be better here for security 
but not speed, while can also help for speed in queries), e.g in a loop. 
This way you do not need individual multi-inserts.

COMMIT; -- OR COMMIT WORK; -- here ROLLBACK is an alternative (I guess with 
InnoDB, but not traditional MySQL).


This is independent of how you execute queries, but some database 
abstraction layers have something like beginTransation() etc. [This might 
be available in a database abstraction layer, those are a good idea anyway, 
as you do not want to be tied to MySQL.]

That isn't really needed; It doesn't do anything more complicated, unless 
you have nested transactions, that you probably do not need. You may want 
to loop up "mini-batching" also if you have a lot of inserts (pros and 
cons), that is if the database does not handle number of inserts.

I will be glad if you can provide very short explanation or example. 

-- 
Palli.

Reply via email to