view · edit · sidebar · attach · print · history

20110121-setup-ramaze

<< Masa.20110124-setup-ramaze | 2011 | Masa.20110120-update-rpdf2txt-setup-ramaze >>


  1. Resume set up ramaze oddb.org
  2. Try to run ramaze oddb on Ruby 1.9.1

Goal
  • Setup Ramaze version oddb / 40%
Milestones
  • Set up ramaze version oddb
    • Trace error messages
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

Resume set up ramaze oddb.org

Check the current status

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

ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

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:62: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:37:in `execute'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/base_classes/database.rb:96:in `execute'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/base_classes/database.rb:114:in `do'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:106:in `do'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:176:in `create_index'
        from /home/masa/ywesee/odba/lib/odba/index.rb:226:in `initialize'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:148:in `new'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:148:in `block in create_index'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:558:in `call'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:558:in `block in transaction'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:209:in `transaction'
        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:554:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:520:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:140: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:437: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>'

The updated point

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

    class ColumnInfo < DelegateClass(Hash)

        # Create a new ColumnInfo object.
        #
        # If no Hash is provided, one will be created for you. The hash will be
        # shallow cloned for storage inside the object, and an attempt will be
        # made to convert all string keys to symbols.
        #
        # In the event that both string and symbol keys are provided in the
        # initial hash, we cannot safely route around collisions and therefore
        # a TypeError is raised.
        #
        def initialize(hash=nil)
            @hash = hash.dup rescue nil
            @hash ||= Hash.new

            # coerce all strings to symbols
            hash_tmp = {}
            @hash.each_key do |x|
                if x.kind_of? String
                    sym = x.to_sym
                    if @hash.has_key? sym
                        raise ::TypeError,
                            "#{self.class.name} may construct from a hash keyed with strings or symbols, but not both"
                    end
                    #@hash[sym] = @hash[x]
                    hash_tmp[sym] = @hash[x]
                    @hash.delete(x)
                end
            end
            hash_tmp.each do |k,v|
              @hash[k] = v
            end

            super(@hash)
        end

Note

  • It is possible to work by replacing '@hash.each_key do |x|' to '@hash.keys.each do |x|'
  • I posted emails to Ruby mailing lists (ruby-list:47766, ruby-dev:43111 (Japanese))) regarding this hash iteration problem
  • I got an solution from Nobuoka-san for this prohibition (ruby-dev:43126 (Japanese))
  • This script runs not only in Ruby 1.9 but 1.8 (and hash elements are iterated in order)
  • Attach:mod_hash.rb.txt
  • The usage is as follows
masa@masa ~/work $ ls
mod_hash.rb test.rb
masa@masa ~/work $ cat test.rb 
h = {}
h[1] = 2

h.each do |k,v|
  h[k+1] = v*2 if v < 10000000000
  print k, " " , v, "\n"
end
masa@masa ~/work $ ruby1.9 -v
ruby 1.9.2dev (2010-07-11 revision 28618) [x86_64-linux]
masa@masa ~/work $ ruby1.9 test.rb 
test.rb:5:in `[]=': can't add a new key into hash during iteration (RuntimeError)
        from test.rb:5:in `block in <main>'
        from test.rb:4:in `each'
        from test.rb:4:in `<main>'
masa@masa ~/work $ ruby1.9 -I . -rmod_hash test.rb
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
16 65536
17 131072
18 262144
19 524288
20 1048576
21 2097152
22 4194304
23 8388608
24 16777216
25 33554432
26 67108864
27 134217728
28 268435456
29 536870912
30 1073741824
31 2147483648
32 4294967296
33 8589934592
34 17179869184

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:62

    #
    # See DBI::BaseDatabase#execute.
    #
    # This method will make use of PostgreSQL's native BLOB support if
    # DBI::Binary objects are passed in.
    #
    def execute
        # replace DBI::Binary object by oid returned by lo_import
        @bindvars.collect! do |var|
            if var.is_a? DBI::Binary then
                oid = @db.__blob_create(PGconn::INV_WRITE)
                @db.__blob_write(oid, var.to_s)
                oid
            else
                var
            end
        end

        internal_prepare

        if not @db['AutoCommit'] then
            #          if not SQL.query?(boundsql) and not @db['AutoCommit'] then
            @db.start_transaction unless @db.in_transaction?
        end

        if @db["pg_native_binding"]
            pg_result = @db._exec_prepared(@stmt_name, *@bindvars)
        else
            pg_result = @db._exec_prepared(@stmt_name)
        end

        @result = DBI::DBD::Pg::Tuples.new(@db, pg_result)
    rescue PGError, RuntimeError => err
        raise DBI::ProgrammingError.new(err.message)     #<= HERE
    end

Experiment

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

        #
        # Commits, runs the block provided, yielding the DatabaseHandle as it's
        # argument. If an exception is raised through the block, rollback occurs.
        # Otherwise, commit occurs.
        #
        def transaction
            sanity_check
            raise InterfaceError, "No block given" unless block_given?

            commit
            begin
                yield self
                commit
            rescue Exception
p "masa"
                rollback
                raise
            end
        end

Result

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

ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

"masa"

Note

  • The error comes from here
  • But I should dive into deeper

Experiment

/home/masa/ywesee/odba/lib/odba/connection_pool.rb:36

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

Notes

  • 'method_missing' again!! I hate this

Result

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

"masa3"
"masa1"
ERROR:  relation "prefetchable_index" already exists

"masa3"
...
"masa1"
ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

"masa3"
"masa1"
ERROR:  relation "oddb_business_company_name" already exists

"masa3"
/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:62: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:37:in `execute'
...

Notes

  • It starts from 'masa1' and ends at 'masa3' for each ERROR
  • It stops only in the last case

Experiment

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:35

    #
    # See DBI::BaseDatabase#execute.
    #
    # This method will make use of PostgreSQL's native BLOB support if
    # DBI::Binary objects are passed in.
    #
    def execute
        # replace DBI::Binary object by oid returned by lo_import
        @bindvars.collect! do |var|
            if var.is_a? DBI::Binary then
                oid = @db.__blob_create(PGconn::INV_WRITE)
                @db.__blob_write(oid, var.to_s)
                oid
            else
                var
            end
        end
        internal_prepare
        if not @db['AutoCommit'] then
            #          if not SQL.query?(boundsql) and not @db['AutoCommit'] then
            @db.start_transaction unless @db.in_transaction?
        end
p "A"
        if @db["pg_native_binding"]
p "B"
            pg_result = @db._exec_prepared(@stmt_name, *@bindvars)
        else
p "C"
            pg_result = @db._exec_prepared(@stmt_name)
        end
p "D"
        @result = DBI::DBD::Pg::Tuples.new(@db, pg_result)
    rescue PGError, RuntimeError => err
        raise DBI::ProgrammingError.new(err.message)
    end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../oddb/lib:../odba/lib start.rb 
...
"A"
"B"
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:75: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'
...

Notes

  • That means, '@db._exec_prepared(@stmt_name, *@bindvars)' causes the error

Experiment

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

module DBI::DBD::Pg
    ################################################################
    # Convenience adaptor to hide details command execution API calls.
    # See PgExecutorAsync subclass
    class PgExecutor
        def initialize(pg_conn)
            @pg_conn = pg_conn
        end

        def exec(sql, parameters = nil)
            @pg_conn.exec(sql, parameters)
        end

        def exec_prepared(stmt_name, parameters = nil)
p "getin DBI::DBD::Pg::PgExecutor#exec_prepared"
print "@pg_conn.class="
p @pg_conn.class
            @pg_conn.exec_prepared(stmt_name, parameters)
        end

Result

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ruby1.9 -I ../oddb/lib:../odba/lib start.rb 
...
"getin DBI::DBD::Pg::PgExecutor#exec_prepared"
@pg_conn.class=PGconn
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:75: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'
...

Note

  • Where is the PGconn class definition?
  • I guess PGconn is defined somewhere in 'pg' libraries by C language

suspend

Trace forward of the error message

Error

/usr/lib64/ruby/gems/1.9.1/gems/dbd-pg-0.3.9/lib/dbd/pg/statement.rb:75: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:96:in `execute'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/base_classes/database.rb:114:in `do'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:106:in `do'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:176:in `create_index'
        from /home/masa/ywesee/odba/lib/odba/index.rb:226:in `initialize'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:148:in `new'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:148:in `block in create_index'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:558:in `call'
        from /home/masa/ywesee/odba/lib/odba/storage.rb:558:in `block in transaction'
        from /usr/lib64/ruby/gems/1.9.1/gems/dbi-0.4.5/lib/dbi/handles/database.rb:209: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:554:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:520:in `transaction'
        from /home/masa/ywesee/odba/lib/odba/cache.rb:140: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:437: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>'

Experiment

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

        # Creates a new index according to IndexDefinition
        def create_index(index_definition, origin_module=Object)
print "index_definition.resolve_search_term="
p index_definition.resolve_search_term
            transaction {
                klass = if(index_definition.fulltext)
                                    FulltextIndex
                                elsif(index_definition.resolve_search_term.is_a?(Hash))
                                    ConditionIndex
                                else
                                    Index
                                end
print "klass="
p klass
print "index_definition="
p index_definition
print "origin_module="
p origin_module
                index = klass.new(index_definition, origin_module)
print "index="
p index
                indices.store(index_definition.index_name, index)
                indices.odba_store_unsaved
                index
            }
        end

Result

ERROR:  relation "target_id_oddb_drugs_sequence_fachinfo_indications_de" already exists

index_definition.resolve_search_term="name.all"
klass=ODBA::Index
index_definition=#<ODBA::IndexDefinition:0x0000000289eef8 @index_name="oddb_business_company_name", @origin_klass=ODDB::Business::Company, @target_klass=ODDB::Business::Company, @resolve_search_term="name.all", @resolve_target=:none, @resolve_origin="", @dictionary="", @init_source="", @fulltext=false, @class_filter=:is_a?>
origin_module=Object
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:75: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'

Note

  • The error comes from 'ODBA::Index#new'

Experiment

/home/masa/ywesee/odba/lib/odba/index.rb#initialize

    # Currently there are 3 predefined Index-classes
    # For Sample Code see
    # http://dev.ywesee.com/wiki.php/ODBA/SimpleIndex
    # http://dev.ywesee.com/wiki.php/ODBA/ConditionIndex
    # http://dev.ywesee.com/wiki.php/ODBA/FulltextIndex
    class Index < IndexCommon # :nodoc: all
        def initialize(index_definition, origin_module) # :nodoc:
p "getin ODBA::Index#new"
            super(index_definition, origin_module)
print "ODBA.storage.class="
p ODBA.storage.class
            ODBA.storage.create_index(index_definition.index_name)
        end

Result

"getin ODBA::Index#new"
ODBA.storage.class=ODBA::Storage

Note

  • The error comes from ODBA::Storage.create_index

Experiment

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

    def create_index(table_name)
p "getin create_index"
print "self.class="
p self.class
print "self.dbi.class="
p self.dbi.class
      self.dbi.do <<-SQL
        CREATE TABLE #{table_name} (
          origin_id INTEGER,
          search_term TEXT,
          target_id INTEGER
        );
      SQL
p "WWW"

Result

"getin create_index"
self.class=ODBA::Storage
self.dbi.class=DBI::DatabaseHandle
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:75: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'

Note

  • The error comes from DBI::DatabaseHandle#do

Experiment

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

        #
        # Perform a statement. This goes straight to the DBD's implementation
        # of #do (and consequently, BaseDatabase#do), and does not work like
        # #execute and #prepare. Should return a row modified count.
        #
        def do(stmt, *bindvars)
p "getin do"
print "self.class="
p self.class
            sanity_check(stmt)
            @last_statement = stmt
print "@handle.class="
p @handle.class
            @handle.do(stmt, *DBI::Utils::ConvParam.conv_param(driver_name, *bindvars))
p "end"
        end

Result

"getin do"
self.class=DBI::DatabaseHandle
@handle.class=DBI::DBD::Pg::Database
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:75: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'

Note

  • The error comes from DBI::DBD::Pg::Database#do
  • But DBI::DBD::Pg::Database class does not have 'do' method but it inherits DBI::BaseDatabase class

Experiment

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

        # Execute and complete the statement with the binds provided. Returns
        # the row modified count (via BaseStatement#rows). Finishes the
        # statement handle for you.
        #
        # Roughly equivalent to:
        #
        #   sth = dbh.prepare("my statement")
        #   sth.execute(my, bind, vars)
        #   result = sth.rows
        #   sth.finish
        #
        # Returning the value stored in `result`.
        def do(statement, *bindvars)
print "self.class="
p self.class
            stmt = execute(statement, *bindvars)
p "A"
            res = stmt.rows
            stmt.finish
            return res
        end

Result

self.class=DBI::DBD::Pg::Database
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:75:in `rescue in execute': ERROR:  relation "oddb_business_company_name" already exists (DBI::ProgrammingError)

Note

  • The error comes from DBI::DBD::Pg::Database#execute

Experiment

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

        # 
        # Execute a statement with the binds provided. Returns the statement
        # handle unfinished.
        #
        # This is roughly equivalent to:
        #
        #   sth = dbh.prepare("my statement")
        #   sth.execute(my, bind, vars)
        #   
        def execute(statement, *bindvars)
print "self.class="
p self.class
            stmt = prepare(statement)
p "A"
            stmt.bind_params(*bindvars)
print "stmt.class="
p stmt.class
            stmt.execute
p "B"
            stmt
        end

Result

self.class=DBI::DBD::Pg::Database
"A"
stmt.class=DBI::DBD::Pg::Statement
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:75:in `rescue in execute': ERROR:  relation "oddb_business_company_name" already exists (DBI::ProgrammingError)

Note

  • The error comes from DBI::DBD::Pg::Statement#execute

Experiment

    #
    # See DBI::BaseDatabase#execute.
    #
    # This method will make use of PostgreSQL's native BLOB support if
    # DBI::Binary objects are passed in.
    #
    def execute
        # replace DBI::Binary object by oid returned by lo_import
            if var.is_a? DBI::Binary then
                oid = @db.__blob_create(PGconn::INV_WRITE)
                @db.__blob_write(oid, var.to_s)
                oid
            else
                var
            end
        end
        internal_prepare
        if not @db['AutoCommit'] then
            #          if not SQL.query?(boundsql) and not @db['AutoCommit'] then
            @db.start_transaction unless @db.in_transaction?
        end
p "A"
        if @db["pg_native_binding"]
p "B"
print "@db.class="
p @db.class
            pg_result = @db._exec_prepared(@stmt_name, *@bindvars)
        else
p "C"
            pg_result = @db._exec_prepared(@stmt_name)
        end
p "D"

Result

"A"
"B"
@db.class=DBI::DBD::Pg::Database
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)

Note

  • The error comes from DBI::DBD::Pg::Database#_exec_prepared

Experiment

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

    def _exec_prepared(stmt_name, *parameters)
# masa
#p "DBI::DBD::Pg::Database#getin _exec_prepared"
print "@pgexec.class="
p @pgexec.class
        @pgexec.exec_prepared(stmt_name, parameters)
    end

Result

@pgexec.class=DBI::DBD::Pg::PgExecutor

Note

  • The error comes from DBI::DBD::Pg::PgExecutor#exec_prepared

Experiment

/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)
#p "getin DBI::DBD::Pg::PgExecutor#exec_prepared"
print "@pg_conn.class="
p @pg_conn.class
            @pg_conn.exec_prepared(stmt_name, parameters)
        end

Result

@pg_conn.class=PGconn
ERROR:  relation "oddb_business_company_name" already exists

Note

  • The error comes from PGconn#exec_prepared
  • It returns to PGconn#exec_prepared finally

Just for my information

Experiment

        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

@pg_conn.class=PGconn
stmt_name="ruby-dbi:Pg:214759001295621337.8080456"
parameters=[]

BraSt

  • What to do next?
    • Read and understand PGconn behavior
    • But this PGconn is probably defined in C source code
    • I have to recompile it everytime
    • Other solution is to jut try to avoid a new creation of relation in ODBA
    • It looks better to do first for me

Try to run ramaze oddb on Ruby 1.9.1

Install Ruby 1.9.1

Run ramaze version of oddb.org

masa@masa ~/ywesee/ramaze.ch.oddb.org $ ~/bin/ruby191/bin/ruby -I ../odba/lib:../oddb/lib start.rb
...
D [2011-01-21 16:36:07 $27219] DEBUG | : Using webrick
I [2011-01-21 16:36:07 $27219]  INFO | : WEBrick 1.3.1
I [2011-01-21 16:36:07 $27219]  INFO | : ruby 1.9.1 (2010-08-16) [x86_64-linux]
D [2011-01-21 16:36:07 $27219] DEBUG | : TCPServer.new(0.0.0.0, 7000)
D [2011-01-21 16:36:07 $27219] DEBUG | : Rack::Handler::WEBrick is mounted on /.
I [2011-01-21 16:36:07 $27219]  INFO | : WEBrick::HTTPServer#start: pid=27219 port=7000

Check gem list

masa@masa ~/ywesee/ramaze.ch.oddb.org $ sudo ~/bin/ruby191/bin/ruby /usr/bin/gem list

*** LOCAL GEMS ***

activesupport (2.3.3)
dbd-pg (0.3.9)
dbi (0.4.5)
deprecated (2.0.1)
facets (1.8.54)
haml (3.0.25)
innate (2010.07)
pg (0.8.0)
rack (1.2.1)
ramaze (2010.06.18)
rclconf (1.0.0)
rmagick (2.13.1)
rubygems-update (1.4.2)

Note

  • (I guess) Pgconn (Pg) does not work on Ruby 1.9.2, but it runs on Ruby 1.9.1 and Ruby 1.8
view · edit · sidebar · attach · print · history
Page last modified on January 19, 2012, at 02:27 PM