instance method
unquote_mariadb_default
Ruby on Rails edge
Since edge Private — implementation detail, not part of the public APISignature
unquote_mariadb_default(field)
MariaDB reports a default as the SQL literal that produced it, where ‘SHOW FULL FIELDS` reports the value: a literal comes back quoted, and a newline inside one is written `\n`. Put them back into the form #new_column_from_field reads.
Parameters
-
fieldreq
Source
# File activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb, line 1098
def unquote_mariadb_default(field)
default = field["Default"]
return if default.nil?
if default == "NULL"
# A column declared DEFAULT NULL, which has no default at all.
field["Default"] = nil
elsif !default.start_with?("'")
# An expression rather than a value. A bare `(1 + 1)` is left alone,
# which is what reading the table directly reports too.
if /[a-zA-Z_]\w*\(/.match?(default) && !/\ACURRENT_TIMESTAMP/i.match?(default)
field["Extra"] = "DEFAULT_GENERATED"
end
elsif !/\A(?:tiny|medium|long)?(?:text|blob)\b/.match?(field["Type"])
# Text and blob defaults stay quoted; #new_column_from_field unquotes those.
field["Default"] = default[1...-1].gsub("''", "'")
.gsub(/\\(.)/) { MARIADB_DEFAULT_ESCAPES.fetch($1, "\\#{$1}") }
end
end
Defined in activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb line 1098
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter