    # File lib/amalgalite/database.rb, line 554
        def transaction( mode = TransactionBehavior::DEFERRED, &block )
          raise Amalgalite::Error, "Invalid transaction behavior mode #{mode}" unless TransactionBehavior.valid?( mode )

          # if already in a transaction, no need to start a new one.
          if not in_transaction? then
            execute( "BEGIN #{mode} TRANSACTION" )
          end

          if block_given? then
            begin
              previous_exception = $!
              return ( yield self )
            ensure
              if $! and ($! != previous_exception) then
                rollback
                raise $!
              else
                commit
              end
            end
          else
            return in_transaction?
          end
        end