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) ⇒ IBM_DataServer

Returns a new instance of IBM_DataServer.



1429
1430
1431
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1429

def initialize(adapter)
  @adapter = adapter
end

Instance Method Details

#change_column_default(table_name, column_name, default) ⇒ Object



1545
1546
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1545

def change_column_default(table_name, column_name, default)
end

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



1548
1549
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1548

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

#check_reserved_words(col_name) ⇒ Object



1445
1446
1447
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1445

def check_reserved_words(col_name)
  col_name
end

#create_index_after_table(table_name, cloumn_name) ⇒ Object



1436
1437
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1436

def create_index_after_table (table_name,cloumn_name)
end

#execute(sql, name = nil) ⇒ Object



1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1513

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



1536
1537
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1536

def get_datetime_mapping
end

#get_double_mappingObject



1542
1543
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1542

def get_double_mapping
end

#get_time_mappingObject



1539
1540
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1539

def get_time_mapping
end

#last_generated_id(stmt) ⇒ Object



1433
1434
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1433

def last_generated_id(stmt)
end

#limit_not_supported_typesObject



1563
1564
1565
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1563

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

#query_offset_limit(sql, offset, limit) ⇒ Object



1533
1534
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1533

def query_offset_limit(sql, offset, limit)
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



1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1451

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



1442
1443
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1442

def reorg_table(table_name)
end

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



1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1467

def select(sql, name, 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
    while single_hash = IBM_DB.fetch_assoc(stmt)
      # Add the record to the +results+ array
      results <<  single_hash
    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
  ensure  # Free resources associated with the statement
    IBM_DB.free_result(stmt)
  end
end

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



1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1490

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
  ensure  # Free resources associated with the statement
    IBM_DB.free_result(stmt)
  end
end

#set_binary_default(value) ⇒ Object



1551
1552
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1551

def set_binary_default(value)
end

#set_binary_valueObject



1554
1555
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1554

def set_binary_value
end

#set_case(value) ⇒ Object



1560
1561
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1560

def set_case(value)
end

#set_schema(schema) ⇒ Object



1529
1530
1531
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1529

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

#set_text_defaultObject



1557
1558
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1557

def set_text_default
end

#setup_for_lob_tableObject



1439
1440
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 1439

def setup_for_lob_table ()
end