Skip to content

Instantly share code, notes, and snippets.

@senny
Last active December 24, 2015 11:39
Show Gist options
  • Save senny/6792797 to your computer and use it in GitHub Desktop.
Save senny/6792797 to your computer and use it in GitHub Desktop.
Mysql Quoting patch
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 552a22d..6ffd4ba 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -61,7 +61,7 @@ module ActiveRecord
if column && column.type == :integer
value ? 1 : 0
else
- value ? 't' : 'f'
+ value ? true_value : false_value
end
# BigDecimals need to be put in a non-normalized form and quoted.
when nil then nil
@@ -103,6 +103,14 @@ module ActiveRecord
quote_table_name("#{table}.#{attr}")
end
+ def true_value
+ "t"
+ end
+
+ def false_value
+ "f"
+ end
+
def quoted_true
"'t'"
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index ee6ca4f..dba9778 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -206,12 +206,6 @@ module ActiveRecord
true
end
- def type_cast(value, column)
- return super unless value == true || value == false
-
- value ? 1 : 0
- end
-
# MySQL 4 technically support transaction isolation, but it is affected by a bug
# where the transaction level gets persisted for the whole session:
#
@@ -268,6 +262,14 @@ module ActiveRecord
@quoted_table_names[name] ||= quote_column_name(name).gsub('.', '`.`')
end
+ def true_value
+ 1
+ end
+
+ def false_value
+ 0
+ end
+
def quoted_true
QUOTED_TRUE
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment