Patches: Browse | Submit New | Admin

[#16741] Patch for "undefined method `[]' for nil:NilClass" in column_info

Date:
2008-01-01 01:22
Priority:
3
Submitted By:
Nobody
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Patch for "undefined method `[]' for nil:NilClass" in column_info

Detailed description
Using version 2.7.3, the following script will raise an exception with the message "undefined method `[]'
for nil:NilClass" from the column_info method:

  require 'dbi'

  ::DBI::connect('dbi:Mysql:host=localhost', 'my_user', 'my_password') do |dbh|
    dbh.select_all("SHOW FULL PROCESSLIST") do |row|
      puts row.inspect
    end
  end

My solution was to add the following after the require to auto-coerce unknown types to String:

  # This fixes a bug in the library where an unknown type will cause
  # exceptions to be raised, rather than using a reasonable default: String
  # coercion.
  require 'DBD/Mysql/Mysql'
  class DBI::DBD::Mysql::Database
    TYPE_MAP.default = TYPE_MAP[nil] if TYPE_MAP.default.nil?
  end

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item