view · edit · sidebar · attach · print · history

20110105-update-dbi-pg-oddb_org

<< | Index | >>


  1. Test the latest pg (PostgreSQL driver) and dbi on oddb.org
  2. Check the function of activesupport and deprecated in oddb.org
  3. Check the relation between dbi (0.4.5) and deprecated (2.0.1)
  4. Try rdbi as an alternative of dbi 0.4.5
  5. Check dbi and pg on local linux
  6. Check dbi and pg on Windows7

Goal
  • Upgrade dbi and pg / 80%
Milestones
  1. Check if the pg latest version works on oddb.org
  2. Try rdbi suspend
  3. Install oddb.org on win
Summary
Commits
ToDo Tomorrow
Keep in Mind
  1. swissmedic_followers debug
  2. On Ice
  3. emerge --sync

Test the latest pg (PostgreSQL driver) and dbi on oddb.org

Check gem (pg, dbi)

masa@masa ~ $ gem search dbi

*** LOCAL GEMS ***


masa@masa ~ $ gem search pg

*** LOCAL GEMS ***

pg (0.8.0)

Check emerge (pg, dbi)

masa@masa ~ $ emerge -s dbi
*  dev-ruby/ruby-dbi
      Latest version available: 0.2.0-r1
      Latest version installed: 0.2.0-r1
      Size of files: 97 kB
      Homepage:      http://ruby-dbi.rubyforge.org
      Description:   Ruby/DBI - a database independent interface for accessing databases - similar to Perl's DBI
      License:       BSD

masa@masa ~ $ emerge -s pg
*  dev-ruby/pg
      Latest version available: 0.10.0
      Latest version installed: 0.9.0-r1
      Size of files: 110 kB
      Homepage:      http://bitbucket.org/ged/ruby-pg/
      Description:   Ruby extension library providing an API to PostgreSQL
      License:       || ( GPL-2 Ruby )

Note

  • 'pg' is installed through RubyGems and emerge
  • 'dbi' is installed through emerge

Check oddb.org working

Result

  • No problem

Uninstall 'pg' through emerge

masa@masa ~ $ sudo emerge -C dev-ruby/pg

Check oddb.org

  • Still works

Upgrade pg

masa@masa ~ $ sudo gem install pg
ERROR:  Error installing pg:
        pg requires Ruby version >= 1.8.7.

Install gp version 0.9.0

masa@masa ~ $ sudo gem install pg --version "= 0.9.0"
Building native extensions.  This could take a while...
Successfully installed pg-0.9.0
1 gem installed
/usr/lib64/ruby/gems/1.8/gems/rdoc-2.5.11/lib/rdoc/ruby_lex.rb:67: warning: parenthesize argument(s) for future version
Installing ri documentation for pg-0.9.0...
Installing RDoc documentation for pg-0.9.0...

Note

  • It works

Check oddb.org

  • Still works
    • pg version 0.9.0 (gem)
    • dbi version 0.2.0 (emerge)

Uninstall dbi

masa@masa ~ $ sudo emerge -C ruby-dbi

Check oddb.org

  • bin/oddbd does not start
masa@masa ~/ywesee/oddb.org $ ruby bin/oddbd 
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- dbi (LoadError)
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/site_ruby/1.8/odba/storage.rb:6
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/site_ruby/1.8/odba.rb:61
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:4
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/oddbd:9

Note

  • It is as expected

Install the latest dbi through gem

masa@masa ~ $ sudo gem install dbi
Successfully installed deprecated-2.0.1
Successfully installed dbi-0.4.5
2 gems installed
/usr/lib64/ruby/gems/1.8/gems/rdoc-2.5.11/lib/rdoc/ruby_lex.rb:67: warning: parenthesize argument(s) for future version
Installing ri documentation for deprecated-2.0.1...
Installing ri documentation for dbi-0.4.5...
Installing RDoc documentation for deprecated-2.0.1...
Installing RDoc documentation for dbi-0.4.5...

Note

  • 'deprecated-2.0.1' is also installed
  • This is also as I expected

Check oddb.org

  • An error when bin/oddbd starts
/usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `instance_method': {:metaclass=>:singleton_class} is not a symbol (TypeError)
        from /usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `deprecate'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object/metaclass.rb:13
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object.rb:5
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext.rb:8
         ... 10 levels...
        from /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:26
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/oddbd:9

Uninstall deprecated

masa@masa ~ $ sudo gem uninstall deprecated

You have requested to uninstall the gem:
        deprecated-2.0.1
dbi-0.4.5 depends on [deprecated (= 2.0.1)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]  Y
Successfully uninstalled deprecated-2.0.1

Check oddb.org

  • Another error when bin/oddbd starts
masa@masa ~/ywesee/oddb.org $ ruby bin/oddbd 
/usr/lib64/ruby/site_ruby/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem deprecated (= 2.0.1) (Gem::LoadError)
        from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:214:in `activate'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:249:in `activate'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:248:in `each'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems.rb:248:in `activate'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:35:in `require'
        from /usr/lib64/ruby/site_ruby/1.8/odba/storage.rb:6
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/site_ruby/1.8/odba.rb:61
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:4
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/oddbd:9

Uninstall dbi from gem

masa@masa ~ $ sudo gem uninstall dbi
Remove executables:
        dbi, test_broken_dbi

in addition to the gem? [Yn]  Y
Removing dbi
Removing test_broken_dbi
Successfully uninstalled dbi-0.4.5

Install ruby-dbi (0.2.0) throuhg emerge again

masa@masa ~ $ sudo emerge ruby-dbi
>>> Installing (1 of 2) dev-ruby/ruby-postgres-0.7.9.20080128-r1
>>> Installing (2 of 2) dev-ruby/ruby-dbi-0.2.0-r1

Note

  • 'ruby-postgres-0.7.9.20080128-r1' is also installed

Check oddb.org

  • It works

Uninstall ruby-postgres from emerge

masa@masa ~ $ sudo emerge -C ruby-postgres

Check oddb.org

  • It works

Conclusion

  • 'pg' version 0.9.0 can work
  • 'pg' version 0.10.0 cannot be installed since it requires Ruby 1.8.7
  • 'ruby-postgres-0.7.9.20080128-r1' is not necessary
  • 'dbi' version 0.2.0 is at the moment required
  • 'dbi' version 0.4.5 cannot work since it depends on 'deprecated-0.2.0' which causes an error

Check the function of activesupport and deprecated in oddb.org

Current condition

  • dbi 0.4.5
  • install deprecated 2.0.1

Trace error message

/usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `instance_method': {:metaclass=>:singleton_class} is not a symbol (TypeError)
        from /usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `deprecate'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object/metaclass.rb:13
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object.rb:5
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext.rb:8
         ... 10 levels...
        from /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:26
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/oddbd:9

Look at the hidden error messages

/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:26

begin
require 'paypal'
rescue => e
  puts e.backtrace
  exit
end

Result

/usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `instance_method'
/usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `deprecate'
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object/metaclass.rb:13
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object.rb:5
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext.rb:8
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext.rb:8:in `each'
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext.rb:8
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support.rb:56
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/usr/lib64/ruby/gems/1.8/gems/paypal-2.0.0/lib/paypal.rb:27
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:27
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
bin/oddbd:9

Question

  • Why does oddbd run if 'deprecated' is not installed
  • (Why does 'deprecated' cause an error)

Check /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object/metaclass.rb

require 'active_support/deprecation'

class Object
  # Get object's meta (ghost, eigenclass, singleton) class.
  #
  # Deprecated in favor of Object#singleton_class.
  def metaclass
    class << self
      self
    end
  end

  deprecate :metaclass => :singleton_class
end

Note

  • From this 'deprecate' calls 'deprecated' library, '/usr/lib64/ruby/gems/1.8/gems/deprecated-2.0.1/lib/deprecated.rb:176:in `deprecate''

Consideration

  • If there is no 'deprecated' library installed, the 'deprecate' calls (probably) a method in 'active_support/deprecation'
  • But if 'deprecated' library is installed, the 'deprecate' calls a method of 'deprecated' library

Experiment

/usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/deprecation.rb

      def deprecate(*method_names)
        options = method_names.extract_options!
        method_names = method_names + options.keys
        method_names.each do |method_name|
          alias_method_chain(method_name, :deprecation) do |target, punctuation|
            class_eval(<<-EOS, __FILE__, __LINE__ + 1)
              def #{target}_with_deprecation#{punctuation}(*args, &block)          # def generate_secret_with_deprecation(*args, &block)
                ::ActiveSupport::Deprecation.warn(                                 #   ::ActiveSupport::Deprecation.warn(
                  self.class.deprecated_method_warning(                            #     self.class.deprecated_method_warning(
                    :#{method_name},                                               #       :generate_secret,
                    #{options[method_name].inspect}),                              #       "You should use ActiveSupport::SecureRandom.hex(64)"),
                  caller                                                           #     caller
                )                                                                  #   )
                send(:#{target}_without_deprecation#{punctuation}, *args, &block)  #   send(:generate_secret_without_deprecation, *args, &block)
              end                                                                  # end
            EOS
          end
        end
      end

and then add

 alias :masa :deprecate

to the last line of

 /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/deprecation.rb

further also add

 masa :metaclass => :singleton_class
 #deprecate :metaclass => :singleton_class

to

 /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/object/metaclass.rb

Result

masa@masa ~/ywesee/oddb.org $ bin/oddbd
/usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:300:in `load_driver': Unable to load driver 'Pg' (underlying error: uninitialized constant DBI::DBD::Pg) (DBI::InterfaceError)
        from /usr/lib64/ruby/1.8/monitor.rb:242:in `synchronize'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:60:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `times'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:59:in `_connect'
        from /usr/lib64/ruby/site_ruby/1.8/odba/connection_pool.rb:56:in `connect'
         ... 7 levels...
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in `new_constants_in'
        from /usr/lib64/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in `require'
        from bin/oddbd:10

Note

  • The error has gone
  • But another error comes
'deprecate' method is used and defined in 'activesupport' library, but
also 'deprecate' method is defined in 'deprecated' library with a
different meaning.
'activesupport' tries to call 'deprecate' method from 'deprecated' library.
This is the cause of error.

Check dbd-pg version on gem

masa@masa ~/ywesee/oddb.org $ gem search dbd-pg -ra

*** REMOTE GEMS ***

dbd-pg (0.3.9, 0.3.8, 0.3.7, 0.3.6, 0.3.5, 0.3.4, 0.3.3)

Install dbd-pg version 0.3.9

masa@masa ~/ywesee/oddb.org $ sudo gem install dbd-pg

Check oddb.org

  • It works!!

Memo

masa@masa ~/ywesee/oddb.org $ sudo gem uninstall pg

You have requested to uninstall the gem:
        pg-0.9.0
dbd-pg-0.3.9 depends on [pg (>= 0)]

Check the installed libraries

*  dev-ruby/ruby-dbi
      Latest version available: 0.2.0-r1
      Latest version installed: [ Not Installed ]
      Size of files: 97 kB
      Homepage:      http://ruby-dbi.rubyforge.org
      Description:   Ruby/DBI - a database independent interface for accessing databases - similar to Perl's DBI
      License:       BSD

*  dev-ruby/ruby-postgres
      Latest version available: 0.7.9.20080128-r1
      Latest version installed: [ Not Installed ]
      Size of files: 32 kB
      Homepage:      http://ruby.scripting.ca/postgres
      Description:   An extension library to access a PostgreSQL database from Ruby
      License:       GPL-2 Ruby

*  dev-ruby/dbd-pg
      Latest version available: 0.3.9
      Latest version installed: [ Not Installed ]
      Size of files: 63 kB
      Homepage:      http://ruby-dbi.rubyforge.org
      Description:   The PostgreSQL database driver (DBD) for Ruby/DBI
      License:       BSD

*  dev-ruby/pg
      Latest version available: 0.10.0
      Latest version installed: [ Not Installed ]
      Size of files: 110 kB
      Homepage:      http://bitbucket.org/ged/ruby-pg/
      Description:   Ruby extension library providing an API to PostgreSQL
      License:       || ( GPL-2 Ruby )

Note

  • There is nothing installed from emerge
masa@masa ~/ywesee/oddb.org $ gem list

*** LOCAL GEMS ***

activesupport (2.3.8)
dbd-pg (0.3.9)
dbi (0.4.5)
deprecated (2.0.1)
pg (0.9.0)

Note

  • 'pg' and 'dbd-pg' are necessary for 'dbi' version 0.4.5
  • 'dbd-pg' requires 'pg'
  • 'dbi' version 0.4.5 requires 'deprecated-2.0.1'
  • 'deprecate' method is deprecated between 'activesupport' and 'deprecated' libraries
  • We have to do something to avoid the collision of the methods

Summary

  • dbi version 0.4.5 can work for oddb.org but we need a little bit modifications regarding 'deprecate' method in 'activesupport' and 'deprecated' libraries
  • Also we have to install 'dbd-pg' through gem
  • These can run on Ruby 1.8.6 with oniguruma

Try rdbi as an alternative of dbi 0.4.5

Result

  • It seems that many libraries depend on 'dbi'
  • So, we have to replace many parts of code in order to use 'rdbi'

Check dbi and pg on local linux

Memo

  • I check first dbi and pg (driver) on local linux
  • Then I check dbi and pg (driver) on windows with the same script
  • If this script does not run, of course ODBA does not run

dbi and pg test by using a simple script

dbi_test.rb

require 'dbi'

begin
print "Available drivers="
p DBI.available_drivers
   # connection to database
   dbh = DBI.connect("dbi:pg:testdb:localhost", "masa", "")
   # get server version string
   row = dbh.select_one("select version()")
   puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
   puts "An error occurred"
   puts "Error code: #{e.err}"
   puts "Error message: #{e.errstr}"
ensure
   # disconnect
   dbh.disconnect if dbh
end

Check libraries

  • ruby-dbi 0.2.0 (emerge)
  • pg 0.9.0 (gem)

Result

masa@masa ~/work $ ruby dbi_test.rb 
Available drivers=["dbi:SQLRelay:", "dbi:Proxy:", "dbi:Pg:"]
Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit

Uninstall

  • ruby-dbi 0.2.0 (emerge)

Install

  • dbi 0.4.5 (gem)
  • deprecated 2.0.1 (gem)

Result

masa@masa ~/work $ ruby dbi_test.rb 
Available drivers=[]
/usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:300:in `load_driver': Unable to load driver 'pg' (underlying error: wrong constant name pg) (DBI::InterfaceError)
        from /usr/lib64/ruby/1.8/monitor.rb:242:in `synchronize'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
        from /usr/lib64/ruby/gems/1.8/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
        from dbi_test2.rb:11

Uninstall

  • dbi 0.4.5 (gem)
  • ruby-dbi 0.2.0 (emerge)

Install

  • ruby-dbi 0.4.5 (emerge)
    • deprecated 3.0.0 (emerge)
    • dbd-pg 0.3.9 (emerge)
    • pg 0.10.0 (emerge)

Uninstall

  • deprecated 3.0.0 (emerge)
  • pg 0.10.0 (emerge)

Now

  • ruby-dbi 0.4.5 (emerge)
  • deprecated 2.0.1 (gem)
  • dbd-pg 0.3.9 (emerge)
  • pg 0.9.0 (gem)
*  dev-ruby/dbd-pg
      Latest version available: 0.3.9
      Latest version installed: 0.3.9
      Size of files: 63 kB
      Homepage:      http://ruby-dbi.rubyforge.org
      Description:   The PostgreSQL database driver (DBD) for Ruby/DBI
      License:       BSD
*  dev-ruby/pg
      Latest version available: 0.10.0
      Latest version installed: [ Not Installed ]
      Size of files: 110 kB
      Homepage:      http://bitbucket.org/ged/ruby-pg/
      Description:   Ruby extension library providing an API to PostgreSQL
      License:       || ( GPL-2 Ruby )
*  dev-ruby/ruby-dbi
      Latest version available: 0.4.3
      Latest version installed: 0.4.3
      Size of files: 79 kB
      Homepage:      http://ruby-dbi.rubyforge.org
      Description:   Ruby/DBI - a database independent interface for accessing databases - similar to Perl's DBI
      License:       BSD
masa@masa ~/work $ gem list
deprecated (2.0.1)
pg (0.9.0)

Note

  • When 'ruby-dbi' is installed through emerge, 'deprecated 3.0.0' is also installed at the same time, but
  • 'ruby-dbi' 0.4.5 requires 'deprecated' version 2.0, so that 'deprecated 3.0.0' should be uninstalled

Result

masa@masa ~/work $ ruby dbi_test.rb 
Available drivers=["dbi:Pg:"]
Server version: PostgreSQL 8.4.2 on x86_64-pc-linux-gnu, compiled by GCC x86_64-pc-linux-gnu-gcc (Gentoo 4.4.3 p1.0) 4.4.3, 64-bit

Note

  • 'dbd-pg' and 'pg' in gem are not recognized by 'dbi' 0.4.5 (gem)

Check dbi and pg on Windows7

Check the current condition of my Windows7

  • PostgreSQL 8.4 is installed but it does not run looks running
  • I confirmed that SQL Shell (psql) runs
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Passwort f³r Benutzer postgres:
psql (8.4.6)
Warnung: Konsolencodeseite (850) unterscheidet sich von der Windows-
         Codeseite (1252). 8-Bit-Zeichen funktionieren möglicherweise nicht
         richtig. Einzelheiten finden Sie auf der psql-Handbuchseite unter
         »Notes for Windows users«.
Geben Sie »help« für Hilfe ein.

postgres=# \l
                                           Liste der Datenbanken
   Name    | Eigent\xFCmer | Kodierung |    Sortierfolge     |     Zeichentyp      |  Zugriffsprivilegien
-----------+---------------+-----------+---------------------+---------------------+-----------------------
 postgres  | postgres      | UTF8      | German, Switzerland | German, Switzerland |
 template0 | postgres      | UTF8      | German, Switzerland | German, Switzerland | =c/postgres
                                                                                   : postgres=CTc/postgres
 template1 | postgres      | UTF8      | German, Switzerland | German, Switzerland | =c/postgres
                                                                                   : postgres=CTc/postgres
(3 Zeilen)


postgres=#

Test dbi script

C:\Users\masa>gem list

*** LOCAL GEMS ***

dbd-pg (0.3.9)
dbi (0.4.5)
deprecated (2.0.1)
pg (0.9.0 x86-mingw32)
C:\Users\masa>type test.rb
require 'dbi'

begin
print "Available drivers="
p DBI.available_drivers
   # connection to database
   dbh = DBI.connect("dbi:pg:testdb:localhost", "masa", "")
   # get server version string
   row = dbh.select_one("select version()")
   puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
   puts "An error occurred"
   puts "Error code: #{e.err}"
   puts "Error message: #{e.errstr}"
ensure
   # disconnect
   dbh.disconnect if dbh
end

Result

C:\Users\masa>ruby -rubygems test.rb
Available drivers=[]
An error occurred
Error code:
Error message: fe_sendauth: no password supplied

Note

  • 'dbi:pg' is not recognized

Experiment

test.rb

require 'rubygems'
require 'dbi'

begin
print "Available drivers="
p DBI.available_drivers
   # connection to database
   dbh = DBI.connect("dbi:pg:postgres:localhost", "postgres", "xxx")
   #dbh = DBI.connect("dbi:pg:testdb:localhost", "masa", "")
   # get server version string
   row = dbh.select_one("select version()")
   puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
   puts "An error occurred"
   puts "Error code: #{e.err}"
   puts "Error message: #{e.errstr}"
ensure
   # disconnect
   dbh.disconnect if dbh
end

Result

C:\Users\masa>ruby test.rb
Available drivers=[]
Server version: PostgreSQL 8.4.6, compiled by Visual C++ build 1400, 32-bit

Note

  • 'Available drivers' is empty but it works...

gem list

C:\Users\masa>gem list

*** LOCAL GEMS ***

dbd-pg (0.3.9)
dbi (0.4.5)
deprecated (2.0.1)
pg (0.9.0 x86-mingw32)

Ruby version

C:\Users\masa>ruby -v
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]

Experiment (create a new database)

  • I cannot create a new user and database

Re-install PostgreSQL 8.4

Point

  • Execute the installer as 'Administrator' (choose from right-click menu)
  • Locate should be 'C'
  • Data should be stored NOT under C:\Program Files, I choose C:\pgdata\8.4

Reference

Check test.rb

C:\Users\masa>ruby test.rb
Available drivers=[]
Server version: PostgreSQL 8.4.6, compiled by Visual C++ build 1400, 32-bit
view · edit · sidebar · attach · print · history
Page last modified on January 12, 2011, at 10:47 AM