diff options
Diffstat (limited to 'activerecord/lib/active_record')
3 files changed, 15 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb index 365fdeb55a..82d94b848a 100644 --- a/activerecord/lib/active_record/attribute_methods/primary_key.rb +++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb @@ -3,6 +3,12 @@ module ActiveRecord module PrimaryKey extend ActiveSupport::Concern + # Returns this record's primary key value wrapped in an Array + # or nil if the record is a new_record? + def to_key + new_record? ? nil : [ id ] + end + module ClassMethods # Defines the primary key field -- can be overridden in subclasses. Overwriting will negate any effect of the # primary_key_prefix_type setting, though. diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 802921e181..9950387420 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -275,6 +275,7 @@ module ActiveRecord rows = [] result.each { |row| rows << row } result.free + @connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped rows end @@ -618,6 +619,7 @@ module ActiveRecord rows = [] result.each_hash { |row| rows << row } result.free + @connection.more_results && @connection.next_result # invoking stored procedures with CLIENT_MULTI_RESULTS requires this to tidy up else connection will be dropped rows end diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 1c4ecda5b5..01cc14b8d6 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -59,17 +59,15 @@ module ActiveRecord end def drop_table! - connection.execute "DROP TABLE #{table_name}" + connection.drop_table table_name end def create_table! - connection.execute <<-end_sql - CREATE TABLE #{table_name} ( - id #{connection.type_to_sql(:primary_key)}, - #{connection.quote_column_name(session_id_column)} VARCHAR(255) UNIQUE, - #{connection.quote_column_name(data_column_name)} TEXT - ) - end_sql + connection.create_table(table_name) do |t| + t.string session_id_column, :limit => 255 + t.text data_column_name + end + connection.add_index table_name, session_id_column, :unique => true end end @@ -205,6 +203,7 @@ module ActiveRecord class << self alias :data_column_name :data_column + remove_method :connection def connection @@connection ||= ActiveRecord::Base.connection end |