|
From: Michael N. <uu...@rz...> - 2002-09-18 08:12:33
|
Sean Chittenden wrote:
> I've got a pretty interesting problem in that I'm dynamically creating
> a database using Ruby. I've got something of a problem though with
> the way that transactions are handled with the execute() methods in
> that they always prepend BEGIN WORK; if you're outside of a
> transaction. There are a couple of workarounds for this, but none of
> them elegant or correct, IMHO.
>
> *) What I'm doing now:
>
> dbh.do('ABORT; #{sql}; COMMIT; BEGIN;')
>
> It's super ugly, but it works insofar as it keeps the database in
> sync with DBI.
>
> *) A possible hack would be to add :in_transaction as an accessor:
>
> # make sure you're currently outside of a transaction
> dbh.in_transaction = true
> dbh.do(sql)
> dbh.in_transaction = false
>
> *) Another option would be to create something parallel to #do, only
> have it skip the write-through transaction bits.
>
> dbh.do_exec(sql)
>
> *) The most elegant and likely correct solution would be to add
> another options tunable that would let #do omit adding a 'BEGIN
> WORK;' to every command.
>
> dbh['AutoBegin'] = false
> dbh.do(sql)
> dbh.commit
Have you tried the following?
dbh['AutoCommit'] = false
If this was set to false, no commit should be issued automatically!
You can also disable AutoCommit from the beginning on:
dbh = DBI.connect("dbi:xxxx", "user", "pw", "AutoCommit" => false)
Hope this helps!
Regards,
Michael
|