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, #prepare, #primary_key_definition, #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, #prepare, #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



2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2170

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

#query_offset_limit!(sql, offset, limit, options) ⇒ Object



2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2186

def query_offset_limit!(sql, offset, limit, options)
  if (offset.nil?)
     options[:paramArray] = []
     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 ? AND ?"
  options[:paramArray] = [offset+1, last_record]
end

#reorg_table(table_name) ⇒ Object

Reorganizes the table for column changes



2166
2167
2168
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2166

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