Spec-Zone.ru › Ruby on Rails 4.1

модуль ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Quoting

Публичные методы экземпляра

escape_bytea(value) Показать исходный код

Экранирует двоичные строки для ввода bytea в базу данных.

# File activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb, line 6
def escape_bytea(value)
  PGconn.escape_bytea(value) if value
end
quote_table_name(name) Показать исходный код

Проверяет следующие случаи:

  • имя_таблицы

  • “таблица.имя”

  • имя_схемы.имя_таблицы

  • имя_схемы.“таблица.имя”

  • “схема.имя”.имя_таблицы

  • “схема.имя”.“таблица.имя”

# File activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb, line 153
def quote_table_name(name)
  schema, name_part = extract_pg_identifier_from_name(name.to_s)

  unless name_part
    quote_column_name(schema)
  else
    table_name, name_part = extract_pg_identifier_from_name(name_part)
    "#{quote_column_name(schema)}.#{quote_column_name(table_name)}"
  end
end
quote_table_name_for_assignment(table, attr) Показать исходный код
# File activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb, line 164
def quote_table_name_for_assignment(table, attr)
  quote_column_name(attr)
end
type_cast(value, column, array_member = false) Показать исходный код
Вызывает метод суперкласса
# File activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb, line 85
def type_cast(value, column, array_member = false)
  return super(value, column) unless column

  case value
  when Range
    if /range$/ =~ column.sql_type
      PostgreSQLColumn.range_to_string(value)
    else
      super(value, column)
    end
  when NilClass
    if column.array && array_member
      'NULL'
    elsif column.array
      value
    else
      super(value, column)
    end
  when Array
    case column.sql_type
    when 'point' then PostgreSQLColumn.point_to_string(value)
    when 'json' then PostgreSQLColumn.json_to_string(value)
    else
      if column.array
        PostgreSQLColumn.array_to_string(value, column, self)
      else
        super(value, column)
      end
    end
  when String
    if 'bytea' == column.sql_type
      # Return a bind param hash with format as binary.
      # See http://deveiate.org/code/pg/PGconn.html#method-i-exec_prepared-doc
      # for more information
      { value: value, format: 1 }
    else
      super(value, column)
    end
  when Hash
    case column.sql_type
    when 'hstore' then PostgreSQLColumn.hstore_to_string(value, array_member)
    when 'json' then PostgreSQLColumn.json_to_string(value)
    else super(value, column)
    end
  when IPAddr
    if %w(inet cidr).include? column.sql_type
      PostgreSQLColumn.cidr_to_string(value)
    else
      super(value, column)
    end
  else
    super(value, column)
  end
end
unescape_bytea(value) Показать исходный код

Раскладывает экранированный вывод bytea из базы данных до двоичной строки, которую он представляет. ПРИМЕЧАНИЕ: Это НЕ обратное преобразование #escape_bytea! Это должно использоваться только для экранированного двоичного вывода из драйвера базы данных.

# File activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb, line 13
def unescape_bytea(value)
  PGconn.unescape_bytea(value) if value
end

© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API