Flowdock
method

table_structure_with_collation

Importance_0
v5.0.0.1 - Show latest stable - 0 notes - Class: ActiveRecord::ConnectionAdapters::SQLite3Adapter
table_structure_with_collation(table_name, basic_structure) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 531
        def table_structure_with_collation(table_name, basic_structure)
          collation_hash = {}
          sql            = "SELECT sql FROM
                              (SELECT * FROM sqlite_master UNION ALL
                               SELECT * FROM sqlite_temp_master)
                            WHERE type='table' and name='#{ table_name }' \;"

          # Result will have following sample string
          # CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
          #                       "password_digest" varchar COLLATE "NOCASE");
          result = exec_query(sql, 'SCHEMA').first

          if result
            # Splitting with left parentheses and picking up last will return all
            # columns separated with comma(,).
            columns_string = result["sql"].split('(').last

            columns_string.split(',').each do |column_string|
              # This regex will match the column name and collation type and will save
              # the value in $1 and $2 respectively.
              collation_hash[$1] = $2 if (COLLATE_REGEX =~ column_string)
            end

            basic_structure.map! do |column|
              column_name = column['name']

              if collation_hash.has_key? column_name
                column['collation'] = collation_hash[column_name]
              end

              column
            end
          else
            basic_structure.to_hash
          end
        end
Register or log in to add new notes.