aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-25 17:56:03 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-25 17:56:03 +0000
commitb3df95985a449fd155868b4ec04a556530a03e6c (patch)
treed5ebffef075e2dc6680c4a81adc6ad237835fbfa /activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
parentea654654226924f9b900e7981fdbdbd452ca15d8 (diff)
downloadrails-b3df95985a449fd155868b4ec04a556530a03e6c.tar.gz
rails-b3df95985a449fd155868b4ec04a556530a03e6c.tar.bz2
rails-b3df95985a449fd155868b4ec04a556530a03e6c.zip
Refactored the AbstractAdapter to be a lot less scary. Cleaned up the docs and style for the OSS adapters
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2339 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/quoting.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
new file mode 100644
index 0000000000..7f7cc03c7a
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -0,0 +1,42 @@
+module ActiveRecord
+ module ConnectionAdapters # :nodoc:
+ # TODO: Document me!
+ module Quoting
+ def quote(value, column = nil)
+ case value
+ when String
+ if column && column.type == :binary
+ "'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode)
+ elsif column && [:integer, :float].include?(column.type)
+ value.to_s
+ else
+ "'#{quote_string(value)}'" # ' (for ruby-mode)
+ end
+ when NilClass then "NULL"
+ when TrueClass then (column && column.type == :boolean ? quoted_true : "1")
+ when FalseClass then (column && column.type == :boolean ? quoted_false : "0")
+ when Float, Fixnum, Bignum then value.to_s
+ when Date then "'#{value.to_s}'"
+ when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
+ else "'#{quote_string(value.to_yaml)}'"
+ end
+ end
+
+ def quote_string(s)
+ s.gsub(/\\/, '\&\&').gsub(/'/, "''") # ' (for ruby-mode)
+ end
+
+ def quote_column_name(name)
+ name
+ end
+
+ def quoted_true
+ "'t'"
+ end
+
+ def quoted_false
+ "'f'"
+ end
+ end
+ end
+end \ No newline at end of file