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, #initialize, #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_DB2

Instance Method Details

#query_offset_limit(sql, offset, limit) ⇒ Object



2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2207

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



2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2223

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



2203
2204
2205
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2203

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