Sha256: f3d0cf79668e29b4bbc83314878dd3c37607265de285efce215d2dd4d8a03f33

Contents?: true

Size: 1.62 KB

Versions: 20

Compression:

Stored size: 1.62 KB

Contents

class TestPostgresTransaction < DBDConfig.testbase(:postgresql)
    def test_rollback
        dbh = get_dbh
        dbh["AutoCommit"] = false
        @sth = dbh.prepare('insert into names (name, age) values (?, ?)')
        @sth.execute("Foo", 51)
        dbh.rollback
        assert_equal 1, @sth.rows
        @sth.finish


        @sth = dbh.prepare('select name, age from names where name=?')
        @sth.execute("Foo")
        assert !@sth.fetch
        @sth.finish
        dbh.disconnect 
    end

    def test_commit
        dbh = get_dbh
        dbh["AutoCommit"] = false
        @sth = dbh.prepare('insert into names (name, age) values (?, ?)')
        @sth.execute("Foo", 51)
        dbh.commit
        assert_equal 1, @sth.rows
        @sth.finish
        
        @sth = dbh.prepare('select name, age from names where name=?')
        @sth.execute("Foo")
        row = @sth.fetch
        assert row
        assert_equal "Foo", row[0]
        assert_equal 51, row[1]
        @sth.finish
        dbh.disconnect 
    end

    def test_select_transaction
        # per bug #10466
        dbh = get_dbh
        dbh["AutoCommit"] = false
        @sth = dbh.prepare('select * from test_insert(?, ?)');
        @sth.execute("Foo", 51)
        dbh.rollback
        @sth.finish

        @sth = dbh.prepare('select name, age from names where name=?')
        @sth.execute("Foo")
        assert !@sth.fetch
        @sth.finish
        dbh.disconnect 
    end

    def get_dbh
        config = DBDConfig.get_config
        DBI.connect("dbi:Pg:#{config['postgresql']['dbname']}", config['postgresql']['username'], config['postgresql']['password'])
    end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
ydbd-pg-0.6.0 test/dbd/postgresql/test_transactions.rb
ydbi-0.6.0 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.9 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.8 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.7 test/dbd/postgresql/test_transactions.rb
ydbi-0.5.7 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.6 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.5 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.4 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.3 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.2 test/dbd/postgresql/test_transactions.rb
ydbd-pg-0.5.1 test/dbd/postgresql/test_transactions.rb
ydbi-0.5.0 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.9 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.8 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.3 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.4 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.5 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.6 test/dbd/postgresql/test_transactions.rb
dbd-pg-0.3.7 test/dbd/postgresql/test_transactions.rb