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

Lars Olsson lasso at lassoweb.nu
Mon Jan 23 05:34:36 EST 2006


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'

# 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.save
end
</snip>

The program generates the following output:

<snip>
I, [2006-01-21T12:36:54.953000 #1820]  INFO -- : Og uses the Sqlite store.
I, [2006-01-21T12:36:55.015000 #1820]  INFO -- : Cannot drop 'db1'!
D, [2006-01-21T12:36:55.046000 #1820] DEBUG -- : Og manageable classes: []
I, [2006-01-21T12:36:55.046000 #1820]  INFO -- : Og uses the Sqlite store.
I, [2006-01-21T12:36:55.046000 #1820]  INFO -- : Cannot drop 'db2'!
D, [2006-01-21T12:36:55.062000 #1820] DEBUG -- : Og manageable classes: []
I, [2006-01-21T12:36:55.078000 #1820]  INFO -- : Created table 'ogfoo'.
D, [2006-01-21T12:36:55.078000 #1820] DEBUG -- : INSERT INTO ogfoo 
(bar,baz,oid) VALUES ('Ten',10,NULL)
D, [2006-01-21T12:36:55.078000 #1820] DEBUG -- : INSERT INTO ogfoo 
(bar,baz,oid) VALUES ('Twenty',20,NULL)
D, [2006-01-21T12:36:55.078000 #1820] DEBUG -- : INSERT INTO ogfoo 
(bar,baz,oid) VALUES ('Thirty',30,NULL)
D, [2006-01-21T12:36:55.093000 #1820] DEBUG -- : INSERT INTO ogfoo 
(bar,baz,oid) VALUES ('Forty',40,NULL)
D, [2006-01-21T12:36:55.093000 #1820] DEBUG -- : SELECT * FROM ogfoo
e:/program/ruby/lib/ruby/gems/1.8/gems/og-0.27.0/lib/og/store/sql.rb:314: 
warning: already initialized constant OGTABLE
D, [2006-01-21T12:36:55.109000 #1820] DEBUG -- : Table already exists
Classes managed by db1:
Classes managed by db2: Foo
D, [2006-01-21T12:36:55.109000 #1820] DEBUG -- : UPDATE ogfoo SET 
bar='Ten', baz=10 WHERE oid=1
D, [2006-01-21T12:36:55.109000 #1820] DEBUG -- : UPDATE ogfoo SET 
bar='Twenty', baz=20 WHERE oid=2
D, [2006-01-21T12:36:55.109000 #1820] DEBUG -- : UPDATE ogfoo SET 
bar='Thirty', baz=30 WHERE oid=3
D, [2006-01-21T12:36:55.109000 #1820] DEBUG -- : UPDATE ogfoo SET 
bar='Forty', baz=40 WHERE oid=4
</snip>

The problem is that even if db2 is managing Foo object, Og still updates 
db1. db2 just ends up empty. I'm not entirely sure whether this is a bug 
or by design, but it sure is confusing. Can anyone please clarify this 
for me? Am I doing something wrong or is this a bug?


Kindly

/Lars

-- 
________________________________________
Lars Olsson
lasso at lassoweb.nu
http://www.lassoweb.nu/




-- 
________________________________________
Lars Olsson
lasso at lassoweb.nu
http://www.lassoweb.nu/



More information about the Nitro-general mailing list