Permalink
Browse files

Add mysql2 compatibility

  • Loading branch information...
1 parent 64005f1 commit 5f24ecb26e1ddc5e272c273a83acb94758003f35 @grobie committed Mar 25, 2012
View
@@ -5,5 +5,6 @@ rvm:
- 1.8.7
- 1.9.3
gemfile:
- - gemfiles/ar-2.3.gemfile
- - gemfiles/ar-3.2.gemfile
+ - gemfiles/ar-2.3_mysql.gemfile
+ - gemfiles/ar-3.2_mysql.gemfile
+ - gemfiles/ar-3.2_mysql2.gemfile
View
@@ -1,6 +1,7 @@
# 1.1.0 (not released yet)
* Add option to specify custom index name
+* Add mysql2 compatibility
# 1.0.3 (February 23, 2012)
@@ -1,4 +1,5 @@
source :rubygems
+gem "mysql", "~> 2.8.1"
gem "activerecord", "~> 2.3.14"
gemspec :path=>"../"
@@ -1,4 +1,5 @@
source :rubygems
+gem "mysql", "~> 2.8.1"
gem "activerecord", "~> 3.2.2"
gemspec :path=>"../"
@@ -0,0 +1,5 @@
+source :rubygems
+
+gem "mysql2", "~> 0.3.11"
+gem "activerecord", "~> 3.2.2"
+gemspec :path=>"../"
View
@@ -19,8 +19,6 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.executables = ["lhm-kill-queue"]
- # this should be a real dependency, but we're using a different gem in our code
- s.add_development_dependency "mysql", "~> 2.8.1"
s.add_development_dependency "minitest", "= 2.10.0"
s.add_development_dependency "rake"
View
@@ -28,15 +28,15 @@ def sql(statements)
[statements].flatten.each do |statement|
connection.execute(tagged(statement))
end
- rescue ActiveRecord::StatementInvalid, Mysql::Error => e
+ rescue ActiveRecord::StatementInvalid => e
error e.message
end
def update(statements)
[statements].flatten.inject(0) do |memo, statement|
memo += connection.update(tagged(statement))
end
- rescue ActiveRecord::StatementInvalid, Mysql::Error => e
+ rescue ActiveRecord::StatementInvalid => e
error e.message
end
View
@@ -38,7 +38,9 @@ def initialize(table_name, connection)
def ddl
sql = "show create table `#{ @table_name }`"
- @connection.execute(sql).fetch_row.last
+ specification = nil
+ @connection.execute(sql).each { |row| specification = row.last }
+ specification
end
def parse
@@ -4,34 +4,39 @@
require File.expand_path(File.dirname(__FILE__)) + "/../bootstrap"
require 'active_record'
+begin
+ require 'mysql2'
+rescue LoadError
+ require 'mysql'
+end
require 'lhm/table'
require 'lhm/sql_helper'
module IntegrationHelper
- attr_accessor :connection
-
#
# Connectivity
#
+ def connection
+ ActiveRecord::Base.connection
+ end
+
def connect_master!
- @connection = connect!(3306)
+ connect!(3306)
end
def connect_slave!
- @connection = connect!(3307)
+ connect!(3307)
end
def connect!(port)
ActiveRecord::Base.establish_connection(
- :adapter => 'mysql',
+ :adapter => defined?(Mysql2) ? 'mysql2' : 'mysql',
:host => '127.0.0.1',
:database => 'lhm',
:username => '',
:port => port
)
-
- ActiveRecord::Base.connection
end
def select_one(*args)

0 comments on commit 5f24ecb

Please sign in to comment.