Class: ActiveRecord::ConnectionAdapters::IBM_DB2_LUW

Inherits:
IBM_DB2 show all
Defined in:
lib/active_record/connection_adapters/ibm_db_adapter.rb

Overview

class IBM_DB2

Direct Known Subclasses

IBM_DB2_LUW_COBRA

Instance Method Summary collapse

Methods inherited from IBM_DB2

#change_column, #change_column_default, #change_column_null, #execute, #get_datetime_mapping, #get_double_mapping, #get_time_mapping, #last_generated_id, #primary_key, #rename_column, #select, #select_rows, #set_binary_default, #set_binary_value, #set_case, #set_text_default

Methods inherited from IBM_DataServer

#change_column_default, #change_column_null, #check_reserved_words, #create_index_after_table, #execute, #get_datetime_mapping, #get_double_mapping, #get_time_mapping, #initialize, #last_generated_id, #limit_not_supported_types, #remove_column, #select, #select_rows, #set_binary_default, #set_binary_value, #set_case, #set_schema, #set_text_default, #setup_for_lob_table

Constructor Details

This class inherits a constructor from ActiveRecord::ConnectionAdapters::IBM_DataServer

Instance Method Details

#query_offset_limit(sql, offset, limit) ⇒ Object



1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1828

def query_offset_limit(sql, offset, limit)
  if (offset.nil?)
     return sql << " FETCH FIRST #{limit} ROWS ONLY"
  end
  # Defines what will be the last record
  last_record = offset + limit
  # Transforms the SELECT query in order to retrieve/fetch only
  # a number of records after the specified offset.
  # 'select' or 'SELECT' is replaced with the partial query below that adds the sys_row_num column
  # to select with the condition of this column being between offset+1 and the offset+limit
  sql.sub!(/SELECT/i,"SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM (SELECT")
  # The final part of the query is appended to include a WHERE...BETWEEN...AND condition,
  # and retrieve only a LIMIT number of records starting from the OFFSET+1
  sql << ") AS I) AS O WHERE sys_row_num BETWEEN #{offset+1} AND #{last_record}"
end

#reorg_table(table_name) ⇒ Object

Reorganizes the table for column changes



1824
1825
1826
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1824

def reorg_table(table_name)
  execute("CALL ADMIN_CMD('REORG TABLE #{table_name}')")
end