[Nitro] Og - Unexspected results when using two Sqlite3 stores

Bryan Soto bryan.a.soto at gmail.com
Mon Jan 23 19:19:07 EST 2006


Hi,

On 1/23/06, Lars Olsson <lasso at lassoweb.nu> wrote:
>
>
> Hi all,
>
> I recently discovered Og and started playing around with it. Very cool
> stuff!
>
> However, when trying to work with two Sqlite3 stores in the same program
> I ran into some unexspected trouble. After reading through an example on
> the website (http://repo.nitrohq.com/og/examples/mysql_to_psql.rb) I
> wanted to try creating something similar myself. I came up with the
> following:
>
> <snip>
> # Turn on Og debugging
> $DBG = true
>
> # Require necessary modules
> require 'rubygems'
> require 'og'


# Added
Og.thread_safe = false # So Og doesn't pool  the first setup.

# Set up stores
> db1 = Og.setup(:destroy => true, :name => 'db1', :store => 'sqlite')
> db2 = Og.setup(:destroy => true, :name => 'db2', :store => 'sqlite')
>
> # Define example class
> class Foo
>         property :bar, String
>         property :baz, Fixnum
>
>         def initialize(bar, baz)
>                 @bar = bar
>                 @baz = baz
>         end
> end
>
> # Let the first store manage Foo objects
> db1.manage(Foo)
>
> # Create some Foo objects
> Foo.create('Ten', 10)
> Foo.create('Twenty', 20)
> Foo.create('Thirty', 30)
> Foo.create('Forty', 40)
>
> # Fetch all Foo objects from the first store
> coll = Foo.all
>
> # Don't let the first store manage Foo objects anymore
> db1.unmanage_class(Foo)
>
> # Let the second store manage Foo objects
> db2.manage(Foo)
>
> # Print out the classes managed by each store
> puts "Classes managed by db1: #{db1.managed_classes}"
> puts "Classes managed by db2: #{db2.managed_classes}"
>
> # Save all Foo objects in the second store
> # This doesn't work! Og updates the first store, not the second!
> coll.each do |f|


            f.insert  # changed to this from #        f.save

end
> </snip>
>
> The program generates the following output:
>
> <snip>


 I, [2006-01-23T15:59:50.417551 #6085]  INFO -- : Og uses the Sqlite store.
D, [2006-01-23T15:59:50.866242 #6085] DEBUG -- : Og manageable classes: []
I, [2006-01-23T15:59:50.866801 #6085]  INFO -- : Og uses the Sqlite store.
D, [2006-01-23T15:59:50.875152 #6085] DEBUG -- : Og manageable classes: []
I, [2006-01-23T15:59:51.639264 #6085]  INFO -- : Created table 'ogfoo'.
D, [2006-01-23T15:59:51.861332 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Ten',10,NULL)
D, [2006-01-23T15:59:52.222801 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Twenty',20,NULL)
D, [2006-01-23T15:59:52.578944 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Thirty',30,NULL)
D, [2006-01-23T15:59:52.913715 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Forty',40,NULL)
D, [2006-01-23T15:59:53.220872 #6085] DEBUG -- : SELECT * FROM ogfoo
/usr/lib/ruby/gems/1.8/gems/og-0.27.0/lib/og/store/sql.rb:314: warning:
already initialized constant OGTABLE
I, [2006-01-23T15:59:53.709571 #6085]  INFO -- : Created table 'ogfoo'.
Classes managed by db1:
Classes managed by db2: Foo
D, [2006-01-23T15:59:53.713887 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Ten',10,1)
D, [2006-01-23T15:59:54.177731 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Twenty',20,2)
D, [2006-01-23T15:59:54.483771 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Thirty',30,3)
D, [2006-01-23T15:59:55.231459 #6085] DEBUG -- : INSERT INTO ogfoo
(bar,baz,oid) VALUES ('Forty',40,4)


Hope that helps,

Bryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20060123/c29ee985/attachment.html 


More information about the Nitro-general mailing list