aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-09-25 15:49:35 +0000
committerJamis Buck <jamis@37signals.com>2005-09-25 15:49:35 +0000
commitea654654226924f9b900e7981fdbdbd452ca15d8 (patch)
tree606aefd628d9e31eababdefc59b02c3b29d51867 /activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
parente7059fd28191a77d53e66389f8df5b22036699e8 (diff)
downloadrails-ea654654226924f9b900e7981fdbdbd452ca15d8.tar.gz
rails-ea654654226924f9b900e7981fdbdbd452ca15d8.tar.bz2
rails-ea654654226924f9b900e7981fdbdbd452ca15d8.zip
Standardize the interpretation of boolean columns in the Mysql and Sqlite adapters. (Use MysqlAdapter.emulate_booleans = false to disable this behavior)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2335 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/mysql_adapter.rb')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 426d035bae..eea47817f6 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -41,6 +41,14 @@ module ActiveRecord
end
module ConnectionAdapters
+ class MysqlColumn < Column #:nodoc:
+ private
+ def simplified_type(field_type)
+ return :boolean if MysqlAdapter.emulate_booleans && field_type.downcase == "tinyint(1)"
+ super
+ end
+ end
+
# The MySQL adapter will work with both Ruby/MySQL, which is a Ruby-based MySQL adapter that comes bundled with Active Record, and with
# the faster C-based MySQL/Ruby adapter (available both as a gem and from http://www.tmtm.org/en/mysql/ruby/).
#
@@ -56,7 +64,17 @@ module ActiveRecord
# * <tt>:sslcert</tt> -- Necessary to use MySQL with an SSL connection
# * <tt>:sslcapath</tt> -- Necessary to use MySQL with an SSL connection
# * <tt>:sslcipher</tt> -- Necessary to use MySQL with an SSL connection
+ #
+ # By default, the MysqlAdapter will consider all columns of type tinyint(1)
+ # as boolean. If you wish to disable this emulation (which was the default
+ # behavior in versions 0.13.1 and earlier) you can add the following line
+ # to your environment.rb file:
+ #
+ # ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false
class MysqlAdapter < AbstractAdapter
+ @@emulate_booleans = true
+ cattr_accessor :emulate_booleans
+
LOST_CONNECTION_ERROR_MESSAGES = [
"Server shutdown in progress",
"Broken pipe",
@@ -126,7 +144,7 @@ module ActiveRecord
def columns(table_name, name = nil)
sql = "SHOW FIELDS FROM #{table_name}"
columns = []
- execute(sql, name).each { |field| columns << Column.new(field[0], field[4], field[1], field[2] == "YES") }
+ execute(sql, name).each { |field| columns << MysqlColumn.new(field[0], field[4], field[1], field[2] == "YES") }
columns
end
@@ -184,6 +202,9 @@ module ActiveRecord
end
+ def quoted_true() "1" end
+ def quoted_false() "0" end
+
def quote_column_name(name)
"`#{name}`"
end