Jim Weirich wrote:

> On Wed, 2002-10-16 at 19:05, Michael Schuerig wrote:
> 
>> The first problem is that I can't convince Pg to switch autocommit
>> mode off. All I get is "'autocommit' is not a valid option name", no
>> matter if I do it via DBI or in psql.
> 
> This works for me with DBI ...
> 
>     dbh['AutoCommit'] = false

Doesn't work for me, although I'm sure it should. I have no idea what's 
going wrong.


> The key is that when the DB handle is in auto-commit mode, it will not
> automatically insert the BEGIN/END statements.  The transaction method
> should (but doesn't) disable auto-commit internally.
> 
> My work around was to do this ...
> 
>    def f(db)
>      ac = db['AutoCommit']
>      db['AutoCommit'] = false
>      db.transaction {
>        # ... do database stuff ...
>      }
>    ensure
>      db['AutoCommit'] = ac
>    end

Alternatively, the same could be done elegantly with more general 
version of fluid by Brian Marick:

    def f(db)
      Fluid.let(["db['AutoCommit']", false]) {
        db.transaction {
          # ... do database stuff ...
        }
      }
    end

As it is, the code above does not work. The general intention of 
Fluid.let is to change the value of a global variable for the duration 
of a block. I'd really like to see a facility for this in the standard 
lib.


Michael

-- 
Michael Schuerig ? ? ? ? ? ? ? ? ?If at first you don't succeed...
mailto:schuerig / acm.org? ? ? ? ? ?try, try again.
http://www.schuerig.de/michael/? ?--Jerome Morrow, "Gattaca"