From: Jim Weirich Date: 2002-10-17T14:26:41+09:00 Subject: Re: DBI:Pg 'autocommit' is not a valid option name > Jim Weirich wrote: > > This works for me with DBI ... > > dbh['AutoCommit'] = false On Thu, 2002-10-17 at 00:05, Michael Schuerig wrote: > Doesn't work for me, although I'm sure it should. I have no idea what's > going wrong. Here's the full script. This one was written against the Pg DBD. When the "fail" is triggered, the INSERT will be rolled back, as expected. #!/usr/bin/env ruby require 'dbi' db = DBI.connect("DBI:Pg:junk", "jim") fail "Usage: insert.rb first last" if ARGV.size != 2 first, last = ARGV begin db['AutoCommit'] = false db.transaction { db.do ("INSERT INTO people(first, last) VALUES (?,?)", first, last) fail if first == "John" } rescue RuntimeError => ex puts "Got Exception: #{ex}" end db['AutoCommit'] = true row = db.select_one( "SELECT first, last FROM people WHERE first = ? AND last = ?", first, last) if row.nil? puts "Insert failed" else puts "Inserted #{row[0]} #{row[1]}" end -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)