Sunday, February 13, 2011

MySQL Gem and “uninitialized constant MysqlCompat::MysqlRes” on Linux

Stumbled across the same MySQL Gem error (uninitialized constant MysqlCompat::MysqlRes) that I ran into recently on OSX/Snow Leopard when upgrading/building the MySQL 2.8.11 Gem against MySQL 5.5 client libraries on Linux.

Steps to fix this are below:

... assuming you've already unpackaged the mysql source into a directory (my steps assume it's in /usr/local/mysql) ...


  1. Install the MySQL Ruby gem w/ the correct architecture (-arch i386 for 32bit or -arch x86_64 for 64bit): env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

  2. Check if an existing mysql library configuration file exists for the linux shared library (ld) in /etc/ld.so.conf.d directory.

  3. If the library exists, edit it and update the path to your source (/usr/local/mysql/lib)

  4. If the library DOES NOT exist, create a new file named "mysql.conf" containing "/usr/local/mysql/lib" (echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf).

  5. run "ldconfig"



You can verify your MySQL gem's library references by using "ldd" on the "mysql_api.so" file within the gem's installation directory:

BEFORE (w/out update):

ngeren@....:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib# ldd mysql_api.so
linux-gate.so.1 => (0xb7f50000)
libmysqlclient.so.16 => not found
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7f15000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7eee000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7ee5000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7ee1000)
libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7eaf000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d51000)
/lib/ld-linux.so.2 (0xb7f51000)

AFTER:

ngeren@.....:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib# ldd mysql_api.so
linux-gate.so.1 => (0xb809a000)
libmysqlclient.so.16 => /usr/local/mysql/lib/libmysqlclient.so.16 (0xb7d47000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7d2e000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7d07000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7cfe000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7cfa000)
libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7cc8000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b6a000)
/lib/ld-linux.so.2 (0xb809b000)

Friday, February 11, 2011

AuthorizeNetCimGateway create_customer_profile and update_customer_payment_profile not supporting validation mode

ActiveMerchant::Billing::AuthorizeNetCimGateway "create_customer_profile" and "update_customer_payment_profile" method does not support the "validation_mode" option, which tells Authorize.net how to perform validations against the optionally provided payment profile(s) (See bottom of page 14 of CIM XML implementation guide - "validationMode"). The patch below implements the support for the missing option in both methods.


module ActiveMerchant
module Billing
class AuthorizeNetCimGateway < Gateway

alias :original_build_create_customer_profile_request :build_create_customer_profile_request
def build_create_customer_profile_request(xml, options)
add_profile( xml, options[:profile] )
xml.tag!( 'validationMode', CIM_VALIDATION_MODES[ options[:validation_mode] ] ) if options[:validation_mode]
xml.target!
end

alias :original_build_update_customer_payment_profile_request :build_update_customer_payment_profile_request
def build_update_customer_payment_profile_request(xml, options)
xml.tag!('customerProfileId', options[:customer_profile_id])
xml.tag!('paymentProfile') do
add_payment_profile(xml, options[:payment_profile])
end
xml.tag!( 'validationMode', CIM_VALIDATION_MODES[ options[:validation_mode] ] ) if options[:validation_mode]
xml.target!
end
end
end
end

Wednesday, February 09, 2011

Ruby, Rails and MySQL 5.5 Oh my!

I've seen many postings regarding issues with running 64bit Ruby, Rails and MySQL 5.5 in Leopard/Snow Leopard, especially regarding the missing const error "MysqlCompat::MysqlRes" and the mysql.bundle library issues. After investing about an hour, I had an upgraded MySQL 5.5 and MySQL gem 2.8.1 installation, and I did it like this ...


  1. Download and install MySQL 5.5 (I untar it in /usr/local and create a "msyql" symlink to ease upgrades) - configure your /etc/my.cnf as necessary.

  2. Fire up your new MySQL installation to make sure it works (/usr/local/mysql/bin/mysqld_safe ...) will work for now, or you can go ahead and enable startup via launchctl.

  3. Uninstall all mysql gems (root and individual user level gems).

  4. Install the new gem for root:

    1. sudo su - (if you're not already root)

    2. env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

    3. install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle

    4. vi (or mate) /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/test/test_mysql.rb - add a require "rubygems"

    5. ruby test_mysql.rb - see if everything passes:
      (115 tests, 391 assertions, 0 failures, 0 errors)



  5. For user installed gem, do the same as you did for the root user, except update your paths accordingly.



--Noel (ngeren)