[Nitro] Request for Transaction example

Reid Thompson Reid.Thompson at ateb.com
Mon Jun 4 16:34:57 EDT 2007


On Mon, 2007-06-04 at 23:22 +0300, Jonathan Buch wrote:
> Hi,
> 
> Loadtbl.transaction do |store|
> 
> > myfile.each_line {|line|
> >     tbl = Loadtbl.new
> >     tbl.save
> > }
> 
> end
> 
> Jo
> 
Ok mod'ed to...

db = Og.setup(og_psql)

store = db.get_store
myfile = File.open("/home/rthompso/reid")
Loadtbl.transaction do |store|
    myfile.each_line {|line|
        date, ts, type, telno,t2, location, calltype, fa, fn, result = line.split(' ')

        tbl = Loadtbl.new
        tbl.date = date
        tbl.ts = ts
        tbl.type = type
        tbl.telno = telno + t2
        tbl.location = location
        tbl.calltype = calltype
        tbl.fa = fa
        tbl.fn = fn
        tbl.result = result
        tbl.save
    }
end

It still appears to be committing on each save -- if all records were in
a single transaction, no rows should be present until the final commit
-- correct????  

yet...

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 31692
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 32055
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 32293
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 32611
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 32985
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 33431
(1 row)

rthompso at jhereg:~$ psql -U rthompso -c "select count(*) from tbl4" test
 count 
-------
 33883
(1 row)


More information about the Nitro-general mailing list