view · edit · sidebar · attach · print · history

20110124-setup-ramaze

<< Masa.20110125-setup-ramaze-setup-de_oddb-on-ubuntu | 2011 | Masa.20110121-setup-ramaze >>


  1. Summarize the Error in Ruby 1.9.2
  2. Check the process of creating a table in ODBA

Goal
  • Setup Ramaze version oddb / 60%
Milestones
Summary
Commits
ToDo Tomorrow
Keep in Mind
  1. Encoding woes (from Davatz-san)
  2. Feedback: This option indicates that the regular expression is parsed as 'UTF8' (from Davatz-san)
  3. pg on Ubuntu - see http://dev.ywesee.com/wiki.php/Gem/Pg (from Davatz-san)
  4. On Ice
  5. emerge --sync

Summarize the Error in Ruby 1.9.2

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/exec.rb

        def exec_prepared(stmt_name, parameters = nil)
print "@pg_conn.class="
p @pg_conn.class
print "stmt_name="
p stmt_name
print "parameters="
p parameters
            @pg_conn.exec_prepared(stmt_name, parameters)
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb 
masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb 
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:263267001295854189.9956114"
parameters=[]
ERROR:  relation "object" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:263241601295854189.9961154"
parameters=[]
ERROR:  relation "prefetchable_index" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262591001295854189.9964752"
parameters=[]
ERROR:  relation "extent_index" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262553801295854189.996887"
parameters=[]
ERROR:  relation "object_connection" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262426601295854189.997202"
parameters=[]
ERROR:  relation "target_id_index" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262310401295854189.9975603"
parameters=[]
ERROR:  relation "collection" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262268201295854189.997828"
parameters=["object"]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:262078601295854189.9994574"
parameters=["object"]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:261491001295854190.001187"
parameters=["object"]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:260885401295854190.0029678"
parameters=["__cache_server_indices__"]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:260814201295854190.0037463"
parameters=[]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:259961201295854190.005485"
parameters=[]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:259895001295854190.0064704"
parameters=[]
@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:259713201295854190.0074348"
parameters=[]
ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:259574601295854190.0078135"
parameters=[]
ERROR:  relation "oddb_business_company_name" already exists

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:71:in `rescue in execute': ERROR:  relation "oddb_business_company_name" already exists (DBI::ProgrammingError)
        from /usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:40:in `execute'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/base_classes/database.rb:101:in `execute'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/base_classes/database.rb:122:in `do'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:110:in `do'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:181:in `create_index'
        from /home/masa/ywesee/odba/lib/odba/index.rb:229:in `initialize'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:156:in `new'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:156:in `block in create_index'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:564:in `call'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:564:in `block in transaction'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:214:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:38:in `block in method_missing'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:26:in `next_connection'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:37:in `method_missing'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:560:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:530:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:142:in `create_index'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:131:in `block in create_deferred_indices'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:125:in `each'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:125:in `create_deferred_indices'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:447:in `setup'
        from /home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb:35:in `<module:ODDB>'
        from /home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb:28:in `<top (required)>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/model/init.rb:3:in `require'
        from /home/masa/ywesee/ramaze.ch.oddb.org/model/init.rb:3:in `<top (required)>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:32:in `require'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:32:in `<top (required)>'
        from start.rb:7:in `require'
        from start.rb:7:in `<main>'

Note

  • I cannot trace anymore than this place (PGconn#exec_prepared), because PGconn class is defined in C source code
 /usr/lib64/ruby/gems/1.9.1/gems/pg-0.10.1/ext/pg.c

Check the process of creating a table in ODBA

Memo

  • The error message comes from PostgreSQL, when it creates a new table on a database
  • That is why we should check the process of creating a table in ODBA
  • I do not know why and how but ODBA tries to create a new table every time when it starts
  • This does not make a sense

Trace the start up process of ODBA

Experiment

/home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb

module ODDB
  module Persistence
    module ODBA
    end
  end
  ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{@config.db_name}",
                                              @config.db_user, @config.db_auth)
#  ODBA.cache.setup
end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb 
/usr/lib64/ruby/gems/1.9.1/gems/ramaze-2010.06.18/lib/ramaze/view/haml.rb:1:in `require': no such file to load -- haml/util (LoadError)
        from /usr/lib64/ruby/gems/1.9.1/gems/ramaze-2010.06.18/lib/ramaze/view/haml.rb:1:in `<top (required)>'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/view.rb:55:in `const_get'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/view.rb:55:in `block in obtain'
        from <internal:prelude>:10:in `synchronize'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/state.rb:15:in `sync'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/view.rb:52:in `obtain'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/view.rb:43:in `get'
        from /usr/lib64/ruby/gems/1.9.1/gems/innate-2010.07/lib/innate/node.rb:223:in `provide'
        from /usr/lib64/ruby/gems/1.9.1/gems/ramaze-2010.06.18/lib/ramaze/controller.rb:58:in `engine'
        from /home/masa/ywesee/ramaze.ch.oddb.org/controller/init.rb:16:in `<class:Controller>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/controller/init.rb:4:in `<top (required)>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:33:in `require'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:33:in `<top (required)>'
        from start.rb:7:in `require'
        from start.rb:7:in `<main>'

Note

  • The error does not come, whic means the error happens in 'ODBA.cache.setup'

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#setup

  def setup
p "getin ODBA.cache.setup"
    ODBA.storage.setup
p "done ODBA.storage.setup"
      self.indices.each_key { |index_name|
        ODBA.storage.ensure_target_id_index(index_name)
      }
p "before create_deferred_indices"
      create_deferred_indices
p "after create_deferred_indices"
      nil
    end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb 
"getin ODBA.cache.setup"
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

"done ODBA.storage.setup"
ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

"before create_deferred_indices"
ERROR:  relation "oddb_business_company_name" already exists

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:71:in `rescue in execute': ERROR:  relation "oddb_business_company_name" already exists (DBI::ProgrammingError)

Notes

  • The first 6 errors comes from 'ODBA.storage.setup'
  • The 7th error comes from 'ODBA.storage.ensure_target_id_index'
  • The last one comes from 'create_deferred_indices'

Hypothesis

  • Each error comes from a different process, but the catching point is the same (method_missing method)
  • That is why this error is difficult to be debugged

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#create_deferred_indices]]

  def create_deferred_indices(drop_existing = false)
p "getin create_deferred_indices"
print "@deferred_indices.length="
p @deferred_indices.length
    @deferred_indices.each { |definition|
      name = definition.index_name
print "name="
p name
      if(drop_existing && self.indices.include?(name))
p "A"
        drop_index(name)
      end
print "self.class="
p self.class
print "self.indices.include?(name)="
p self.indices.include?(name)
      unless(self.indices.include?(name))
print "definition="
p definition
        index = create_index(definition)
        if(index.target_klass.respond_to?(:odba_extent))
          index.fill(index.target_klass.odba_extent)
        end
      end
    }
  end

Result (Ruby 1.9.1)

 "getin create_deferred_indices"
 @deferred_indices.length=31
 name="oddb_business_company_name"
 self.class=ODBA::Cache
 self.indices.include?(name)=true

Result (Ruby 1.9.2)

 "getin create_deferred_indices"
 @deferred_indices.length=31
 name="oddb_business_company_name"
 self.class=ODBA::Cache
 self.indices.include?(name)=false

Note

  • This condition is different

Next

  • How (why) does this condition become different?

Check the 'self.indices'

/home/masa/ywesee/odba/lib

  def create_deferred_indices(drop_existing = false)
    @deferred_indices.each { |definition|
      name = definition.index_name
print "name="
p name
      if(drop_existing && self.indices.include?(name))
        drop_index(name)
      end
print "self.class="
p self.class
print "self.indices.include?(name)="
p self.indices.include?(name)
print "self.indices.class="
p self.indices.class
print "self.indices="
p self.indices
exit

Result (Ruby 1.9.1)

name="oddb_business_company_name"
self.class=ODBA::Cache
self.indices.include?(name)=true
self.indices.class=Hash
self.indices={"oddb_drugs_atc_code"=>#<ODBA::Stub:22390312#5 @odba_class= @odba_container=21306824#1>, "oddb_drugs_atc_name"=>#<ODBA::Stub:22389724#10 @odba_class= @odba_container=21306824#1>, 
"oddb_drugs_unit_name"=>#<ODBA::Stub:22389136#43 @odba_class= @odba_container=21306824#1>, "oddb_drugs_package_atc"=>#<ODBA::Stub:22388548#29 @odba_class= @odba_container=21306824#1>, 
"oddb_drugs_package_code"=>#<ODBA::Stub:22387960#24 @odba_class= @odba_container=21306824#1>, "oddb_drugs_package_name"=>#<ODBA::Stub:22387372#30 @odba_class= @odba_container=21306824#1>, 
"oddb_drugs_product_name"=>#<ODBA::Stub:22411676#34 @odba_class= @odba_container=21306824#1>, "oddb_drugs_sequence_atc"=>#<ODBA::Stub:22411088#281283 @odba_class=ODBA::Index 
@odba_container=21306824#1>, "oddb_business_invoice_id"=>#<ODBA::Stub:22410444#4 @odba_class= @odba_container=21306824#1>, "oddb_drugs_sequence_code"=>#<ODBA::Stub:22409856#35 @odba_class= 
@odba_container=21306824#1>, "oddb_drugs_substance_code"=>#<ODBA::Stub:22409268#19 @odba_class= @odba_container=21306824#1>, "oddb_drugs_substance_name"=>#<ODBA::Stub:22408680#18 @odba_class= 
@odba_container=21306824#1>, "oddb_text_document_source"=>#<ODBA::Stub:22408092#46 @odba_class= @odba_container=21306824#1>, "oddb_business_company_name"=>#<ODBA::Stub:22407504#2 @odba_class= 
@odba_container=21306824#1>, "oddb_drugs_indication_name"=>#<ODBA::Stub:22406916#281282 @odba_class=ODBA::Index @odba_container=21306824#1>, "oddb_drugs_package_company"=>#<ODBA::Stub:22406272#32 
@odba_class= @odba_container=21306824#1>, "oddb_drugs_package_product"=>#<ODBA::Stub:22405684#33 @odba_class= @odba_container=21306824#1>, "oddb_drugs_galenicform_code"=>#<ODBA::Stub:22405096#12 
@odba_class= @odba_container=21306824#1>, "oddb_drugs_genericgroup_key"=>#<ODBA::Stub:22404508#281280 @odba_class=ODBA::Index @odba_container=21306824#1>, "oddb_drugs_sequence_product"=>#
<ODBA::Stub:22403864#41 @odba_class= @odba_container=21306824#1>, "oddb_drugs_galenicgroup_name"=>#<ODBA::Stub:22419628#17 @odba_class= @odba_container=21306824#1>, "oddb_drugs_package_substance"=>#
<ODBA::Stub:22419040#31 @odba_class= @odba_container=21306824#1>, "oddb_drugs_atc_level_and_code"=>#<ODBA::Stub:22418452#6 @odba_class= @odba_container=21306824#1>, "oddb_regulatory_authority_key"=>#
<ODBA::Stub:22417864#281284 @odba_class=ODBA::Index @odba_container=21306824#1>, "oddb_business_invoice_yus_name"=>#<ODBA::Stub:22417220#3 @odba_class= @odba_container=21306824#1>, 
"oddb_drugs_substancegroup_name"=>#<ODBA::Stub:22416632#42 @odba_class= @odba_container=21306824#1>, "oddb_regulatory_authority_name"=>#<ODBA::Stub:22416044#44 @odba_class= 
@odba_container=21306824#1>, "oddb_regulatory_registration_code"=>#<ODBA::Stub:22415456#45 @odba_class= @odba_container=21306824#1>, "oddb_drugs_galenicform_description"=>#<ODBA::Stub:22414868#11 
@odba_class= @odba_container=21306824#1>, "oddb_drugs_indextherapeuticus_code"=>#<ODBA::Stub:22414280#281281 @odba_class=ODBA::Index @odba_container=21306824#1>, 
"oddb_drugs_sequence_fachinfo_indications_de"=>#<ODBA::Stub:22413636#40 @odba_class= @odba_container=21306824#1>}

Result (Ruby 1.9.2)

name="oddb_business_company_name"
self.class=ODBA::Cache
self.indices.include?(name)=false
self.indices.class=Hash
self.indices={"oddb_drugs_sequence_fachinfo_indications_de"=>#<ODBA::Stub:14949900#40 @odba_class= @odba_container=15033540#1>}

Note

  • They are so different

Next

  • How (When) does the ODBA::Cache#indices set?

Experiment

/home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb

  ODBA.storage.dbi = ODBA::ConnectionPool.new("DBI:Pg:#{@config.db_name}",
                                              @config.db_user, @config.db_auth)
print "ODBA.cache.indices="
p ODBA.cache.indices

Result (Ruby 1.9.1)

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb 
ODBA.cache.indices={"oddb_drugs_atc_code"=>#<ODBA::Stub:17056368#5 @odba_class= @odba_container=17005912#1>, "oddb_drugs_atc_name"=>#<ODBA::Stub:17055780#10 @odba_class= @odba_container=17005912#1>, 
"oddb_drugs_unit_name"=>#<ODBA::Stub:17055192#43 @odba_class= @odba_container=17005912#1>, "oddb_drugs_package_atc"=>#<ODBA::Stub:17054604#29 @odba_class= @odba_container=17005912#1>, 
"oddb_drugs_package_code"=>#<ODBA::Stub:17054016#24 @odba_class= @odba_container=17005912#1>, "oddb_drugs_package_name"=>#<ODBA::Stub:17053428#30 @odba_class= @odba_container=17005912#1>, 
"oddb_drugs_product_name"=>#<ODBA::Stub:17052840#34 @odba_class= @odba_container=17005912#1>, "oddb_drugs_sequence_atc"=>#<ODBA::Stub:17052252#281283 @odba_class=ODBA::Index 
@odba_container=17005912#1>, "oddb_business_invoice_id"=>#<ODBA::Stub:17051608#4 @odba_class= @odba_container=17005912#1>, "oddb_drugs_sequence_code"=>#<ODBA::Stub:17051020#35 @odba_class= 
@odba_container=17005912#1>, "oddb_drugs_substance_code"=>#<ODBA::Stub:17050432#19 @odba_class= @odba_container=17005912#1>, "oddb_drugs_substance_name"=>#<ODBA::Stub:17069304#18 @odba_class= 
@odba_container=17005912#1>, "oddb_text_document_source"=>#<ODBA::Stub:17068716#46 @odba_class= @odba_container=17005912#1>, "oddb_business_company_name"=>#<ODBA::Stub:17068128#2 @odba_class= 
@odba_container=17005912#1>, "oddb_drugs_indication_name"=>#<ODBA::Stub:17067540#281282 @odba_class=ODBA::Index @odba_container=17005912#1>, "oddb_drugs_package_company"=>#<ODBA::Stub:17066896#32 
@odba_class= @odba_container=17005912#1>, "oddb_drugs_package_product"=>#<ODBA::Stub:17066308#33 @odba_class= @odba_container=17005912#1>, "oddb_drugs_galenicform_code"=>#<ODBA::Stub:17065720#12 
@odba_class= @odba_container=17005912#1>, "oddb_drugs_genericgroup_key"=>#<ODBA::Stub:17065132#281280 @odba_class=ODBA::Index @odba_container=17005912#1>, "oddb_drugs_sequence_product"=>#
<ODBA::Stub:17064488#41 @odba_class= @odba_container=17005912#1>, "oddb_drugs_galenicgroup_name"=>#<ODBA::Stub:17063900#17 @odba_class= @odba_container=17005912#1>, "oddb_drugs_package_substance"=>#
<ODBA::Stub:17063312#31 @odba_class= @odba_container=17005912#1>, "oddb_drugs_atc_level_and_code"=>#<ODBA::Stub:17062724#6 @odba_class= @odba_container=17005912#1>, "oddb_regulatory_authority_key"=>#
<ODBA::Stub:17062136#281284 @odba_class=ODBA::Index @odba_container=17005912#1>, "oddb_business_invoice_yus_name"=>#<ODBA::Stub:16444988#3 @odba_class= @odba_container=17005912#1>, 
"oddb_drugs_substancegroup_name"=>#<ODBA::Stub:16444400#42 @odba_class= @odba_container=17005912#1>, "oddb_regulatory_authority_name"=>#<ODBA::Stub:16443812#44 @odba_class= 
@odba_container=17005912#1>, "oddb_regulatory_registration_code"=>#<ODBA::Stub:16443224#45 @odba_class= @odba_container=17005912#1>, "oddb_drugs_galenicform_description"=>#<ODBA::Stub:16442636#11 
@odba_class= @odba_container=17005912#1>, "oddb_drugs_indextherapeuticus_code"=>#<ODBA::Stub:16442048#281281 @odba_class=ODBA::Index @odba_container=17005912#1>, 
"oddb_drugs_sequence_fachinfo_indications_de"=>#<ODBA::Stub:16441404#40 @odba_class= @odba_container=17005912#1>}

Result (Ruby 1.9.2)

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb 
ODBA.cache.indices={"oddb_drugs_sequence_fachinfo_indications_de"=>#<ODBA::Stub:25873240#40 @odba_class= @odba_container=25957080#1>}

Note

  • These are already different from the beginning

Next

  • Check 'def indices'

/home/masa/ywesee/odba/lib/odba/cache.rb#indices

      # Returns a Hash-table containing all stored indices. 
      def indices
          @indices ||= fetch_named('__cache_server_indices__', self) {
              {}
          }
      end

Note

  • I should check 'fetch_named'

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#fetch_named

      def fetch_named(name, odba_caller, &block) # :nodoc:
          fetch_or_do(name, odba_caller) {
              dump = ODBA.storage.restore_named(name)
              if(dump.nil?)
                  odba_obj = block.call
                  odba_obj.odba_name = name
                  odba_obj.odba_store(name)
                  odba_obj
              else
print "name="
p name
print "dump="
p dump
exit
                  fetch_or_restore(name, dump, odba_caller)
              end
          }
      end

Note

  • The results are same between Ruby 1.9.1 and 1.9.2

Next

  • Check fetch_or_restore

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#fetch_or_restore

  def fetch_or_restore(odba_id, dump, odba_caller) # :nodoc:
p "getin fetch_or_restore"
print "odba_id="
p odba_id
    fetch_or_do(odba_id, odba_caller) {
      odba_obj, collection = restore(dump)
print "odba_obj="
p odba_obj
exit

Result (Ruby 1.9.1)

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb 
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin fetch_or_restore"
odba_id=2
odba_obj=#<ODBA::Index:0x00000002896220 @origin_klass=ODDB::Business::Company, @target_klass=ODDB::Business::Company, @resolve_origin="", @resolve_target=:none, @index_name="oddb_business_company_name", @resolve_search_term="name.all", @dictionary="", @class_filter=:is_a?, @odba_id=2, @odba_persistent=true, @odba_observers=nil, @proc_origin=nil, @proc_target=nil, @proc_resolve_search_term=nil>

Result (Ruby 1.9.2)

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin fetch_or_restore"
odba_id=40
odba_obj=#<ODBA::FulltextIndex:0x00000002a8ba68 @origin_klass=ODDB::Text::Document, @target_klass=ODDB::Drugs::Sequence, @resolve_origin="fachinfo.de", @resolve_target=:none, @index_name="oddb_drugs_sequence_fachinfo_indications_de", @resolve_search_term="chapter(\"indications\").to_s", @dictionary="german", @class_filter=:is_a?, @odba_id=40, @odba_persistent=true, @odba_observers=nil, @proc_origin=nil, @proc_target=nil, @proc_resolve_search_term=nil>

Notes

  • 'restore(dump)' looks working differently
  • 'restore(dump)' (probably) calls 'fetch_or_restore' recursively

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#restore

        def restore(dump)
p "getin restore"
            odba_obj = ODBA.marshaller.load(dump)
print "odba_obj="
p odba_obj

      unless(odba_obj.is_a?(Persistable))
p "AAA"
        odba_obj.extend(Persistable)
      end
            collection = fetch_collection(odba_obj)
print "collection="
p collection
exit
            odba_obj.odba_restore(collection)
            [odba_obj, collection]
        end

Result (Ruby 1.9.1)

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_or_restore"
odba_id=2
"getin restore"
odba_obj=#<ODBA::Index:0x00000002bfeba0 @origin_klass=ODDB::Business::Company, @target_klass=ODDB::Business::Company, @resolve_origin="", @resolve_target=:none, @index_name="oddb_business_company_name", @resolve_search_term="name.all", @dictionary="", @class_filter=:is_a?, @odba_id=2, @odba_persistent=true, @odba_observers=nil, @proc_origin=nil, @proc_target=nil, @proc_resolve_search_term=nil>
collection=[]

Result (Ruby 1.9.2)

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_or_restore"
odba_id=40
"getin restore"
odba_obj=#<ODBA::FulltextIndex:0x00000002554540 @origin_klass=ODDB::Text::Document, @target_klass=ODDB::Drugs::Sequence, @resolve_origin="fachinfo.de", @resolve_target=:none, @index_name="oddb_drugs_sequence_fachinfo_indications_de", @resolve_search_term="chapter(\"indications\").to_s", @dictionary="german", @class_filter=:is_a?, @odba_id=40, @odba_persistent=true, @odba_observers=nil, @proc_origin=nil, @proc_target=nil, @proc_resolve_search_term=nil>
collection=[]

Notes

  • 'fetch_collection(odba_obj)' works fetch_collection(odba_obj)differently
  • 'fetch_collection(odba_obj)' calls fetch_or_restore' recursively

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#fetch_collection

      def fetch_collection(odba_obj) # :nodoc:
p "getin fetch_collection"
          collection = []
          bulk_fetch_ids = [] 
print "odba_obj.odba_id="
p odba_obj.odba_id
          rows = ODBA.storage.restore_collection(odba_obj.odba_id)
print "rows.size="
p rows.size
print "rows[0]="
p rows[0]
    return collection if rows.empty?
          rows.each { |row|
              key = ODBA.marshaller.load(row[0])
              value = ODBA.marshaller.load(row[1])
print "key="
p key

Result (Ruby 1.9.1)

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_collection"
odba_obj.odba_id=1
rows.size=31
rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
key="oddb_drugs_atc_code"
key="oddb_drugs_atc_name"
key="oddb_drugs_unit_name"
key="oddb_drugs_package_atc"
key="oddb_drugs_package_code"
key="oddb_drugs_package_name"
key="oddb_drugs_product_name"
key="oddb_drugs_sequence_atc"
key="oddb_business_invoice_id"
key="oddb_drugs_sequence_code"
key="oddb_drugs_substance_code"
key="oddb_drugs_substance_name"
key="oddb_text_document_source"
key="oddb_business_company_name"
key="oddb_drugs_indication_name"
key="oddb_drugs_package_company"
key="oddb_drugs_package_product"
key="oddb_drugs_galenicform_code"
key="oddb_drugs_genericgroup_key"
key="oddb_drugs_sequence_product"
key="oddb_drugs_galenicgroup_name"
key="oddb_drugs_package_substance"
key="oddb_drugs_atc_level_and_code"
key="oddb_regulatory_authority_key"
key="oddb_business_invoice_yus_name"
key="oddb_drugs_substancegroup_name"
key="oddb_regulatory_authority_name"
key="oddb_regulatory_registration_code"
key="oddb_drugs_galenicform_description"
key="oddb_drugs_indextherapeuticus_code"
key="oddb_drugs_sequence_fachinfo_indications_de"

Result (Ruby 1.9.2)

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_collection"
odba_obj.odba_id=1
rows.size=31
rows[0]=["04084922306f6464625f64727567735f73657175656e63655f66616368696e666f5f696e6469636174696f6e735f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964692d3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"
key="oddb_drugs_sequence_fachinfo_indications_de"

Notes

  • The return value of 'ODBA.storage.restore_collection(odba_obj.odba_id)' is differrent
  • That is why the 'ODBA.marshaller.load(row[0])' is also different

Experiment

/home/masa/ywesee/odba/lib/odba/cache.rb#fetch_collection

      def fetch_collection(odba_obj) # :nodoc:
p "getin fetch_collection"
          collection = []
          bulk_fetch_ids = []
print "odba_obj.odba_id="
p odba_obj.odba_id
          rows = ODBA.storage.restore_collection(odba_obj.odba_id)
if RUBY_VERSION == "1.9.1"
  f=open("test.dat","wb")
  str = Marshal.dump(rows)
  f.write str
  f.close
else
  f=open("test.dat","rb")
  rows=Marshal.load(f.read)
  f.close
end
p rows.size
print "rows[0]="
p rows[0]
    return collection if rows.empty?
          rows.each { |row|
              key = ODBA.marshaller.load(row[0])
              value = ODBA.marshaller.load(row[1])
print "key="
p key

Run on Ruby 1.9.1 first

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_collection"
odba_obj.odba_id=1
31
rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
key="oddb_drugs_atc_code"
key="oddb_drugs_atc_name"
key="oddb_drugs_unit_name"
key="oddb_drugs_package_atc"
key="oddb_drugs_package_code"
key="oddb_drugs_package_name"
key="oddb_drugs_product_name"
key="oddb_drugs_sequence_atc"
key="oddb_business_invoice_id"
key="oddb_drugs_sequence_code"
key="oddb_drugs_substance_code"
key="oddb_drugs_substance_name"
key="oddb_text_document_source"
key="oddb_business_company_name"
key="oddb_drugs_indication_name"
key="oddb_drugs_package_company"
key="oddb_drugs_package_product"
key="oddb_drugs_galenicform_code"
key="oddb_drugs_genericgroup_key"
key="oddb_drugs_sequence_product"
key="oddb_drugs_galenicgroup_name"
key="oddb_drugs_package_substance"
key="oddb_drugs_atc_level_and_code"
key="oddb_regulatory_authority_key"
key="oddb_business_invoice_yus_name"
key="oddb_drugs_substancegroup_name"
key="oddb_regulatory_authority_name"
key="oddb_regulatory_registration_code"
key="oddb_drugs_galenicform_description"
key="oddb_drugs_indextherapeuticus_code"
key="oddb_drugs_sequence_fachinfo_indications_de"

Run on Ruby 1.9.2 next

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"getin fetch_collection"
odba_obj.odba_id=1
31
rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
key="oddb_drugs_atc_code"
key="oddb_drugs_atc_name"
key="oddb_drugs_unit_name"
key="oddb_drugs_package_atc"
key="oddb_drugs_package_code"
key="oddb_drugs_package_name"
key="oddb_drugs_product_name"
key="oddb_drugs_sequence_atc"
key="oddb_business_invoice_id"
key="oddb_drugs_sequence_code"
key="oddb_drugs_substance_code"
key="oddb_drugs_substance_name"
key="oddb_text_document_source"
key="oddb_business_company_name"
key="oddb_drugs_indication_name"
key="oddb_drugs_package_company"
key="oddb_drugs_package_product"
key="oddb_drugs_galenicform_code"
key="oddb_drugs_genericgroup_key"
key="oddb_drugs_sequence_product"
key="oddb_drugs_galenicgroup_name"
key="oddb_drugs_package_substance"
key="oddb_drugs_atc_level_and_code"
key="oddb_regulatory_authority_key"
key="oddb_business_invoice_yus_name"
key="oddb_drugs_substancegroup_name"
key="oddb_regulatory_authority_name"
key="oddb_regulatory_registration_code"
key="oddb_drugs_galenicform_description"
key="oddb_drugs_indextherapeuticus_code"
key="oddb_drugs_sequence_fachinfo_indications_de"

Notes

  • The experiment above is as follows
    1. Write the binary data of 'rows' in Ruby 1.9.1
    2. Load the binary data of 'rows' in Ruby 1.9.2
    3. Then, the result becomes same
  • So, 'ODBA.storage.restore_collection(odba_obj.odba_id)' looks working differently

Next

  • Check ODBA::Storage#restore_collection

Experiment

/home/masa/ywesee/odba/lib/odba/storage.rb#restore_collection

        def restore_collection(odba_id)
p "ODBA::Storage#getin restore_collection"
print "odba_id="
p odba_id
print "self.dbi.class="
p self.dbi.class
exit
            self.dbi.select_all <<-EOQ
                SELECT key, value FROM collection WHERE odba_id = #{odba_id}
            EOQ
        end

Result

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"ODBA::Storage#getin restore_collection"
odba_id=1
self.dbi.class=ODBA::ConnectionPool

Next

  • Check ODBA::ConnectionPool#select_all
  • But there is no method definition of 'select_all' in ODBA::ConnectionPool class

Experiment

/home/masa/ywesee/odba/lib/odba/connection_pool.rb#method_missing

        def method_missing(method, *args, &block) # :nodoc:
if method==:select_all
p "getin method_missin"
print "method="
p method
print "args"
p args
end
            tries = SETUP_RETRIES
            begin
p "missing0"
                next_connection { |conn|
print "conn.class="
p conn.class
                    conn.send(method, *args, &block)
                }
            rescue NoMethodError, DBI::Error => e
p "missing1"
        warn e
                if(tries > 0 && (!e.is_a?(DBI::ProgrammingError) \
           || e.message == 'no connection to the server'))
p "missing2"
                    sleep(SETUP_RETRIES - tries)
                    tries -= 1
                    reconnect
                    retry
                else
p "missing3"
p e
                    raise
                end
            end
        end

Result

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"ODBA::Storage#getin restore_collection"
odba_id=1
"getin method_missin"
method=:select_all
args["\t\t\t\tSELECT key, value FROM collection WHERE odba_id = 1\n"]
"missing0"
conn.class=DBI::DatabaseHandle

Next

  • Check 'next_connection' and 'DBI::DatabaseHandle#select_all'

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb

        def select_all(stmt, *bindvars, &p)
p "getin DBI::DatabaseHandle#select_all"
print "stmt="
p stmt
print "bindvars="
p bindvars
            sanity_check(stmt)
            rows = nil
            execute(stmt, *bindvars) do |sth|
print "sth.class="
p sth.class
                if block_given?
p "A"
                    sth.each(&p)
                else
p "B"
                    rows = sth.fetch_all
                end
            end
p "C"
            return rows
        end

Result

"getin fetch_or_restore"
odba_id="__cache_server_indices__"
"getin restore"
odba_obj={}
"ODBA::Storage#getin restore_collection"
odba_id=1
"getin method_missin"
method=:select_all
args["\t\t\t\tSELECT key, value FROM collection WHERE odba_id = 1\n"]
"missing0"
conn.class=DBI::DatabaseHandle
"getin DBI::DatabaseHandle#select_all"
stmt="\t\t\t\tSELECT key, value FROM collection WHERE odba_id = 1\n"
bindvars=[]
sth.class=DBI::StatementHandle
"B"
"C"

Next

  • Check 'DBI::StatementHandle#fetch_all' and 'DBI::DatabaseHandle#execute'

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch_all
 p "getin DBI::StatementHandle#fetch_all"
            sanity_check({:fetchable => true, :prepared => true, :executed => true})

            cols = column_names
 print "cols="
 p cols
            fetched_rows = []

            begin
                 while row = fetch do
 print "row="
 p row
                     fetched_rows.push(row)
                 end
            rescue Exception
            end
            @handle.cancel
            @fetchable = false
 exit
            return fetched_rows
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb > ruby192.txt

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb > ruby191.txt

masa@masa ~/ywesee/ramaze.ch.oddb.org $ diff ruby191.txt ruby192.txt 
masa@masa ~/ywesee/ramaze.ch.oddb.org $ 

Note

  • They are totally same

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch_all
p "getin DBI::StatementHandle#fetch_all"
            sanity_check({:fetchable => true, :prepared => true, :executed => true})

            cols = column_names
print "cols="
p cols
            fetched_rows = []

            begin
                while row = fetch do
#print "row="
#p row
                    fetched_rows.push(row)
                end
            rescue Exception
            end
            @handle.cancel
            @fetchable = false
print "fetched_rows="
p fetched_rows
exit
            return fetched_rows
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb > ruby192.txt

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb > ruby191.txt

masa@masa ~/ywesee/ramaze.ch.oddb.org $ diff ruby191.txt ruby192.txt 
10c10
< fetched_rows=[["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", 
"04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"], 
["04084922186f6464625f64727567735f6174635f6e616d65063a0d656e636f64696e67220d55532d4153434949", 
"04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690f3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"],
...
---
> fetched_rows=[["04084922306f6464625f64727567735f73657175656e63655f66616368696e666f5f696e6469636174696f6e735f6465063a0d656e636f64696e67220d55532d4153434949", 
"04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964692d3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"], 
["04084922306f6464625f64727567735f73657175656e63655f66616368696e666f5f696e6469636174696f6e735f6465063a0d656e636f64696e67220d55532d4153434949", 
"04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964692d3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"], 
...

Note

  • 'fetched_rows.push(row)' works differently
  • or 'fetch' method works differently

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch(&p)
            sanity_check({ :fetchable => true, :prepared => true, :executed => true })

            if block_given?
                while (res = @handle.fetch) != nil
                    @row = @row.dup
                    @row.set_values(res)
                    yield @row
                end
                @handle.cancel
                @fetchable = false
                return nil
            else
                res = @handle.fetch
                if res.nil?
                    @handle.cancel
                    @fetchable = false
                else
                    @row = @row.dup
                    @row.set_values(res)
                    res = @row
                end
print "res="
p res
                return res
            end
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb > ruby192.txt 

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb > ruby191.txt 

masa@masa ~/ywesee/ramaze.ch.oddb.org $ diff ruby191.txt ruby192.txt 
masa@masa ~/ywesee/ramaze.ch.oddb.org $

Note

  • 'fetch' method works as well in both Ruby 1.9.1 and 1.9.2

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch_all
p "getin DBI::StatementHandle#fetch_all"
            sanity_check({:fetchable => true, :prepared => true, :executed => true})

            cols = column_names
print "cols="
p cols
            fetched_rows = []

            begin
                #while row = fetch do
                while row = fetch
#print "row="
#p row
print "fetched_rows[0]="
p fetched_rows[0]
                    fetched_rows.push(row)
                end
            rescue Exception
            end
            @handle.cancel
            @fetchable = false
#print "fetched_rows="
#p fetched_rows
exit
            return fetched_rows
        end

Result (Ruby 1.9.1)

fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922186f6464625f64727567735f6174635f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690a3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
...

Note

  • This is correct as expected

Result (Ruby 1.9.2)

fetched_rows[0]=["04084922186f6464625f64727567735f6174635f6e616d65063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964690f3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["04084922196f6464625f64727567735f756e69745f6e616d65063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f696469303a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["040849221b6f6464625f64727567735f7061636b6167655f617463063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f696469223a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
fetched_rows[0]=["040849221c6f6464625f64727567735f7061636b6167655f636f6465063a0d656e636f64696e67220d55532d4153434949", "04086f3a0f4f4442413a3a53747562083a0d406f6462615f6964691d3a14406f6462615f636f6e7461696e6572303a154072656365697665725f6c6f6164656454"]
...

Note

  • This is wrong
  • Because 'fetched_row[0]' should be all the same
  • But why does this change?

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch_all
p "getin DBI::StatementHandle#fetch_all"
            sanity_check({:fetchable => true, :prepared => true, :executed => true})

            cols = column_names
print "cols="
p cols
            fetched_rows = []
            begin
                while row = fetch do
print "row.class="
p row.class
#print "fetched_rows[0]="
#p fetched_rows[0]
                    fetched_rows.push(row.to_a)
                    #fetched_rows.push(row.to_s)
                end
            rescue Exception
            end
            @handle.cancel
            @fetchable = false
print "fetched_rows="
pp fetched_rows
exit
            return fetched_rows
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../odba/lib:../oddb/lib start.rb > ruby192.txt 

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb > ruby191.txt 

masa@masa ~/ywesee/ramaze.ch.oddb.org $ diff ruby191.txt ruby192.txt 
masa@masa ~/ywesee/ramaze.ch.oddb.org $ 

Note

  • This means
    • The return value or 'DBI::Row' is different between 1.9.1 and 1.9.2

After re-install dbi, the other error comes

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../oddb/lib:../odba/lib start.rb 
ERROR:  relation "object" already exists

ERROR:  relation "prefetchable_index" already exists

ERROR:  relation "extent_index" already exists

ERROR:  relation "object_connection" already exists

ERROR:  relation "target_id_index" already exists

ERROR:  relation "collection" already exists

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/columninfo.rb:49:in `[]=': can't add a new key into hash during iteration (RuntimeError)
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/columninfo.rb:49:in `block in initialize'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/columninfo.rb:42:in `each_key'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/columninfo.rb:42:in `initialize'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:161:in `new'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:161:in `block in columns'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:161:in `collect'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:161:in `columns'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:36:in `block in method_missing'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:26:in `next_connection'
        from /home/masa/ywesee/odba/lib/odba/connection_pool.rb:35:in `method_missing'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:525:in `setup'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:433:in `setup'
        from /home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb:35:in `<module:ODDB>'
        from /home/masa/ywesee/oddb/lib/oddb/persistence/odba.rb:28:in `<top (required)>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/model/init.rb:3:in `require'
        from /home/masa/ywesee/ramaze.ch.oddb.org/model/init.rb:3:in `<top (required)>'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:32:in `require'
        from /home/masa/ywesee/ramaze.ch.oddb.org/app.rb:32:in `<top (required)>'
        from start.rb:7:in `require'
        from start.rb:7:in `<main>'

Note

  • This is the hash iteration problem

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/statement.rb

        def fetch_all
            sanity_check({:fetchable => true, :prepared => true, :executed => true})

            cols = column_names
            fetched_rows = []

            begin
                while row = fetch do
                    #fetched_rows.push(row)
                    fetched_rows.push(row.to_a)
                end
            rescue Exception
            end

            @handle.cancel
            @fetchable = false
            return fetched_rows
        end

Result (Ruby 1.9.1)

D [2011-01-24 16:45:48 $13399] DEBUG | : Using webrick
I [2011-01-24 16:45:49 $13399]  INFO | : WEBrick 1.3.1
I [2011-01-24 16:45:49 $13399]  INFO | : ruby 1.9.1 (2010-08-16) [x86_64-linux]
D [2011-01-24 16:45:49 $13399] DEBUG | : TCPServer.new(0.0.0.0, 7000)
D [2011-01-24 16:45:49 $13399] DEBUG | : Rack::Handler::WEBrick is mounted on /.
I [2011-01-24 16:45:49 $13399]  INFO | : WEBrick::HTTPServer#start: pid=13399 port=7000

Result (Ruby 1.9.2)

D [2011-01-24 16:45:00 $13373] DEBUG | : Using webrick
I [2011-01-24 16:45:00 $13373]  INFO | : WEBrick 1.3.1
I [2011-01-24 16:45:00 $13373]  INFO | : ruby 1.9.2 (2010-07-11) [x86_64-linux]
D [2011-01-24 16:45:00 $13373] DEBUG | : TCPServer.new(0.0.0.0, 7000)
D [2011-01-24 16:45:00 $13373] DEBUG | : Rack::Handler::WEBrick is mounted on /.
I [2011-01-24 16:45:00 $13373]  INFO | : WEBrick::HTTPServer#start: pid=13373 port=7000

Note

  • Success

Summary

  • The problem is the Array#push method for DBI::Row instance
    fetched_rows.push(row)
  • 'fetched_rows' is a nomarl Array instance
  • 'row' is an Instance of DBI::Row
  • This behavior between Ruby 1.9.1 and 1.9.2 is different
  • The other case where the argument of push method is normal Interger or something works as usual
  • In only the case of DBI::Row instance it works differently
  • I have not understood yet it is because of Ruby version or DBI::Row class
view · edit · sidebar · attach · print · history
Page last modified on January 19, 2012, at 02:27 PM