Class: ActiveRecord::ConnectionAdapters::IBM_DataServer

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

Overview

This class contains common code across DB’s (DB2 LUW, zOS, i5 and IDS)

Direct Known Subclasses

IBM_DB2, IBM_IDS

Instance Method Summary collapse

Constructor Details

#initialize(adapter, ar3) ⇒ IBM_DataServer

Returns a new instance of IBM_DataServer.



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

def initialize(adapter, ar3)
  @adapter = adapter
		@isAr3 = ar3
end

Instance Method Details

#change_column_default(table_name, column_name, default) ⇒ Object



2314
2315
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2314

def change_column_default(table_name, column_name, default)
end

#change_column_null(table_name, column_name, null, default) ⇒ Object



2317
2318
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2317

def change_column_null(table_name, column_name, null, default)
end

#check_reserved_words(col_name) ⇒ Object



2184
2185
2186
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2184

def check_reserved_words(col_name)
  col_name.to_s
end

#create_index_after_table(table_name, cloumn_name) ⇒ Object



2175
2176
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2175

def create_index_after_table (table_name,cloumn_name)
end

#execute(sql, name = nil) ⇒ Object



2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2276

def execute(sql, name = nil)
  begin
    if stmt = IBM_DB.exec(@adapter.connection, sql)
      stmt   # Return the statement object
    else
      raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
    end
  rescue StandardError => exec_err
    if exec_err && !exec_err.message.empty?
      raise "Failed to execute statement due to: #{exec_err}"
    else 
      raise
    end
  end
end

#get_datetime_mappingObject



2305
2306
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2305

def get_datetime_mapping
end

#get_double_mappingObject



2311
2312
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2311

def get_double_mapping
end

#get_limit_offset_clauses(limit, offset) ⇒ Object



2299
2300
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2299

def get_limit_offset_clauses(limit, offset)
end

#get_time_mappingObject



2308
2309
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2308

def get_time_mapping
end

#last_generated_id(stmt) ⇒ Object



2172
2173
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2172

def last_generated_id(stmt)
end

#limit_not_supported_typesObject



2332
2333
2334
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2332

def limit_not_supported_types
  [:integer, :double, :date, :time, :timestamp, :xml, :bigint]
end

#prepare(sql, name = nil) ⇒ Object

Praveen



2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2259

def prepare(sql,name = nil)
  begin
    stmt = IBM_DB.prepare(@adapter.connection, sql)
    if( stmt )
      stmt
    else
      raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
    end
  rescue StandardError => prep_err
    if prep_err && !prep_err.message.empty?
      raise "Failed to prepare sql #{sql} due to: #{prep_err}"
    else 
      raise
    end
  end
end

#query_offset_limit(sql, offset, limit) ⇒ Object



2296
2297
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2296

def query_offset_limit(sql, offset, limit)
end

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



2302
2303
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2302

def query_offset_limit!(sql, offset, limit, options)
end

#remove_column(table_name, column_name) ⇒ Object

This is supported by the DB2 for Linux, UNIX, Windows data servers and by the DB2 for i5 data servers



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

def remove_column(table_name, column_name)
  begin
    @adapter.execute "ALTER TABLE #{table_name} DROP #{column_name}"
    reorg_table(table_name)
  rescue StandardError => exec_err
    # Provide details on the current XML columns support
    if exec_err.message.include?('SQLCODE=-1242') && exec_err.message.include?('42997')
      raise StatementInvalid, 
            "A column that is part of a table containing an XML column cannot be dropped. \
To remove the column, the table must be dropped and recreated without the #{column_name} column: #{exec_err}"
    else
      raise "#{exec_err}"
    end
  end
end

#reorg_table(table_name) ⇒ Object



2181
2182
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2181

def reorg_table(table_name)
end

#select(stmt) ⇒ Object



2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2206

def select(stmt)
  results = []
  # Fetches all the results available. IBM_DB.fetch_assoc(stmt) returns
  # an hash for each single record.
  # The loop stops when there aren't any more valid records to fetch
  begin
  if(@isAr3)
      while single_hash = IBM_DB.fetch_assoc(stmt)
        # Add the record to the +results+ array
        results <<  single_hash
      end
    else
      while single_hash = IBM_DB.fetch_array(stmt)
        # Add the record to the +results+ array
        results <<  single_hash
      end
    end
  rescue StandardError => fetch_error # Handle driver fetch errors
    error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
    if error_msg && !error_msg.empty?
      raise StatementInvalid,"Failed to retrieve data: #{error_msg}"
    else
      error_msg = "An unexpected error occurred during data retrieval"
      error_msg = error_msg + ": #{fetch_error.message}" if !fetch_error.message.empty?
      raise error_msg
    end
  end
  return results
end

#select_rows(sql, name, stmt, results) ⇒ Object



2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2236

def select_rows(sql, name, stmt, results)
  # Fetches all the results available. IBM_DB.fetch_array(stmt) returns
  # an array representing a row in a result set.
  # The loop stops when there aren't any more valid records to fetch
  begin
    while single_array = IBM_DB.fetch_array(stmt)
      #Add the array to results array
      results <<  single_array
    end
  rescue StandardError => fetch_error # Handle driver fetch errors
    error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
    if error_msg && !error_msg.empty?
      raise StatementInvalid,"Failed to retrieve data: #{error_msg}"
    else
      error_msg = "An unexpected error occurred during data retrieval"
      error_msg = error_msg + ": #{fetch_error.message}" if !fetch_error.message.empty?
      raise error_msg
    end
  end
  return results
end

#set_binary_default(value) ⇒ Object



2320
2321
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2320

def set_binary_default(value)
end

#set_binary_valueObject



2323
2324
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2323

def set_binary_value
end

#set_case(value) ⇒ Object



2329
2330
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2329

def set_case(value)
end

#set_schema(schema) ⇒ Object



2292
2293
2294
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2292

def set_schema(schema)
  @adapter.execute("SET SCHEMA #{schema}")
end

#set_text_defaultObject



2326
2327
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2326

def set_text_default
end

#setup_for_lob_tableObject



2178
2179
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 2178

def setup_for_lob_table ()
end