Class: ActiveRecord::ConnectionAdapters::IBM_DataServer
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::IBM_DataServer
- 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)
Instance Method Summary collapse
- #change_column_default(table_name, column_name, default) ⇒ Object
- #change_column_null(table_name, column_name, null, default) ⇒ Object
- #check_reserved_words(col_name) ⇒ Object
- #create_index_after_table(table_name, cloumn_name) ⇒ Object
-
#execute(sql, _name = nil) ⇒ Object
Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
- #get_datetime_mapping ⇒ Object
- #get_double_mapping ⇒ Object
- #get_time_mapping ⇒ Object
-
#initialize(adapter, ar3) ⇒ IBM_DataServer
constructor
A new instance of IBM_DataServer.
- #last_generated_id(stmt) ⇒ Object
- #limit_not_supported_types ⇒ Object
-
#prepare(sql, _name = nil) ⇒ Object
Praveen.
-
#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.
- #reorg_table(table_name) ⇒ Object
- #select(stmt) ⇒ Object
- #select_rows(_sql, _name, stmt, results) ⇒ Object
- #set_binary_default(value) ⇒ Object
- #set_binary_value ⇒ Object
- #set_case(value) ⇒ Object
- #set_schema(schema) ⇒ Object
- #set_text_default ⇒ Object
- #setup_for_lob_table ⇒ Object
Constructor Details
#initialize(adapter, ar3) ⇒ IBM_DataServer
Returns a new instance of IBM_DataServer.
3529 3530 3531 3532 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3529 def initialize(adapter, ar3) @adapter = adapter @isAr3 = ar3 end |
Instance Method Details
#change_column_default(table_name, column_name, default) ⇒ Object
3661 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3661 def change_column_default(table_name, column_name, default); end |
#change_column_null(table_name, column_name, null, default) ⇒ Object
3663 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3663 def change_column_null(table_name, column_name, null, default); end |
#check_reserved_words(col_name) ⇒ Object
3542 3543 3544 3545 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3542 def check_reserved_words(col_name) @adapter.puts_log 'check_reserved_words' col_name.to_s end |
#create_index_after_table(table_name, cloumn_name) ⇒ Object
3536 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3536 def create_index_after_table(table_name, cloumn_name); end |
#execute(sql, _name = nil) ⇒ Object
Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3630 def execute(sql, _name = nil) @adapter.puts_log "IBM_DataServer execute #{sql} #{Thread.current}" begin if @adapter.connection.nil? || @adapter.connection == false raise ActiveRecord::ConnectionNotEstablished, 'called on a closed database' elsif stmt = IBM_DB.exec(@adapter.connection, sql) stmt # Return the statement object else raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN), sql end rescue StandardError => e raise unless e && !e..empty? @adapter.puts_log "104 error = #{e.}" @adapter.puts_log "104 sql = #{sql}" raise StatementInvalid end end |
#get_datetime_mapping ⇒ Object
3655 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3655 def get_datetime_mapping; end |
#get_double_mapping ⇒ Object
3659 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3659 def get_double_mapping; end |
#get_time_mapping ⇒ Object
3657 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3657 def get_time_mapping; end |
#last_generated_id(stmt) ⇒ Object
3534 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3534 def last_generated_id(stmt); end |
#limit_not_supported_types ⇒ Object
3673 3674 3675 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3673 def limit_not_supported_types %i[integer double date time timestamp xml bigint] end |
#prepare(sql, _name = nil) ⇒ Object
Praveen
3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3615 def prepare(sql, _name = nil) @adapter.puts_log 'prepare' begin stmt = IBM_DB.prepare(@adapter.connection, sql) raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN) unless stmt stmt rescue StandardError => e raise "Failed to prepare sql #{sql} due to: #{e}" if e && !e..empty? raise 'An unexpected error occurred during SQLprepare' end 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
3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3549 def remove_column(table_name, column_name) @adapter.puts_log 'remove_column' begin @adapter.execute "ALTER TABLE #{table_name} DROP #{column_name}" reorg_table(table_name) rescue StandardError => e # Provide details on the current XML columns support raise "#{e}" unless e..include?('SQLCODE=-1242') && e..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: #{e}" end end |
#reorg_table(table_name) ⇒ Object
3540 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3540 def reorg_table(table_name); end |
#select(stmt) ⇒ Object
3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3564 def select(stmt) @adapter.puts_log 'select' 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 => e # Handle driver fetch errors error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT) raise StatementInvalid, "Failed to retrieve data: #{error_msg}" if error_msg && !error_msg.empty? error_msg = 'An unexpected error occurred during data retrieval' error_msg += ": #{e.}" unless e..empty? raise error_msg end results end |
#select_rows(_sql, _name, stmt, results) ⇒ Object
3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3593 def select_rows(_sql, _name, stmt, results) @adapter.puts_log 'select_rows' # 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 => e # Handle driver fetch errors error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT) raise StatementInvalid, "Failed to retrieve data: #{error_msg}" if error_msg && !error_msg.empty? error_msg = 'An unexpected error occurred during data retrieval' error_msg += ": #{e.}" unless e..empty? raise error_msg end results end |
#set_binary_default(value) ⇒ Object
3665 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3665 def set_binary_default(value); end |
#set_binary_value ⇒ Object
3667 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3667 def set_binary_value; end |
#set_case(value) ⇒ Object
3671 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3671 def set_case(value); end |
#set_schema(schema) ⇒ Object
3650 3651 3652 3653 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3650 def set_schema(schema) @adapter.puts_log 'set_schema' @adapter.execute("SET SCHEMA #{schema}") end |
#set_text_default ⇒ Object
3669 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3669 def set_text_default; end |
#setup_for_lob_table ⇒ Object
3538 |
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 3538 def setup_for_lob_table; end |